removed mods directory from the ATutor codebase
[atutor.git] / mods / wiki / tools / setup
diff --git a/mods/wiki/tools/setup b/mods/wiki/tools/setup
deleted file mode 100755 (executable)
index 741d4ba..0000000
+++ /dev/null
@@ -1,815 +0,0 @@
-#!/usr/local/bin/php -qC
-<?php
-/*
-   Console/terminal tool to generate ewiki.ini, config.php or a
-   monsterwiki file (plugins+core merged into single php script).
-   Works best on Linux flavours, with dialog/cdialog/whiptail or
-   Xdialog/gdialog/kdialog installed.
-
-   - $set contains list of plugin names
-   - constants and values are added to $set only after the according
-     plugin gets activated
-   - menus switch to each other by name, but some are implemented by
-     callback functions ("OPTIONS" is regenerated on the fly)
-*/
-
-// $_ENV["NO_X"] = 1;
-// $_ENV["DIALOG"] = "cdialog";
-define("OPTIONS_SPACING", 0);
-
-
-#-- init
-chdir(dirname(dirname(__FILE__)));  // change into ewiki base directory
-include_once("plugins/lib/upgrade.php");  // PHP4.3 minimum
-dialog::init();   // prepare UI
-include_once("plugins/lib/pluginmetadata.php");
-
-#-- read in *.meta files
-ewiki_pmd(0,1,0,"d_gauge"); d_gauge();
-
-
-#-- plugin/option states
-$set_init = array(
-   ".\$ini" => "ewiki.ini",
-   ".\$php" => "config.php",
-   ".\$mwiki" => "monsterwiki.php",
-   "DB_INIT" => "mysql_connect(localhost,user,password) && mysql_query(dbname)",
-   "EWIKI_DB_TABLE_NAME" => "ewiki",
-   "EWIKI_DB_UTF8" => 0,
-   "EWIKI_DB_BIN64" => 0,
-   "EWIKI_DBFILES_DIRECTORY" => "./files/",
-   "EWIKI_DBFILES_GZLEVEL" => 0,
-   "EWIKI_DB_FAST_FILES" => 0,
-   "EWIKI_DBFF_ACCURATE" => 0,
-   "DZF2_HIT_COUNTING" => 1,
-   "EWIKI_DBA" => "/tmp/mywiki.flatfile",
-);
-$set = $set_init;
-$priority_1 = "core,required,standard,default,important";
-m_reset();     // initial settings
-m_load_dat();  // load backup values
-
-
-#-- menus ----------------------------------------------------------------
-$menus = array(
-   "MAIN" => array(
-      array("PLUGINS", "Select plugins", "List available extension plugins to enable or disable them.", ""),
-      array("OPTIONS", "Tweak configuration options and plugin settings", "Override and pre-define constants and configuration variables.", "m_options"),
-      array("DATABASE", "Choose and configure database backend", "Unlike the backend selection under plugins, this entry is for auto-initialization.", "m_database"),
-      array("SAVE_PHP", "Generate \"config.php\"", "Exports a ready-to-use ewiki config include script.", "m_save_php"),
-      array("SAVE_INI", "Generate \"ewiki.ini\"", "An .ini file can contain all plugin and configuration options.", "m_save_ini"),
-      array("SAVE_WIKI", "Generate \"monsterwiki.php\" script", "All plugins and settings get merged into one script.", "m_save_mwiki"),
-      array("LOAD_PHP", "Decipher settings from \"config.php\"", "Reading from .php scripts is not reliable.", "m_load_php"),
-      array("LOAD_INI", "Load settings from \"ewiki.ini\"", "Save settings into an reusable .ini-style configuration file.", "m_load_ini"),
-      array("DONE", "Exit this tool", "Automatically saves current plugin and config settings. Press ^C else.", "m_exit"),
-      array("HELP", "Documentation", "Additional usage informations for this utility.", "m_help"),
-/*    array("IDENTIFIER",                 // denotes next/sub menu
- *          "Title", "Help text",         // for display
- *          "func_handler(arg2)",         // entry handler, if no sub menu
- *          "func_mangle_display_menu",   // callback, tweaks title with $set values   */
-   ),
-   "OPTIONS" => array(
-      // automatically emptied sub menu, so the menu() selection ignores it
-   ),
-   "PLUGINS" => array(
-      array("PLUGINLIST", "All plugins in one list", "Gives complete overview over available plugins, alphabetical but rough listing.", "m_checklist_plugins()"),
-      array("FAVORITES", "Enable plugins by priority / favorites", "Selects multiple plugins/features at once.", ""),
-   ),
-   "FAVORITES" => array(
-      array("PR_core", "priority: core - plugins that must be loaded", "Core and required plugins.", "m_enable_by_priority(core,required)"),
-      array("PR_standard", "add standard plugins - loaded in default setup", "", "m_enable_by_priority(core,required,standard,default)"),
-      array("PR_important", "add important plugins - highly recommended", "", "m_enable_by_priority(important)"),
-      array("PR_recommended", "add recommended plugins", "", "m_enable_by_priority(recommended)"),
-      array("PR_optional", "add optional plugins", "", "m_enable_by_priority(optional)"),
-      array("PR_extra", "add extra plugins", "", "m_enable_by_priority(extra)"),
-      array("RESET", "Reset plugin list and options (to standard)", "All core plugins will be selected.", "m_reset"),
-      array("FAV_mario", "personal favorites of: Mario", "http,rss,qdiff,mpi,flat_files,textupload,limit_links,rc,wikinews,...", "m_enable_list(fix,http,http_cache,xml,feed,feedparse,raw,diff,rss,like_pages,htm,info_qdiff,email_protect,jump,notify,fancy_list_dict,flat_files,imgresize_gd,search_highlight,editable,xmlrpc,opensearch,linkdatabase,css,,definitionlinks,mpi,mpi_backtree,mpi_embed,mpi_insert,mpi_survey,mpi_syndicate,mpi_backlinks,mpi_localsitemap,mpi_tableeditor,mpi_addlink,aboutplugins,powersearch,textupload,wikinews,recentchanges,authorname,limitlinks,ewiki)"),
-   ),
-   "DATABASE" => array(
-      array("DB_PLUGIN", "Choose database backend", "Only one generic plugin/backend should be chosen.", "m_checklist_plugins(database)"),
-      array("DB_INIT", "Define how to initialize database / connect to it", "Initialization is mostly necessary for SQL databases only.", "m_set_option2(Set the SQL/DBA database initialization using its generic initialization function call, but that the syntax is restricted here - absolutely NO spaces and quotation marks around the arguments. For MySQL you`d use mysql_connect(, for PgSql you say anydb_connect( or pg_connect( and for Berkely/Sleepycat DBA files you set this to dba_open( instead."),
-      array("DB_OPTIONS", "Set other parameters for your database plugin", "Unsorted list, not all constants/settings apply to all database types.", ""),
-   ),
-   "DB_OPTIONS" => array(
-      array("EWIKI_DB_TABLE_NAME", "SQL table name (ewiki)", "[sql] database table name", "m_set_option(mysql)"),
-      array("EWIKI_DB_UTF8", "Code UTF-8 from/to database (Postgres)", "[pgsql] unicode2latin", "m_set_option(anydb)"),
-      array("EWIKI_DB_BIN64", "Encipher binary entries in the database (Postgres)", "[pgsql] binary as base64 encoded TEXT columns", "m_set_option(anydb)"),
-      array("EWIKI_DBFILES_DIRECTORY", "where to store flat files (./files/)", "[flat_files] storage directory", "m_set_option(flat_files)"),
-      array("EWIKI_DB_FAST_FILES", "fast file format, php serializiation (0)", "[flat_files] use `application/vnd.php.serialized` format", "m_set_option(flat_files)"),
-      array("EWIKI_DBFILES_GZLEVEL", "compress flat files (0)", "[flat_files] compression", "m_set_option(flat_files)"),
-      array("EWIKI_DBFF_ACCURATE", "more correct return values {slower} for some functions  (dzf2)", "[flat_files/dzf2] correctness vs. speed", "m_set_option(dzf2)"),
-      array("DZF2_HIT_COUNTING", "count page acccess (dzf2)", "[flat_files/dzf2] hits", "m_set_option(dzf2)"),
-      array("EWIKI_DBA", "Berkely/Sleepycat DBA storage file", "[dba] filename", "m_set_option(dba)"),
-   ),
-);
-#-- append plugin list menus
-foreach (ewiki_pmd_by_category() as $cat=>$ls) {
-   $menus["PLUGINS"][] = array("$cat/", "category $cat", "", "m_checklist_plugins($cat)");
-}
-
-
-
-#-- main loop ------------------------------------------------------------
-$menu="MAIN";
-do {
-   menu();
-}
-while (true);
-
-#-- display and switch between menus, call menu functions, dialog interface
-function menu($GOTO="", $BACK="MAIN")
-{
-   global $menus, $menu, $dialog_exit;
-   static $menu_stack = array();
-
-   #-- display
-   $next = dialog::menu($menus[$menu], "ewiki setup/config tool", "$menu menu");
-
-   #-- see what to do
-   if ($menus[$next]) {
-      array_push($menu_stack, $menu);
-      $menu = $next;
-   }
-   elseif ($dialog_exit=="1") {
-      $menu = array_pop($menu_stack);
-      if (!$menu || !$menus[$menu]) {
-         $menu = $BACK;
-      }
-   }
-   else {
-      #-- search selected entry
-      foreach ($menus[$menu] as $l)  {
-         if ($l[0] == $next) {
-            $selected = $l;
-         }
-      }
-      #-- call
-      if ($selected) {
-         m_call_func($selected[3], $next);
-      }
-   }
-}
-
-
-
-
-#== control code ($set plugins) ==========================================
-
-
-#-- enable/disable single plugin
-function m_switch_plugin($id, $id2) {
-   global $set;
-   if ($set[$id]) {
-      $set[$id] = false;
-   }
-   else {
-      $set[$id] = true;
-   }
-}
-
-
-#-- set plugin state from (inclusion) priority class
-function m_reset()
-{
-   global $set, $ewiki_pmd, $priority_1;
-   foreach ($ewiki_pmd as $id=>$row) {
-      $set[$id] = false;
-   }
-   m_enable_by_priority("", $priority_1);
-}
-
-
-#-- set plugins from comma separated priority list
-function m_enable_by_priority($next, $priority)
-{
-   global $set, $ewiki_pmd;
-   $priority = ",,,$priority,";
-   foreach ($ewiki_pmd as $id=>$row) {
-      if (strpos($priority, ",$row[priority],")) {
-         $set[$id] = true;
-      }
-   }
-}
-
-
-#-- enable plugins by name (favorite lists)
-function m_enable_list($next, $list)
-{
-   global $set, $ewiki_pmd;
-   foreach (explode(",", $list) as $id) {
-      $set[trim($id)] = true;
-   }
-}
-
-
-#-- load setup.dat from last session
-function m_load_dat() {
-   if ($dat = file_get_contents("tools/setup.dat")) {
-      $GLOBALS["set"] = unserialize($dat);
-   }
-}
-
-
-#-- handles function calls in menus
-function m_call_func($funcdef, $arg1) {
-   $func = strtok($funcdef, "(");
-   $args = array($arg1, strtok(")"));
-   call_user_func_array($func, $args);
-}
-
-
-#-- callback function, which mangles the displayed title for
-#   menu entries in the plugin section (injects values from $set[])
-function m_inj_menu_set(&$title, $row) {
-   global $set;
-   $id = $row[0];
-   if (isset($set[$id])) {
-      $title = str_pad($title, 30, " ")
-             . " " . ($set[$id]? "[YES]":"[NO]");
-   }
-}
-
-
-#-- show checkboxes to enable plugins from a category
-function m_checklist_plugins($next, $cat) {
-   global $set, $ewiki_pmd;
-   $list = array();
-   foreach (ewiki_pmd_by_category() as $c=>$ls) {
-      if (!$cat || ($cat==$c)) {
-         foreach ($ls as $id=>$row) if (!ewiki_pmd_hidden($row)) {
-            $list[$id] = array($id, $row["title"], $row["description"]);
-         }
-      }
-   }
-   ksort($list);
-   dialog::check($list, $set, "ewiki setup/config tool", "enable or disable $cat plugins");
-}
-
-
-#-- help screen for plugins
-function m_plugin_info($id) {
-   global $ewiki_pmd;
-   if (!$ewiki_pmd[$id]) {
-      $id = preg_replace("/[^\w\d]/", "", $id);
-      foreach ($ewiki_pmd as $i=>$row) {
-         if ($id == preg_replace("/[^\w\d]/", "", $row["description"])) {
-            $id = $i;
-            break;
-         }
-      }
-   }
-   if ($row = $ewiki_pmd[$id]) {
-      $text = "id: $id\n";
-      foreach ($row as $i=>$v) {
-         $text .= "$i: $v\n";
-      }
-      $text = strtr($text, "'", "`");
-      dialog::real("--title '$id' --msgbox '$text' 18 70");
-   }
-}
-
-
-
-
-#== $set options =========================================================
-
-
-#-- dynamic sub-menu
-function m_options() {
-   global $menu, $menus, $opts_l;
-   global $set, $ewiki_pmd;
-
-   #-- hack, calls main menu() function for display
-   $menu = "OPTIONS";
-   do {
-
-      #-- regenerate menu (in case something changed)
-      $opts_l = get_option_list();
-      $menus["OPTIONS"] = array();
-      foreach ($opts_l as $row) {
-         list($name, $val, $help, $id, $default) = $row;
-         if (OPTIONS_SPACING && ($id != $last_id)) {
-            $menus["OPTIONS"][] = array(" [$id]", "", "", "");
-            $last_id = $id;
-         }
-         $menus["OPTIONS"][] = array($name, "$val", "[$id] $help (default=$default)", "m_set_option($id)");
-      }
-
-      menu();
-   } while (($menu != "MAIN")
-         && ($menus["OPTIONS"]));
-   $menus["OPTIONS"] = array();
-}
-
-
-#-- settings from all enabled and auto plugins
-function get_option_list() {
-   $ls = array();
-   foreach (final_plugin_list() as $id) {
-      foreach (get_config_options($id) as $row) {
-         $ls[$row[0]] = $row;
-      }
-   }
-   return($ls);
-}
-function get_config_options($id) {
-   global $ewiki_pmd, $set;
-   $r = array();
-   foreach (explode("\n", $ewiki_pmd[$id]["config"]) as $line) {
-      if (preg_match("#^(.+?)=(.*?)(?:\s//(.+))?$#", trim($line), $uu)) {
-         $name = trim($uu[1]);
-         $value = trim($uu[2]);
-         $value = preg_replace("#^(\d)\|\d$#", "$1", $value);   // for "0|1"
-         $value = preg_replace("#^\"([^\d].*)\"$#", "$1", $value);
-         $help = trim($uu[3]);
-         if (!isset($set[$name])) {
-            $set[$name] = $value;       // set default config value
-         }
-         $r[] = array($name, $set[$name], $help, $id, $value);
-      }
-   }
-   return($r);
-}
-
-
-#-- edit config setting
-function m_set_option($name, $id) {
-   global $set, $opts_l;
-   dialog::edit("$name", $set[$name], "Change configuration option/constant", "This setting is defined/used by the `$id` plugin.\n\n" . $opts_l[$name][2] . "\n\n");
-}
-
-#-- help from 2nd parameter (instead of $opts_l)
-function m_set_option2($name, $help) {
-   global $set;
-   dialog::edit("$name", $set[$name], "Set option", $help);
-}
-
-
-
-
-
-#-- safe+load code -------------------------------------------------------
-
-
-#-- save ewiki.ini
-function m_save_ini() {
-   global $set, $dialog_exit;
-   dialog::edit(".\$ini", $set[".\$ini"], "Save configuration as ewiki.ini file", "Give the filename under which to save the current settings. Beware, that any existing file will be overwritten.");
-   if ($dialog_exit) { return; }
-   file_put_contents($set[".\$ini"], m_mk_ini());
-}
-
-
-#-- generate ewiki.ini
-function m_mk_ini() {
-   global $set, $ewiki_pmd;
-
-   #-- start ewiki.ini
-   $T = "; automatically generated configuration summary\n; see ewiki config wizard\n";
-   $T .= "\n[db]\n";
-   if ($set["DB_INIT"]) {
-      $T .= "init = ".$set["DB_INIT"]."\n";
-   }
-   else {
-      $T .= "; no initialization necessary, or no database backend specified\n";
-   }
-
-   #-- config
-   $T .= "\n[settings]\n";
-   foreach (get_option_list() as $row) {
-      $T .= "$row[0] = $row[1]\n";
-   }
-
-   #-- plugins
-   $T .= "\n[plugins]\n";
-   foreach (final_plugin_list() as $id) {
-      if ($fn = $ewiki_pmd[$id]["fn"]) {
-         $T .= "load = $fn\n";
-      }
-      else {
-         $T .= ";load = $id\n";
-      }
-   }
-   return($T . "\n");
-}
-
-
-#-- save config.php
-function m_save_php() {
-   global $set, $dialog_exit;
-   dialog::edit(".\$php", $set[".\$php"], "Save configuration as config.php file", "To which filename do you wish the configuration script to be written? This will overwrite any existing file.");
-   if ($dialog_exit) { return; }
-   file_put_contents($set[".\$php"], m_mk_php());
-}
-
-
-#-- generate config.php body
-function m_mk_php($with_plugins=1) {
-   global $set, $ewiki_pmd;
-
-   #-- start config.php
-   $T = "<?php\n# automatically generated configuration file\n# see ewiki config/setup wizard\n";
-   $T .= "\n#-- db\n";
-   if ($set["DB_INIT"]) {
-      foreach (split("&&|;", $set["DB_INIT"]) as $str) {
-         $fn = strtok(trim($str), "(");
-         $args = explode(",", strtok(")"));
-         $args = '"' . implode('", "', $args) . '"';
-         $fn = trim(strtok($fn, "/"));
-         $T .=  "if (function_exists(\"$fn\")) {\n   $fn($args);\n}\n";
-      }
-   }
-   else {
-      $T .= "// no initialization necessary, or no database backend configured\n";
-   }
-
-   #-- config
-   $T .= "\n#-- settings\n";
-   foreach (get_option_list() as $row) {
-      list($name, $val) = $row;
-      if (!preg_match("/^\d+$/", $val)) {
-         $val = "\"" . $val . "\"";
-      }
-      if ($name[0] == "$") {
-         $T .= "$name = $val;\n";
-      }
-      else {
-         $T .= "define(\"$name\", $val);\n";
-      }
-   }
-
-   #-- plugins
-   if ($with_plugins) {
-      $T .= "\n#-- plugins\n";
-      foreach (final_plugin_list() as $id) {
-         if ($fn = $ewiki_pmd[$id]["fn"]) {
-            $T .= "include_once(\"$fn\");\n";
-         }
-         else {
-            $T .= "//plugin not found: $id\n";
-         }
-      }
-   }
-   return($T . "\n?" . ">");
-}
-
-
-#-- save config.php
-function m_save_mwiki() {
-   global $set, $ewiki_pmd, $dialog_exit;
-   dialog::edit(".\$mwiki", $set[".\$mwiki"], "Export a MonsterWiki", "Merge all plugins and configuration data into one giant PHP script.");
-   if ($dialog_exit) { return; }
-
-   #-- merge everything together
-   $f = fopen($mwiki=$set[".\$mwiki"], "wb");
-   fwrite($f, m_mk_php($_with_plugins=0));
-   $list = final_plugin_list();
-   foreach ($list as $n=>$id) {
-      if (file_exists($fn = $ewiki_pmd[$id]["fn"])) {
-         fwrite($f, file_get_contents($fn));
-      }
-      d_gauge($n, count($list), "assembling $mwiki", 75000, 2);
-   }
-   fclose($f);
-   d_gauge(0,0);
-}
-
-
-#-- add dependencies to $set array, send list
-function final_plugin_list($add_required=1) {
-   global $set, $ewiki_pmd;
-   if ($add_required) {
-      m_enable_by_priority(".FINALIZE", "core,required");
-   }
-   $list = array();
-   foreach ($set as $id=>$state) {
-      if ($id && $state && $ewiki_pmd[$id]) {
-         $list[] = $id;
-      }
-   }
-   ewiki_pmd_resolve_dependencies($list, $_add_suggested=0);
-   return($list);
-}
-
-
-
-
-#== loading ==============================================================
-
-
-#-- load from ewiki.ini file (without [para] dissection)
-function m_load_ini() {
-   global $set, $set_init, $dialog_exit, $ewiki_pmd;
-   $pmd_by_fn = ewiki_pmd_by("fn");
-
-   #-- from which file
-   $new = array();
-   dialog::edit(".\$ini", $set[".\$ini"], "Import configuration settings from .ini file", "Select the .ini file to load. Most current configuration settings will be forgotten.");
-   if ($dialog_exit) { return; }
-
-   #-- read in
-   if ($txt = file_get_contents($set[".\$ini"])) {
-      #-- database
-      if (preg_match("/^ *init *= *([^\n]+)/m", $txt, $uu)) {
-         $new["DB_INIT"] = $uu[1];
-      }
-      #-- plugins
-      if (preg_match_all("/^ *load *= *([^\s]+)/m", $txt, $uu)) {
-         foreach ($uu[1] as $i=>$fn) {
-            if (! ($id = $pmd_by_fn[$fn])) {
-               if (preg_match("/(^|\/)([-\d\w_]+)\.php$/m", $fn, $uu)) {
-                  $id = $uu[2];
-               }
-               else {
-                  $id = $fn;   // (useless)
-               }
-            }
-            $new[$id] = true;
-         }
-      }
-      #-- config
-      if (preg_match_all("/^ *([A-Z\$][^\s]+) *= *([^\n]+)/m", $txt, $uu)) {
-         foreach ($uu[1] as $i=>$v) {
-            $new[$uu[1][$i]] = trim(trim($uu[2][$i]), "\"");
-         }
-      }
-   }
-
-   #-- merge in old/minumum data
-   foreach ($set_init as $i=>$v) {
-      if (!isset($new[$i])) {
-         $new[$i] = isset($set[$i]) ? $set[$i] : $set_init[$i];
-      }
-   }
-   $set = $new;
-}
-
-
-#-- import settings from config.php (mostly guessing)
-function m_load_php() {
-   global $set, $set_init, $dialog_exit, $ewiki_pmd;
-   $pmd_by_fn = ewiki_pmd_by("fn");
-
-   #-- from which file
-   $new = array();
-   dialog::edit(".\$php", $set[".\$php"], "Guess configuration settings from config.php script", "Choose the ewiki config script. Currently made plugin selections and option settings will get unset/replaced.");
-   if ($dialog_exit) { return; }
-
-   #-- read in
-   if ($txt = file_get_contents($set[".\$php"])) {
-      #-- database
-      if (preg_match("/\b(@*(mysql_p?connect|anydb_connect|dba_open)\(.+?\))\b/m", $txt, $uu)) {
-         $new["DB_INIT"] = preg_replace("/[\s+\"\']/", "", $uu[1]);
-      }
-      #-- plugins
-      if (preg_match_all("/^ *@*include(?:_once)? *\(? *[\"\']([^\s\"\']+)/m", $txt, $uu)) {
-         foreach ($uu[1] as $i=>$fn) {
-            if ($id = $pmd_by_fn[$fn]) {
-               $new[$id] = true;
-            }
-            elseif (preg_match("/(^|\/)([-\d\w_]+)\.php$/m", $fn, $uu)) {
-               $new[$uu[2]] = true;
-            }
-         }
-      }
-      #-- config
-      if (preg_match_all("/^ *(\$[^\s]+) *= *([^\n]+) *;/m", $txt, $uu)) {
-         foreach ($uu[1] as $i=>$v) {
-            $new[$uu[1][$i]] = trim(trim($uu[2][$i]), "\"");
-         }
-      }
-      if (preg_match_all("/^ *@*define *\( *[\"\']([A-Z][^\s]+)[\"\'] *,([^\n]+)\) *;/m", $txt, $uu)) {
-         foreach ($uu[1] as $i=>$v) {
-            $new[$uu[1][$i]] = trim(trim($uu[2][$i]), "\"");
-         }
-      }
-   }
-
-   #-- merge in old/minumum data
-   foreach ($set_init as $i=>$v) {
-      if (!isset($new[$i])) {
-         $new[$i] = isset($set[$i]) ? $set[$i] : $set_init[$i];
-      }
-   }
-   $set = $new;
-}
-
-
-
-
-#== menu helper code =====================================================
-
-#-- wrapper
-function m_exit() {
-   @header("ewiki-setup: 0.7");
-   file_put_contents("tools/setup.dat", serialize($GLOBALS["set"]));
-   echo "- settings saved.\n";
-   exit;
-}
-
-#-- does nothing
-function m_nop() {
-}
-
-#-- show readme
-function m_help() {
-   dialog::text("doc/SetupTool", "Help");
-}
-
-
-
-
-#== terminal dialog ======================================================
-class dialog {
-
-
-   #-- preparations
-   function init()
-   {
-      global $dialog_bin, $dialog_add, $dialog_exit, $dialog_help, $dialog_fix, $dialog_nobg;
-
-      #-- tweak PATH env variable for distributed `whiptail`
-      putenv("PATH=$_ENV[PATH]:".dirname(__FILE__));
-
-      #-- available tools
-      $progs = $_ENV["DISPLAY$_ENV[NO_X]"]
-      ? array(
-         "Xdialog" => array("--wrap --ignore --stderr", 1),
-#<bogus># "gdialog" => array("", 0, -1), // new zenity wrapper is incompatible
-#<bogus># "kdialog" => array("", 0, -1), // slow if KDE isn't already running
-#<bogus># "zenity" => array("", 0),  // totally incompatible (a GNUish project)
-      )
-      : array(
-         "$_ENV[DIALOG]" => array("--stderr", 0),
-         "dialog" => array("--stderr ", 1),
-         "whiptail" => array("", 0),
-         "cdialog" => array("--stderr", 1),
-         array_shift(glob("/usr/src/*-2.*/scripts/lxdialog/lxdialog")) => array("", 0, 0, "_INJ_BOGUS_UNDOC_PARAM_MENU"),
-      );
-
-      #-- search binary
-      foreach ($progs as $d=>$args) {
-         if ($dialog_bin = trim(`which $d`)) {
-            list($dialog_add, $dialog_help, $dialog_nobg, $dialog_fix) = $args;
-            return;
-         }
-      }
-      die("This script requires one of the dialog utilities (cdialog, whiptail, Xdialog).\n");
-   }
-
-
-   #-- invoke dialog binary
-   function real($args, $adv="", $bg="ewiki setup/control tool")
-   {
-      global $dialog_bin, $dialog_add, $dialog_exit, $dialog_nobg;
-
-      $keytmp = "/tmp/php.dialog.keystroke.tmp." . getmypid(); 
-      if (!$dialog_add) {
-         $adv = "";  // this variant only supports most basic args
-      }
-      $cmd = "$dialog_bin";
-      if (!$dialog_nobg) { $cmd .= " --backtitle '$bg'"; }
-      $cmd .= " $dialog_add $adv $args";
-
-#echo "CMD: $cmd\n";
-      system("$cmd >/dev/stdin 2>$keytmp", $dialog_exit);
-      $ret = trim(file_get_contents($keytmp));
-
-      unlink($keytmp);
-      return($ret);
-   }
-
-   #-- escape param list into exec string
-   function params() {
-      $s = "";
-      foreach (func_get_args() as $a) {
-         $s .= " '" . strtr($a, "'", "`") . "'";
-      }
-      return($s);
-   }
-
-
-   #-- show list
-   function menu($list, $title, $text)
-   {
-      global $dialog_bin, $dialog_add, $dialog_exit, $dialog_help, $dialog_fix;
-      if ($dialog_help) { $adv = " --item-help"; }
-      $args = "--title '$title' --menu '$text' 20 70 11 $dialog_fix";
-      foreach ($list as $n=>$l) {
-         list ($name, $line, $help, $_hfunc, $_mangle) = $l;
-//         if ($_mangle) { $_mangle($line, $l); }
-         $args .= dialog::params($name, $line);
-         if ($dialog_help) { $args .= dialog::params($help); }
-      }
-      return dialog::real($args, $adv);
-   }
-
-
-   #-- checkbox list
-   function check($list, &$states, $title, $text)
-   {
-      global $dialog_bin, $dialog_add, $dialog_exit, $dialog_help;
-      $current = $states;
-
-      #-- args
-      $args = "--title '$title' --checklist '$text' 20 70 11";
-      if ($dialog_help) { $adv = " --help-button --item-help"; }
-      $names = array();
-      foreach ($list as $n=>$l) {
-         list ($name, $line, $help, $_hfunc, $_mangle) = $l;
-         $args .= dialog::params($name, $line, ($current[$name]? "on":"off"));
-         if ($dialog_help) { $args .= dialog::params($help); }
-         $names[] = $name;
-      }
-
-      #-- display
-      do {
-         $rs = dialog::real($args, $adv);
-         if ($dialog_exit == "0") {
-            foreach ($names as $name) {
-               $current[$name] = strpos(" $rs", "\"$name\"")?true:false;
-               $set = $current;
-            }
-         }
-         if (substr($rs, 0, 5) == "HELP ") {
-            m_plugin_info(substr($rs, 5));
-            $rs="HELP";
-         }
-      }
-      while ($rs == "HELP");
-
-      #-- store
-      if (($dialog_exit == "0") && isset($set)) {
-         foreach ($names as $name) {
-            $current[$name] = strpos(" $rs", "\"$name\"")?true:false;
-         }
-         $states = $current;
-      }
-   }
-
-
-   #-- input box
-   function edit($name, &$var, $title="Change", $help="")
-   {
-      global $dialog_bin, $dialog_add, $dialog_exit;
-      $var = dialog::real("--title '$title' --inputbox '\n$help\n' 14 70 '$var'");
-   }
-
-
-   #-- flags
-   function yesno($name, &$var, $title="Change", $help="")
-   {
-      global $dialog_bin, $dialog_add, $dialog_exit;
-      dialog::real("--title '$title' --yesno '$help' 15 60");
-      $c = $dialog_exit;
-      if (($c==0)||($c==1)) {
-         $var = 1 - $c;   //0=Yes, 1=No
-      }
-   }
-
-
-   #-- show file
-   function text($file, $title)
-   {
-      global $dialog_bin, $dialog_add, $dialog_exit;
-#      $file = dialog::params(file_get_contents($file));
-      dialog::real("--title '$title' --textbox $file 21 72");
-   }
-
-}
-
-
-#-- gauge display
-function d_gauge($i=0, $max=0, $title="initializing from *.meta data files", $pause=15000, $every=15)
-{
-   global $dialog_bin;
-   static $p, $last_max;
-
-   #-- clean up again
-   if ($p && !$max) {
-      pclose($p);
-      $p = NULL;
-      $last_max = 0;
-      return;
-   }
-   #-- init
-   elseif (!isset($p) || ($last_max != $max)) {
-      $p = popen("$dialog_bin --gauge '$title' 7 72 000", "w");
-      $last_max = $max;
-   }
-
-   #-- output
-   if ($i && $max) {
-      $percent = (int) (100 * $i / $max);
-      fwrite($p, "$percent\n");
-
-      #-- delay
-      if (0 == $i % $every) {
-         if (function_exists("usleep")) { usleep($pause); }
-      }
-   }
-}
-
-
-
-?>
\ No newline at end of file