/** * gets all the stuff we need for the fight * * @param string $section section name * @param string $page section page * @param array $config config array for db */ public function load_core($common) { $this->db =& code_database_wrapper::get_db(); $this->section = 'common'; $this->page = 'fight'; $this->player =& $common->player; $this->player_section = $common->section; $this->player_page = $common->page; $common->page_generation->section = 'common'; $this->skin =& $common->page_generation->make_skin("skin_fight"); $this->lang =& $common->lang; $common->page_generation->section = $this->player_section; // hacky hacky hacky }
/** * initiation function * * @param code_common $common page calling * @return core_mail_api this thing */ public function load_core($common) { $this->db =& code_database_wrapper::get_db(); return $this; }
/** * constructor, gives us the db * * @param array $config db values */ public function __construct($settings = array(), $config = array()) { $this->db = code_database_wrapper::get_db($config); }
/** * The common constructor for every class which extends code_common. * * Accepts and sets the section name and the page name, and an optional * config array. Also invokes code_database_wrapper to get the database * object. * * @param string $section name of the site chunk we're in * @param string $page name of our particular page * @param string $config config values */ public function __construct($section = "", $page = "", $config = array()) { $this->section = $section; $this->page = $page; $this->config = $config; $this->core("default_lang"); $this->core("error"); $this->db = code_database_wrapper::get_db($this->config); }
/** * 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; }
/** * Manual database connection function. * * Connects to the database, if for whatever reason this failed when the * class was constructed. * * @param bool $skipError if set, the error message isn't displayed if the connection fails * @return void */ public function make_db($skipError = false) { $this->db =& code_database_wrapper::get_db($this->config); if (!$this->db->IsConnected() && !$skipError) { if (!$this->skin) { $this->core("page_generation"); $this->skin =& $this->page_generation->make_skin(); } $this->page_generation->error_page($this->lang->failed_to_connect); } }