[wp-cvs] wordpress/wp-admin theme-editor.php, NONE, 1.1 themes.php, NONE, 1.1 admin-functions.php, 1.38, 1.39 menu.php, 1.25, 1.26 upgrade-schema.php, 1.4, 1.5

Ryan Boren rboren at users.sourceforge.net
Sat Sep 11 16:12:42 UTC 2004


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

Modified Files:
	admin-functions.php menu.php upgrade-schema.php 
Added Files:
	theme-editor.php themes.php 
Log Message:
Themes.

Index: admin-functions.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/admin-functions.php,v
retrieving revision 1.38
retrieving revision 1.39
diff -C2 -d -r1.38 -r1.39
*** admin-functions.php	9 Sep 2004 17:51:33 -0000	1.38
--- admin-functions.php	11 Sep 2004 16:12:39 -0000	1.39
***************
*** 489,491 ****
--- 489,638 ----
  }
  
+ 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 && '' != $name) {
+ 		$theme = __("<a href='{$theme_uri[1]}' title='Visit theme homepage'>{$theme}</a>");
+ 	}
+ 
+ 	if ('' == $author_uri) {
+ 		$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' => 'Default', 'Description' => 'The default theme', 'Author' => '', 'Version' => '1.3', 'Template' => 'default', 'Stylesheet' => 'default', 'Template Files' => $default_template_files, 'Stylesheet Files' => $default_stylesheet_files);
+ 
+ 	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;
+ 		}
+ 
+ 		$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);
+ 	}
+ 
+ 	return $themes;
+ }
+ 
  ?>
\ No newline at end of file

Index: menu.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/menu.php,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -d -r1.25 -r1.26
*** menu.php	5 Sep 2004 00:24:26 -0000	1.25
--- menu.php	11 Sep 2004 16:12:39 -0000	1.26
***************
*** 14,19 ****
  $menu[30] = array(__('Options'), 6, 'options-general.php');
  $menu[35] = array(__('Plugins'), 8, 'plugins.php');
! $menu[40] = array(__('Templates'), 4, 'templates.php');
! $menu[45] = array(__('Upload'), get_settings('fileupload_minlevel'), 'upload.php');
  ksort($menu); // So other files can plugin
  
--- 14,20 ----
  $menu[30] = array(__('Options'), 6, 'options-general.php');
  $menu[35] = array(__('Plugins'), 8, 'plugins.php');
! $menu[40] = array(__('Presentation'), 8, 'themes.php');
! $menu[45] = array(__('Templates'), 4, 'templates.php');
! $menu[50] = array(__('Upload'), get_settings('fileupload_minlevel'), 'upload.php');
  ksort($menu); // So other files can plugin
  
***************
*** 40,43 ****
--- 41,47 ----
  $submenu['options-general.php'][30] = array(__('Miscellaneous'), 5, 'options-misc.php');
  
+ $submenu['themes.php'][5] = array(__('Themes'), 5, 'themes.php');
+ $submenu['themes.php'][10] = array(__('Theme Editor'), 5, 'theme-editor.php');
+ 
  $self = preg_replace('|.*/wp-admin/|i', '', $_SERVER['PHP_SELF']);
  if (!isset($parent_file)) $parent_file = '';

Index: upgrade-schema.php
===================================================================
RCS file: /cvsroot/cafelog/wordpress/wp-admin/upgrade-schema.php,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** upgrade-schema.php	8 Sep 2004 10:19:05 -0000	1.4
--- upgrade-schema.php	11 Sep 2004 16:12:40 -0000	1.5
***************
*** 216,219 ****
--- 216,221 ----
  	add_option('recently_edited');
  	add_option('use_linksupdate', 0);
+ 	add_option('template', 'default');
+ 	add_option('stylesheet', 'default');
  
  	// Delete unused options

--- NEW FILE: theme-editor.php ---
<?php
require_once('../wp-includes/wp-l10n.php');

$title = __("Template &amp; file editing");
$parent_file = 'themes.php';

function add_magic_quotes($array) {
	foreach ($array as $k => $v) {
		if (is_array($v)) {
			$array[$k] = add_magic_quotes($v);
		} else {
			$array[$k] = addslashes($v);
		}
	}
	return $array;
} 

function validate_file($file) {
	if ('..' == substr($file,0,2))
		die (__('Sorry, can&#8217;t edit files with ".." in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.'));
	
	if (':' == substr($file,1,1))
		die (__('Sorry, can&#8217;t call files with their real path.'));

	if ('/' == substr($file,0,1))
		$file = '.' . $file;
	
	$file = stripslashes($file);
	$file = str_replace('../', '', $file);

    return $file;
}

if (!get_magic_quotes_gpc()) {
	$_GET    = add_magic_quotes($_GET);
	$_POST   = add_magic_quotes($_POST);
	$_COOKIE = add_magic_quotes($_COOKIE);
}

