[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/template/smarty/plugins/ -> function.pager.php (source)

   1  <?php
   2  
   3  /**
   4   * Shamelessly ripped off from the phpbb pager
   5   *
   6   * Supported parameters:
   7   * @param data The Pager object containing the information that needs to be displayed 
   8   * @param style Style, one of the following values: 'links', 'list', 'prevonly', 'forwardonly'
   9   * @param separator The character to use as a separator between pages, defaults to an empty space
  10   * @param next Text to be used to the link to the next page in the sequence. If not present, it defaults to
  11   * whatever the current locale has defined for 'next_post'
  12   * @param previous Text to be used to the link to the previous page in the sequence. If not present, it defaults to
  13   * whatever the current locale has defined for 'prev_post'
  14   * @param disablediv Whether not to enclose the pager data in a <div class="pager">...</pager> or not. Defaults to 'false'
  15   * @param anchor Specify the name of an HTML anchor that will be appended to each one of the links in pages, so that
  16   * we can get the browser to jump to the right section of the page (in case the paged content doesn't start at the
  17   * top of the page)
  18   */
  19  function smarty_function_pager($params, &$smarty)    
  20  {
  21      // fetch the parameters
  22      if( isset( $params["data"]))
  23          $pager = $params["data"];
  24      else {
  25          // see if we can load the pager from the smarty context
  26          if( isset( $smarty->_tpl_vars["pager"] ))
  27              $pager = $smarty->_tpl_vars["pager"];
  28          else
  29              return( "" );
  30      }
  31      
  32      // Style parameter. It can either "links", "list", "forwardonly" and "backonly"
  33      isset( $params["style"] ) ? $style = $params["style"] : $style = "links";
  34      
  35      // Separator parameter, defaults to blank spaces
  36      isset( $params["separator"] ) ? $separator = $params["separator"] : $separator = " ";
  37      
  38      // whether to use a <div> area or not
  39      $useDiv = !isset( $params["disablediv" ]);
  40      
  41      // Text used for the "next" link. If not present, this function will look for an object called
  42      // $locale in the template context. If not available, the default locale will be used
  43      if( isset( $params["next"])) {
  44          $nextText = $params["next"];
  45      }
  46      else {
  47          if( isset( $smarty->_tpl_vars["locale"] )) {
  48              $locale = $smarty->_tpl_vars["locale"];            
  49          }
  50          else {
  51              lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
  52              $locale =& Locales::getLocale();
  53          }
  54          $nextText = $locale->tr( "next_post" )."&raquo;";
  55      }
  56      
  57      // Text used for the "previous" link. If not present, this function will look for an object called
  58      // $locale in the template context. If not available, the default locale will be used
  59      if( isset( $params["previous"])) {
  60          $prevText = $params["previous"];
  61      }
  62      else {
  63          if( isset( $smarty->_tpl_vars["locale"] )) {
  64              $locale = $smarty->_tpl_vars["locale"];            
  65          }
  66          else {
  67              lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
  68              $locale =& Locales::getLocale();
  69          }
  70          $prevText = "&laquo;".$locale->tr( "previous_post" );
  71      }    
  72      
  73      // number of pages shown in the beginning
  74      isset( $params["beginning"] ) ? $beginning = $params["beginning"] : $beginning = 3;
  75      // number of pages shown in the middle
  76      isset( $params["middle"] ) ? $middle = $params["middle"] : $middle = 5;
  77      // Number of pages shown in the end
  78      isset( $params["end"] ) ? $end = $params["end"] : $end = 3;
  79      // whether we need to append an anchor reference to all links (in case the paged
  80      // doesn't start immediately at the top of the page)
  81      isset( $params["anchor"]) ? $anchor = $params["anchor"] : $anchor = "";
  82      
  83          
  84      $base_url = $pager->getBaseUrl();
  85      $total_pages = $pager->getTotalPages();
  86      $per_page = $pager->getRegsForPage();
  87      $start_item = 1;
  88      $add_prevnext_text = true;
  89      $on_page = $pager->getCurrentPage();
  90  
  91      $page_string = '';
  92      
  93      $pageLinks = $pager->getPageLinks();
  94      
  95      if( $style == "links" ) {
  96          if ( $total_pages == 1 )
  97              return '';
  98  
  99          if ( $total_pages > ($beginning + 1 + $middle + 1 + $middle + 1 + $end ))
 100          {
 101              $init_page_max = ( $total_pages > $beginning ) ? $beginning : $total_pages;
 102  
 103              for($i = 1; $i < $init_page_max + 1; $i++) {
 104                  $page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 105                  if ( $i <  $init_page_max ) {
 106                      $page_string .= $separator;
 107                  }
 108              }
 109  
 110              if ( $on_page > 1  && $on_page < $total_pages ) {
 111                  $page_string .= ( $on_page > ($beginning + $middle + 1) ) ? ' ... ' : $separator;
 112  
 113                  $init_page_min = ( $on_page > ($beginning + $middle) ) ? $on_page : ($beginning + $middle + 1 );
 114                  $init_page_max = ( $on_page < $total_pages - ($end + 1) ) ? $on_page : $total_pages - ($end + $middle);
 115  
 116  
 117                  for($i = $init_page_min - $middle; $i < $init_page_max + ($middle + 1); $i++) {
 118                      $page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 119                      if ( $i <  $init_page_max + 1 ) {
 120                          $page_string .= $separator;
 121                      }
 122                  }
 123  
 124                  $page_string .= ( $on_page < $total_pages - ($end + $middle) ) ? ' ... ' : $separator;
 125              }
 126              else {
 127                  $page_string .= ' ... ';
 128              }
 129              
 130              for($i = $total_pages - ($end - 1); $i < $total_pages + 1; $i++) {
 131                  $page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 132                  if( $i <  $total_pages ) {
 133                      $page_string .= $separator;
 134                  }
 135              }
 136          }
 137          else {
 138              for($i = 1; $i < $total_pages + 1; $i++) {
 139                  $page_string .= ( $i == $on_page ) ? " <span class=\"pagerCurrent\">$i</span>" : " <a class=\"pagerLink\" href=\"".$pageLinks[$i].$anchor."\">$i</a>";
 140                  if ( $i <  $total_pages ) {
 141                      $page_string .= $separator;
 142                  }
 143              }
 144          }
 145  
 146          if ( $add_prevnext_text ) {
 147              if ( $on_page > 1 ) {
 148                  $page_string = ' <a class="pagerLinkPrevPage" href="'.$pageLinks[$on_page - 1 ].$anchor.'">'.$prevText.'</a>&nbsp;&nbsp;'.$page_string;
 149              }
 150  
 151              if ( $on_page < $total_pages ) {
 152                  $page_string .= '&nbsp;&nbsp;<a class="pagerLinkNextPage" href="'.$pageLinks[$on_page + 1].$anchor.'">'.$nextText.'</a>';
 153              }            
 154          }
 155      }
 156      elseif( $style == "list" ) {
 157          $page_string .= "
 158          <script type=\"text/javascript\">
 159  			function onPagerListChange(list) 
 160              {
 161                  var index = list.selectedIndex;
 162                  var value = list.options[index].value;
 163                  top.location.href = value;
 164                  return true;
 165              }
 166          </script>
 167          <span class=\"pager\">";
 168          if( !$pager->isFirstPage() && !$pager->isEmpty()) {
 169              $page_string .= "<span class=\"list_action_button\">
 170                 <a href=\"".$pager->getPrevPageLink().$anchor."\"><img src=\"imgs/admin/icon_left-16.png\" alt=\"$prevText\" /></a>
 171               </span>";
 172          }
 173          $page_string .= "<select name=\"plogPager\" id=\"plogPager\" onChange=\"onPagerListChange(this)\""; 
 174          if( $pager->isEmpty()) {
 175              $page_string .= "disabled=\"disabled\"";
 176          }
 177          $page_string .= ">";
 178          foreach( $pager->getPageLinks() as $pageId => $pageLink ) {
 179              $page_string .= "<option value=\"{$pageLink}{$anchor}\"";
 180              if( $pageId == $pager->getCurrentPage())
 181                  $page_string .= "selected=\"selected\"";
 182              $page_string .= ">$pageId</option>";
 183          }
 184  
 185          $page_string .= "</select>";
 186          
 187          if( !$pager->isLastPage() && !$pager->isEmpty()) {
 188               $page_string .= "<span class=\"list_action_button\">";
 189              $page_string .= "<a href=\"".$pager->getNextPageLink().$anchor."\"><img src=\"imgs/admin/icon_right-16.png\" alt=\"$nextText\" /></a>";
 190               $page_string .= "</span>";
 191          }
 192          $page_string .= "</span>";
 193      }
 194      elseif( $style == "prevonly" ) {
 195          if (!$pager->isFirstPage() && !$pager->isEmpty()) {
 196             $page_string .= "<a class=\"pagerLinkPrevPage\" href=\"".$pager->getPrevPageLink().$anchor."\">$prevText</a>&nbsp;";
 197          }
 198      }
 199      elseif( $style == "nextonly" ) {
 200          if (!$pager->isLastPage() && !$pager->isEmpty()) {
 201             $page_string .= "<a class=\"pagerLinkNextPage\" href=\"".$pager->getNextPageLink().$anchor."\">$nextText</a>&nbsp;";
 202          }        
 203      }
 204      else {
 205          $smarty->trigger_error( "Unrecognized 'style' parameter for the pager. Valid values are: 'links', 'prevonly', 'nextonly'" );
 206      }
 207      
 208      if( $useDiv )
 209          $page_string = '<div class="pager">'.$page_string.'</div>';
 210  
 211      return $page_string;
 212  }
 213  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics