]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/templates.php
Wordpress 2.0.11
[autoinstalls/wordpress.git] / wp-admin / templates.php
1 <?php
2 require_once('admin.php');
3 $title = __('Template &amp; File Editing');
4 $parent_file =  'edit.php';
5
6 $wpvarstoreset = array('action','redirect','profile','error','warning','a','file');
7 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
8         $wpvar = $wpvarstoreset[$i];
9         if (!isset($$wpvar)) {
10                 if (empty($_POST["$wpvar"])) {
11                         if (empty($_GET["$wpvar"])) {
12                                 $$wpvar = '';
13                         } else {
14                                 $$wpvar = $_GET["$wpvar"];
15                         }
16                 } else {
17                         $$wpvar = $_POST["$wpvar"];
18                 }
19         }
20 }
21
22 $recents = get_option('recently_edited');
23
24 if (empty($file)) {
25         if ($recents) {
26                 $file = $recents[0];
27         } else {
28                 $file = 'index.php';
29         }
30 }
31
32 $file = validate_file_to_edit($file);
33 $real_file = get_real_file_to_edit($file);
34
35 switch($action) {
36
37 case 'update':
38
39         check_admin_referer('edit-file_' . $file);
40
41         if ( ! current_user_can('edit_files') )
42         die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
43
44         $newcontent = stripslashes($_POST['newcontent']);
45         if (is_writeable($real_file)) {
46                 $f = @ fopen($real_file, 'w+');
47                 if ( $f ) {
48                         fwrite($f, $newcontent);
49                         fclose($f);
50                         wp_redirect("templates.php?file=$file&a=te");
51                 } else {
52                         wp_redirect("templates.php?file=$file&a=err");
53                 }
54         } else {
55                 wp_redirect("templates.php?file=$file&a=err");
56         }
57
58         exit();
59
60 break;
61
62 default:
63
64         require_once('./admin-header.php');
65         
66         if ( ! current_user_can('edit_files') )
67         die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
68
69         if ( strstr( $file, 'wp-config.php' ) )
70         die('<p>'.__('The config file cannot be edited or viewed through the web interface. Sorry!').'</p>');
71
72         update_recently_edited($file);
73
74         if ( !is_file($real_file) ) {
75                 $error = true;
76         } else {
77                 $f = @ fopen($real_file, 'r');
78                 if ( $f ) {
79                         if ( filesize($real_file ) > 0 ) {
80                                 $content = fread($f, filesize($real_file));
81                                 $content = htmlspecialchars($content);
82                         } else {
83                                 $content = '';
84                         }
85                 } else {
86                         $error = true;
87                 }
88         }
89
90         ?>
91 <?php if (isset($_GET['a'])) : ?>
92         <?php if ( 'err' == $_GET['a'] ) : ?>
93  <div id="message" class="error"><p><?php _e('Could not save file.') ?></p></div>
94         <?php else: ?>
95  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
96         <?php endif; ?> 
97 <?php endif; ?>
98  <div class="wrap"> 
99 <?php
100 if (is_writeable($real_file)) {
101         echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
102 } else {
103         echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
104 }
105 ?>
106 <div id="templateside">
107 <?php 
108 if ( $recents ) : 
109 ?>
110 <h3><?php _e('Recent'); ?></h3>
111 <?php
112 echo '<ol>';
113 foreach ($recents as $recent) :
114         echo "<li><a href='templates.php?file=" . attribute_escape($recent) . "'>" . wp_specialchars(get_file_description(basename($recent))) . "</a></li>";
115 endforeach;
116 echo '</ol>';
117 endif;
118 ?>
119 <h3><?php _e('Common'); ?></h3>
120         <?php $common_files = array('index.php', '.htaccess', 'my-hacks.php');
121  $old_files = array('wp-layout.css', 'wp-comments.php', 'wp-comments-popup.php');
122  foreach ($old_files as $old_file) {
123          if (file_exists(ABSPATH . $old_file))
124                  $common_files[] = $old_file;
125  } ?>
126   <ul>
127          <?php foreach ($common_files as $common_file) : ?>
128           <li><a href="templates.php?file=<?php echo $common_file?>"><?php echo get_file_description($common_file); ?></a></li>
129          <?php endforeach; ?>
130   </ul>
131 </div>
132 <?php if (!$error) { ?>
133   <form name="template" id="template" action="templates.php" method="post"> 
134   <?php wp_nonce_field('edit-file_' . $file) ?>
135      <div><textarea cols="70" rows="25" name="newcontent" id='newcontent' tabindex="1"><?php echo $content ?></textarea> 
136      <input type="hidden" name="action" value="update" /> 
137      <input type="hidden" name="file" value="<?php echo $file ?>" /> 
138 </div>
139 <?php if ( is_writeable($real_file) ) : ?>
140      <p class="submit">
141 <?php
142         echo "<input type='submit' name='submit' value='        " . __('Update File') . " &raquo;' tabindex='2' />";
143 ?>
144 </p>
145 <?php else : ?>
146 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
147 <?php endif; ?>
148    </form> 
149   <?php
150         } else {
151                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
152         }
153         ?>
154 <div class="clear"> &nbsp; </div>
155 </div>
156 <div class="wrap">
157 <h2><?php _e('Other Files') ?></h2>
158
159   <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> 
160   <form name="file" action="templates.php" method="get"> 
161     <input type="text" name="file" /> 
162     <input type="submit" name="submit"  value="<?php _e('Edit file &raquo;') ?>" /> 
163   </form> 
164
165   <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>
166 </div> 
167 <?php
168
169 break;
170 }
171
172 include("admin-footer.php");
173 ?>