[ Index ]

MailPress 544

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

title

Body

[close]

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

   1  <?php
   2  class MP_AdminPage extends MP_adminpage_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          if     ( !empty($_REQUEST['action'])  && ($_REQUEST['action']  != -1))    $action = $_REQUEST['action'];
  16          elseif ( !empty($_REQUEST['action2']) && ($_REQUEST['action2'] != -1) )    $action = $_REQUEST['action2'];
  17          if (!isset($action)) return;
  18  
  19          $addons = get_option(MP_Addons::option_name);
  20          if (!is_array($addons)) $addons = array();
  21  
  22          $url_parms     = self::get_url_parms(array('status', 's'));
  23          $checked    = (isset($_GET['checked'])) ? $_GET['checked'] : array();
  24  
  25          $count    = str_replace('bulk-', '', $action);
  26          $count     .= 'd';
  27          $$count    = 0;
  28  
  29          switch($action)
  30          {
  31              case 'bulk-activate' :
  32                  foreach($checked as $addon)
  33                  {
  34                      if (isset($addons[$addon])) continue;
  35                      if (MP_Addons::load($addon))
  36                      {
  37                          $addons[$addon] = $addon;
  38                          do_action('activate_' . $addon);
  39                          $$count++;
  40                      }
  41                  }
  42              break;
  43              case 'bulk-deactivate' :
  44                  foreach($checked as $addon)
  45                  {
  46                      if (!isset($addons[$addon])) continue;
  47                      unset($addons[$addon]);
  48                      do_action('deactivate_' . $addon);
  49                      $$count++;
  50                  }
  51              break;
  52              case 'activate' :
  53                  $addon = $_GET['addon'];
  54                  if (isset($addons[$addon])) break;
  55                  if (MP_Addons::load($addon))
  56                  {
  57                      $addons[$addon] = $addon;
  58                      do_action('activate_' . $addon);
  59                      $$count++;
  60                  }
  61              break;
  62              case 'deactivate' :
  63                  $addon = $_GET['addon'];
  64                  if (!isset($addons[$addon])) break;
  65                  unset($addons[$addon]);
  66                  do_action('deactivate_' . $addon);
  67                  $$count++;
  68              break;
  69          }
  70          ksort($addons);
  71  
  72          update_option(MP_Addons::option_name, $addons);
  73  
  74          if ($$count) $url_parms[$count] = $$count;
  75          self::mp_redirect( self::url(MailPress_addons, $url_parms) );
  76      }
  77  
  78  //// Columns ////
  79  
  80  	public static function get_columns() 
  81      {
  82          $columns = array(    'cb'         => "<input type='checkbox' />", 
  83                      'title'     => __('Add-on', MP_TXTDOM), 
  84                      'desc'     => __('Description') );
  85          $columns = apply_filters('MailPress_addons_columns', $columns);
  86          return $columns;
  87      }
  88  
  89  //// List ////
  90  
  91  	public static function get_list($args) 
  92      {
  93          extract( $args );
  94  
  95          $addons = MP_Addons::get_all();
  96  
  97          $counts['active'] = $counts['inactive'] = $counts['search'] = 0;
  98  
  99          $counts['all'] = count($addons);
 100          foreach($addons as $k => $v)
 101          {
 102              ($v['active']) ? $counts['active']++ : $counts['inactive']++;
 103              if (isset($url_parms['s']))
 104              {
 105                  if (stripos($k, $url_parms['s']) !== false) continue;
 106                  foreach($v as $kk => $vv)
 107                  {
 108                      if (stripos($vv, $url_parms['s']) !== false) continue 2;
 109                  }
 110                  unset($addons[$k]);
 111              }
 112              if (isset($url_parms['status']))
 113              {
 114                  if (($url_parms['status'] == 'inactive') && $v['active'])         unset($addons[$k]);
 115                  elseif (($url_parms['status'] == 'active') && !$v['active'])     unset($addons[$k]);
 116              }
 117          }
 118          if (isset($url_parms['s'])) $counts['search'] = count($addons);
 119  
 120          $libs = array( 'all' => __('All'), 'active' =>    __('Active'), 'inactive' => __('Inactive'), 'search' => __('Search Results') );
 121          foreach($libs as $k => $lib)
 122          {
 123              if (!isset($counts[$k]) || !$counts[$k]) continue;
 124              $cls = '';
 125              if (isset($url_parms['s']))            { if ('search' == $k)                 $cls = " class='current'"; }
 126              elseif (isset($url_parms['status'])) { if ($url_parms['status'] == $k )      $cls = " class='current'"; }
 127              elseif ('all' == $k)                                        $cls = " class='current'"; 
 128                  $url = MailPress_addons . ( ('search' == $k) ? '&amp;s=' . $url_parms['s'] : ( ('all' == $k) ? '' : "&amp;status=$k" ) );
 129              $sum = $counts[$k];
 130              $out[] = "<a$cls href='$url'>$lib <span class='count'>($sum)</span></a>";
 131          }
 132  
 133          return array($addons, '<li>' . join( ' | </li><li>', $out ) . '</li>');
 134      }
 135  
 136  ////  Row  ////
 137  
 138  	public static function get_row( $addon, $url_parms, $xtra = false) 
 139      {
 140          $context = (isset($url_parms['status'])) ? $url_parms['status'] : false;
 141          $actions = array();
 142  // url's
 143          $args = array();
 144          $args['addon']     = $addon['file'];
 145  
 146  // actions
 147          $actions = array();
 148          if ($addon['active'])
 149          {
 150              $row_class         = 'active';
 151              $args['action']     = 'deactivate';
 152              $deactivate_url     = esc_url(self::url( MailPress_addons, array_merge($args, $url_parms) ));
 153              $actions['deactivate']    = "<a href='$deactivate_url'       title='" .  __('Deactivate') . "'>" . __('Deactivate') . '</a>';
 154              $actions = apply_filters('plugin_action_links', $actions, $addon['file'], '', '' );
 155          }
 156          else
 157          {
 158              $row_class         = 'inactive';
 159              $args['action']     = 'activate';
 160              $activate_url     = esc_url(self::url( MailPress_addons, array_merge($args, $url_parms) ));
 161              $actions['activate']    = "<a href='$activate_url'       title='" .  __('Activate') . "'>" . __('Activate') . '</a>';
 162          }
 163  ?>
 164      <tr class='<?php echo $row_class; ?>'>
 165  <?php
 166          $columns = self::get_columns();
 167          $hidden  = self::get_hidden_columns();
 168  
 169          foreach ( $columns as $column_name => $column_display_name ) 
 170          {
 171              $class = "class='$column_name column-$column_name'";
 172  
 173              $style = '';
 174              if ( in_array($column_name, $hidden) )     $style .= 'display:none;';
 175              $style = ' style="' . $style . '"';
 176  
 177              $attributes = "$class$style";
 178  
 179              switch ($column_name) 
 180              {
 181  
 182                  case 'cb':
 183  ?>
 184          <th class='check-column'>
 185              <input type='checkbox' name='checked[]' value="<?php echo $addon['file']; ?>" />
 186          </th>
 187  <?php
 188                  break;
 189                  case 'title':
 190                      $haystack = $addon['Name'];
 191                      $needle   = 'MailPress_';
 192                      if (strpos($haystack, $needle) === 0) 
 193                      {
 194                          $haystack = substr($haystack, strlen($needle));
 195                          $haystack = ucfirst($haystack);
 196                      }
 197  ?>
 198          <td  <?php echo $attributes ?>>
 199  <?php
 200                      echo "<strong>{$haystack}</strong>";
 201                      echo self::get_actions($actions, 'row-actions-visible'); ?>
 202          </td>
 203  <?php
 204                  break;
 205                  case 'desc':
 206                      $haystack = $addon['Description'];
 207                      $needle   = 'This is just an add-on for MailPress to ';
 208                      if (strpos($haystack, $needle) === 0) 
 209                      {
 210                          $haystack = substr($haystack, strlen($needle));
 211                          $haystack = ucfirst($haystack);
 212                      }
 213  ?>
 214          <td  <?php echo $attributes ?>>      
 215  <?php
 216                      echo "<p>{$haystack}</p>";
 217                      $addon_meta = array();
 218                      if ( !empty($addon['Version']) )
 219                      $addon_meta[] = sprintf(__('Version %s'), $addon['Version']);
 220                      if ( !empty($addon['Author']) ) 
 221                      {
 222                          $author = $addon['Author'];
 223                          if ( !empty($addon['AuthorURI']) )
 224                              $author = '<a href="' . $addon['AuthorURI'] . '" title="' . __( 'Visit author homepage' ) . '">' . $addon['Author'] . '</a>';
 225                          $addon_meta[] = sprintf( __('By %s'), $author );
 226                      }
 227                      if ( ! empty($addon['PluginURI']) )
 228                          $addon_meta[] = '<a href="' . $addon['PluginURI'] . '" title="' . __( 'Visit add-on page', MP_TXTDOM ) . '">' . __('Visit add-on page', MP_TXTDOM ) . '</a>';
 229                      echo implode(' | ', $addon_meta);
 230  ?>
 231          </td>
 232  <?php
 233                  break;
 234                  default:
 235  ?>
 236          <td  <?php echo $attributes ?>>
 237              <?php    do_action('MailPress_addons_get_row', $column_name, $addon, $url_parms); ?>
 238          </td>
 239  <?php
 240                  break;
 241              }
 242          }
 243  ?>
 244        </tr>
 245  <?php
 246      }
 247  }


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