[wp-cvs] wordpress/wp-admin admin-functions.php, 1.57, 1.58 plugins.php, 1.17, 1.18

Ryan Boren rboren at users.sourceforge.net
Fri Nov 26 02:29:47 UTC 2004


Update of /cvsroot/cafelog/wordpress/wp-admin
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26565/wp-admin

Modified Files:
	admin-functions.php plugins.php 
Log Message:
get_plugin_data() and get_plugins()

Index: plugins.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/plugins.php,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** plugins.php	19 Oct 2004 03:03:05 -0000	1.17
--- plugins.php	26 Nov 2004 02:29:45 -0000	1.18
***************
*** 52,68 ****
  <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) {
  	_e("<p>Couldn't open plugins directory or there are no plugins available.</p>"); // TODO: make more helpful
  } else {
--- 52,62 ----
  <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
  
  if ( get_settings('active_plugins') )
  	$current_plugins = get_settings('active_plugins');
  
! $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 {
***************
*** 77,110 ****
  	</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>");
! 		}
! 
! 
! 
  		$style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
  
--- 71,76 ----
  	</tr>
  <?php
  	$style = '';
! 	foreach($plugins as $plugin_file => $plugin_data) {
  		$style = ('class="alternate"' == $style) ? '' : 'class="alternate"';
  
***************
*** 117,124 ****
  		echo "
  	<tr $style>
! 		<td>$plugin</td>
! 		<td>$version</td>
! 		<td>$author</td>
! 		<td>$description</td>
  		<td>$action</td>
  	</tr>";
--- 83,90 ----
  		echo "
  	<tr $style>
! 		<td>{$plugin_data['Title']}</td>
! 		<td>{$plugin_data['Version']}</td>
! 		<td>{$plugin_data['Author']}</td>
! 		<td>{$plugin_data['Description']}</td>
  		<td>$action</td>
  	</tr>";

Index: admin-functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/admin-functions.php,v
retrieving revision 1.57
retrieving revision 1.58
diff -C2 -d -r1.57 -r1.58
*** admin-functions.php	26 Nov 2004 01:50:36 -0000	1.57
--- admin-functions.php	26 Nov 2004 02:29:45 -0000	1.58
***************
*** 840,842 ****
--- 840,911 ----
  }
  
+ 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;
+ }
+ 
  ?>
\ No newline at end of file




More information about the cvs mailing list