Skip to content
Code-Schnipsel Gruppen Projekte
Commit 15aa42fd erstellt von Henning Leutz's avatar Henning Leutz :martial_arts_uniform:
Dateien durchsuchen

PSR-2 -> lib to src

Übergeordneter 741ffac0
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
werden angezeigt mit 1802 Ergänzungen und 0 Löschungen
.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;
}
}
{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>
<?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');
}
}
{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>
<?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');
}
}
.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
<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>
<?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');
}
}
#SimpleGoogleMaps {
background: none;
border: none;
display: block;
height: 300px;
width: 100%;
}
\ No newline at end of file
<iframe id="SimpleGoogleMaps" src="{$url}"></iframe>
\ No newline at end of file
<?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');
}
}
.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
<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
<?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');
}
}
<?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
<?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;
}
}
<?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;
}
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren