[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_
   3  {
   4      const screen        = 'mailpress_user';
   5      const capability    = 'MailPress_edit_users';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/';
   7      const file            = __FILE__;
   8  
   9      const map_of        = 'mp_user';
  10  
  11  ////  Redirect  ////
  12  
  13  	public static function redirect() 
  14      {
  15          $action = parent::redirect();
  16          if ( !$action ) return;
  17  
  18          if ( isset( self::$get_['id'] ) )
  19          {
  20              $id = self::$get_['id'];
  21          }
  22  
  23          $list_url = self::url( MailPress_users, self::get_url_parms() );
  24  
  25          switch( $action ) 
  26          {
  27              case 'activate' :
  28                  if ( MP_User::set_status( $id, 'active' ) )
  29                  {
  30                      $list_url .= '&activated=1';
  31                  }
  32                  self::mp_redirect( $list_url );
  33              break;
  34              case 'deactivate' :
  35                  if ( MP_User::set_status( $id, 'waiting' ) )
  36                  {
  37                      $list_url .= '&deactivated=1';
  38                  }
  39                  self::mp_redirect( $list_url );
  40              break;
  41              case 'unbounce' :
  42                  if ( MP_User::set_status( $id, 'waiting' ) )
  43                  {
  44                      MP_User_meta::delete( $id, '_MailPress_bounce_handling' );
  45                      $list_url .= '&unbounced=1';
  46                  }
  47                  self::mp_redirect( $list_url );
  48              break;
  49              case 'delete' :
  50                  if ( MP_User::set_status( $id, 'delete' ) )
  51                  {
  52                      $list_url .= '&deleted=1';
  53                  }
  54                  self::mp_redirect( $list_url );
  55              break;
  56  
  57              case 'save' :
  58                  $id = ( int ) self::$pst_['id'];
  59  
  60                  if ( self::$pst_['mp_user_name'] != self::$pst_['mp_user_old_name'] )
  61                  {
  62                      MP_User::update_name( $id, self::$pst_['mp_user_name'] );
  63                  }
  64  
  65                  switch ( true )
  66                  {
  67                      case isset( self::$pst_['addmeta'] ) :
  68                          MP_User_meta::add_meta( $id );
  69                      break;
  70                      case isset( self::$pst_['usermeta'] ) :
  71                          foreach ( self::$pst_['usermeta'] as $meta_id => $meta )
  72                          {
  73                              $meta_key = $meta['key'];
  74                              $meta_value = $meta['value'];
  75                              MP_User_meta::update_by_id( $meta_id , $meta_key, $meta_value );
  76                          }
  77                      break;
  78                      case isset( self::$pst_['deletemeta'] ) :
  79                          foreach ( self::$pst_['deletemeta'] as $meta_id => $x )
  80                          {
  81                              MP_User_meta::delete_by_id( $meta_id );
  82                          }
  83                      break;
  84                  }
  85  
  86                  // what else ?
  87                  do_action( 'MailPress_update_meta_boxes_user' );
  88  
  89                  $parm = "&saved=1";
  90  
  91                  $url = MailPress_user;
  92                  $url .= "$parm&id=$id";
  93                  self::mp_redirect( $url );
  94              break;
  95          } 
  96      }
  97  
  98  ////  Title  ////
  99  
 100  	public static function title()
 101      {
 102          global $title;
 103          $title = __( 'MailPress User', 'MailPress' );
 104      }
 105  
 106  //// Help ////
 107  
 108  	public static function add_help_tab() 
 109      {
 110          global $current_screen;
 111  
 112          $content = '';
 113          $content .= '<p><strong>' . __( 'User :', 'MailPress' ) . '</strong></p>';
 114          $content .= '<p>' . __( 'You can modify information on each mp user:', 'MailPress' ) . '</p>';
 115          $content .= '<ul>';
 116          $content .= '<li>' . __( '<strong>Name</strong> &mdash; only name can be modified, email being the unique key., MailPress' ) . '</li>';
 117          $content .= '<li>' . __( '<strong>Other tabs</strong> &mdash; check other help tabs for more information.', 'MailPress' ) . '</li>';
 118          $content .= '</ul>';
 119  
 120          $current_screen->add_help_tab( array(     'id'        => 'overview',
 121                                          'title'    => __( 'Overview' ),
 122                                          'content'    => $content )
 123          );
 124  
 125                  $content = '';
 126                  $content .= '<p>' . __( '<strong>Custom Fields</strong> &mdash; is only used for text replacement in mails.', 'MailPress' ) . '</p>';
 127                  $content .= '<p>' . __( 'Let us say you want to manage honorific (e.g. : Mr, Miss, Sir ...) for all mp users. Create a custom field with name "honorific" and the appropriate value for each mp user. When creating a new Mail, you can write to a set of mp users starting your mail with the following "Dear {{honorific}}" (double opening and closing curly brackets inspired by <code>{{mustache}}</code> ). At the mail level, you can also create a default custom field "honorific" that will be the value if it was missing at the mp user level.', 'MailPress' ) . '</p>';
 128                  $content .= '<p>' . __( 'Custom fields can also be populated when importing mp users (import add-on).', 'MailPress' ) . '</p>';
 129                  $current_screen->add_help_tab( array(     'id'        => 'customfields',
 130                                          'title'    => __( 'Custom Fields', 'MailPress' ),
 131                                          'content'    => $content )
 132          );
 133                  
 134                  do_action( 'MailPress_add_help_tab_user' );
 135      }
 136  
 137  ////  Styles  ////
 138  
 139  	public static function print_styles( $s ) 
 140      {
 141          $styles = ( is_array( $s ) ) ? $s : array();
 142  
 143          $styles[] = MP_Map::print_styles();
 144  
 145          wp_register_style( self::screen,    '/' . MP_PATH . 'mp-admin/css/user.css', array( 'thickbox' ) );
 146          $styles[] = self::screen;
 147  
 148          parent::print_styles( $styles );
 149      }
 150  
 151  	public static function print_styles_icons( $i = array( 'flag', ) ) 
 152      {
 153          return parent::print_styles_icons( $i );
 154      }
 155  
 156  ////  Scripts  ////
 157  
 158  	public static function print_scripts( $scripts = array() ) 
 159      {
 160          global $mp_general;
 161  
 162          $deps[] = MP_Map::print_scripts();
 163  
 164          wp_register_script( 'mp-ajax-response',     '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array( 'jquery' ), false, 1 );
 165          wp_localize_script( 'mp-ajax-response',     'wpAjax', array(     
 166              'noPerm' => __( 'Update database failed', 'MailPress' ), 
 167              'broken' => __( 'An unidentified error has occurred.' ), 
 168              'l10n_print_after' => 'try{convertEntities( wpAjax );}catch( e ){};' 
 169           ) );
 170  
 171          $deps[] = 'jquery-ui-tabs';
 172  
 173          wp_register_script( 'mp_customfields',    '/' . MP_PATH . 'mp-includes/js/mp_customfields.js',false, false, 1 );
 174          wp_localize_script( 'mp_customfields',     'MP_CustomFieldsL10n',  array( 
 175              'object_id' => 'mp_user_id',
 176           ) );
 177  
 178          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array( 'mp-ajax-response', 'mp_customfields' ), false, 1 );
 179  
 180          $deps[] = 'mp-lists';
 181          $deps[] = 'postbox';
 182  
 183          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array( 'thickbox' ), false, 1 );
 184          $deps[] = 'mp-thickbox';
 185  
 186          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/user.js', $deps, false, 1 );
 187          wp_localize_script( self::screen,         'MP_AdminPageL10n',  array( 
 188              'screen' => self::screen,
 189           ) );
 190  
 191          $scripts[] = self::screen;
 192          parent::print_scripts( $scripts );
 193      }
 194  
 195  ////  Metaboxes  ////
 196  
 197  	public static function admin_head() 
 198      {
 199          global $mp_general;
 200  
 201          $id = ( isset( self::$get_['id'] ) ) ? self::$get_['id'] : 0;
 202          add_meta_box( 'submitdiv',    __( 'Save', 'MailPress' ),     array( __CLASS__, 'meta_box_submit' ),     self::screen, 'side', 'core' );
 203  
 204          add_meta_box( 'IP_info',     __( 'IP info', 'MailPress' ),     array( __CLASS__, 'meta_box_IP_info' ),     self::screen, 'side', 'core' );
 205  
 206          if ( current_user_can( 'MailPress_user_custom_fields' ) )
 207          {
 208              add_meta_box( 'customfieldsdiv',     __( 'Custom Fields' ),     array( __CLASS__, 'meta_box_customfields' ), self::screen, 'normal', 'core' );
 209          }
 210          else
 211          {
 212              if ( $id )
 213              {
 214                  $metas = MP_User_meta::get( $id );
 215                  if ( $metas ) 
 216                  {
 217                      if ( !is_array( $metas ) )
 218                      {
 219                          $metas = array( $metas );
 220                      }
 221                      foreach ( $metas as $meta )
 222                      {
 223                          if ( $meta->meta_key[0] == '_' )
 224                          {
 225                              continue;
 226                          }
 227                          add_meta_box( 'customfieldsdiv',     __( 'Custom Fields' ),     array( __CLASS__, 'meta_box_browse_customfields' ), self::screen, 'normal', 'core' );
 228                          break;
 229                      }
 230                  }
 231              }
 232          }
 233  
 234          do_action( 'MailPress_add_meta_boxes_user', $id, self::screen );
 235  
 236          parent::admin_head();
 237      }
 238  /**/
 239  	public static function meta_box_submit( $mp_user ) 
 240      {
 241          $url_parms     = self::get_url_parms();
 242  
 243          $args            = array();
 244          $args['id']    = $mp_user->id;
 245  
 246  // url's
 247          if ( class_exists( 'MailPress_tracking' ) )
 248          {
 249              $tracking_url   = esc_url( self::url( MailPress_tracking_u, $args ) );
 250          }
 251  
 252          if ( current_user_can( 'MailPress_delete_users' ) )
 253          {
 254              $args['action']    = 'delete';
 255              $delete_url    = esc_url( self::url( MailPress_user, array_merge( $args, $url_parms ), "delete-user_{$mp_user->id}" ) );
 256          }
 257  
 258          if ( 'bounced' == $mp_user->status )
 259          {
 260              $args['action'] = 'unbounce';
 261              $unbounce_url = esc_url( self::url( MailPress_user, array_merge( $args, $url_parms ) ) );
 262          }
 263  
 264  // actions
 265          $actions        = array();
 266  
 267          if ( isset( $tracking_url ) )
 268          {
 269              $actions['tracking'] = '<a class="button preview" href="' . $tracking_url . '">' . __( 'Tracking', 'MailPress' ) . '</a>';
 270          }
 271  
 272          if ( isset( $delete_url ) )
 273          {
 274              $onclick = "onclick=\"return (confirm('" . esc_js(sprintf( __("You are about to delete this MailPress user '%s'\n  'Cancel' to stop, 'OK' to unbounce.", 'MailPress' ), $mp_user->id )) . "') );\"";
 275              $actions['delete'] = '<a class="submitdelete" href="' . $delete_url . '" ' . $onclick . '>' . __( 'Delete', 'MailPress' ) . '</a>';
 276          }
 277  
 278          if ( isset( $unbounce_url ) )
 279          {
 280              $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 )) . "') );\"";
 281              $actions['unbounce'] = '<a href="' . $unbounce_url . '" ' . $onclick . '>' . __( 'Unbounce', 'MailPress' ) . '</a>';
 282          }
 283  
 284          $out  = '<div class="submitbox" id="submitpost">' . "\r\n";
 285          $out .= '    <div id="minor-publishing">' . "\r\n";
 286          $out .= '        <div id="minor-publishing-actions">' . "\r\n";
 287          $out .= '               <span id="unbounce">';
 288          if ( isset( $actions['unbounce'] ) ) $out .= $actions['unbounce'];
 289          $out .= '</span>' . "\r\n";
 290          $out .= '               <span id="tracking">';
 291          if ( isset( $actions['tracking'] ) ) $out .= $actions['tracking'];
 292          $out .= '</span>' . "\r\n";
 293          $out .= '        </div>' . "\r\n";
 294          $out .= '        <div class="clear"><br /><br /><br /><br /><br /></div>' . "\r\n";
 295          $out .= '    </div>' . "\r\n";
 296          $out .= '    <div id="major-publishing-actions">' . "\r\n";
 297          $out .= '        <div id="delete-action">' . "\r\n";
 298          if ( isset( $actions['delete'] ) ) $out .= $actions['delete'] . "\r\n";
 299          $out .= '        </div>' . "\r\n";
 300          $out .= '        <div id="publishing-action">' . "\r\n";
 301          $out .= '            <input type="submit" name="save" id="publish" class="button-primary" value="' . esc_attr( __( 'Save', 'MailPress' ) ) . '" />' . "\r\n";
 302          $out .= '        </div>' . "\r\n";
 303          $out .= '        <div class="clear"></div>' . "\r\n";
 304          $out .= '    </div>' . "\r\n";
 305          $out .= '</div>' . "\r\n";
 306  
 307          echo $out;
 308      }
 309  /**/
 310  	public static function meta_box_IP_info( $mp_user )
 311      {
 312          $t = array();
 313          $t['meta_box_IP_info']['settings'] = null;
 314  
 315      // meta_box_IP_info
 316          $y = false;
 317          $ip = ( '' == $mp_user->laststatus_IP ) ? $mp_user->created_IP : $mp_user->laststatus_IP;
 318          $y  = MP_Ip::get_all( $ip );
 319  
 320      // meta_box_IP_info settings
 321          $t['meta_box_IP_info']['settings'] = MP_User_meta::get( $mp_user->id, '_MailPress_meta_box_IP_info' );
 322          if ( !$t['meta_box_IP_info']['settings'] ) $t['meta_box_IP_info']['settings'] = get_user_option( '_MailPress_meta_box_IP_info' );
 323          $def_lat = ( isset( $y['geo']['lat'] ) )? $y['geo']['lat'] : 48.8352;
 324          $def_lng = ( isset( $y['geo']['lng'] ) )? $y['geo']['lng'] : 2.4718;
 325          if ( !$t['meta_box_IP_info']['settings'] ) $t['meta_box_IP_info']['settings'] = array( 'center_lat' => $def_lat, 'center_lng' => $def_lng, 'zoomlevel' => 3, 'maptype' => 'NORMAL' );
 326          $t['meta_box_IP_info']['settings']['prefix'] = 'meta_box_IP_info';
 327          $t['meta_box_IP_info']['settings']['count'] = 1;
 328  
 329      // meta_box_IP_info markers
 330          if ( isset( $y['geo'] ) )
 331          {
 332              $x = $y['geo'];
 333              $x['ip'] = $ip;
 334              if ( isset( $y['html'] ) )     $x['info']  = str_replace( '"', '&quote;', $y['html'] );
 335              if ( isset( $y['provider'] ) ) $x['info'] .= str_replace( '"', '&quote;', '<div><p style=\'margin:3px;\'><i><small>' . sprintf( __( 'ip data provided by %1$s', 'MailPress' ), $y['provider']['credit'] ) . '</small></i></p></div>' );
 336              $t['meta_box_IP_info']['markers'][] = $x;
 337          }
 338  
 339          $out = '';
 340  
 341          $out .= '<script type="text/javascript">' . "\r\n";
 342          $out .= '/* <![CDATA[ */' . "\r\n";
 343          foreach ( $t as $var => $val )
 344          {
 345              $out .= 'var ' . $var . ' = ' . MP_AdminPage::print_scripts_l10n_val( $val );
 346          }
 347          $out .= ';' . "\r\n";
 348          $out .= '/* ]]> */' . "\r\n";
 349          $out .= '</script>' . "\r\n";
 350  
 351          $out .= '<div id="meta_box_IP_info_map" style="overflow:hidden;height:400px;width:auto;padding:0;margin:0;"></div>';
 352  
 353          foreach( $t['meta_box_IP_info']['settings'] as $k => $v ) 
 354          {
 355                  if ( 'prefix' == $k ) continue;
 356              $out .= '        <input type="hidden" id="meta_box_IP_info_' . $k . '" value="' . esc_attr( $v ) . '" />' . "\r\n";
 357          }
 358  
 359          echo $out;
 360  
 361          if ( isset( $x['html'] ) )
 362          {
 363              echo $x['html'];
 364          }
 365          if ( isset( $x['provider'] ) )
 366          {
 367              printf( '<div><p class="ipm3"><i><small>' . '%1$s' . '</small></i></p></div>', sprintf( __( 'ip data provided by %1$s', 'MailPress' ), sprintf( '<a href="%1$s" target="_blank">%2$s</a>', $x['provider']['credit'], $x['provider']['credit'] ) ) );
 368          }
 369      }
 370  /**/
 371  	public static function meta_box_browse_customfields( $mp_user )
 372      {
 373          MP_User_customfields::meta_box_browse_customfields( $mp_user );
 374      }
 375  
 376  	public static function meta_box_customfields( $mp_user )
 377      {
 378          MP_User_customfields::meta_box_customfields( $mp_user );
 379      }
 380  }


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