Skip to content

Commit

Permalink
remove page path from searchable pages (fixes #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzmg committed Aug 8, 2018
1 parent ad0bf55 commit 41e4155
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
37 changes: 33 additions & 4 deletions system/modules/simple_news_urls/classes/SimpleNewsUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ public function getPageIdFromUrl( $arrFragments )
/**
* generateFrontendUrl Hook
* checks if the parameter for the generated URL is a news alias and rewrites the URL without its page alias
* @param array page data
* @param string URL parameters
* @param string current URL
* @param array page data
* @param string URL parameters
* @param string current URL
* @return string
*/
public function generateFrontendUrl($arrRow, $strParams, $strUrl)
{
Expand All @@ -93,13 +94,41 @@ public function generateFrontendUrl($arrRow, $strParams, $strUrl)
{
// remove the page alias from the URL
$strUrl = str_replace($arrRow['alias'] . '/', '', $strUrl);
}
}

// return the url
return $strUrl;
}


/**
* Remove page path from searchable pages for news entries.
* @param array $arrPages
* @param integer $intRoot
* @param boolean $blnIsSitemap
* @return array
*/
public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
{
// get all news archives
if (null !== $objArchive = \NewsArchiveModel::findAll())
{
while ($objArchive->next())
{
if ($objArchive->jumpTo && null !== ($objTarget = $objArchive->getRelated('jumpTo')))
{
foreach ($arrPages as &$page)
{
$page = str_replace($objTarget->alias . '/', '', $page);
}
}
}
}

return $arrPages;
}


/**
* parseArticles Hook to either generate a 301 redirect or a canonical URL
* to the simple news URL to prevent duplicate URLs
Expand Down
1 change: 1 addition & 0 deletions system/modules/simple_news_urls/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
$GLOBALS['TL_HOOKS']['getPageIdFromUrl'][] = array('SimpleNewsUrls','getPageIdFromUrl');
$GLOBALS['TL_HOOKS']['generateFrontendUrl'][] = array('SimpleNewsUrls','generateFrontendUrl');
$GLOBALS['TL_HOOKS']['parseArticles'][] = array('SimpleNewsUrls','parseArticles');
$GLOBALS['TL_HOOKS']['getSearchablePages'][] = array('SimpleNewsUrls', 'getSearchablePages');

// settings
$GLOBALS['TL_CONFIG']['simpleNewsUrlsRedirect'] = 301;

0 comments on commit 41e4155

Please sign in to comment.