<?php
$currpage = empty($_GET['page']) ? 1 : (int)$_GET['page'];
$count = 12;
function EchoLink($page, $sep=true)
{
global $currpage;
if($currpage == $page) echo "[$page]";
else echo " [
url='$PHP_SELF?page=$page']$page[/
url]";
if($sep) echo ', ';
}
function EchoBackLink()
{
global $currpage;
$page = $currpage-1;
if($page > 0)
echo "[
url='$PHP_SELF?page=$page']<=[/
url]";
}
function EchoNextLink()
{
global $currpage, $count;
$page = $currpage+1;
if($page <= $count)
echo "[
url='$PHP_SELF?page=$page']=>[/
url]";
}
if($count <= 7)
for($i=1; $i<=$count; $i++)
EchoLink($i, $i!=$count);
else
{
EchoBackLink();
$idx = (($currpage==4) || ($currpage==5)) ? $currpage : 3;
for($i=1; $i<=$idx; $i++)
EchoLink($i, $i!=$idx);
if(($currpage > 5) && ($currpage < $count-4))
{
echo "...";
for($i=$currpage-1; $i<=$currpage+1; $i++)
EchoLink($i, $i!=$currpage+1);
}
echo "...";
$idx = $count-2;
if(($currpage == $count-3) ||($currpage == $count-4))
$idx = $currpage;
for($i=$idx; $i<=$count; $i++)
EchoLink($i, $i!=$count);
EchoNextLink();
}
?>