4 The StaticPages plugin allows you to put some .html or .php files
5 into dedicated directories, which then will get available with their
6 basename as ewiki pages. The files can be in wiki format (.txt or no
7 extension), they can also be in .html format and they may even contain
8 php code (.php). Some binary files may also be thrown into there, but
9 you should use PathInfo or a ModRewrite setup then.
11 Of course it is not possible to provide anything else, than viewing
12 those pages (editing is not possible), but it is of course up to you
13 to add php code to achieve some interactivity.
14 The idea for this plugin was 'borought' from http://geeklog.org/.
16 In your static page .php files you cannot do everything you could
17 normally do, there are some restrictions because of the way these static
18 pages are processed. You need to use $GLOBALS to access variables other
19 than the $ewiki_ ones. To return headers() you must append them to the
20 $headers[] or $ewiki_headers[] array.
22 If you define("EWIKI_SPAGES_DIR") then this directory will be read
23 initially, but you could also just edit the following list/array of
24 directories, or call ewiki_init_spages() yourself.
28 #-- specify which dirs to search for page files
32 # "/usr/local/share/wikipages",
33 # "C:/Documents/StaticPages/",
36 if (defined("EWIKI_SPAGES_DIR")) {
37 ewiki_init_spages(EWIKI_SPAGES_DIR);
39 define("EWIKI_SPAGES_BIN", 1);
43 # - will be added automatically by _init_spages()
47 function ewiki_spage($id, &$data, $action) {
49 global $ewiki_spages, $ewiki_plugins, $ewiki_t;
54 $fn = $ewiki_spages[strtolower($id)];
57 if (strpos($fn, ".php") || strpos($fn, ".htm")) {
59 #-- start new ob level
63 #-- prepare environment
64 global $ewiki_id, $ewiki_title, $ewiki_author, $ewiki_ring,
65 $ewiki_t, $ewiki_config, $ewiki_action, $_EWIKI,
66 $ewiki_auth_user, $ewiki_headers, $headers;
67 $ewiki_headers = array();
68 $headers = &$ewiki_headers;
74 $r = ob_get_contents();
79 headers(implode("\n", $ewiki_headers));
85 elseif (EWIKI_SPAGES_BIN && !headers_sent() && preg_match('#\.(png|gif|jpe?g|zip|tar)#', $fn)) {
86 $ct = "application/octet-stream";
87 if (function_exists("mime_content_type")) {
88 $ct = mime_content_type($fn);
90 header("Content-Type: $ct");
91 header("ETag: ewiki:spages:".md5($r).":0");
92 header("Last-Modified: " . gmstrftime($ewiki_t["C"]["DATE"], filemtime($fn)));
98 $f = gzopen($fn, "rb");
99 $r = gzread($f, 256<<10);
102 #-- render as text/plain, text/x-wiki
104 $r = $ewiki_plugins["render"][0]($r);
108 #-- strip <html> and <head> parts (if any)
110 $r = preg_replace('#^.+<body[^>]*>(.+)</body>.+$#is', '$1', $r);
113 #-- return body (means successfully handled)
120 function ewiki_init_spages($dirs, $idprep="") {
122 global $ewiki_spages, $ewiki_plugins;
124 if (!is_array($dirs)) {
125 $dirs = array($dirs);
128 #-- go through list of directories
129 foreach ($dirs as $dir) {
135 #-- read in one directory
137 while ($fn = readdir($dh)) {
139 #-- skip over . and ..
140 if ($fn[0] == ".") { continue; }
143 if ($fn && is_dir("$dir/$fn")) {
144 if ($fn != trim($fn, ".")) {
145 $fnadd = trim($fn, ".") . ".";
151 ewiki_init_spages(array("$dir/$fn"), "$idprep$fnadd");
156 #-- strip filename extensions
158 array(".html", ".htm", ".php", ".txt", ".wiki", ".src"),
163 #-- register spage file and as page plugin (one for every spage)
164 $ewiki_spages[strtolower("$idprep$id")] = "$dir/$fn";
165 $ewiki_plugins["page"]["$idprep$id"] = "ewiki_spage";