diff -r 27377179fe58 -r 4f9bec0d65c1 includes/plugins.php --- a/includes/plugins.php Wed Jul 02 19:36:44 2008 -0400 +++ b/includes/plugins.php Wed Jul 02 22:15:55 2008 -0400 @@ -288,89 +288,13 @@ // it's a PHP file, attempt to read metadata $fullpath = ENANO_ROOT . "/plugins/$dh"; - // first can we use cached info? - if ( isset($plugins_cache[$dh]) && $plugins_cache[$dh]['file md5'] === $this->md5_header($fullpath) ) - { - $plugin_meta = $plugins_cache[$dh]; - } - else + $plugin_meta = $this->get_plugin_info($fullpath); + + if ( is_array($plugin_meta) ) { - // the cache is out of date if we reached here -- regenerate - if ( $use_cache ) - $this->generate_plugins_cache(); - - // pass 1: try to read a !info block - $blockdata = $this->parse_plugin_blocks($fullpath, 'info'); - if ( empty($blockdata) ) - { - // no !info block, check for old header - $fh = @fopen($fullpath, 'r'); - if ( !$fh ) - // can't read, bail out - continue; - $plugin_data = array(); - for ( $i = 0; $i < 8; $i++ ) - { - $plugin_data[] = @fgets($fh, 8096); - } - // close our file handle - fclose($fh); - // is the header correct? - if ( trim($plugin_data[0]) != ' $value ) - { - $plugin_meta[ strtolower($key) ] = $value; - } - } + // all checks passed + $plugin_list[$dh] = $plugin_meta; } - if ( !isset($plugin_meta) || !is_array(@$plugin_meta) ) - { - // parsing didn't work. - continue; - } - // check for required keys - $required_keys = array('plugin name', 'plugin uri', 'description', 'author', 'version', 'author uri'); - foreach ( $required_keys as $key ) - { - if ( !isset($plugin_meta[$key]) ) - // not set, skip this plugin - continue 2; - } - // decide if it's a system plugin - $plugin_meta['system plugin'] = in_array($dh, $this->system_plugins); - // reset installed variable - $plugin_meta['installed'] = false; - $plugin_meta['status'] = 0; - // all checks passed - $plugin_list[$dh] = $plugin_meta; } } // gather info about installed plugins @@ -408,6 +332,103 @@ } /** + * Retrieves the metadata block from a plugin file + * @param string Path to plugin file (full path) + * @return array + */ + + function get_plugin_info($fullpath) + { + global $plugins_cache; + $dh = basename($fullpath); + + // first can we use cached info? + if ( isset($plugins_cache[$dh]) && $plugins_cache[$dh]['file md5'] === $this->md5_header($fullpath) ) + { + $plugin_meta = $plugins_cache[$dh]; + } + else + { + // the cache is out of date if we reached here -- regenerate + if ( $use_cache ) + $this->generate_plugins_cache(); + + // pass 1: try to read a !info block + $blockdata = $this->parse_plugin_blocks($fullpath, 'info'); + if ( empty($blockdata) ) + { + // no !info block, check for old header + $fh = @fopen($fullpath, 'r'); + if ( !$fh ) + // can't read, bail out + return false; + $plugin_data = array(); + for ( $i = 0; $i < 8; $i++ ) + { + $plugin_data[] = @fgets($fh, 8096); + } + // close our file handle + fclose($fh); + // is the header correct? + if ( trim($plugin_data[0]) != ' $value ) + { + $plugin_meta[ strtolower($key) ] = $value; + } + } + } + if ( !isset($plugin_meta) || !is_array(@$plugin_meta) ) + { + // parsing didn't work. + return false; + } + // check for required keys + $required_keys = array('plugin name', 'plugin uri', 'description', 'author', 'version', 'author uri'); + foreach ( $required_keys as $key ) + { + if ( !isset($plugin_meta[$key]) ) + // not set, skip this plugin + return false; + } + // decide if it's a system plugin + $plugin_meta['system plugin'] = in_array($dh, $this->system_plugins); + // reset installed variable + $plugin_meta['installed'] = false; + $plugin_meta['status'] = 0; + + return $plugin_meta; + } + + + /** * Attempts to cache plugin information in a file to speed fetching. */