/[drupal]/contributions/modules/pagination/pagination.module
ViewVC logotype

Diff of /contributions/modules/pagination/pagination.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.23, Sun Mar 1 00:37:43 2009 UTC revision 1.1.2.24, Sun Mar 1 01:17:30 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  //  $Id: pagination.module,v 1.1.2.22 2009/02/21 02:47:36 mundowen Exp $  //  $Id: pagination.module,v 1.1.2.23 2009/03/01 00:37:43 mundowen Exp $
3    
4  /**  /**
5   *  @file   pagination.module   *  @file   pagination.module
# Line 138  function pagination_admin_settings() { Line 138  function pagination_admin_settings() {
138      '#description'    =>  t('Enable a "Show full page" link below the content.'),      '#description'    =>  t('Enable a "Show full page" link below the content.'),
139      '#default_value'  =>  variable_get('pagination_showall', 1),      '#default_value'  =>  variable_get('pagination_showall', 1),
140    );    );
141      $form['pagination_onebased'] = array(
142        '#type'           =>  'checkbox',
143        '#title'          =>  t('Use 1 based pagers'),
144        '#description'    =>  t('Enable 1 based pagers (Drupal by default uses 0 based pagers)'),
145        '#default_value'  =>  variable_get('pagination_onebased', 1),
146      );
147    $form['submit'] = array(    $form['submit'] = array(
148      '#type'   =>  'submit',      '#type'   =>  'submit',
149      '#value'  =>  t('Set pagination'),      '#value'  =>  t('Set pagination'),
# Line 153  function pagination_admin_settings_submi Line 159  function pagination_admin_settings_submi
159    $style      = $form_state['values']['style'];    $style      = $form_state['values']['style'];
160    $showall    = $form_state['values']['pagination_showall'];    $showall    = $form_state['values']['pagination_showall'];
161    $ignore     = $form_state['values']['pagination_ignore'];    $ignore     = $form_state['values']['pagination_ignore'];
162      $onebased   = $form_state['values']['pagination_onebased'];
163  //  sadly probably faster to just wipe the table and rebuild it then checking for existing records first  //  sadly probably faster to just wipe the table and rebuild it then checking for existing records first
164    $query = "DELETE FROM {pagination}";    $query = "DELETE FROM {pagination}";
165    db_query($query);    db_query($query);
166    variable_set('pagination_showall', (int)$showall);    variable_set('pagination_showall', (int)$showall);
167    variable_set('pagination_ignore', $ignore);    variable_set('pagination_ignore', $ignore);
168      variable_set('pagination_onebased', (int)$onebased);
169    foreach($pagination as $type=>$value) {    foreach($pagination as $type=>$value) {
170      if ($value > 0) {      if ($value > 0) {
171        $query = "INSERT INTO {pagination} (type, paginate, style) VALUES ('%s', %d, %d)";        $query = "INSERT INTO {pagination} (type, paginate, style) VALUES ('%s', %d, %d)";
# Line 533  class Pagination { Line 541  class Pagination {
541     */     */
542    function getPageVar() {    function getPageVar() {
543      $page = isset($_GET['page']) ? $_GET['page'] : 0;      $page = isset($_GET['page']) ? $_GET['page'] : 0;
544      $page = $page > 0 ? --$page : $page;      if (variable_get('pagination_onebased', 1) == 1) {
545          $page = $page > 0 ? --$page : $page;
546        }
547      return $page;      return $page;
548    }    }
549    
# Line 547  class Pagination { Line 557  class Pagination {
557      $pager_page_array     = explode(',', (int) $this->getPageVar() );      $pager_page_array     = explode(',', (int) $this->getPageVar() );
558      $pager_total[0]       = $this->getPageCount();      $pager_total[0]       = $this->getPageCount();
559      $pager_page_array[0]  = max(0, min( (int) $pager_page_array[0], (int) $pager_total[0]) );      $pager_page_array[0]  = max(0, min( (int) $pager_page_array[0], (int) $pager_total[0]) );
560        $pager                = theme('pager', null, 1, 0);
561    
562    //  Drupal default pager is 0 based, we'll use 1 based for ours    //  Drupal default pager is 0 based, we'll use 1 based for ours
563      $regex  = '#(\?|\&)page=(.+?)(\"|&|/)#se';      if (variable_get('pagination_onebased', 1) ) {
564      $pager  = theme('pager', null, 1, 0);        $regex  = '#(\?|\&)page=(.+?)(\"|&|/)#se';
565      $pager  = preg_replace($regex, "'$1page='.($2 + 1).''.stripslashes('$3').''", $pager);        $pager  = preg_replace($regex, "'$1page='.($2 + 1).''.stripslashes('$3').''", $pager);
566        }
567      return $pager;      return $pager;
568    }    }
569    

Legend:
Removed from v.1.1.2.23  
changed lines
  Added in v.1.1.2.24

  ViewVC Help
Powered by ViewVC 1.1.2