Theme, plugin, and file editing cleanup. Work in progress.
git-svn-id: http://svn.automattic.com/wordpress/trunk@1858 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -1,25 +1,9 @@
|
||||
<?php
|
||||
require_once('admin.php');
|
||||
|
||||
$title = __("Template & file editing");
|
||||
$title = __("Edit Themes");
|
||||
$parent_file = 'themes.php';
|
||||
|
||||
function validate_file($file) {
|
||||
if ('..' == substr($file,0,2))
|
||||
die (__('Sorry, can’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’t call files with their real path.'));
|
||||
|
||||
if ('/' == substr($file,0,1))
|
||||
$file = '.' . $file;
|
||||
|
||||
$file = stripslashes($file);
|
||||
$file = str_replace('../', '', $file);
|
||||
|
||||
return $file;
|
||||
}
|
||||
|
||||
$wpvarstoreset = array('action','redirect','profile','error','warning','a','file', 'theme');
|
||||
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
|
||||
$wpvar = $wpvarstoreset[$i];
|
||||
@@ -36,6 +20,21 @@ for ($i=0; $i<count($wpvarstoreset); $i += 1) {
|
||||
}
|
||||
}
|
||||
|
||||
$themes = get_themes();
|
||||
|
||||
if (empty($theme)) {
|
||||
$theme = get_current_theme();
|
||||
}
|
||||
|
||||
$allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $allowed_files, $themes[$theme]['Template Files']);
|
||||
|
||||
if (empty($file)) {
|
||||
$file = $allowed_files[0];
|
||||
}
|
||||
|
||||
$file = validate_file_to_edit($file, $allowed_files);
|
||||
$real_file = get_real_file_to_edit($file);
|
||||
|
||||
switch($action) {
|
||||
|
||||
case 'update':
|
||||
@@ -45,17 +44,14 @@ case 'update':
|
||||
}
|
||||
|
||||
$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");
|
||||
}
|
||||
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();
|
||||
|
||||
@@ -67,34 +63,8 @@ default:
|
||||
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 = get_current_theme();
|
||||
}
|
||||
|
||||
$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;
|
||||
}
|
||||
update_recently_edited($file);
|
||||
|
||||
if (!is_file($real_file))
|
||||
$error = 1;
|
||||
@@ -128,24 +98,43 @@ default:
|
||||
|
||||
<div class="wrap">
|
||||
<?php
|
||||
echo "<p>" . sprintf(__('Editing <strong>%s</strong>'), $file) . "</p>";
|
||||
|
||||
if (is_writeable($real_file)) {
|
||||
echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), $file) . '</h2>';
|
||||
} else {
|
||||
echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), $file) . '</h2>';
|
||||
}
|
||||
?>
|
||||
<div id="templateside">
|
||||
<h3><?php printf(__("<strong>'%s'</strong> theme files"), $theme) ?></h3>
|
||||
|
||||
<?php
|
||||
if ($allowed_files) :
|
||||
?>
|
||||
<ul>
|
||||
<?php foreach($allowed_files as $allowed_file) : ?>
|
||||
<li><a href="theme-editor.php?file=<?php echo "$allowed_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo get_file_description(basename($allowed_file)); ?></a></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
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>
|
||||
<form name="template" id="template" action="theme-editor.php" method="post">a
|
||||
<div><textarea cols="70" rows="25" name="newcontent" id="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 ?>" />
|
||||
<input type="hidden" name="theme" value="<?php echo $theme ?>" />
|
||||
</div>
|
||||
<?php if ( is_writeable($real_file) ) : ?>
|
||||
<p class="submit">
|
||||
<?php
|
||||
if (is_writeable($real_file)) {
|
||||
echo "<input type='submit' name='submit' value='Update File »' 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' />";
|
||||
}
|
||||
?>
|
||||
<?php
|
||||
echo "<input type='submit' name='submit' value=' " . __('Update File') . " »' tabindex='2' />";
|
||||
?>
|
||||
</p>
|
||||
<?php else : ?>
|
||||
<p><em><?php _e('If this file was writable you could edit it.'); ?></em></p>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
<?php
|
||||
} else {
|
||||
@@ -153,25 +142,7 @@ default:
|
||||
}
|
||||
?>
|
||||
</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"; ?>&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"; ?>&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’t have access to a text editor or FTP client.') ?></p>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user