1 #!/usr/local/bin/php -qC
4 # This cmdline tool makes a "page_" plugin from a "StaticPage" (usually
5 # found in the spages/ subdir). This is useful if you want to merge such
6 # a (dynamic) "StaticPage" into a "monsterwiki.php" script (using the
7 # 'mkhuge' tool or the cat/type command).
10 if ($_SERVER["argc"] < 2) {
11 echo "\nsyntax: mkpageplugin spages/PageOne spages/DynamicPage.php\n\n"
12 . "Makes ewiki page plugins from the 'StaticPage' files usually found in spages/,\n"
13 . "what is useful for merging those generated plugin scripts into a monsterwiki\n"
14 . "file as described in the README.\n\n";
17 $files = $_SERVER["argv"];
20 foreach ($files as $file) {
23 $c = implode("", file($file));
25 #-- check type (.htm / .txt / .php)
26 $ext = strtolower(substr($file, strrpos($file, ".")));
27 switch(substr($ext, 1, 3)) {
30 if (strpos($c, "<?") !== false) {
44 #-- generate pagename from filename
45 ($id = substr($file, 0, strrpos($file, ".")))
47 $id = strtr($id, DIRECTORY_SEPARATOR, "/");
48 if (($r = strrpos($id, "/")) !== false) {
49 $id = substr($id, $r + 1);
53 #-- generate output script
54 $func2 = "ewiki_mkpageplugin_".$id;
56 . "# This ewiki page plugin was generated from the StaticPage file\n"
57 . "# '$file' using tools/mkpageplugin.\n\n\n"
58 . '$ewiki_plugins["page"]["'.$id.'"] = "'.$func2.'";'."\n\n\n"
59 . "function $func2(\$id, &\$data, \$action) {\n\n";
61 $cn2 .= " return ewiki_format(<<<END_OF_WIKIPAGE\n"
63 . "\nEND_OF_WIKIPAGE\n );";
66 $cn2 .= " return<<<END_OF_HTML\n"
71 $c = preg_replace("/\bheader\((.+?)\);/ims", '$ewiki_headers[] = \\1;', $c);
72 $cn2 .= ' global $ewiki_plugins, $ewiki_id, $ewiki_title, $ewiki_author, $ewiki_ring, $ewiki_t, $ewiki_config, $ewiki_action, $_EWIKI, $ewiki_auth_user;'
74 . " \$ewiki_headers = array();\n"
75 . " \$headers = &\$ewiki_headers;\n\n";
77 . " ob_implicit_flush(0);\n\n"
81 . " \$o = ob_get_contents();\n"
82 . " ob_end_clean();\n\n"
83 . " headers(implode(\"\n\", \$ewiki_headers));\n"
86 $cn2.= "\n\n}\n\n?".">";
89 $fn2 = "page_{$id}.php";
90 if (($r = strrpos($file, "/")) !== false) {
91 $fn2 = substr($file, 0, $r + 1) . $fn2;
95 echo "converting $file to $fn2 plugin...\n";
96 if ($f = fopen($fn2, "w")) {
101 echo "ERROR: cannot write to '$fn2'\n";