/** * admin? install? or something more sinister? decide which section and page we're heading too. * */ public function page_setup() { /** * Default page and section * (TODO) make these customisable? */ $section = "public"; $page = "index"; $this->make_config(); /** * Gets sections, by reading the folder names from 'code' */ $sections = code_bootstrap::get_sections(); if ($this->config['default_section'] && in_array($this->config['default_section'], $sections)) { $section = $this->config['default_section']; } $test = strtolower($_GET['section']); if (in_array($test, $sections)) { $section = strtolower($_GET['section']); } require_once "code/common/code_database_wrapper.php"; /** * Check if we're meant to be running the installer. If not, proceed to * load up the database */ if (!IS_INSTALLED) { $section = "install"; $pages[$section] = array("index" => "start", "database" => "database", "user" => "user", "upgrade_database" => "upgrade_database"); } else { $this->db =& code_database_wrapper::get_db($this->config); // this unassuming line creates the database if (!$this->db->IsConnected()) { $this->page = new code_common(); $this->page->core("default_lang"); $this->page->core("page_generation"); $this->page->skin =& $this->page->page_generation->make_skin(); $this->page->page_generation->error_page($this->page->lang->failed_to_connect); } $page_query = $this->db->execute("SELECT * FROM `pages`"); while ($page_row = $page_query->fetchrow()) { foreach (explode(",", $page_row['redirect']) as $redirect) { $pages[$page_row['section']][$redirect] = $page_row['name']; } if ($page_row['mod']) { $mods[$page_row['section']][$page_row['name']] = $page_row['mod']; } } } /** * If the page exists, take it. */ if ($pages[$section][$_GET['page']]) { $page = $_GET['page']; } /** * Else; shit the bed. */ if (!$pages[$section][$page]) { $this->page = new code_common(); $this->page->core("default_lang"); $this->page->core("page_generation"); $this->page->page_generation->error_page($this->page->lang->page_not_exist); } if (file_exists("code/" . $section . "/" . "code_common_" . $section . ".php")) { /** *If there is, for example, a code_common_install which makes universal adjustments to code_common * then load it. */ require_once "code/" . $section . "/" . "code_common_" . $section . ".php"; } /** * The main code_whatever.php page is required here */ require_once "code/" . $section . "/code_" . $pages[$section][$page] . ".php"; /** * Our delightful hook override system thingy! If there's a 'mod', load * that. Otherwise, take the default class name. */ if (isset($mods[$section][$pages[$section][$page]])) { require_once "mods/" . $mods[$section][$pages[$section][$page]] . ".php"; $class_name = $mods[$section][$pages[$section][$page]]; } else { $class_name = "code_" . $pages[$section][$page]; } $this->page = new $class_name($section, $page, $this->config); $this->page->pages = $pages; }
/** * edits and adds menu items * * @return string html */ protected function edit() { if (isset($_POST['menu-id'])) { $id = $_POST['menu-id']; $button_text = $_POST['menu-submit']; // Name-value pairs $item = array('label' => $_POST['menu-label'], 'category' => $_POST['menu-category'], 'section' => $_POST['menu-section'], 'page' => $_POST['menu-page'], 'extra' => $_POST['menu-extra'], 'enabled' => $_POST['menu-enabled'] == "on" ? true : false, 'function' => $_POST['menu-function'] == "on" ? true : false, 'guest' => $_POST['menu-guest'] == "on" ? true : false); // Error check if (!$item['label']) { $edit = $this->show_menu($this->skin->error_box($this->lang->no_label)); return $edit; } if (!$item['section']) { $edit = $this->show_menu($this->skin->error_box($this->lang->no_section)); return $edit; } if (!$item['page']) { $edit = $this->show_menu($this->skin->error_box($this->lang->no_page)); return $edit; } // Get me the Iron Giant! $this->core("menu"); if ($id == "-1") { $this->menu->add_menu_entry($item['label'], $item['category'], $item['section'], $item['page'], $item['extra'], $item['function'], $item['enabled'], $item['guest']); } else { $this->menu->modify_menu_entry($id, $item['label'], $item['category'], $item['section'], $item['page'], $item['extra'], $item['function'], $item['enabled'], $item['guest']); } header("location:?section=admin&page=menu"); } $id = intval($_GET['id']); $item_query = $this->db->execute("SELECT * FROM `menu` WHERE `id`=?", array($id)); if ($item_query->numrows() == 1) { $item = $item_query->fetchrow(); $button_text = "Save changes"; } else { $item = array('id' => '-1'); $button_text = "Add new item"; } $sections = code_bootstrap::get_sections(); foreach ($sections as $section) { $section = htmlentities($section, ENT_QUOTES, 'utf-8'); // coming from folder names; folder names can be funky if ($item['section'] == $section) { $section_options .= $this->skin->section_selected($section); } else { $section_options .= $this->skin->section($section); } } $done = array(); foreach ($this->pages as $section_array) { foreach ($section_array as $page => $useless) { if (in_array($page, $done)) { continue; // prevent duplicates } $done[] = $page; if ($item['page'] == $page) { $page_options .= $this->skin->page_selected($page); } else { $page_options .= $this->skin->page($page); } } } $modify = $this->skin->edit($item, $button_text, $section_options, $page_options, $message); return $modify; }