[ Index ]

MailPress 544

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]     [ Statistics ]    

title

Body

[close]

/mp-includes/class/ -> MP_adminpage_list_.class.php (source)

   1  <?php
   2  abstract class MP_adminpage_list_ extends MP_adminpage_
   3  {
   4      const per_page = true;
   5  
   6  	function __construct()
   7      {
   8          parent::__construct();
   9  
  10          add_filter('set-screen-option',                      array('MP_AdminPage', 'set_screen_option'), 8, 3);
  11  
  12          add_filter('manage_' . MP_AdminPage::screen . '_columns',     array('MP_AdminPage', 'get_columns'));
  13      }
  14  
  15  //// Screen Options ////
  16  
  17  	public static function screen_meta() 
  18      {
  19          parent::screen_meta();
  20  
  21          if (MP_AdminPage::per_page)
  22          {
  23              global $title;
  24              add_screen_option( 'per_page', array('label' => $title, 'default' => 20) );
  25          }
  26      }
  27  
  28  	public static function set_screen_option($a, $b, $c)
  29      {
  30          return $c;
  31      }
  32  
  33  	public static function get_per_page($default = 20)
  34      {
  35          $option = MP_AdminPage::screen . '_per_page';
  36          $per_page = (int) get_user_option( $option );
  37          if ( empty( $per_page ) || $per_page < 1 )
  38              $per_page = $default;
  39  
  40          return (int) apply_filters( $option, $per_page );
  41      }
  42  
  43  //// Columns ////
  44  
  45  	public static function columns_list($id = true)
  46      {
  47          $columns = MP_AdminPage::get_columns();
  48          $hidden  = MP_AdminPage::get_hidden_columns();
  49          foreach ( $columns as $key => $display_name ) 
  50          {
  51              $thid  = ( $id ) ? " id='$key'" : '';
  52              $class = ( 'cb' === $key ) ? " class='check-column'" : " class='manage-column column-$key'";
  53              $style = ( in_array($key, $hidden) ) ? " style='display:none;'" : '';
  54  
  55              echo "<th$thid$class$style>$display_name</th>";
  56          } 
  57      }
  58  
  59  	public static function get_hidden_columns()
  60      {
  61          return get_hidden_columns(MP_AdminPage::screen);
  62      }
  63  
  64  //// List ////
  65  
  66  	public static function pagination( $args, $which = '' ) 
  67      {
  68          if (!is_array($args)) if (is_numeric($args)) $args = array('total_items' => $args); else return;
  69  
  70          $defaults = array (    'per_page'     => self::get_per_page(), 
  71                          'current'   => isset( $_REQUEST['paged'] ) ? max( 1, $_REQUEST['paged'] ) : 1,
  72                      );
  73          $r = wp_parse_args( $args, $defaults );
  74          extract( $r );
  75  
  76          if ( !isset($total_items) ) return;
  77          if ( !isset($total_pages) && $per_page > 0 ) $total_pages = ceil( $total_items / $per_page );
  78  
  79          $output = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
  80  
  81          $current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  82  
  83          $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
  84  
  85          $page_links = array();
  86  
  87          $disable_first = $disable_last = '';
  88          if ( $current == 1 ) $disable_first = ' disabled';
  89          if ( $current == $total_pages ) $disable_last = ' disabled';
  90  
  91          $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
  92              'first-page' . $disable_first,
  93              esc_attr__( 'Go to the first page' ),
  94              esc_url( remove_query_arg( 'paged', $current_url ) ),
  95              '&laquo;'
  96          );
  97  
  98          $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
  99              'prev-page' . $disable_first,
 100              esc_attr__( 'Go to the previous page' ),
 101              esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
 102              '&lsaquo;'
 103          );
 104  
 105          if ( 'bottom' == $which )
 106              $html_current_page = $current;
 107          else
 108              $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name='%s' value='%s' size='%d' />",
 109                  esc_attr__( 'Current page' ),
 110                  esc_attr( 'paged' ),
 111                  $current,
 112                  strlen( $total_pages )
 113              );
 114  
 115          $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
 116          $page_links[] = '<span class="paging-input">' . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . '</span>';
 117  
 118          $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
 119              'next-page' . $disable_last,
 120              esc_attr__( 'Go to the next page' ),
 121              esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
 122              '&rsaquo;'
 123          );
 124  
 125          $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>",
 126              'last-page' . $disable_last,
 127              esc_attr__( 'Go to the last page' ),
 128              esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
 129              '&raquo;'
 130          );
 131  
 132          $output .= "\n<span class='pagination-links'>" . join( "\n", $page_links ) . '</span>';
 133  
 134          if ( $total_pages )
 135              $page_class = $total_pages < 2 ? ' one-page' : '';
 136          else
 137              $page_class = ' no-pages';
 138  
 139          echo "<div class='tablenav-pages{$page_class}'>$output</div>\n";
 140      }
 141  
 142  	public static function get_search_clause($s, $sc = array())
 143      {
 144          $replaces = array("\\" => "\\\\\\\\", "_" => "\_", "%" => "\%", "'" => "\'",);
 145  
 146          foreach($replaces as $k => $v) $s = str_replace($k, $v, $s);
 147  
 148          foreach($sc as $k => $v) $sc[$k] = "$v LIKE '%$s%'";
 149  
 150          return ' AND (' . join(' OR ', $sc) . ') '; 
 151      }
 152  
 153  	public static function get_list($args) 
 154      {
 155          extract($args);
 156  
 157          global $wpdb;
 158  
 159          $start = abs( (int) $start );
 160          $_per_page = (int) $_per_page;
 161  
 162          $rows = $wpdb->get_results( "$query LIMIT $start, $_per_page" );
 163  
 164          self::update_cache($rows, $cache_name);
 165  
 166          $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
 167  
 168          return array($rows, $total);
 169      }
 170  
 171  	public static function get_bulk_actions($bulk_actions = array(), $name = 'action')
 172      {
 173          $bulk_actions = apply_filters('MailPress_bulk_actions_' . MP_AdminPage::screen, $bulk_actions);
 174          if (count($bulk_actions) <=1 ) return;
 175  ?>
 176                  <select name='<?php echo $name; ?>'>
 177  <?php
 178          foreach($bulk_actions as $k => $v) :
 179  ?>
 180                      <option <?php echo (!empty($k)) ? "value='bulk-$k'": "selected='selected' value='-1'"; ?>><?php echo $v; ?></option>
 181  <?php
 182          endforeach;
 183  ?>
 184                  </select>
 185                  <input type="submit" name="do<?php echo $name; ?>" id="do<?php echo $name; ?>" value="<?php esc_attr_e('Apply'); ?>" class="button-secondary apply" />
 186  <?php
 187      }
 188  
 189  //// Row ////
 190  
 191  	public static function get_actions($actions, $class = 'row-actions')
 192      {
 193          foreach ( $actions as $k => $v ) $actions[$k] = "<span class='$k'>$v";
 194          return "<div class='$class'>" . join( ' | </span>', $actions ) . '</span></div>';
 195      }
 196  
 197  	public static function human_time_diff($m_time)
 198      {
 199          $time   = strtotime( get_gmt_from_date( $m_time ) );
 200          $time_diff = current_time('timestamp', true) - $time;
 201  
 202          if ( $time_diff <= 0 )            return __('now', MP_TXTDOM);
 203          elseif ( $time_diff < 24*60*60 )    return sprintf( __('%s ago'), human_time_diff( $time ) );
 204          else                        return mysql2date(__('Y/m/d'), $m_time);
 205      }
 206  
 207  ////  ////
 208  
 209  	public static function update_cache($xs, $y) 
 210      {
 211          foreach ( (array) $xs as $x ) wp_cache_add($x->id, $x, $y);
 212      }
 213  }


Generated: Thu Apr 28 18:38:52 2016 Cross-referenced by PHPXref 0.7.1