From 15aa42fd020c671c274c87ea6f51e29bf2f358ab Mon Sep 17 00:00:00 2001 From: Henning Leutz <leutz@pcsg.de> Date: Fri, 27 Nov 2015 11:29:08 +0100 Subject: [PATCH] PSR-2 -> lib to src --- src/QUI/Bricks/Brick.php | 386 ++++++++++ src/QUI/Bricks/Controls/Banner.css | 5 + src/QUI/Bricks/Controls/Banner.html | 7 + src/QUI/Bricks/Controls/Banner.php | 55 ++ src/QUI/Bricks/Controls/BoxContent.css | 79 ++ src/QUI/Bricks/Controls/BoxContent.html | 15 + src/QUI/Bricks/Controls/BoxContent.php | 98 +++ src/QUI/Bricks/Controls/ContentSwitcher.css | 49 ++ src/QUI/Bricks/Controls/ContentSwitcher.html | 23 + src/QUI/Bricks/Controls/ContentSwitcher.php | 61 ++ src/QUI/Bricks/Controls/Image.css | 22 + src/QUI/Bricks/Controls/Image.html | 21 + src/QUI/Bricks/Controls/Image.php | 58 ++ src/QUI/Bricks/Controls/Pagination.css | 61 ++ src/QUI/Bricks/Controls/Pagination.html | 148 ++++ src/QUI/Bricks/Controls/Pagination.php | 300 ++++++++ src/QUI/Bricks/Controls/SideBox1.html | 35 + src/QUI/Bricks/Controls/SideBox1.php | 114 +++ src/QUI/Bricks/Controls/SideBox2.html | 55 ++ src/QUI/Bricks/Controls/SideBox2.php | 93 +++ src/QUI/Bricks/Controls/SideBox3.css | 37 + src/QUI/Bricks/Controls/SideBox3.html | 56 ++ src/QUI/Bricks/Controls/SideBox3.php | 93 +++ src/QUI/Bricks/Controls/SideBox3TitleTop.html | 55 ++ src/QUI/Bricks/Controls/SideBox3TitleTop.php | 68 ++ src/QUI/Bricks/Controls/SideBox4.css | 85 +++ src/QUI/Bricks/Controls/SideBox4.html | 55 ++ src/QUI/Bricks/Controls/SideBox4.php | 91 +++ src/QUI/Bricks/Controls/SimpleGoogleMaps.css | 7 + src/QUI/Bricks/Controls/SimpleGoogleMaps.html | 1 + src/QUI/Bricks/Controls/SimpleGoogleMaps.php | 64 ++ src/QUI/Bricks/Controls/SocialBox.css | 69 ++ src/QUI/Bricks/Controls/SocialBox.html | 18 + src/QUI/Bricks/Controls/SocialBox.php | 59 ++ src/QUI/Bricks/Events.php | 153 ++++ src/QUI/Bricks/Manager.php | 707 ++++++++++++++++++ src/QUI/Bricks/Utils.php | 184 +++++ 37 files changed, 3487 insertions(+) create mode 100644 src/QUI/Bricks/Brick.php create mode 100644 src/QUI/Bricks/Controls/Banner.css create mode 100644 src/QUI/Bricks/Controls/Banner.html create mode 100644 src/QUI/Bricks/Controls/Banner.php create mode 100644 src/QUI/Bricks/Controls/BoxContent.css create mode 100644 src/QUI/Bricks/Controls/BoxContent.html create mode 100644 src/QUI/Bricks/Controls/BoxContent.php create mode 100644 src/QUI/Bricks/Controls/ContentSwitcher.css create mode 100644 src/QUI/Bricks/Controls/ContentSwitcher.html create mode 100644 src/QUI/Bricks/Controls/ContentSwitcher.php create mode 100644 src/QUI/Bricks/Controls/Image.css create mode 100644 src/QUI/Bricks/Controls/Image.html create mode 100644 src/QUI/Bricks/Controls/Image.php create mode 100644 src/QUI/Bricks/Controls/Pagination.css create mode 100644 src/QUI/Bricks/Controls/Pagination.html create mode 100644 src/QUI/Bricks/Controls/Pagination.php create mode 100644 src/QUI/Bricks/Controls/SideBox1.html create mode 100644 src/QUI/Bricks/Controls/SideBox1.php create mode 100644 src/QUI/Bricks/Controls/SideBox2.html create mode 100644 src/QUI/Bricks/Controls/SideBox2.php create mode 100644 src/QUI/Bricks/Controls/SideBox3.css create mode 100644 src/QUI/Bricks/Controls/SideBox3.html create mode 100644 src/QUI/Bricks/Controls/SideBox3.php create mode 100644 src/QUI/Bricks/Controls/SideBox3TitleTop.html create mode 100644 src/QUI/Bricks/Controls/SideBox3TitleTop.php create mode 100644 src/QUI/Bricks/Controls/SideBox4.css create mode 100644 src/QUI/Bricks/Controls/SideBox4.html create mode 100644 src/QUI/Bricks/Controls/SideBox4.php create mode 100644 src/QUI/Bricks/Controls/SimpleGoogleMaps.css create mode 100644 src/QUI/Bricks/Controls/SimpleGoogleMaps.html create mode 100644 src/QUI/Bricks/Controls/SimpleGoogleMaps.php create mode 100644 src/QUI/Bricks/Controls/SocialBox.css create mode 100644 src/QUI/Bricks/Controls/SocialBox.html create mode 100644 src/QUI/Bricks/Controls/SocialBox.php create mode 100644 src/QUI/Bricks/Events.php create mode 100644 src/QUI/Bricks/Manager.php create mode 100644 src/QUI/Bricks/Utils.php diff --git a/src/QUI/Bricks/Brick.php b/src/QUI/Bricks/Brick.php new file mode 100644 index 0000000..7a92874 --- /dev/null +++ b/src/QUI/Bricks/Brick.php @@ -0,0 +1,386 @@ +<?php + +/** + * This file contains \QUI\Bricks\Brick + */ + +namespace QUI\Bricks; + +use QUI; + +/** + * Class Brick + * A Brick from the Brickmanager + * + * @author www.pcsg.de (Henning Leutz) + * @package quiqqer/bricks + */ +class Brick extends QUI\QDOM +{ + /** + * internal brick id + * + * @var + */ + protected $id = false; + + /** + * Brick settings + * + * @var array + */ + protected $settings = array(); + + /** + * Fields can be overwritten by another user + * + * @var array + */ + protected $customfields = array(); + + /** + * Internal control + * + * @var null + */ + protected $Control = null; + + /** + * List of extra css classes + * + * @var array + */ + protected $cssClasses = array(); + + /** + * Constructor + * + * @param array $params - brick params + */ + public function __construct($params = array()) + { + // default + $default = array( + 'type' => 'content', + 'content' => '', + 'title' => '', + 'description' => '', + 'project' => '', + 'areas' => '', + 'height' => '', + 'width' => '', + 'classes' => '' + ); + + $this->setAttributes($default); + + foreach ($default as $key => $value) { + if (isset($params[$key])) { + $this->setAttribute($key, $params[$key]); + } + } + + if (isset($params['id'])) { + $this->id = $params['id']; + } + + // default settings from control + $Control = $this->getControl(); + $Manager = Manager::init(); + + $availableSettings = $Manager->getAvailableBrickSettingsByBrickType( + $this->getAttribute('type') + ); + + foreach ($availableSettings as $entry) { + $this->settings[$entry['name']] = false; + } + + // control default settings + if (is_object($Control)) { + $controlSettings = $Control->getAttributes(); + + foreach ($this->settings as $key => $value) { + if (isset($controlSettings[$key])) { + $this->settings[$key] = $controlSettings[$key]; + } + } + } + + // settings from database + if (isset($params['settings'])) { + $settings = $params['settings']; + + if (is_string($settings)) { + $settings = json_decode($settings, true); + } + + if (is_array($settings)) { + foreach ($this->settings as $key => $value) { + if (isset($settings[$key])) { + $this->settings[$key] = $settings[$key]; + } + } + } + } + + // customfields + if (isset($params['customfields'])) { + $customfields = $params['customfields']; + + if (is_string($customfields)) { + $customfields = json_decode($customfields, true); + } + + if (is_array($customfields)) { + $this->customfields = $customfields; + } + } + } + + /** + * Return the class type + * + * @return String + */ + public function getType() + { + $Control = $this->getControl(); + + if (is_object($Control)) { + return get_class($Control); + } + + return get_class($this); + } + + /** + * Check, if control canbe created + * + * @throws QUI\Exception + * @return QUI\Bricks\Brick + */ + public function check() + { + if ($this->getAttribute('type') == 'content') { + return $this; + } + + $Control = $this->getControl(); + + if (!$Control) { + throw new QUI\Exception('Control not found. Brick could not be created'); + } + + return $this; + } + + /** + * Return the HTML of the Brick + * + * @return string + * + * @throws QUI\Exception + */ + public function create() + { + if ($this->getAttribute('type') == 'content') { + $_classes = array( + 'brick-' . $this->id + ); + + foreach ($this->cssClasses as $cssClass) { + $_classes[] = $cssClass; + } + + if ($this->getAttribute('classes')) { + $classes = explode(' ', $this->getAttribute('classes')); + + foreach ($classes as $class) { + $class = trim($class); + $class = preg_replace('/[^a-zA-Z0-9\-]/', '', $class); + + $_classes[] = $class; + } + } + + $_classes = array_unique($_classes); + $classesStr = implode($_classes, ' '); + $classesStr = 'class="' . $classesStr . '"'; + + return "<div {$classesStr}>{$this->getAttribute('content')}</div>"; + } + + $Control = $this->getControl(); + + if (!$Control) { + throw new QUI\Exception('Control not found. Brick could not be created'); + } + + $Control->setAttributes($this->getSettings()); + + if ($this->getAttribute('classes')) { + $classes = explode(' ', $this->getAttribute('classes')); + + foreach ($classes as $class) { + $class = trim($class); + $class = preg_replace('/[^a-zA-Z0-9\-]/', '', $class); + + $Control->addCSSClass($class); + } + } + + if ($this->id) { + $Control->addCSSClass('brick-' . $this->id); + } + + foreach ($this->cssClasses as $cssClass) { + $Control->addCSSClass($cssClass); + } + + return $Control->create(); + } + + /** + * Return the internal control + * + * @return QUI\Control|Bool + */ + protected function getControl() + { + if ($this->Control) { + return $this->Control; + } + + $Ctrl = $this->getAttribute('type'); + + if ($Ctrl === 'content') { + return true; + } + + if (!is_callable($Ctrl) && !class_exists($Ctrl)) { + return false; + } + + /* @var $Control \QUI\Control */ + $Control = new $Ctrl($this->getSettings()); + + $Control->setAttribute('height', $this->getAttribute('height')); + $Control->setAttribute('width', $this->getAttribute('width')); + $Control->setAttribute('content', $this->getAttribute('content')); + + + if (!($Control instanceof QUI\Control) || !$Control) { + return false; + } + + $this->Control = $Control; + + return $Control; + } + + /** + * Return the brick settings + * + * @return array + */ + public function getSettings() + { + return $this->settings; + } + + /** + * Set brick settings + * + * @param array $settings - list of settings + * + * @return void + */ + public function setSettings($settings) + { + foreach ($settings as $key => $value) { + $this->setSetting($key, $value); + } + } + + /** + * Return the setting of the brick + * + * @param String $name - Name of the setting + * + * @return boolean|string + */ + public function getSetting($name) + { + if (isset($this->settings[$name])) { + return $this->settings[$name]; + } + + return false; + } + + /** + * Set a brick setting + * + * @param string $name - name of the setting + * @param string $value - value of the setting + * + * @return void + */ + public function setSetting($name, $value) + { + if (isset($this->settings[$name])) { + $this->settings[$name] = $value; + } + } + + /** + * This fields can be overwritten by another user + * + * @return array + */ + public function getCustomFields() + { + return $this->customfields; + } + + /** + * Add an exxtra CSS Class to the control + * + * @param string $cssClass - Name of the CSS Class + * + * @return void + */ + public function addCSSClass($cssClass) + { + $this->cssClasses[] = $cssClass; + } + + /** + * Match pattern agains the css classes + * + * @param string $pattern - The shell wildcard pattern. + * + * @return boolean + */ + public function hasCSSClass($pattern) + { + if ($this->getAttribute('classes') + && fnmatch($pattern, $this->getAttribute('classes')) + ) { + return true; + } + + if (empty($this->cssClasses)) { + return false; + } + + foreach ($this->cssClasses as $cssClass) { + if (fnmatch($pattern, $cssClass)) { + return true; + } + } + + return false; + } +} diff --git a/src/QUI/Bricks/Controls/Banner.css b/src/QUI/Bricks/Controls/Banner.css new file mode 100644 index 0000000..f5a9cda --- /dev/null +++ b/src/QUI/Bricks/Controls/Banner.css @@ -0,0 +1,5 @@ +.quiqqer-bricks-banner { + margin-bottom: 0; + padding: 4.5em 0; + text-align: center; +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/Banner.html b/src/QUI/Bricks/Controls/Banner.html new file mode 100644 index 0000000..1b1deaa --- /dev/null +++ b/src/QUI/Bricks/Controls/Banner.html @@ -0,0 +1,7 @@ + +<header> + <h2>{$this->getAttribute('title')}</h2> + <p> + {$this->getAttribute('text')} + </p> +</header> diff --git a/src/QUI/Bricks/Controls/Banner.php b/src/QUI/Bricks/Controls/Banner.php new file mode 100644 index 0000000..67fa4e6 --- /dev/null +++ b/src/QUI/Bricks/Controls/Banner.php @@ -0,0 +1,55 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\Banner + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class Banner + * + * @package quiqqer/bricks + */ +class Banner extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'title' => '', + 'text' => '', + 'class' => 'quiqqer-bricks-banner', + 'nodeName' => 'section' + )); + + $this->addCSSFile( + dirname(__FILE__).'/Banner.css' + ); + + parent::setAttributes($attributes); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + + $Engine->assign(array( + 'this' => $this + )); + + return $Engine->fetch(dirname(__FILE__).'/Banner.html'); + } +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/BoxContent.css b/src/QUI/Bricks/Controls/BoxContent.css new file mode 100644 index 0000000..04aa364 --- /dev/null +++ b/src/QUI/Bricks/Controls/BoxContent.css @@ -0,0 +1,79 @@ +.quiqqer-box-content { + width: 100%; +} + +.box-content-entry { + float: left; + padding-top: 20px; + padding-bottom: 0px; +} + +.box-content-entry h4 { + width: 100%; + white-space: nowrap; + overflow: hidden; + -ms-text-overflow: ellipsis; + text-overflow: ellipsis; +} + + +.box-content-entry-1 { + width: 100%; +} + +.box-content-entry-2 { + width: 50%; +} + +.box-content-entry-3 { + width: 33%; +} + +.box-content-entry-4 { + width: 25%; +} + +.box-content-entry-5 { + width: 20%; +} + +.box-content-entry-6 { + width: 16.6666%; +} + +.box-content-entry-7 { + width: 14.27%; +} + +.box-content-entry-8 { + width: 12.5%; +} + +.box-content-entry-9 { + width: 11.11%; +} + +.box-content-entry-10 { + width: 10%; +} + + +@media screen and (max-width: 767px) { + .quiqqer-box-content { + padding-top: 20px; + } + + .box-content-entry { + padding-top: 0; + padding-bottom: 40px; + text-align: center; + width: 50% !important; + } +} + + +@media screen and (max-width: 460px) { + .box-content-entry { + width: 100% !important; + } +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/BoxContent.html b/src/QUI/Bricks/Controls/BoxContent.html new file mode 100644 index 0000000..cd98ed3 --- /dev/null +++ b/src/QUI/Bricks/Controls/BoxContent.html @@ -0,0 +1,15 @@ +<div class="quiqqer-box-content"> + {if $this->getAttribute('content')} + <div class="grid-100 grid-parent"> + {$this->getAttribute('content')} + </div> + {/if} + {foreach from=$entries item=entry} + <div class="box-content-entry{$extraClass}"> + <h4 title="{$entry.title|escape:"html"}"> + {$entry.title} + </h4> + <p>{$entry.text}</p> + </div> + {/foreach} +</div> \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/BoxContent.php b/src/QUI/Bricks/Controls/BoxContent.php new file mode 100644 index 0000000..04fed28 --- /dev/null +++ b/src/QUI/Bricks/Controls/BoxContent.php @@ -0,0 +1,98 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\BoxContent + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class BoxContent + * + * @package quiqqer/bricks + */ +class BoxContent extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'title' => 'Box Content', + 'contentList' => false, + 'entries' => array() + )); + + parent::__construct($attributes); + + $this->addCSSFile( + dirname(__FILE__) . '/BoxContent.css' + ); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $entries = $this->getAttribute('entries'); + + if (is_string($entries)) { + $entries = json_decode($entries, true); + } + + $count = count($entries); + $extraClass = ''; + + switch ($count) { + case 1: + $extraClass = ' box-content-entry-1'; + break; + case 2: + $extraClass = ' box-content-entry-2'; + break; + case 3: + $extraClass = ' box-content-entry-3'; + break; + case 4: + $extraClass = ' box-content-entry-4'; + break; + case 5: + $extraClass = ' box-content-entry-5'; + break; + case 6: + $extraClass = ' box-content-entry-6'; + break; + case 7: + $extraClass = ' box-content-entry-7'; + break; + case 8: + $extraClass = ' box-content-entry-8'; + break; + case 9: + $extraClass = ' box-content-entry-9'; + break; + case 10: + $extraClass = ' box-content-entry-10'; + break; + + } + + $Engine->assign(array( + 'this' => $this, + 'entries' => $entries, + 'extraClass' => $extraClass + )); + + return $Engine->fetch(dirname(__FILE__) . '/BoxContent.html'); + } +} diff --git a/src/QUI/Bricks/Controls/ContentSwitcher.css b/src/QUI/Bricks/Controls/ContentSwitcher.css new file mode 100644 index 0000000..8864b8d --- /dev/null +++ b/src/QUI/Bricks/Controls/ContentSwitcher.css @@ -0,0 +1,49 @@ +.content-switcher { + display: flex; + min-height: 360px; + align-items: center; + flex-direction: row; +} + + .content-switcher-image { + height: 400px; + width: 50%; + padding:50px; + display: flex; + align-items: center; + justify-content: center + } + + img.content-switcher-image-img { + height: auto; + max-width: 100%; + } + + .content-switcher-content { + width: 50%; + padding: 50px 0; + + } + +@media screen and (max-width: 767px){ + .content-switcher { + flex-direction: column; + border-bottom: 2px solid #f5f5f5; + } + + .content-switcher:last-child { + border-bottom: none; + } + + .content-switcher-image { + width: 100%; + height: auto; + padding: 20px 0; + } + + .content-switcher-content { + width: 100%; + } +} + + diff --git a/src/QUI/Bricks/Controls/ContentSwitcher.html b/src/QUI/Bricks/Controls/ContentSwitcher.html new file mode 100644 index 0000000..07c6cb3 --- /dev/null +++ b/src/QUI/Bricks/Controls/ContentSwitcher.html @@ -0,0 +1,23 @@ + +{if !$this->getAttribute('content') == ""} +<div class="grid-100 grid-parent"> + {$this->getAttribute('content')} +</div> +{/if} + +{foreach from=$entries item=entry key=key} +{assign var=img value=$entry.img} + +<div class="content-switcher"> +{assign var=modKey value=$key+1} + <div class="content-switcher-image {if $modKey && $modKey % 2 !== 0 }push-50 mobile-pull-100{/if}"> + {if $img != ""} + {image src=$entry.img width=300 class="content-switcher-image-img"} + {/if} + </div> + <div class="content-switcher-content {if $modKey && $modKey % 2 !== 0 }pull-50 mobile-pull-100{/if}"> + <h2>{$entry.title}</h2> + <p>{$entry.content}</p> + </div> +</div> +{/foreach} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/ContentSwitcher.php b/src/QUI/Bricks/Controls/ContentSwitcher.php new file mode 100644 index 0000000..8a4f54a --- /dev/null +++ b/src/QUI/Bricks/Controls/ContentSwitcher.php @@ -0,0 +1,61 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\ContentSwitcher + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class ContentSwitcher + * + * @package quiqqer/bricks + */ +class ContentSwitcher extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'title' => 'Content Switcher', + 'contentList' => false, + 'entries' => array() + )); + + parent::__construct($attributes); + + $this->addCSSFile( + dirname(__FILE__) . '/ContentSwitcher.css' + ); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $entries = $this->getAttribute('entries'); + + if (is_string($entries)) { + $entries = json_decode($entries, true); + } + + $Engine->assign(array( + 'this' => $this, + 'entries' => $entries + )); + + + return $Engine->fetch(dirname(__FILE__) . '/ContentSwitcher.html'); + } +} diff --git a/src/QUI/Bricks/Controls/Image.css b/src/QUI/Bricks/Controls/Image.css new file mode 100644 index 0000000..1243f58 --- /dev/null +++ b/src/QUI/Bricks/Controls/Image.css @@ -0,0 +1,22 @@ +.brick-image-text { + margin-bottom: 40px; +} + +.brick-image-picture-container { + text-align: center; +} + +a.brick-image-link:hover { + outline: none; + background: none; + border: none; + box-shadow: none; +} + +a.brick-image-link { + display: block; +} + +.brick-image-picture { + max-width: 100%; +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/Image.html b/src/QUI/Bricks/Controls/Image.html new file mode 100644 index 0000000..a3ddfe5 --- /dev/null +++ b/src/QUI/Bricks/Controls/Image.html @@ -0,0 +1,21 @@ +{assign var=img value=$brickImage} +{assign var=link value=$brickLink} +<dev class="content-body brick-image"> + + {if !$this->getAttribute('content') == ""} + <div class="grid-100 grid-parent brick-image-text"> + {$this->getAttribute('content')} + </div> + {/if} + + <div class="grid-100 grid-parent brick-image-picture-container"> + {if $link != ""} + <a class="brick-image-link" href="{$link}"> + {/if} + {image src=$img class="brick-image-picture"} + {if $link != ""} + </a> + {/if} + </div> + +</dev> \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/Image.php b/src/QUI/Bricks/Controls/Image.php new file mode 100644 index 0000000..10d1f32 --- /dev/null +++ b/src/QUI/Bricks/Controls/Image.php @@ -0,0 +1,58 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\Image + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class Image + * + * @package quiqqer/bricks + */ +class Image extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'title' => 'Image Brick', + 'contentList' => false + )); + + parent::__construct($attributes); + + $this->addCSSFile( + dirname(__FILE__) . '/Image.css' + ); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $brickImage = $this->getAttribute('picture'); + $brickLink = $this->getAttribute('link'); + + $Engine->assign(array( + 'this' => $this, + 'brickImage' => $brickImage, + 'brickLink' => $brickLink + )); + + + return $Engine->fetch(dirname(__FILE__) . '/Image.html'); + } +} diff --git a/src/QUI/Bricks/Controls/Pagination.css b/src/QUI/Bricks/Controls/Pagination.css new file mode 100644 index 0000000..cd6d105 --- /dev/null +++ b/src/QUI/Bricks/Controls/Pagination.css @@ -0,0 +1,61 @@ +@CHARSET "UTF-8"; + +.quiqqer-sheets-mobile select { + width: 100%; +} + +.quiqqer-sheets-desktop { + clear: both; + float: left; + margin: 0; + width: calc(100% - 120px); +} + +.quiqqer-sheets-desktop__100 { + width: 100%; +} + +.quiqqer-sheets-desktop:last-child { + margin: 20px 0; +} + +.quiqqer-sheets-desktop a, +.quiqqer-sheets-desktop span { + border: 1px solid #D0D3D3; + border-top: 1px solid #D0D3D3; + border-bottom: 1px solid #D0D3D3; + float: left; + line-height: 30px; + margin: 0; + text-align: center; + text-decoration: none; +} + +.quiqqer-sheets-desktop-disabled { + color: #AAAAAA; + cursor: default; + border-color: #DDDDDD; +} + +.quiqqer-sheets-desktop-current { + color: #FFFFFF; + cursor: default; + background: #666; + border-color: #666; +} + +.quiqqer-sheets-desktop a:hover { + color: #FFFFFF; + text-decoration: none; +} + +.quiqqer-sheets-desktop-limits { + float: right; + line-height: 40px; + text-align: center; + width: 120px; +} + +.quiqqer-sheets-desktop .more { + border: none; +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/Pagination.html b/src/QUI/Bricks/Controls/Pagination.html new file mode 100644 index 0000000..6d4fb8e --- /dev/null +++ b/src/QUI/Bricks/Controls/Pagination.html @@ -0,0 +1,148 @@ + +<div class="quiqqer-sheets-mobile hide-on-desktop"> + <select name="select-sheet" class="hide-on-desktop" onchange="window.location = this.value"> + {section name=sheets start=0 loop=$count} + {assign var=num value=$smarty.section.sheets.index+1} + + {$getParams['limit'] = $limit} + {$getParams['sheet'] = $num} + <option value="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + {if $num == $active} + selected="selected" + {/if} + >{locale group="quiqqer/bricks" + value="controls.pagination.mobile.option" + from=$num + max=$count + }</option> + {/section} + </select> +</div> + +<div class="quiqqer-sheets-desktop hide-on-mobile{if !$this->getAttribute('showLimit')} quiqqer-sheets-desktop__100{/if}" + {if $this->getAttribute('useAjax')}style="opacity:0"{/if} +> + {if (!isset($smarty.request.sheet) || $active == 1) + && $this->getAttribute('useAjax') === false + } + <span class="quiqqer-sheets-desktop-disabled fa fa-angle-double-left quiqqer-sheets-first" + title="{t}quiqqer/bricks controls.pagination.first.page{/t}"> + </span> + {else} + {$getParams['limit'] = $limit} + {$getParams['sheet'] = false} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + class="fa fa-angle-double-left quiqqer-sheets-first" + title="{t}quiqqer/bricks controls.pagination.first.page{/t}"> + </a> + {/if} + + {if (!isset($smarty.request.sheet) || $active <= 1) + && $this->getAttribute('useAjax') === false + } + <span class="quiqqer-sheets-desktop-disabled fa fa-angle-left quiqqer-sheets-prev" + title="{t}quiqqer/bricks controls.pagination.back{/t}"> + </span> + {else} + {math assign=backward equation="x - y" x=$active y=1} + {if $backward == 1} + {$getParams['limit'] = $limit} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + class="fa fa-angle-left quiqqer-sheets-prev" + title="{t}quiqqer/bricks controls.pagination.back{/t}"> + </a> + {else} + {$getParams['sheet'] = $backward} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + class="fa fa-angle-left quiqqer-sheets-prev" + title="{t}quiqqer/bricks controls.pagination.back{/t}"> + </a> + {/if} + {/if} + + {if $start > 1} + <span class="more">...</span> + {/if} + + + {section name=sheets start=$start loop=$end+1} + {assign var=num value=$smarty.section.sheets.index} + {if $num == $active} + {if $this->getAttribute('useAjax') === false} + <span class="quiqqer-sheets-desktop-current">{$num}</span> + {else} + {$getParams['limit'] = $limit} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + class="quiqqer-sheets-sheet quiqqer-sheets-desktop-current" + data-page="{$num}" + > + {$num} + </a> + {/if} + {else} + {$getParams['limit'] = $limit} + {if $num == 1} + {$getParams['sheet'] = false} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + class="quiqqer-sheets-sheet" + data-page="{$num}" + > + {$num} + </a> + {else} + {$getParams['sheet'] = $num} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + class="quiqqer-sheets-sheet" + data-page="{$num}" + > + {$num} + </a> + {/if} + {/if} + {/section} + + + {if $end < $count} + <span class="more">...</span> + {/if} + + {if $active >= $count && $this->getAttribute('useAjax') === false} + <span class="quiqqer-sheets-desktop-disabled fa fa-angle-right quiqqer-sheets-next" + title="{t}quiqqer/bricks controls.pagination.next{/t}" + > + </span> + {else} + {math assign=forward equation="x + y" x=$active y=1 } + {$getParams['sheet'] = $forward} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + class="fa fa-angle-right quiqqer-sheets-next" + title="{t}quiqqer/bricks controls.pagination.next{/t}" + > + </a> + {/if} + + {if $active >= $count && $this->getAttribute('useAjax') === false} + <span class="quiqqer-sheets-desktop-disabled fa fa-angle-double-right quiqqer-sheets-last" + title="{t}quiqqer/bricks controls.pagination.last.page{/t}" + ></span> + {else} + {$getParams['sheet'] = $count} + <a href="{$Site->getUrl($pathParams, $getParams)}{$anchor}" + title="{t}quiqqer/bricks controls.pagination.last.page{/t}" + class="fa fa-angle-double-right quiqqer-sheets-last" + ></a> + {/if} +</div> + +{if $this->getAttribute('showLimit') && $limits} +<div class="quiqqer-sheets-desktop-limits"> + {foreach from=$limits item=limitEntry name=limits} + {$getParams['limit'] = $limitEntry} + {$getParams['sheet'] = false} + <a href="{$Site->getUrl($pathParams, $getParams)}" data-limit="{$limitEntry}"> + {$limitEntry} + </a> + {if not $smarty.foreach.limits.last} | {/if} + {/foreach} +</div> +{/if} diff --git a/src/QUI/Bricks/Controls/Pagination.php b/src/QUI/Bricks/Controls/Pagination.php new file mode 100644 index 0000000..857fe42 --- /dev/null +++ b/src/QUI/Bricks/Controls/Pagination.php @@ -0,0 +1,300 @@ +<?php + +/** + * This file contains \QUI\Bricks\Controls\Pagination + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Pagination + * + * @author www.pcsg.de (Henning Leutz) + * @licence For copyright and license information, please view the /README.md + */ +class Pagination extends QUI\Control +{ + /** + * GET Params + * + * @var array + */ + protected $getParams = array(); + + /** + * URL Params + * + * @var array + */ + protected $urlParams = array(); + + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + $this->setAttributes(array( + 'showLimit' => false, + 'limits' => '[10,20,50]', + 'limit' => 10, + 'order' => false, + 'sheet' => 1, + 'useAjax' => false, + 'showmax' => 10, + 'anchor' => false + )); + + parent::__construct($attributes); + + $this->addCSSFile( + dirname(__FILE__) . '/Pagination.css' + ); + + + if ($this->getAttribute('useAjax')) { + $this->setAttribute( + 'data-qui', + 'package/quiqqer/bricks/bin/Controls/Pagination' + ); + } else { + $this->setAttribute('data-qui', false); + } + + $this->setAttribute('class', 'quiqqer-pagination grid-100 grid-parent'); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $Site = $this->getAttribute('Site'); + $Project = $Site->getProject(); + + $count = $this->getAttribute('sheets'); + + if ($count === false) { + if ($this->getAttribute('limit') && + $this->getAttribute('count') + ) { + $count = ceil( + (int)$this->getAttribute('count') / + (int)$this->getAttribute('limit') + ); + + $this->setAttribute('sheets', $count); + } + } + + $showmax = $this->getAttribute('showmax'); + $limits = $this->getAttribute('limits'); + + if ($this->getAttribute('useAjax')) { + $this->setAttribute( + 'data-qui', + 'package/quiqqer/bricks/bin/Controls/Pagination' + ); + } else { + $this->setAttribute('data-qui', false); + } + + if ($limits && is_string($limits)) { + $limits = json_decode($limits, true); + + if (!is_array($limits)) { + $limits = false; + } + } + + $active = $this->getAttribute('sheet'); + $anchor = ''; + + if ($this->getAttribute('anchor')) { + $anchor = $this->getAttribute('anchor'); + } + + if ($showmax >= $count) { + $showmax = false; + } + + if (!$showmax) { + $showmax = $count * 2; + } + + $gap = floor($showmax / 2); + + $start = $active - $gap; + $end = $active + $gap; + + if ($showmax % 2 === 0) { + $end--; // -1, weil aktuelle seite nicht mit berechnet werden soll + } + + if ($start <= 0) { + $start = 1; + $end = $showmax; + } + + if ($end >= $count) { + $end = $count; + $start = $end - $showmax + 1; + + if ($start <= 0) { + $start = 1; + } + } + + // get params + $limit = $this->getAttribute('limit'); + $order = $this->getAttribute('order'); + $sheet = $this->getAttribute('sheet'); + + $this->getParams['sheet'] = $sheet; + $this->getParams['limit'] = $limit; + + if (!empty($order)) { + $this->getParams['order'] = $order; + } + + if ((!$count || $count == 1) + && $this->getAttribute('limit') === false + ) { + return ''; + } + + $Engine->assign(array( + 'this' => $this, + 'count' => $count, + 'start' => $start, + 'end' => $end, + 'active' => $active, + 'pathParams' => $this->urlParams, + 'getParams' => $this->getParams, + 'anchor' => $anchor, + 'limit' => $limit, + 'limits' => $limits, + 'Site' => $Site, + 'Project' => $Project + )); + + return $Engine->fetch(dirname(__FILE__) . '/Pagination.html'); + } + + /** + * Load the GET request variables into the sheet + */ + public function loadFromRequest() + { + $limit = $this->getAttribute('limit'); + $order = $this->getAttribute('order'); + $sheet = $this->getAttribute('sheet'); + + if (isset($_GET['limit']) && is_numeric($_GET['limit'])) { + $limit = (int)$_GET['limit']; + } + + if (isset($_GET['order'])) { + $order = $_GET['order']; + } + + if (isset($_GET['sheet'])) { + $sheet = $_GET['sheet']; + } + + $this->setAttribute('limit', $limit); + $this->setAttribute('order', $order); + $this->setAttribute('sheet', $sheet); + + $this->urlParams = QUI::getRewrite()->getUrlParamsList(); + } + + /** + * Return SQL params + * + * @example $this->getSQLParams() : array( + * 'limit' => '0,20', + * 'order' => 'field' + * ) + * + * @return array + */ + public function getSQLParams() + { + $result = array(); + + if ($this->getAttribute('limit')) { + $result['limit'] = $this->getStart() + . ',' . $this->getAttribute('limit'); + } + + if ($this->getAttribute('order')) { + $result['order'] = $this->getAttribute('order'); + } + + return $result; + } + + /** + * Return the start + * + * @return integer + */ + public function getStart() + { + $limit = $this->getAttribute('limit'); + $sheet = $this->getAttribute('sheet'); + + return ($sheet - 1) * $limit; + } + + /** + * Set GET parameter to the links + * + * @param $name + * @param $value + */ + public function setGetParams($name, $value) + { + $name = QUI\Utils\Security\Orthos::clear($name); + $value = QUI\Utils\Security\Orthos::clearFormRequest($value); + + if (empty($value)) { + if (isset($this->getParams[$name])) { + unset($this->getParams[$name]); + } + + return; + } + + $this->getParams[$name] = urlencode($value); + } + + /** + * Set URL parameter to the links + * + * @param $name + * @param $value + */ + public function setUrlParams($name, $value) + { + $name = QUI\Utils\Security\Orthos::clear($name); + $value = QUI\Utils\Security\Orthos::clear($value); + + if (empty($value)) { + if (isset($this->urlParams[$name])) { + unset($this->urlParams[$name]); + } + + return; + } + + $this->urlParams[$name] = $value; + } +} diff --git a/src/QUI/Bricks/Controls/SideBox1.html b/src/QUI/Bricks/Controls/SideBox1.html new file mode 100644 index 0000000..3122194 --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox1.html @@ -0,0 +1,35 @@ + +{if $this->getAttribute( 'showImage' ) && $Site->getAttribute('image_site')} +<a href="{url site=$Site}" class="image"> + {image src=$Site->getAttribute('image_site') width=1400} +</a> +{/if} + +{if $this->getAttribute( 'showTitle' ) || $this->getAttribute( 'showShort' )} +<header> + {if $this->getAttribute( 'showTitle' )} + <h2> + <a href="{url site=$Site}"> + {$Site->getAttribute('title')} + </a> + </h2> + {/if} + {if $this->getAttribute( 'showShort' )} + <p> + {$Site->getAttribute('short')} + </p> + {/if} +</header> +{/if} + +{if $this->getAttribute( 'showContent' )} +<p> + {$Site->getAttribute('content')} +</p> +{/if} + +<footer> + <a href="{url site=$Site}" class="button"> + {locale group="quiqqer/bricks" var="continue.reading"} + </a> +</footer> diff --git a/src/QUI/Bricks/Controls/SideBox1.php b/src/QUI/Bricks/Controls/SideBox1.php new file mode 100644 index 0000000..2f40224 --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox1.php @@ -0,0 +1,114 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\SideBox1 + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class SocialBox + * + * @package quiqqer/bricks + */ +class SideBox1 extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'showImage' => true, + 'showTitle' => true, + 'showDescription' => true, + 'showContent' => true, + 'class' => 'quiqqer-bricks-sidebox1', + 'nodeName' => 'article', + 'site' => false, + 'order' => 'release_from DESC' + )); + + parent::__construct($attributes); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + + $Engine->assign(array( + 'this' => $this, + 'Site' => $this->getSite() + )); + + return $Engine->fetch(dirname(__FILE__) . '/SideBox1.html'); + } + + /** + * Return the site object + * + * @return QUI\Projects\Site + */ + protected function getSite() + { + $Project = $this->_getProject(); + $site = $this->getAttribute('site'); + + if (is_numeric($site)) { + try { + return $Project->get((int)$site); + + } catch (QUI\Exception $Exception) { + QUI\System\Log::addWarning($Exception->getMessage()); + + return $Project->firstChild(); + } + } + + + // order + switch ($this->getAttribute('order')) { + case 'name ASC': + case 'name DESC': + case 'title ASC': + case 'title DESC': + case 'c_date ASC': + case 'c_date DESC': + case 'd_date ASC': + case 'd_date DESC': + case 'release_from ASC': + case 'release_from DESC': + $order = $this->getAttribute('order'); + break; + + default: + $order = 'release_from DESC'; + break; + } + + $children = QUI\Projects\Site\Utils::getSitesByInputList( + $this->getProject(), + $this->getAttribute('site'), + array( + 'limit' => 1, + 'order' => $order + ) + ); + + if (isset($children[0])) { + return $children[0]; + } + + return $Project->firstChild(); + } +} diff --git a/src/QUI/Bricks/Controls/SideBox2.html b/src/QUI/Bricks/Controls/SideBox2.html new file mode 100644 index 0000000..7441e4e --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox2.html @@ -0,0 +1,55 @@ + +<div class="{$this->getAttribute('grid-class-row')}"> + {if $this->getAttribute('content')} + <div class="quiqqer-bricks-sidebox2-content"> + {$this->getAttribute('content')} + </div> + {/if} +</div> + +<div class="{$this->getAttribute('grid-class-row')}"> + +{foreach from=$children item=Child key=key} + <article class="{$this->getAttribute('grid-class-article')} quiqqer-bricks-sidebox-article"> + {if $this->getAttribute( 'showImage' )} + <a href="{url site=$Child}" class="image"> + {image src=$Child->getAttribute('image_site') width=640} + </a> + {/if} + + {if $this->getAttribute( 'showTitle' ) || $this->getAttribute( 'showShort' )} + <header> + {if $this->getAttribute( 'showTitle' )} + <h3> + <a href="{url site=$Child}"> + {$Child->getAttribute('title')} + </a> + </h3> + {/if} + </header> + {/if} + + {if $this->getAttribute( 'showShort' )} + <p> + {text_passage text=$Child->getAttribute('short') start=0 end=120 striphtml=true append="..."} + </p> + {/if} + + {if $this->getAttribute( 'showContent' )} + {$Child->getAttribute('content')} + {/if} + + <footer class="article-button"> + <a href="{url site=$Child}" class="button"> + {locale group="quiqqer/bricks" var="continue.reading"} + </a> + </footer> + </article> + + {assign var=modKey value=$key+1} + {if $modKey && $modKey % 2 === 0 && $Child@last} + </div> + <div class="{$this->getAttribute('grid-class-row')}"> + {/if} + {/foreach} +</div> diff --git a/src/QUI/Bricks/Controls/SideBox2.php b/src/QUI/Bricks/Controls/SideBox2.php new file mode 100644 index 0000000..83cf05a --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox2.php @@ -0,0 +1,93 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\SideBox2 + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class SocialBox + * + * @package quiqqer/bricks + */ +class SideBox2 extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'showImage' => true, + 'showTitle' => true, + 'showDescription' => true, + 'showContent' => false, + 'class' => 'quiqqer-bricks-sidebox2', + 'nodeName' => 'section', + 'site' => false, + 'limit' => 2, + 'order' => 'release_from DESC', + 'grid-class-row' => 'row', + 'grid-class-article' => '6u' + )); + + parent::__construct($attributes); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $limit = $this->getAttribute('limit'); + + if (!$limit) { + $limit = 2; + } + + // order + switch ($this->getAttribute('order')) { + case 'name ASC': + case 'name DESC': + case 'title ASC': + case 'title DESC': + case 'c_date ASC': + case 'c_date DESC': + case 'd_date ASC': + case 'd_date DESC': + case 'release_from ASC': + case 'release_from DESC': + $order = $this->getAttribute('order'); + break; + + default: + $order = 'release_from DESC'; + break; + } + + $children = QUI\Projects\Site\Utils::getSitesByInputList( + $this->getProject(), + $this->getAttribute('site'), + array( + 'limit' => $limit, + 'order' => $order + ) + ); + + $Engine->assign(array( + 'this' => $this, + 'children' => $children + )); + + return $Engine->fetch(dirname(__FILE__) . '/SideBox2.html'); + } +} diff --git a/src/QUI/Bricks/Controls/SideBox3.css b/src/QUI/Bricks/Controls/SideBox3.css new file mode 100644 index 0000000..d349696 --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox3.css @@ -0,0 +1,37 @@ +.quiqqer-bricks-sidebox3, +.quiqqer-bricks-sidebox3-row { + float: left; + width: 100%; +} + +.quiqqer-bricks-sidebox3-row { + display: flex; +} + +.quiqqer-bricks-sidebox3-article { + align-items: flex-start; + display: flex; + flex-direction: column; + float: left; + padding: 20px 10px 0 10px; + width: 33.3333%; +} + +.quiqqer-bricks-sidebox3-content { + margin-bottom: 20px; +} + +@media screen and (max-width: 736px) { + .quiqqer-bricks-sidebox3-row { + display: block; + flex: none; + } + + .quiqqer-bricks-sidebox3-article { + display: block; + clear: both; + flex: none; + padding: 10px; + width: 100% !important; + } +} diff --git a/src/QUI/Bricks/Controls/SideBox3.html b/src/QUI/Bricks/Controls/SideBox3.html new file mode 100644 index 0000000..84a8a05 --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox3.html @@ -0,0 +1,56 @@ +{if $this->getAttribute('content')} +<div class="grid-100"> + {$this->getAttribute('content')} +</div> +{/if} + +<div class="quiqqer-bricks-sidebox3"> + + <div class="quiqqer-bricks-sidebox3-row"> + + {foreach from=$children item=Child key=key} + <article class="quiqqer-bricks-sidebox3-article"> + {if $this->getAttribute( 'showImage' )} + <a href="{url site=$Child}" class="image"> + {image src=$Child->getAttribute('image_site') width=640} + </a> + {/if} + + {if $this->getAttribute( 'showTitle' ) || $this->getAttribute( 'showShort' )} + <header> + {if $this->getAttribute( 'showTitle' )} + <h3> + <a href="{url site=$Child}"> + {$Child->getAttribute('title')} + </a> + </h3> + {/if} + </header> + {/if} + + {if $this->getAttribute( 'showShort' )} + <p> + {text_passage text=$Child->getAttribute('short') start=0 end=120 striphtml=true append="..."} + </p> + {/if} + + {if $this->getAttribute( 'showContent' )} + {$Child->getAttribute('content')} + {/if} + + <footer class="article-button"> + <a href="{url site=$Child}" class="button"> + {locale group="quiqqer/bricks" var="continue.reading"} + </a> + </footer> + </article> + + {assign var=modKey value=$key+1} + {if $modKey && $modKey % 3 === 0 && !$Child@last} + </div> + <div class="quiqqer-bricks-sidebox3-row"> + {/if} + + {/foreach} + </div> +</div> diff --git a/src/QUI/Bricks/Controls/SideBox3.php b/src/QUI/Bricks/Controls/SideBox3.php new file mode 100644 index 0000000..5fd18df --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox3.php @@ -0,0 +1,93 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\SideBox3 + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class SocialBox + * + * @package quiqqer/bricks + */ +class SideBox3 extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'showImage' => true, + 'showTitle' => true, + 'showDescription' => true, + 'showContent' => false, + 'class' => 'quiqqer-bricks-sidebox3', + 'nodeName' => 'section', + 'site' => false, + 'limit' => 3, + 'order' => 'release_from DESC' + )); + + $this->addCSSFile(dirname(__FILE__) . '/SideBox3.css'); + + parent::__construct($attributes); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $limit = $this->getAttribute('limit'); + + if (!$limit) { + $limit = 3; + } + + // order + switch ($this->getAttribute('order')) { + case 'name ASC': + case 'name DESC': + case 'title ASC': + case 'title DESC': + case 'c_date ASC': + case 'c_date DESC': + case 'd_date ASC': + case 'd_date DESC': + case 'release_from ASC': + case 'release_from DESC': + $order = $this->getAttribute('order'); + break; + + default: + $order = 'release_from DESC'; + break; + } + + $children = QUI\Projects\Site\Utils::getSitesByInputList( + $this->getProject(), + $this->getAttribute('site'), + array( + 'limit' => $limit, + 'order' => $order + ) + ); + + $Engine->assign(array( + 'this' => $this, + 'children' => $children + )); + + return $Engine->fetch(dirname(__FILE__) . '/SideBox3.html'); + } +} diff --git a/src/QUI/Bricks/Controls/SideBox3TitleTop.html b/src/QUI/Bricks/Controls/SideBox3TitleTop.html new file mode 100644 index 0000000..dd9b9af --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox3TitleTop.html @@ -0,0 +1,55 @@ + +{if $this->getAttribute('header-title') && $this->getAttribute('header-short')} +<header> + <h2>{$this->getAttribute('header-title')}</h2> + <p>{$this->getAttribute('header-short')}</p> +</header> +{/if} + +<div class="{$this->getAttribute('grid-class-row')}"> + + {foreach from=$children item=Site key=key} + <article class="{$this->getAttribute('grid-class-article')}"> + {if $this->getAttribute( 'showTitle' ) || $this->getAttribute( 'showShort' )} + <header> + {if $this->getAttribute( 'showTitle' )} + <h3> + <a href="{url site=$Site}"> + {$Site->getAttribute('title')} + </a> + </h3> + {/if} + </header> + {/if} + + {if $this->getAttribute( 'showImage' )} + <a href="{url site=$Site}" class="image"> + {image src=$Site->getAttribute('image_site') width=640} + </a> + {/if} + + {if $this->getAttribute( 'showShort' )} + <p> + {text_passage text=$Site->getAttribute('short') start=0 end=120 striphtml=true append="..."} + </p> + {/if} + + {if $this->getAttribute( 'showContent' )} + {$Site->getAttribute('content')} + {/if} + + <footer> + <a href="{url site=$Site}" class="button"> + {locale group="quiqqer/bricks" var="continue.reading"} + </a> + </footer> + </article> + + {assign var=modKey value=$key+1} + {if $modKey && $modKey % 3 === 0} + </div> + <div class="{$this->getAttribute('grid-class-row')}"> + {/if} + + {/foreach} +</div> diff --git a/src/QUI/Bricks/Controls/SideBox3TitleTop.php b/src/QUI/Bricks/Controls/SideBox3TitleTop.php new file mode 100644 index 0000000..1198b3a --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox3TitleTop.php @@ -0,0 +1,68 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\SideBox3TitleTop + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class SocialBox + * + * @package quiqqer/bricks + */ +class SideBox3TitleTop extends QUI\Bricks\Controls\SideBox3 +{ + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $limit = $this->getAttribute('limit'); + + if (!$limit) { + $limit = 3; + } + + // order + switch ($this->getAttribute('order')) { + case 'name ASC': + case 'name DESC': + case 'title ASC': + case 'title DESC': + case 'c_date ASC': + case 'c_date DESC': + case 'd_date ASC': + case 'd_date DESC': + case 'release_from ASC': + case 'release_from DESC': + $order = $this->getAttribute('order'); + break; + + default: + $order = 'release_from DESC'; + break; + } + + $children = QUI\Projects\Site\Utils::getSitesByInputList( + $this->getProject(), + $this->getAttribute('site'), + array( + 'limit' => $limit, + 'order' => $order + ) + ); + + $Engine->assign(array( + 'this' => $this, + 'children' => $children + )); + + return $Engine->fetch(dirname(__FILE__) . '/SideBox3TitleTop.html'); + } +} diff --git a/src/QUI/Bricks/Controls/SideBox4.css b/src/QUI/Bricks/Controls/SideBox4.css new file mode 100644 index 0000000..bb88b01 --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox4.css @@ -0,0 +1,85 @@ +.quiqqer-bricks-sidebox4, +.quiqqer-bricks-sidebox4-row { + float: left; + width: 100%; +} + +.quiqqer-bricks-sidebox4-row { + display: flex; +} + +.quiqqer-bricks-sidebox4-article { + align-items: flex-start; + display: flex; + flex-direction: column; + float: left; + padding: 20px 15px 0 15px; + text-align: center; + width: 25%; +} +.quiqqer-bricks-sidebox4-article:first-child { + padding-left: 0; +} + +.quiqqer-bricks-sidebox4-article:last-child { + padding-right: 0; +} + +.sidebox4-container { + -webkit-border-radius: 15px; + -moz-border-radius: 15px; + border-radius: 15px; + overflow: hidden; + max-width: 100%; + height: 180px; +} + + +.sidebox4-container-image { + -webkit-border-radius: 15px; + -moz-border-radius: 15px; + border-radius: 15px; + width: 100%; + height: auto; +} + +header { + width: 100%; + padding: 15px 0; +} + +h3.sidebox4-header { + width: 100%; + text-overflow: ellipsis; + white-space: nowrap; + overflow: hidden; + font-weight: normal; + + margin-top: auto; +} + +.quiqqer-bricks-sidebox4-content { + margin-bottom: 20px; +} + +.article-button { + margin: 0 auto; + margin-top: auto; +} + + +@media screen and (max-width: 736px) { + .quiqqer-bricks-sidebox4-row { + display: block; + flex: none; + } + + .quiqqer-bricks-sidebox4-article { + display: block; + clear: both; + flex: none; + padding: 10px; + width: 100% !important; + } + +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/SideBox4.html b/src/QUI/Bricks/Controls/SideBox4.html new file mode 100644 index 0000000..98333e8 --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox4.html @@ -0,0 +1,55 @@ + +<div class="quiqqer-bricks-sidebox4"> + + {if $this->getAttribute('content')} + <div class="quiqqer-bricks-sidebox4-content"> + {$this->getAttribute('content')} + </div> + {/if} + + <div class="quiqqer-bricks-sidebox4-row"> + + {foreach from=$children item=Child key=key} + <article class="quiqqer-bricks-sidebox4-article"> + + + {if $this->getAttribute( 'showImage' )} + {image src=$Child->getAttribute('image_site') width=650 class="sidebox4-container-image"} + {/if} + + {if $this->getAttribute( 'showTitle' ) || $this->getAttribute( 'showShort' )} + <header> + {if $this->getAttribute( 'showTitle' )} + <h3 class="sidebox4-header"> + {$Child->getAttribute('title')} + </h3> + {/if} + </header> + {/if} + + {if $this->getAttribute( 'showShort' )} + <p> + {text_passage text=$Child->getAttribute('short') start=0 end=120 striphtml=true append="..."} + </p> + {/if} + + {if $this->getAttribute( 'showContent' )} + {$Child->getAttribute('content')} + {/if} + + <footer class="article-button"> + <a href="{url site=$Child}" class="sidebox-button"> + {locale group="quiqqer/bricks" var="continue.reading"} + </a> + </footer> + </article> + + {assign var=modKey value=$key+1} + {if $modKey && $modKey % 4 === 0 && !$Child@last} + </div> + <div class="quiqqer-bricks-sidebox4-row"> + {/if} + + {/foreach} + </div> +</div> diff --git a/src/QUI/Bricks/Controls/SideBox4.php b/src/QUI/Bricks/Controls/SideBox4.php new file mode 100644 index 0000000..deee65c --- /dev/null +++ b/src/QUI/Bricks/Controls/SideBox4.php @@ -0,0 +1,91 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\SideBox4 + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class SocialBox + * + * @package quiqqer/bricks + */ +class SideBox4 extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'showImage' => true, + 'showTitle' => true, + 'showDescription' => true, + 'showContent' => false, + 'site' => false, + 'limit' => 4, + 'order' => 'release_from DESC' + )); + + $this->addCSSFile(dirname(__FILE__) . '/SideBox4.css'); + + parent::__construct($attributes); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $limit = $this->getAttribute('limit'); + + if (!$limit) { + $limit = 3; + } + + // order + switch ($this->getAttribute('order')) { + case 'name ASC': + case 'name DESC': + case 'title ASC': + case 'title DESC': + case 'c_date ASC': + case 'c_date DESC': + case 'd_date ASC': + case 'd_date DESC': + case 'release_from ASC': + case 'release_from DESC': + $order = $this->getAttribute('order'); + break; + + default: + $order = 'release_from DESC'; + break; + } + + $children = QUI\Projects\Site\Utils::getSitesByInputList( + $this->getProject(), + $this->getAttribute('site'), + array( + 'limit' => $limit, + 'order' => $order + ) + ); + + $Engine->assign(array( + 'this' => $this, + 'children' => $children + )); + + return $Engine->fetch(dirname(__FILE__) . '/SideBox4.html'); + } +} diff --git a/src/QUI/Bricks/Controls/SimpleGoogleMaps.css b/src/QUI/Bricks/Controls/SimpleGoogleMaps.css new file mode 100644 index 0000000..fe7229d --- /dev/null +++ b/src/QUI/Bricks/Controls/SimpleGoogleMaps.css @@ -0,0 +1,7 @@ +#SimpleGoogleMaps { + background: none; + border: none; + display: block; + height: 300px; + width: 100%; +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/SimpleGoogleMaps.html b/src/QUI/Bricks/Controls/SimpleGoogleMaps.html new file mode 100644 index 0000000..50c13b5 --- /dev/null +++ b/src/QUI/Bricks/Controls/SimpleGoogleMaps.html @@ -0,0 +1 @@ +<iframe id="SimpleGoogleMaps" src="{$url}"></iframe> \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/SimpleGoogleMaps.php b/src/QUI/Bricks/Controls/SimpleGoogleMaps.php new file mode 100644 index 0000000..01d0256 --- /dev/null +++ b/src/QUI/Bricks/Controls/SimpleGoogleMaps.php @@ -0,0 +1,64 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\SimpleGoogleMaps + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class SimpleGoogleMaps + * + * @package quiqqer/bricks + */ +class SimpleGoogleMaps extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'title' => '' + )); + + parent::__construct($attributes); + + $this->addCSSFile( + dirname(__FILE__) . '/SimpleGoogleMaps.css' + ); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $brickTitle = $this->getAttribute('title'); + $brickStreet = $this->getAttribute('street'); + $brickZip = $this->getAttribute('zip'); + $brickCity = $this->getAttribute('city'); + $zoom = $this->getAttribute('zoom'); + + $query = http_build_query(array( + 'key' => trim($this->getAttribute('api')), + 'q' => "{$brickTitle},{$brickZip},{$brickStreet},{$brickCity}" + )); + + $url = 'https://www.google.com/maps/embed/v1/place?' . $query . "&zoom=" . $zoom . "&"; + + $Engine->assign(array( + 'url' => $url + )); + + return $Engine->fetch(dirname(__FILE__) . '/SimpleGoogleMaps.html'); + } +} diff --git a/src/QUI/Bricks/Controls/SocialBox.css b/src/QUI/Bricks/Controls/SocialBox.css new file mode 100644 index 0000000..e0bd6bb --- /dev/null +++ b/src/QUI/Bricks/Controls/SocialBox.css @@ -0,0 +1,69 @@ +.quiqqer-bricks-socialbox { + list-style-type: none; + margin: 0; + padding: 0; +} + +.quiqqer-bricks-socialbox li { + float: left; + margin: 0 0.75em 0.75em 0; +} + +.quiqqer-bricks-socialbox li a { + background-color: #888; + border-radius: 5px; + color: #fff; + display: inline-block; + height: 3em; + text-align: center; + width: 3em; +} + +.quiqqer-bricks-socialbox li a:hover { + opacity: 0.5; +} + +.quiqqer-bricks-socialbox .fa { + font-size: 2em; + line-height: 1.5; +} + +/** styling for footer + * ========================================================== */ + +footer .quiqqer-bricks-socialbox li a{ + float: left; + margin: 0 0.2em 0em 0.2em; + opacity: 0.5; +} + +footer .quiqqer-bricks-socialbox li a:hover { + opacity: 1; +} + +footer .quiqqer-bricks-socialbox ul { + list-style-type: none; + margin: 0; + padding: 0; +} + +footer .quiqqer-bricks-socialbox li a { + background-color: #dd151b; + border-radius: 5px; + color: #fff; + display: inline-block; + height: 2.5em; + text-align: center; + width: 2.5em; +} + +footer .quiqqer-bricks-socialbox .fa { + font-size: 1.5em; + line-height: 1.7; + transition: all .3s ease .15s; +} + +footer .quiqqer-bricks-socialbox li a:hover { + box-shadow: none !important; + +} \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/SocialBox.html b/src/QUI/Bricks/Controls/SocialBox.html new file mode 100644 index 0000000..74795ec --- /dev/null +++ b/src/QUI/Bricks/Controls/SocialBox.html @@ -0,0 +1,18 @@ +<ul class="quiqqer-bricks-socialbox"> + + {foreach from=$socialList item=entry} + {if isset( $entry.url ) && isset( $entry.background ) && isset( $entry.icon ) } + <li> + <a href="{$entry.url}" + target="_blank" + rel="nofollow" + style="background-color: {$entry.background}" + class="smooth" + > + <span class="{$entry.icon}"></span> + </a> + </li> + {/if} + {/foreach} + +</ul> \ No newline at end of file diff --git a/src/QUI/Bricks/Controls/SocialBox.php b/src/QUI/Bricks/Controls/SocialBox.php new file mode 100644 index 0000000..0f6f2e3 --- /dev/null +++ b/src/QUI/Bricks/Controls/SocialBox.php @@ -0,0 +1,59 @@ +<?php + +/** + * This file contains QUI\Bricks\Controls\SocialBox + */ + +namespace QUI\Bricks\Controls; + +use QUI; + +/** + * Class SocialBox + * + * @package quiqqer/bricks + */ +class SocialBox extends QUI\Control +{ + /** + * constructor + * + * @param array $attributes + */ + public function __construct($attributes = array()) + { + // default options + $this->setAttributes(array( + 'title' => 'Social', + 'socialList' => false + )); + + parent::__construct($attributes); + + $this->addCSSFile( + dirname(__FILE__) . '/SocialBox.css' + ); + } + + /** + * (non-PHPdoc) + * + * @see \QUI\Control::create() + */ + public function getBody() + { + $Engine = QUI::getTemplateManager()->getEngine(); + $socialList = $this->getAttribute('socialList'); + + if ($socialList) { + $socialList = json_decode($socialList, true); + } + + $Engine->assign(array( + 'this' => $this, + 'socialList' => $socialList + )); + + return $Engine->fetch(dirname(__FILE__) . '/SocialBox.html'); + } +} diff --git a/src/QUI/Bricks/Events.php b/src/QUI/Bricks/Events.php new file mode 100644 index 0000000..1cd3eb7 --- /dev/null +++ b/src/QUI/Bricks/Events.php @@ -0,0 +1,153 @@ +<?php + +/** + * This file contains \QUI\Bricks\Events + */ + +namespace QUI\Bricks; + +use QUI; +use QUI\Projects\Site; +use QUI\Projects\Site\Edit; + +/** + * Class Events + * + * @package quiqqer/bricks + */ +class Events +{ + /** + * Event : on site save + * Create site brick cache, for inheritance + * + * @param Site|Edit $Site + */ + static function onSiteSave($Site) + { + QUI\Rights\Permission::checkPermission('quiqqer.bricks.assign'); + + + $areas = $Site->getAttribute( 'quiqqer.bricks.areas' ); + $areas = json_decode( $areas, true ); + + if ( !$areas || empty( $areas ) ) { + return; + } + + $Manager = Manager::init(); + + // get inharitance areas + $Project = $Site->getProject(); + $projectAreas = $Manager->getAreasByProject( $Project ); + $projectTable = QUI::getDBProjectTableName( Manager::TABLE_CACHE, $Project ); + + + foreach ( $projectAreas as $area ) + { + if ( !$area[ 'inheritance' ] ) { + continue; + } + + if ( !isset( $areas[ $area[ 'name' ] ] ) ) { + continue; + } + + if ( empty( $areas[ $area[ 'name' ] ] ) ) { + continue; + } + + $bricks = $areas[ $area[ 'name' ] ]; + + // clear area and new data set + QUI::getDataBase()->delete($projectTable, array( + 'id' => $Site->getId(), + 'area' => $area[ 'name' ] + )); + + // check if deactivated + if ( isset( $bricks[ 0 ] ) && isset( $bricks[ 0 ][ 'deactivate' ] ) ) + { + QUI::getDataBase()->insert($projectTable, array( + 'id' => $Site->getId(), + 'area' => $area[ 'name' ], + 'brick' => -1 + )); + + continue; + } + + + foreach ( $bricks as $brick ) + { + $customFields = array(); + + if (isset($brick['customfields']) && is_string($brick['customfields'])) { + $customFields = json_decode($brick['customfields'], true); + } + + if (isset($brick['customfields']) && is_array($brick['customfields'])) { + $customFields = $brick['customfields']; + } + + if (!isset($customFields['inheritance']) || !(int)$customFields['inheritance']) { + continue; + } + + QUI::getDataBase()->insert($projectTable, array( + 'id' => $Site->getId(), + 'area' => $area[ 'name' ], + 'brick' => (int)$brick['brickId'] + )); + } + } + } + + /** + * Event : on smarty init + * add new brickarea function + */ + static function onSmartyInit($Smarty) + { + // {brickarea} + if ( !isset( $Smarty->registered_plugins['function'] ) || + !isset( $Smarty->registered_plugins['function']['brickarea'] ) + ) + { + $Smarty->registerPlugin("function", "brickarea", "\QUI\Bricks\Events::brickarea"); + } + } + + /** + * Smarty brickarea function {brickarea} + * + * @param Array $params - function parameter + * @param \Smarty + */ + static function brickarea($params, $smarty) + { + if ( !isset( $params['Site'] ) || !isset( $params['area'] ) ) + { + if ( !isset( $params['assign'] ) ) { + return array(); + } + + $smarty->assign( $params['assign'], array() ); + return; + } + + + $BricksManager = \QUI\Bricks\Manager::init(); + + $Site = $params['Site']; + $area = $params['area']; + + $result = $BricksManager->getBricksByArea( $area, $Site ); + + if ( !isset( $params['assign'] ) ) { + return $result; + } + + $smarty->assign( $params['assign'], $result ); + } +} \ No newline at end of file diff --git a/src/QUI/Bricks/Manager.php b/src/QUI/Bricks/Manager.php new file mode 100644 index 0000000..4a3a7b7 --- /dev/null +++ b/src/QUI/Bricks/Manager.php @@ -0,0 +1,707 @@ +<?php + +/** + * This file contains \QUI\Bricks\Manager + */ + +namespace QUI\Bricks; + +use QUI; +use QUI\Projects\Project; +use QUI\Projects\Site; + +/** + * Brick Manager + * + * @package quiqqer/bricks + */ +class Manager +{ + /** + * Bricks table name + */ + const TABLE = 'bricks'; + + /** + * Brick Cache table name + */ + const TABLE_CACHE = 'bricksCache'; + + /** + * Brick temp collector + * + * @var array + */ + protected $_bricks = array(); + + /** + * Initialized brick manager + * + * @var null + */ + static $_BrickManager = null; + + /** + * Return the global QUI\Bricks\Manager + * + * @return Manager + */ + static function init() + { + if (is_null(self::$_BrickManager)) { + self::$_BrickManager = new QUI\Bricks\Manager(true); + } + + return self::$_BrickManager; + } + + /** + * Constructor + * Please use \QUI\Bricks\Manager::init() + * + * @param boolean $init - please use \QUI\Bricks\Manager::init() + */ + public function __construct($init = false) + { + if ($init === false) { + QUI\System\Log::addWarning('Please use \QUI\Bricks\Manager::init()'); + } + } + + /** + * Creates a new brick for the project + * + * @param Project $Project + * @param Brick $Brick + * + * @return integer - Brick-ID + */ + public function createBrickForProject(Project $Project, Brick $Brick) + { + QUI\Rights\Permission::checkPermission('quiqqer.bricks.create'); + + + QUI::getDataBase()->insert( + $this->getTable(), + array( + 'project' => $Project->getName(), + 'lang' => $Project->getLang(), + 'title' => $Brick->getAttribute('title'), + 'description' => $Brick->getAttribute('description'), + 'type' => $Brick->getAttribute('type') + ) + ); + + $lastId = QUI::getPDO()->lastInsertId(); + + return $lastId; + } + + /** + * CLears the bricks cache + */ + public function clearCache() + { + QUI\Cache\Manager::clear('quiqqer/bricks'); + } + + /** + * Delete the brick + * + * @param Integer $brickId - Brick-ID + */ + public function deleteBrick($brickId) + { + QUI\Rights\Permission::checkPermission('quiqqer.bricks.delete'); + + // check if brick exist + $this->getBrickById($brickId); + + QUI::getDataBase()->delete($this->getTable(), array( + 'id' => $brickId + )); + } + + /** + * Return the areas which are available in the project + * + * @param Project $Project + * @param string|boolean $layoutType - optional, returns only the areas + * for the specific layout type + * (default = false) + * @return array + */ + public function getAreasByProject(Project $Project, $layoutType = false) + { + $templates = array(); + $bricks = array(); + + $projectName = $Project->getName(); + + if ($Project->getAttribute('template')) { + $templates[] = $Project->getAttribute('template'); + } + + // get all vhosts, and the used templates of the project + $vhosts = QUI::getRewrite()->getVHosts(); + + foreach ($vhosts as $vhost) { + if (!isset($vhost['template'])) { + continue; + } + + if ($vhost['project'] != $projectName) { + continue; + } + + $templates[] = $vhost['template']; + } + + $templates = array_unique($templates); + + // get bricks + foreach ($templates as $template) { + $brickXML = realpath(OPT_DIR . $template . '/bricks.xml'); + + if (!$brickXML) { + continue; + } + + $bricks = array_merge( + $bricks, + Utils::getTemplateAreasFromXML($brickXML, $layoutType) + ); + } + + // unque values + $cleaned = array(); + foreach ($bricks as $val) { + if (!isset($cleaned[$val['name']])) { + $cleaned[$val['name']] = $val; + } + } + + $bricks = array_values($cleaned); + + usort($bricks, function ($a, $b) { + + $transA = QUI::getLocale()->get( + $a['title']['group'], + $a['title']['var'] + ); + + $transB = QUI::getLocale()->get( + $b['title']['group'], + $b['title']['var'] + ); + + return $transA > $transB ? 1 : -1; + }); + + + QUI::getEvents()->fireEvent( + 'onBricksGetAreaByProject', + array($this, $Project, &$bricks) + ); + + return $bricks; + } + + /** + * Returns the available bricks + * + * @return array + */ + public function getAvailableBricks() + { + $cache = 'quiqqer/bricks/availableBricks'; + + try { + return QUI\Cache\Manager::get($cache); + + } catch (QUI\Exception $Exception) { + } + + $xmlFiles = $this->getBricksXMLFiles(); + $result = array(); + + $result[] = array( + 'title' => array('quiqqer/bricks', 'brick.content.title'), + 'description' => array( + 'quiqqer/bricks', + 'brick.content.description' + ), + 'control' => 'content' + ); + + foreach ($xmlFiles as $bricksXML) { + $result = array_merge($result, Utils::getBricksFromXML($bricksXML)); + } + + QUI\Cache\Manager::set($cache, $result); + + + return $result; + } + + /** + * Get a Brick by its Brick-ID + * + * @param Integer $id + * + * @return Brick + * @throws QUI\Exception + */ + public function getBrickById($id) + { + if (isset($this->_bricks[$id])) { + return $this->_bricks[$id]; + } + + $data = QUI::getDataBase()->fetch(array( + 'from' => $this->getTable(), + 'where' => array( + 'id' => (int)$id + ), + 'limit' => 1 + )); + + if (!isset($data[0])) { + throw new QUI\Exception('Brick not found'); + } + + $this->_bricks[$id] = new Brick($data[0]); + $this->_bricks[$id]->setAttribute('id', $id); + + return $this->_bricks[$id]; + } + + /** + * Return the available brick settings by the brick type + * + * @param $brickType + * + * @return array + */ + public function getAvailableBrickSettingsByBrickType($brickType) + { + if ($brickType == 'content') { + return array(); + } + + $cache = 'quiqqer/bricks/brickType/' . md5($brickType); + + try { + return QUI\Cache\Manager::get($cache); + + } catch (QUI\Exception $Exception) { + } + + + $settings = array(); + $xmlFiles = $this->getBricksXMLFiles(); + + foreach ($xmlFiles as $brickXML) { + $Dom = QUI\Utils\XML::getDomFromXml($brickXML); + $Path = new \DOMXPath($Dom); + + $Settings = $Path->query( + "//quiqqer/bricks/brick[@control='{$brickType}']/settings/setting" + ); + + if (!$Settings->length) { + continue; + } + + foreach ($Settings as $Setting) { + /* @var $Setting \DOMElement */ + /* @var $Option \DOMElement */ + + $options = false; + + if ($Setting->getAttribute('type') == 'select') { + $optionElements = $Setting->getElementsByTagName('option'); + + foreach ($optionElements as $Option) { + $options[] = array( + 'value' => $Option->getAttribute('value'), + 'text' => QUI\Utils\DOM::getTextFromNode($Option, false) + ); + } + } + + $settings[] = array( + 'name' => $Setting->getAttribute('name'), + 'text' => QUI\Utils\DOM::getTextFromNode($Setting, false), + 'type' => $Setting->getAttribute('type'), + 'class' => $Setting->getAttribute('class'), + 'data-qui' => $Setting->getAttribute('data-qui'), + 'options' => $options + ); + } + + break; + } + + QUI\Cache\Manager::set($cache, $settings); + + return $settings; + } + + /** + * Return the bricks from the area + * + * @param string $brickArea - Name of the area + * @param Site $Site + * + * @return array + */ + public function getBricksByArea($brickArea, Site $Site) + { + if (empty($brickArea)) { + return array(); + } + + $brickAreas = $Site->getAttribute('quiqqer.bricks.areas'); + $brickAreas = json_decode($brickAreas, true); + + if (!isset($brickAreas[$brickArea]) || empty($brickAreas[$brickArea])) { + $bricks = $this->getInheritedBricks($brickArea, $Site); + + } else { + $bricks = array(); + $brickData = $brickAreas[$brickArea]; + + foreach ($brickData as $brick) { + if (isset($brick['deactivate'])) { + break; + } + + $bricks[] = $brick; + } + } + + + $result = array(); + + foreach ($bricks as $brickData) { + $brickId = (int)$brickData['brickId']; + + try { + $Brick = $this->getBrickById($brickId); + + if (isset($brickData['customfields']) + && !empty($brickData['customfields']) + ) { + $custom = json_decode($brickData['customfields'], true); + + if ($custom) { + $Brick->setSettings($custom); + } + } + + $result[] = $Brick->check(); + + } catch (QUI\Exception $Exception) { + QUI\System\Log::addWarning( + $Exception->getMessage() . ' Brick-ID:' . $brickId + ); + } + } + + + return $result; + } + + /** + * Return a list with \QUI\Bricks\Brick which are assigned to a project + * + * @param Project $Project + * + * @return array + */ + public function getBricksFromProject(Project $Project) + { + $result = array(); + + $list = QUI::getDataBase()->fetch(array( + 'from' => $this->getTable(), + 'where' => array( + 'project' => $Project->getName(), + 'lang' => $Project->getLang() + ) + )); + + foreach ($list as $entry) { + $result[] = $this->getBrickById($entry['id']); + } + + return $result; + } + + /** + * @param string|integer $brickId - Brick-ID + * @param array $brickData - Brick data + */ + public function saveBrick($brickId, array $brickData) + { + QUI\Rights\Permission::checkPermission('quiqqer.bricks.edit'); + + $Brick = $this->getBrickById($brickId); + $areas = array(); + $areaString = ''; + + if (isset($brickData['id'])) { + unset($brickData['id']); + } + + // check areas + $Project = QUI::getProjectManager()->getProject( + $Brick->getAttribute('project') + ); + + $availableAreas = array_map(function ($data) { + if (isset($data['name'])) { + return $data['name']; + } + + return ''; + }, $this->getAreasByProject($Project)); + + if (isset($brickData['attributes']) + && isset($brickData['attributes']['areas']) + ) { + $brickData['areas'] = $brickData['attributes']['areas']; + } + + + if (isset($brickData['areas'])) { + $parts = explode(',', $brickData['areas']); + + foreach ($parts as $area) { + if (in_array($area, $availableAreas)) { + $areas[] = $area; + } + } + } + + if (!empty($areas)) { + $areaString = ',' . implode(',', $areas) . ','; + } + + $Brick->setAttributes($brickData); + + // fields + if (isset($brickData['attributes'])) { + foreach ($brickData['attributes'] as $key => $value) { + if ($key == 'areas') { + continue; + } + + $Brick->setAttribute($key, $value); + } + } + + // brick settings + if (isset($brickData['settings'])) { + $Brick->setSettings($brickData['settings']); + } + + + // custom fields + $customfields = array(); + + if (isset($brickData['customfields'])) { + $availableSettings = $Brick->getSettings(); + $availableSettings['width'] = true; + $availableSettings['height'] = true; + + foreach ($brickData['customfields'] as $customfield) { + $customfield = str_replace('flexible-', '', $customfield); + + if ($customfield == 'classes') { + $customfields[] = $customfield; + continue; + } + + if (isset($availableSettings[$customfield])) { + $customfields[] = $customfield; + } + } + } + + + // update + QUI::getDataBase()->update($this->getTable(), array( + 'title' => $Brick->getAttribute('title'), + 'description' => $Brick->getAttribute('description'), + 'content' => $Brick->getAttribute('content'), + 'type' => $Brick->getAttribute('type'), + 'settings' => json_encode($Brick->getSettings()), + 'customfields' => json_encode($customfields), + 'areas' => $areaString, + 'height' => $Brick->getAttribute('height'), + 'width' => $Brick->getAttribute('width'), + 'classes' => $Brick->getAttribute('classes') + ), array( + 'id' => (int)$brickId + )); + } + + /** + * Returns the bricks table name + * + * @return String + */ + protected function getTable() + { + return QUI::getDBTableName(self::TABLE); + } + + /** + * List of available bricks.xml files + * + * @return array + */ + protected function getBricksXMLFiles() + { + $cache = 'quiqqer/bricks/availableBrickFiles'; + + try { + return QUI\Cache\Manager::get($cache); + + } catch (QUI\Exception $Exception) { + } + + $PKM = QUI::getPackageManager(); + $Projects = QUI::getProjectManager(); + $packages = $PKM->getInstalled(); + $result = array(); + + // package bricks + foreach ($packages as $package) { + $bricksXML = OPT_DIR . $package['name'] . '/bricks.xml'; + + if (file_exists($bricksXML)) { + $result[] = $bricksXML; + } + } + + // project bricks + $projects = $Projects->getProjects(); + + foreach ($projects as $project) { + $bricksXML = USR_DIR . $project . '/bricks.xml'; + + if (file_exists($bricksXML)) { + $result[] = $bricksXML; + } + } + + + QUI\Cache\Manager::set($cache, $result); + + return $result; + } + + /** + * Return the bricks from an area which are inherited from its parents + * + * @param String $brickArea - Name of the area + * @param Site $Site - Site object + * + * @return array + */ + protected function getInheritedBricks($brickArea, Site $Site) + { + // inheritance ( vererbung ) + $Project = $Site->getProject(); + $areas = $this->getAreasByProject($Project); + + + foreach ($areas as $area) { + if ($area['name'] != $brickArea) { + continue; + } + + if (!$area['inheritance']) { + return array(); + } + + break; + } + + if (!isset($area) || !isset($area['name'])) { + return array(); + } + + if ($area['name'] != $brickArea) { + return array(); + } + + if (!Utils::hasInheritance($Project, $brickArea)) { + return array(); + } + + + $result = array(); + $parentIds = $Site->getParentIdTree(); + $parentIds = array_reverse($parentIds); + + $projectCacheTable = QUI::getDBProjectTableName( + self::TABLE_CACHE, + $Project + ); + + foreach ($parentIds as $parentId) { + $bricks = QUI::getDataBase()->fetch(array( + 'from' => $projectCacheTable, + 'where' => array( + 'id' => $parentId, + 'area' => $brickArea + ) + )); + + if (empty($bricks) || !is_array($bricks)) { + continue; + } + + try { + $Parent = $Project->get($parentId); + + } catch (QUI\Exception $Exception) { + continue; + } + + $parentAreas = $Parent->getAttribute('quiqqer.bricks.areas'); + $parentAreas = json_decode($parentAreas, true); + + + if (!isset($parentAreas[$brickArea])) { + continue; + } + + + $brickIds = array(); + $area = $parentAreas[$brickArea]; + + foreach ($bricks as $brick) { + $brickIds[$brick['brick']] = true; + } + + foreach ($area as $brick) { + if (isset($brickIds[$brick['brickId']])) { + $result[] = $brick; + } + } + + if (empty($result)) { + continue; + } + + break; + } + + return $result; + } +} diff --git a/src/QUI/Bricks/Utils.php b/src/QUI/Bricks/Utils.php new file mode 100644 index 0000000..9cf0a37 --- /dev/null +++ b/src/QUI/Bricks/Utils.php @@ -0,0 +1,184 @@ +<?php + +/** + * This file contains \QUI\Bricks\Utils + */ + +namespace QUI\Bricks; + +use QUI; +use QUI\Utils\XML; +use QUI\Projects\Project; + +/** + * Class Utils + * Bricks helper class + * + * @package QUI\Bricks + * @author www.pcsg.de (Henning Leutz) <support@pcsg.de> + */ +class Utils +{ + /** + * Return the bricks from a xml file + * + * @param String $file - path to file + * + * @return array + */ + public static function getBricksFromXML($file) + { + if (!file_exists($file)) { + return array(); + } + + $Dom = XML::getDomFromXml($file); + $Path = new \DOMXPath($Dom); + + $bricks = $Path->query("//quiqqer/bricks/brick"); + $list = array(); + + if (!$bricks->length) { + return $list; + } + + foreach ($bricks as $Brick) { + $list[] = self::parseAreaToArray($Brick, $Path); + } + + return $list; + } + + /** + * Return the template bricks from a xml file + * + * @param string $file - path to xm file + * @param string|bool $layoutType - optional, return only the bricks for the specific layout type + * + * @return array + */ + public static function getTemplateAreasFromXML($file, $layoutType = false) + { + if (!file_exists($file)) { + return array(); + } + + $Dom = XML::getDomFromXml($file); + $Path = new \DOMXPath($Dom); + + $globalAreas + = $Path->query("//quiqqer/bricks/templateAreas/areas/area"); + + if ($layoutType) { + $typeAreas = $Path->query( + "//quiqqer/bricks/templateAreas/layouts/layout[@layout='{$layoutType}']/area" + ); + + } else { + $typeAreas + = $Path->query("//quiqqer/bricks/templateAreas/layouts/layout/area"); + } + + + $list = array(); + + if ($globalAreas->length) { + foreach ($globalAreas as $Area) { + $list[] = self::parseAreaToArray($Area, $Path); + } + } + + if ($typeAreas->length) { + foreach ($typeAreas as $Area) { + $list[] = self::parseAreaToArray($Area, $Path); + } + } + + return $list; + } + + public static function getGlobalTemplateAreasFromXML() + { + + } + + /** + * @param $file + * @param $siteType + */ + public static function getTypeTemplateAreasFromXML($file, $siteType) + { + + } + + /** + * parse a <area> xml node to an array + * + * @param \DOMElement $Brick + * @param \DOMXPath $Path + * + * @return array + */ + public static function parseAreaToArray(\DOMElement $Brick, \DOMXPath $Path) + { + $control = $Brick->getAttribute('control'); + $name = $Brick->getAttribute('name'); + $title = array(); + $description = array(); + + $titleLocale = $Path->query('./title/locale', $Brick); + $descLocale = $Path->query('./description/locale', $Brick); + + if ($titleLocale->length) { + $title = array( + 'group' => $titleLocale->item(0)->getAttribute('group'), + 'var' => $titleLocale->item(0)->getAttribute('var') + ); + } + + if ($descLocale->length) { + $description = array( + 'group' => $descLocale->item(0)->getAttribute('group'), + 'var' => $descLocale->item(0)->getAttribute('var') + ); + } + + return array( + 'control' => $control, + 'name' => $name, + 'title' => $title, + 'description' => $description, + 'inheritance' => $Brick->getAttribute('inheritance') + ); + } + + /** + * + * @param Project $Project + * @param String $areaName + * + * @return bool + */ + public static function hasInheritance(Project $Project, $areaName) + { + $template = $Project->getAttribute('template'); + + // getAreasByProject + $brickXML = realpath(OPT_DIR . $template . '/bricks.xml'); + $bricks = self::getTemplateAreasFromXML($brickXML); + + foreach ($bricks as $brickData) { + if ($brickData['name'] != $areaName) { + continue; + } + + if (isset($brickData['inheritance']) && $brickData['inheritance']) { + return true; + } + + return false; + } + + return true; + } +} -- GitLab