Example #1
0
 public function Create($page)
 {
     $this->Buffer = '';
     $page = fix_path($page);
     if (!($data = G::$Engine->DB->FetchRow("SELECT * FROM `" . G::$Engine->DB->Prefix . "pages` WHERE `page_path` = '{$page}' OR `page_path` = '/{$page}' OR `page_path` = '{$page}/' OR `page_path` = '/{$page}/' LIMIT 1", "slave"))) {
         return false;
     }
     // if the page is disabled, load the disabled page
     if ($data['state'] === "private") {
         $data = G::$Engine->DB->FetchRow("SELECT * FROM `" . G::$Engine->DB->Prefix . "pages` WHERE `page_path` = 'disabled' OR `page_path` = '/disabled'  OR `page_path` = 'disabled/' OR `page_path` = '/disabled/' LIMIT 1", "slave");
     }
     //--------------------------------
     // Lets make this easier to manage
     //--------------------------------
     $data = preg_replace_array("/^page_/i", '', $data);
     // add to our title history
     $data['title'] = isset($data['name']) && $data['name'] != '' ? array($data['name']) : isset($data['title']) && $data['title'] != '' ? array_merge($this['title'], array($data['title'])) : $this['title'];
     $this->Merge($data);
     // set mime-type header
     $this->Headers['Content-Type'] = $this['mime_type'];
     return true;
 }
Example #2
0
 public function __construct($DB)
 {
     parent::__construct();
     //--------------------------------
     // Create primary classes
     //--------------------------------
     $this->Handler = new Handler();
     set_error_handler(array($this->Handler, "Error"));
     set_exception_handler(array($this->Handler, "Exception"));
     $this->Request = new Request();
     $this->Session = new Session();
     $this->Languages = new Languages();
     $this->Macros = new Macros();
     $this->TemplateEngine = new TemplateEngine();
     $this->Lang = new Lang();
     $this->Sections = new Sections();
     //--------------------------------
     // Load rewrites
     //--------------------------------
     $query = "SELECT * \n\t\t\t\tFROM `" . $this->DB->Prefix . "rewrites`";
     $this->Rewrites = $this->DB->FetchRows($query, "slave");
     //--------------------------------
     // Load subclass settings
     //--------------------------------
     $settings =& G::$Engine->LoadSetting("site");
     $settings['path'] = PATH;
     // figure out the protocol type
     $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === "on" ? "https://" : "http://";
     // figure out the server path
     $server = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'];
     // set the cms url
     $settings['url'] = fix_path($protocol . $server . "/" . str_replace(realpath($_SERVER['DOCUMENT_ROOT']), "", $settings['path']));
     if (!$settings['copyright']) {
         $settings['copyright'] = "All Rights Reserved © " . date("Y", time()) . " " . $settings['title'];
     }
     // if a default theme doesn't exist
     if (!$settings['theme_name'] || !is_dir($settings['path'] . "/themes/" . $settings['theme_name'])) {
         $settings['theme_name'] = "default";
     }
     if (!$settings['language']) {
         $settings['language'] = "en";
     }
     if (!$settings['charset']) {
         $settings['charset'] = "utf-8";
     }
     if (!$settings['mime_type']) {
         $settings['mime_type'] = "text/html; charset=" . $settings['charset'];
     }
     //iso-8859-1
     if (!$settings['language']) {
         $settings['language'] = "en";
     }
     //--------------------------------
     // Setup subclasses
     //--------------------------------
     $this->Site = new Site($settings);
     $this->Site->HTTPS = false;
     $this->Page = new Page($settings);
     $this->Page->HTTPS = false;
     //--------------------------------
     // Check HTTPS
     //--------------------------------
     if ($settings['https_enabled'] === "1") {
         $this->Rewrites[] = array("rewrite_rule" => "^(.+)\$", "rewrite_replacement" => "\$1", "rewrite_https" => "1");
     }
     //--------------------------------
     // Validate visitor
     //--------------------------------
     $this->User = new User();
     $this->User->Validated = false;
     if ($this->Session->Validate("username", "password")) {
         $query = "SELECT * FROM `{$this->DB->Prefix}users` \n\t\t\t\t\tWHERE `user_username` = '{$this->Session['username']}' \n\t\t\t\t\tAND `user_password` = '{$this->Session['password']}'\n\t\t\t\t\tLIMIT 1";
         // username/password is correct
         if ($data = $this->DB->FetchRow($query, "slave")) {
             //--------------------------------
             // Lets make this easier to manage
             //--------------------------------
             $user = preg_replace_array("/^user_/i", '', $data);
             $this->User->Merge($user);
             $this->User->Validated = true;
         } else {
             // remove session vars
             foreach ($args as $value) {
                 unset($this->Session[$value]);
             }
         }
     }
     if ($this->User['group_id']) {
         $group = $this->User['group_id'];
     } else {
         $group = $this->Page['group_id'];
     }
     $query = "SELECT * FROM `{$this->DB->Prefix}groups` \n\t\t\t\tWHERE `group_id` = '{$group}'\n\t\t\t\tLIMIT 1";
     if ($data = $this->DB->FetchRow($query, "slave")) {
         $group = preg_replace_array("/^group_/i", '', $data);
         $this->User->Group->Merge($group);
     }
 }