Просмотр файла engine/classes/page.class.php

Размер файла: 2.93Kb
  1. <?php
  2. Class Page
  3. {
  4. public
  5. $k_post,
  6. $start,
  7. $k_page,
  8. $l_post,
  9. $page=1;
  10.  
  11. function __construct($k_post,$l_post)
  12. {
  13. $this->k_post = $k_post;
  14. $this->l_post = $l_post;
  15. }
  16. /*
  17. function __get($var)
  18. {
  19. return $this->$var();
  20. }
  21. */
  22.  
  23. function limit()
  24. {
  25. return $this->start() . ', '. $this->l_post;
  26. }
  27. public function page()
  28. {
  29. $this->page = 1;
  30.  
  31. if (isset($_GET['page']))
  32. {
  33. if ($_GET['page'] == 'end')
  34. {
  35. $this->page = intval(self::k_page());
  36. }
  37.  
  38. elseif (is_numeric($_GET['page']))
  39. {
  40. $this->page = intval($_GET['page']);
  41. }
  42. }
  43. if ($this->page < 1)
  44. $this->page = 1;
  45. return $this->page;
  46. }
  47. public function start()
  48. {
  49. return $this->start = $this->l_post * self::page() - $this->l_post;
  50. }
  51. public function k_page()
  52. {
  53. if ($this->k_post)
  54. {
  55. return $this->k_page = ceil($this->k_post/$this->l_post);
  56. }
  57. return $this->k_post;
  58. }
  59. public function display($link = '?')
  60. {
  61. if ($this->k_page() > 1)
  62. {
  63. //if ($page<1)$page=1;
  64. echo '<div class="post">';
  65. if ($this->page() > 1)
  66. {
  67. echo '<a class="page" href="'.$link.'page=1">&lt;&lt;</a> <a class="page" href="'.$link.'page='.($this->page() - 1).'">&lt;</a>';
  68. }
  69. if ($this->page() < $this->k_page())
  70. echo '<a class="page" href="'.$link.'page='.($this->page() +1).'" title="Следующая страница - '.($this->page() +1).')">&gt;</a>';
  71. if ($this->page() != $this->k_page())
  72. echo '<a class="page" href="'.$link.'page=end" title="Последняя страница">&gt;&gt;</a>';
  73. echo '<br />';
  74. if ($this->page() !=1)
  75. echo '<a class="page" href="'.$link.'page=1" title="Страница - 1">1</a>';
  76. else
  77. echo '<span class="page_no">1</span>';
  78. for ($ot=-3; $ot<=3; $ot++)
  79. {
  80. if ($this->page() + $ot >1 && $this->page() + $ot < $this->k_page())
  81. {
  82. if ($ot == -3 && $this->page() + $ot > 2)
  83. echo '..';
  84. if ($ot)
  85. echo ' <a class="page" href="'.$link.'page='.($this->page() + $ot).'" title="Страница - '.($this->page() + $ot).'">'.($this->page() + $ot).'</a> ';
  86. else
  87. echo '<span class="page_no">'.($this->page() + $ot).'</span>';
  88. if ($ot==3 && $this->page() + $ot < $this->k_page - 1)
  89. echo '..';
  90. }
  91. }
  92. if ($this->page() != $this->k_page())
  93. echo ' <a class="page" href="'.$link.'page=end" title="Страница - '.$this->k_page().'">'.$this->k_page().'</a>';
  94. elseif ($this->k_page() > 1)
  95. echo '<span class="page_no">'.$this->k_page().'</span>';
  96. echo '</div>';
  97. }
  98. }
  99. }