*/ /** * All DokuWiki plugins to extend the admin function * need to inherit from this class */ class admin_plugin_preregister extends DokuWiki_Admin_Plugin { var $output = ''; private $metaFn; function __construct() { $metafile= 'preregister:db'; $this->metaFn = metaFN($metafile,'.ser'); } /** * handle user request */ function handle() { if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do $this->output = 'invalid'; if (!checkSecurityToken()) return; if (!is_array($_REQUEST['cmd'])) return; // verify valid values switch (key($_REQUEST['cmd'])) { case 'confirm' : $this->prune_datafile($_REQUEST['del']) ; break; case 'secure' : $this->secure_datafile() ; break; } // msg('
' . print_r($_REQUEST['del'],true) . '
'); } /** * output appropriate html */ function html() { ptln('Toggle info
'); ptln('
'. $this->locale_xhtml('info') . '

' ); ptln('
'); // output hidden values to ensure dokuwiki will return back to this plugin ptln(' '); ptln(' '); formSecurityToken(); ptln('   '); ptln(' '); ptln('

'); echo $this->getConfirmList(); ptln('
'); ptln('
'); $this->js(); } function getConfirmList() { global $conf; $delete_time = $this->getConf('list_age'); if(strpos($delete_time,'*') !== false) { $elems = explode('*',$delete_time); $delete_time = 1; foreach($elems as $n) { $delete_time *= $n; } } $data = unserialize(io_readFile($this->metaFn,false)); if (!is_array($data)) $data = array(); $hidden = array(); $result = ""; $current_time = time(); foreach($data as $index=>$entry) { $age = $current_time - $entry['savetime']; if($age >= $delete_time) { $hidden[] = $index; $hours = round(($age/3600),2); if($hours >= 24) { $hours = round($hours/24,2); $hours .= ' day(s)'; } else $hours .= ' hours'; $result .= '\n"; } } $result .= '
loginemailnamesave timeage
'. $entry['login'] . '' . $entry['email'] . '' . $entry['fullname'] . '' . strftime($conf['dformat'],$entry['savetime']) . '' . $hours . "
'; foreach($hidden as $del) { $result .= "\n"; } return $result ."\n"; } function secure_datafile() { $perm = substr(sprintf('%o', fileperms($this->metaFn )), -4); if(preg_match('/\d\d(\d)/',$perm,$matches)) { if($matches[1] > 0) { msg("Data file is currently accessible to all: $perm"); if(chmod($this->metaFn ,0600)) { msg("Succesfully change permissions to: 0600"); } else msg("Unable to change permissions to: 0600"); } } } function prune_datafile($which) { $data = unserialize(io_readFile($this->metaFn,false)); if (!is_array($data)) $data = array(); foreach($data as $index=>$entry) { if(in_array($index,$which)) { unset($data[$index]); } } io_saveFile($this->metaFn,serialize($data)); } function js() { echo << SCRIPT; } }