]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/plugin-editor.php
Wordpress 2.0.2-scripts
[autoinstalls/wordpress.git] / wp-admin / plugin-editor.php
1 <?php
2 require_once('admin.php');
3
4 $title = __("Edit Plugins");
5 $parent_file = 'plugins.php';
6
7 $wpvarstoreset = array('action','redirect','profile','error','warning','a','file');
8 for ($i=0; $i<count($wpvarstoreset); $i += 1) {
9         $wpvar = $wpvarstoreset[$i];
10         if (!isset($$wpvar)) {
11                 if (empty($_POST["$wpvar"])) {
12                         if (empty($_GET["$wpvar"])) {
13                                 $$wpvar = '';
14                         } else {
15                                 $$wpvar = $_GET["$wpvar"];
16                         }
17                 } else {
18                         $$wpvar = $_POST["$wpvar"];
19                 }
20         }
21 }
22
23 $plugins = get_plugins();
24 $plugin_files = array_keys($plugins);
25
26 if (empty($file)) {
27         $file = $plugin_files[0];
28 }
29
30 $file = validate_file_to_edit($file, $plugin_files);
31 $real_file = get_real_file_to_edit("wp-content/plugins/$file");
32
33 switch($action) {
34
35 case 'update':
36
37         if ( !current_user_can('edit_plugins') )
38         die('<p>'.__('You have do not have sufficient permissions to edit templates for this blog.').'</p>');
39
40         $newcontent = stripslashes($_POST['newcontent']);
41         if (is_writeable($real_file)) {
42                 $f = fopen($real_file, 'w+');
43                 fwrite($f, $newcontent);
44                 fclose($f);
45                 header("Location: plugin-editor.php?file=$file&a=te");
46         } else {
47                 header("Location: plugin-editor.php?file=$file");
48         }
49
50         exit();
51
52 break;
53
54 default:
55         
56         require_once('admin-header.php');
57         if ( !current_user_can('edit_plugins') )
58         die('<p>'.__('You have do not have sufficient permissions to edit plugins for this blog.').'</p>');
59
60         update_recently_edited("wp-content/plugins/$file");
61         
62         if (!is_file($real_file))
63                 $error = 1;
64         
65         if (!$error) {
66                 $f = fopen($real_file, 'r');
67                 $content = fread($f, filesize($real_file));
68                 $content = htmlspecialchars($content);
69         }
70
71         ?>
72 <?php if (isset($_GET['a'])) : ?>
73  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
74 <?php endif; ?>
75  <div class="wrap"> 
76   <?php
77         if (is_writeable($real_file)) {
78                 echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), $file) . '</h2>';
79         } else {
80                 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), $file) . '</h2>';
81         }
82         ?>
83         <div id="templateside">
84 <h3><?php _e('Plugin files') ?></h3>
85
86 <?php
87 if ($plugin_files) :
88 ?>
89   <ul>
90 <?php foreach($plugin_files as $plugin_file) : ?>
91                  <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
92 <?php endforeach; ?>
93   </ul>
94 <?php endif; ?>
95 </div>
96         <?php   if (!$error) { ?> 
97   <form name="template" id="template" action="plugin-editor.php" method="post">
98                  <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 
99      <input type="hidden" name="action" value="update" /> 
100      <input type="hidden" name="file" value="<?php echo $file ?>" /> 
101                 </div>
102 <?php if ( is_writeable($real_file) ) : ?>
103      <p class="submit">
104 <?php
105         echo "<input type='submit' name='submit' value='        " . __('Update File') . " &raquo;' tabindex='2' />";
106 ?>
107 </p>
108 <?php else : ?>
109 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
110 <?php endif; ?>
111    </form> 
112   <?php
113         } else {
114                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
115         }
116         ?>
117 <div class="clear"> &nbsp; </div>
118 </div> 
119 <?php
120 break;
121 }
122
123 include("admin-footer.php") ?>