]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/plugin-editor.php
Wordpress 2.0.11-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         check_admin_referer('edit-plugin_' . $file);
38
39         if ( !current_user_can('edit_plugins') )
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                 fwrite($f, $newcontent);
46                 fclose($f);
47                 wp_redirect("plugin-editor.php?file=$file&a=te");
48         } else {
49                 wp_redirect("plugin-editor.php?file=$file");
50         }
51
52         exit();
53
54 break;
55
56 default:
57         
58         require_once('admin-header.php');
59         if ( !current_user_can('edit_plugins') )
60         die('<p>'.__('You have do not have sufficient permissions to edit plugins for this blog.').'</p>');
61
62         update_recently_edited("wp-content/plugins/$file");
63         
64         if (!is_file($real_file))
65                 $error = 1;
66         
67         if (!$error) {
68                 $f = fopen($real_file, 'r');
69                 $content = fread($f, filesize($real_file));
70                 $content = htmlspecialchars($content);
71         }
72
73         ?>
74 <?php if (isset($_GET['a'])) : ?>
75  <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
76 <?php endif; ?>
77  <div class="wrap"> 
78   <?php
79         if (is_writeable($real_file)) {
80                 echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), $file) . '</h2>';
81         } else {
82                 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), $file) . '</h2>';
83         }
84         ?>
85         <div id="templateside">
86 <h3><?php _e('Plugin files') ?></h3>
87
88 <?php
89 if ($plugin_files) :
90 ?>
91   <ul>
92 <?php foreach($plugin_files as $plugin_file) : ?>
93                  <li><a href="plugin-editor.php?file=<?php echo "$plugin_file"; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
94 <?php endforeach; ?>
95   </ul>
96 <?php endif; ?>
97 </div>
98         <?php   if (!$error) { ?> 
99   <form name="template" id="template" action="plugin-editor.php" method="post">
100   <?php wp_nonce_field('edit-plugin_' . $file) ?>
101                  <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 
102      <input type="hidden" name="action" value="update" /> 
103      <input type="hidden" name="file" value="<?php echo $file ?>" /> 
104                 </div>
105 <?php if ( is_writeable($real_file) ) : ?>
106      <p class="submit">
107 <?php
108         echo "<input type='submit' name='submit' value='        " . __('Update File') . " &raquo;' tabindex='2' />";
109 ?>
110 </p>
111 <?php else : ?>
112 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
113 <?php endif; ?>
114    </form> 
115   <?php
116         } else {
117                 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
118         }
119         ?>
120 <div class="clear"> &nbsp; </div>
121 </div> 
122 <?php
123 break;
124 }
125
126 include("admin-footer.php") ?>