title, ENT_QUOTES, "UTF-8") . "\">"); fwrite($fp, htmlspecialchars($this->content, ENT_QUOTES, "UTF-8") . "\n"); } public function show() { global $DATA_DIR, $modules; $str = Markdown($this->content); if(preg_match_all("/\[\[([\?,a-zA-Z0-9_]+)\]\]/", $str, $res)) { $modulecodes = array_unique($res[1]); foreach($modulecodes as $modulecode) { $m = explode("?", $modulecode); $module = $m[0]; $params = explode(",", $m[1]); if($modules[$module]) { $modulestr = $modules[$module]->run($params); } else { $modulestr = "
CMS ERROR: Could not find module: [[" . $modulecode . "]]
"; } $str = str_replace("[[" . $modulecode . "]]", $modulestr, $str); } } echo $str; } public function Page($title, $content) { $this->title = $title; $this->content = $content; } } class Pages { private $file; private $pages = array(); // Admin config public $admin_title = "Pages"; public $admin_submodules = array("Edit page" => "edit"); public function admin_edit($action, $vars) { switch($action) { case "add": $this->pages[$vars["title"]]->content = $vars["content"]; $this->write(); echo "\"" . $this->pages[$vars["title"]]->title . "\" has now been edited."; break; case "preview": $p = new Page($vars["title"], $vars["content"]); echo "Looking ok?
"; beginform("add"); hidden($vars); button("yes"); endform(); beginform("retry"); hidden($vars); button("no"); endform(); break; case "edit": case "retry": if(isset($vars["content"])) $content = $vars["content"]; else $content = $this->pages[$vars["title"]]->content; beginform("preview"); hidden($vars); textedit("Content", "content", $content); button("Preview"); endform(); break; case "select": default: $pagelist = array(); foreach($this->pages as $p) { $pagelist[$p->title] = $p->title; } beginform("edit"); combobox("Edit this entry:", "title", "", $pagelist); button("Edit..."); endform(); break; } } public function admin($sub, $action, $vars) { switch($sub) { case "edit": $this->admin_edit($action, $vars); break; } } public function getPage($title) { return $this->pages[$title]; } public function add($page) { $key = $page->title; $this->pages[$key] = $page; } public function write() { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); fwrite($fp, "