View file news/includes/navigator.class.php

File size: 1.08Kb
<?php
class Navigator
{
	function __construct($all,$pnumber,$query='')
	{
		$this->all=$all;
		$this->pnumber=$pnumber;
		$this->query=$query;
		$this->page=isset($_GET['p']) ? (int)$_GET['p'] : 1;
	}

	function start()
	{
		$this->num_pages=ceil($this->all/$this->pnumber);
		
		if (isset($_GET['last']))
		$this->page=$this->num_pages;
		
		$this->start=$this->page*$this->pnumber-$this->pnumber;

		if ($this->page > $this->num_pages || $this->page < 1)
		{
			$this->page=1;
			$this->start=0;
		}

		return $this->start;
	}

	function navi()
	{
		
		if ($this->num_pages<2)
		return '';		
		
		$buff='<div class="m"><div class="top">';
		
		if (!empty($_GET['news_id'])) {
			$nd	=	'&news_id='.intval($_GET['news_id']).'';
		} else {
			$nd	=	'';
		}
		
    for($pr = '', $i =1; $i <= $this->num_pages; $i++)
    {
        $buff.= 
        $pr=(($i == 1 || $i == $this->num_pages || abs($i-$this->page) < 2) ? ($i == $this->page ? " [$i] " : ' <a href="'.$_SERVER['SCRIPT_NAME'].'?p='.$i.$nd.'">'.$i.'</a> ') : (($pr == ' ... ' || $pr == '')? '' : ' ... '));
    }
		return $buff.'</div></div>';
	}

}


?>