function App($rootdir, $args) { Profiler::StartTimer("WebApp", 1); Profiler::StartTimer("WebApp::Init", 1); Profiler::StartTimer("WebApp::TimeToDisplay", 1); $GLOBALS["webapp"] = $this; register_shutdown_function(array('Logger', 'processShutdown')); ob_start(); $this->rootdir = $rootdir; $this->debug = !empty($args["debug"]); $this->getAppVersion(); Logger::Info("WebApp Initializing (" . $this->appversion . ")"); Logger::Info("Path: " . get_include_path()); $this->initAutoLoaders(); Logger::Info("Turning Pandora flag on"); if (class_exists("PandoraLog")) { $pandora = PandoraLog::singleton(); $pandora->setFlag(true); } $this->locations = array("scripts" => "htdocs/scripts", "css" => "htdocs/css", "tmp" => "tmp", "config" => "config"); $this->request = $this->ParseRequest(NULL, $args); $this->locations["basedir"] = $this->request["basedir"]; $this->locations["scriptswww"] = $this->request["basedir"] . "/scripts"; $this->locations["csswww"] = $this->request["basedir"] . "/css"; $this->locations["imageswww"] = $this->request["basedir"] . "/images"; $this->InitProfiler(); $this->cfg = ConfigManager::singleton($rootdir); $this->InitProfiler(); // reinitialize after loading the config $this->locations = array_merge($this->locations, $this->cfg->locations); $this->data = DataManager::singleton($this->cfg); set_error_handler(array($this, "HandleError"), error_reporting()); DependencyManager::init($this->locations); if ($this->initialized()) { try { $this->session = SessionManager::singleton(); // Set sticky debug flag if (isset($this->request["args"]["debug"])) { $this->debug = $_SESSION["debug"] = $this->request["args"]["debug"] == 1; } else { if (!empty($_SESSION["debug"])) { $this->debug = $_SESSION["debug"]; } } $this->cobrand = $this->GetRequestedConfigName($this->request); $this->cfg->GetConfig($this->cobrand, true, $this->cfg->role); $this->ApplyConfigOverrides(); $this->locations = DependencyManager::$locations = $this->cfg->locations; // And the google analytics flag if (isset($this->request["args"]["GAalerts"])) { $this->GAalerts = $this->session->temporary["GAalerts"] = $this->request["args"]["GAalerts"] == 1 ? 1 : 0; } else { if (!empty($this->session->temporary["GAalerts"])) { $this->GAalerts = $this->session->temporary["GAalerts"]; } else { $this->GAalerts = 0; } } $this->apiversion = any($this->request["args"]["apiversion"], ConfigManager::get("api.version.default"), 0); $this->tplmgr = TemplateManager::singleton($this->rootdir); $this->tplmgr->assign_by_ref("webapp", $this); $this->components = ComponentManager::singleton($this); $this->orm = OrmManager::singleton(); //$this->tplmgr->SetComponents($this->components); } catch (Exception $e) { print $this->HandleException($e); } } else { $fname = "./templates/uninitialized.tpl"; if (($path = file_exists_in_path($fname, true)) !== false) { print file_get_contents($path . "/" . $fname); } } $this->user = User::singleton(); $this->user->InitActiveUser($this->request); // Merge permanent user settings from the URL if (!empty($this->request["args"]["settings"])) { foreach ($this->request["args"]["settings"] as $k => $v) { $this->user->SetPreference($k, $v, "user"); } } // ...and then do the same for session settings if (!empty($this->request["args"]["sess"])) { foreach ($this->request["args"]["sess"] as $k => $v) { $this->user->SetPreference($k, $v, "temporary"); } } // And finally, initialize abtests if (class_exists(ABTestManager)) { Profiler::StartTimer("WebApp::Init - abtests", 2); $this->abtests = ABTestmanager::singleton(array("cobrand" => $this->cobrand, "v" => $this->request["args"]["v"])); Profiler::StopTimer("WebApp::Init - abtests"); } Profiler::StopTimer("WebApp::Init"); }
function App($rootdir, $args) { Profiler::StartTimer("WebApp", 1); Profiler::StartTimer("WebApp::Init", 1); Profiler::StartTimer("WebApp::TimeToDisplay", 1); // disable notices by default. This should probably be a config option... error_reporting(error_reporting() ^ E_NOTICE); // FIXME - xdebug recursion limit causes problems in some components... ini_set('xdebug.max_nesting_level', 250); $GLOBALS["webapp"] = $this; register_shutdown_function(array($this, 'shutdown')); ob_start(); $this->rootdir = $rootdir; $this->debug = !empty($args["debug"]); $this->getAppVersion(); Logger::Info("WebApp Initializing (" . $this->appversion . ")"); Logger::Info("Path: " . get_include_path()); $this->initAutoLoaders(); if (class_exists("PandoraLog")) { Logger::Info("Turning Pandora flag on"); $pandora = PandoraLog::singleton(); $pandora->setFlag(true); } $this->InitProfiler(); $this->request = $this->ParseRequest(NULL, $args); $this->cfg = ConfigManager::singleton(array("rootdir" => $rootdir, "basedir" => $this->request["basedir"])); $this->locations = ConfigManager::getLocations(); $this->InitProfiler(); // reinitialize after loading the config Profiler::StartTimer("WebApp::Init - handleredirects", 1); $this->request = $this->ApplyRedirects($this->request); Profiler::StopTimer("WebApp::Init - handleredirects"); $this->data = DataManager::singleton($this->cfg); set_error_handler(array($this, "HandleError"), error_reporting()); DependencyManager::init($this->locations); if ($this->initialized()) { try { $this->session = SessionManager::singleton(); // Set sticky debug flag if (isset($this->request["args"]["debug"])) { $this->debug = $_SESSION["debug"] = $this->request["args"]["debug"] == 1; } else { if (!empty($_SESSION["debug"])) { $this->debug = $_SESSION["debug"]; } } $this->cobrand = $this->GetRequestedConfigName($this->request); if (isset($this->request["args"]["_role"])) { $this->role = $this->request["args"]["_role"]; } else { if (isset($this->cfg->servers["role"])) { $this->role = $this->cfg->servers["role"]; } else { $this->role = "dev"; } } $this->cfg->GetConfig($this->cobrand, true, $this->role); $this->ApplyConfigOverrides(); $this->locations = DependencyManager::$locations = $this->cfg->locations; // And the google analytics flag if (isset($this->request["args"]["GAalerts"])) { $this->GAalerts = $this->session->temporary["GAalerts"] = $this->request["args"]["GAalerts"] == 1 ? 1 : 0; } else { if (!empty($this->session->temporary["GAalerts"])) { $this->GAalerts = $this->session->temporary["GAalerts"]; } else { $this->GAalerts = 0; } } $this->apiversion = isset($this->request["args"]["apiversion"]) ? $this->request["args"]["apiversion"] : ConfigManager::get("api.version.default", 0); $this->tplmgr = TemplateManager::singleton($this->locations); $this->tplmgr->assign_by_ref("webapp", $this); $this->components = ComponentManager::singleton($this); if (class_exists("OrmManager")) { $this->orm = OrmManager::singleton($this->locations); } //$this->tplmgr->SetComponents($this->components); } catch (Exception $e) { print $this->HandleException($e); } } else { $fname = "components/elation/templates/uninitialized.html"; if (($path = file_exists_in_path($fname, true)) !== false) { print file_get_contents($path . "/" . $fname); } } $this->user = User::singleton(); $this->user->InitActiveUser($this->request); // Merge permanent user settings from the URL if (!empty($this->request["args"]["settings"])) { foreach ($this->request["args"]["settings"] as $k => $v) { $this->user->SetPreference($k, $v, "user"); } } // ...and then do the same for session settings if (!empty($this->request["args"]["sess"])) { foreach ($this->request["args"]["sess"] as $k => $v) { $this->user->SetPreference($k, $v, "temporary"); } } // And finally, initialize abtests if (class_exists("ABTestManager")) { Profiler::StartTimer("WebApp::Init - abtests", 2); $this->abtests = ABTestmanager::singleton(array("cobrand" => $this->cobrand, "v" => $this->request["args"]["v"])); Profiler::StopTimer("WebApp::Init - abtests"); } Profiler::StopTimer("WebApp::Init"); }
function Dispatch($page = NULL, $args = NULL, $output = "html") { $alternateret = $this->HandleDispatchArgs($args); $outputtype = !empty($_SERVER["HTTP_X_AJAX"]) ? "ajax" : $output; if (isset($args["_output"])) { $outputtype = $args["_output"]; } if ($args === NULL) { $args = $_REQUEST; } // Load all content URLs from the config, and build a lookup table based on URL $cfg = ConfigManager::singleton(); $contentpages = $cfg->getSetting("page.content"); $contenturls = array(); $contentredirects = array(); if (!empty($contentpages)) { foreach ($contentpages as $pagename => $pagevalues) { $contenturls[$pagevalues["url"]] = $pagevalues; $contenturls[$pagevalues["url"]]["name"] = $pagename; if (!empty($pagevalues["redirects"])) { $redirects = explode(",", $pagevalues["redirects"]); foreach ($redirects as $r) { $contentredirects[$r] = $pagevalues["url"]; } } } } $tplmgr = TemplateManager::singleton(); $this->pagecfg = array(); $pagecfg =& $this->pagecfg; $smarty = TemplateManager::singleton(); $smarty->assign_by_ref("pagecfg", $pagecfg); $ret["type"] = $pagecfg["type"] = $outputtype; $ret["page"] = $pagecfg["page"] = $page; $ret["pagename"] = $pagecfg["pagename"] = ''; //str_replace("/", "_", substr($page, 1)); $this->pagecfg["args"] = $args; $applysettings = empty($args["xmlapi"]); $page_noextension = preg_replace("/\\.[^.]+\$/", "", $page); if (!empty($contenturls[$page]) || !empty($contenturls[$page_noextension])) { // Check for config-mapped URL first $pagevars = any($contenturls[$page], $contenturls[$page_noextension]); $pagecfg["pagename"] = any($pagevars["pagename"], $pagevars["name"]); $pagecfg["pagegroup"] = $pagevars["pagegroup"]; $ext = substr($page, strlen($page_noextension) + 1); if (!empty($ext)) { $outputtype = $ret["type"] = $ret["responsetype"] = $pagecfg["type"] = $ext; } if (!empty($pagevars["options"])) { $cfg->ConfigMerge($cfg->current, $pagevars["options"]); } if (!empty($pagevars["layout"])) { $layoutcfg = ConfigManager::get("page.layout." . $pagevars["layout"]); if (!empty($layoutcfg)) { $pagecfg["layout"] = $layoutcfg; } } if (!empty($pagevars["ads"])) { $pagecfg["ads"] = $pagevars["ads"]; } $args = $this->ApplyOverrides($args, $applysettings); if (!empty($pagevars["component"]) && self::has($pagevars["component"])) { $componentargs = !empty($pagevars["vars"]) ? array_merge($pagevars["vars"], $args) : $args; $ret["component"] = $pagevars["component"]; $ret["content"] = self::fetch($pagevars["component"], $componentargs, $outputtype); } else { if (!empty($pagevars["template"]) && $tplmgr->template_exists($pagevars["template"])) { $pagevars["vars"]["args"] = $args; $pagevars["vars"]["sitecfg"] = $this->root->sitecfg; $ret["content"] = $this->GetTemplate($pagevars["template"], $pagevars["vars"]); } else { $ret["content"] = $this->GetTemplate("404.tpl", $pagevars["vars"]); $ret["http_status"] = 404; } } } else { if ($page == "/") { // Handle the homepage $ret["component"] = "index"; $ret["content"] = self::fetch("index", $args, $outputtype); } else { if (strpos($page, "/../") === false && file_exists("./htdocs" . $page)) { $pathinfo = pathinfo($page); // FIXME - this should be extended and made configurable, we do similar stuff later... $mimetypes = array("js" => "application/javascript", "css" => "text/css", "html" => "text/html", "txt" => "text/plain"); $outputtype = any($mimetypes[$pathinfo["extension"]], mime_content_type("./htdocs" . $page), "text/plain"); $ret["type"] = $ret["responsetype"] = $outputtype; $ret["content"] = file_get_contents("./htdocs" . $page); } else { if (isset($contentredirects[$page])) { // Redirects stored in page.content.*.redirects http_redirect($contentredirects[$page]); } else { if (preg_match("|^/((?:[^./]+/?)*)(?:\\.(.*))?\$|", $page, $m)) { // Dispatch directly to a component. File extension determines output type $componentname = str_replace("/", ".", $m[1]); // FIXME - this is ugly. Basically: // - If we passed an output in via the &_output= URL param, it takes precedence // - If the request has a file extension, use that... // - UNLESS the extension is .fhtml and we've already determined this is an AjaxLib response (LEGACY CODE) if (empty($args["_output"]) && !empty($m[2]) && !($m[2] == "fhtml" && $outputtype == "ajax")) { $outputtype = $m[2]; } $ret["component"] = $componentname; $ret["type"] = $ret["responsetype"] = $outputtype; $args = $this->ApplyOverrides($args, $applysettings); if ($component = $this->Get($componentname)) { $componentargs = !empty($this->dispatchargs[$componentname]) ? array_merge_recursive($args, $this->dispatchargs[$componentname]) : $args; $ret["content"] = $component->HandlePayload($componentargs, $outputtype); if ($component instanceof ComponentMissing) { $ret["http_status"] = 404; } } } } } } } if (is_array($ret['content'])) { $ret['content'] = new ComponentResponse(NULL, $ret['content']); $outputtype = "ajax"; } if ($ret['content'] instanceof ComponentResponse) { $output = $ret['content']->getOutput($outputtype); $ret['type'] = $ret['responsetype'] = $output[0]; $ret['content'] = $output[1]; } else { if ($outputtype == "ajax") { $ret['type'] = $ret['responsetype'] = "application/xml"; } else { if (empty($ret['type'])) { $ret['type'] = $ret['responsetype'] = "text/html"; } } } // Pandora page log if (class_exists("PandoraLog")) { $pandora = PandoraLog::singleton(); $session = SessionManager::singleton(); $pandora_pages = array("timestamp" => time(), "session_id" => $session->flsid, "fluid" => $session->fluid, "referrer_url" => $_SERVER['HTTP_REFERER'], "page_url" => "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], "page_type" => $pagecfg["pagename"]); if (!ConfigManager::get("tracking.pandora", true)) { $pandora->setFlag(false); } if ($pagecfg['pagename'] && $pandora instanceof PandoraLog) { $pandora->addData("pages", $pandora_pages); // if $pagecfg["pagename"] known, update the session if (!empty($pagecfg["pagename"])) { $pandora->setPageType($pagecfg["pagename"]); } } } // TODO - handle redirects and postprocessing for different output types here return $ret; }
/** * session close requirement * Persist the data warehouse log data. */ public function close() { //$this->data->Quit(); Profiler::StartTimer("Pandora", 1); $pandora = PandoraLog::singleton(); if ($pandora->getFlag() == false) { // if pandora logging is not turned on, return Profiler::StopTimer("Pandora"); return; } // exclude the internal server crawls and testings $exclude_user_agents = array("im2-"); for ($i = 0; $i < count($exclude_user_agents); $i++) { if (strpos($_SERVER['HTTP_USER_AGENT'], $exclude_user_agents[$i]) !== false) { Profiler::StopTimer("Pandora"); return; } } // process the pandora logging $pandora = PandoraLog::singleton(); $pandora->writeLog(); Profiler::StopTimer("Pandora"); }