Skip to content

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzmg committed Sep 25, 2020
1 parent 63ac174 commit 7967a41
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions system/modules/simple_news_urls/classes/SimpleNewsUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
* @license GPL-2.0
*/

use Contao\Config;
use Contao\Controller;
use Contao\Environment;
use Contao\ModuleLoader;
use Contao\ModuleNewsReader;
use Contao\NewsArchiveModel;
use Contao\NewsModel;
use Contao\PageModel;

class SimpleNewsUrls
{
Expand All @@ -27,7 +34,7 @@ public function getPageIdFromUrl( $arrFragments )
// extract alias from fragments
$alias = null;
// handle special case with i18nl10n (see #4)
if( in_array( 'i18nl10n', \ModuleLoader::getActive() ) && count( $arrFragments ) == 3 )
if( in_array( 'i18nl10n', ModuleLoader::getActive() ) && count( $arrFragments ) == 3 )
{
if( $arrFragments[0] == null && $arrFragments[1] == 'language' )
{
Expand All @@ -44,13 +51,13 @@ public function getPageIdFromUrl( $arrFragments )
if( $alias )
{
// check if news item exists
if( ( $objNews = \NewsModel::findByAlias( $alias ) ) !== null )
if( ( $objNews = NewsModel::findByAlias( $alias ) ) !== null )
{
// check if jumpTo page exists
if( ( $objTarget = \PageModel::findWithDetails( $objNews->getRelated('pid')->jumpTo ) ) !== null )
if( ( $objTarget = PageModel::findWithDetails( $objNews->getRelated('pid')->jumpTo ) ) !== null )
{
// check if target page is in the right language
if( \Config::get('addLanguageToUrl') && $objTarget->rootLanguage != \Input::get('language') )
if( Config::get('addLanguageToUrl') && $objTarget->rootLanguage != \Input::get('language') )
{
// return fragments without change
return $arrFragments;
Expand Down Expand Up @@ -91,7 +98,7 @@ public function generateFrontendUrl($arrRow, $strParams, $strUrl)
}

// check if param is a news alias
if (null !== ($objNews = \NewsModel::findByAlias(ltrim($strParams, '/'))))
if (null !== ($objNews = NewsModel::findByAlias(ltrim($strParams, '/'))))
{
// remove the page alias from the URL
$strUrl = str_replace($arrRow['alias'] . '/', '', $strUrl);
Expand All @@ -112,7 +119,7 @@ public function generateFrontendUrl($arrRow, $strParams, $strUrl)
public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = false)
{
// get all news archives
if (null !== $objArchive = \NewsArchiveModel::findAll())
if (null !== $objArchive = NewsArchiveModel::findAll())
{
while ($objArchive->next())
{
Expand All @@ -139,7 +146,7 @@ public function getSearchablePages($arrPages, $intRoot = 0, $blnIsSitemap = fals
public function parseArticles($objTemplate, $arrArticle, $objModule)
{
// check for news module
if (!$objModule instanceof \ModuleNewsReader)
if (!$objModule instanceof ModuleNewsReader)
{
return;
}
Expand All @@ -157,15 +164,15 @@ public function parseArticles($objTemplate, $arrArticle, $objModule)
$strRequest = preg_replace('~^'.Environment::get('scriptName').'/~', '', $strRequest);

// remove language, if applicable
if (\Config::get('addLanguageToUrl'))
if (Config::get('addLanguageToUrl'))
{
$strRequest = substr($strRequest, 3);
}

// check if news alias is at the beginning of url
if (stripos(urldecode($strRequest), $arrArticle['alias']) !== 0)
{
/** @var \PageModel $objPage */
/** @var PageModel $objPage */
global $objPage;

// generate the news URL
Expand All @@ -178,7 +185,7 @@ public function parseArticles($objTemplate, $arrArticle, $objModule)
$strQuery = Environment::get('queryString') ? '?'.Environment::get('queryString') : '';

// check for redirect
$redirectType = \Config::get('simpleNewsUrlsRedirect');
$redirectType = Config::get('simpleNewsUrlsRedirect');
switch ($redirectType)
{
// insert canonical meta tag
Expand All @@ -187,8 +194,8 @@ public function parseArticles($objTemplate, $arrArticle, $objModule)
// redirect to simple URL
case 301:
case 302:
case 303: \Controller::redirect($strUrl . $strQuery, $redirectType); break;
default: \Controller::redirect($strUrl . $strQuery, 301 );
case 303: Controller::redirect($strUrl . $strQuery, $redirectType); break;
default: Controller::redirect($strUrl . $strQuery, 301 );
}
}
}
Expand Down

0 comments on commit 7967a41

Please sign in to comment.