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

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