function unpack($packed) { if (!$packed) { return false; } // ZLIB format has a five bit checksum in it's header. // Lets check for sanity. if ((ord($packed[0]) * 256 + ord($packed[1])) % 31 == 0 and substr($packed, 0, 2) == "‹" or substr($packed, 0, 2) == "xÚ") { if (function_exists('gzuncompress')) { // Looks like ZLIB. $data = gzuncompress($packed); return unserialize($data); } else { // user our php lib. TESTME include_once "ziplib.php"; $zip = new ZipReader($packed); list(, $data, $attrib) = $zip->readFile(); return unserialize($data); } } if (substr($packed, 0, 2) == "O:") { // Looks like a serialized object return unserialize($packed); } if (preg_match("/^\\w+\$/", $packed)) { return $packed; } // happened with _BackendInfo problem also. trigger_error("Can't unpack bad cached markup. Probably php_zlib extension not loaded.", E_USER_WARNING); return false; }
function LoadZipOrDir($dbi, $zip_or_dir) { global $LANG, $genericpages; $type = filetype($zip_or_dir); if ($type == 'file') { $zip = new ZipReader($zip_or_dir); while (list($fn, $data, $attrib) = $zip->readFile()) { LoadFile($dbi, $fn, $data, $attrib['mtime']); } } else { if ($type == 'dir') { $handle = opendir($dir = $zip_or_dir); // load default pages while ($fn = readdir($handle)) { if ($fn[0] == '.' || filetype("{$dir}/{$fn}") != 'file') { continue; } $stat = stat("{$dir}/{$fn}"); $mtime = $stat[9]; LoadFile($dbi, $fn, implode("", file("{$dir}/{$fn}")), $mtime); } closedir($handle); if ($LANG != "C") { // if language is not default, then insert // generic pages from the English ./pgsrc reset($genericpages); $dir = DEFAULT_WIKI_PGSRC; while (list(, $fn) = each($genericpages)) { LoadFile($dbi, $fn, implode("", file("{$dir}/{$fn}")), $mtime); } } } } }
function LoadZip(&$request, $zipfile, $files = false, $exclude = false) { $zip = new ZipReader($zipfile); $timeout = !$request->getArg('start_debug') ? 20 : 120; while (list($fn, $data, $attrib) = $zip->readFile()) { // FIXME: basename("filewithnoslashes") seems to return // garbage sometimes. $fn = basename("/dummy/" . $fn); if ($files && !in_array($fn, $files) || $exclude && in_array($fn, $exclude)) { PrintXML(HTML::dt(WikiLink($fn)), HTML::dd(_("Skipping"))); flush(); continue; } longer_timeout($timeout); // longer timeout per page LoadFile($request, $fn, $data, $attrib['mtime']); } }