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 if ( ! current_user_can('edit_files') )
40 die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
42 $newcontent = stripslashes($_POST['newcontent']);
43 if (is_writeable($real_file)) {
44 $f = @ fopen($real_file, 'w+');
46 fwrite($f, $newcontent);
48 header("Location: templates.php?file=$file&a=te");
50 header("Location: templates.php?file=$file&a=err");
53 header("Location: templates.php?file=$file&a=err");
62 require_once('./admin-header.php');
64 if ( ! current_user_can('edit_files') )
65 die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
67 if ( strstr( $file, 'wp-config.php' ) )
68 die('<p>'.__('The config file cannot be edited or viewed through the web interface. Sorry!').'</p>');
70 update_recently_edited($file);
72 if (!is_file($real_file))
76 $f = @ fopen($real_file, 'r');
78 $content = fread($f, filesize($real_file));
79 $content = htmlspecialchars($content);
86 <?php if (isset($_GET['a'])) : ?>
87 <?php if ( 'err' == $_GET['a'] ) : ?>
88 <div id="message" class="error"><p><?php _e('Could not save file.') ?></p></div>
90 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
95 if (is_writeable($real_file)) {
96 echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
98 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
101 <div id="templateside">
105 <h3><?php _e('Recent'); ?></h3>
108 foreach ($recents as $recent) :
109 echo "<li><a href='templates.php?file=$recent'>" . get_file_description(basename($recent)) . "</a></li>";
114 <h3><?php _e('Common'); ?></h3>
115 <?php $common_files = array('index.php', '.htaccess', 'my-hacks.php');
116 $old_files = array('wp-layout.css', 'wp-comments.php', 'wp-comments-popup.php');
117 foreach ($old_files as $old_file) {
118 if (file_exists(ABSPATH . $old_file))
119 $common_files[] = $old_file;
122 <?php foreach ($common_files as $common_file) : ?>
123 <li><a href="templates.php?file=<?php echo $common_file?>"><?php echo get_file_description($common_file); ?></a></li>
127 <?php if (!$error) { ?>
128 <form name="template" id="template" action="templates.php" method="post">
129 <div><textarea cols="70" rows="25" name="newcontent" id='newcontent' tabindex="1"><?php echo $content ?></textarea>
130 <input type="hidden" name="action" value="update" />
131 <input type="hidden" name="file" value="<?php echo $file ?>" />
133 <?php if ( is_writeable($real_file) ) : ?>
136 echo "<input type='submit' name='submit' value=' " . __('Update File') . " »' tabindex='2' />";
140 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
145 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
148 <div class="clear"> </div>
151 <h2><?php _e('Other Files') ?></h2>
153 <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>
154 <form name="file" action="templates.php" method="get">
155 <input type="text" name="file" />
156 <input type="submit" name="submit" value="<?php _e('Edit file »') ?>" />
159 <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>
166 include("admin-footer.php");