2 require_once('admin.php');
3 $title = __('Template & File Editing');
4 $parent_file = 'edit.php';
6 $wpvarstoreset = array('action','redirect','profile','error','warning','a','file');
7 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
8 $wpvar = $wpvarstoreset[$i];
10 if (empty($_POST["$wpvar"])) {
11 if (empty($_GET["$wpvar"])) {
14 $$wpvar = $_GET["$wpvar"];
17 $$wpvar = $_POST["$wpvar"];
22 $recents = get_option('recently_edited');
32 $file = validate_file_to_edit($file);
33 $real_file = get_real_file_to_edit($file);
39 check_admin_referer('edit-file_' . $file);
41 if ( ! current_user_can('edit_files') )
42 die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
44 $newcontent = stripslashes($_POST['newcontent']);
45 if (is_writeable($real_file)) {
46 $f = @ fopen($real_file, 'w+');
48 fwrite($f, $newcontent);
50 wp_redirect("templates.php?file=$file&a=te");
52 wp_redirect("templates.php?file=$file&a=err");
55 wp_redirect("templates.php?file=$file&a=err");
64 require_once('./admin-header.php');
66 if ( ! current_user_can('edit_files') )
67 die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
69 if ( strstr( $file, 'wp-config.php' ) )
70 die('<p>'.__('The config file cannot be edited or viewed through the web interface. Sorry!').'</p>');
72 update_recently_edited($file);
74 if (!is_file($real_file))
78 $f = @ fopen($real_file, 'r');
80 $content = fread($f, filesize($real_file));
81 $content = htmlspecialchars($content);
88 <?php if (isset($_GET['a'])) : ?>
89 <?php if ( 'err' == $_GET['a'] ) : ?>
90 <div id="message" class="error"><p><?php _e('Could not save file.') ?></p></div>
92 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
97 if (is_writeable($real_file)) {
98 echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
100 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
103 <div id="templateside">
107 <h3><?php _e('Recent'); ?></h3>
110 foreach ($recents as $recent) :
111 echo "<li><a href='templates.php?file=$recent'>" . get_file_description(basename($recent)) . "</a></li>";
116 <h3><?php _e('Common'); ?></h3>
117 <?php $common_files = array('index.php', '.htaccess', 'my-hacks.php');
118 $old_files = array('wp-layout.css', 'wp-comments.php', 'wp-comments-popup.php');
119 foreach ($old_files as $old_file) {
120 if (file_exists(ABSPATH . $old_file))
121 $common_files[] = $old_file;
124 <?php foreach ($common_files as $common_file) : ?>
125 <li><a href="templates.php?file=<?php echo $common_file?>"><?php echo get_file_description($common_file); ?></a></li>
129 <?php if (!$error) { ?>
130 <form name="template" id="template" action="templates.php" method="post">
131 <?php wp_nonce_field('edit-file_' . $file) ?>
132 <div><textarea cols="70" rows="25" name="newcontent" id='newcontent' tabindex="1"><?php echo $content ?></textarea>
133 <input type="hidden" name="action" value="update" />
134 <input type="hidden" name="file" value="<?php echo $file ?>" />
136 <?php if ( is_writeable($real_file) ) : ?>
139 echo "<input type='submit' name='submit' value=' " . __('Update File') . " »' tabindex='2' />";
143 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
148 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
151 <div class="clear"> </div>
154 <h2><?php _e('Other Files') ?></h2>
156 <p><?php _e('To edit a file, type its name here. You can edit any file <a href="http://codex.wordpress.org/Changing_File_Permissions" title="Read more about making files writable">writable by the server</a>, e.g. CHMOD 666.') ?></p>
157 <form name="file" action="templates.php" method="get">
158 <input type="text" name="file" />
159 <input type="submit" name="submit" value="<?php _e('Edit file »') ?>" />
162 <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>
169 include("admin-footer.php");