includes/plugins.php
changeset 607 935f3799b654
parent 601 9c1f07ae26d5
child 613 c08670a77871
equal deleted inserted replaced
605:d2d4e40ecd29 607:935f3799b654
   444       $info['file md5'] = $this->md5_header(ENANO_ROOT . "/plugins/$plugin");
   444       $info['file md5'] = $this->md5_header(ENANO_ROOT . "/plugins/$plugin");
   445     }
   445     }
   446     
   446     
   447     $this->update_plugins_cache($plugin_info);
   447     $this->update_plugins_cache($plugin_info);
   448     $GLOBALS['plugins_cache'] = $plugin_info;
   448     $GLOBALS['plugins_cache'] = $plugin_info;
   449     @define('ENANO_PLUGINS_CACHE_LOADED', true);
       
   450   }
   449   }
   451   
   450   
   452   /**
   451   /**
   453    * Writes an information array to the cache file.
   452    * Writes an information array to the cache file.
   454    * @param array
   453    * @param array
   455    * @access private
   454    * @access private
   456    */
   455    */
   457   
   456   
   458   function update_plugins_cache($plugin_info)
   457   function update_plugins_cache($plugin_info)
   459   {
   458   {
   460     $plugin_info = Language::var_export_string($plugin_info);
   459     global $cache;
   461     
   460     return $cache->store('plugins', $plugin_info, -1);
   462     $file = ENANO_ROOT . '/cache/cache_plugins.php';
       
   463     $fh = @fopen($file, 'w');
       
   464     if ( !$fh )
       
   465       // can't open for writing
       
   466       return false;
       
   467       
       
   468     $contents = <<<EOF
       
   469 <?php
       
   470 /**
       
   471  * Cache of plugin files. Automatically generated, any modifications will soon be lost
       
   472  */
       
   473 
       
   474 @define('ENANO_PLUGINS_CACHE_LOADED', true);
       
   475 \$GLOBALS['plugins_cache'] = $plugin_info;
       
   476 
       
   477 EOF;
       
   478     fwrite($fh, $contents);
       
   479     fclose($fh);
       
   480   }
   461   }
   481   
   462   
   482   /**
   463   /**
   483    * Loads the plugins cache if any.
   464    * Loads the plugins cache if any.
   484    */
   465    */
   485   
   466   
   486   function load_plugins_cache()
   467   function load_plugins_cache()
   487   {
   468   {
   488     if ( file_exists(ENANO_ROOT . '/cache/cache_plugins.php') && !defined('ENANO_PLUGINS_CACHE_LOADED') )
   469     global $cache;
   489     {
   470     if ( $data = $cache->fetch('plugins') )
   490       require(ENANO_ROOT . '/cache/cache_plugins.php');
   471     {
       
   472       $GLOBALS['plugins_cache'] = $data;
   491     }
   473     }
   492   }
   474   }
   493   
   475   
   494   /**
   476   /**
   495    * Calculates the MD5 sum of the first 10 lines of a file. Useful for caching plugin header information.
   477    * Calculates the MD5 sum of the first 10 lines of a file. Useful for caching plugin header information.