Skip to content

Commit

Permalink
Support newer banner versions (#14)
Browse files Browse the repository at this point in the history
* support newer banner versions

* update deps

* refactoring and adjustments

* fix error

* fixes for BannerTemplate

* added missing dependency
  • Loading branch information
koertho authored Aug 24, 2022
1 parent 8831e41 commit 716ceaa
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 89 deletions.
20 changes: 6 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,16 @@
"issues":"https://github.com/heimrichhannot/contao-banner_plus/issues"
},
"require": {
"php": "~7.1",
"contao/core-bundle": "~4.4",
"bugbuster/contao-banner-bundle": "1.0.10.*",
"heimrichhannot/contao-mediaquery": "^1.1"
"php": "^7.2 || ^8.0",
"contao/core-bundle": "~4.9",
"bugbuster/contao-banner-bundle": ">=1.0.11 <1.4",
"heimrichhannot/contao-mediaquery": "^1.1",
"heimrichhannot/contao-utils-bundle": "^2.218"
},
"autoload": {
"psr-4": {
"HeimrichHannot\\BannerPlusBundle\\": "src/"
},
"classmap": [
"src/Resources/contao/"
],
"exclude-from-classmap": [
"src/Resources/contao/config/",
"src/Resources/contao/dca/",
"src/Resources/contao/languages/",
"src/Resources/contao/templates/"
]
}
},
"extra": {
"contao-manager-plugin": "HeimrichHannot\\BannerPlusBundle\\ContaoManager\\Plugin"
Expand Down
1 change: 0 additions & 1 deletion src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ public function getBundles(ParserInterface $parser)
public function registerContainerConfiguration(LoaderInterface $loader, array $managerConfig)
{
$loader->load('@ContaoBannerPlusBundle/Resources/config/services.yml');
$loader->load('@ContaoBannerPlusBundle/Resources/config/listeners.yml');
}
}
1 change: 0 additions & 1 deletion src/EventListener/CompileSlickNewsListListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class CompileSlickNewsListListener
*/
public function onCompileSlickNewsList(&$objTemplate, $frontendModule, $objModel)
{

$slickBannerGenerator = new SlickBannerTemplate();
$slickBannerGenerator->generateSlickBanner($objTemplate, $frontendModule, $objModel);
}
Expand Down
17 changes: 12 additions & 5 deletions src/EventListener/InitializeSystemListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@
namespace HeimrichHannot\BannerPlusBundle\EventListener;


use Contao\System;
use HeimrichHannot\UtilsBundle\Container\ContainerUtil;
use Contao\CoreBundle\ServiceAnnotation\Hook;
use HeimrichHannot\UtilsBundle\Util\Utils;

