8 var $downloaded = array();
10 function ap_manage(&$manager, $plugin) {
11 $this->manager
= & $manager;
12 $this->plugin
= $plugin;
13 $this->lang
= & $manager->lang
;
21 print $this->manager
->locale_xhtml('admin_plugin');
25 // build our standard menu
26 function html_menu($listPlugins = true) {
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" />');
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'].'" />');
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" />');
58 $this->html_pluginlist();
60 ptln(' <fieldset class="buttons">');
61 ptln(' <input type="submit" class="button" name="fn[enable]" value="'.$this->lang
['btn_enable'].'" />');
71 function html_pluginlist() {
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)
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
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
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');
136 * Write a log entry to the given target directory
138 function plugin_writelog($target, $cmd, $data) {
140 $file = $target.'/manager.dat';
146 if (!$fp = @fopen
($file, 'w')) return;
147 fwrite($fp, "installed=$date\nurl=$url\n");
153 if (!$fp = @fopen
($file, 'a')) return;
154 fwrite($fp, "updated=$date\n");
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];
175 if (preg_match_all('/'.$field.'=(.*)$/m',$log[$plugin], $match))
176 return implode("\n", $match[1]);
182 * delete, with recursive sub-directory support
184 function dir_delete($path) {
185 if (!is_string($path) ||
$path == "") return false;
188 if (!$dh = @opendir
($path)) return false;
190 while ($f = readdir($dh)) {
191 if ($f == '..' ||
$f == '.') continue;
192 $this->dir_delete("$path/$f");
196 return @rmdir
($path);
198 return @unlink
($path);