get_plugin_data() and get_plugins()

git-svn-id: http://svn.automattic.com/wordpress/trunk@1887 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-11-26 02:29:45 +00:00
parent 8b9b4d71da
commit a4c058f2c8
2 changed files with 77 additions and 42 deletions

View File

@ -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 = __("<a href='{$plugin_uri[1]}' title='Visit plugin homepage'>{$plugin}</a>");
}
if ('' == $author_uri[1]) {
$author = $author_name[1];
} else {
$author = __("<a href='{$author_uri[1]}' title='Visit author homepage'>{$author_name[1]}</a>");
}
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;
}
?>

View File

@ -51,19 +51,13 @@ foreach ($check_plugins as $check_plugin) {
<h2><?php _e('Plugin Management'); ?></h2>
<p><?php _e('Plugins are files you usually download separately from WordPress that add functionality. To install a plugin you generally just need to put the plugin file into your <code>wp-content/plugins</code> directory. Once a plugin is installed, you may activate it or deactivate it here. If something goes wrong with a plugin and you can&#8217;t use WordPress, delete that plugin from the <code>wp-content/plugins</code> directory and it will be automatically deactivated.'); ?></p>
<?php
// Files in wp-content/plugins directory
$plugins_dir = @ dir(ABSPATH . 'wp-content/plugins');
if ($plugins_dir) {
while(($file = $plugins_dir->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("<p>Couldn't open plugins directory or there are no plugins available.</p>"); // TODO: make more helpful
} else {
?>
@ -76,36 +70,8 @@ if (!$plugins_dir || !$plugin_files) {
<th><?php _e('Action'); ?></th>
</tr>
<?php
sort($plugin_files); // Alphabetize by filename. Better way?
$style = '';
foreach($plugin_files as $plugin_file) {
$plugin_data = implode('', file(ABSPATH . '/wp-content/plugins/' . $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]);
if ('' == $plugin_uri) {
$plugin = $plugin_name[1];
} else {
$plugin = __("<a href='{$plugin_uri[1]}' title='Visit plugin homepage'>{$plugin_name[1]}</a>");
}
if ('' == $author_uri) {
$author = $author_name[1];
} else {
$author = __("<a href='{$author_uri[1]}' title='Visit author homepage'>{$author_name[1]}</a>");
}
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 "
<tr $style>
<td>$plugin</td>
<td>$version</td>
<td>$author</td>
<td>$description</td>
<td>{$plugin_data['Title']}</td>
<td>{$plugin_data['Version']}</td>
<td>{$plugin_data['Author']}</td>
<td>{$plugin_data['Description']}</td>
<td>$action</td>
</tr>";
}