1 #!/usr/local/bin/php -Cq
4 # please keep this script inside of the tools/ directory (one
5 # subdirectory below the ewiki.php and config.php)
8 #-- make wiki links filesystem local
9 define("EWIKI_SCRIPT", "%s.htm");
10 define("EWIKI_SCRIPT_BINARY", "bin/%s");
12 #-- load ewiki library / open database
14 chdir(dirname(__FILE__));
15 foreach (array("config.php", "ewiki.php", "t_config.php") as $inc) {
16 foreach (array('./', '../') as $dir) {
18 if (function_exists("ewiki_database")) break 2;
22 if (!function_exists("ewiki_database")) {
23 echo "You cannot move around this utility, it needs to be located nereby the\nother ewiki tools/ (or at least ewiki.php or some config.php)!\n";
28 $config = regex_getopts(
30 "help" => "/^-+(h|help)$/i",
31 "dirs" => "/^-+(d|dir.*|create.*)$/i",
32 "ext" => "/^-+(e|ext.*)$/i",
33 "keepref" => "/^-+(k|keep.*|ref.*)$/i",
37 if ($config["help"]) {
38 echo "
\e[21mwiki2html
\e[27m converts your ewiki database into .html body part files.
39 These files miss the <html> and <head> markup and only contain the rendered
41 If you rather want a static version of your site please choose 'wget' or a
42 similar utility instead.
44 --help prints this help screen
45 --dirs creates the bin/ and img/ subdirectories (auto)
46 --ext extension for the created pages (.htm is default)
47 --keep keep references to external (but cached) images (NYI)
54 $dest = "wiki2html-".time();
56 ($ext = $config["ext"]) || ($ext = "htm");
57 $ewiki_config["script"] = "%s." . trim($ext, ".");
58 $ewiki_config["script_binary"] = "bin/%s";
61 $result = ewiki_db::GETALL(array("flags"));
64 while ($row = $result->get()) {
67 $row = ewiki_db::GET($id);
70 if (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_TEXT) {
72 $html = ewiki_format($row["content"]);
74 $f = fopen("$dest/" . ewiki_script("", $id), "wb");
75 fwrite($f, $html); fclose($f);
79 elseif (($row["flags"] & EWIKI_DB_F_TYPE) == EWIKI_DB_F_BINARY) {
81 if (!file_exists("$dest/bin")) {
85 $f = fopen("$dest/bin/" . ewiki_script("", $id), "wb");
86 fwrite($f, $row["content"]); fclose($f);
93 #------------------------------------------------------------------------
95 function regex_getopts($regexopts) {
96 if (empty($_SERVER)) {
97 $_SERVER = $GLOBALS["HTTP_SERVER_VARS"];
99 if (!empty($GLOBALS["argc"])) {
100 $_SERVER["argc"] = $GLOBALS["argc"];
101 $_SERVER["argv"] = $GLOBALS["argv"];
104 for ($n = 1; $n < $_SERVER["argc"]; $n++) {
105 foreach ($regexopts as $opts_id => $optsregex) {
106 if (preg_match($optsregex, $_SERVER["argv"][$n])) {
108 if (($next = @$_SERVER['argv'][$n+1]) && ($next[0] != "-")) {
112 $opts[$opts_id] = $value;
116 $opts[] = $_SERVER["argv"][$n];
120 #-------------------------------------------------------------------------