コード例 #1
0
ファイル: webapp_class.php プロジェクト: ameyer430/elation
 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;
 }
コード例 #2
0
ファイル: webapp_class.php プロジェクト: jbaicoianu/elation
 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;
 }