"title", "Menu" => "menu", "Splash" => "splash"); public function admin_title($action, $vars) { switch($action) { case "update": $this->setValue("title", $vars["title"]); echo "The title has now been changed to \"". $this->value("title") . "\""; $this->write(); break; default: $form = new Form("update"); $form->addWidget(new LineEdit("Site title:", "title", $this->value("title", "Title not yet set"))); $form->addWidget(new Button("Update")); $form->render(); break; } } public function admin_splash($action, $vars) { switch($action) { case "update": $this->setValue("splash", $vars["splash"]); $this->setValue("splashpage", $vars["splashpage"]); $this->setValue("splashreshow", $vars["splashreshow"]); echo "Splash has now been updated."; $this->write(); break; default: $form = new Form("update"); $form->addWidget(new LineEdit("Splash:", "splash", $this->value("splash", "false"))); $form->addWidget(new LineEdit("Splash page:", "splashpage", $this->value("splashpage", "splash"))); $form->addWidget(new LineEdit("Splash reshow:", "splashreshow", $this->value("splashreshow", "3600"))); $form->addWidget(new Button("Update")); $form->render(); break; } } public function admin_menu($action, $vars) { switch($action) { case "update": global $menulist; $menu = ListEditor::splitValues($menulist); $this->setValue("menu", $menu); $this->write(); break; default: global $config; global $pages; $pagetitles = array(); foreach($pages->pages as $page) { $pagetitles[$page->title] = $page->title; } $form = new Form("update"); $form->addWidget(new ListEditor("Menu items", "menulist", new LineEdit("Title", "title"), new ComboBox("Page", "page", "", $pagetitles), $config->value("menu"))); $form->addWidget(new Button("Update")); $form->render(); break; } } public function admin($sub, $action, $vars) { switch($sub) { case "title": $this->admin_title($action, $vars); break; case "menu": $this->admin_menu($action, $vars); break; case "splash": $this->admin_splash($action, $vars); break; } } public function write() { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); fwrite($fp, "\n"); foreach($this->configs as $name => $value) { fwrite($fp, " \n"); } fwrite($fp, "\n"); fclose($fp); } private function read() { $dom = new DomDocument; $dom->preserveWhiteSpace = TRUE; $dom->load($this->file); $configElems = $dom->getElementsByTagName('config'); foreach ($configElems as $config) { $this->setValue($config->getAttribute('name'), unserialize(htmlspecialchars_decode($config->getAttribute('value'), ENT_QUOTES))); } } public function value($name, $default = "") { if(isset($this->configs[$name])) return $this->configs[$name]; ////////// ////////// TEMPORARY VAR EXPANSION - Remove when the real values are done. ////////// global $TITLE, $PRELOAD, $DEFAULT_PAGE, $MENU; switch($name) { case 'title': return $TITLE; case 'preload': return $PRELOAD; case 'default': return $DEFAULT_PAGE; case 'menu': return $MENU; default: return $default; } return $default; } public function setValue($name, $value) { $this->configs[$name] = $value; } public function Config($file) { $this->file = $file; if(file_exists($file)) $this->read(); } } function config_init() { global $DATA_DIR; return new Config($DATA_DIR . "/config.xml"); } ?>