function ewiki_page_wiki_mini_tarball_dump($id, $data, $action) { global $ewiki_config, $ewiki_plugins; #-- get all pages / binary files $result = ewiki_db::GETALL(array("id", "version", "flags")); if ($result) { #-- HTTP headers header("Content-Type: application/x-tar"); header("Content-Disposition: attachment; filename=\"InitPages.tar.gz\""); #-- start tar file $tarball = new ewiki_virtual_tarball(); $tarball->open(0); #-- convert all pages while ($row = $result->get(0, 0x1037)) { $id = $row["id"]; $row = ewiki_db::GET($id); $content =& $row["content"]; $fn = $id; if (!$row || !$row["id"] || !$row["content"]) { continue; } #-- for tarball $perms = array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00)); #-- add file $tarball->add($fn, $content, $perms); } #-- end output $tarball->close(); } #-- fin die; }
function ewiki_page_wiki_dump_send($imgs = 1, $fullhtml = 0, $virtual = 0, $rootid, $depth = 1, $arctype = EWIKI_WIKIDUMP_DEFAULTTYPE, $complevel = 1) { global $ewiki_config, $ewiki_plugins; #-- disable protected email foreach ($ewiki_plugins["link_url"] as $key => $linkplugin) { if ($linkplugin == "ewiki_email_protect_link") { unset($ewiki_plugins["link_url"][$key]); } } #-- set uservars $a_uservars = ewiki_get_uservar("WikiDump", array()); if (!is_array($a_uservars)) { $a_uservars = unserialize($a_uservars); } $a_uservars[$rootid] = $depth; ewiki_set_uservar("WikiDump", $a_uservars); #-- if $fullhtml $HTML_TEMPLATE = '<html> <head>' . ewiki_t("EWIKIDUMPCSS") . ' <title>$title</title> </head> <body bgcolor="#ffffff";> <div id="PageText"> <h2>$title</h2> $content </div> </body> </html> '; #-- reconfigure ewiki_format() to generate offline pages and files $html_ext = ".htm"; if ($fullhtml) { $html_ext = ".html"; } $ewiki_config["script"] = "%s{$html_ext}"; $ewiki_config["script_binary"] = "%s"; #-- fetch also dynamic pages $a_virtual = array_keys($ewiki_plugins["page"]); #-- get all pages / binary files $a_validpages = ewiki_valid_pages(1, $virtual); $a_pagelist = ewiki_sitemap_create($rootid, $a_validpages, $depth, 1); foreach ($a_pagelist as $key => $value) { if (is_array($a_validpages[$value]["refs"])) { foreach ($a_validpages[$value]["refs"] as $refs) { if ($a_validpages[$refs]["type"] == "image") { $a_pagelist[] = $refs; } } } } foreach ($a_pagelist as $key => $value) { if ($a_validpages[$value]["type"] == "image") { $a_images[] = urlencode($value); $a_rimages[] = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $value)); unset($a_validpages[$value]); } } $a_sitemap = ewiki_sitemap_create($rootid, $a_validpages, $depth, 0); if ($a_pagelist) { #-- create new zip file if ($arctype == "ZIP") { $archivename = EWIKI_WIKIDUMP_ARCNAME . "{$rootid}.zip"; $archive = new ewiki_virtual_zip(); } elseif ($arctype == "TAR") { $archivename = EWIKI_WIKIDUMP_ARCNAME . "{$rootid}.tar"; $archive = new ewiki_virtual_tarball(); } else { die; } $a_pagelist = array_unique($a_pagelist); #-- convert all pages foreach ($a_pagelist as $pagename) { if (!in_array($pagename, $a_virtual)) { $id = $pagename; #-- not a virtual page $row = ewiki_db::GET($pagename); $content = ""; } elseif ($virtual) { $id = $pagename; #-- is a virtual page $pf = $ewiki_plugins["page"][$id]; $content = $pf($id, $content, "view"); if ($fullhtml) { $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE)); } $fn = urlencode($id); $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $fn); $fn = $fn . $html_ext; } else { continue; } if (empty($content)) { switch ($row["flags"] & EWIKI_DB_F_TYPE) { case EWIKI_DB_F_TEXT: $content = ewiki_format($row["content"]); $content = str_replace($a_images, $a_rimages, $content); $fn = preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", urlencode($id)); $fn = $fn . $html_ext; if ($fullhtml) { $content = str_replace('$content', $content, str_replace('$title', $id, $HTML_TEMPLATE)); } break; case EWIKI_DB_F_BINARY: if ($row["meta"]["class"] == "image" && $imgs) { $fn = urlencode(preg_replace(EWIKI_DUMP_FILENAME_REGEX, "", $id)); $content =& $row["content"]; } else { #-- php considers switch statements as loops so continue 2 is needed to #-- hit the end of the for loop continue 2; } break; default: # don't want it continue 2; } } $content = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $content); #-- add file $archive->add($content, $fn, array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00)), $complevel); } #-- create index page $timer = array(); $level = -1; $fordump = 1; $str_formatted = "<ul>\n<li><a href=\"" . $rootid . $html_ext . "\">" . $rootid . "</a></li>"; $fin_level = format_sitemap($a_sitemap, $rootid, $str_formatted, $level, $timer, $fordump); $str_formatted .= "</ul>" . str_pad("", $fin_level * 6, "</ul>\n"); $str_formatted = preg_replace_callback('/(<a href=")(.*?)(\\.html">)/', create_function('$matches', 'return($matches[1].preg_replace(EWIKI_DUMP_FILENAME_REGEX,"",$matches[2]).$matches[3]);'), $str_formatted); #-- add index page $archive->add($str_formatted, "Index_{$rootid}" . $html_ext, array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00)), $complevel); #-- Headers Header("Content-type: application/octet-stream"); Header("Content-disposition: attachment; filename=\"{$archivename}\""); Header("Cache-control: private"); Header("Original-Filename: {$archivename}"); Header("X-Content-Type: application/octet-stream"); Header("Content-Location: {$archivename}"); #-- end output echo $archive->close(); } #-- fin die; }
function ewiki_page_wiki_dump_send($imgs = 1, $fullhtml = 0, $virtual = 0, $linksto = 0) { global $ewiki_config, $ewiki_plugins; #-- reconfigure ewiki_format() to generate offline pages and files $html_ext = ".htm"; if ($fullhtml) { $html_ext = ".html"; } $ewiki_config["script"] = "%s{$html_ext}"; $ewiki_config["script_binary"] = "%s"; $ewiki_config["print_title"] = 0; #-- fetch also dynamic pages if ($virtual) { $virtual = array_keys($ewiki_plugins["page"]); } else { $virtual = array(); } #-- get all pages / binary files $result = ewiki_db::GETALL(array("id", "version", "flags")); if ($result) { #-- HTTP headers header("Content-Type: application/x-tar"); header("Content-Disposition: attachment; filename=\"WikiDump.tar.gz\""); #-- start tar file $tarball = new ewiki_virtual_tarball(); $tarball->open(0); #-- convert all pages while (($row = $result->get()) || count($virtual)) { $content = ""; #-- fetch page from database if ($id = $row["id"]) { $row = ewiki_db::GET($id); } elseif ($id = array_pop($virtual)) { $pf = $ewiki_plugins["page"][$id]; $content = $pf($id, $content, "view"); $row = array("flags" => EWIKI_DB_F_TEXT | EWIKI_DB_F_HTML, "lastmodified" => time()); } else { break; } #-- file name $fn = $id; $fn = urlencode($fn); #-- post process for ordinary pages / binary data if (empty($content)) { switch ($row["flags"] & EWIKI_DB_F_TYPE) { case EWIKI_DB_F_TEXT: $content = ewiki_format($row["content"]); break; case EWIKI_DB_F_BINARY: if ($row["meta"]["class"] == "image" && $imgs) { $content =& $row["content"]; } else { return; } break; default: # don't want it continue; } } #-- size check if (empty($content)) { continue; } #-- for tarball $perms = array("mtime" => $row["lastmodified"], "uname" => "ewiki", "mode" => 0664 | ($row["flags"] & EWIKI_DB_F_WRITEABLE ? 02 : 00)); #-- html post process if (!($row["flags"] & EWIKI_DB_F_BINARY)) { #-- use page template if ($fullhtml) { $content = ewiki_dump_template($id, $content, $linksto); } #-- add links/ page if ($linksto) { $tarball->add("{$fn}.links{$html_ext}", ewiki_dump_template($id, ewiki_page_links($id, $row, "links"), $lto = -1), $perms); } $fn .= $html_ext; } #-- add file $tarball->add($fn, $content, $perms); } #-- end output $tarball->close(); } #-- fin die; }