first commit. dokuwiki.
[h2N7SspZmY.git] / lib / plugins / plugin / classes / ap_manage.class.php
blob297764ebb2e866282a0a0b88b506b45c87bd904a
1 <?php
3 class ap_manage {
5 var $manager = NULL;
6 var $lang = array();
7 var $plugin = '';
8 var $downloaded = array();
10 function ap_manage(&$manager, $plugin) {
11 $this->manager = & $manager;
12 $this->plugin = $plugin;
13 $this->lang = & $manager->lang;
16 function process() {
17 return '';
20 function html() {
21 print $this->manager->locale_xhtml('admin_plugin');
22 $this->html_menu();
25 // build our standard menu
26 function html_menu($listPlugins = true) {
27 global $ID;
29 ptln('<div class="pm_menu">');
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>');
47 if ($listPlugins) {
48 ptln('<h2>'.$this->lang['manage'].'</h2>');
50 ptln('<form action="'.wl($ID).'" method="post" class="plugins">');
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>');
58 $this->html_pluginlist();
60 ptln(' <fieldset class="buttons">');
61 ptln(' <input type="submit" class="button" name="fn[enable]" value="'.$this->lang['btn_enable'].'" />');
62 ptln(' </fieldset>');
64 // ptln(' </div>');
65 ptln('</form>');
68 ptln('</div>');
71 function html_pluginlist() {
72 global $ID;
73 global $plugin_protected;
75 foreach ($this->manager->plugin_list as $plugin) {
77 $disabled = plugin_isdisabled($plugin);
78 $protected = in_array($plugin,$plugin_protected);
80 $checked = ($disabled) ? '' : ' checked="checked"';
81 $check_disabled = ($protected) ? ' disabled="disabled"' : '';
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';
89 $class = count($class) ? ' class="'.join(' ', $class).'"' : '';
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>');
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);
100 $this->html_button($plugin, 'update', !$this->plugin_readlog($plugin, 'url'), 6);
101 $this->html_button($plugin, 'delete', $protected, 6);
103 ptln(' </fieldset>');
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);
113 * Refresh plugin list
115 function refresh() {
116 global $MSG,$config_cascade;
118 //are there any undisplayed messages? keep them in session for display
119 if (isset($MSG) && count($MSG)){
120 //reopen session, store data and close session again
121 @session_start();
122 $_SESSION[DOKU_COOKIE]['msg'] = $MSG;
123 session_write_close();
126 // expire dokuwiki caches
127 // touching local.php expires wiki page, JS and CSS caches
128 @touch(reset($config_cascade['main']['local']));
130 // update latest plugin date - FIXME
131 header('Location: '.wl($ID).'?do=admin&page=plugin');
132 exit();
136 * Write a log entry to the given target directory
138 function plugin_writelog($target, $cmd, $data) {
140 $file = $target.'/manager.dat';
142 switch ($cmd) {
143 case 'install' :
144 $url = $data[0];
145 $date = date('r');
146 if (!$fp = @fopen($file, 'w')) return;
147 fwrite($fp, "installed=$date\nurl=$url\n");
148 fclose($fp);
149 break;
151 case 'update' :
152 $date = date('r');
153 if (!$fp = @fopen($file, 'a')) return;
154 fwrite($fp, "updated=$date\n");
155 fclose($fp);
156 break;
160 function plugin_readlog($plugin, $field) {
161 static $log = array();
162 $file = DOKU_PLUGIN.plugin_directory($plugin).'/manager.dat';
164 if (!isset($log[$plugin])) {
165 $tmp = @file_get_contents($file);
166 if (!$tmp) return '';
167 $log[$plugin] = & $tmp;
170 if ($field == 'ALL') {
171 return $log[$plugin];
174 $match = array();
175 if (preg_match_all('/'.$field.'=(.*)$/m',$log[$plugin], $match))
176 return implode("\n", $match[1]);
178 return '';
182 * delete, with recursive sub-directory support
184 function dir_delete($path) {
185 if (!is_string($path) || $path == "") return false;
187 if (is_dir($path)) {
188 if (!$dh = @opendir($path)) return false;
190 while ($f = readdir($dh)) {
191 if ($f == '..' || $f == '.') continue;
192 $this->dir_delete("$path/$f");
195 closedir($dh);
196 return @rmdir($path);
197 } else {
198 return @unlink($path);
201 return false;