$wpvarstoreset = array('action','standalone','redirect','profile','error','warning','a','file', 'theme');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
	$wpvar = $wpvarstoreset[$i];
	if (!isset($$wpvar)) {
		if (empty($_POST["$wpvar"])) {
			if (empty($_GET["$wpvar"])) {
				$$wpvar = '';
			} else {
				$$wpvar = $_GET["$wpvar"];
			}
		} else {
			$$wpvar = $_POST["$wpvar"];
		}
	}
}

switch($action) {

case 'update':

	$standalone = 1;
	require_once("admin-header.php");

	if ($user_level < 5) {
		die(__('<p>You have do not have sufficient permissions to edit templates for this blog.</p>'));
	}

	$newcontent = stripslashes($_POST['newcontent']);
	$file = $_POST['file'];
    $file = validate_file($file);
	$real_file = '../' . $file;
    if (is_writeable($real_file)) {
        $f = fopen($real_file, 'w+');
        fwrite($f, $newcontent);
        fclose($f);
        header("Location: theme-editor.php?file=$file&a=te");
    } else {
        header("Location: theme-editor.php?file=$file");
    }

	exit();

break;

default:
	
	require_once('admin-header.php');
	update_option('recently_edited', array(1, 2, 3) );
	if ($user_level <= 5) {
		die(__('<p>You have do not have sufficient permissions to edit themes for this blog.</p>'));
	}
	
	$themes = get_themes();

	if (! isset($theme)  || empty($theme)) {
		$theme = 'Default';
	}

	$stylesheet_files = $themes[$theme]['Stylesheet Files'];
	$template_files = $themes[$theme]['Template Files'];
	
	if ('' == $file) {
		$file = $stylesheet_files[0];
	}
	
	$home = get_settings('home');
	if (($home != '')
			&& ($home != get_settings('siteurl')) &&
			('index.php' == $file || get_settings('blogfilename') == $file ||
			 '.htaccess' == $file)) {
		$home_root = parse_url($home);
		$home_root = $home_root['path'];
		$root = str_replace($_SERVER["PHP_SELF"], '', $_SERVER["PATH_TRANSLATED"]);
		$home_root = $root . $home_root;
		$real_file = $home_root . '/' . $file;
	} else {
		$file = validate_file($file);
		$real_file = '../' . $file;
	}
	
	if (!is_file($real_file))
		$error = 1;
	
	if (!$error) {
		$f = fopen($real_file, 'r');
		$content = fread($f, filesize($real_file));
		$content = htmlspecialchars($content);
	}

	?>
<?php if (isset($_GET['a'])) : ?>
 <div class="updated"><p><?php _e('File edited successfully.') ?></p></div>
<?php endif; ?>
 <div class="wrap">
  <form name="theme" action="theme-editor.php" method="post"> 
		<?php _e('Select theme to edit:') ?>
		<select name="theme" id="theme">
	<?php
		foreach ($themes as $a_theme) {
		$theme_name = $a_theme['Name'];
		if ($theme_name == $theme) $selected = " selected='selected'";
		else $selected = '';
		echo "\n\t<option value='$theme_name' $selected>$theme_name</option>";
	}
?>
 </select>
 <input type="submit" name="Submit" value="<?php _e('Select') ?> &raquo;" />
 </form>
 </div>

 <div class="wrap"> 
  <?php
	echo "<p>" . sprintf(__('Editing <strong>%s</strong>'), $file) . "</p>";
	
	if (!$error) {
	?> 
  <form name="template" action="theme-editor.php" method="post"> 
     <textarea cols="80" rows="21" style="width:95%; margin-right: 10em; font-family: 'Courier New', Courier, monopace; font-size:small;" name="newcontent" tabindex="1"><?php echo $content ?></textarea> 
     <input type="hidden" name="action" value="update" /> 
     <input type="hidden" name="file" value="<?php echo $file ?>" /> 
     <input type="hidden" name="theme" value="<?php echo $theme ?>" /> 
     <p class="submit">
     <?php
		if (is_writeable($real_file)) {
			echo "<input type='submit' name='submit' value='Update File &raquo;' tabindex='2' />";
		} else {
			echo "<input type='button' name='oops' value='" . __('(You cannot update that file/template: must make it writable, e.g. CHMOD 666)') ."' tabindex='2' />";
		}
		?> 
</p>
   </form> 
  <?php
	} else {
		echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
	}
	?> 
</div> 
<div class="wrap">
<?php

if ($template_files || $stylesheet_files) :
?>
  <p><?php printf(__('<strong>%s</strong> theme files:'), $theme) ?></p>
  <ul>
<?php foreach($stylesheet_files as $stylesheet_file) : ?>
		 <li><a href="theme-editor.php?file=<?php echo "$stylesheet_file"; ?>&amp;theme=<?php echo $theme; ?>"><?php echo basename($stylesheet_file); ?></a></li>
<?php endforeach; ?>
<?php foreach($template_files as $template_file) : ?>
		<li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&amp;theme=<?php echo $theme; ?>"><?php echo basename($template_file); ?></a></li>
<?php endforeach; ?>
  </ul>
<?php endif; ?>
  <p><?php _e('Note: of course, you can also edit the files/templates in your text editor of choice and upload them. This online editor is only meant to be used when you don&#8217;t have access to a text editor or FTP client.') ?></p>
</div> 
<?php

break;
}

