* Language was set earlier, but we can over-ride it in the session. * We have to do it here because the session was just now opened. */ if (array_key_exists('system_language', $_POST)) { if (strlen($_POST['system_language'])) { $_SESSION['language'] = $_POST['system_language']; } else { unset($_SESSION['language']); } } if (x($_SESSION, 'language') && $_SESSION['language'] !== $lang) { App::$language = $_SESSION['language']; load_translation_table(App::$language); } if (x($_GET, 'zid') && !App::$install) { App::$query_string = strip_zids(App::$query_string); if (!local_channel()) { $_SESSION['my_address'] = $_GET['zid']; zid_init($a); } } if (x($_SESSION, 'authenticated') || x($_POST, 'auth-params') || App::$module === 'login') { require 'include/auth.php'; } if (!x($_SESSION, 'sysmsg')) { $_SESSION['sysmsg'] = array(); } if (!x($_SESSION, 'sysmsg_info')) { $_SESSION['sysmsg_info'] = array(); } /*
/** * App constructor. */ public static function init() { // we'll reset this after we read our config file date_default_timezone_set('UTC'); self::$config = array('system' => array()); self::$page = array(); self::$pager = array(); self::$query_string = ''; startup(); set_include_path('include' . PATH_SEPARATOR . 'library' . PATH_SEPARATOR . 'library/langdet' . PATH_SEPARATOR . '.'); self::$scheme = 'http'; if (x($_SERVER, 'HTTPS') && $_SERVER['HTTPS']) { self::$scheme = 'https'; } elseif (x($_SERVER, 'SERVER_PORT') && intval($_SERVER['SERVER_PORT']) == 443) { self::$scheme = 'https'; } if (x($_SERVER, 'SERVER_NAME')) { self::$hostname = $_SERVER['SERVER_NAME']; if (x($_SERVER, 'SERVER_PORT') && $_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443) { self::$hostname .= ':' . $_SERVER['SERVER_PORT']; } /** * Figure out if we are running at the top of a domain * or in a sub-directory and adjust accordingly */ $path = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\'); if (isset($path) && strlen($path) && $path != self::$path) { self::$path = $path; } } set_include_path("include/self::{$hostname}" . PATH_SEPARATOR . get_include_path()); if (x($_SERVER, 'QUERY_STRING') && substr($_SERVER['QUERY_STRING'], 0, 2) === "q=") { self::$query_string = substr($_SERVER['QUERY_STRING'], 2); // removing trailing / - maybe a nginx problem if (substr(self::$query_string, 0, 1) == "/") { self::$query_string = substr(self::$query_string, 1); } } if (x($_GET, 'q')) { self::$cmd = trim($_GET['q'], '/\\'); } // unix style "homedir" if (substr(self::$cmd, 0, 1) === '~') { self::$cmd = 'channel/' . substr(self::$cmd, 1); } /* * Break the URL path into C style argc/argv style arguments for our * modules. Given "http://example.com/module/arg1/arg2", self::$argc * will be 3 (integer) and self::$argv will contain: * [0] => 'module' * [1] => 'arg1' * [2] => 'arg2' * * There will always be one argument. If provided a naked domain * URL, self::$argv[0] is set to "home". */ self::$argv = explode('/', self::$cmd); self::$argc = count(self::$argv); if (array_key_exists('0', self::$argv) && strlen(self::$argv[0])) { self::$module = str_replace(".", "_", self::$argv[0]); self::$module = str_replace("-", "_", self::$module); if (strpos(self::$module, '_') === 0) { self::$module = substr(self::$module, 1); } } else { self::$argc = 1; self::$argv = array('home'); self::$module = 'home'; } /* * See if there is any page number information, and initialise * pagination */ self::$pager['page'] = x($_GET, 'page') && intval($_GET['page']) > 0 ? intval($_GET['page']) : 1; self::$pager['itemspage'] = 60; self::$pager['start'] = self::$pager['page'] * self::$pager['itemspage'] - self::$pager['itemspage']; if (self::$pager['start'] < 0) { self::$pager['start'] = 0; } self::$pager['total'] = 0; /* * Detect mobile devices */ $mobile_detect = new Mobile_Detect(); self::$is_mobile = $mobile_detect->isMobile(); self::$is_tablet = $mobile_detect->isTablet(); self::head_set_icon('/images/hz-32.png'); /* * register template engines */ spl_autoload_register('ZotlabsAutoloader::loader'); self::$meta = new Zotlabs\Web\HttpMeta(); // create an instance of the smarty template engine so we can register it. $smarty = new Zotlabs\Render\SmartyTemplate(); $dc = get_declared_classes(); foreach ($dc as $k) { if (in_array('Zotlabs\\Render\\TemplateEngine', class_implements($k))) { self::register_template_engine($k); } } }
public function run() { /* * Bootstrap the application, load configuration, load modules, load theme, etc. */ require_once 'boot.php'; sys_boot(); \App::$language = get_best_language(); load_translation_table(\App::$language, \App::$install); /** * * Important stuff we always need to do. * * The order of these may be important so use caution if you think they're all * intertwingled with no logical order and decide to sort it out. Some of the * dependencies have changed, but at least at one time in the recent past - the * order was critical to everything working properly * */ if (\App::$session) { \App::$session->start(); } else { session_start(); register_shutdown_function('session_write_close'); } /** * Language was set earlier, but we can over-ride it in the session. * We have to do it here because the session was just now opened. */ if (array_key_exists('system_language', $_POST)) { if (strlen($_POST['system_language'])) { $_SESSION['language'] = $_POST['system_language']; } else { unset($_SESSION['language']); } } if (x($_SESSION, 'language') && $_SESSION['language'] !== $lang) { \App::$language = $_SESSION['language']; load_translation_table(\App::$language); } if (x($_GET, 'zid') && !\App::$install) { \App::$query_string = strip_zids(\App::$query_string); if (!local_channel()) { $_SESSION['my_address'] = $_GET['zid']; zid_init(); } } if (x($_GET, 'zat') && !\App::$install) { \App::$query_string = strip_zats(\App::$query_string); if (!local_channel()) { zat_init(); } } if (x($_SESSION, 'authenticated') || x($_POST, 'auth-params') || \App::$module === 'login') { require 'include/auth.php'; } if (!x($_SESSION, 'sysmsg')) { $_SESSION['sysmsg'] = array(); } if (!x($_SESSION, 'sysmsg_info')) { $_SESSION['sysmsg_info'] = array(); } /* * check_config() is responsible for running update scripts. These automatically * update the DB schema whenever we push a new one out. It also checks to see if * any plugins have been added or removed and reacts accordingly. */ if (\App::$install) { /* Allow an exception for the view module so that pcss will be interpreted during installation */ if (\App::$module != 'view') { \App::$module = 'setup'; } } else { check_config($a); } nav_set_selected('nothing'); $Router = new Router($a); /* initialise content region */ if (!x(\App::$page, 'content')) { \App::$page['content'] = ''; } call_hooks('page_content_top', \App::$page['content']); $Router->Dispatch($a); // If you're just visiting, let javascript take you home if (x($_SESSION, 'visitor_home')) { $homebase = $_SESSION['visitor_home']; } elseif (local_channel()) { $homebase = z_root() . '/channel/' . \App::$channel['channel_address']; } if (isset($homebase)) { \App::$page['content'] .= '<script>var homebase = "' . $homebase . '";</script>'; } // now that we've been through the module content, see if the page reported // a permission problem and if so, a 403 response would seem to be in order. if (is_array($_SESSION['sysmsg']) && stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) { header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.')); } call_hooks('page_end', \App::$page['content']); construct_page($a); killme(); }