includes/plugins.php
changeset 975 bff25c6113ae
parent 953 323c4cd1aa37
child 979 aafb9f6806c9
equal deleted inserted replaced
974:6bfe9eb428e9 975:bff25c6113ae
    73       return false;
    73       return false;
    74     }
    74     }
    75     
    75     
    76     $dir = ENANO_ROOT.'/plugins/';
    76     $dir = ENANO_ROOT.'/plugins/';
    77     
    77     
    78     $this->load_list = $this->system_plugins;
    78     $plugin_list = $this->get_plugin_list();
    79     $q = $db->sql_query('SELECT plugin_filename, plugin_version FROM ' . table_prefix . 'plugins WHERE plugin_flags & ~' . PLUGIN_DISABLED . ' = plugin_flags;');
    79     $this->load_list = array();
    80     if ( !$q )
    80     
    81       $db->_die();
    81     foreach ( $plugin_list as $filename => $data )
    82     
    82     {
    83     while ( $row = $db->fetchrow() )
    83       if ( $data['status'] & PLUGIN_OUTOFDATE || $data['status'] & PLUGIN_DISABLED )
    84     {
       
    85       if ( file_exists(ENANO_ROOT . "/plugins/{$row['plugin_filename']}") )
       
    86       {
       
    87         $this->load_list[] = $row['plugin_filename'];
       
    88       }
       
    89     }
       
    90     $this->load_list = array_unique($this->load_list);
       
    91     
       
    92     $this->loaded_plugins = $this->get_plugin_list($this->load_list);
       
    93     
       
    94     // check for out-of-date plugins
       
    95     foreach ( $this->load_list as $i => $plugin )
       
    96     {
       
    97       if ( in_array($plugin, $this->system_plugins) )
       
    98         continue;
    84         continue;
    99       
    85       
   100       if ( $this->loaded_plugins[$plugin]['status'] & PLUGIN_OUTOFDATE )
    86       $this->load_list[] = $filename;
   101       {
    87       $this->loaded_plugins[$filename] = $data;
   102         // it's out of date, don't load
    88     }
   103         unset($this->load_list[$i]);
       
   104         unset($this->loaded_plugins[$plugin]);
       
   105       }
       
   106     }
       
   107     
       
   108     $this->load_list = array_unique($this->load_list);
       
   109   }
    89   }
   110   
    90   
   111   /**
    91   /**
   112    * Name kept for compatibility. This method is used to add a new hook into the code somewhere. Plugins are encouraged
    92    * Name kept for compatibility. This method is used to add a new hook into the code somewhere. Plugins are encouraged
   113    * to set hooks and hook into other plugins in a fail-safe way, this encourages reuse of code. Returns an array, whose
    93    * to set hooks and hook into other plugins in a fail-safe way, this encourages reuse of code. Returns an array, whose
   273     // Scan all plugins
   253     // Scan all plugins
   274     $plugin_list = array();
   254     $plugin_list = array();
   275     $ta = 0;
   255     $ta = 0;
   276     // won't load twice (failsafe automatic skip)
   256     // won't load twice (failsafe automatic skip)
   277     $this->load_plugins_cache();
   257     $this->load_plugins_cache();
   278     if ( $use_cache )
   258     global $plugins_cache;
   279     {
   259     if ( $use_cache && !empty($plugins_cache) )
   280       global $plugins_cache;
   260     {
       
   261       return $plugins_cache;
   281     }
   262     }
   282     else
   263     else
   283     {
   264     {
   284       // blank array - effectively skips importing the cache
   265       // blank array - effectively skips importing the cache
   285       $plugins_cache = array();
   266       $plugins_cache = array();
   286     }
   267     }
   287     
   268     
       
   269     // List all plugins
   288     if ( $dirh = @opendir( ENANO_ROOT . '/plugins' ) )
   270     if ( $dirh = @opendir( ENANO_ROOT . '/plugins' ) )
   289     {
   271     {
   290       while ( $dh = @readdir($dirh) )
   272       while ( $dh = @readdir($dirh) )
   291       {
   273       {
   292         if ( !preg_match('/\.php$/i', $dh) )
   274         if ( !preg_match('/\.php$/i', $dh) )
   296           if ( !in_array($dh, $restrict) )
   278           if ( !in_array($dh, $restrict) )
   297             continue;
   279             continue;
   298           
   280           
   299         // it's a PHP file, attempt to read metadata
   281         // it's a PHP file, attempt to read metadata
   300         $fullpath = ENANO_ROOT . "/plugins/$dh";
   282         $fullpath = ENANO_ROOT . "/plugins/$dh";
   301         $plugin_meta = $this->get_plugin_info($fullpath, $use_cache);
   283         $plugin_meta = $this->read_plugin_headers($fullpath, $use_cache);
   302         
   284         
   303         if ( is_array($plugin_meta) )
   285         if ( is_array($plugin_meta) )
   304         {
   286         {
   305           // all checks passed
   287           // all checks passed
   306           $plugin_list[$dh] = $plugin_meta;
   288           $plugin_list[$dh] = $plugin_meta;
   307         }
   289         }
   308       }
   290       }
   309     }
   291     }
   310     // gather info about installed plugins
   292     
       
   293     // Populate with additional metadata from database
   311     $q = $db->sql_query('SELECT plugin_id, plugin_filename, plugin_version, plugin_flags FROM ' . table_prefix . 'plugins;');
   294     $q = $db->sql_query('SELECT plugin_id, plugin_filename, plugin_version, plugin_flags FROM ' . table_prefix . 'plugins;');
   312     if ( !$q )
   295     if ( !$q )
   313       $db->_die();
   296       $db->_die();
   314     while ( $row = $db->fetchrow() )
   297     while ( $row = $db->fetchrow() )
   315     {
   298     {
   345    * Retrieves the metadata block from a plugin file
   328    * Retrieves the metadata block from a plugin file
   346    * @param string Path to plugin file (full path)
   329    * @param string Path to plugin file (full path)
   347    * @return array
   330    * @return array
   348    */
   331    */
   349   
   332   
   350   function get_plugin_info($fullpath, $use_cache = true)
   333   function read_plugin_headers($fullpath, $use_cache = true)
   351   {
   334   {
   352     global $plugins_cache;
   335     global $plugins_cache;
   353     $dh = basename($fullpath);
   336     $dh = basename($fullpath);
   354     
   337     
   355     // first can we use cached info?
   338     // first can we use cached info?
   526   {
   509   {
   527     $filename = ENANO_ROOT . '/plugins/' . $filename;
   510     $filename = ENANO_ROOT . '/plugins/' . $filename;
   528     if ( !file_exists($filename) )
   511     if ( !file_exists($filename) )
   529       return false;
   512       return false;
   530     
   513     
   531     $info = $this->get_plugin_info($filename);
   514     $info = $this->read_plugin_headers($filename);
   532     if ( isset($info['auth plugin']) )
   515     if ( isset($info['auth plugin']) )
   533       return true;
   516       return true;
   534     
   517     
   535     $contents = @file_get_contents($filename);
   518     $contents = @file_get_contents($filename);
   536     if ( strstr($contents, 'login_process_userdata_json') )
   519     if ( strstr($contents, 'login_process_userdata_json') )