From a4c058f2c8fa309fa2d3c97b49ae20edf0b1438e Mon Sep 17 00:00:00 2001 From: rboren Date: Fri, 26 Nov 2004 02:29:45 +0000 Subject: [PATCH] get_plugin_data() and get_plugins() git-svn-id: http://svn.automattic.com/wordpress/trunk@1887 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-functions.php | 69 ++++++++++++++++++++++++++++++++++++ wp-admin/plugins.php | 50 +++++--------------------- 2 files changed, 77 insertions(+), 42 deletions(-) diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 7b332bf1db..0e5998af2f 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -839,4 +839,73 @@ function update_recently_edited($file) { update_option('recently_edited', $oldfiles); } +function get_plugin_data($plugin_file) { + $plugin_data = implode('', file($plugin_file)); + preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name); + preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri); + preg_match("|Description:(.*)|i", $plugin_data, $description); + preg_match("|Author:(.*)|i", $plugin_data, $author_name); + preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri); + if ( preg_match("|Version:(.*)|i", $plugin_data, $version) ) + $version = $version[1]; + else + $version =''; + + $description = wptexturize($description[1]); + + $name = $plugin_name[1]; + $name = trim($name); + $plugin = $name; + if ('' != $plugin_uri[1] && '' != $name) { + $plugin = __("{$plugin}"); + } + + if ('' == $author_uri[1]) { + $author = $author_name[1]; + } else { + $author = __("{$author_name[1]}"); + } + + return array('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]); +} + +function get_plugins() { + global $wp_plugins; + + if (isset($wp_plugins)) { + return $wp_plugins; + } + + $wp_plugins = array(); + $plugin_loc = 'wp-content/plugins'; + $plugin_root = ABSPATH . $plugin_loc; + + // Files in wp-content/plugins directory + $plugins_dir = @ dir($plugin_root); + if ($plugins_dir) { + while(($file = $plugins_dir->read()) !== false) { + if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) + $plugin_files[] = $file; + } + } + + if (!$plugins_dir || !$plugin_files) { + return $wp_plugins; + } + + sort($plugin_files); + + foreach($plugin_files as $plugin_file) { + $plugin_data = get_plugin_data("$plugin_root/$plugin_file"); + + if (empty($plugin_data['Name'])) { + continue; + } + + $wp_plugins[basename($plugin_file)] = $plugin_data; + } + + return $wp_plugins; +} + ?> \ No newline at end of file diff --git a/wp-admin/plugins.php b/wp-admin/plugins.php index acfc6a9f84..a4a3e4ae06 100644 --- a/wp-admin/plugins.php +++ b/wp-admin/plugins.php @@ -51,19 +51,13 @@ foreach ($check_plugins as $check_plugin) {

wp-content/plugins directory. Once a plugin is installed, you may activate it or deactivate it here. If something goes wrong with a plugin and you can’t use WordPress, delete that plugin from the wp-content/plugins directory and it will be automatically deactivated.'); ?>

read()) !== false) { - if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) - $plugin_files[] = $file; - } -} if ( get_settings('active_plugins') ) $current_plugins = get_settings('active_plugins'); -if (!$plugins_dir || !$plugin_files) { +$plugins = get_plugins(); + +if (empty($plugins)) { _e("

Couldn't open plugins directory or there are no plugins available.

"); // TODO: make more helpful } else { ?> @@ -76,36 +70,8 @@ if (!$plugins_dir || !$plugin_files) { {$plugin_name[1]}"); - } - - if ('' == $author_uri) { - $author = $author_name[1]; - } else { - $author = __("{$author_name[1]}"); - } - - - + foreach($plugins as $plugin_file => $plugin_data) { $style = ('class="alternate"' == $style) ? '' : 'class="alternate"'; if (!empty($current_plugins) && in_array($plugin_file, $current_plugins)) { @@ -116,10 +82,10 @@ if (!$plugins_dir || !$plugin_files) { } echo " - $plugin - $version - $author - $description + {$plugin_data['Title']} + {$plugin_data['Version']} + {$plugin_data['Author']} + {$plugin_data['Description']} $action "; }