include("admin-footer.php") ?> 

--- NEW FILE: themes.php ---
<?php

if ( isset($_GET['action']) ) {
	$standalone = 1;
	require_once('admin-header.php');

	check_admin_referer();

	if ('activate' == $_GET['action']) {
	  if (isset($_GET['template'])) {
	    update_option('template', $_GET['template']);
	  }

	  if (isset($_GET['stylesheet'])) {
	    update_option('stylesheet', $_GET['stylesheet']);
	  }

	  header('Location: themes.php?activate=true');
	}
 }

require_once('../wp-includes/wp-l10n.php');
$title = __('Manage Themes');
$parent_file = 'themes.php';
require_once('admin-header.php');

if ($user_level < 9) // Must be at least level 9
	die (__('Sorry, you must be at least a level 8 user to modify themes.'));
?>

<?php
$themes = get_themes();
$theme_names = array_keys($themes);
natcasesort($theme_names);
$current_template = get_settings('template');
$current_stylesheet = get_settings('stylesheet');
$current_theme = 'Default';
$current_parent_theme = '';
$current_template_dir = '/';
$current_stylesheet_dir = '/';

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'];
			if ($current_template != 'default')
				$current_template_dir = dirname($themes[$theme_name]['Template Files'][0]);
			if ($current_stylesheet != 'default')
				$current_stylesheet_dir = dirname($themes[$theme_name]['Stylesheet Files'][0]);
		}

		if (($current_template != $current_stylesheet) &&
				($themes[$theme_name]['Stylesheet'] == $themes[$theme_name]['Template']) &&
				($themes[$theme_name]['Template'] == $current_template)) {
			$current_parent_theme = $themes[$theme_name]['Name'];
		}
	}
}
?>

<?php if ($current_parent_theme) { ?>
	<div class="updated"><p><?php printf(__('The active theme is <strong>%s</strong>.  The template files are located in <code>%s</code>.  The stylesheet files are located in <code>%s</code>.  <strong>%s</strong> uses templates from <strong>%s</strong>.  Changes made to the templates will affect both themes.'), $current_theme, $current_template_dir, $current_stylesheet_dir, $current_theme, $current_parent_theme); ?></p></div>
<?php } else { ?>
	<div class="updated"><p><?php printf(__('The active theme is <strong>%s</strong>.  The template files are located in <code>%s</code>.  The stylesheet files are located in <code>%s</code>.'), $current_theme, $current_template_dir, $current_stylesheet_dir); ?></p></div>
<?php } ?>

<div class="wrap">
<h2><?php _e('Theme Management'); ?></h2>
<p><?php _e('Themes are usually downloaded separately from WordPress. To install a theme you generally just need to put the theme file or files into your <code>wp-content/themes</code> directory. Once a theme is installed, you may select it here.'); ?></p>
<?php

if (empty($themes)) {
	_e("<p>Couldn't open themes directory or there are no themes available.</p>"); // TODO: make more helpful
} else {
?>
<table width="100%" cellpadding="3" cellspacing="3">
	<tr>
		<th><?php _e('Theme'); ?></th>
		<th><?php _e('Version'); ?></th>
		<th><?php _e('Author'); ?></th>
		<th><?php _e('Description'); ?></th>
		<th><?php _e('Select'); ?></th>
	</tr>
<?php
	$theme = '';

	$theme_names = array_keys($themes);
	natcasesort($theme_names);

	foreach ($theme_names as $theme_name) {
		$template = $themes[$theme_name]['Template'];
		$stylesheet = $themes[$theme_name]['Stylesheet'];
		$title = $themes[$theme_name]['Title'];
		$version = $themes[$theme_name]['Version'];
		$description = $themes[$theme_name]['Description'];
		$author = $themes[$theme_name]['Author'];

		if ($template == $current_template && $stylesheet == $current_stylesheet) {
			$action = "<a href='themes.php' title='" . __('Active theme') . "' class='edit'>" . __('Active Theme') . '</a>';
		} else {
			$action = "<a href='themes.php?action=activate&amp;template=$template&amp;stylesheet=$stylesheet' title='" . __('Select this theme') . "' class='edit'>" . __('Select') . '</a>';
		}

		$theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
		echo "
	  <tr $theme>
	     <td>$title</td>
	     <td>$version</td>
	     <td>$author</td>
	     <td>$description</td>
	     <td>$action</td>
	  </tr>";
	}
?>

</table>
<?php
}
?>
</div>

<?php
include('admin-footer.php');
?>



More information about the cvs mailing list