public function _index($account, $sub_tool = FALSE) { $url_array = URI::url_array(); $page_name = $this->get_page_name($url_array['0'], 'account', $account->id); $username = $url_array['2']; $action = (empty($url_array['1']) or 'tool' == $url_array['1']) ? 'index' : $url_array['1']; switch ($action) { case 'index': $content = self::dashboard($page_name); break; case 'create': return $this->wrap_tool(self::create_account($page_name), 'account', $account); break; case 'profile': return $this->wrap_tool(self::profile($username), 'account', $account); break; case 'all': return $this->wrap_tool(self::all_users($page_name), 'account', $account); break; case 'edit_profile': $content = self::edit_profile($page_name); break; case 'change_password': $content = self::change_password($page_name); break; case 'reset_password': $content = self::reset_password($page_name); break; case 'logout': $this->account_user->logout(); $primary = $this->display_login($page_name); return $this->wrap_tool($primary, 'account', $account); break; /* plusjade stuff only */ /* plusjade stuff only */ case 'safe_mode': $content = self::safe_mode($page_name, $username); break; case 'new_website': $content = self::new_website($page_name); break; default: Event::run('system.404'); } # the logic above will determine whether the user is logged in/out $wrapper = $this->account_user->logged_in($this->site_id) ? new View('public_account/accounts/dashboard') : new View('public_account/accounts/index'); $wrapper->content = $content; $wrapper->page_name = $page_name; return $this->wrap_tool($wrapper, 'account', $account); }
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)); }