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