function entry_onsubmit($param, $post) { $data = ["msglist" => gettable("select * from site_guestbook")]; $scr = new Scriptor("site_guestbook/guestbook.html", $data); if (($post = $scr->validate("entry", $post)) === false) { return $scr->result(); } dbinsert("site_guestbook", ["name" => $post["name"], "content" => $post["content"]]); return child_render($param); }
function result() { global $g_cfg, $g_page, $g_pageforms; $g_page = $this->defaults; // GET-less URI $uri = explode("?", $_SERVER["REQUEST_URI"]); $uri = $uri[0]; $cm = $this->map($uri); list($incfn, $childfunc) = is_array($cm) ? $cm : array($cm, null); // Rule 1: functions are called directly if ($incfn instanceof Closure) { $g_page["child"] = $incfn; } else { if (endsWith($incfn, ".html")) { $scr = new Scriptor($incfn, array()); $g_page["child"] = $scr->result(); $incfn = null; } else { if (!endsWith($incfn, ".php") && file_exists($incfn)) { // determine content-type via file extension $mimetype = "text/plain; charset=utf-8"; if (endsWith($incfn, ".ico")) { $mimetype = "image/x-icon"; } if (endsWith($incfn, ".xml")) { $mimetype = "application/xhtml+xml; charset=UTF-8"; } header("Content-Type: " . $mimetype); return file_get_contents($incfn); } } } // everything from hereon assumed to be UTF-8 string header("Content-Type: text/html; charset=UTF-8"); // include optional handler file; this gets merged in the global function space if ($incfn != null && (!is_callable($incfn) && file_exists($incfn))) { include_once $incfn; } // merge child_render into frame if (!isset($g_page["child"]) && is_callable("child_render")) { $g_page["child"] = function ($params) { return child_render($params); }; } if (!isset($g_page["child"])) { internal_error("No renderer for URL: " . $uri); } // handle forms if (isset($_POST["submitedForm"]) && isset($g_pageforms[$_POST["submitedForm"]])) { $g_page["child"] = $g_pageforms[$_POST["submitedForm"]]($this->regparams, $_POST); } if ($g_page["child"] instanceof Closure) { $g_page["child"] = $g_page["child"]($this->regparams); } // results are either: // - null for redirection, // - an array for ajax endpoints; or // - an UTF-8 string containing HTML output if ($g_page["child"] == null) { return ""; } if (is_array($g_page["child"])) { // JSONP extension // IE file uploading requires text/html header("Content-Type: application/json; charset=UTF-8"); if (isset($_GET["perfstats"]) && $g_cfg["debug"] == true) { global $g_logstart, $pagequeries; $g_logend = array_sum(explode(' ', microtime())); $pagegen = $g_logend - $g_logstart; $g_page["child"]["__perfstats"] = ["total" => $pagegen, "breakdown" => $pagequeries]; } if (isset($_GET["callback"])) { return $_GET["callback"] . '(' . json_encode($g_page["child"]) . ')'; } else { return json_encode($g_page["child"]); } } // format HTML results into the frame $scr = new Scriptor($g_page["frame"], $g_page); return $scr->result(); }