[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_list_
   3  {
   4      const screen        = MailPress_page_autoresponders;
   5      const capability    = 'MailPress_manage_autoresponders';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/add-ons/autoresponder/';
   7      const file            = __FILE__;
   8  
   9      const taxonomy        = MailPress_autoresponder::taxonomy;
  10  
  11      const add_form_id    = 'add';
  12      const list_id        = 'the-list';
  13      const tr_prefix_id    = 'atrspndr';
  14  
  15  ////  Redirect  ////
  16  
  17  	public static function redirect() 
  18      {
  19          $action = parent::redirect();
  20          if ( !$action ) return;
  21  
  22          $url_parms    = self::get_url_parms( array( 's', 'paged', 'id' ) );
  23          $checked    = ( isset( self::$get_['checked'] ) ) ? self::$get_['checked'] : array();
  24  
  25          $count    = str_replace( 'bulk-', '', $action );
  26          $count    .= 'd';
  27          $$count    = 0;
  28  
  29          switch( $action ) 
  30          {
  31              case 'bulk-delete' :
  32                  foreach( $checked as $id )
  33                  {
  34                      if ( MP_Autoresponder::delete( $id ) )
  35                      {
  36                          $$count++;
  37                      }
  38                  }
  39  
  40                  if ( $$count )
  41                  {
  42                      $url_parms[$count] = $$count;
  43                  }
  44  
  45                  $url_parms['message'] = ( $$count <= 1 ) ? 3 : 4;
  46                  self::mp_redirect( self::url( MailPress_autoresponders, $url_parms ) );
  47              break;
  48  
  49              case 'add':
  50                  $e = MP_Autoresponder::insert( self::$pst_ );
  51                  $url_parms['message'] = ( $e && !is_wp_error( $e ) ) ? 1 : 91;
  52                  unset( $url_parms['s'] );
  53                  self::mp_redirect( self::url( MailPress_autoresponders, $url_parms ) );
  54              break;
  55              case 'edited':
  56                  unset( self::$get_['action'] );
  57                  if ( !isset( self::$pst_['cancel'] ) ) 
  58                  {
  59                      $e = MP_Autoresponder::insert( self::$pst_ );
  60                      $url_parms['message'] = ( $e && !is_wp_error( $e ) ) ? 2 : 92 ;
  61                  }
  62                  unset( $url_parms['id'] );
  63                  self::mp_redirect( self::url( MailPress_autoresponders, $url_parms ) );
  64              break;
  65              case 'delete':
  66                  MP_Autoresponder::delete( $url_parms['id'] );
  67                  unset( $url_parms['id'] );
  68  
  69                  $url_parms['message'] = 3;
  70                  self::mp_redirect( self::url( MailPress_autoresponders, $url_parms ) );
  71              break;
  72          }
  73      }
  74  
  75  ////  Title  ////
  76  
  77  	public static function title()
  78      {
  79          if ( isset( self::$get_['id'] ) )
  80          {
  81              global $title;
  82              $title = __( 'Edit Autoresponder', 'MailPress' );
  83          }
  84      }
  85  
  86  //// Help ////
  87  
  88  	public static function add_help_tab() 
  89      {
  90          global $current_screen;
  91  
  92          $content = '';
  93          $content .= '<p><strong>' . __( 'Autoresponders :', 'MailPress' ) . '</strong></p>';
  94          $content .= '<p>' . __( 'You can use autoresponders to send one or a set of specific mails based on a specific event triggered by a mp user.', 'MailPress' ) . '</p>';
  95  
  96          $current_screen->add_help_tab( array(     'id'        => 'overview',
  97                                          'title'    => __( 'Overview' ),
  98                                          'content'    => $content )
  99          );
 100  
 101          $content = '';
 102          $content .= '<p>' . __( 'When adding a new autoresponder on this screen, you&#8217;ll fill in the following fields:', 'MailPress' ) . '</p>';
 103          $content .= '<ul>';
 104          $content .= '<li>' . __( '<strong>Name</strong> &mdash; The name is used to identify the autoresponder almost everywhere.', 'MailPress' ) . '</li>';
 105          $content .= '<li>' . __( '<strong>Slug</strong> &mdash; The &#8220;slug&#8221; is a unique id for the autoresponder. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'MailPress' ) . '</li>';
 106          $content .= '<li>' . __( '<strong>Description</strong> &mdash; The description is not prominent by default.', 'MailPress' ) . '</li>';
 107          $content .= '<li>' . __( '<strong>Active</strong> &mdash; whether this autoresponder is active or not.', 'MailPress' );
 108          $content .= '    ' . __( 'If not active during a certain period of time, All mails that should have been sent on time will be cancelled. following mails in a set, if any, will be lost as well.', 'MailPress' ) . '</li>';
 109          $content .= '<li>' . __( '<strong>Event</strong> &mdash; depending on add-on activations, events list will be populated accordingly.', 'MailPress' ) . '</li>';
 110          $content .= '</ul>';
 111          $content .= '<p>' . __( 'You can customize the display of this screen&#8217;s content:', 'MailPress' ) . '</p>';
 112          $content .= '<ul>';
 113          $content .= '<li>' . __( 'You can hide/display columns based on your needs and decide how many autoresponders to list per screen using the Screen Options tab.', 'MailPress' ) . '</li>';
 114          $content .= '</ul>';
 115  
 116          $current_screen->add_help_tab( array(     'id'        => 'adding-autoresponder',
 117                                          'title'    => __( 'Adding Autoresponder', 'MailPress' ),
 118                                          'content'    => $content )
 119          );
 120  
 121          $content = '';
 122          $content .= '<p>' . __( 'When scheduling an autoresponder, do as follow:', 'MailPress' ) . '</p>';
 123          $content .= '<ul>';
 124          $content .= '<li>' . sprintf( __( 'Create a new %s and use the appropriate box, link it to the MailPress autoresponder by specifying the delay between the triggered event and the mail release. For a set of mails, you will need to create as many as mails required, linked to the same autoresponder with different delays.', 'MailPress' ), sprintf( '<a href="' . MailPress_write . '" target="_blank">%s</a>', __( 'Mail', 'MailPress' ) ) ) . '</li>';
 125          $content .= '<li>' . __( 'When saving the mail, a recipient mail is required but will be replaced on time by the right recipient&#8217;s mail.', 'MailPress' ) . '</li>';
 126          $content .= '<li>' . sprintf( __( 'Autoresponder draft mail can be quickly identified in %1$s with a little clock icon : %2$s', 'MailPress' ), sprintf( '<a href="' . MailPress_mails . '" target="_blank">%s</a>', __( 'Mails list', 'MailPress' ) ) , '<span class="mp_icon mp_icon_autoresponder" title="' . esc_attr( __('Autoresponder', 'MailPress' ) ) . '"></span>' ) . '</li>';
 127          $content .= '</ul>';
 128  
 129          $content .= '<p>';
 130          if (MP_addons::is_active('MailPress_wp_cron'))
 131          {
 132              $content .= sprintf( __('Check the autoresponder mail(s) scheduled, if any, on %1$s', 'MailPress'), sprintf( '<a href="' . MailPress_wp_cron . '" target="_blank">%s</a>', __( 'Tools > Wp_cron', 'MailPress' ) ) );
 133          }
 134          else
 135          {
 136              $content .= sprintf( __('Activate add-on %1$s, so you can check the autoresponder mail(s) scheduled, if any.', 'MailPress'), sprintf( '<a href="' . MailPress_addons . '#MailPress_wp_cron' . '" target="_blank">%s</a>', __( 'Wp_cron', 'MailPress' ) ) );
 137          }
 138          $content .= '</p>';
 139  
 140          $current_screen->add_help_tab( array(     'id'        => 'scheduling-autoresponder',
 141                                          'title'    => __( 'Scheduling Autoresponder', 'MailPress' ),
 142                                          'content'    => $content )
 143          );
 144      }
 145  
 146  ////  Styles  ////
 147  
 148  	public static function print_styles( $s ) 
 149      {
 150          $styles = ( is_array( $s ) ) ? $s : array();
 151  
 152          wp_register_style( self::screen,         '/' . MP_PATH . 'mp-admin/css/autoresponders.css',       array( 'thickbox' ) );
 153          $styles[] = self::screen;
 154  
 155          parent::print_styles( $styles );
 156      }
 157  
 158  	public static function print_styles_icons( $i = array( 'icon', ) ) 
 159      {
 160          return parent::print_styles_icons( $i );
 161      }
 162  
 163  //// Scripts ////
 164  
 165  	public static function print_scripts( $scripts = array() )  
 166      {
 167          wp_register_script( 'mp-ajax-response',    '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array( 'jquery' ), false, 1 );
 168          wp_localize_script( 'mp-ajax-response',     'wpAjax', array( 
 169              'noPerm' => __( 'An unidentified error has occurred.' ), 
 170              'broken' => __( 'An unidentified error has occurred.' ), 
 171              'l10n_print_after' => 'try{convertEntities( wpAjax );}catch( e ){};' 
 172           ) );
 173  
 174          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array( 'mp-ajax-response' ), false, 1 );
 175  
 176          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array( 'thickbox' ), false, 1 );
 177  
 178          wp_register_script( 'mp-taxonomy',         '/' . MP_PATH . 'mp-includes/js/mp_taxonomy.js', array( 'mp-lists' ), false, 1 );
 179          wp_localize_script( 'mp-taxonomy',         'MP_AdminPageL10n', array(     
 180              'pending' => __( '%i% pending' ), 
 181              'screen' => self::screen,
 182              'list_id' => self::list_id,
 183              'add_form_id' => self::add_form_id,
 184              'tr_prefix_id' => self::tr_prefix_id,
 185              'l10n_print_after' => 'try{convertEntities( MP_AdminPageL10n );}catch( e ){};' 
 186           ) );
 187  
 188          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/autoresponders.js', array( 'mp-taxonomy', 'mp-thickbox', 'jquery-ui-tabs' ), false, 1 );
 189  
 190          $scripts[] = self::screen;
 191          parent::print_scripts( $scripts );
 192      }
 193  
 194  //// Columns ////
 195  
 196  	public static function get_columns() 
 197      {
 198          $columns = array(    'cb'        => '<input type="checkbox" />',
 199                          'name'    => __( 'Name', 'MailPress' ),
 200                          'active'    => __( 'Active', 'MailPress' ),
 201                          'desc'    => __( 'Description', 'MailPress' ),
 202                          'event'     => __( 'Event', 'MailPress' )
 203          );
 204          return $columns;
 205      }
 206  
 207  //// List ////
 208  
 209  	public static function get_list( $args )
 210      {
 211          extract( $args );
 212  
 213          $url_parms = self::get_url_parms( array( 's', 'paged' ) );
 214  
 215          $_args = array(    'offset'         => ( $start - 1 ) * $_per_page, 
 216                      'number'         => $_per_page, 
 217                      'hide_empty'     => 0
 218          );
 219  
 220          if ( isset( $url_parms['s'] ) )
 221          {
 222              $_args['search'] = $url_parms['s'];
 223          }
 224  
 225          $autoresponders = MP_Autoresponder::get_all( $_args );
 226  
 227          if ( empty( $autoresponders ) )
 228          {
 229              return false;
 230          }
 231  
 232          echo self::_get_list( $autoresponders, $url_parms );
 233      }
 234  
 235  	public static function _get_list( $autoresponders, $url_parms )
 236      {
 237          $out = '';
 238  
 239          foreach( $autoresponders as $autoresponder )
 240          {
 241              $out .= self::get_row( $autoresponder, $url_parms );
 242          }
 243  
 244          return $out;
 245      }
 246  
 247  ////  Row  ////
 248  
 249  	public static function get_row( $autoresponder, $url_parms ) 
 250      {
 251          $mp_autoresponder_registered_events = MP_Autoresponder_events::get_all();
 252  
 253          static $row_class = '';
 254  
 255          $autoresponder = MP_Autoresponder::get( $autoresponder );
 256  
 257          $name = $autoresponder->name ;
 258  
 259  // url's
 260          $url_parms['action']     = 'edit';
 261          $url_parms['id']     = $autoresponder->term_id;
 262  
 263          $edit_url = esc_url( self::url( MailPress_autoresponders, $url_parms ) );
 264          $url_parms['action']     = 'delete';
 265          $delete_url = esc_url( self::url( MailPress_autoresponders, $url_parms, 'delete-autoresponder_' . $autoresponder->term_id ) );
 266  // actions
 267          $actions = array();
 268          $actions['edit'] = '<a href="' . $edit_url . '">' . __( 'Edit' ) . '</a>';
 269          $actions['delete'] = '<a class="submitdelete delete:' . self::tr_prefix_id . '" href="' . $delete_url . '">' . __( 'Delete' ) . '</a>';
 270  
 271          $row_class = 'alternate' == $row_class ? '' : 'alternate';
 272  
 273          $out = '';
 274          $out .= '<tr id="' . self::tr_prefix_id . '-' . $autoresponder->term_id . '" class="iedit ' . $row_class . '">';
 275  
 276          $columns = self::get_columns();
 277          $hidden  = self::get_hidden_columns();
 278  
 279          foreach ( $columns as $column_name => $column_display_name ) 
 280          {
 281              $attributes = sprintf( 'class="%1$s column-%1$s%2$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '' );
 282  
 283              switch ( $column_name ) 
 284              {
 285                  case 'cb':
 286                      $out .= '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $autoresponder->term_id . '" /></th>';
 287                  break;
 288                  case 'name':
 289                      $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_url . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
 290                      $out .= self::get_actions( $actions );
 291                      $out .= '</td>';
 292                  break;
 293                  case 'active':
 294                      $x = ( isset( $autoresponder->description['active'] ) ) ? __( 'Yes', 'MailPress' ) : __( 'No', 'MailPress' );
 295                      $out .= '<td ' . $attributes . '>' . $x . '</td>';
 296                  break;
 297                  case 'desc':
 298                      $out .= '<td ' . $attributes . '>' . stripslashes( $autoresponder->description['desc'] ) . '</td>';
 299                  break;
 300                  case 'event':
 301                      $out .= '<td ' . $attributes . '>' . $mp_autoresponder_registered_events[$autoresponder->description['event']] . '</td>';
 302                  break;
 303              }
 304          }
 305          $out .= '</tr>';
 306  
 307          return $out;
 308      }
 309  }


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