]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/templates.php
4631ac42dc113dbafbc7240a39bc17fe489098e1
[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         
77         if (!$error) {
78                 $f = @ fopen($real_file, 'r');
79                 if ( $f ) {
80                         $content = fread($f, filesize($real_file));
81                         $content = htmlspecialchars($content);
82                 } else {
83                         $error = true;
84                 }
85         }
86
87         ?>
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>
91         <?php else: ?>
92  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
93         <?php endif; ?> 
94 <?php endif; ?>
95  <div class="wrap"> 
96 <?php
97 if (is_writeable($real_file)) {
98         echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
99 } else {
100         echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
101 }
102 ?>
103 <div id="templateside">
104 <?php 
105 if ( $recents ) : 
106 ?>
107 <h3><?php _e('Recent'); ?></h3>
108 <?php
109 echo '<ol>';
110 foreach ($recents as $recent) :
111         echo "<li><a href='templates.php?file=$recent'>" . get_file_description(basename($recent)) . "</a></li>";
112 endforeach;
113 echo '</ol>';
114 endif;
115 ?>
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;
122  } ?>
123   <ul>
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>
126          <?php endforeach; ?>
127   </ul>
128 </div>
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 ?>" /> 
135 </div>
136 <?php if ( is_writeable($real_file) ) : ?>
137      <p class="submit">
138 <?php
139         echo "<input type='submit' name='submit' value='        " . __('Update File') . " &raquo;' tabindex='2' />";
140 ?>
141 </p>
142 <?php else : ?>
143 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
144 <?php endif; ?>
145    </form> 
146   <?php
147         } else {
148                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
149         }
150         ?>
151 <div class="clear"> &nbsp; </div>
152 </div>
153 <div class="wrap">
154 <h2><?php _e('Other Files') ?></h2>
155
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 &raquo;') ?>" /> 
160   </form> 
161
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&#8217;t have access to a text editor or FTP client.') ?></p>
163 </div> 
164 <?php
165
166 break;
167 }
168
169 include("admin-footer.php");
170 ?>