1 <?php // $Id: zip.php,v 1.1.2.1.2.2 2005-01-07 13:59:57 rurban Exp $
3 function encode_pagename_for_wikizip ($pagename) {
4 $enc = rawurlencode($pagename);
5 // URL encode leading dot:
6 $enc = preg_replace('/^\./', '%2e', $enc);
10 function MailifyPage ($pagehash, $oldpagehash = false)
12 global $SERVER_ADMIN, $ArchivePageStore;
14 $from = isset($SERVER_ADMIN) ? $SERVER_ADMIN : 'foo@bar';
16 $head = "From $from " . ctime(time()) . "\r\n";
17 $head .= "Subject: " . encode_pagename_for_wikizip($pagehash['pagename']) . "\r\n";
18 $head .= "From: $from (PhpWiki)\r\n";
19 $head .= "Date: " . rfc1123date($pagehash['lastmodified']) . "\r\n";
20 $head .= "Mime-Version: 1.0 (Produced by PhpWiki 1.1.x)\r\n";
22 if (is_array($oldpagehash))
24 return $head . MimeMultipart(array(MimeifyPage($oldpagehash),
25 MimeifyPage($pagehash)));
28 return $head . MimeifyPage($pagehash);
32 * The main() function which generates a zip archive of a PhpWiki.
34 * If $include_archive is false, only the current version of each page
35 * is included in the zip file; otherwise all archived versions are
38 function MakeWikiZip ($include_archive = false)
40 global $dbi, $WikiPageStore, $ArchivePageStore;
42 $pages = GetAllWikiPageNames($dbi);
43 $zipname = "wiki.zip";
45 if ($include_archive) {
46 $zipname = "wikidb.zip";
49 $zip = new ZipWriter("Created by PhpWiki", $zipname);
51 for (reset($pages); $pagename = current($pages); next($pages))
54 set_time_limit(30); // Reset watchdog.
55 $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore);
57 if (! is_array($pagehash))
61 $oldpagehash = RetrievePage($dbi, $pagename, $ArchivePageStore);
65 $attrib = array('mtime' => $pagehash['lastmodified'],
67 if (($pagehash['flags'] & FLAG_PAGE_LOCKED) != 0)
68 $attrib['write_protected'] = 1;
70 $content = MailifyPage($pagehash, $oldpagehash);
72 $zip->addRegularFile( encode_pagename_for_wikizip($pagehash['pagename']),
79 if(defined('WIKI_ADMIN'))
80 MakeWikiZip(($zip == 'all'));