/**
* @Hook("initializeSystem")
*/
class InitializeSystemListener
{
private Utils $utils;

public function __construct(Utils $utils)
{
$this->utils = $utils;
}

/**
* @Hook("initializeSystem")
Expand All @@ -42,9 +51,7 @@ public function onInitializeSystem()

private function addBackendAssets()
{
$containerUtil = System::getContainer()->get(ContainerUtil::class);

if ($containerUtil->isBackend()) {
if ($this->utils->container()->isBackend()) {
$GLOBALS['TL_JAVASCRIPT']['be_bannerplusbundle'] = 'bundles/contaobannerplus/assets/contao-banner-plus-bundle-be.js|static';
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/EventListener/LoadDataContainerListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
namespace HeimrichHannot\BannerPlusBundle\EventListener;


use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\ModuleLoader;
use HeimrichHannot\BannerPlusBundle\Type\HtmlType;

/**
* @Hook("loadDataContainer")
*/
class LoadDataContainerListener
{

/**
* @Hook("loadDataContainer")
*/
public function onLoadDataContainer(string $table): void
public function __invoke(string $table): void
{
switch ($table) {
case 'tl_module':
Expand All @@ -33,7 +33,7 @@ public function onLoadDataContainer(string $table): void
}
}

public function updateModuleDataContainer()
public function updateModuleDataContainer(): void
{
$dc = &$GLOBALS['TL_DCA']['tl_module'];
$active = ModuleLoader::getActive();
Expand All @@ -47,7 +47,7 @@ public function updateModuleDataContainer()
}
}

public function updateBannerDataContainer(string $table)
public function updateBannerDataContainer(string $table): void
{
$dca = &$GLOBALS['TL_DCA'][$table];
$options = HtmlType::BANNER_TYPES;
Expand Down
3 changes: 0 additions & 3 deletions src/EventListener/ReplaceInsertTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@

class ReplaceInsertTagsListener
{
/**
* @Hook("replaceInsertTags")
*/
public function onReplaceInsertTags(string $insertTag)
{
$bannerGenerator = new BannerTemplate();
Expand Down
6 changes: 0 additions & 6 deletions src/Resources/config/listeners.yml

This file was deleted.

4 changes: 4 additions & 0 deletions src/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ services:
public: true
autowire: true

HeimrichHannot\BannerPlusBundle\:
resource: '../../{EventListener}/*'
autoconfigure: true

HeimrichHannot\BannerPlusBundle\Type\HtmlType: ~
3 changes: 0 additions & 3 deletions src/Resources/contao/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
*/


$GLOBALS['TL_HOOKS']['initializeSystem']['huh_banner_plus'] = [\HeimrichHannot\BannerPlusBundle\EventListener\InitializeSystemListener::class, 'onInitializeSystem'];
$GLOBALS['TL_HOOKS']['loadDataContainer']['huh_banner_plus'] = [\HeimrichHannot\BannerPlusBundle\EventListener\LoadDataContainerListener::class, 'onLoadDataContainer'];

$GLOBALS['TL_MODELS']['tl_banner'] = \HeimrichHannot\BannerPlusBundle\Model\BannerModel::class;
$GLOBALS['TL_MODELS']['tl_banner_category'] = \HeimrichHannot\BannerPlusBundle\Model\BannerCategoryModel::class;

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<?php if ($banner['banner_pic']) : ?>
<figure class="banner_fireplace_ad banner_wrap<?php echo $banner['banner_wrap_class']; ?>"<?php echo $banner['banner_wrap_id']; ?>>
<div class="banner_image" id="banner_<?php echo $banner['banner_id']; ?>">
<?php if ($banner['banner_url']): ?><a class="clean" href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key'].$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_comment']; ?>"><?php endif; ?>
<?php if ($banner['banner_url']): ?><a class="clean" href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_comment']; ?>"><?php endif; ?>
<?php $this->insert('picture_default', $banner['picture']) ?>
<?php if ($banner['banner_pic_left']) : ?>
<?php $this->insert('picture_default', $banner['picture_left']) ?>
Expand All @@ -24,7 +24,7 @@
<?php if ($banner['banner_flash']) : ?>
<figure class="banner_wrap<?php echo $banner['banner_wrap_class']; ?>"<?php echo $banner['banner_wrap_id']; ?>>
<div class="banner_flash block" style="height:<?php echo $banner['swf_height']; ?>px; width:<?php echo $banner['swf_width']; ?>px;">
<?php if ($banner['banner_url']): ?><a href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key'].$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_comment']; ?>" ><?php endif; ?>
<?php if ($banner['banner_url']): ?><a href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_comment']; ?>" ><?php endif; ?>
<span id="swf_<?php echo $banner['swf_id']; ?>">
<?php echo $banner['fallback_content']; ?>
</span>
Expand All @@ -50,9 +50,9 @@
<?php if ($banner['banner_text']) : ?>
<figure class="banner_wrap<?php echo $banner['banner_wrap_class']; ?>"<?php echo $banner['banner_wrap_id']; ?>>
<div class="banner_text" id="banner_<?php echo $banner['banner_id']; ?>">
<div class="banner_text_name"><?php if ($banner['banner_url']): ?><a href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key'].$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_name']; ?>" ><?php endif; ?><?php echo $banner['banner_name']; ?><?php if ($banner['banner_url']): ?></a><?php endif; ?></div>
<div class="banner_text_name"><?php if ($banner['banner_url']): ?><a href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_name']; ?>" ><?php endif; ?><?php echo $banner['banner_name']; ?><?php if ($banner['banner_url']): ?></a><?php endif; ?></div>
<div class="banner_text_comment"><?php echo $banner['banner_comment']; ?></div>
<?php if ($banner['banner_url']): ?><div class="banner_text_url"><a href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key'].$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_name']; ?>" ><?php echo $banner['banner_url_kurz']; ?></a></div><?php endif; ?>
<?php if ($banner['banner_url']): ?><div class="banner_text_url"><a href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?> title="<?php echo $banner['banner_name']; ?>" ><?php echo $banner['banner_url_kurz']; ?></a></div><?php endif; ?>
</div>
</figure>
<?php endif; ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<figure class="banner_high_impact_ad banner-<?= ($banner['banner_animation'] == 'left')?'left':'top'; ?> banner_wrap<?php echo $banner['banner_wrap_class']; ?>"<?php echo $banner['banner_wrap_id']; ?>>
<div class="banner_image slide-<?php if ($banner['banner_animation'] == 'left'): echo 'left'; elseif ($banner['banner_animation'] == 'top'): echo 'top'; else: echo 'left';endif; ?>" id="banner_<?php echo $banner['banner_id']; ?>">
<div class="ad-close-button" id="closeAd" onclick=document.getElementById("banner_<?php echo $banner['banner_id']; ?>").classList.add("hide")>x</div>
<?php if ($banner['banner_url']): ?><a class="clean" href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key']
. $banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
<?php if ($banner['banner_url']): ?><a class="clean" href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
title="<?php echo $banner['banner_comment']; ?>"><?php endif; ?>
<?php $this->insert('picture_default', $banner['picture']) ?>
<?php if ($banner['banner_url']): ?></a><?php endif; ?>
Expand All @@ -21,8 +20,7 @@
<?php if ($banner['banner_flash']) : ?>
<figure class="banner_wrap<?php echo $banner['banner_wrap_class']; ?>"<?php echo $banner['banner_wrap_id']; ?>>
<div class="banner_flash block" style="height:<?php echo $banner['swf_height']; ?>px; width:<?php echo $banner['swf_width']; ?>px;">
<?php if ($banner['banner_url']): ?><a href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key']
. $banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
<?php if ($banner['banner_url']): ?><a href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
title="<?php echo $banner['banner_comment']; ?>"><?php endif; ?>
<span id="swf_<?php echo $banner['swf_id']; ?>">
<?php echo $banner['fallback_content']; ?>
Expand Down Expand Up @@ -51,14 +49,12 @@
<figure class="banner_wrap<?php echo $banner['banner_wrap_class']; ?>"<?php echo $banner['banner_wrap_id']; ?>>
<div class="banner_text" id="banner_<?php echo $banner['banner_id']; ?>">
<div class="banner_text_name"><?php if ($banner['banner_url']): ?><a
href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key']
. $banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
title="<?php echo $banner['banner_name']; ?>"><?php endif; ?><?php echo $banner['banner_name']; ?><?php if ($banner['banner_url']): ?></a><?php endif; ?>
</div>
<div class="banner_text_comment"><?php echo $banner['banner_comment']; ?></div>
<?php if ($banner['banner_url']): ?>
<div class="banner_text_url"><a href="system/modules/banner/public/conban_clicks.php?<?php echo $banner['banner_key']
. $banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
<div class="banner_text_url"><a href="<?= $this->route('bugbuster_banner_frontend_clicks') ?>/<?php echo $banner['banner_key'].'/'.$banner['banner_id']; ?>" <?php echo $banner['banner_target']; ?>
title="<?php echo $banner['banner_name']; ?>"><?php echo $banner['banner_url_kurz']; ?></a>
</div><?php endif; ?>
</div>
Expand Down
56 changes: 21 additions & 35 deletions src/Template/BannerTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BannerTemplate extends BannerInsertTag
* @param integer $moduleId
* @return boolean
*/
protected function getModuleData($moduleId)
protected function getModuleData($moduleId, array $allowedType = ['banner']): bool
{
$this->module_id = $moduleId; //for RandomBlocker Session
$objBannerModule = Database::getInstance()->prepare("SELECT
Expand All @@ -41,13 +41,14 @@ protected function getModuleData($moduleId)
banner_redirect,
banner_useragent,
cssID,
headline
headline,
type
FROM
tl_module
WHERE
id=?")
->execute($moduleId);
if ($objBannerModule->numRows == 0) {
if ($objBannerModule->numRows == 0 || !in_array($objBannerModule->type, $allowedType)) {
return false;
}
$this->banner_hideempty = $objBannerModule->banner_hideempty;
Expand All @@ -69,24 +70,21 @@ protected function getModuleData($moduleId)
protected function generateBanner()
{
//DEBUG log_message('generateBanner banner_categories:'.$this->banner_categories,'Banner.log');
if ($this->bannerHelperInit() === false)
{
if ($this->bannerHelperInit() === false) {
BannerLog::log('Problem in bannerHelperInit', 'ModuleBannerTag generateBanner', TL_ERROR);
return false;
}

if ($this->statusBannerFrontendGroupView === false)
{
if ($this->statusBannerFrontendGroupView === false) {
// Eingeloggter FE Nutzer darf nichts sehen, falsche Gruppe
// auf Leer umschalten
$this->strTemplate='mod_banner_empty';
$this->Template = new \FrontendTemplate($this->strTemplate);
$this->strTemplate = 'mod_banner_empty';
$this->Template = new \FrontendTemplate($this->strTemplate);
return $this->Template->parse();
}
$this->Template = new \FrontendTemplate($this->strTemplate);

if ($this->statusAllBannersBasic === false)
{
if ($this->statusAllBannersBasic === false) {
//keine Banner vorhanden in der Kategorie
//default Banner holen
//kein default Banner, ausblenden wenn leer?
Expand All @@ -99,19 +97,16 @@ protected function generateBanner()

//OK, Banner vorhanden, dann weiter
//BannerSeen vorhanden? Dann beachten.
if ( count(BannerHelper::$arrBannerSeen) ) //TODO
if (count(BannerHelper::$arrBannerSeen)) //TODO
{
//$arrAllBannersBasic dezimieren um die bereits angezeigten
foreach (BannerHelper::$arrBannerSeen as $BannerSeenID)
{
if (array_key_exists($BannerSeenID,$this->arrAllBannersBasic))
{
foreach (BannerHelper::$arrBannerSeen as $BannerSeenID) {
if (array_key_exists($BannerSeenID, $this->arrAllBannersBasic)) {
unset($this->arrAllBannersBasic[$BannerSeenID]);
};
}
//noch Banner übrig?
if ( count($this->arrAllBannersBasic) == 0 )
{
if (count($this->arrAllBannersBasic) == 0) {
//default Banner holen
//kein default Banner, ausblenden wenn leer?
$this->getDefaultBanner();
Expand All @@ -123,29 +118,23 @@ protected function generateBanner()

//OK, noch Banner übrig, weiter gehts
//Single Banner?
if ($this->arrCategoryValues['banner_numbers'] != 1)
{
if ($this->arrCategoryValues['banner_numbers'] != 1) {
//FirstViewBanner?
$objBannerLogic = new BannerLogic();

if ($objBannerLogic->getSetFirstView($this->banner_firstview,$this->banner_categories,$this->module_id) === true)
{
if ($objBannerLogic->getSetFirstView($this->banner_firstview, $this->banner_categories, $this->module_id) === true) {
$this->getSingleBannerFirst();
//Css generieren
$this->setCssClassIdStyle();
return $this->Template->parse();
}
else
{
} else {
//single banner
$this->getSingleBanner();
//Css generieren
$this->setCssClassIdStyle();
return $this->Template->parse();
}
}
else
{
} else {
//multi banner
$this->getMultiBanner();
//Css generieren
Expand All @@ -158,7 +147,7 @@ protected function generateBanner()
protected function getDefaultBanner(): void
{
$objBannerSingle = new SingleBannerTemplate($this->arrCategoryValues, $this->banner_template, $this->strTemplate, $this->Template, $this->arrAllBannersBasic);
$this->Template = $objBannerSingle->getDefaultBanner($this->banner_hideempty);
$this->Template = $objBannerSingle->getDefaultBanner($this->banner_hideempty, $this->module_id);
}

protected function getSingleBannerFirst(): void
Expand Down Expand Up @@ -198,18 +187,15 @@ protected function getSetAllBannerForCategory()
* (exclude == display module not on this page)
* (include == display module only on this page)
*/
if(is_array($arrPages) && count($arrPages) > 0)
{
if (is_array($arrPages) && count($arrPages) > 0) {
// add nested pages to the filter
if($bannerModel->addPageDepth)
{
if ($bannerModel->addPageDepth) {
$arrPages = array_merge($arrPages, Database::getInstance()->getChildRecords($arrPages, 'tl_page'));
}

$check = ($bannerModel->addVisibility == 'exclude') ? true : false;

if(in_array($objPage->id, $arrPages) == $check)
{
if (in_array($objPage->id, $arrPages) == $check) {
unset($this->arrAllBannersBasic[$bannerId]);
}
}
Expand Down
Loading

0 comments on commit 716ceaa

Please sign in to comment.