*/ require_once(DOKU_INC . 'lib/plugins/pdftools/functions.php'); class admin_plugin_pdftools extends DokuWiki_Admin_Plugin { var $output = 'COMMAND: none'; function getMenuText($language){ return $this->getLang('admin menu'); } /** * handle user request */ function handle() { # Check if dw2pdf is activated $list = plugin_list(); if(in_array('dw2pdf',$list)===false) return; if (!isset($_REQUEST['cmd'])) return; // first time - nothing to do if (!checkSecurityToken()) return; if (!is_array($_REQUEST['cmd'])) return; // verify valid values $command = key($_REQUEST['cmd']); if (strpos($command,"install:")===0) { $command = str_replace("install:","",$command); $this->output = "COMMAND: Install template '$command'"; recurse_copy(DOKU_PLUGIN."/pdftools/tpl/$command",DOKU_PLUGIN."/dw2pdf/tpl/$command"); } if (strpos($command,"erase:")===0) { $command = str_replace("erase:","",$command); $this->output = "COMMAND: Erase '$command'"; $this->rrmdir(DOKU_PLUGIN."dw2pdf/tpl/$command"); } # Upload templates if(strpos($command,"upload")===0) { $filename = $_FILES["zip_file"]["name"]; $source = $_FILES["zip_file"]["tmp_name"]; $type = $_FILES["zip_file"]["type"]; $name = explode(".", $filename); $accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed'); foreach($accepted_types as $mime_type) { if($mime_type == $type) { $okay = true; break; } } $continue = strtolower($name[1]) == 'zip' ? true : false; if(!$continue) { msg("The file you are trying to upload is not a .zip file. Please try again.",-1); return; } $target_path = DOKU_PLUGIN."dw2pdf/tpl/".$filename; // change this to the correct site path if(move_uploaded_file($source, $target_path)) { # Using Linix unzip on the command line ob_start(); system("unzip -d '".DOKU_PLUGIN."dw2pdf/tpl/' $target_path"); $retval = ob_get_contents(); ob_end_clean(); unlink($target_path); msg("Your .zip file was uploaded and unpacked into the dw2pdf/tpl directory.

$retval
",1); } else { msg("There was a problem with the upload. Could not move uploaded file to plugin directory.",-1); } } } /** * output appropriate html */ function html() { global $ID; ptln('
'); // output hidden values to ensure dokuwiki will return back to this plugin ptln(' '); ptln(' '); formSecurityToken(); $dw = dirList(DOKU_PLUGIN."/dw2pdf/tpl/"); $pi = dirList(DOKU_PLUGIN."/pdftools/tpl/"); echo '

'.$this->getLang('admin title main').'

'; $p_time = filectime(__FILE__); # Upload form echo '

'.$this->getLang('admin title upload').'

'; echo $this->getLang('text upload'); echo '

'; echo '
'; echo '

'.$this->getLang('admin title manage').'

'; echo ''; echo ''; # Installed templates foreach ($dw as $v) { ptln (''); ptln(""); ptln (""); if (file_exists(DOKU_PLUGIN."/dw2pdf/tpl/$v/preview.png")) { ptln (''); } else ptln(""); if (file_exists(DOKU_PLUGIN."/dw2pdf/tpl/$v/description.html")) { ptln (''); } else ptln(""); ptln (''); } # Volagen aus dem Vorlagenpaket, welche nicht installiert sind foreach ($pi as $v) { if (in_array($v,$dw) === false) { ptln (''); ptln (""); ptln(''); if (file_exists(DOKU_PLUGIN."/pdftools/tpl/$v/preview.png")) { ptln (''); } else ptln(""); if (file_exists(DOKU_PLUGIN."/pdftools/tpl/$v/description.html")) { ptln (''); } else ptln(""); ptln (''); } } ptln ('
$v"); if (in_array($v,$pi) !== false) { ptln('

'); } echo '

'; # Zeitpunkt der Installation der Vorlage $m_time = filectime(DOKU_PLUGIN."/dw2pdf/tpl/$v/style.css"); ptln("Installation: ".date("Y-m-d / H:i:s",$m_time)); # Zeitpunkt, an der das Plugin bzw. das Template aktualisiert wurde, prüfen. # Aktualisierungshinweis geben, wenn dieser über dem Zeitpunkt der Installation liegt if (in_array($v,$pi) !== false) { $o_time = filectime(DOKU_PLUGIN."/pdftools/tpl/$v/style.css"); if ($o_time>$m_time) ptln ("

".$this->getLang('text update')."
Update: ".date("Y-m-d / H:i:s",$o_time)."
"); } ptln ("
".$this->getLang('text preview')."'.file_get_contents(DOKU_URL.'lib/plugins/dw2pdf/tpl/'.$v.'/description.html').'".$this->getLang('text desc')."
$v'); ptln('

'); $m_time = filectime(DOKU_PLUGIN."/pdftools/tpl/$v/style.css"); ptln(date("Y-m-d / H:i:s",$m_time)); ptln('
".$this->getLang('text preview')."'.file_get_contents(DOKU_URL.'lib/plugins/pdftools/tpl/'.$v.'/description.html').'".$this->getLang('text desc')."
'); ptln('
'); ptln('
'.htmlspecialchars($this->output).''); } # From: https://www.php.net/manual/de/function.rmdir.php # recursively erase a directory with its subdirectories function rrmdir($src) { $dir = opendir($src); while(false !== ( $file = readdir($dir)) ) { if (( $file != '.' ) && ( $file != '..' )) { $full = $src . '/' . $file; if ( is_dir($full) ) { rrmdir($full); } else { unlink($full); } } } closedir($dir); rmdir($src); } }