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
10 Of course it is not possible to provide anything else, than viewing
11 those pages (editing is not possible), but it is of course up to you
12 to add php code to achieve some interactivity.
13 The idea for this plugin was 'borought' from http://geeklog.org/.
15 In your static page .php files you cannot do everything you could
16 normally do, there are some restrictions because of the way these static
17 pages are processed. You need to use $GLOBALS to access variables other
18 than the $ewiki_ ones. To return headers() you must append them to the
19 $headers[] or $ewiki_headers[] array.
21 If you define("EWIKI_SPAGES_DIR") then this directory will be read
22 initially, but you could also just edit the following list/array of
23 directories, or call ewiki_init_spages() yourself.
27 #-- specify which dirs to search for page files
31 # "/usr/local/share/wikipages",
32 # "C:/Documents/StaticPages/",
35 if (defined("EWIKI_SPAGES_DIR")) {
36 ewiki_init_spages(EWIKI_SPAGES_DIR
);
41 # - will be added automatically by _init_spages()
45 function ewiki_spage($id, $data, $action) {
47 global $ewiki_spages, $ewiki_plugins;
52 $fn = $ewiki_spages[strtolower($id)];
55 if (strpos($fn, ".php") ||
strpos($fn, ".htm")) {
57 #-- start new ob level
61 #-- prepare environment
62 global $ewiki_id, $ewiki_title, $ewiki_author, $ewiki_ring,
63 $ewiki_t, $ewiki_config, $ewiki_action, $_EWIKI,
64 $ewiki_auth_user, $ewiki_headers, $headers;
65 $ewiki_headers = array();
66 $headers = &$ewiki_headers;
72 $r = ob_get_contents();
77 headers(implode("\n", $ewiki_headers));
84 $f = fopen($fn, "rb");
85 $r = fread($f, 256<<10);
88 $r = $ewiki_plugins["render"][0]($r);
91 #-- strip <html> and <head> parts (if any)
92 if (($l = strpos(strtolower($r), "<body")) &&
93 ($w = strpos(strtolower($r), "</body")) )
95 $l = strpos($r, ">", $l+
1) +
1;
97 $r = substr($r, $l, $w);
100 #-- return body (means successful handled)
108 #<old># $ewiki_plugins["handler"][] = "ewiki_handler_spages";
109 function ewiki_handler_spages($id, $data, $action) {
111 global $ewiki_spages;
113 #-- compare requested page $id with spages` $id values
114 $i0 = strtolower($id);
115 foreach ($ewiki_spages as $i1 => $fn) {
116 if (strtolower($i1)==$i0) {
118 return(ewiki_spage($id));
127 function ewiki_init_spages($dirs, $idprep="") {
129 global $ewiki_spages, $ewiki_plugins;
131 if (!is_array($dirs)) {
132 $dirs = array($dirs);
135 #-- go through list of directories
136 foreach ($dirs as $dir) {
142 #-- read in one directory
144 while ($fn = readdir($dh)) {
146 #-- skip over . and ..
147 if ($fn[0] == ".") { continue; }
150 if ($fn && is_dir("$dir/$fn")) {
151 if ($fn != trim($fn, ".")) {
152 $fnadd = trim($fn, ".") . ".";
158 ewiki_init_spages(array("$dir/$fn"), "$idprep$fnadd");
163 #-- strip filename extensions
165 array(".html", ".htm", ".php", ".txt", ".wiki", ".src"),
170 #-- register spage file and as page plugin (one for every spage)
171 $ewiki_spages[strtolower("$idprep$id")] = "$dir/$fn";
172 $ewiki_plugins["page"]["$idprep$id"] = "ewiki_spage";