示例#1
0
 function parseJFRule($router, &$uri)
 {
     //echo "got here too lang = ".$uri->getVar("lang","")."<br/>";
     $route = $uri->getPath();
     $conf = JFactory::getConfig();
     $params = $conf->getValue("jfrouter.params");
     $sefordomain = $params->get("sefordomain", "sefprefix");
     if ($sefordomain == "domain") {
         $host = $uri->getHost();
         // TODO cache the indexed array
         $rawsubdomains = $params->getValue("sefsubdomain", array());
         $subdomains = array();
         $jfm = JoomFishManager::getInstance();
         $langs = $jfm->getLanguagesIndexedById();
         foreach ($rawsubdomains as $domain) {
             list($langid, $domain) = explode("::", $domain, 2);
             // if you have inactive languages and are not logged in then skip inactive language
             if (!array_key_exists($langid, $langs)) {
                 continue;
             }
             $domain = strtolower(str_replace("http://", "", $domain));
             $domain = str_replace("https://", "", $domain);
             $domain = preg_replace("#/\$#", "", $domain);
             //$domain = str_replace("/","",$domain);
             $subdomains[$domain] = $langs[$langid]->shortcode;
         }
         if (array_key_exists($host, $subdomains)) {
             $lang = $subdomains[$host];
             // This get over written later - really stupid !!!
             $uri->setVar("lang", $lang);
             JRequest::setVar('lang', $lang);
             // I need to discover language here since menu is loaded in router
             plgSystemJFRouter::_discoverJFLanguage();
             $config = JFactory::getConfig();
             // TODO fix this for HTTPS
             $config->setValue('config.live_site', "http://" . $host);
             $config->setValue("joomfish.current_host", $host);
             return array("lang" => $lang);
         }
     } else {
         // Consider stripping base path from URI
         /*
         $live_site = JURI::base();
         $livesite_uri = new JURI($live_site);
         $livesite_path = $livesite_uri->getPath();
         $route = str_replace($livesite_path,"",$route);
         */
         $jfm = JoomFishManager::getInstance();
         $langs = $jfm->getLanguagesIndexedById();
         $sefprefixes = $params->getValue("sefprefixes", array());
         // Workaround if some language prefixes are missing
         if (!is_array($sefprefixes)) {
             $sefprefixes = array();
         }
         if (count($sefprefixes) < count($langs)) {
             foreach ($sefprefixes as $prefix) {
                 list($langid, $prefix) = explode("::", $prefix, 2);
                 if (array_key_exists($langid, $langs)) {
                     $langs[$langid]->hasprefix = true;
                 }
             }
             foreach ($langs as $lang) {
                 if (!isset($lang->hasprefix)) {
                     $sefprefixes[] = $lang->lang_id . "::" . $lang->sef;
                 }
             }
         }
         $segments = explode('/', $route);
         $seg = 0;
         while ($seg < count($segments)) {
             if (strlen($segments[$seg]) == 0) {
                 $seg++;
                 continue;
             }
             foreach ($sefprefixes as $prefix) {
                 list($langid, $prefix) = explode("::", $prefix, 2);
                 // explode off any suffix
                 if (strpos($segments[$seg], ".") > 0) {
                     $segcompare = substr($segments[$seg], 0, strpos($segments[$seg], "."));
                     // Trap for pdf, feed of html info in the extension
                     if (strpos($segments[$seg], $prefix . ".") === 0) {
                         $format = str_replace($prefix . ".", "", $segments[$seg]);
                         //$uri->setVar("format",$format);
                         //JRequest::setVar('format', $format);
                     }
                 } else {
                     $segcompare = $segments[$seg];
                 }
                 // including fix for suffix based url's and feeds
                 if ($conf->getValue('sef_suffix') == 1 && $conf->getValue('sef_rewrite') == 1 && $conf->getValue('sef')) {
                     for ($l = 0; $l < count($segments); $l++) {
                         if (!empty($segments[$l])) {
                             $format = explode(".", $segments[$l]);
                             if (!empty($format[1]) && trim($format[1]) !== "" && trim($format[1]) !== "php") {
                                 $uri->setVar("format", $format[1]);
                                 JRequest::setVar('format', $format[1]);
                                 break;
                             }
                         }
                     }
                 }
                 // does the segment match the prefix
                 if ($segcompare == $prefix) {
                     // This section forces the current url static to include the language string which means the base tag is correct - but ONLY on the home page
                     // restricting this to the homepage means no risk for image paths etc.
                     $homepage = true;
                     for ($seg2 = $seg + 1; $seg2 < count($segments); $seg2++) {
                         $segment = $segments[$seg2];
                         if (strlen($segment) > 0) {
                             $homepage = false;
                         }
                     }
                     if ($homepage) {
                         $current = JURI::current();
                         $uri = JURI::getInstance();
                         $current = $uri->toString(array('scheme', 'host', 'port', 'path'));
                     }
                     unset($segments[$seg]);
                     //array_shift($segments);
                     $uri->setPath(implode("/", $segments));
                     $lang = $langs[$langid]->shortcode;
                     // This get over written later - really stupid !!!
                     $uri->setVar("lang", $lang);
                     JRequest::setVar('lang', $lang);
                     // I need to discover language here since menu is loaded in router
                     plgSystemJFRouter::_discoverJFLanguage();
                     return array("lang" => $lang);
                 }
             }
             $seg++;
         }
     }
     plgSystemJFRouter::_discoverJFLanguage();
     return array();
 }
