Skip to content

Commit

Permalink
do not add newsreader selection in newer contao versions (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzmg committed Sep 30, 2020
1 parent 8a823bb commit f2b94d7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 11 deletions.
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
}
],
"require": {
"php": ">=5.4",
"php": ">=7.1",
"contao/core-bundle": "^3.0 || ^4.0",
"contao-community-alliance/composer-plugin": "^2.4 || ^3.0"
"contao-community-alliance/composer-plugin": "^2.4 || ^3.0",
"jean85/pretty-package-versions": "^1.0"
},
"extra": {
"contao": {
Expand Down
33 changes: 29 additions & 4 deletions system/modules/newslist_extended/classes/NewslistExtended.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@

namespace NewslistExtended;

use Contao\Config;
use Contao\Controller;
use Contao\CoreBundle\ContaoCoreBundle;
use Contao\Environment;
use Contao\PageModel;
use Jean85\PrettyVersions;

class NewslistExtended
{
/**
Expand Down Expand Up @@ -57,10 +64,10 @@ public function parseArticles($objTemplate, $arrArticle, $objModule)
if ($objModule->type == 'newsreader')
{
// get the current uri
$strCurrentUri = \Environment::get('uri');
$strCurrentUri = Environment::get('uri');

// get the canonical uri
$strCanonicalUri = (strpos($objTemplate->link, 'http') !== 0 ? \Environment::get('base') : '') . $objTemplate->link;
$strCanonicalUri = (strpos($objTemplate->link, 'http') !== 0 ? Environment::get('base') : '') . $objTemplate->link;

// check if Uris are the same
if ($strCurrentUri != $strCanonicalUri)
Expand All @@ -77,10 +84,10 @@ public function parseArticles($objTemplate, $arrArticle, $objModule)
if ('default' === $arrArticle['source']
&& $objModule->news_overrideRedirect
&& $objModule->jumpTo
&& null !== ($objTarget = \PageModel::findById($objModule->jumpTo)))
&& null !== ($objTarget = PageModel::findById($objModule->jumpTo)))
{
// build the href
$strHref = \Controller::generateFrontendUrl($objTarget->row(), ((\Config::get('useAutoItem') && !\Config::get('disableAlias')) ? '/' : '/items/') . ((!\Config::get('disableAlias') && $arrArticle['alias'] != '') ? $arrArticle['alias'] : $arrArticle['id']), $objTarget->rootLanguage, true);
$strHref = Controller::generateFrontendUrl($objTarget->row(), ((Config::get('useAutoItem') && !Config::get('disableAlias')) ? '/' : '/items/') . ((!Config::get('disableAlias') && $arrArticle['alias'] != '') ? $arrArticle['alias'] : $arrArticle['id']), $objTarget->rootLanguage, true);

// encode href
$strHref = ampersand($strHref);
Expand All @@ -91,4 +98,22 @@ public function parseArticles($objTemplate, $arrArticle, $objModule)
$objTemplate->more = $this->generateNewsLink( $strHref, $arrArticle['headline'], $GLOBALS['TL_LANG']['MSC']['more'], true);
}
}

/**
* Checks whether to add the newsreader feature.
*/
public static function addNewsReader(): bool
{
if (!class_exists(ContaoCoreBundle::class)) {
return true;
}

try {
$contaoVersion = PrettyVersions::getVersion('contao/core-bundle');
} catch (\OutOfBoundsException $e) {
$contaoVersion = PrettyVersions::getVersion('contao/contao');
}

return version_compare($contaoVersion->getShortVersion(), '4.7.0', '<');
}
}
1 change: 1 addition & 0 deletions system/modules/newslist_extended/config/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @copyright Fritz Michael Gschwantner 2017
*/

use Contao\ClassLoader;

/**
* Register the namespace
Expand Down
8 changes: 6 additions & 2 deletions system/modules/newslist_extended/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@
* @copyright Fritz Michael Gschwantner 2017
*/

use NewslistExtended\ModuleNewsList;
use NewslistExtended\NewslistExtended;

/**
* Hooks
*/
$GLOBALS['TL_HOOKS']['parseArticles'][] = array('NewslistExtended\NewslistExtended','parseArticles');
$GLOBALS['TL_HOOKS']['parseArticles'][] = [NewslistExtended::class, 'parseArticles'];

/**
* Frontend modules
*/
$GLOBALS['FE_MOD']['news']['newslist'] = \NewslistExtended\ModuleNewsList::class;
if (NewslistExtended::addNewsReader()) {
$GLOBALS['FE_MOD']['news']['newslist'] = ModuleNewsList::class;
}
7 changes: 6 additions & 1 deletion system/modules/newslist_extended/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@


$GLOBALS['TL_DCA']['tl_module']['palettes']['__selector__'][] = 'news_overrideRedirect';
$GLOBALS['TL_DCA']['tl_module']['palettes']['newslist'] = str_replace(';{template_legend', ',news_readerModule;{redirect_legend},news_overrideRedirect;{template_legend', $GLOBALS['TL_DCA']['tl_module']['palettes']['newslist']);

if (stripos($GLOBALS['TL_DCA']['tl_module']['palettes']['newslist'], ',news_readerModule,') === false) {
$GLOBALS['TL_DCA']['tl_module']['palettes']['newslist'] = str_replace(';{template_legend', ',news_readerModule;{template_legend', $GLOBALS['TL_DCA']['tl_module']['palettes']['newslist']);
}

$GLOBALS['TL_DCA']['tl_module']['palettes']['newslist'] = str_replace(';{template_legend', ';{redirect_legend},news_overrideRedirect;{template_legend', $GLOBALS['TL_DCA']['tl_module']['palettes']['newslist']);
$GLOBALS['TL_DCA']['tl_module']['subpalettes']['news_overrideRedirect'] = 'jumpTo';

$GLOBALS['TL_DCA']['tl_module']['fields']['news_overrideRedirect'] = array
Expand Down
7 changes: 5 additions & 2 deletions system/modules/newslist_extended/modules/ModuleNewsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

namespace NewslistExtended;

use Contao\Config;
use Contao\Controller;

if (class_exists('\Codefog\NewsCategoriesBundle\FrontendModule\NewsListModule')) {
class ParentModuleNewsList extends \Codefog\NewsCategoriesBundle\FrontendModule\NewsListModule {}
} elseif (class_exists('\NewsCategories\ModuleNewsList')) {
Expand All @@ -37,9 +40,9 @@ public function generate()
}

// Show the news reader if an item has been selected
if ($this->news_readerModule > 0 && (isset($_GET['items']) || (\Config::get('useAutoItem') && isset($_GET['auto_item']))))
if ($this->news_readerModule > 0 && (isset($_GET['items']) || (Config::get('useAutoItem') && isset($_GET['auto_item']))))
{
return \Controller::getFrontendModule($this->news_readerModule, $this->strColumn);
return Controller::getFrontendModule($this->news_readerModule, $this->strColumn);
}

return parent::generate();
Expand Down

0 comments on commit f2b94d7

Please sign in to comment.