source: documentation/trunk/packages/dokuwiki-2011-05-25a/lib/plugins/plugin/classes/ap_manage.class.php@ 25027

Last change on this file since 25027 was 25027, checked in by jmt12, 12 years ago

Adding the packages directory, and within it a configured version of dokuwiki all ready to run

File size: 6.1 KB
Line 
1<?php
2
3class ap_manage {
4
5 var $manager = NULL;
6 var $lang = array();
7 var $plugin = '';
8 var $downloaded = array();
9
10 function ap_manage(&$manager, $plugin) {
11 $this->manager = & $manager;
12 $this->plugin = $plugin;
13 $this->lang = & $manager->lang;
14 }
15
16 function process() {
17 return '';
18 }
19
20 function html() {
21 print $this->manager->locale_xhtml('admin_plugin');
22 $this->html_menu();
23 }
24
25 // build our standard menu
26 function html_menu($listPlugins = true) {
27 global $ID;
28
29 ptln('<div class="pm_menu">');
30
31 ptln('<div class="common">');
32 ptln(' <h2>'.$this->lang['download'].'</h2>');
33 ptln(' <form action="'.wl($ID).'" method="post">');
34 ptln(' <fieldset class="hidden">',4);
35 ptln(' <input type="hidden" name="do" value="admin" />');
36 ptln(' <input type="hidden" name="page" value="plugin" />');
37 formSecurityToken();
38 ptln(' </fieldset>');
39 ptln(' <fieldset>');
40 ptln(' <legend>'.$this->lang['download'].'</legend>');
41 ptln(' <label for="dw__url">'.$this->lang['url'].'<input name="url" id="dw__url" class="edit" type="text" maxlength="200" /></label>');
42 ptln(' <input type="submit" class="button" name="fn[download]" value="'.$this->lang['btn_download'].'" />');
43 ptln(' </fieldset>');
44 ptln(' </form>');
45 ptln('</div>');
46
47 if ($listPlugins) {
48 ptln('<h2>'.$this->lang['manage'].'</h2>');
49
50 ptln('<form action="'.wl($ID).'" method="post" class="plugins">');
51
52 ptln(' <fieldset class="hidden">');
53 ptln(' <input type="hidden" name="do" value="admin" />');
54 ptln(' <input type="hidden" name="page" value="plugin" />');
55 formSecurityToken();
56 ptln(' </fieldset>');
57
58 $this->html_pluginlist();
59
60 ptln(' <fieldset class="buttons">');
61 ptln(' <input type="submit" class="button" name="fn[enable]" value="'.$this->lang['btn_enable'].'" />');
62 ptln(' </fieldset>');
63
64 // ptln(' </div>');
65 ptln('</form>');
66 }
67
68 ptln('</div>');
69 }
70
71 function html_pluginlist() {
72 global $ID;
73 global $plugin_protected;
74
75 foreach ($this->manager->plugin_list as $plugin) {
76
77 $disabled = plugin_isdisabled($plugin);
78 $protected = in_array($plugin,$plugin_protected);
79
80 $checked = ($disabled) ? '' : ' checked="checked"';
81 $check_disabled = ($protected) ? ' disabled="disabled"' : '';
82
83 // determine display class(es)
84 $class = array();
85 if (in_array($plugin, $this->downloaded)) $class[] = 'new';
86 if ($disabled) $class[] = 'disabled';
87 if ($protected) $class[] = 'protected';
88
89 $class = count($class) ? ' class="'.join(' ', $class).'"' : '';
90
91 ptln(' <fieldset'.$class.'>');
92 ptln(' <legend>'.$plugin.'</legend>');
93 ptln(' <input type="checkbox" class="enable" name="enabled[]" value="'.$plugin.'"'.$checked.$check_disabled.' />');
94 ptln(' <h3 class="legend">'.$plugin.'</h3>');
95
96 $this->html_button($plugin, 'info', false, 6);
97 if (in_array('settings', $this->manager->functions)) {
98 $this->html_button($plugin, 'settings', !@file_exists(DOKU_PLUGIN.$plugin.'/settings.php'), 6);
99 }
100 $this->html_button($plugin, 'update', !$this->plugin_readlog($plugin, 'url'), 6);
101 $this->html_button($plugin, 'delete', $protected, 6);
102
103 ptln(' </fieldset>');
104 }
105 }
106
107 function html_button($plugin, $btn, $disabled=false, $indent=0) {
108 $disabled = ($disabled) ? 'disabled="disabled"' : '';
109 ptln('<input type="submit" class="button" '.$disabled.' name="fn['.$btn.']['.$plugin.']" value="'.$this->lang['btn_'.$btn].'" />',$indent);
110 }
111
112 /**
113 * Refresh plugin list
114 */
115 function refresh() {
116 global $config_cascade;
117
118 // expire dokuwiki caches
119 // touching local.php expires wiki page, JS and CSS caches
120 @touch(reset($config_cascade['main']['local']));
121
122 // update latest plugin date - FIXME
123 global $ID;
124 send_redirect(wl($ID,array('do'=>'admin','page'=>'plugin'),true, '&'));
125 }
126
127 /**
128 * Write a log entry to the given target directory
129 */
130 function plugin_writelog($target, $cmd, $data) {
131
132 $file = $target.'/manager.dat';
133
134 switch ($cmd) {
135 case 'install' :
136 $url = $data[0];
137 $date = date('r');
138 if (!$fp = @fopen($file, 'w')) return;
139 fwrite($fp, "installed=$date\nurl=$url\n");
140 fclose($fp);
141 break;
142
143 case 'update' :
144 $date = date('r');
145 if (!$fp = @fopen($file, 'a')) return;
146 fwrite($fp, "updated=$date\n");
147 fclose($fp);
148 break;
149 }
150 }
151
152 function plugin_readlog($plugin, $field) {
153 static $log = array();
154 $file = DOKU_PLUGIN.plugin_directory($plugin).'/manager.dat';
155
156 if (!isset($log[$plugin])) {
157 $tmp = @file_get_contents($file);
158 if (!$tmp) return '';
159 $log[$plugin] = & $tmp;
160 }
161
162 if ($field == 'ALL') {
163 return $log[$plugin];
164 }
165
166 $match = array();
167 if (preg_match_all('/'.$field.'=(.*)$/m',$log[$plugin], $match))
168 return implode("\n", $match[1]);
169
170 return '';
171 }
172
173 /**
174 * delete, with recursive sub-directory support
175 */
176 function dir_delete($path) {
177 if (!is_string($path) || $path == "") return false;
178
179 if (is_dir($path) && !is_link($path)) {
180 if (!$dh = @opendir($path)) return false;
181
182 while ($f = readdir($dh)) {
183 if ($f == '..' || $f == '.') continue;
184 $this->dir_delete("$path/$f");
185 }
186
187 closedir($dh);
188 return @rmdir($path);
189 } else {
190 return @unlink($path);
191 }
192
193 return false;
194 }
195
196
197}
Note: See TracBrowser for help on using the repository browser.