static function draw() { $page = self::urlArray(0); if ($page != "setupcomplete" && $page != "action" && file_exists(getSitePath() . "install/")) { forward("setupcomplete"); } $body = $header = $nav = $footer = NULL; if ($page) { $page_handler_class = "SocialApparatus\\" . ucfirst($page) . "PageHandler"; } else { $page_handler_class = "SocialApparatus\\HomePageHandler"; } Vars::clear(); if (class_exists($page_handler_class)) { $body = (new $page_handler_class())->view(); } else { new SystemMessage("Page not found."); forward("home"); } Vars::clear(); $header = display("page_elements/header"); Vars::clear(); $nav = display("page_elements/navigation"); Vars::clear(); $footer = display("page_elements/footer"); Vars::clear(); echo $header; echo $nav; echo $body; echo $footer; Debug::clear(); Dbase::con()->close(); die; }
public function __construct($class, $metadata_name, $type) { $storage_types_complete = Cache::get("storage_types_complete", "site"); if (!$storage_types_complete) { $class = strtolower($class); $query = "CREATE TABLE IF NOT EXISTS `{$class}` (guid INT(12) UNSIGNED PRIMARY KEY)"; Dbase::con()->query($query); if ($type != "index") { $query = "ALTER TABLE `{$class}` ADD `{$metadata_name}` {$type};"; Dbase::con()->query($query); } else { $query = "SELECT COUNT(1) IndexIsThere FROM INFORMATION_SCHEMA.STATISTICS WHERE table_schema=DATABASE() AND table_name='{$class}' AND index_name='{$metadata_name}';"; $result = Dbase::con()->query($query); $row = $result->fetch_assoc(); if (isset($row['IndexIsThere'])) { if ($row['IndexIsThere'] == 0) { $query = "CREATE INDEX `{$metadata_name}` ON `{$class}`(`{$metadata_name}`);"; Dbase::con()->query($query); } } } } }
static function getInput($name, $value = false, $allow_get = true) { if (isset($_POST[$name])) { $output = $_POST[$name]; if (!is_array($output)) { $output = htmlspecialchars($output); } return $output; } if ($allow_get) { if (isset($_GET[$name])) { $output = $_GET[$name]; if (!is_array($output)) { $output = Dbase::con()->real_escape_string($output); $output = htmlspecialchars($output); } return $output; } } return $value; }
public function save() { Cache::set("entity_" . $this->guid, $this); Dbase::createDefaultTables(); if (!$this->owner_guid && loggedIn()) { if ($this->type != "systemvariable") { $this->owner_guid = getLoggedInUserGuid(); } } $fields = array(); $time = time(); $ignore = array("type", "guid", "default_icon"); if (!$this->access_id) { $default_access = Setting::get("default_access"); if (!$default_access) { $default_access = "public"; } $this->access_id = getInput("access_id") ? getInput("access_id") : $default_access; } $this->last_updated = $time; Dbase::addColumn('last_updated', strtolower($this->type)); if (!$this->guid) { $this->time_created = $time; $query = "INSERT INTO `entities` (`type`) VALUES ('" . strtolower($this->type) . "')"; $guid = Dbase::query($query); if ($guid == 0) { return false; } $this->guid = $guid; } Dbase::createTable(strtolower($this->type)); $vars = get_object_vars($this); $query = "SELECT * FROM `" . strtolower($this->type) . "` WHERE `guid` = '{$this->guid}' LIMIT 1"; $results = Dbase::getResults($query); if (!$results || $results->num_rows == 0) { $query = "INSERT INTO `" . strtolower($this->type) . "` (`guid`) VALUES ('{$this->guid}')"; Dbase::query($query); } $query = "UPDATE `" . strtolower($this->type) . "` SET "; $columns = Dbase::getResultsArray("SHOW columns FROM `" . strtolower($this->type) . "`"); foreach ($columns as $column) { $fields[] = $column['Field']; } foreach ($vars as $key => $value) { if (!in_array($key, $ignore)) { if (is_array($value) || is_object($value) || is_bool($value)) { $value = Dbase::con()->real_escape_string(serialize($value)); } else { $value = Dbase::con()->real_escape_string($value); } if (!in_array($key, $fields)) { Dbase::addColumn($key, strtolower($this->type)); } $query .= "`{$key}`='{$value}',"; } } $query = rtrim($query, ","); $query .= " WHERE `guid` = '{$this->guid}'"; Dbase::query($query); return $this->guid; }