PageRenderTime 51ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/wp-content/plugins/nextgen-gallery/lib/navigation.php

https://bitbucket.org/dkrzos/phc
PHP | 120 lines | 61 code | 14 blank | 45 comment | 21 complexity | 5f188ff9c8271aa8e135fb102dd00c3e MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * nggNavigation - PHP class for the pagination
  4. *
  5. * @package NextGEN Gallery
  6. * @author Alex Rabe
  7. *
  8. * @version 1.0.1
  9. * @access public
  10. */
  11. class nggNavigation {
  12. /**
  13. * Return the navigation output
  14. *
  15. * @access public
  16. * @var string
  17. */
  18. var $output = false;
  19. /**
  20. * Link to previous page
  21. *
  22. * @access public
  23. * @var string
  24. */
  25. var $prev = false;
  26. /**
  27. * Link to next page
  28. *
  29. * @access public
  30. * @var string
  31. */
  32. var $next = false;
  33. /**
  34. * PHP4 compatibility layer for calling the PHP5 constructor.
  35. *
  36. */
  37. function nggNavigation() {
  38. return $this->__construct();
  39. }
  40. /**
  41. * Main constructor - Does nothing.
  42. * Call create_navigation() method when you need a navigation.
  43. *
  44. */
  45. function __construct() {
  46. return;
  47. }
  48. /**
  49. * nggNavigation::create_navigation()
  50. *
  51. * @param mixed $page
  52. * @param integer $totalElement
  53. * @param integer $maxElement
  54. * @return string pagination content
  55. */
  56. function create_navigation($page, $totalElement, $maxElement = 0) {
  57. global $nggRewrite;
  58. $prev_symbol = apply_filters('ngg_prev_symbol', '&#9668;');
  59. $next_symbol = apply_filters('ngg_prev_symbol', '&#9658;');
  60. if ($maxElement > 0) {
  61. $total = $totalElement;
  62. // create navigation
  63. if ( $total > $maxElement ) {
  64. $total_pages = ceil( $total / $maxElement );
  65. $r = '';
  66. if ( 1 < $page ) {
  67. $args['nggpage'] = ( 1 == $page - 1 ) ? FALSE : $page - 1;
  68. $previous = $args['nggpage'];
  69. if (FALSE == $args['nggpage']) {
  70. $previous = 1;
  71. }
  72. $this->prev = $nggRewrite->get_permalink ( $args );
  73. $r .= '<a class="prev" id="ngg-prev-' . $previous . '" href="' . $this->prev . '">' . $prev_symbol . '</a>';
  74. }
  75. $total_pages = ceil( $total / $maxElement );
  76. if ( $total_pages > 1 ) {
  77. for ( $page_num = 1; $page_num <= $total_pages; $page_num++ ) {
  78. if ( $page == $page_num ) {
  79. $r .= '<span class="current">' . $page_num . '</span>';
  80. } else {
  81. $p = false;
  82. if ( $page_num < 3 || ( $page_num >= $page - 3 && $page_num <= $page + 3 ) || $page_num > $total_pages - 3 ) {
  83. $args['nggpage'] = ( 1 == $page_num ) ? FALSE : $page_num;
  84. $r .= '<a class="page-numbers" href="' . $nggRewrite->get_permalink( $args ) . '">' . ( $page_num ) . '</a>';
  85. $in = true;
  86. } elseif ( $in == true ) {
  87. $r .= '<span class="more">...</span>';
  88. $in = false;
  89. }
  90. }
  91. }
  92. }
  93. if ( ( $page ) * $maxElement < $total || -1 == $total ) {
  94. $args['nggpage'] = $page + 1;
  95. $this->next = $nggRewrite->get_permalink ( $args );
  96. $r .= '<a class="next" id="ngg-next-' . $args['nggpage'] . '" href="' . $this->next . '">' . $next_symbol . '</a>';
  97. }
  98. $this->output = "<div class='ngg-navigation'>$r</div>";
  99. } else {
  100. $this->output = "<div class='ngg-clear'></div>"."\n";
  101. }
  102. }
  103. return $this->output;
  104. }
  105. }
  106. ?>