private function checkPass(&$home, $addlang = 0) { $uri = JUri::getInstance(); if ($addlang) { $sef = $uri->getVar('lang'); if (empty($sef)) { $langs = array_keys(JLanguageHelper::getLanguages('sef')); $path = RLString::substr($uri->toString(array('scheme', 'user', 'pass', 'host', 'port', 'path')), RLString::strlen($uri->base())); $path = preg_replace('#^index\\.php/?#', '', $path); $parts = explode('/', $path); $part = reset($parts); if (in_array($part, $langs)) { $sef = $part; } } if (empty($sef)) { return false; } } $query = $uri->toString(array('query')); if (strpos($query, 'option=') === false && strpos($query, 'Itemid=') === false) { $url = $uri->toString(array('host', 'path')); } else { $url = $uri->toString(array('host', 'path', 'query')); } // remove the www. $url = preg_replace('#^www\\.#', '', $url); // replace ampersand chars $url = str_replace('&', '&', $url); // remove any language vars $url = preg_replace('#((\\?)lang=[a-z-_]*(&|$)|&lang=[a-z-_]*)#', '\\2', $url); // remove trailing nonsense $url = trim(preg_replace('#/?\\??&?$#', '', $url)); // remove the index.php/ $url = preg_replace('#/index\\.php(/|$)#', '/', $url); // remove trailing / $url = trim(preg_replace('#/$#', '', $url)); $root = JUri::root(); // remove the http(s) $root = preg_replace('#^.*?://#', '', $root); // remove the www. $root = preg_replace('#^www\\.#', '', $root); //remove the port $root = preg_replace('#:[0-9]+#', '', $root); // so also passes on urls with trailing /, ?, &, /?, etc... $root = preg_replace('#(Itemid=[0-9]*).*^#', '\\1', $root); // remove trailing / $root = trim(preg_replace('#/$#', '', $root)); if ($addlang) { $root .= '/' . $sef; } /* Pass urls: * [root] */ $regex = '#^' . $root . '$#i'; if (preg_match($regex, $url)) { return true; } /* Pass urls: * [root]?Itemid=[menu-id] * [root]/?Itemid=[menu-id] * [root]/index.php?Itemid=[menu-id] * [root]/[menu-alias] * [root]/[menu-alias]?Itemid=[menu-id] * [root]/index.php?[menu-alias] * [root]/index.php?[menu-alias]?Itemid=[menu-id] * [root]/[menu-link] * [root]/[menu-link]&Itemid=[menu-id] */ $regex = '#^' . $root . '(/(' . 'index\\.php' . '|' . '(index\\.php\\?)?' . preg_quote($home->alias, '#') . '|' . preg_quote($home->link, '#') . ')?)?' . '(/?[\\?&]Itemid=' . (int) $home->id . ')?' . '$#i'; return preg_match($regex, $url); }
/** * Creates an array of different syntaxes of titles to match against a url variable */ public static function createUrlMatches($titles = array()) { $matches = array(); foreach ($titles as $title) { $matches[] = $title; $matches[] = RLString::strtolower($title); } $matches = array_unique($matches); foreach ($matches as $title) { $matches[] = htmlspecialchars(RLText::html_entity_decoder($title)); } $matches = array_unique($matches); foreach ($matches as $title) { $matches[] = urlencode($title); $matches[] = utf8_decode($title); $matches[] = str_replace(' ', '', $title); $matches[] = trim(preg_replace('#[^a-z0-9]#i', '', $title)); $matches[] = trim(preg_replace('#[^a-z]#i', '', $title)); } $matches = array_unique($matches); foreach ($matches as $i => $title) { $matches[$i] = trim(str_replace('?', '', $title)); } $matches = array_diff(array_unique($matches), array('', '-')); return $matches; }