Skip to content

Commit

Permalink
trim and perf
Browse files Browse the repository at this point in the history
Trimming suffix and prefix, performance improvement
#30
  • Loading branch information
bednee committed Aug 25, 2015
1 parent c5408a9 commit c1e294a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Classes/Core/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public static function prepareforOutput($path,$lConf) {
$path = (string)$lConf->urlprefix.$path;
}
if (self::excludeInclude($path,$lConf->urlsuffix)) {
$path .= (string)$lConf->urlsuffix;
$suffix = (string)$lConf->urlsuffix;
$path .= trim($suffix);
}
return $path;
}
Expand Down Expand Up @@ -452,10 +453,12 @@ public static function specCharsToASCII($title) {

public static function prepareLinkForCache($path,$lConf) {
if (!empty($lConf->cache->prefix)) {
$path = ($lConf->cache->prefix).$path;
$prefix = (string)$lConf->cache->prefix;
$path = trim($prefix).$path;
}
if (!empty($lConf->cache->suffix)) {
$path .= ($lConf->cache->suffix);
$suffix = (string)$lConf->cache->suffix;
$path .= trim($suffix);
}
if (!empty($lConf->removetrailingslash) && $lConf->removetrailingslash==1) {
$temppath = self::removeSlash($path);
Expand Down
8 changes: 6 additions & 2 deletions Classes/Core/Translate.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ private function removeUriParts($uri) {
private function removeFixes($uri) {
$temp = explode('?',$uri);
if (!empty(self::$conf->urlsuffix)) {
$temp[0] = preg_replace('~'.Functions::addregexpslashes((string)self::$conf->urlsuffix).'$~','',$temp[0]);
$suffix = (string)self::$conf->urlsuffix;
$suffix = trim($suffix);
$temp[0] = preg_replace('~'.Functions::addregexpslashes($suffix).'$~','',$temp[0]);
}
if (!empty(self::$conf->urlprefix)) {
$temp[0] = preg_replace('~^'.Functions::addregexpslashes((string)self::$conf->urlprefix).'~','',$temp[0]);
$prefix = (string)self::$conf->urlprefix;
$prefix = trim($prefix);
$temp[0] = preg_replace('~^'.Functions::addregexpslashes($prefix).'~','',$temp[0]);
}
$uri = implode('?',$temp);
return $uri;
Expand Down
8 changes: 8 additions & 0 deletions Classes/Integration/CoolUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ public static function findDomainGroup($domain)

public static function getDomain($id)
{
static $domains = array();
if (isset($domains[$id])) {
return $domains[$id];
}

\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Getting domain for ' . $id, 'CoolUri');
if ($GLOBALS['TSFE']->showHiddenPage || self::isBEUserLoggedIn()) {
$enable = ' AND pages.deleted=0';
Expand All @@ -388,6 +393,7 @@ public static function getDomain($id)
if ($page['domainName'] && !$page['redirectTo']) {
$resDom = preg_replace('~^.*://(.*)/?$~', '\\1', preg_replace('~/$~', '', $page['domainName']));
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Resolved domain: ' . $resDom, 'CoolUri');
$domains[$id] = $resDom;
return $resDom;
}

Expand All @@ -399,6 +405,7 @@ public static function getDomain($id)

if ($page['is_siteroot'] == 1 || $count['num'] > 0) {
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Domain missing for ID ' . $id . ', using HTTP_HOST ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'), 'CoolUri');
$domains[$id] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
return \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
}

Expand All @@ -407,6 +414,7 @@ public static function getDomain($id)
--$max;
}
\TYPO3\CMS\Core\Utility\GeneralUtility::devLog('Domain not found, using HTTP_HOST ' . \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST'), 'CoolUri', 2);
$domains[$id] = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
return \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('HTTP_HOST');
}

Expand Down

0 comments on commit c1e294a

Please sign in to comment.