Slice

This recipe allows you to slice a large Mini list into subpages.

We are going to add:

  • a new mini markup Mini_Slice:* which will slice the list into subpages;
  • a new link markup SubPagesMini:# to print the 1 2 3...# links

See first the usage examples, and below, how to install the new functions.

Usage

The page T.T contains 56 thumbnails. Here we display 6 of them at a time.
Below, we have the 1 2 3...10 links (click on them).

Mini_Slice:T.T/6,*
SubPagesMini:10
BlechnumColensoiBreslau Ring Ostseite 1890-1900Bridge declarerCanis lupus layingCitrus fruitsColumbia.sts-1.01

1 2 3 4 5 6 7 8 9 10

or, alternatively:

PaginateMini:10

<< < 1 2 3 4 5 ... > >>

About the Mini_Slice: markup. You can have :

  • Mini_Slice:* displays 20 thumbnails of all
  • Mini_Slice:10,*.jpg displays 10 thumbnails of all JPEGs
  • Mini_Slice:OtherPage/7,* displays 7 thumbnails attached to OtherPage (see the example).
    The *.jpg list is exactly like in the Mini: markup, only preceded by a number indicating how many thumbs should appear at once. You can have *,-1.jpg for example.

About the SubPagesMini: markup. Just add the number of subpages.
You could have, for example:

Go to gallery subpage: SubPagesMini:10

Go to gallery subpage: 1 2 3 4 5 6 7 8 9 10

You could also use Mini1_Slice for an advanced mini set, as well as lowercase "m" in mini_Slice to disable links. (Just like with the regular Mini and with the random sets.)

Notes

  • Note that the recipe probably works best with one single "Mini_Slice:" markup in the wiki page.
  • Note that the recipe will not work with full gallery caching enabled.

Installation

Add to config.php the Mini_Slice: definition (required):

function uMini_Slice($a){ # slice a mini list into subpages
	global $Mini; SDVA($Mini, array('uPerPage'=>20));
	foreach($a as $k=>$v)break;
	$cnt=is_numeric($v)?array_shift($a):$Mini['uPerPage'];
	$mp = intval(@$_GET['mp']); if($mp<=0)$mp=1; $mp--;
	$b = array_slice($a, $cnt*$mp, $cnt);
	$c=array();foreach($b as $v)$c[$v]=$v;return $c;
}

Add to config.php SubPagesMini: definition (if you use it):

$LinkFunctions['SubPagesMini'] = 'SubPagesMini';
function SubPagesMini($pagename,$imap,$path) {
	$mp = intval(@$_GET['mp']); if($mp<=0)$mp=1;
	$path = intval(preg_replace('/[^\\d]+/', '', $path));
	$out = '';
	for($i=1; $i<=$path; $i++){
		if($i==$mp) $out .= " $i";
		else $out .= " ". LinkPage($pagename,'<:page>',"$pagename?mp=$i",'',$i);
	}
	return $out;
 }

Add to config.php PaginateMini: definition (if you use it):

$PaginateFmt['PaginateMini'] = array(
  'start' => '&lt;&lt;',
  'end'   => '&gt;&gt;',
  'prev'  => '&lt;',
  'next'  => '&gt;',
  'count' => 5,
  'urlparm'=> 'mp',
);
$LinkFunctions['PaginateMini'] = 'Paginate';
function Paginate($pagename,$imap,$path,$alt,$txt,$fmt=NULL) {
	global $PaginateFmt;
	$My = (array)@$PaginateFmt[$imap];
	$mp = intval(@$_GET[ $My['urlparm'] ]); if($mp<=0) $mp=1;
	$path = intval(preg_replace('/[^\\d]+/', '', $path));
	$out = array();
	if(isset($My['start'])) $out[] = PaginateLink($pagename, $My['start'], 1, $mp);
	if(isset($My['prev'])) $out[] = PaginateLink($pagename, $My['prev'], max(1, $mp-1), $mp);


	if(@$My['count']>0) {
		$start1 = max(1, $mp-floor($My['count']/2));
		$start2 = max(1, $path-$My['count']+1);

		$start = min($start1, $start2);
		$end = min($path, $start+$My['count']-1);
	}
	else {$start = 1; $end = $path;}

	if($start>1) $out[] = '...';
	for($i=$start; $i<=$end; $i++) $out[] = PaginateLink($pagename, $i, $i, $mp);
	if($end<$path) $out[] = '...';
	if(isset($My['next'])) $out[] = PaginateLink($pagename, $My['next'], min($path, $mp+1), $mp);
	if(isset($My['end'])) $out[] = PaginateLink($pagename, $My['end'], $path, $mp);

	return  "<span class='subpagelinks'>". implode(' ', $out). "</span>";
}
function PaginateLink($pagename, $text, $i, $mp){
	if(!is_numeric($i) || $i==$mp) return $text;
	return LinkPage($pagename,'<:page>', "$pagename?mp=$i",'',$text);
}

For the PaginateMini: links, you can set what you want to be displayed:

  'start' => 'first',
  'end'   => 'last',
  'prev'  => 'previous',
  'next'  => 'next',
  'count' => 3,

and you can remove 'start', 'end', 'prev' and/or 'next' if you do not need them, and you can set 'count' to the number of links to appear at once (or 0 to display links to all subpages).


Enjoy. --Petko 2009-10-01 00:30