Source for file sef.php
Documentation is available at sef.php
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Add the canonical uri to the head
if ($app->getName() !=
'site' ||
$doc->getType() !==
'html')
$router =
$app->getRouter();
$domain =
$this->params->get('domain');
if ($domain ===
null ||
$domain ===
'')
$domain =
$uri->toString(array('scheme', 'host', 'port'));
$parsed =
$router->parse($uri);
$link =
$domain .
JRoute::_($fakelink, false);
* Converting the site URL to fit to the HTTP request
if ($app->getName() !=
'site' ||
$app->getCfg('sef') ==
'0')
$buffer =
$app->getBody();
$regex =
'#href="index.php\?([^"]*)#m';
$this->checkBuffer($buffer);
$protocols =
'[a-zA-Z0-9]+:'; //To check for all unknown protocals (a protocol must contain at least one alpahnumeric fillowed by :
$regex =
'#(src|href|poster)="(?!/|' .
$protocols .
'|\#|\')([^"]*)"#m';
$this->checkBuffer($buffer);
$regex =
'#(onclick="window.open\(\')(?!/|' .
$protocols .
'|\#)([^/]+[^\']*?\')#m';
$buffer =
preg_replace($regex, '$1' .
$base .
'$2', $buffer);
$this->checkBuffer($buffer);
// ONMOUSEOVER / ONMOUSEOUT
$regex =
'#(onmouseover|onmouseout)="this.src=([\']+)(?!/|' .
$protocols .
'|\#|\')([^"]+)"#m';
$buffer =
preg_replace($regex, '$1="this.src=$2' .
$base .
'$3$4"', $buffer);
$this->checkBuffer($buffer);
$regex =
'#style\s*=\s*[\'\"](.*):\s*url\s*\([\'\"]?(?!/|' .
$protocols .
'|\#)([^\)\'\"]+)[\'\"]?\)#m';
$buffer =
preg_replace($regex, 'style="$1: url(\'' .
$base .
'$2$3\')', $buffer);
$this->checkBuffer($buffer);
// OBJECT <param name="xx", value="yy"> -- fix it only inside the <param> tag
$regex =
'#(<param\s+)name\s*=\s*"(movie|src|url)"[^>]\s*value\s*=\s*"(?!/|' .
$protocols .
'|\#|\')([^"]*)"#m';
$buffer =
preg_replace($regex, '$1name="$2" value="' .
$base .
'$3"', $buffer);
$this->checkBuffer($buffer);
// OBJECT <param value="xx", name="yy"> -- fix it only inside the <param> tag
$regex =
'#(<param\s+[^>]*)value\s*=\s*"(?!/|' .
$protocols .
'|\#|\')([^"]*)"\s*name\s*=\s*"(movie|src|url)"#m';
$buffer =
preg_replace($regex, '<param value="' .
$base .
'$2" name="$3"', $buffer);
$this->checkBuffer($buffer);
// OBJECT data="xx" attribute -- fix it only in the object tag
$regex =
'#(<object\s+[^>]*)data\s*=\s*"(?!/|' .
$protocols .
'|\#|\')([^"]*)"#m';
$buffer =
preg_replace($regex, '$1data="' .
$base .
'$2"$3', $buffer);
$this->checkBuffer($buffer);
private function checkBuffer($buffer)
case PREG_BACKTRACK_LIMIT_ERROR:
$message =
"PHP regular expression limit reached (pcre.backtrack_limit)";
case PREG_RECURSION_LIMIT_ERROR:
$message =
"PHP regular expression limit reached (pcre.recursion_limit)";
case PREG_BAD_UTF8_ERROR:
$message =
"Bad UTF8 passed to PCRE function";
$message =
"Unknown PCRE error calling PCRE function";
throw
new RuntimeException($message);
* Replaces the matched tags
* @param array &$matches An array of matches (see preg_match_all)
protected static function route(&$matches)
$route =
JRoute::_('index.php?'.
$url);
return 'href="' .
$route;
Documentation generated on Tue, 19 Nov 2013 15:12:47 +0100 by phpDocumentor 1.4.3