Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

72 строки
2.1 KiB

  1. <?php
  2. /**
  3. * 仿雅虎搜索的分页
  4. *
  5. * @author iwind <iwind.iwind@gmail.com>
  6. * @link http://ifphp.cn
  7. * @version $Id$
  8. * @package if
  9. * @subpackage plugin.pager
  10. */
  11. /**
  12. * 仿Yahoo搜索的分页
  13. *
  14. * @version $Id$
  15. * @package if
  16. * @subpackage plugin.pager
  17. * @since 1.0
  18. */
  19. import("@.RPage");
  20. class RPageStyle1 extends RPage {
  21. function __toString() {
  22. $pages = array();
  23. $pageNum = $this->length();
  24. $currPageNo = $this->current();
  25. $query = $this->query();
  26. $size = $this->size();
  27. $total = $this->total();
  28. $pageSetNum = $this->pageSetNum();
  29. $middlePageNum = ceil($pageSetNum/2);
  30. if ($pageNum > 0) {
  31. if ($currPageNo <= $middlePageNum) {
  32. $start = 1;
  33. $end = min($pageNum, $pageSetNum);
  34. }
  35. else if ($currPageNo + $middlePageNum - 1 > $pageNum) {
  36. $start = max(1, $pageNum - $pageSetNum - 1);
  37. $end = $pageNum;
  38. }
  39. else {
  40. $start = max(1, $currPageNo - $middlePageNum);
  41. $end = min($currPageNo + $middlePageNum - 1, $pageNum);
  42. }
  43. if ($pageNum > 1) {
  44. $pages[] = "<a href=\"" . $this->url(1) . "\" title=\"First Page\">&laquo;</a>&nbsp; ";
  45. }
  46. if ($currPageNo > 1) {
  47. $pages[] = "<a href=\"" . $this->url($currPageNo - 1) . "\" title=\"Previous {$size}\">" . $this->message("pager_prev") . "</a>&nbsp; ";
  48. }
  49. for ($i = $start; $i <= $end; $i++) {
  50. $_start = $size * ($i - 1) + 1;
  51. $_end = min($size * $i, $total);
  52. if ($i != $currPageNo) {
  53. $pages[] = "<a href=\"" . $this->url($i) . "\" title=\"Results {$_start} - {$_end}\">{$i}</a>";
  54. }
  55. else {
  56. $pages[] = "<span><a href=\"" . $this->url($i) . "\" title=\"Results {$_start} - {$_end}\">{$i}</a></span>";
  57. }
  58. }
  59. if ($currPageNo < $pageNum) {
  60. $pages[] = " &nbsp;<a href=\"" . $this->url($currPageNo + 1) . "\" title=\"Next {$size}\">" . $this->message("pager_next") . "</a>";
  61. }
  62. if ($pageNum > 1) {
  63. $pages[] = "<a href=\"" . $this->url($pageNum) . "\" title=\"Last Page\">&raquo;</a>&nbsp; ";
  64. }
  65. }
  66. $string = implode(" &nbsp;", $pages);
  67. return $string;
  68. }
  69. }