str('onlyCode'); $insideTag = $INPUT->str('insideTag'); $title=tpl_pagetitle(null,true); $titletext=tpl_pagetitle(null,true); if (empty($conf['useacl']) || auth_quickaclcheck($ID) >= AUTH_READ) { $file = rawWiki($ID); $articleWiki = $file; $fileLastMod = wikiFN($ID); $lastMod = @filemtime($fileLastMod); // from page $NS=getNS($ID); // get revisions $filepath = str_replace(":", "/", $ID); // list all revisions $path=DOKU_INC."data/attic/". $filepath."*"; $files = glob($path); //print_r($files); $changes="data/meta/".$filepath .".changes"; $indexed="data/meta/".$filepath .".indexed"; $meta="data/meta/".$filepath .".meta"; $dir_changes=DOKU_INC."data/meta/".$filepath .".changes"; $dir_indexed=DOKU_INC."data/meta/".$filepath .".indexed"; $dir_meta=DOKU_INC."data/meta/".$filepath .".meta"; //echo $dir_changes; //if ($onlyCode) // $file = preg_replace('/[\s\S]*/m', '', preg_replace('/<\/code>[\s\S]*/m', '', $file)); //if ($insideTag) // $file = preg_replace('/[\s\S]*<' . $insideTag . '[^>]*>/m', '', preg_replace('/<\/' . $insideTag . '>[\s\S]*/m', '', $file)); //print $file; // file_put_contents("tmp/article.txt", $file); $pieces = explode(":", $ID); $filename="article"; if (count($pieces)>1) $filename=texifyReference($pieces[1]); // no spaces etc.. $filename=DOKU_INC."data/cache/".$filename . ".zwi"; $zipfilename=$filename; // clear unlink( $filename ); //$filename="/tmp/".$filename . ".wik"; //echo $filename; //die("OK"); $zip = new ZipArchive; $isZipOpen=$zip->open($filename, ZipArchive::CREATE); if ($isZipOpen === TRUE) { // Add files to the zip file //$zip->addFile('test.txt'); //$zip->addFile('test.pdf'); // Add random.txt file to zip and rename it to newfile.txt //$zip->addFile('random.txt', 'newfile.txt'); // Add a file new.txt file to zip using the text specified $zip->addFromString('article.dokuwiki', $articleWiki); // XHTML for embedding $xx=$CURRENT_URL."/doku.php?id=".$ID."&do=export_xhtmlbody"; $body_content = file_get_contents($xx); # push all revisions too $xr=0; foreach ($files as $xfile) { $destination = str_replace(DOKU_INC, "", $xfile); //print($destination); $zip->addFile($xfile, $destination); $xr=$xr+1; }; // metadata $zip->addFile($dir_changes, $changes); $zip->addFile($dir_indexed, $indexed); $zip->addFile($dir_meta, $meta); // css $css_file=DOKU_INC."/lib/plugins/zwidoku/files/common.css"; $zip->addFile($css_file, "data/css/common.css"); $css_file=DOKU_INC."/lib/plugins/zwidoku/files/fonts.css"; $zip->addFile($css_file, "data/css/fonts.css"); $css_file=DOKU_INC."/lib/plugins/zwidoku/files/doku.css"; $zip->addFile($css_file, "data/css/doku.css"); $page_title=tpl_pagetitle(null,true); //$page_info=tpl_pageinfo(true); //die("OK"); // list used plugins for consistency foreach(glob(DOKU_INC."lib/plugins/*", GLOB_ONLYDIR) as $dir) { $usedplugins[] = basename($dir); } $zip->addFromString('plugins.json', json_encode($usedplugins)); $DESC = new ShortDescription($articleWiki,$articleTXT); $description=$DESC->getDescription(); $Lang="en"; // remove styles $html_tmp=preg_replace('/(<(script|style)\b[^>]*>).*?(<\/\2>)/is', "$1$3", $body_content); $html_tmp=strip_tags($html_tmp, ''); // remove bold, so it will not move to upper case; $html_tmp=strip_tags($html_tmp, ''); // remove italic $html2TextConverter = new \Html2Text\Html2Text($html_tmp); $articleTXT = $html2TextConverter->getText(); $content_array= array(); $content_array["article.dokuwiki"]=sha1($file); //$revision->getSha1(); $content_array["article.html"]=sha1($body_content); $content_array["article.txt"]=sha1($articleTXT); $generator="DokuWiki"; // ZWI -specific metadata for the current revision $tt['ZWIversion'] = "1.3"; $tt['Primary'] = "article.dokuwiki"; $tt['Title'] = $title; $tt['Namespace'] = $NS; $tt['LastModified'] = dformat($INFO['lastmod']); $tt['TimeCreated'] = dformat($INFO['lastmod']); $tt['Location'] = $fileLastMod; $tt['Revisions'] = $xr; $tt['Publisher']=$wgMzwiName; $tt['Content'] = $content_array; $tt['GeneratorName'] = $generator; // short description // article information $pagemeta=pageinfo(); // do not expose pass $pagemeta["userinfo"]["pass"]=""; $tt['PageInfo'] = $pagemeta; //$tt['Creator']=$pagemeta['meta'][; //$tt['Contributors']=$pagemeta['contributor']; // $mresult = array_merge($tt, $pagemeta); //$mresult=$tt; $tt['Lang'] = $Lang; //$tt['Comment'] = $title->getEditNotices (); $tt['Rating'] = ""; $tt['License'] = $wgMzwiLicense; $tt['Description']=$description; $tt['Author']=$author; // write $zip->addFromString('metadata.json', json_encode($tt, JSON_PRETTY_PRINT)); $toReplace = array(); $replacement = array(); $nn=0; $doc = new DOMDocument(); @$doc->loadHTML($body_content); $tags = $doc->getElementsByTagName('img'); foreach ($tags as $tag) { $URL=$tag->getAttribute('src'); //die($URL); $pieces = explode($NS.":", $URL); $img="none"; if (count($pieces)) $img=$pieces[1]; $output="data/media/".$NS."/".$img; //echo $output ."\n"; $imgfile_tmp=$output; //die($imgfile_tmp); $imgfile=DOKU_INC.$output; //die($imgfile); $info = pathinfo($imgfile); $ext = $info["extension"]; if (strlen($ext)<1) continue; if (!file_exists($imgfile)) continue; //die($imgfile); //echo $imgfile ."\n"; $URL = str_replace("&", "&", $URL); //echo $URL . " -> " . $imgfile; //die($imgfile); //print($URL); $zip->addFile($imgfile, $output); array_push($toReplace,$URL); array_push($replacement,$imgfile_tmp); //$newbody_content = str_replace($URL, $imgfile_tmp, $body_content); //$newhtml_content = str_replace($URL, $imgfile_tmp, $html_content); //print($URL. "\n"); $nn=$nn+1; } //print_r($toReplace); //print_r($replacement); //die(); //$newhtml_content = str_replace($toReplace, $replacement, $html_content); $newbody_content = str_replace($toReplace, $replacement, $body_content); //print($newhtml_content); //die(); /* $lines = explode("\n", $newbody_content); $exclude = array(); $n=0; foreach ($lines as $line) { if (strpos($line, 'stylesheet') !== FALSE) { $exclude[] = ""; continue; } $exclude[] = $line; } $newhtml_content=implode("\n", $exclude); */ $start_content = file_get_contents( DOKU_INC."/lib/plugins/zwidoku/html_start" ); $end_content = file_get_contents( DOKU_INC."/lib/plugins/zwidoku/html_end" ); $html_content = $start_content . $newbody_content . $end_content; $zip->addFromString('article.html', $html_content); // $zip->addFromString('article.xhtml', $newbody_content); $zip->addFromString("article.txt", $articleTXT); } // All files are added, so close the zip file. $zip->close(); /* if (file_exists($filename)) { print($filename); }; */ /* if (file_exists($filename)) { header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="'.basename($filename).'"'); header('Content-Length: ' . filesize($filename)); flush(); readfile($filename); // delete file unlink($filename); } */ //die($ext_path); $permissionErr = 0; $xsub=""; if ($permissionErr ==0) $xsub=""; else if ($permissionErr == 1) $xsub="
(not registered user)"; else if ($permissionErr == 2) $xsub="
(did not contribute to this article)"; $submit_script=$ext_path . "/" . "zwipush.php"; $str = << ZWI submit

Export the article '$title' ?

$xsub
Submit this article to the Encyclosphere Network that can be viewed in EncycloReader supported by EncyclosphereKSF


Save this article to your computer

EOD; print($str); } else print "Unauthorized"; ?>