Example #1
0
 /**
  *@param string $strHref
  *@return string - Return the new string if exists engine:xmlnuke or module:... Otherwise returns the original value
  *@desc Replace a HREF value with XMLNuke context values.
  */
 public function GetFullLink($strHref)
 {
     $arResult = array();
     $result = "";
     $pattern = "(?:(?P<protocol>module|admin|engine):)?(?P<host>[\\w\\d\\-\\.]*)(?P<port>:\\d*)?(?:\\?(?P<param>(([\\w\\d\\W]*=[\\w\\d\\W]*)(?:&(?:amp;)?)?)*))?";
     preg_match_all("/{$pattern}/", $strHref, $arResult);
     $sep = "?";
     switch ($arResult["protocol"][0]) {
         case "engine":
             if ($arResult["host"][0] == "xmlnuke") {
                 $result = $this->_context->UrlXmlnukeEngine() . $arResult["port"][0];
             } else {
                 $result = "Unknow Engine " . $arResult["host"][0];
             }
             break;
         case "module":
             if ($arResult['host'][0] == '__self__') {
                 $result = $this->_context->UrlModule() . $arResult["port"][0] . "?module=" . $this->_context->getModule();
             } else {
                 $result = $this->_context->UrlModule() . $arResult["port"][0] . "?module=" . $arResult["host"][0];
             }
             $sep = "&";
             break;
         case "admin":
             if ($arResult["host"] == "engine") {
                 $result = $this->_context->UrlXmlNukeAdmin() . $arResult["port"][0];
             } else {
                 $result = $this->_context->UrlModule() . $arResult["port"][0] . "?module=" . (strpos($arResult["host"][0], ".") === false ? "Xmlnuke.Admin." : "") . $arResult["host"][0];
                 $sep = "&";
             }
             break;
         default:
             return $strHref;
     }
     $arParam = array();
     $xmlnukeParam = array();
     $fullLink = $this->_context->get("xmlnuke.USEFULLPARAMETER") == "true";
     if ($fullLink || $this->_context->getXsl() != $this->_context->get("xmlnuke.DEFAULTPAGE")) {
         $xmlnukeParam["xsl"] = $this->_context->getXsl() == "index" ? $this->_context->get("xmlnuke.DEFAULTPAGE") : $this->_context->getXsl();
     }
     if ($fullLink) {
         $xmlnukeParam["xml"] = $this->_context->getXml();
     }
     if ($fullLink || array_key_exists("lang", $_REQUEST) && $_REQUEST["lang"] == strtolower($this->_context->Language()->getName())) {
         $xmlnukeParam["lang"] = strtolower($this->_context->Language()->getName());
     }
     $paramsTmp = explode("&", str_replace("&amp;", "&", $arResult["param"][0]));
     foreach ($paramsTmp as $value) {
         $arTmp = explode("=", $value);
         switch ($arTmp[0]) {
             case "xml":
             case "xsl":
             case "lang":
                 $xmlnukeParam[$arTmp[0]] = $arTmp[1];
                 break;
             default:
                 if ($value != "") {
                     $arParam[] = $value;
                 }
         }
     }
     $strParam = implode("&", $arParam);
     $arParam2 = array();
     foreach ($xmlnukeParam as $key => $value) {
         $arParam2[] = $key . "=" . $value;
     }
     $strParam2 = implode("&", $arParam2);
     $paramsFinal = $strParam2 . (!empty($strParam2) && !empty($strParam) ? "&" : "") . $strParam;
     return $this->_context->VirtualPathAbsolute($result . ($paramsFinal != "" ? $sep . $paramsFinal : ""));
 }