[ Index ]

MailPress 7.1

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

title

Body

[close]

/mp-admin/ -> users.php (source)

   1  <?php 
   2  class MP_AdminPage extends MP_WP_Admin_page_list_
   3  {
   4      const screen        = MailPress_page_users;
   5      const capability    = 'MailPress_edit_users';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/';
   7      const file            = __FILE__;
   8  
   9  ////  Redirect  ////
  10  
  11  	public static function redirect() 
  12      {
  13          add_action( 'MailPress_users_restrict', array( __CLASS__, 'users_restrict' ), 1, 1 );
  14  
  15          $action = parent::redirect();
  16          if ( !$action ) return;
  17  
  18          $url_parms    = self::get_url_parms();
  19          $checked    = ( isset( self::$get_['checked'] ) ) ? self::$get_['checked'] : array();
  20  
  21          $count    = str_replace( 'bulk-', '', $action );
  22          $count    .= 'd';
  23          $$count    = 0;
  24  
  25          switch( $action )
  26          {
  27              case 'bulk-activate' :
  28                  foreach( $checked as $id )
  29                  {
  30                      if ( MP_User::set_status( $id, 'active' ) )
  31                      {
  32                          $$count++;
  33                      }
  34                  }
  35              break;
  36              case 'bulk-deactivate' :
  37                  foreach( $checked as $id )
  38                  {
  39                      if ( MP_User::set_status( $id, 'waiting' ) )
  40                      {
  41                          $$count++;
  42                      }
  43                  }
  44              break;
  45              case 'bulk-unbounce' :
  46                  foreach( $checked as $id ) { if ( MP_User::set_status( $id, 'waiting' ) )
  47                  {
  48                      MP_User_meta::delete( $id, '_MailPress_bounce_handling' );
  49                      $$count++;
  50                                  } }
  51              break;
  52              case 'bulk-delete' :
  53                  foreach( $checked as $id )
  54                  {
  55                      if ( MP_User::set_status( $id, 'delete' ) )
  56                      {
  57                          $$count++;
  58                      }
  59                  }
  60              break;
  61              default :
  62                  $$count = do_action( 'MailPress_do_bulk_action_' . self::screen, $action, $checked );
  63              break;
  64          }
  65          if ( $$count )
  66          {
  67              $url_parms[$count] = $$count;
  68          }
  69          self::mp_redirect( self::url( MailPress_users, $url_parms ) );
  70      }
  71  
  72  //// Help ////
  73  
  74  	public static function add_help_tab() 
  75      {
  76          global $current_screen;
  77  
  78          $content = '';
  79          $content .= '<p><strong>' . __( 'Users :', 'MailPress' ) . '</strong></p>';
  80          $content .= '<p>' . __( 'This screen provides access to all of your mp users. You can customize the display of this screen to suit your needs.', 'MailPress' ) . '</p>';
  81  
  82  
  83          $current_screen->add_help_tab( array(     'id'        => 'overview',
  84                                          'title'        => __( 'Overview' ),
  85                                          'content'    => $content )
  86          );
  87  
  88          $content = '';
  89          $content .= '<p>' . __( 'You can customize the display of this screen&#8217;s contents in a number of ways:', 'MailPress' ) . '</p>';
  90          $content .= '<ul>';
  91          $content .= '<li>' . __( 'You can hide/display columns based on your needs and decide how many mp users to list per screen using the Screen Options tab.', 'MailPress' ) . '</li>';
  92          $content .= '<li>' . __( 'You can filter the list of mp users by status using the text links above the mp users list to only show mp users with that status. The default view is to show all mp users.', 'MailPress' ) . '</li>';
  93          $content .= '<li>' . __( 'Depending on which add on you have activated, you may find new columns and/or new filters.', 'MailPress' ) . '</li>';
  94          $content .= '</ul>';
  95  
  96          $current_screen->add_help_tab( array(     'id'        => 'screen-display',
  97                                          'title'        => __( 'Screen Display' ),
  98                                          'content'    => $content )
  99          );
 100  
 101          $content = '';
 102          $content .= '<p>' . __( 'Hovering over a row in the mp users list will display action links that allow you to manage the mp user. You can perform the following actions depending on mp user status and when available:', 'MailPress' ) . '</p>';
 103          $content .= '<ul>';
 104          $content .= '<li>' . __( '<strong>Edit</strong> &mdash; takes you to the editing screen for that mp user. You can also reach that screen by clicking on the mp user&#8217;s mail.', 'MailPress' ) . '</li>';
 105          $content .= '<li>' . __( '<strong>Deactivate/Activate</strong> &mdash; deactivated mp user is expected to confirm his subscription. When being activated, mp user receives a confirmation mail.', 'MailPress' ) . '</li>';
 106          $content .= '<li>' . __( '<strong>Delete</strong> &mdash; removes your mp user from this list and delete it permanently.', 'MailPress' ) . '</li>';
 107          $content .= '<li>' . __( '<strong>Tracking</strong> &mdash; displays collected informations during the tracking. Resume all data collected for each mail received by the mp user. Available for any new sent mail after tracking add on activation.', 'MailPress' ) . '</li>';
 108          $content .= '<li>' . __( '<strong>Unbounce</strong> &mdash; when using one of the bounce add-on. Bounced mp user has been over the threshold set in add-on settings.', 'MailPress' ) . '</li>';
 109          $content .= '</ul>';
 110  
 111          $current_screen->add_help_tab( array(     'id'        => 'action-links',
 112                                          'title'    => __( 'Available Actions' ),
 113                                          'content'    => $content )
 114          );
 115  
 116          $content = '';
 117          $content .= '<p>' . __( 'You can also permanently delete multiple mp users at once. Select the mp users you want to act on using the checkboxes, then select the action you want to take from the Bulk Actions menu and click Apply.', 'MailPress' ) . '</p>';
 118  
 119          $current_screen->add_help_tab( array(     'id'        => 'bulk-actions',
 120                                          'title'    => __( 'Bulk Actions' ),
 121                                          'content'    => $content )
 122          );
 123      }
 124  
 125  ////  Styles  ////
 126  
 127  	public static function print_styles( $s ) 
 128      {
 129          $styles = ( is_array( $s ) ) ? $s : array();
 130  
 131          wp_register_style( self::screen,         '/' . MP_PATH . 'mp-admin/css/users.css' );
 132          $styles[] =self::screen;
 133  
 134          parent::print_styles( $styles );
 135      }
 136  
 137  	public static function print_styles_icons( $i = array( 'flag', 'icon', ) ) 
 138      {
 139          return parent::print_styles_icons( $i );
 140      }
 141  
 142  //// Scripts ////
 143  
 144  	public static function print_scripts( $scripts = array() ) 
 145      {
 146          wp_register_script( 'mp-ajax-response',     '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array( 'jquery' ), false, 1 );
 147          wp_localize_script( 'mp-ajax-response',     'wpAjax', array( 
 148              'noPerm' => __( 'Update database failed', 'MailPress' ), 
 149              'broken' => __( 'An unidentified error has occurred.' ), 
 150              'l10n_print_after' => 'try{convertEntities( wpAjax );}catch( e ){};' 
 151           ) );
 152  
 153          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array( 'mp-ajax-response' ), false, 1 );
 154  
 155          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/users.js', array( 'mp-lists' ), false, 1 );
 156          wp_localize_script( self::screen,     'MP_AdminPageL10n', array( 
 157              'pending' => __( '%i% pending' ), 
 158              'screen' => self::screen, 
 159              'l10n_print_after' => 'try{convertEntities( MP_AdminPageL10n );}catch( e ){};' 
 160           ) );
 161  
 162          $scripts[] = self::screen;
 163          parent::print_scripts( $scripts );
 164      }
 165  
 166  //// Columns ////
 167  
 168  	public static function get_columns() 
 169      {
 170          $disabled = ( !current_user_can( 'MailPress_delete_users' ) ) ? ' disabled="disabled"' : '';
 171  
 172          $columns = array(    'cb'        => '<input type="checkbox"' . $disabled .  '/>', 
 173                          'title'        => __( 'E-mail', 'MailPress' ), 
 174                          'user_name'    => __( 'Name', 'MailPress' ), 
 175                          'author'        => __( 'Author' ), 
 176                          'date'        => __( 'Date' )
 177          );
 178          $columns = apply_filters( 'MailPress_users_columns', $columns );
 179          return $columns;
 180      }
 181  
 182  //// List ////
 183  
 184  	public static function get_list( $args ) 
 185      {
 186          extract( $args );
 187  
 188          global $wpdb;
 189  
 190          $where = $tables = '';
 191          $order = "a.created";
 192  
 193          if ( isset( $url_parms['s'] ) )
 194          {
 195              $sc = array( 'a.email', 'a.name', 'a.laststatus_IP', 'a.created_IP' );
 196  
 197              $where .= self::get_search_clause( $url_parms['s'], $sc );
 198          }
 199  
 200          if ( isset( $url_parms['status'] ) && !empty( $url_parms['status'] ) )
 201          {
 202              $where .= " AND a.status = '" . $url_parms['status'] . "'";
 203          }
 204          if ( isset( $url_parms['author'] ) && !empty( $url_parms['author'] ) )
 205          {
 206              $where .= " AND ( a.created_user_id = " . $url_parms['author'] . "  OR a.laststatus_user_id = " . $url_parms['author'] . " ) ";
 207          }
 208  
 209          list( $where, $tables, $no_cls ) = apply_filters( 'MailPress_users_get_list', array( $where, $tables, false ), $url_parms );
 210  
 211          if ( isset( $url_parms['startwith'] ) )
 212          {
 213              $where .= " AND ( a.email >= '" . $url_parms['startwith'] . "' ) ";
 214              $order = "a.email";
 215              $no_cls = true;
 216          }
 217  
 218          $args['query'] = "SELECT DISTINCT SQL_CALC_FOUND_ROWS a.id, a.email, a.name, a.status, a.confkey, a.created, a.created_IP, a.created_agent, a.created_user_id, a.created_country, a.created_US_state, a.laststatus, a.laststatus_IP, a.laststatus_agent, a.laststatus_user_id FROM $wpdb->mp_users a $tables WHERE 1=1 $where ORDER BY $order";
 219          $args['cache_name'] = 'mp_user';
 220  
 221          list( $_users, $total ) = parent::get_list( $args );
 222  
 223          $counts = array();
 224          $query = "SELECT status, count( * ) as count FROM $wpdb->mp_users GROUP BY status;";
 225          $statuses = $wpdb->get_results( $query );
 226  
 227          $subsubsub_urls = false;
 228  
 229          $libs = array(    'all'            => __( 'All' ), 
 230                      'waiting'        => __( 'Waiting', 'MailPress' ),
 231                      'active'        => __( 'Active', 'MailPress' ),
 232                      'bounced'        => __( 'Bounced', 'MailPress' ),
 233                      'unsubscribed'    => __( 'Unsubscribed', 'MailPress' ),
 234                      'search'        => __( 'Search Results' )
 235          );
 236  
 237          if ( $statuses )
 238          {
 239              foreach( $statuses as $status )
 240              {
 241                  if ( $status->count )
 242                  {
 243                      $counts[$status->status] = $status->count;
 244                  }
 245              }
 246              $counts['all'] = $wpdb->get_var( "SELECT count( * ) FROM $wpdb->mp_users;" );
 247              if ( isset( $url_parms['s'] ) )
 248              {
 249                  $counts['search'] = count( $_users );
 250              }
 251              $out = array();
 252  
 253              foreach( $libs as $k => $lib )
 254              {
 255                  if ( !isset( $counts[$k] ) || !$counts[$k] )
 256                  {
 257                      continue;
 258                  }
 259  
 260                  $args = array();
 261                  if ( ( 'search' == $k ) && ( isset( $url_parms['s'] ) ) )      $args['s'] = $url_parms['s'];
 262                  elseif ( 'all' != $k )                         $args['status'] = $k;
 263                  $url    = esc_url( add_query_arg( $args, MailPress_users ) );
 264  
 265                  $cls = '';
 266                  if ( !$no_cls )
 267                  {
 268                      $cls = '';
 269                      if ( isset( $url_parms['s'] ) )
 270                      {
 271                          if ( 'search' == $k )
 272                          {
 273                              $cls = ' class="current"';
 274                          }
 275                      }
 276                      elseif ( isset( $url_parms['status'] ) )
 277                      {
 278                          if ( $url_parms['status'] == $k )
 279                          {
 280                              $cls = ' class="current"';
 281                          }
 282                      }
 283                      elseif ( 'all' == $k )
 284                      {
 285                          $cls = ' class="current"';
 286                      }
 287                  }
 288  
 289                  $out[] = sprintf( '<a%1$s href="%2$s">%3$s <span class="count">( <span class="user-count-%4$s">%5$s</span> )</span></a>', $cls, $url, $lib, $k, $counts[$k] );
 290              }
 291  
 292              if ( !empty( $out ) )
 293              {
 294                  $subsubsub_urls = '<li>' . join( ' | </li><li>', $out ) . '</li>';
 295              }
 296          }
 297  
 298          add_filter( 'MailPress_get_icon_users',     array( __CLASS__, 'get_icon_users' ), 8, 2 );
 299  
 300          return array( $_users, $total, $subsubsub_urls );
 301      }
 302  
 303  ////  Row  ////
 304  
 305  	public static function get_row( $id, $url_parms, $checkbox = true )
 306      {
 307          global $mp_user;
 308          static $row_class = '';
 309  
 310          $mp_user = $user = MP_User::get( $id );
 311          $the_user_status = $user->status;
 312  
 313  // url's
 314          $args            = array();
 315          $args['id']    = $id;
 316  
 317          $edit_url        = esc_url( self::url( MailPress_user, array_merge( $args, $url_parms ) ) );
 318  
 319          $args['action']    = 'activate';
 320          $activate_url    = esc_url( self::url( MailPress_user, array_merge( $args, $url_parms ), "activate-user_$id" ) );
 321  
 322          $args['action']    = 'deactivate';
 323          $deactivate_url    = esc_url( self::url( MailPress_user, array_merge( $args, $url_parms ), "deactivate-user_$id" ) );
 324  
 325          $args['action']    = 'delete';
 326          $delete_url    = esc_url( self::url( MailPress_user, array_merge( $args, $url_parms ), "delete-user_$id" ) );
 327  
 328          unset( $args['action'] );
 329  
 330  // actions
 331          $actions        = array();
 332          $actions['edit'] = '<a href="' . $edit_url . '"  title="' . esc_attr( sprintf( __( 'Edit &#8220;%1$s&#8221;', 'MailPress' ), $mp_user->email ) ) . '">' . __( 'Edit' ) . '</a>';
 333  
 334          $actions        = apply_filters( 'MailPress_users_actions', $actions, $mp_user, $url_parms );
 335  
 336          $actions['approve']   = '<a href="' . $activate_url    . '"     class="dim:the-user-list:user-' . $id . ':unapproved:e7e7d3:e7e7d3:">' . __( 'Activate', 'MailPress' )    . '</a>';
 337          $actions['unapprove'] = '<a href="' . $deactivate_url    . '"     class="dim:the-user-list:user-' . $id . ':unapproved:e7e7d3:e7e7d3:">' . __( 'Deactivate', 'MailPress' )    . '</a>';
 338  
 339          if ( 'bounced' == $user->status )
 340          {
 341              unset( $actions['approve'], $actions['unapprove'] );
 342              $args['action'] = 'unbounce';
 343              $unbounce_url = esc_url( self::url( MailPress_user, array_merge( $args, $url_parms ) ) );
 344              $onclick = "onclick=\"return (confirm('" . esc_js(sprintf( __("You are about to unbounce this MailPress user '%s'\n  'Cancel' to stop, 'OK' to unbounce.", 'MailPress' ), $mp_user->id )) . "'));\"";
 345              $actions['unbounce'] = '<a href="' . $unbounce_url . '" ' . $onclick . '>' . __( 'Unbounce', 'MailPress' ) . '</a>';
 346          }
 347  
 348          if ( 'unsubscribed' == $user->status )
 349          {
 350              unset( $actions['approve'] );
 351          }
 352  
 353          $actions['delete'] = '<a href="' . $delete_url . '" class="submitdelete">' . __( 'Delete', 'MailPress' ) . '</a>';
 354  
 355          if ( !current_user_can( 'MailPress_delete_users' ) )
 356          {
 357              unset( $actions['delete'] );
 358          }
 359  
 360  // table row 
 361  //    class
 362          $row_class = ( 'alternate' == substr( $row_class, 0, 9 ) ) ? '' : 'alternate ';
 363          switch ( $the_user_status )
 364          {
 365              case 'waiting' :
 366                  $row_class .= 'unapproved';
 367              break;
 368              case 'bounced' :
 369                  $row_class .= 'bounced';
 370              break;
 371              case 'unsubscribed' :
 372                  $row_class .= 'unsubscribed';
 373              break;
 374          }
 375  //     checkbox
 376          $disabled = ( !current_user_can( 'MailPress_delete_users' ) ) ? ' disabled="disabled"' : '';
 377  //     email
 378          $email_display = $user->email;
 379          if ( strlen( $email_display ) > 40 )
 380          {
 381              $email_display = substr( $email_display, 0, 39 ) . '...';
 382          }
 383  //    author
 384          $x            = ( isset( $url_parms['s'] ) ) ? $url_parms['s'] : '';
 385          $url_parms['s']    = self::get_user_author_IP();
 386          $ip_url        = esc_url( self::url( MailPress_users, $url_parms ) );
 387          $url_parms['s']    = $x;
 388  
 389          $author = ( 0 == $user->laststatus_user_id ) ? $user->created_user_id : $user->laststatus_user_id;
 390          if ( $author != 0 && is_numeric( $author ) )
 391          {
 392              unset( $url_parms['author'] );
 393              $wp_user = get_userdata( $author );
 394              $author_url = esc_url( self::url( MailPress_users, array_merge( array( 'author' => $author ), $url_parms ) ) );
 395          }
 396  
 397          $out = '';
 398          $out .= '<tr id="user-' . $id . '" class="' . $row_class . '">';
 399  
 400          $columns = self::get_columns();
 401          $hidden  = self::get_hidden_columns();
 402  
 403          foreach ( $columns as $column_name => $column_display_name ) 
 404          {
 405              $attributes = sprintf( 'class="%1$s column-%1$s%2$s%3$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '', ( in_array( $user->status, array('bounced', 'unsubscribed') ) ) ? ' fi' : '' );
 406  
 407               switch ( $column_name ) 
 408              {
 409                  case 'cb':
 410                      if ( $checkbox )
 411                      {
 412                          $out .= '<th class="check-column">';
 413                          $out .= ' <input type="checkbox" name="checked[]" value="' . $id . '"' . $disabled . ' />';
 414                          $out .= '</th>';
 415                      }
 416                  break;
 417                  case 'title' :
 418  
 419                      $attributes = sprintf( 'class="username column-username%2$s%3$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '', ( in_array( $user->status, array('bounced', 'unsubscribed') ) ) ? ' fi' : '' );
 420  
 421                      $out .= '<td ' . $attributes . '>';
 422                      $out .= self::get_flag_IP();
 423                      $out .= apply_filters( 'MailPress_get_icon_users', '', $mp_user ); 
 424                      $out .= ( get_option( 'show_avatars' ) ) ? get_avatar( $user->email, 32 ) : '';
 425                      $out .= '<strong>';
 426                      $out .= '<a class="row-title" href="' . $edit_url . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%1$s&#8221;', 'MailPress' ) ,$user->email ) ) . '">';
 427                      $out .= $email_display;
 428                      $out .= '</a>';
 429                      $out .= '</strong>';
 430                      $out .= self::get_actions( $actions );
 431                      $out .= '</td>';
 432                  break;
 433                  case 'user_name' :
 434                      $out .= '<td ' . $attributes . '>';
 435                      $out .= '<abbr title="' . esc_attr( $user->name ) . '">' . esc_attr( $user->name ) . '</abbr>';
 436                      $out .= '</td>';
 437                  break;
 438                  case 'date' :
 439                      $t_time = self::get_user_date( __( 'Y/m/d H:i:s' ) );
 440                      $h_time = self::human_time_diff( self::get_user_date_raw() );
 441  
 442                      $out .= '<td ' . $attributes . '>';
 443                      $out .= '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
 444                      $out .= '</td>';
 445                  break;
 446                  case 'author' :
 447                      $out .= '<td ' . $attributes . '>';
 448                      if ( $author != 0 && is_numeric( $author ) )
 449                      {
 450                          $out .= '<a href="' . $author_url . '" title="' . esc_attr( sprintf( __( 'Users by &#8220;%1$s&#8221;', 'MailPress' ), $wp_user->display_name ) ) . '">' . $wp_user->display_name . '</a>';
 451                      }
 452                      else
 453                      {
 454                          $out .= __( '(unknown)', 'MailPress' );
 455                      }
 456                      $out .= '</td>';
 457                  break;
 458                  default:
 459                      $out .= '<td ' . $attributes . '>';
 460                      $out .= apply_filters( 'MailPress_users_get_row', '', $column_name, $user, $url_parms );
 461                      $out .= '</td>';
 462                  break;
 463              }
 464          }
 465          $out .= '</tr>';
 466  
 467          return $out;
 468      }
 469  
 470  	public static function get_user_date( $d = '' )
 471      {
 472          $x = self::get_user_date_raw();
 473          return ( '' == $d ) ? mysql2date( get_option( 'date_format' ), $x ) : mysql2date( $d, $x );
 474      }
 475  
 476  	public static function get_user_date_raw()
 477      {
 478          global $mp_user;
 479          return ( $mp_user->created >= $mp_user->laststatus ) ? $mp_user->created : $mp_user->laststatus;
 480      }
 481  
 482  	public static function get_user_author_IP()
 483      {
 484          global $mp_user;
 485          $ip = ( '' == $mp_user->laststatus_IP ) ? $mp_user->created_IP : $mp_user->laststatus_IP;
 486          return $ip;
 487      }
 488  
 489  	public static function get_flag_IP()
 490      {
 491          global $mp_user;
 492          return ( ( 'ZZ' == $mp_user->created_country ) || empty( $mp_user->created_country ) ) ? '' : '<div class="mp_flag mp_flag_' . strtolower( $mp_user->created_country ) . '" title="' . esc_attr( strtolower( $mp_user->created_country ) ) . '"></div>';
 493      }
 494  
 495  	public static function get_icon_users( $out, $mp_user )
 496      {
 497          if ( 'unsubscribed' == $mp_user->status )
 498          {
 499              $out .= '<span class="mp_icon mp_icon_unsubscribed" title="' . esc_attr( __( 'Unsubscribed', 'MailPress' ) ) . '"></span>';
 500          }
 501          return $out;
 502      }
 503  
 504  //// Body ////
 505  
 506  	public static function users_restrict( $url_parms )
 507      {
 508          global $wpdb;
 509          $list = array();
 510  
 511          $query = "SELECT DISTINCT UPPER( SUBSTRING( email, 1, 1 ) ) as letter FROM $wpdb->mp_users ORDER BY 1;";
 512          $letters = $wpdb->get_results( $query );
 513  
 514          if ( $letters )
 515          {
 516              $list[-1] = __( 'Starting with...', 'MailPress' );
 517          }
 518          foreach ( $letters as $letter )
 519          {
 520              $list[$letter->letter] = $letter->letter;
 521          }
 522  
 523          $selected = ( isset( $url_parms['startwith'] ) ) ? $url_parms['startwith'] : -1;
 524  
 525          echo '<select name="startwith" id="letters_dropdown" class="postform">';
 526          self::select_option( $list, $selected );
 527          echo '</select>';
 528      }
 529  }


Generated: Mon Mar 11 18:33:33 2019 Cross-referenced by PHPXref 0.7.1