From 6912fdda4981e1c8cbf0405cce7b1b0ffbbb7b89 Mon Sep 17 00:00:00 2001 From: Christian Barkowsky Date: Thu, 17 Jan 2019 17:09:26 +0100 Subject: [PATCH] #30 --- elements/ContentTabControl.php | 230 +++++++++++++++------------------ 1 file changed, 105 insertions(+), 125 deletions(-) diff --git a/elements/ContentTabControl.php b/elements/ContentTabControl.php index 41f61a4..6054cc7 100755 --- a/elements/ContentTabControl.php +++ b/elements/ContentTabControl.php @@ -2,111 +2,100 @@ /** * TabControl - * - * @copyright Christian Barkowsky 2012-2013, Jean-Bernard Valentaten 2009-2012 + * + * @copyright Christian Barkowsky 2012-2019, Jean-Bernard Valentaten 2009-2012 * @package tabControl * @author Christian Barkowsky , Jean-Bernard Valentaten * @license LGPL */ - - + namespace Contao; +use Contao\Database; +use Contao\ContentElement; -class ContentTabControl extends \ContentElement +/** + * Class ContentTabControl + * @package Contao + */ +class ContentTabControl extends ContentElement { - /** + /** * Template */ protected $strTemplate = 'ce_tabcontrol_tab'; - /** * Contains the default classes used in our tab-template */ private static $defaultClasses = array('tabs', 'panes'); - /** * Generate content element */ protected function compile() { - static $panelIndex = 0; - $classes = deserialize($this->tabClasses); + static $panelIndex = 0; + + $classes = deserialize($this->tabClasses); $arrTabTabs = deserialize($this->tab_tabs); //default classes if neccessary - if (!count($classes)) - { + if (\is_array($classes) && !\count($classes)) { $classes = self::$defaultClasses; - } - else - { + } else { if (!strlen($classes[0])) $classes[0] = self::$defaultClasses[0]; if (!strlen($classes[1])) $classes[1] = self::$defaultClasses[1]; } - switch ($this->tabType) - { - // Tabcontrol - start & tabs - case 'tabcontroltab': - if (TL_MODE == 'FE') - { - if (!is_array($GLOBALS['TL_JAVASCRIPT'])) - { - if (isset($GLOBALS['TL_HOOKS']['tabControlJS']) && is_array($GLOBALS['TL_HOOKS']['tabControlJS'])) - { - foreach ($GLOBALS['TL_HOOKS']['tabControlJS'] as $callback) - { - $this->import($callback[0]); - $this->$callback[0]->{$callback[1]}(); - } - } - else - { - $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/tabcontrol/assets/js/moo_tabcontrol.js'; - } - } - elseif (!in_array($this->strPlugin, $GLOBALS['TL_JAVASCRIPT'])) - { - if (isset($GLOBALS['TL_HOOKS']['tabControlJS']) && is_array($GLOBALS['TL_HOOKS']['tabControlJS'])) - { - foreach ($GLOBALS['TL_HOOKS']['tabControlJS'] as $callback) - { - $this->import($callback[0]); - $this->$callback[0]->{$callback[1]}(); - } - } - else - { - $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/tabcontrol/assets/js/moo_tabcontrol.js'; - } - } - - $this->Template = new FrontendTemplate($this->tab_template); + switch ($this->tabType) { + // Tabcontrol - start & tabs + case 'tabcontroltab': + if (TL_MODE == 'FE') { + if (!is_array($GLOBALS['TL_JAVASCRIPT'])) { + if (isset($GLOBALS['TL_HOOKS']['tabControlJS']) && is_array($GLOBALS['TL_HOOKS']['tabControlJS'])) { + foreach ($GLOBALS['TL_HOOKS']['tabControlJS'] as $callback) { + $this->import($callback[0]); + $this->$callback[0]->{$callback[1]}(); + } + } else { + $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/tabcontrol/assets/js/moo_tabcontrol.js'; + } + } + elseif (!in_array($this->strPlugin, $GLOBALS['TL_JAVASCRIPT'])) { + if (isset($GLOBALS['TL_HOOKS']['tabControlJS']) && is_array($GLOBALS['TL_HOOKS']['tabControlJS'])) { + foreach ($GLOBALS['TL_HOOKS']['tabControlJS'] as $callback) { + $this->import($callback[0]); + $this->$callback[0]->{$callback[1]}(); + } + } else { + $GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/tabcontrol/assets/js/moo_tabcontrol.js'; + } + } + + $this->Template = new FrontendTemplate($this->tab_template); } else { $titleList = ''; - + if(!empty($arrTabTabs)) { - $counter = 1; - foreach($arrTabTabs as $index) - { - $titleList .= $counter++ . '. ' . $index['tab_tabs_name'] . '
'; - } + $counter = 1; + foreach($arrTabTabs as $index) + { + $titleList .= $counter++ . '. ' . $index['tab_tabs_name'] . '
'; + } } - + $this->Template = new BackendTemplate('be_wildcard'); $this->Template->wildcard = '### TABCONTROL: TABGROUP START ###'; $this->Template->title = $titleList; } break; - + // Panel - start case 'tabcontrolstart': if (TL_MODE == 'FE') @@ -131,19 +120,19 @@ protected function compile() $this->Template->wildcard = '### TABCONTROL: ' . $panelIndex . '. SECTION END ###'; } break; - + // Tabcontrol - end case 'tabcontrol_end': default: - if (TL_MODE == 'FE') + if (TL_MODE == 'FE') { - $this->Template = new FrontendTemplate($this->tab_template_end); - } else { - $this->Template = new BackendTemplate('be_wildcard'); + $this->Template = new FrontendTemplate($this->tab_template_end); + } else { + $this->Template = new BackendTemplate('be_wildcard'); $this->Template->wildcard = '### TABCONTROL: TABGROUP END ###'; $panelIndex = 0; - } - break; + } + break; } $this->Template->id = $this->id; @@ -156,42 +145,38 @@ protected function compile() $this->Template->panesSelector = '.' . str_replace(' ', '.', $classes[1]); $this->Template->tabs = $classes[0]; $this->Template->tabsSelector = '.' . str_replace(' ', '.', $classes[0]); - - if(!empty($arrTabTabs)) - { - $defaultByCookie = ''; - $default = 0; - - foreach($arrTabTabs as $index => $title) - { - $arrTabTitles[] = $title['tab_tabs_name']; - - if($title['tab_tabs_default']) - { - $default = $index; - } - - if($this->tabControlCookies) - { - if($this->check($title, $this->tabControlCookies)) - { - $defaultByCookie = $index; - } - } - } - - if($defaultByCookie != '') - { - $this->Template->tab_tabs_default = $defaultByCookie; - } - else - { - $this->Template->tab_tabs_default = $default; - } - - $this->Template->titles = $arrTabTitles; - } - + + if (!empty($arrTabTabs)) { + $defaultByCookie = ''; + $default = 0; + + foreach ($arrTabTabs as $index => $title) + { + $arrTabTitles[] = $title['tab_tabs_name']; + + if($title['tab_tabs_default']) + { + $default = $index; + } + + if($this->tabControlCookies) + { + if($this->check($title, $this->tabControlCookies)) + { + $defaultByCookie = $index; + } + } + } + + if ($defaultByCookie != '') { + $this->Template->tab_tabs_default = $defaultByCookie; + } else { + $this->Template->tab_tabs_default = $default; + } + + $this->Template->titles = $arrTabTitles; + } + $this->Template->tab_autoplay_autoSlide = $this->tab_autoplay_autoSlide; $this->Template->tab_autoplay_delay = $this->tab_autoplay_delay; $this->Template->tab_autoplay_fade = $this->tab_autoplay_fade; @@ -200,39 +185,34 @@ protected function compile() } - /** - * Get article alias - */ + /** + * Get article alias + */ protected function getArticleAlias($pid) { - $objArticle = $this->Database->prepare("SELECT id, alias FROM tl_article WHERE id=?")->limit(1)->execute($pid); + $objArticle = Database::getInstance()->prepare("SELECT id, alias FROM tl_article WHERE id=?")->limit(1)->execute($pid); - if ($objArticle->numRows) - { + if ($objArticle->numRows) { return $objArticle->alias; } return null; } - - + + /** * Set default tab by cookie */ protected function check($title, $cookieName) { - $cookieValue = Input::cookie($cookieName); - - if($cookieValue) - { - if($title['tab_tabs_cookies_value'] == $cookieValue) - { - return true; - } - } - - return false; + $cookieValue = Input::cookie($cookieName); + + if ($cookieValue) { + if ($title['tab_tabs_cookies_value'] == $cookieValue) { + return true; + } + } + + return false; } } - -?>