示例#2
0
 public function routeJFRule($router, &$uri)
 {
     jimport('joomla.html.parameter');
     $registry = JFactory::getConfig();
     $multilingual_support = $registry->getValue("config.multilingual_support", false);
     $jfLang = $registry->getValue("joomfish_language", false);
     $jfm = JoomFishManager::getInstance();
     $langs = $jfm->getLanguagesIndexedById();
     if ($multilingual_support && $jfLang) {
         if ($uri->getVar("lang", "") == "") {
             $uri->setVar("lang", $jfLang->shortcode != '' ? $jfLang->shortcode : $jfLang->iso);
         }
         // this is dependent on Joomfish router being first!!
         $lang = $uri->getVar("lang", "");
         // This may not ready at this stage
         $params = $registry->getValue("jfrouter.params");
         // so load plugin parameters directly
         if (is_null($params)) {
             $params = JPluginHelper::getPlugin("system", "jfrouter");
             $params = new JRegistry($params->params);
         }
         $sefordomain = $params->get("sefordomain", "sefprefix");
         if ($sefordomain == "domain") {
             // If I set config_live_site I actually don't need this function at all let alone this logic ?  Apart from language switcher.
             // TODO cache the indexed array
             $rawsubdomains = $params->getValue("sefsubdomain", array());
             $subdomains = array();
             foreach ($rawsubdomains as $domain) {
                 list($langid, $domain) = explode("::", $domain, 2);
                 $domain = strtolower(str_replace("http://", "", $domain));
                 $domain = str_replace("https://", "", $domain);
                 $domain = preg_replace("#/\$#", "", $domain);
                 //$domain = str_replace("/","",$domain);
                 $subdomains[$langs[$langid]->shortcode] = $domain;
             }
             if (array_key_exists($lang, $subdomains)) {
                 $uri->setHost($subdomains[$lang]);
                 $uri->delVar("lang");
                 $registry->setValue("joomfish.sef_host", $subdomains[$lang]);
                 plgSystemJFRouter::procesCustomBuildRule($router, $uri);
                 return;
             }
         } else {
             // Get the path data
             $route = $uri->getPath();
             //Add the suffix to the uri
             if ($router->getMode() == JROUTER_MODE_SEF && $route && !$lang !== "") {
                 $jfLang = $jfm->getLanguageByShortcode($lang);
                 if (!$jfLang) {
                     return;
                 }
                 $sefprefixes = $params->getValue("sefprefixes", array());
                 // Workaround if some language prefixes are missing
                 if (!is_array($sefprefixes)) {
                     $sefprefixes = array();
                 }
                 if (count($sefprefixes) < count($langs)) {
                     foreach ($sefprefixes as $prefix) {
                         list($langid, $prefix) = explode("::", $prefix, 2);
                         if (array_key_exists($langid, $langs)) {
                             $langs[$langid]->hasprefix = true;
                         }
                     }
                     foreach ($langs as $lang) {
                         if (!isset($lang->hasprefix)) {
                             $sefprefixes[] = $lang->lang_id . "::" . $lang->sef;
                         }
                     }
                 }
                 foreach ($sefprefixes as $prefix) {
                     list($langid, $prefix) = explode("::", $prefix, 2);
                     if ($jfLang->lang_id == $langid) {
                         $uri->setPath($uri->getPath() . "/" . $prefix);
                         $uri->delVar("lang");
                         plgSystemJFRouter::procesCustomBuildRule($router, $uri);
                         return;
                     }
                 }
             }
         }
     }
     return;
 }