[ Index ]

MailPress 7.1

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_WP_Admin_page_list_
   3  {
   4      const screen    = MailPress_page_addons;
   5      const capability= 'MailPress_manage_addons';
   6      const help_url    = 'http://blog.mailpress.org/tutorials/add-ons/';
   7      const file        = __FILE__;
   8  
   9      const per_page     = false;
  10  
  11  ////  Redirect  ////
  12  
  13  	public static function redirect() 
  14      {
  15          $action = parent::redirect();
  16          if ( !$action ) return;
  17  
  18          $url_parms    = self::get_url_parms( array( 'status', 's' ) );
  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          $addons = get_option( MP_Addons::option_name );
  26  
  27          if ( !is_array( $addons ) )
  28          {
  29              $addons = array();
  30          }
  31  
  32          switch( $action )
  33          {
  34              case 'bulk-activate' :
  35                  foreach( $checked as $addon )
  36                  {
  37                      if ( isset( $addons[$addon] ) )
  38                      {
  39                          continue;
  40                      }
  41                      if ( MP_Addons::load( $addon ) )
  42                      {
  43                          $addons[$addon] = $addon;
  44                          do_action( "activate_{$addon}" );
  45                          $$count++;
  46                      }
  47                  }
  48              break;
  49              case 'bulk-deactivate' :
  50                  foreach( $checked as $addon )
  51                  {
  52                      if ( !isset( $addons[$addon] ) )
  53                      {
  54                          continue;
  55                      }
  56                      unset( $addons[$addon] );
  57                      do_action( "deactivate_{$addon}" );
  58                      $$count++;
  59                  }
  60              break;
  61              case 'activate' :
  62                  $addon = self::$get_['addon'];
  63                  if ( isset( $addons[$addon] ) )
  64                  {
  65                      break;
  66                  }
  67                  if ( MP_Addons::load( $addon ) )
  68                  {
  69                      $addons[$addon] = $addon;
  70                      do_action( "activate_{$addon}" );
  71                      $$count++;
  72                  }
  73              break;
  74              case 'deactivate' :
  75                  $addon = self::$get_['addon'];
  76                  if ( !isset( $addons[$addon] ) )
  77                  {
  78                      break;
  79                  }
  80                  unset( $addons[$addon] );
  81                  do_action( "deactivate_{$addon}" );
  82                  $$count++;
  83              break;
  84          }
  85          ksort( $addons );
  86  
  87          update_option( MP_Addons::option_name, $addons );
  88  
  89          if ( $$count )
  90          {
  91              $url_parms[$count] = $$count;
  92          }
  93  
  94          self::mp_redirect( self::url( MailPress_addons, $url_parms ) );
  95      }
  96  
  97  //// Help ////
  98  
  99  	public static function add_help_tab() 
 100      {
 101          global $current_screen;
 102  
 103          $content = '';
 104          $content .= '<p><strong>' . __( 'MailPress Add-ons :', 'MailPress' ) . '</strong></p>';
 105          $content .= '<p>' . __( 'MailPress Add-ons extend and expand the functionality of MailPress. You can activate it or deactivate it here.', 'MailPress' ) . '</p>';
 106          $content .= '<p>' . __( 'Conflicts between add-ons may appear, so READ CAREFULLY each description before activation.', 'MailPress' ) . '</p>';
 107          $content .= '<p>' . sprintf( __( 'All Add-ons are currently stored in %s.', 'MailPress' ), '<code>' . MP_FOLDER . '/' . MP_CONTENT_FOLDER . '/add-ons</code>');
 108          $content .= '</p>';
 109          $content .= '<p><i>' . __( 'For Developers : ', 'MailPress') . '</i>';
 110          $content .= sprintf( __( ' Read this %s for more explanations', 'MailPress' ), sprintf( '<a href="../' . MP_PATH_CONTENT . 'add-ons/readme.txt" target="_blank">%s</a>', 'readme.txt' ) );
 111          $content .= '</p>';
 112  
 113          $current_screen->add_help_tab( array(     'id'        => 'overview',
 114                                          'title'    => __( 'Overview' ),
 115                                          'content'    => $content )
 116          );
 117      }
 118  
 119  //// Columns ////
 120  
 121  	public static function get_columns() 
 122      {
 123          $columns = array(    'cb'         => '<input type="checkbox" />', 
 124                          'title'    => __( 'Add-on', 'MailPress' ), 
 125                          'desc'    => __( 'Description' )
 126          );
 127          $columns = apply_filters( 'MailPress_addons_columns', $columns );
 128          return $columns;
 129      }
 130  
 131  //// List ////
 132  
 133  	public static function get_list( $args ) 
 134      {
 135          extract( $args );
 136  
 137          $addons = MP_Addons::get_all();
 138  
 139          $counts = array('all'        => count( $addons ), 
 140                      'active'    => 0, 
 141                      'inactive'    => 0,
 142                      'search'    => 0
 143          );
 144  
 145          foreach( $addons as $k => $v )
 146          {
 147              ( $v['active'] ) ? $counts['active']++ : $counts['inactive']++;
 148  
 149              if ( isset( $url_parms['s'] ) )
 150              {
 151                  if ( stripos( $k, $url_parms['s'] ) !== false )
 152                  {
 153                      continue;
 154                  }
 155                  foreach( $v as $kk => $vv )
 156                  {
 157                      if ( stripos( $vv, $url_parms['s'] ) !== false ) continue 2;
 158                  }
 159                  unset( $addons[$k] );
 160              }
 161              if ( isset( $url_parms['status'] ) )
 162              {
 163                  if ( ( $url_parms['status'] == 'inactive' ) && $v['active'] )
 164                  {
 165                      unset( $addons[$k] );
 166                  }
 167                  elseif ( ( $url_parms['status'] == 'active' ) && !$v['active'] )
 168                  {
 169                      unset( $addons[$k] );
 170                  }
 171              }
 172          }
 173          if ( isset( $url_parms['s'] ) )
 174          {
 175              $counts['search'] = count( $addons );
 176          }
 177  
 178          $libs = array(    'all'        => __( 'All' ), 
 179                      'active'    =>    __( 'Active' ), 
 180                      'inactive'    => __( 'Inactive' ),
 181                      'search'    => __( 'Search Results' )
 182          );
 183  
 184          $out = array();
 185  
 186          foreach( $libs as $k => $lib )
 187          {
 188              if ( !isset( $counts[$k] ) || !$counts[$k] )
 189              {
 190                  continue;
 191              }
 192  
 193              $args = array();
 194              if ( ( 'search' == $k ) && ( isset( $url_parms['s'] ) ) )    $args['s'] = $url_parms['s'];
 195              elseif ( 'all' != $k )                             $args['status'] = $k;
 196              $url    = esc_url( add_query_arg( $args, MailPress_addons ) );
 197  
 198              $cls = '';
 199              if ( isset( $url_parms['s'] ) )
 200              {
 201                  if ( 'search' == $k )
 202                  {
 203                      $cls = ' class="current"';
 204                  }
 205              }
 206              elseif ( isset( $url_parms['status'] ) )
 207              {
 208                  if ( $url_parms['status'] == $k )
 209                  {
 210                      $cls = ' class="current"';
 211                  }
 212              }
 213              elseif ( 'all' == $k )
 214              {
 215                  $cls = ' class="current"';
 216              }
 217  
 218              $out[] = sprintf( '<a%1$s href="%2$s">%3$s <span class="count">( %5$s )</span></a>', $cls, $url, $lib, $k, $counts[$k] );
 219          }
 220  
 221          return array( $addons, '<li>' . join( ' | </li><li>', $out ) . '</li>' );
 222      }
 223  
 224  ////  Row  ////
 225  
 226  	public static function get_row( $addon, $url_parms, $xtra = false ) 
 227      {
 228          $context = ( isset( $url_parms['status'] ) ) ? $url_parms['status'] : false;
 229          $actions = array();
 230  // url's
 231          $args = array();
 232          $args['addon']     = $addon['file'];
 233  
 234  // actions
 235          $actions = array();
 236          if ( $addon['active'] )
 237          {
 238              $row_class            = 'active';
 239              $args['action']        = 'deactivate';
 240              $deactivate_url        = esc_url( self::url( MailPress_addons, array_merge( $args, $url_parms ) ) );
 241              $actions['deactivate']= '<a href="' . $deactivate_url . '">' . __( 'Deactivate' ) . '</a>';
 242              $actions = apply_filters( 'plugin_action_links', $actions, $addon['file'], '', '' );
 243          }
 244          else
 245          {
 246              $row_class            = 'inactive';
 247              $args['action']        = 'activate';
 248              $activate_url        = esc_url( self::url( MailPress_addons, array_merge( $args, $url_parms ) ) );
 249              $actions['activate']    = '<a href="' . $activate_url . '">' . __( 'Activate' ) . '</a>';
 250          }
 251  
 252          $out = '';
 253          $out .= '<tr id="' . substr( basename( $addon['file'] ), 0, -4 ) . '" class="' . $row_class . '">';
 254  
 255          $columns = self::get_columns();
 256          $hidden  = self::get_hidden_columns();
 257  
 258          foreach ( $columns as $column_name => $column_display_name ) 
 259          {
 260              $attributes = sprintf( 'class="%1$s column-%1$s%2$s"', $column_name, ( in_array( $column_name, $hidden ) ) ? ' hidden' : '' );
 261  
 262              switch ( $column_name ) 
 263              {
 264                  case 'cb':
 265                      $out .= '<th class="check-column"> <input type="checkbox" name="checked[]" value="' . $addon['file'] . '" /></th>';
 266                  break;
 267                  case 'title':
 268                      $haystack = $addon['Name'];
 269                      $needle   = 'MailPress_';
 270                      if ( strpos( $haystack, $needle ) === 0 ) 
 271                      {
 272                          $haystack = substr( $haystack, strlen( $needle ) );
 273                          $haystack = ucfirst( $haystack );
 274                      }
 275  
 276                      $out .= '<td ' . $attributes . '>';
 277                      $out .= '<strong>' . $haystack . '</strong>';
 278                      $out .= self::get_actions( $actions, 'row-actions-visible' );
 279                      $out .= '</td>';
 280                  break;
 281                  case 'desc':
 282                      $haystack = $addon['Description'];
 283                      $needle   = 'This is just an add-on for MailPress to ';
 284                      if ( strpos( $haystack, $needle ) === 0 ) 
 285                      {
 286                          $haystack = substr( $haystack, strlen( $needle ) );
 287                          $haystack = ucfirst( $haystack );
 288                      }
 289  
 290                      $addon_meta = array();
 291                      if ( !empty( $addon['Version'] ) )
 292                      {
 293                          $addon_meta[] = sprintf( __( 'Version %s' ), $addon['Version'] );
 294                      }
 295                      if ( !empty( $addon['Author'] ) ) 
 296                      {
 297                          $author = $addon['Author'];
 298                          if ( !empty( $addon['AuthorURI'] ) )
 299                          {
 300                              $author = '<a href="' . $addon['AuthorURI'] . '">' . $addon['Author'] . '</a>';
 301                          }
 302                          $addon_meta[] = sprintf( __( 'By %s' ), $author );
 303                      }
 304                      if ( ! empty( $addon['PluginURI'] ) )
 305                      {
 306                          $addon_meta[] = '<a href="' . $addon['PluginURI'] . '">' . __( 'Visit add-on page', 'MailPress' ) . '</a>';
 307                      }
 308  
 309                      $out .= '<td ' . $attributes . '>';
 310                      $out .= '<p>' . $haystack . '</p>';
 311                      $out .= implode( ' | ', $addon_meta );
 312                      $out .= '</td>';
 313                  break;
 314              }
 315          }
 316          $out .= '</tr>';
 317  
 318          return $out;
 319      }
 320  }


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