[wp-cvs] wordpress/wp-admin admin-functions.php,1.49,1.50

Ryan Boren rboren at users.sourceforge.net
Thu Oct 14 03:54:59 UTC 2004


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

Modified Files:
	admin-functions.php 
Log Message:
Move get_theme*() from admin-functions to functions so that templates and plugins can use them.

Index: admin-functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/admin-functions.php,v
retrieving revision 1.49
retrieving revision 1.50
diff -C2 -d -r1.49 -r1.50
*** admin-functions.php	8 Oct 2004 00:16:44 -0000	1.49
--- admin-functions.php	14 Oct 2004 03:54:56 -0000	1.50
***************
*** 549,739 ****
  }
  
- function get_theme_data($theme_file) {
- 	$theme_data = implode('', file($theme_file));
- 	preg_match("|Theme Name:(.*)|i", $theme_data, $theme_name);
- 	preg_match("|Theme URI:(.*)|i", $theme_data, $theme_uri);
- 	preg_match("|Description:(.*)|i", $theme_data, $description);
- 	preg_match("|Author:(.*)|i", $theme_data, $author_name);
- 	preg_match("|Author URI:(.*)|i", $theme_data, $author_uri);
- 	preg_match("|Template:(.*)|i", $theme_data, $template);
- 	if ( preg_match("|Version:(.*)|i", $theme_data, $version) )
- 		$version = $version[1];
- 	else
- 		$version ='';
- 
- 	$description = wptexturize($description[1]);
- 
- 	$name = $theme_name[1];
- 	$name = trim($name);
- 	$theme = $name;
- 	if ('' != $theme_uri[1] && '' != $name) {
- 		$theme = __("<a href='{$theme_uri[1]}' title='Visit theme homepage'>{$theme}</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' => $theme, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
- }
- 
- function get_themes() {
- 	$themes = array();
- 	$theme_loc = 'wp-content/themes';
- 	$theme_root = ABSPATH . $theme_loc;
- 
- 	// Files in wp-content/themes directory
- 	$themes_dir = @ dir($theme_root);
- 	if ($themes_dir) {
- 		while(($theme_dir = $themes_dir->read()) !== false) {
- 			if (is_dir($theme_root . '/' . $theme_dir)) {
- 				$stylish_dir = @ dir($theme_root . '/' . $theme_dir);
- 				while(($theme_file = $stylish_dir->read()) !== false) {
- 					if ( $theme_file == 'style.css' ) {
- 						$theme_files[] = $theme_dir . '/' . $theme_file;
- 					}
- 				}
- 			}
- 		}
- 	}
- 
- 	$default_files = array(get_settings('blogfilename'), 'wp-comments.php', 'wp-comments-popup.php', 'wp-comments-post.php', 'wp-footer.php', 'wp-header.php', 'wp-sidebar.php', 'footer.php', 'header.php', 'sidebar.php');
- 
- 	// Get the files for the default template.
- 	$default_template_files = array();
- 	{
- 		$dirs = array('', 'wp-content');
- 		foreach ($dirs as $dir) {
- 			$template_dir = @ dir(ABSPATH . $dir);
- 			while(($file = $template_dir->read()) !== false) {
- 				if ( !preg_match('|^\.+$|', $file) && in_array($file, $default_files)) 
- 					$default_template_files[] = trim("$dir/$file", '/');
- 			}
- 		}
- 	}
- 
- 	// Get the files for the default stylesheet.
- 	$default_stylesheet_files = array();
- 	{
- 		$stylesheet_dir = @ dir(ABSPATH);
- 		while(($file = $stylesheet_dir->read()) !== false) {
- 			if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file)) 
- 				$default_stylesheet_files[] = "$file";
- 		}
- 	}
- 	
- 	// The default theme always exists.
- 	$themes['Default'] = array('Name' => 'Default', 'Title' => 'WordPress Default', 'Description' => 'The default theme included with WordPress.', 'Author' => 'Dave Shea', 'Version' => '1.3', 'Template' => 'default', 'Stylesheet' => 'default', 'Template Files' => $default_template_files, 'Stylesheet Files' => $default_stylesheet_files, 'Template Dir' => '/', 'Stylesheet Dir' => '/', 'Parent Theme' => '');
- 
- 	if (!$themes_dir || !$theme_files) {
- 		return $themes;
- 	}
- 
- 	sort($theme_files);
- 
- 	foreach($theme_files as $theme_file) {
- 		$theme_data = get_theme_data("$theme_root/$theme_file");
- 	  
- 		$name = $theme_data['Name']; 
- 		$title = $theme_data['Title'];
- 		$description = wptexturize($theme_data['Description']);
- 		$version = $theme_data['Version'];
- 		$author = $theme_data['Author'];
- 		$template = $theme_data['Template'];
- 		$stylesheet = dirname($theme_file);
- 
- 		if (empty($template)) {
- 			if (file_exists(dirname("$theme_root/$theme_file/index.php"))) {
- 				$template = dirname($theme_file);
- 			} else {
- 				continue;
- 			}
- 		}
- 
- 		$template = trim($template);
- 
- 		if (($template != 'default') && (! file_exists("$theme_root/$template/index.php"))) {
- 			continue;
- 		}
- 
- 		if (empty($name)) {
- 			$name = dirname($theme_file);
- 			$title = $name;
- 		}
- 		
- 		$stylesheet_files = array();
- 		if ($stylesheet != 'default') {
- 			$stylesheet_dir = @ dir("$theme_root/$stylesheet");
- 			if ($stylesheet_dir) {
- 				while(($file = $stylesheet_dir->read()) !== false) {
- 					if ( !preg_match('|^\.+$|', $file) && preg_match('|\.css$|', $file) ) 
- 						$stylesheet_files[] = "$theme_loc/$stylesheet/$file";
- 				}
- 			}
- 		} else {
- 			$stylesheet_files = $default_stylesheet_files;
- 		}
- 
- 		$template_files = array();		
- 		if ($template != 'default') {
- 			$template_dir = @ dir("$theme_root/$template");
- 			if ($template_dir) {
- 				while(($file = $template_dir->read()) !== false) {
- 					if ( !preg_match('|^\.+$|', $file) && preg_match('|\.php$|', $file) ) 
- 						$template_files[] = "$theme_loc/$template/$file";
- 				}
- 			}
- 		} else {
- 			$template_files = $default_template_files;
- 		}
- 
- 		$template_dir = dirname($template_files[0]);
- 		$stylesheet_dir = dirname($stylesheet_files[0]);
- 
- 		if (empty($template_dir)) $template_dir = '/';
- 		if (empty($stylesheet_dir)) $stylesheet_dir = '/';
- 		
- 		$themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template, 'Stylesheet' => $stylesheet, 'Template Files' => $template_files, 'Stylesheet Files' => $stylesheet_files, 'Template Dir' => $template_dir, 'Stylesheet Dir' => $stylesheet_dir);
- 	}
- 
- 	// Resolve theme dependencies.
- 	$theme_names = array_keys($themes);
- 
- 	foreach ($theme_names as $theme_name) {
- 		$themes[$theme_name]['Parent Theme'] = '';
- 		if ($themes[$theme_name]['Stylesheet'] != $themes[$theme_name]['Template']) {
- 			foreach ($theme_names as $parent_theme_name) {
- 				if (($themes[$parent_theme_name]['Stylesheet'] == $themes[$parent_theme_name]['Template']) && ($themes[$parent_theme_name]['Template'] == $themes[$theme_name]['Template'])) {
- 					$themes[$theme_name]['Parent Theme'] = $themes[$parent_theme_name]['Name'];
- 					break;
- 				}
- 			}
- 		}
- 	}
- 
- 	return $themes;
- }
- 
- function get_current_theme() {
- 	$themes = get_themes();
- 	$theme_names = array_keys($themes);
- 	$current_template = get_settings('template');
- 	$current_stylesheet = get_settings('stylesheet');
- 	$current_theme = 'Default';
- 
- 	if ($themes) {
- 		foreach ($theme_names as $theme_name) {
- 			if ($themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
- 					$themes[$theme_name]['Template'] == $current_template) {
- 				$current_theme = $themes[$theme_name]['Name'];
- 			}
- 		}
- 	}
- 
- 	return $current_theme;
- }
- 
  function validate_current_theme() {
  	$theme_loc = 'wp-content/themes';
--- 549,552 ----




More information about the cvs mailing list