function custom_404() { $build_page = new Build_Page_Controller(); die($build_page->_custom_404()); }
function get_site() { $session = Session::instance(); $domain_array = explode('.', $_SERVER['HTTP_HOST']); # if the url = [subdomain].plusjade.org if (in_array(ROOTNAME, $domain_array)) { $field_name = 'subdomain'; $site_name = $domain_array['0']; # if no subdomain, set the site_name to the admin account if ('2' == count($domain_array)) { $site_name = ROOTACCOUNT; } } else { $field_name = 'custom_domain'; $site_name = $_SERVER['HTTP_HOST']; } $site = ORM::factory('site')->where(array($field_name => $site_name))->find(); if (!$site->loaded) { header("HTTP/1.0 404 Not Found"); die('site does not exist'); } # IMPORTANT: sets the site name & non-sensitive site_data. $_SESSION['site_name'] = $site->subdomain; # Make sure site_config file exists # the site_config file is parsed in the root Controller_Core library file. $site_config_path = DATAPATH . "{$site->subdomain}/protected/site_config.yml"; if (!file_exists($site_config_path)) { $replacements = array($site->id, $site->subdomain, $site->theme, $site->banner, $site->homepage); yaml::new_site_config($site_name, $replacements); } /* --- Route the URL --- --------------------- * The URL will tell us how to build the page. a. is /get/ b. is file request c. is ajax request d. is page_name is protected page? */ # Get page_name $url_array = URI::url_array(); $page_name = empty($url_array['0']) ? $site->homepage : $url_array['0']; # app/config/routes.php routes the url correctly. if ('get' == $page_name) { return FALSE; } if ('files' == $page_name) { $file = new Files_Controller(); die($file->_output($url_array)); } # Is page_name protected? $page_config_value = yaml::does_key_exist($site->subdomain, 'pages_config', $page_name); # Is protected ajax request? # get info from pages_config.yaml if ($page_config_value and request::is_ajax()) { # extract toolname and parent_id from pages_config.yaml $page_data = explode('-', $page_config_value); list($toolname, $parent_id) = $page_data; # make sure the page_name is correct. $url_array['0'] = $page_name; # send to tool _ajax handler. we expect raw data output. die(Load_Tool::factory($toolname)->_ajax($url_array, $parent_id)); } elseif (isset($_POST['post_handler']) and request::is_ajax()) { # currently only enabled for format form type. list($toolname, $parent_id) = explode(':', $_POST['post_handler']); die(Load_Tool::factory($toolname)->_ajax($url_array, $parent_id)); } # Non-protected page_names can be a subdirectory name. # do this only if an actual url string is being sent. # so we need to get the full url string. if (!empty($url_array['1']) and !$page_config_value) { $page_name = strstr($_SERVER['REQUEST_URI'], '/'); $page_name = ltrim($page_name, '/'); } $page = ORM::factory('page')->where(array('fk_site' => $site->id, 'page_name' => $page_name))->find(); if (!$page->loaded) { Event::run('system.404'); } # Load the page! $build_page = new Build_Page_Controller(); die($build_page->_index($page)); }