[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_list_
   3  {
   4      const screen        = MailPress_page_mailinglists;
   5      const capability    = 'MailPress_manage_mailinglists';
   6      const help_url        = 'http://blog.mailpress.org/tutorials/add-ons/mailinglist/';
   7      const file            = __FILE__;
   8  
   9      const taxonomy        = MailPress_mailinglist::taxonomy;
  10  
  11      const add_form_id    = 'add';
  12      const list_id        = 'the-list';
  13      const tr_prefix_id    = 'mlnglst';
  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 ( $id == get_option( MailPress_mailinglist::option_name_default ) )
  35                      {
  36                          wp_die( sprintf( __( "Can&#8217;t delete the <strong>%s</strong> mailing list: this is the default one", 'MailPress' ), MP_Mailinglist::get_name( $id ) ) );
  37                      }
  38  
  39                      if ( MP_Mailinglist::delete( $id ) )
  40                      {
  41                          $$count++;
  42                      }
  43                  }
  44  
  45                  if ( $$count )
  46                  {
  47                      $url_parms[$count] = $$count;
  48                  }
  49  
  50                  $url_parms['message'] = ( $$count <= 1 ) ? 3 : 4;
  51                  self::mp_redirect( self::url( MailPress_mailinglists, $url_parms ) );
  52              break;
  53  
  54              case 'add':
  55                  $e = MP_Mailinglist::insert( self::$pst_ );
  56                  $url_parms['message'] = ( $e && !is_wp_error( $e ) ) ? 1 : 91;
  57                  unset( $url_parms['s'] );
  58                  self::mp_redirect( self::url( MailPress_mailinglists, $url_parms ) );
  59              break;
  60              case 'edited':
  61                  unset( self::$get_['action'] );
  62                  if ( !isset( self::$pst_['cancel'] ) ) 
  63                  {
  64                      $e = MP_Mailinglist::insert( self::$pst_ );
  65                      $url_parms['message'] = ( $e && !is_wp_error( $e ) ) ? 2 : 92 ;
  66                  }
  67                  unset( $url_parms['id'] );
  68                  self::mp_redirect( self::url( MailPress_mailinglists, $url_parms ) );
  69              break;
  70              case 'delete':
  71                  if ( $url_parms['id'] == get_option( MailPress_mailinglist::option_name_default ) )
  72                  {
  73                      wp_die( sprintf( __( "Can&#8217;t delete the <strong>%s</strong> mailing list: this is the default one", 'MailPress' ), MP_Mailinglist::get_name( $id ) ) );
  74                  }
  75  
  76                  MP_Mailinglist::delete( $url_parms['id'] );
  77                  unset( $url_parms['id'] );
  78  
  79                  $url_parms['message'] = 3;
  80                  self::mp_redirect( self::url( MailPress_mailinglists, $url_parms ) );
  81              break;
  82          }
  83      }
  84  
  85  ////  Title  ////
  86  
  87  	public static function title()
  88      {
  89          if ( isset( self::$get_['id'] ) )
  90          {
  91              global $title;
  92              $title = __( 'Edit Mailinglist', 'MailPress' );
  93          }
  94      }
  95  
  96  //// Help ////
  97  
  98  	public static function add_help_tab() 
  99      {
 100          global $current_screen;
 101  
 102          $content = '';
 103          $content .= '<p><strong>' . __( 'Mailing lists :', 'MailPress' ) . '</strong></p>';
 104          $content .= '<p>' . sprintf( __( 'You can use mailing list to group mp users for sending them any %1$s.', 'MailPress' ),  sprintf( '<a href="%1$s" target="_blank">%2$s</a>', MailPress_write, __( 'Mail', 'MailPress' ) ) ) . '</p>';
 105          $content .= '<p>' . sprintf( __( 'The default mailing list is &#8220;Uncategorized&#8221; until you change it in your %1$s settings.', 'MailPress' ), sprintf( '<a href="%1$s" target="_blank">%2$s</a>',MailPress_settings, __( 'General', 'MailPress' ) ) ) . '</p>';
 106          $content .= '<p>' . sprintf( __( 'You can also make these mailing list public for subscription with your %1$s settings.', 'MailPress' ), sprintf( '<a href="%1$s" target="_blank">%2$s</a>', MailPress_settings . '&tab=subscriptions', __( 'Subscriptions', 'MailPress' ) ) ) . '</p>';
 107  
 108          $current_screen->add_help_tab( array(     'id'        => 'overview',
 109                                          'title'        => __( 'Overview' ),
 110                                          'content'    => $content )
 111          );
 112  
 113          $content = '';
 114          $content .= '<p>' . __( 'When adding a new mailing list on this screen, you&#8217;ll fill in the following fields:', 'MailPress' ) . '</p>';
 115          $content .= '<ul>';
 116          $content .= '<li>' . __( '<strong>Name</strong> &mdash; The name is how it appears on your site.', 'MailPress' ) . '</li>';
 117          $content .= '<li>' . __( '<strong>Slug</strong> &mdash; The &#8220;slug&#8221; is the unique version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.', 'MailPress' ) . '</li>';
 118          $content .= '<li>' . __( '<strong>Description</strong> &mdash; The description is not prominent by default.', 'MailPress' ) . '</li>';
 119          $content .= '<li>' . __( '<strong>Parent</strong> &mdash; Mailing lists, can have a hierarchy. You might have a Rock&#8217;n roll mailing list, and under that have children mailing lists for Elvis and The Beatles. Totally optional ! To create a sub mailing list, just choose another mailing list from the Parent dropdown.', 'MailPress' ) . '</li>';
 120          $content .= '</ul>';
 121          $content .= '<p>' . __( 'You can customize the display of this screen&#8217;s content:', 'MailPress' ) . '</p>';
 122          $content .= '<ul>';
 123          $content .= '<li>' . __( 'You can hide/display columns based on your needs and decide how many mailing lists to list per screen using the Screen Options tab.', 'MailPress' ) . '</li>';
 124          $content .= '</ul>';
 125  
 126          $current_screen->add_help_tab( array(     'id'        => 'adding-terms',
 127                                          'title'        => __( 'Adding Mailinglists', 'MailPress' ),
 128                                          'content'    => $content )
 129          );
 130  
 131  
 132      }
 133  
 134  //// Scripts ////
 135  
 136  	public static function print_scripts( $scripts = array() ) 
 137      {
 138          wp_register_script( 'mp-ajax-response',    '/' . MP_PATH . 'mp-includes/js/mp_ajax_response.js', array( 'jquery' ), false, 1 );
 139          wp_localize_script( 'mp-ajax-response',     'wpAjax', array( 
 140              'noPerm' => __( 'An unidentified error has occurred.' ), 
 141              'broken' => __( 'An unidentified error has occurred.' ), 
 142              'l10n_print_after' => 'try{convertEntities( wpAjax );}catch( e ){};' 
 143           ) );
 144  
 145          wp_register_script( 'mp-lists',         '/' . MP_PATH . 'mp-includes/js/mp_lists.js', array( 'mp-ajax-response' ), false, 1 );
 146  
 147          wp_register_script( self::screen,         '/' . MP_PATH . 'mp-includes/js/mp_taxonomy.js', array( 'mp-lists' ), false, 1 );
 148          wp_localize_script( self::screen,         'MP_AdminPageL10n', array( 
 149              'pending' => __( '%i% pending' ), 
 150              'screen'  => self::screen,
 151              'list_id' => self::list_id,
 152              'add_form_id' => self::add_form_id,
 153              'tr_prefix_id' => self::tr_prefix_id,
 154              'l10n_print_after' => 'try{convertEntities( MP_AdminPageL10n );}catch( e ){};' 
 155           ) );
 156  
 157          $scripts[] = self::screen;
 158          parent::print_scripts( $scripts );
 159      }
 160  
 161  //// Columns ////
 162  
 163  	public static function get_columns() 
 164      {
 165          $columns = array(    'cb'        => '<input type="checkbox" />',
 166                          'name'    => __( 'Name', 'MailPress' ),
 167                          'desc'    => __( 'Description', 'MailPress' ),
 168                          'allowed'    => __( 'Allowed', 'MailPress' ),
 169                          'num'        => __( 'MP users', 'MailPress' )
 170          );
 171          return $columns;
 172      }
 173  
 174  //// List ////
 175  
 176  	public static function get_list( $args )
 177      {
 178          extract( $args );
 179  
 180          $url_parms = self::get_url_parms( array( 's', 'paged' ) );
 181  
 182          $_args = array( 'offset' => ( $start - 1 ) * $_per_page, 'number' => $_per_page, 'hide_empty' => 0 );
 183          if ( isset( $url_parms['s'] ) )
 184          {
 185              $_args['search'] = $url_parms['s'];
 186          }
 187  
 188          $_mailinglists = MP_Mailinglist::get_all( $_args );
 189          if ( empty( $_mailinglists ) )
 190          {
 191              return false;
 192          }
 193  
 194          $children = _get_term_hierarchy( self::taxonomy );
 195  
 196          foreach( $_mailinglists as $_mailinglist )
 197          {
 198              $_mailinglist->_found = true;
 199              $mailinglists[$_mailinglist->term_id] = $_mailinglist;
 200          }
 201          unset( $_mailinglists, $_mailinglist );
 202  
 203          foreach( $mailinglists as $mailinglist )
 204          {
 205              if ( !$my_parent = $mailinglist->parent )
 206              {
 207                  continue;
 208              }
 209  
 210              do
 211              {  
 212                  if ( !isset( $mailinglists[$my_parent] ) )
 213                  {
 214                      $mailinglists[$my_parent] = get_term( $my_parent, self::taxonomy );
 215                  }
 216                  $my_parent = $mailinglists[$my_parent]->parent;  
 217              } while ( $my_parent );
 218          }
 219          echo self::_get_list( $mailinglists, $url_parms, $children );
 220      }
 221  
 222  	public static function _get_list( $mailinglists, $url_parms, &$children, $level = 0, $parent = 0 )
 223      {
 224          $out = ''; 
 225          foreach ( $mailinglists as $key => $mailinglist )  
 226          { 
 227              if ( $parent == $mailinglist->parent )  
 228              { 
 229                  $out .= self::get_row( $mailinglist, $url_parms, $level ); 
 230                  unset( $mailinglists[ $key ] ); 
 231                  if ( isset( $children[$mailinglist->term_id] ) )
 232                  {
 233                      $out .= self::_get_list( $mailinglists, $url_parms, $children, $level + 1, $mailinglist->term_id );
 234                  }
 235              } 
 236          } 
 237          return $out;
 238      }
 239  
 240  ////  Row  ////
 241  
 242  	public static function get_row( $mailinglist, $url_parms, $level, $name_override = false ) 
 243      {
 244          global $mp_subscriptions;
 245  
 246          static $row_class = '';
 247  
 248          $mailinglist = MP_Mailinglist::get( $mailinglist );
 249  
 250          $default_mailinglist_id = get_option( MailPress_mailinglist::option_name_default );
 251          $pad = str_repeat( '&#8212; ', $level );
 252          $name = ( $name_override ) ? $name_override : $pad . ' ' . $mailinglist->name ;
 253  
 254  // url's
 255          $url_parms['action'] = 'edit';
 256          $url_parms['id'] = $mailinglist->term_id;
 257  
 258          $edit_url = esc_url( self::url( MailPress_mailinglists, $url_parms ) );
 259          $url_parms['action']    = 'delete';
 260          $delete_url = esc_url( self::url( MailPress_mailinglists, $url_parms,  'delete-mailinglist_' . $mailinglist->term_id ) );
 261  // actions
 262          $actions = array();
 263          $actions['edit'] = '<a href="' . $edit_url . '">' . __( 'Edit' ) . '</a>';
 264          $actions['delete'] = '<a class="submitdelete delete-' . self::tr_prefix_id . '" href="' . $delete_url . '">' . __( 'Delete' ) . '</a>';
 265  
 266          if ( $default_mailinglist_id == $mailinglist->term_id )
 267          {
 268              unset( $actions['delete'] );
 269          }
 270  
 271          $mailinglist->allowed = ( isset( $mp_subscriptions['display_mailinglists'][$mailinglist->term_id] ) );
 272  
 273  
 274          $row_class  = ( 'alternate' == substr( $row_class, 0, 9 ) ) ? '' : 'alternate ';
 275          $row_class .= 'iedit';
 276          $row_class .= ( isset( $mailinglist->_found ) ) ? '' : ' ebeeef';
 277  
 278          $out = '';
 279          $out .= '<tr id="' . self::tr_prefix_id . '-' . $mailinglist->term_id . '" class="' . $row_class . '">';
 280  
 281          $columns = self::get_columns();
 282          $hidden  = self::get_hidden_columns();
 283  
 284          foreach ( $columns as $column_name => $column_display_name ) 
 285          {
 286              $attributes = sprintf( 'class="%1$s column-%1$s%2$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '' );
 287  
 288              switch ( $column_name ) 
 289              {
 290                  case 'cb':
 291                      $out .= '<th class="check-column">';
 292                      if ( $default_mailinglist_id != $mailinglist->term_id )
 293                      {
 294                          $out .= '<input type="checkbox" name="checked[]" value="' . $mailinglist->term_id . '" />';
 295                      }
 296                      else
 297                      {
 298                          $out .= '&#160;';
 299                      }
 300                      $out .= '</th>';
 301                  break;
 302                  case 'name':
 303                      $out .= '<td ' . $attributes . '><strong><a class="row-title" href="' . $edit_url . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
 304                      $out .= self::get_actions( $actions );
 305                      $out .= '</td>';
 306                   break;
 307                   case 'desc':
 308                       $out .= '<td ' . $attributes . '>' . stripslashes( $mailinglist->description ) . '</td>';
 309                   break;
 310                   case 'allowed':
 311                       $out .= '<td ' . $attributes . '>' . ( ( $mailinglist->allowed ) ? __( 'yes', 'MailPress' ) : __( 'no', 'MailPress' ) ) . '</td>';
 312                   break;
 313                  case 'num':
 314                      $mailinglist->count = number_format_i18n( $mailinglist->count );
 315  
 316                      if ( current_user_can( 'MailPress_edit_users' ) )
 317                      {
 318                          $url    = esc_url( add_query_arg( 'mailinglist', $mailinglist->term_id, MailPress_users ) );
 319                          $mp_users_count = ( $mailinglist->count > 0 ) ? '<a href="' . $url . '">' . $mailinglist->count . '</a>' : $mailinglist->count;
 320                      }
 321                      else
 322                      {
 323                          $mp_users_count =  $mailinglist->count;
 324                      }
 325  
 326                      $attributes = sprintf( 'class="num column-num%2$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '' );
 327  
 328                      $out .= '<td ' . $attributes . '>' . $mp_users_count . '</td>';
 329                   break;
 330              }
 331          }
 332          $out .= '</tr>';
 333  
 334          return $out;
 335      }
 336  }


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