[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_adminpage_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          if     ( !empty($_REQUEST['action'])  && ($_REQUEST['action']  != -1))    $action = $_REQUEST['action'];
  20          elseif ( !empty($_REQUEST['action2']) && ($_REQUEST['action2'] != -1) )    $action = $_REQUEST['action2'];
  21          if (!isset($action)) return;
  22  
  23          $url_parms     = self::get_url_parms(array('s', 'paged', 'id'));
  24          $checked    = (isset($_GET['checked'])) ? $_GET['checked'] : array();
  25  
  26          $count    = str_replace('bulk-', '', $action);
  27          $count     .= 'd';
  28          $$count    = 0;
  29  
  30          switch($action) 
  31          {
  32              case 'bulk-delete' :
  33                  foreach($checked as $id) if (MP_Autoresponder::delete($id)) $$count++;
  34  
  35                  if ($$count) $url_parms[$count] = $$count;
  36                  $url_parms['message'] = ($$count <= 1) ? 3 : 4;
  37                  self::mp_redirect( self::url(MailPress_autoresponders, $url_parms) );
  38              break;
  39  
  40              case 'add':
  41                  $e = MP_Autoresponder::insert($_POST);
  42                  $url_parms['message'] = ( $e && !is_wp_error( $e ) ) ? 1 : 91;
  43                  unset($url_parms['s']);
  44                  self::mp_redirect( self::url(MailPress_autoresponders, $url_parms) );
  45              break;
  46              case 'edited':
  47                  unset($_GET['action']);
  48                  if (!isset($_POST['cancel'])) 
  49                  {
  50                      $e = MP_Autoresponder::insert($_POST);
  51                      $url_parms['message'] = ( $e && !is_wp_error( $e ) ) ? 2 : 92 ;
  52                  }
  53                  unset($url_parms['id']);
  54                  self::mp_redirect( self::url(MailPress_autoresponders, $url_parms) );
  55              break;
  56              case 'delete':
  57                  MP_Autoresponder::delete($url_parms['id']);
  58                  unset($url_parms['id']);
  59  
  60                  $url_parms['message'] = 3;
  61                  self::mp_redirect( self::url(MailPress_autoresponders, $url_parms) );
  62              break;
  63          }
  64      }
  65  
  66  ////  Title  ////
  67  
  68  	public static function title() { if (isset($_GET['id'])) { global $title; $title = __('Edit Autoresponder', MP_TXTDOM); } }
  69  
  70  ////  Styles  ////
  71  
  72  	public static function print_styles($styles = array()) 
  73      {
  74          $styles[] = 'thickbox';
  75          parent::print_styles($styles);
  76      }
  77  
  78  //// Scripts ////
  79  
  80  	public static function print_scripts($scripts = array())  
  81      {
  82          wp_register_script( 'mp-ajax-response',    '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array('jquery'), false, 1);
  83          wp_localize_script( 'mp-ajax-response',     'wpAjax', array(
  84              'noPerm' => __('An unidentified error has occurred.'), 
  85              'broken' => __('An unidentified error has occurred.'), 
  86              'l10n_print_after' => 'try{convertEntities(wpAjax);}catch(e){};' 
  87          ));
  88  
  89          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array('mp-ajax-response'), false, 1);
  90          wp_localize_script( 'mp-lists',         'wpListL10n', array( 
  91              'url' => MP_Action_url
  92          ));
  93  
  94          wp_register_script( 'mp-thickbox',         '/' . MP_PATH . 'mp-includes/js/mp_thickbox.js', array('thickbox'), false, 1);
  95  
  96          wp_register_script( 'mp-taxonomy',         '/' . MP_PATH . 'mp-includes/js/mp_taxonomy.js', array('mp-lists'), false, 1);
  97          wp_localize_script( 'mp-taxonomy',         'MP_AdminPageL10n', array(    
  98              'pending' => __('%i% pending'), 
  99              'screen' => self::screen,
 100              'list_id' => self::list_id,
 101              'add_form_id' => self::add_form_id,
 102              'tr_prefix_id' => self::tr_prefix_id,
 103              'l10n_print_after' => 'try{convertEntities(MP_AdminPageL10n);}catch(e){};' 
 104          ));
 105  
 106          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-admin/js/autoresponders.js', array('mp-taxonomy', 'mp-thickbox', 'jquery-ui-tabs'), false, 1);
 107  
 108          $scripts[] = self::screen;
 109          parent::print_scripts($scripts);
 110      }
 111  
 112  //// Columns ////
 113  
 114  	public static function get_columns() 
 115      {
 116          $columns = array(    'cb'         => "<input type='checkbox' />", 
 117                      'name'     => __('Name', MP_TXTDOM), 
 118                      'active'    => __('Active', MP_TXTDOM), 
 119                      'desc'    => __('Description', MP_TXTDOM), 
 120                      'event'     => __('Event', MP_TXTDOM)
 121                  );
 122          return $columns;
 123      }
 124  
 125  //// List ////
 126  
 127  	public static function get_list($args)
 128      {
 129          extract($args);
 130  
 131          $url_parms = self::get_url_parms(array('s', 'paged'));
 132  
 133          $_args = array('offset' => ($start - 1) * $_per_page, 'number' => $_per_page, 'hide_empty' => 0);
 134          if (isset($url_parms['s'])) $_args['search'] = $url_parms['s'];
 135  
 136          $terms = MP_Autoresponder::get_all($_args);
 137          if (empty($terms)) return false;
 138  
 139          echo self::_get_list($url_parms, $terms);
 140      }
 141  
 142  	public static function _get_list($url_parms, $autoresponders)
 143      {
 144          $out = '';
 145  
 146          foreach( $autoresponders as $autoresponder ) 
 147              $out .= self::get_row( $autoresponder, $url_parms );
 148  
 149          return $out;
 150      }
 151  
 152  ////  Row  ////
 153  
 154  	public static function get_row( $autoresponder, $url_parms ) 
 155      {
 156          $mp_autoresponder_registered_events = MP_Autoresponder_events::get_all();
 157  
 158          static $row_class = '';
 159  
 160          $autoresponder = MP_Autoresponder::get( $autoresponder );
 161  
 162          $name = $autoresponder->name ;
 163  
 164  // url's
 165          $url_parms['action']     = 'edit';
 166          $url_parms['id']     = $autoresponder->term_id;
 167  
 168          $edit_url = esc_url(self::url( MailPress_autoresponders, $url_parms ));
 169          $url_parms['action']     = 'delete';
 170          $delete_url = esc_url(self::url( MailPress_autoresponders, $url_parms, 'delete-autoresponder_' . $autoresponder->term_id ));
 171  // actions
 172          $actions = array();
 173          $actions['edit'] = '<a href="' . $edit_url . '">' . __('Edit') . '</a>';
 174          $actions['delete'] = "<a class='submitdelete' href='$delete_url'>" . __('Delete') . "</a>";
 175  
 176          $row_class = 'alternate' == $row_class ? '' : 'alternate';
 177  
 178          $out = '';
 179          $out .= "<tr id='" . self::tr_prefix_id . "-$autoresponder->term_id' class='iedit $row_class'>";
 180  
 181          $columns = self::get_columns();
 182          $hidden  = self::get_hidden_columns();
 183  
 184          foreach ( $columns as $column_name => $column_display_name ) 
 185          {
 186              $class = "class='$column_name column-$column_name'";
 187  
 188              $style = '';
 189              if ( in_array($column_name, $hidden) )
 190                  $style = ' style="display:none;"';
 191  
 192              $attributes = "$class$style";
 193  
 194              switch ($column_name) 
 195              {
 196                  case 'cb':
 197                      $out .= '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $autoresponder->term_id . '" /></th>';
 198                  break;
 199                  case 'name':
 200                      $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_url . '" title="' . esc_attr(sprintf(__('Edit "%s"'), $name)) . '">' . $name . '</a></strong><br />';
 201                      $out .= self::get_actions($actions);
 202                      $out .= '</td>';
 203                  break;
 204                  case 'active':
 205                      $x = (isset($autoresponder->description['active'])) ? __('Yes', MP_TXTDOM) : __('No', MP_TXTDOM);
 206                      $out .= "<td $attributes>" . $x . "</td>";
 207                  break;
 208                  case 'desc':
 209                      $out .= "<td $attributes>" . stripslashes($autoresponder->description['desc']) . "</td>";
 210                  break;
 211                  case 'event':
 212                      $out .= "<td $attributes>" . $mp_autoresponder_registered_events[$autoresponder->description['event']] . "</td>";
 213                  break;
 214              }
 215          }
 216          $out .= '</tr>';
 217  
 218          return $out;
 219      }
 220  }


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