* @based_on "externallink" plugin by Otto Vainio * @based_on "pagelist" plugin by Esther Brunner * */ if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../../').'/'); if(!defined('DOKU_LIB')) define('DOKU_LIB',realpath(dirname(__FILE__).'/../../').'/'); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_LIB.'plugins/'); //define('DOKU_MAIN',realpath(dirname(__FILE__).'/../../../').'/'); // must be run within Dokuwiki if(!defined('DOKU_INC')) die("Cannot find installed DokuWiki"); $CURRENT_URL="https://enhub.org/dokuwiki"; //require_once(DOKU_INC.'/inc/pageutils.php'); require_once(DOKU_INC.'/inc/init.php'); require_once(DOKU_INC.'/inc/template.php'); $target_dir = DOKU_INC. "/data/tmp/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); // start page echo file_get_contents(DOKU_INC.'/lib/plugins/zwidoku/html_start'); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); // Check if image file is a actual image or fake image if(isset($_POST["submit"])) { // Check file size if ($_FILES["fileToUpload"]["size"] > 10000000) { echo "

Sorry, your file is too large (more than 10MB)

"; $uploadOk = 0; die(); } // Check if file already exists if (file_exists($target_file)) { echo "

Sorry, file already exists.

"; $uploadOk = 0; die(); } // Allow certain file formats if($imageFileType != "zwi" && $imageFileType != "ZWI" ) { echo "

Sorry, only ZWI files are allowed.

"; echo "

Please return and select correct ZWI file.

"; $uploadOk = 0; die(); } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; // if everything is ok, try to upload file } else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded."; $zip = new ZipArchive; $zip->open( $target_file); $json=$zip->getFromName('metadata.json'); $infowik=json_decode($json, TRUE); $ZWIversion = $infowik['ZWIversion']; $Title = $infowik['Title']; $Namespace = $infowik['Namespace']; # check plugins $json1=$zip->getFromName('plugins.json'); $infoplugins=json_decode( $json1, TRUE); // list used plugins for consistency foreach(glob(DOKU_INC."lib/plugins/*", GLOB_ONLYDIR) as $dir) { $usedplugins[] = basename($dir); } $json2=$zip->getFromName('metadata.json'); $infopage=json_decode( $json2, TRUE); $Xmeta=$infopage["meta"]; $Xtitle= $Xmeta["title"]; $Xcreator= $Xmeta["creator"]; echo "

" . $Xtitle . "

"; echo "original author: " . $Xcreator . "

"; // get article $article=$zip->getFromName('article.dokuwiki'); //echo "Title=". $Title ."
"; echo "Namespace:". $Namespace ."
"; $newtitle = str_replace(":", "/", $Title) . ".txt"; $out_file= DOKU_INC."data/pages/".$newtitle; $articleExist=False; if (file_exists($out_file)) { $ss=" Old Revisions "; echo "

"; echo "Status: replacement for the existing article with the same name.
"; echo "Article $Title was replaced. If this is not your intension, revert it using $ss
"; echo "

"; $articleExist=true; } else { echo "

"; echo "Status: New article"; echo "

"; //echo "Fill name of the new article: ". $Title ."
"; } echo "ZWI format version=". $ZWIversion ."
"; echo "Checking compartibility of used plugins
"; $compat=true; foreach ($usedplugins as &$value) { $ex=false; foreach ($infoplugins as &$val) if ($val == $value) $ex=true; if ($ex == false) { echo "Warning: plugin \"$value\" used for this ZWI file is missing
"; $compat=false; }; } if ($compat) echo "All plugins used for this file are available in the system
"; file_put_contents($out_file, $article); $xpath=str_replace(":", "/", $Title); $out_dir= DOKU_INC."data/tmp/".$xpath; $zip->extractTo($out_dir); // we always copy (add) media from ZWI $xm="/data/media/".$Namespace."/"; $out_media = DOKU_INC.$xm; $input_media = $out_dir . $xm; $cmd="cp -rf $input_media $out_media"; shell_exec("mkdir -p " . $out_meta); shell_exec($cmd); // new article. Then copy meta and history if ($articleExist==false) { // if this is new article, we also copy previous revisions and meta $xm="/data/attic/".$Namespace."/"; $input_attic = $out_dir . $xm; $out_attic = DOKU_INC.$xm; $cmd="cp -rf $input_attic $out_attic"; #echo $cmd; shell_exec("mkdir -p " . $out_attic); shell_exec($cmd); // if this is new article, we also copy metadata $xm="/data/meta/".$Namespace."/"; $input_meta = $out_dir . $xm; $out_meta = DOKU_INC.$xm; $cmd="cp -rf $input_meta $out_meta"; shell_exec("mkdir -p " . $out_meta); shell_exec($cmd); echo "Old revisions were imported from the ZWI file.
"; } // echo "All media files for this article were imported
"; echo "Done! Your article in the Staged article area "; $zip->close(); // cleaning //$cmd="rm -rf $out_dir"; //shell_exec($cmd); unlink( $target_file ); // reading zip file end } else { die("Sorry, there was an error uploading your file."); } } } echo file_get_contents(DOKU_INC.'/lib/plugins/zwidoku/html_end'); ?>