public function runReferrerControl() { //WARNING, THIS COULD LEAD TO INFINITE LOOP $sLastURL = FlexiPlatformHandler::getReferrerURL(); //var_dump($sLastURL); //echo __METHOD__ . ":baseurl: " . FlexiConfig::$sBaseURL; $iPos = strpos(strtolower($sLastURL), strtolower(FlexiConfig::$sBaseURL)); //var_dump($iPos); if ($iPos !== false && $iPos == 0) { //is this site $aURL = FlexiURLUtil::parseURL($sLastURL); $sMethod = "default"; $sModule = "default"; $aQuery = $aURL["aQuery"]; if (count($aQuery) > 0) { $sRequestModule = $sQueryModule = FlexiConfig::getRequestModuleVarName(); $sQueryMethod = FlexiConfig::getRequestMethodVarName(); if (isset($aQuery[$sQueryModule]) && !empty($sQueryModule)) { $sModule = $aQuery[$sQueryModule]; } if (isset($aQuery[$sQueryMethod]) && !empty($sQueryMethod)) { $sMethod = $aQuery[$sQueryMethod]; } } FlexiLogger::debug(__METHOD__, "running referrer: " . $sModule . "," . $sMethod); $bResult = $this->runControl($sMethod, $sModule); FlexiPlatformHandler::getPlatformHandler()->forceDie(); } else { //if is not from this site, return to the calling url return $this->redirectURL($sLastURL); } }
function flexiURL($sURL, $bAjax = false) { if (!is_string($sURL)) { throw new Exception("URL is not string: " . serialize($sURL)); } if (substr(strtolower($sURL), 0, 5) == "http:" || substr(strtolower($sURL), 0, 6) == "https:" || substr(strtolower($sURL), 0, 4) == "ftp:" || substr(strtolower($sURL), 0, 11) == "javascript:") { return $sURL; } //echo "Getting: " . $sURL . ", " . ($bAjax ? ",is ajax": ",normal")."<br/>\n"; //$sep = substr(FlexiConfig::$sBaseURL, -1) == "/" ? "" : "/"; if ($bAjax) { $iPos = strpos(FlexiConfig::$sBaseURL, "?"); $sQuery = ""; if ($iPos !== false) { //contain query //FlexiConfig::$sBaseURL[strlen(FlexiConfig::$sBaseURL)-1] != "/" && //parse_str($sURL, $aInfo); $sBaseURL = substr(FlexiConfig::$sBaseURL, 0, $iPos); $sQuery = substr(FlexiConfig::$sBaseURL, $iPos + 1); } else { //no query if (FlexiConfig::$sFramework == "modx2") { $sBaseURL = FlexiConfig::$sBaseURLDir; } else { $sBaseURL = FlexiConfig::$sBaseURL; } } if (!FlexiConfig::$bIsAdminPath && $sBaseURL[strlen($sBaseURL) - 1] == "/") { $sBaseURL .= "flexi." . FlexiConfig::$sFramework . ".php"; } else { if (!FlexiConfig::$bIsAdminPath) { //else , discard ending file $iPos = strrpos($sBaseURL, "/"); if ($iPos !== false) { $sBaseURL = substr($sBaseURL, 0, $iPos + 1); } $sBaseURL .= "flexi." . FlexiConfig::$sFramework . ".php"; } else { if (FlexiConfig::$sFramework == "modx2" && FlexiConfig::$bIsAdminPath) { global $iActionId; $sBaseURL = dirname($sBaseURL) . "/flexi." . FlexiConfig::$sFramework . ".php?a=" . $iActionId; } } } $sBaseURL = str_replace("//", "/", $sBaseURL); //echo "baseurl-1: " .$sBaseURL; if (FlexiConfig::$sFramework != "modx2" && !empty($sQuery)) { if (strpos($sBaseURL, "?") === false) { $sBaseURL .= "?" . $sQuery; } else { $sBaseURL .= "&" . $sQuery; } } //echo "baseurl-12: " .$sBaseURL; } else { $sBaseURL = FlexiConfig::$sBaseURL; //echo "not ajax: " . $sBaseURL; } //if (FlexiConfig::$sFramework == "modx2") var_dump($sBaseURL); //var_dump(FlexiConfig::$aQueryString); if (substr($sURL, 0, 1) == "?") { $sURL = substr($sURL, 1); } switch (FlexiConfig::$sFramework) { case "modx": if (FlexiConfig::$bIsAdminPath) { parse_str($sURL, $aInfo); //var_dump($sURL); $aInfo = array_merge(FlexiConfig::$aQueryString, $aInfo); $sResult = $sBaseURL . "?" . FlexiURLUtil::getQueryStringFromArray($aInfo); } else { $sResult = $sBaseURL . "?" . $sURL; } break; case "modx2": if (FlexiConfig::$bIsAdminPath) { parse_str($sURL, $aInfo); if (!$bAjax) { $aInfo = array_merge(FlexiConfig::$aQueryString, $aInfo); } //echo "baseurl2: " .$sBaseURL; //die(); $sResult = $sBaseURL . (strpos($sBaseURL, "?") !== false ? "&" : "?") . FlexiURLUtil::getQueryStringFromArray($aInfo); } else { $sResult = $sBaseURL . (strpos($sBaseURL, "?") !== false ? "&" : "?") . $sURL; } break; case "": $sResult = $sBaseURL . (strpos($sBaseURL, "?") !== false ? "&" : "?") . $sURL; break; case "core": $sResult = $sBaseURL . (strpos($sBaseURL, "?") !== false ? "&" : "?") . $sURL; break; default: parse_str($sURL, $aInfo); $aInfo = array_merge(FlexiConfig::$aQueryString, $aInfo); //var_dump($aInfo); $sResult = $sBaseURL; $sQuery = ""; foreach ($aInfo as $sKey => $sValue) { $sKey = str_replace("?", "", $sKey); $sQuery .= empty($sQuery) ? "" : "&"; if (is_array($sValue)) { $sValue = implode(",", $sValue); } $sQuery .= urlencode($sKey) . "=" . urlencode($sValue); } $sResult .= "?" . $sQuery; } return $sResult; }