<?php
function paginate($currentPage, $maxPages, $pagesToShow)
{
$middle = ceil($pagesToShow/2); for($i = 1; $i<=$pagesToShow; $i++){
if($currentPage<$middle){
$pages[] = array('number'=> $i, 'active'=>($i==$currentPage)?
true:false); }
elseif(($maxPages-$currentPage)<$middle){
$pages[] = array('number'=> $maxPages-$pagesToShow+$i, 'active'=> ($pagesToShow-$i==$maxPages-$currentPage)?
true:false); }
else{
$pages[] = array('number' => $currentPage-($middle - $i), 'active'=> ($i==$middle)?
true:false); }
}
return $pages;
}
PD9waHAKCmZ1bmN0aW9uIHBhZ2luYXRlKCRjdXJyZW50UGFnZSwgJG1heFBhZ2VzLCAkcGFnZXNUb1Nob3cpCgl7CgkJJG1pZGRsZSA9IGNlaWwoJHBhZ2VzVG9TaG93LzIpOwoJCSRwYWdlcyA9IGFycmF5KCk7CgkJZm9yKCRpID0gMTsgJGk8PSRwYWdlc1RvU2hvdzsgJGkrKyl7CgkJCWlmKCRjdXJyZW50UGFnZTwkbWlkZGxlKXsKCQkJCSRwYWdlc1tdID0gYXJyYXkoJ251bWJlcic9PiAkaSwgJ2FjdGl2ZSc9PigkaT09JGN1cnJlbnRQYWdlKT8gdHJ1ZTpmYWxzZSk7CgkJCX0KCQkKCQkJZWxzZWlmKCgkbWF4UGFnZXMtJGN1cnJlbnRQYWdlKTwkbWlkZGxlKXsKCQkJCSRwYWdlc1tdID0gYXJyYXkoJ251bWJlcic9PiAkbWF4UGFnZXMtJHBhZ2VzVG9TaG93KyRpLCAnYWN0aXZlJz0+ICgkcGFnZXNUb1Nob3ctJGk9PSRtYXhQYWdlcy0kY3VycmVudFBhZ2UpPyB0cnVlOmZhbHNlKTsKCQkJfQoKCQkJZWxzZXsKCQkJCSRwYWdlc1tdID0gYXJyYXkoJ251bWJlcicgPT4gJGN1cnJlbnRQYWdlLSgkbWlkZGxlIC0gJGkpLCAnYWN0aXZlJz0+ICgkaT09JG1pZGRsZSk/IHRydWU6ZmFsc2UpOwoJCQl9CgkJfQoJCXJldHVybiAkcGFnZXM7Cgl9