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 | |
---|
25 | $plugin_files = array(); |
---|
26 | foreach($plugins as $plugin) { |
---|
27 | $plugin_files[] = $plugin['Filename']; |
---|
28 | } |
---|
29 | |
---|
30 | if (empty($file)) { |
---|
31 | $file = $plugin_files[0]; |
---|
32 | } |
---|
33 | |
---|
34 | $file = validate_file_to_edit($file, $plugin_files); |
---|
35 | $real_file = get_real_file_to_edit("wp-content/plugins/$file"); |
---|
36 | |
---|
37 | switch($action) { |
---|
38 | |
---|
39 | case 'update': |
---|
40 | |
---|
41 | if ($user_level < 5) { |
---|
42 | die(__('<p>You have do not have sufficient permissions to edit templates for this blog.</p>')); |
---|
43 | } |
---|
44 | |
---|
45 | $newcontent = stripslashes($_POST['newcontent']); |
---|
46 | if (is_writeable($real_file)) { |
---|
47 | $f = fopen($real_file, 'w+'); |
---|
48 | fwrite($f, $newcontent); |
---|
49 | fclose($f); |
---|
50 | header("Location: plugin-editor.php?file=$file&a=te"); |
---|
51 | } else { |
---|
52 | header("Location: plugin-editor.php?file=$file"); |
---|
53 | } |
---|
54 | |
---|
55 | exit(); |
---|
56 | |
---|
57 | break; |
---|
58 | |
---|
59 | default: |
---|
60 | |
---|
61 | require_once('admin-header.php'); |
---|
62 | if ($user_level <= 5) { |
---|
63 | die(__('<p>You have do not have sufficient permissions to edit plugins for this blog.</p>')); |
---|
64 | } |
---|
65 | |
---|
66 | update_recently_edited("wp-content/plugins/$file"); |
---|
67 | |
---|
68 | if (!is_file($real_file)) |
---|
69 | $error = 1; |
---|
70 | |
---|
71 | if (!$error) { |
---|
72 | $f = fopen($real_file, 'r'); |
---|
73 | $content = fread($f, filesize($real_file)); |
---|
74 | $content = htmlspecialchars($content); |
---|
75 | } |
---|
76 | |
---|
77 | ?> |
---|
78 | <?php if (isset($_GET['a'])) : ?> |
---|
79 | <div class="updated"><p><?php _e('File edited successfully.') ?></p></div> |
---|
80 | <?php endif; ?> |
---|
81 | <div class="wrap"> |
---|
82 | <?php |
---|
83 | if (is_writeable($real_file)) { |
---|
84 | echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), $file) . '</h2>'; |
---|
85 | } else { |
---|
86 | echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), $file) . '</h2>'; |
---|
87 | } |
---|
88 | ?> |
---|
89 | <div id="templateside"> |
---|
90 | <h3><?php _e('Plugin files') ?></h3> |
---|
91 | |
---|
92 | <?php |
---|
93 | if ($plugin_files) : |
---|
94 | ?> |
---|
95 | <ul> |
---|
96 | <?php foreach($plugins as $plugin) : ?> |
---|
97 | <li><a href="plugin-editor.php?file=<?php echo $plugin['Filename']; ?>"><?php echo $plugin['Name']; ?></a></li> |
---|
98 | <?php endforeach; ?> |
---|
99 | </ul> |
---|
100 | <?php endif; ?> |
---|
101 | </div> |
---|
102 | <?php if (!$error) { ?> |
---|
103 | <form name="template" id="template" action="plugin-editor.php" method="post"> |
---|
104 | <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> |
---|
105 | <input type="hidden" name="action" value="update" /> |
---|
106 | <input type="hidden" name="file" value="<?php echo $file ?>" /> |
---|
107 | </div> |
---|
108 | <?php if ( is_writeable($real_file) ) : ?> |
---|
109 | <p class="submit"> |
---|
110 | <?php |
---|
111 | echo "<input type='submit' name='submit' value=' " . __('Update File') . " »' tabindex='2' />"; |
---|
112 | ?> |
---|
113 | </p> |
---|
114 | <?php else : ?> |
---|
115 | <p><em><?php _e('If this file was writable you could edit it.'); ?></em></p> |
---|
116 | <?php endif; ?> |
---|
117 | </form> |
---|
118 | <?php |
---|
119 | } else { |
---|
120 | echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>'; |
---|
121 | } |
---|
122 | ?> |
---|
123 | </div> |
---|
124 | <?php |
---|
125 | break; |
---|
126 | } |
---|
127 | |
---|
128 | include("admin-footer.php") ?> |
---|