function ApplyConfigOverrides() { if (!empty($this->request["args"]["sitecfg"])) { $tmpcfg = array(); array_set_multi($tmpcfg, $this->request["args"]["sitecfg"]); // FIXME - can't we just array_set_multi() on $this->sitecfg directly? ConfigManager::merge($tmpcfg); } if (!empty($this->request["args"]["cobrandoverride"])) { $included_config =& $this->cfg->GetConfig($this->request["args"]["cobrandoverride"], false, $this->cfg->role); if (!empty($included_config)) { ConfigManager::merge($included_config); } } $rolename = any($this->request["args"]["_role"], $this->cfg->role); $rolecfg = ConfigManager::get("roles.{$rolename}.options"); if (!empty($rolecfg)) { Logger::Info("Using overridden role cfg 'roles.{$rolename}'"); ConfigManager::merge($rolecfg); } if ($this->request["ssl"]) { $included_config = $this->cfg->GetConfig("classes.secure", false, $this->cfg->role); if (!empty($included_config)) { ConfigManager::merge($included_config); } } $browseroverride = any($this->request["args"]["sess"]["browser.override"], $_SESSION["temporary"]["user"]["preferences"]["browser"]["override"], NULL); if ($browseroverride !== NULL) { $this->request["browser"] = $browseroverride; } if (!empty($this->request["browser"])) { $included_config =& ConfigManager::get("browsers.{$this->request['browser']}.options"); if (!empty($included_config["include"])) { // These includes sure do get hairy. This allows for browsers.*.options.include to call in different classes $includes = explode(",", $included_config["include"]); foreach ($includes as $include) { $subincluded_config =& $this->cfg->GetConfig($include, false, $this->cfg->role); if (!empty($subincluded_config)) { ConfigManager::merge($subincluded_config); } } unset($included_config["include"]); } if (!empty($included_config)) { ConfigManager::merge($included_config); } } if ($this->debug) { $subincluded_config =& $this->cfg->GetConfig("classes.debug", false, $this->cfg->role); if (!empty($subincluded_config)) { ConfigManager::merge($subincluded_config); } } }
function ParseRequest($page = NULL, $post = NULL) { Profiler::StartTimer("WebApp::Init - parserequest", 1); $webroot = ""; if ($page === NULL) { $page = $_SERVER["SCRIPT_URL"]; } if ($page === NULL) { if (preg_match("/^(.*?)\\/go\\.php\$/", $_SERVER["SCRIPT_NAME"], $m)) { $webroot = $m[1]; } $page = preg_replace("/" . preg_quote($webroot, "/") . "(.*?)(\\?.*)?\$/", "\$1", $_SERVER["REQUEST_URI"]); } if ($post === NULL) { $post = array(); } if (!empty($_GET)) { $post = array_merge($post, $_GET); } if (!empty($_POST)) { $post = array_merge($post, $_POST); } $req = @parse_url($page); // FIXME - PHP sucks and throws a warning here on malformed URLs, with no way to catch as an exception // GET args if (!empty($req["query"])) { parse_str($req["query"], $req["args"]); } else { $req["args"] = array(); } // POST data, if (!empty($post)) { if (get_magic_quotes_gpc()) { $post = array_map('stripslashes_deep', $post); } $req["args"] = array_merge($req["args"], $post); } // application/json POST data if ($_SERVER["REQUEST_METHOD"] == "POST" && $_SERVER["CONTENT_TYPE"] == "application/json") { $postdata = json_decode(file_get_contents("php://input"), true); if (!empty($postdata) && is_array($postdata)) { $req["args"] = array_merge($req["args"], $postdata); } } // Parse friendly URLs $req["friendly"] = false; if (preg_match_all("/\\/([^-\\/]+)-([^\\/]+)/", $req["path"], $m, PREG_SET_ORDER)) { $req["friendly"] = true; $friendlyargs = array(); foreach ($m as $match) { $search[] = $match[0]; $replace[] = ""; array_set($friendlyargs, $match[1], decode_friendly($match[2])); } $req["path"] = str_replace($search, $replace, $req["path"]); if (empty($req["path"])) { $req["path"] = "/"; } if (!empty($friendlyargs)) { $req["args"] = array_merge($friendlyargs, $req["args"]); } } $req["host"] = $_SERVER["HTTP_HOST"]; $req["ssl"] = !empty($_SERVER["HTTPS"]); $req["scheme"] = "http" . ($req["ssl"] ? "s" : ""); $req["ip"] = $_SERVER["REMOTE_ADDR"]; $req["user_agent"] = $_SERVER['HTTP_USER_AGENT']; $req["referrer"] = $_SERVER["HTTP_REFERER"]; if (!empty($_SERVER["HTTP_REFERER"])) { $req["referer"] = parse_url($_SERVER["HTTP_REFERER"]); if (!empty($req["referer"]["query"])) { parse_str($req["referer"]["query"], $req["referer"]["args"]); } else { $req["referer"]["args"] = array(); } } $req["ajax"] = !empty($_SERVER["HTTP_X_AJAX"]) || !empty($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"; if (!empty($_SERVER["PHP_AUTH_USER"])) { $req["user"] = $_SERVER["PHP_AUTH_USER"]; } if (!empty($_SERVER["PHP_AUTH_PW"])) { $req["password"] = $_SERVER["PHP_AUTH_PW"]; } $req["basedir"] = $webroot; $req["baseurl"] = $req["scheme"] . "://" . $req["host"] . $req["basedir"]; //$req["url"] = $req["baseurl"] . $page; $req["url"] = $req["baseurl"] . $_SERVER["REQUEST_URI"]; // FIXME - This probably breaks non-root-level installs... if ($req["basedir"] == '/') { $req["basedir"] = ''; } if (!empty($req["args"]["req"])) { array_set_multi($req, $req["args"]["req"]); } Profiler::StopTimer("WebApp::Init - parserequest"); Profiler::StartTimer("WebApp::Init - handleredirects", 1); $rewritefile = $this->locations["config"] . "/redirects.xml"; if (file_exists($rewritefile)) { $rewrites = new SimpleXMLElement(file_get_contents($rewritefile)); $req = $this->ApplyRedirects($req, $rewrites->rule); } Profiler::StopTimer("WebApp::Init - handleredirects"); if (!empty($req["contenttype"])) { $this->response["type"] = $req["contenttype"]; } return $req; }
function array_set_multi(&$arr, $values, $keys = NULL) { Profiler::StartTimer("array_set_multi"); if ($keys === NULL) { $tmp = array_keys($values); $keys = array_combine($tmp, $tmp); } asort($keys, SORT_STRING); //print_pre($keys); $subelements = array(); foreach ($keys as $key => $fullkey) { list($topkey, $subkey) = explode(".", $key, 2); if (empty($subkey)) { // If we're already at a leaf, just set it //print "set $topkey<br />"; $arr[$topkey] = $values[$fullkey]; } else { if (isset($arr[$topkey]) && !is_array($arr[$topkey])) { //print "skip $topkey<br />"; Logger::Error("array_set_multi: Failed to set {$fullkey}: already a node?"); continue; } else { if (!isset($arr[$topkey])) { $arr[$topkey] = array(); } if (strpos($subkey, ".") === FALSE) { // Shortcut for leaf nodes to cut down on recursion (same effect as leaf case above) $arr[$topkey][$subkey] = $values[$fullkey]; } else { $subelements[$topkey][$subkey] = $fullkey; } } } } foreach ($subelements as $k => $v) { array_set_multi($arr[$k], $values, $v); } Profiler::StopTimer("array_set_multi"); }
public function setOptions($options) { $ret = false; if (!is_array($this->config)) { $this->config = array(); } if (is_array($options)) { array_set_multi($newcfg, $options); $this->config = array_merge_recursive($this->config, $newcfg); $ret = true; } return $ret; }
function ParseRequest($page = NULL, $post = NULL) { Profiler::StartTimer("WebApp::Init - parserequest", 1); $webroot = ""; if ($page === NULL) { if (preg_match("/^(.*?)\\/index\\.php\$/", $_SERVER["SCRIPT_NAME"], $m)) { $webroot = $m[1]; } //print_pre($_SERVER); if (isset($_SERVER["PATH_INFO"])) { $page = $_SERVER["PATH_INFO"]; $webroot = $_SERVER["SCRIPT_NAME"]; } else { if (isset($_SERVER["SCRIPT_URL"])) { $page = $_SERVER["SCRIPT_URL"]; } else { if (empty($_SERVER["REDIRECT_URL"])) { $webroot = $_SERVER["SCRIPT_NAME"]; $page = "/"; } else { $page = preg_replace("/" . preg_quote($webroot, "/") . "(.*?)(\\?.*)?\$/", "\$1", $_SERVER["REQUEST_URI"]); if ($page == "/index.php") { $page = "/"; } } } } } if ($post === NULL) { $post = array(); } if (!empty($_GET)) { $post = array_merge($post, $_GET); } if (!empty($_POST)) { $post = array_merge($post, $_POST); } $req = @parse_url($page); // FIXME - PHP sucks and throws a warning here on malformed URLs, with no way to catch as an exception if (!empty($req["query"])) { parse_str($req["query"], $req["args"]); } else { $req["args"] = array(); } if (!empty($post)) { if (get_magic_quotes_gpc()) { $post = array_map('stripslashes_deep', $post); } $req["args"] = array_merge($req["args"], $post); } $req["friendly"] = false; // Parse friendly URLs if (preg_match_all("/\\/([^-\\/]+)-([^\\/]+)/", $req["path"], $m, PREG_SET_ORDER)) { $req["friendly"] = true; $friendlyargs = array(); foreach ($m as $match) { $search[] = $match[0]; $replace[] = ""; array_set($friendlyargs, $match[1], decode_friendly($match[2])); } $req["path"] = str_replace($search, $replace, $req["path"]); if (empty($req["path"])) { $req["path"] = "/"; } if (!empty($friendlyargs)) { $req["args"] = array_merge($friendlyargs, $req["args"]); } } $req["method"] = $_SERVER["REQUEST_METHOD"]; $req["host"] = $_SERVER["HTTP_HOST"]; $req["ssl"] = !empty($_SERVER["HTTPS"]); $req["scheme"] = "http" . ($req["ssl"] ? "s" : ""); $req["ip"] = $_SERVER["REMOTE_ADDR"]; $req["user_agent"] = $_SERVER['HTTP_USER_AGENT']; $req["referrer"] = $_SERVER["HTTP_REFERER"]; if (!empty($_SERVER["HTTP_REFERER"])) { $req["referer"] = parse_url($_SERVER["HTTP_REFERER"]); if (!empty($req["referer"]["query"])) { parse_str($req["referer"]["query"], $req["referer"]["args"]); } else { $req["referer"]["args"] = array(); } } $req["ajax"] = !empty($_SERVER["HTTP_X_AJAX"]) || !empty($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"; if (!empty($_SERVER["PHP_AUTH_USER"])) { $req["user"] = $_SERVER["PHP_AUTH_USER"]; } if (!empty($_SERVER["PHP_AUTH_PW"])) { $req["password"] = $_SERVER["PHP_AUTH_PW"]; } $req["basedir"] = $webroot; $req["baseurl"] = $req["scheme"] . "://" . $req["host"] . $req["basedir"]; //$req["url"] = $req["baseurl"] . $page; $req["url"] = $req["baseurl"] . $_SERVER["REQUEST_URI"]; // FIXME - This probably breaks non-root-level installs... if ($req["basedir"] == '/') { $req["basedir"] = ''; } if (!empty($req["args"]["req"])) { array_set_multi($req, $req["args"]["req"]); } Profiler::StopTimer("WebApp::Init - parserequest"); return $req; }