2 require_once('admin.php');
4 $title = __("Edit Themes");
5 $parent_file = 'themes.php';
7 $wpvarstoreset = array('action','redirect','profile','error','warning','a','file', 'theme');
8 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
9 $wpvar = $wpvarstoreset[$i];
10 if (!isset($$wpvar)) {
11 if (empty($_POST["$wpvar"])) {
12 if (empty($_GET["$wpvar"])) {
15 $$wpvar = $_GET["$wpvar"];
18 $$wpvar = $_POST["$wpvar"];
23 $themes = get_themes();
26 $theme = get_current_theme();
28 $theme = stripslashes($theme);
32 if ( ! isset($themes[$theme]) )
33 die(__('The requested theme does not exist.'));
35 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
38 $file = $allowed_files[0];
41 $file = validate_file_to_edit($file, $allowed_files);
42 $real_file = get_real_file_to_edit($file);
44 $file_show = basename( $file );
50 check_admin_referer('edit-theme_' . $file . $theme);
52 if ( !current_user_can('edit_themes') )
53 die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
55 $newcontent = stripslashes($_POST['newcontent']);
56 $theme = urlencode($theme);
57 if (is_writeable($real_file)) {
58 $f = fopen($real_file, 'w+');
59 fwrite($f, $newcontent);
61 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
63 $location = "theme-editor.php?file=$file&theme=$theme";
66 $location = wp_kses_no_null($location);
67 $strip = array('%0d', '%0a');
68 $location = str_replace($strip, '', $location);
69 header("Location: $location");
76 require_once('admin-header.php');
77 if ( !current_user_can('edit_themes') )
78 die('<p>'.__('You have do not have sufficient permissions to edit themes for this blog.').'</p>');
80 update_recently_edited($file);
82 if (!is_file($real_file))
85 if (!$error && filesize($real_file) > 0) {
86 $f = fopen($real_file, 'r');
87 $content = fread($f, filesize($real_file));
88 $content = htmlspecialchars($content);
92 <?php if (isset($_GET['a'])) : ?>
93 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
96 <form name="theme" action="theme-editor.php" method="post">
97 <?php _e('Select theme to edit:') ?>
98 <select name="theme" id="theme">
100 foreach ($themes as $a_theme) {
101 $theme_name = $a_theme['Name'];
102 if ($theme_name == $theme) $selected = " selected='selected'";
104 $theme_name = attribute_escape($theme_name);
105 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
109 <input type="submit" name="Submit" value="<?php _e('Select') ?> »" />
115 if ( is_writeable($real_file) ) {
116 echo '<h2>' . sprintf(__('Editing <code>%s</code>'), $file_show) . '</h2>';
118 echo '<h2>' . sprintf(__('Browsing <code>%s</code>'), $file_show) . '</h2>';
121 <div id="templateside">
122 <h3><?php printf(__("<strong>'%s'</strong> theme files"), $theme) ?></h3>
125 if ($allowed_files) :
128 <?php foreach($allowed_files as $allowed_file) : ?>
129 <li><a href="theme-editor.php?file=<?php echo "$allowed_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo get_file_description($allowed_file); ?></a></li>
137 <form name="template" id="template" action="theme-editor.php" method="post">
138 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
139 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
140 <input type="hidden" name="action" value="update" />
141 <input type="hidden" name="file" value="<?php echo $file ?>" />
142 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
144 <?php if ( is_writeable($real_file) ) : ?>
147 echo "<input type='submit' name='submit' value=' " . __('Update File') . " »' tabindex='2' />";
151 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
156 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
159 <div class="clear"> </div>
165 include("admin-footer.php") ?>