]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/templates.php
Wordpress 2.0.2-scripts
[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         if ( ! current_user_can('edit_files') )
40         die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
41
42         $newcontent = stripslashes($_POST['newcontent']);
43         if (is_writeable($real_file)) {
44                 $f = @ fopen($real_file, 'w+');
45                 if ( $f ) {
46                         fwrite($f, $newcontent);
47                         fclose($f);
48                         header("Location: templates.php?file=$file&a=te");
49                 } else {
50                         header("Location: templates.php?file=$file&a=err");
51                 }
52         } else {
53                 header("Location: templates.php?file=$file&a=err");
54         }
55
56         exit();
57
58 break;
59
60 default:
61
62         require_once('./admin-header.php');
63         
64         if ( ! current_user_can('edit_files') )
65         die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
66
67         if ( strstr( $file, 'wp-config.php' ) )
68         die('<p>'.__('The config file cannot be edited or viewed through the web interface. Sorry!').'</p>');
69
70         update_recently_edited($file);
71
72         if (!is_file($real_file))
73                 $error = true;
74         
75         if (!$error) {
76                 $f = @ fopen($real_file, 'r');
77                 if ( $f ) {
78                         $content = fread($f, filesize($real_file));
79                         $content = htmlspecialchars($content);
80                 } else {
81                         $error = true;
82                 }
83         }
84
85         ?>
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>
89         <?php else: ?>
90  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
91         <?php endif; ?> 
92 <?php endif; ?>
93  <div class="wrap"> 
94 <?php
95 if (is_writeable($real_file)) {
96         echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
97 } else {
98         echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
99 }
100 ?>
101 <div id="templateside">
102 <?php 
103 if ( $recents ) : 
104 ?>
105 <h3><?php _e('Recent'); ?></h3>
106 <?php
107 echo '<ol>';
108 foreach ($recents as $recent) :
109         echo "<li><a href='templates.php?file=$recent'>" . get_file_description(basename($recent)) . "</a></li>";
110 endforeach;
111 echo '</ol>';
112 endif;
113 ?>
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;
120  } ?>
121   <ul>
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>
124          <?php endforeach; ?>
125   </ul>
126 </div>
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 ?>" /> 
132 </div>
133 <?php if ( is_writeable($real_file) ) : ?>
134      <p class="submit">
135 <?php
136         echo "<input type='submit' name='submit' value='        " . __('Update File') . " &raquo;' tabindex='2' />";
137 ?>
138 </p>
139 <?php else : ?>
140 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
141 <?php endif; ?>
142    </form> 
143   <?php
144         } else {
145                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
146         }
147         ?>
148 <div class="clear"> &nbsp; </div>
149 </div>
150 <div class="wrap">
151 <h2><?php _e('Other Files') ?></h2>
152
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 &raquo;') ?>" /> 
157   </form> 
158
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&#8217;t have access to a text editor or FTP client.') ?></p>
160 </div> 
161 <?php
162
163 break;
164 }
165
166 include("admin-footer.php");
167 ?>