[ Index ]

MailPress 7.2

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

title

Body

[close]

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

   1  <?php
   2  abstract class MP_WP_Admin_page_list_ extends MP_WP_Admin_page_
   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 admin_head() 
  18      {
  19          parent::admin_head();
  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 get_columns() 
  46      {
  47          return false;
  48      }
  49  
  50  	public static function columns_list( $id = true )
  51      {
  52          $columns = MP_AdminPage::get_columns();
  53          $hidden  = MP_AdminPage::get_hidden_columns();
  54          foreach ( $columns as $key => $display_name ) 
  55          {
  56              $tag  = ( 'cb' === $key ) ? 'td' : 'th';
  57              $thid = ( $id ) ? ' id="' . $key . '"' : '';
  58  
  59              $classes = 'manage-column column-' . $key;
  60              $classes .= ( 'cb' === $key ) ? ' check-column' : '';
  61              $classes .= ( 'title' === $key ) ? ' column-primary' : '';
  62              $classes .= ( in_array( $key, $hidden ) ) ? ' hidden' : '';
  63  
  64              $class = ' class="' . $classes . '"';
  65  
  66              $attributes = '';
  67              $attributes .= ( 'title' === $key ) ? ' scope="col"' : '';
  68  
  69              echo '<' . $tag . $thid . $class . $attributes . '>' . $display_name . '</' . $tag . '>';
  70          } 
  71      }
  72  
  73  	public static function get_hidden_columns()
  74      {
  75          return get_hidden_columns( MP_AdminPage::screen );
  76      }
  77  
  78  //// List ////
  79  
  80  	public static function pagination( $args, $which = '' ) 
  81      {
  82          if ( !is_array( $args ) ) if ( is_numeric( $args ) ) $args = array( 'total_items' => $args ); else return;
  83  
  84          $defaults = array (     'per_page'    => self::get_per_page(), 
  85                          'current'    => isset( self::$req_['paged'] ) ? max( 1, self::$req_['paged'] ) : 1,
  86                       );
  87          $r = wp_parse_args( $args, $defaults );
  88          extract( $r );
  89  
  90          if ( !isset( $total_items ) ) return;
  91          if ( !isset( $total_pages ) && $per_page > 0 ) $total_pages = ceil( $total_items / $per_page );
  92  
  93          $out = '<span class="displaying-num">' . sprintf( _n( '1 item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
  94  
  95          $HTTP_HOST        = filter_input( INPUT_SERVER, 'HTTP_HOST' );
  96          $REQUEST_URI    = filter_input( INPUT_SERVER, 'REQUEST_URI' );
  97  
  98          $current_url = set_url_scheme( 'http://' . $HTTP_HOST     . $REQUEST_URI );
  99  
 100          $current_url = remove_query_arg( wp_removable_query_args(), $current_url );
 101  
 102          $page_links = array();
 103  
 104          $total_pages_before = '<span class="paging-input">';
 105          $total_pages_after  = '</span></span>';
 106  
 107          $disable_first = $disable_last = $disable_prev = $disable_next = false;
 108  
 109          if ( $current == 1 ) {
 110              $disable_first = true;
 111              $disable_prev  = true;
 112          }
 113          if ( $current == 2 ) {
 114              $disable_first = true;
 115          }
 116          if ( $current == $total_pages ) {
 117              $disable_last = true;
 118              $disable_next = true;
 119          }
 120          if ( $current == $total_pages - 1 ) {
 121              $disable_last = true;
 122          }
 123  
 124          if ( $disable_first ) {
 125              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&laquo;</span>';
 126          } else {
 127              $page_links[] = sprintf(
 128                  '<a class="first-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
 129                  esc_url( remove_query_arg( 'paged', $current_url ) ),
 130                  __( 'First page' ),
 131                  '&laquo;'
 132              );
 133          }
 134  
 135          if ( $disable_prev ) {
 136              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&lsaquo;</span>';
 137          } else {
 138              $page_links[] = sprintf(
 139                  '<a class="prev-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
 140                  esc_url( add_query_arg( 'paged', max( 1, $current - 1 ), $current_url ) ),
 141                  __( 'Previous page' ),
 142                  '&lsaquo;'
 143              );
 144          }
 145  
 146          if ( 'bottom' === $which ) {
 147              $html_current_page  = $current;
 148              $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">';
 149          } else {
 150              $html_current_page = sprintf(
 151                  '%s<input class="current-page" id="current-page-selector" type="text" name="paged" value="%s" size="%d" aria-describedby="table-paging" /><span class="tablenav-paging-text">',
 152                  '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
 153                  $current,
 154                  strlen( $total_pages )
 155              );
 156          }
 157          $html_total_pages = sprintf( '<span class="total-pages">%s</span>', number_format_i18n( $total_pages ) );
 158          $page_links[]     = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
 159  
 160          if ( $disable_next ) {
 161              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&rsaquo;</span>';
 162          } else {
 163              $page_links[] = sprintf(
 164                  '<a class="next-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
 165                  esc_url( add_query_arg( 'paged', min( $total_pages, $current + 1 ), $current_url ) ),
 166                  __( 'Next page' ),
 167                  '&rsaquo;'
 168              );
 169          }
 170  
 171          if ( $disable_last ) {
 172              $page_links[] = '<span class="tablenav-pages-navspan button disabled" aria-hidden="true">&raquo;</span>';
 173          } else {
 174              $page_links[] = sprintf(
 175                  '<a class="last-page button" href="%s"><span class="screen-reader-text">%s</span><span aria-hidden="true">%s</span></a>',
 176                  esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
 177                  __( 'Last page' ),
 178                  '&raquo;'
 179              );
 180          }
 181  
 182          $pagination_links_class = 'pagination-links';
 183          $out .= "\n" . '<span class="$pagination_links_class">' . join( "\n", $page_links ) . '</span>';
 184  
 185          if ( $total_pages )
 186              $page_class = $total_pages < 2 ? ' one-page' : '';
 187          else
 188              $page_class = ' no-pages';
 189  
 190          $out = '<div class="tablenav-pages' . $page_class . '">' . $out . '</div>';
 191  
 192          echo $out;
 193      }
 194  
 195  	public static function get_search_clause( $s, $sc = array() )
 196      {
 197          $replaces = array( "\\" => "\\\\\\\\", "_" => "\_", "%" => "\%", "'" => "\'", );
 198  
 199          foreach( $replaces as $k => $v ) $s = str_replace( $k, $v, $s );
 200  
 201          foreach( $sc as $k => $v ) $sc[$k] = "$v LIKE '%$s%'";
 202  
 203          return ' AND ( ' . join( ' OR ', $sc ) . ' ) '; 
 204      }
 205  
 206  	public static function get_list( $args ) 
 207      {
 208          extract( $args );
 209  
 210          global $wpdb;
 211  
 212          $start = abs( ( int ) $start );
 213          $_per_page = ( int ) $_per_page;
 214  
 215          $rows = $wpdb->get_results( "$query LIMIT $start, $_per_page" );
 216  
 217          self::update_cache( $rows, $cache_name );
 218  
 219          $total = $wpdb->get_var( "SELECT FOUND_ROWS()" );
 220  
 221          return array( $rows, $total );
 222      }
 223  
 224  	public static function get_bulk_actions( $bulk_actions = array(), $name = 'action' )
 225      {
 226          $bulk_actions = apply_filters( 'MailPress_bulk_actions_' . MP_AdminPage::screen, $bulk_actions );
 227          if ( count( $bulk_actions ) <= 1 ) return;
 228  
 229          $out = '';
 230          $out .= '<select name="' . $name . '">';
 231  
 232          foreach( $bulk_actions as $k => $v )
 233          {
 234              $out .= '<option ' . ( ( !empty( $k ) ) ? 'value="bulk-' . $k . '"' : 'selected="selected" value="-1"' ) . '>' . $v . '</option>';
 235  
 236          }
 237  
 238          $out .= '</select>' . "\r\n";
 239          $out .= '<input type="submit" name="do' . $name . '" id="do' . $name . '" class="button-secondary apply" value="' . esc_attr( __( 'Apply' ) ) . '" />' ; "\r\n";
 240  
 241          echo $out;
 242      }
 243  
 244  //// Row ////
 245  
 246  	public static function get_actions( $actions, $class = 'row-actions' )
 247      {
 248          foreach ( $actions as $k => $v ) $actions[$k] = '<span class="' . $k . '">' . $v;
 249          return '<div class="' . $class . '">' . join( ' | </span>', $actions ) . '</span></div>';
 250      }
 251  
 252  	public static function human_time_diff( $m_time )
 253      {
 254          $time   = strtotime( get_gmt_from_date( $m_time ) );
 255          $time_diff = current_time( 'timestamp', true ) - $time;
 256  
 257          if ( $time_diff <= 0 )            return __( 'now', 'MailPress' );
 258          elseif ( $time_diff < 24*60*60 )    return sprintf( __( '%s ago' ), human_time_diff( $time ) );
 259          else                        return mysql2date( __( 'Y/m/d' ), $m_time );
 260      }
 261  
 262  ////  ////
 263  
 264  	public static function update_cache( $xs, $y ) 
 265      {
 266          foreach ( ( array ) $xs as $x ) wp_cache_add( $x->id, $x, $y );
 267      }
 268  }


Generated: Tue May 19 15:55:14 2020 Cross-referenced by PHPXref 0.7.1