All pastes #203285 Raw Edit

done

public php v1 · immutable
#203285 ·published 2006-10-15 01:22 UTC
rendered paste body
<?php$URI=array("mail", "read", "page6");function pages($n) { # Template could be used to avoid HTML here, but that would make code slower. $n = n. of pages// This build a simple 'paginator', note that it can only be used in the indexes, not in the results	global $URI;	$way=$URI; # See line above, we don't want to destruct the $URI structure, right?	if(isset($way[2])) { # See if it's on a page other than 1		$activepage=substr($way[2], 4); # $way[2] is passed as pageX where X is the page		unset($way[2]);	} else {		$activepage=1; # If it's on the first page just call it page 1.	}	$way=implode($way, "/"); # Let's implode the $way// 	Now let's define the limits	if($n<=12) {		$limits=array(1,$n);	} elseif($activepage<7) {		$limits=array(1,7,$n-1,$n);	} elseif($activepage>$n-5) {		$limits=array(1,2,$n-5,$n);	} else {		$limits=array(1,2,$activepage-3,$activepage+3,$n-1);	}	$counter=0;	while(isset($limits)) {		for($x=$limits[$counter];$x<=$limits[$counter+1];$x++) {			if($x==$activepage) {				 echo "<em>$x</em>\n";			} else {				echo "<a href=\"/$way/page$x\">$x</a>\n";			}		}		if(isset($limits[$counter+2])) {			$counter++;			echo "...\n";		} else {			unset($limits);		}	}}pages('13');?>