]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - admin/zip.php
2004-12-19 01:02 rurban
[SourceForge/phpwiki.git] / admin / zip.php
1 <?php // $Id: zip.php,v 1.1.2.1.2.3 2005-01-07 14:02:27 rurban Exp $
2
3 function encode_pagename_for_wikizip ($pagename) {
4   $enc = rawurlencode($pagename);
5   // URL encode leading dot:
6   $enc = preg_replace('/^\./', '%2e', $enc);
7   return $enc;
8 }
9
10 function MailifyPage ($pagehash, $oldpagehash = false)
11 {
12   global $SERVER_ADMIN, $ArchivePageStore;
13   
14   $from = isset($SERVER_ADMIN) ? $SERVER_ADMIN : 'foo@bar';
15   
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.2.6)\r\n";
21
22   if (is_array($oldpagehash))
23     {
24       return $head . MimeMultipart(array(MimeifyPage($oldpagehash),
25                                          MimeifyPage($pagehash)));
26     }
27
28   return $head . MimeifyPage($pagehash);
29 }
30
31 /**
32  * The main() function which generates a zip archive of a PhpWiki.
33  *
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
36  * included as well.
37  */
38 function MakeWikiZip ($include_archive = false)
39 {
40   global $dbi, $WikiPageStore, $ArchivePageStore;
41   
42   $pages = GetAllWikiPageNames($dbi);
43   $zipname = "wiki.zip";
44   
45   if ($include_archive) {
46      $zipname = "wikidb.zip";
47   }
48
49   $zip = new ZipWriter("Created by PhpWiki", $zipname);
50
51   for (reset($pages); $pagename = current($pages); next($pages))
52   {
53       
54      set_time_limit(30);        // Reset watchdog.
55      $pagehash = RetrievePage($dbi, $pagename, $WikiPageStore);
56
57      if (! is_array($pagehash))
58         continue;
59
60      if ($include_archive)
61         $oldpagehash = RetrievePage($dbi, $pagename, $ArchivePageStore);
62      else
63         $oldpagehash = false;
64
65      $attrib = array('mtime' => $pagehash['lastmodified'],
66                      'is_ascii' => 1);
67      if (($pagehash['flags'] & FLAG_PAGE_LOCKED) != 0)
68           $attrib['write_protected'] = 1;
69
70      $content = MailifyPage($pagehash, $oldpagehash);
71                      
72      $zip->addRegularFile( encode_pagename_for_wikizip($pagehash['pagename']),
73                            $content, $attrib);
74   }
75   $zip->finish();
76 }
77
78
79 if(defined('WIKI_ADMIN'))
80    MakeWikiZip(($zip == 'all'));
81
82 CloseDataBase($dbi);
83 exit;
84 ?>