[ Index ]

MailPress 544

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

title

Body

[close]

/mp-includes/class/ -> MP_Addons.class.php (source)

   1  <?php
   2  class MP_Addons
   3  {
   4      const option_name = 'MailPress_add-ons';
   5      const folder      = 'add-ons';
   6  
   7  	function __construct()
   8      {
   9          $new = array();
  10          $old = get_option(self::option_name);
  11  
  12          foreach (self::get_all() as $mp_addon)
  13          {
  14              if (!$mp_addon['active'])         continue;
  15              if (!self::load($mp_addon['file'])) continue;
  16  
  17              $new[$mp_addon['file']] = $mp_addon['file'];
  18          }
  19  
  20          if ($new != $old) update_option(self::option_name, $new);
  21  
  22          do_action('MailPress_addons_loaded');
  23      }
  24  
  25  	public static function load($file)
  26      {
  27          $file = ABSPATH . PLUGINDIR . "/$file";
  28  
  29          if (!is_file($file)) return false;
  30          require_once($file);
  31          return true;
  32      }
  33  
  34  	public static function get_all($addon_folder = '')
  35      {
  36          if ( ! $cache_addons = wp_cache_get('mp_addons', 'mp_addons') ) $cache_addons = array();
  37          if ( isset($cache_addons[ $addon_folder ]) ) return $cache_addons[ $addon_folder ];
  38  
  39          $mp_addons = array ();
  40          $addon_root = MP_CONTENT_DIR . self::folder;
  41          if( !empty($addon_folder) ) $addon_root .= $addon_folder;
  42  
  43          // Files in addons directory
  44          $addon_files = array();
  45  
  46          $addons_dir = @opendir( $addon_root);
  47          if ( $addons_dir ) 
  48          {
  49              while (($file = readdir( $addons_dir ) ) !== false ) 
  50              {
  51                  if ( substr($file, 0, 1) == '.' ) continue;
  52                  if ( is_dir( "$addon_root/$file" ) ) 
  53                  {
  54                      $addons_subdir = @opendir( "$addon_root/$file" );
  55                      if ( $addons_subdir ) 
  56                      {
  57                          while (($subfile = readdir( $addons_subdir ) ) !== false ) 
  58                          {
  59                              if ( substr($subfile, 0, 1) == '.' ) continue;
  60                              if ( substr($subfile, -4) == '.php' ) $addon_files[] = plugin_basename("$addon_root/$file/$subfile");
  61                          }
  62                          @closedir( $addons_subdir );
  63                      }
  64                  } 
  65                  else 
  66                  {
  67                      if ( substr($file, -4) == '.php' ) $addon_files[] = plugin_basename("$addon_root/$file");
  68                  }
  69              }
  70              @closedir( $addons_dir );
  71          }
  72          if ( empty($addon_files) ) return $mp_addons;
  73  
  74          $active = get_option(self::option_name);
  75          if (!is_array($active)) $active = array();
  76  
  77          foreach ( $addon_files as $addon_file ) 
  78          {
  79              $file = ABSPATH . PLUGINDIR . "/$addon_file";
  80              if ( !is_readable( $file ) ) continue;
  81              $addon_data = self::get_addon_data( $file, false, false ); //Do not apply markup/translate as it'll be cached.
  82              if ( empty ( $addon_data['Name'] ) ) continue;
  83  
  84              $addon_data['file'] = plugin_basename( $file ) ;
  85              $addon_data['active'] = (isset($active[plugin_basename( $file )])) ;
  86  
  87              $mp_addons[plugin_basename( $file )] = $addon_data;
  88          }
  89          uasort( $mp_addons, create_function( '$a, $b', 'return strnatcasecmp( $a["Name"], $b["Name"] );' ));
  90          $cache_addons[ $addon_folder ] = $mp_addons;
  91          wp_cache_set('mp_addons', $cache_addons, 'mp_addons');
  92  
  93          return $mp_addons;
  94      }
  95  
  96  	public static function get_addon_data( $addon_file ) 
  97      {
  98          $default_headers = array(     'Name'         => 'Plugin Name', 
  99                              'PluginURI'     => 'Plugin URI', 
 100                              'Version'         => 'Version', 
 101                              'Description'     => 'Description', 
 102                              'Author'         => 'Author', 
 103                              'AuthorURI'     => 'Author URI', 
 104                              'TextDomain'     => 'Text Domain', 
 105                              'DomainPath'     => 'Domain Path'
 106          );
 107  
 108          $addon_data = get_file_data( $addon_file, $default_headers, 'mp_addon' );
 109  
 110          //For backward compatibility by default Title is the same as Name.
 111          $addon_data['Title'] = $addon_data['Name'];
 112  
 113          return $addon_data;
 114      }
 115  }


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