*/
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(''); 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);
}
}