| #0 | PDOStatement->execute |
| #1 | Phalcon\Db\Adapter\Pdo\AbstractPdo->executePrepared |
| #2 | Phalcon\Db\Adapter\Pdo\AbstractPdo->query |
| #3 | Phalcon\Mvc\Model\Query->executeSelect |
| #4 | Phalcon\Mvc\Model\Query->execute |
| #5 | Phalcon\Mvc\Model::find
/var/www/html/clsystems.nl/src/app/Lib/Mvc/Model/ModelBase.php (227) <?php
namespace CLSystems\PhalCMS\Lib\Mvc\Model;
use CLSystems\Php\Registry;
use Phalcon\Mvc\Model;
use CLSystems\PhalCMS\Lib\Helper\StringHelper;
use CLSystems\PhalCMS\Lib\Helper\Date;
use CLSystems\PhalCMS\Lib\Helper\User;
use CLSystems\PhalCMS\Lib\Helper\Language;
use CLSystems\PhalCMS\Lib\Form\Form;
use CLSystems\PhalCMS\Lib\Form\FormsManager;
class ModelBase extends Model
{
/** @var string */
protected $titleField = null;
/** @var string */
protected $standardMetadata = false;
public function getTitleField()
{
return $this->titleField;
}
public function getParamsFormsManager()
{
return new FormsManager;
}
public function getIgnorePrefixModelName()
{
return str_replace('CLSystems\\PhalCMS\\Lib\\Mvc\\Model\\', '', get_class($this));
}
public function getOrderFields()
{
return [];
}
public function getSearchFields()
{
return $this->titleField ? [$this->titleField] : [];
}
public function getFilterForm()
{
return new Form('FilterForm', __DIR__ . '/Form/' . $this->getIgnorePrefixModelName() . '/Filter.php');
}
public function getFormsManager()
{
$formsManager = new FormsManager;
$formsManager->set('general', new Form(
'FormData',
__DIR__ . '/Form/' . $this->getIgnorePrefixModelName() . '/General.php'
));
return $formsManager;
}
public function checkin()
{
if ($this->id && $this->standardMetadata) {
$this->assign(
[
'checkedAt' => Date::getInstance()->toSql(),
'checkedBy' => User::getInstance()->id,
]
)->save();
}
return $this;
}
public function checkout()
{
if ($this->id && $this->standardMetadata) {
$this->assign(
[
'checkedAt' => null,
'checkedBy' => 0,
]
)->save();
}
return $this;
}
public function isCheckedIn()
{
if ($this->standardMetadata) {
return $this->checkedAt && $this->checkedBy;
}
return false;
}
public function delete() : bool
{
if (!property_exists($this, 'id')) {
return parent::delete();
}
if ($result = parent::delete()) {
$thisId = (int)$this->id;
if ($this instanceof UcmItem) {
$this->_modelsManager->executeQuery('DELETE FROM ' . UcmItemMap::class . ' WHERE itemId1 = ' . $thisId);
} elseif ($this instanceof UcmComment) {
$this->_modelsManager->executeQuery('DELETE FROM ' . UcmComment::class . ' WHERE parentId = ' . $thisId);
}
}
return $result;
}
public function copy()
{
/** @var ModelBase $entity */
$data = $this->toArray();
unset($data['id']);
$class = get_class($this);
$entity = new $class;
if ($title = $this->getTitleField()) {
$data[$title] = StringHelper::increment($data[$title]);
}
if (isset($data['state'])) {
$data['state'] = 'U';
}
if (property_exists($this, 'createdAt')) {
$data['createdAt'] = Date::getInstance()->toSql();
}
$entity->assign($data);
return $entity->save() ? $entity : false;
}
public function beforeSave()
{
$paramsFormsManager = $this->getParamsFormsManager();
if ($paramsFormsManager->count()) {
foreach ($paramsFormsManager->getForms() as $paramName => $paramForm) {
if (property_exists($this, $paramName) && !is_string($this->{$paramName})) {
if ($this->{$paramName} instanceof Registry) {
$this->{$paramName} = $this->{$paramName}->toString();
} else {
$this->{$paramName} = json_encode($this->{$paramName});
}
}
}
}
}
public function beforeUpdate()
{
if ('cli' !== php_sapi_name() && $this->hasStandardMetadata()) {
$this->assign(
[
'modifiedAt' => Date::getInstance()->toSql(),
'modifiedBy' => User::getInstance()->id,
]
);
}
}
public function hasStandardMetadata()
{
return $this->standardMetadata;
}
public function getRelatedItems()
{
$relatedItems = null;
if ($this->tagContext && $this->tags->count()) {
$tagIds = [];
foreach ($this->tags as $tag) {
$tagIds[] = (int)$tag->id;
}
$relatedItems = $this->getModelsManager()
->createBuilder()
->from(['item' => get_class($this)])
->innerJoin(UcmItemMap::class, 'ItemTagMap.itemId1 = item.id', 'ItemTagMap')
->innerJoin(Tag::class, 'ItemTag.id = ItemTagMap.itemId2', 'ItemTag')
->where(
'ItemTagMap.context= :context: AND ItemTagMap.itemId1 <> :notId: AND ItemTag.id IN({tagIds:array})',
[
'context' => $this->tagContext,
'notId' => $this->id,
'tagIds' => $tagIds,
]
)
->getQuery()
->execute();
}
return $relatedItems;
}
public function getTranslations($language = null, $asArray = false)
{
$refKey = $this->id;
if (null === $language) {
$language = Language::getLanguageQuery();
}
if (empty($refKey) || '*' === $language) {
return [];
}
static $translations = [];
$refTable = preg_replace('/^' . preg_quote($this->_modelsManager->getModelPrefix(), '/')
. '/', '', $this->getSource(), 1);
$tranKey = $refTable . ':' . $refKey . ':' . $language;
if (!isset($translations[$tranKey . '_array'])) {
$entities = Translation::find(
[
'conditions' => 'translationId LIKE :translationId:',
'bind' => [
'translationId' => $language . '.' . $refTable . '.id=' . $refKey . '.%',
],
]
);
if ($entities->count()) {
foreach ($entities as $entity) {
[$langCode, $refTable, $refKey, $refField] = explode('.', $entity->translationId);
$translations[$tranKey . '_value'][$refField] = $entity->translatedValue;
$translations[$tranKey . '_array'][] = [
'language' => $langCode,
'refTable' => $refTable,
'refKey' => $refKey,
'refField' => $refField,
'originalValue' => $entity->originalValue,
'translatedValue' => $entity->translatedValue,
];
}
} else {
$translations[$tranKey . '_array'] = [];
$translations[$tranKey . '_value'] = [];
}
}
return $translations[$asArray ? $tranKey . '_array' : $tranKey . '_value'];
}
protected function afterDelete()
{
$prefix = $this->getModelsManager()->getModelPrefix();
$refTable = str_replace($prefix, '', $this->getIgnorePrefixModelName());
$this->getDI()->get('db')->execute(
'DELETE FROM ' . $prefix . 'translations WHERE translationId LIKE :translationId',
[
'translationId' => '%.' . $refTable . '.id:' . $this->id . '.%',
]
);
}
public function t($field)
{
$translations = $this->getTranslations();
if (isset($translations[$field])) {
return $translations[$field];
}
return $this->{$field};
}
public function controllerBeforeBindData(&$rawData)
{
// Todo something
}
public function controllerDoBeforeSave(&$validData)
{
// Todo something
}
public function controllerDoAfterSave($validData)
{
// Todo something
}
}
|
| #6 | CLSystems\PhalCMS\Lib\Mvc\Model\ModelBase->getTranslations
/var/www/html/clsystems.nl/src/app/Lib/Mvc/Model/UcmItem.php (395) <?php
namespace CLSystems\PhalCMS\Lib\Mvc\Model;
use Phalcon\Db\Adapter\Pdo\Mysql;
use CLSystems\PhalCMS\Lib\Helper\Date as DateHelper;
use CLSystems\PhalCMS\Lib\Helper\Event as EventHelper;
use CLSystems\PhalCMS\Lib\Helper\UcmItem as UcmItemHelper;
use CLSystems\PhalCMS\Lib\Helper\StringHelper;
use CLSystems\PhalCMS\Lib\Helper\Uri;
use CLSystems\PhalCMS\Lib\Helper\User as UserHelper;
use CLSystems\PhalCMS\Lib\Helper\Language;
use CLSystems\PhalCMS\Lib\Form\FormsManager;
use CLSystems\PhalCMS\Lib\Form\Form;
use CLSystems\PhalCMS\Lib\Factory;
use CLSystems\Php\Registry;
use CLSystems\Php\Filter;
use Phalcon\Mvc\Model\ResultsetInterface;
use stdClass;
class UcmItem extends ModelBase
{
/**
* @var integer
*/
public $id;
/**
* @var integer
*/
public $parentId;
/**
* @var string
*/
public $context;
/**
* @var string
*/
public $title;
/**
* @var string
*/
public $route;
/**
* @var integer
*/
public $state;
/**
* @var string
*/
public $image;
/**
*
* @var string
*/
public $summary;
/**
* @var string
*/
public $description;
/**
* @var string
*/
public $createdAt;
/**
* @var integer
*/
public $createdBy = 0;
/**
*
* @var string
*/
public $modifiedAt = null;
/**
* @var integer
*/
public $modifiedBy = 0;
/**
* @var string
*/
public $checkedAt = null;
/**
* @var integer
*/
public $checkedBy = 0;
/**
* @var string
*/
public $metaTitle = '';
/**
* @var string
*/
public $metaKeys = '';
/**
* @var string
*/
public $metaDesc = '';
/**
*
* @var string[]
*/
protected $params;
/**
* @var integer
*/
public $ordering;
/**
* @var integer
*/
public $lft = 0;
/**
* @var integer
*/
public $rgt = 1;
/**
* @var integer
*/
public $level = 0;
/**
* @var integer
*/
public $hits = 0;
/**
* @var boolean
*/
public $hasRoute = false;
/**
* @var string
*/
protected $titleField = 'title';
/**
* @var boolean
*/
protected $standardMetadata = true;
/** @var array */
protected $fieldsData = [];
/** @var array */
protected $translationsFieldsData = [];
public function getParent()
{
return $this->getRelated('parent');
}
/**
* Initialize method for model.
*/
public function initialize()
{
$this->setSource('ucm_items');
}
public function getOrderFields()
{
return [
($this instanceof Nested ? 'lft' : 'ordering'),
'id',
'title',
'description',
'createdAt',
'createdBy',
];
}
public function getFilterForm()
{
return new Form('FilterForm', __DIR__ . '/Form/UcmItem/Filter.php');
}
public function getFormsManager()
{
$formsManager = new FormsManager;
$formsManager->set('general', new Form('FormData', __DIR__ . '/Form/UcmItem/General.php'));
$formsManager->set('aside', new Form('FormData', __DIR__ . '/Form/UcmItem/Aside.php'));
$formsManager->set('metadata', new Form('FormData', __DIR__ . '/Form/Metadata/Metadata.php'));
return $formsManager;
}
public function isContextPrefix($prefix)
{
return preg_match('/^' . $prefix . '/', $this->context) ? true : false;
}
public function isContextSuffix($suffix)
{
return preg_match('/-' . $suffix . '$/', $this->context) ? true : false;
}
public function prepareFormsManager(FormsManager $formsManager)
{
$asideForm = $formsManager->get('aside');
if ($this->id
&& $asideForm->has('tags')
&& ($tags = $this->getRelated('tags'))->count()
)
{
$tagIds = [];
/**
* @var Tag $tag
*/
foreach ($tags as $tag)
{
$tagIds[] = (int)$tag->id;
}
$asideForm->getField('tags')->setValue($tagIds);
}
}
public function controllerDoBeforeSave(&$validData)
{
if ($this->id == $this->parentId)
{
$this->parentId = 0;
}
parent::beforeSave();
}
public function beforeSave()
{
if (is_array($this->image))
{
$this->image = json_encode($this->image);
}
parent::beforeSave();
}
public function beforeUpdate()
{
// Only set metadata if not already set (e.g., by API)
if ('cli' !== php_sapi_name() && $this->hasStandardMetadata()) {
if (empty($this->modifiedAt)) {
$this->modifiedAt = DateHelper::getInstance()->toSql();
}
if (empty($this->modifiedBy) || $this->modifiedBy == 0) {
$this->modifiedBy = UserHelper::getInstance()->id;
}
}
}
public function controllerDoAfterSave($validData)
{
$isCategory = $this->isContextSuffix('category');
$modelsManager = $this->getModelsManager();
$dbo = Factory::getService('db');
$source = $this->getSource();
if ($this->hasRoute && empty($this->route))
{
if ($this->parentId && ($parent = self::findFirst('id = ' . (int)$this->parentId)))
{
$route = Filter::toPath($parent->route . '/' . $this->title);
}
else
{
$prefix = $isCategory ? '' : $this->context . '/';
$route = $prefix . Filter::toSlug($this->title);
}
// Don't use Phalcon Update or Save.
// Because Phalcon has conflicts with array references (hasBelongsTo, hasMany...)
$dbo->query('UPDATE `' . $source . '` SET `route` = :route WHERE `id` = :id', [
'route' => $route,
'id' => (int)$this->id,
]);
}
$modelsManager->executeQuery(
'DELETE FROM ' . UcmItemMap::class . ' WHERE itemId1 = :itemId1: AND context = :context:',
[
'itemId1' => $this->id,
'context' => 'tag',
]
);
if (!empty($validData['tags']))
{
foreach (Filter::clean($validData['tags'], 'unique') as $tagId)
{
$tagId = (int)$tagId;
if ($tagId > 0)
{
(new UcmItemMap)
->assign(
[
'itemId1' => $this->id,
'itemId2' => $tagId,
'context' => 'tag',
]
)->save();
}
}
}
$context = UcmItemHelper::prepareContext($this->context);
EventHelper::trigger('afterSaveUcm' . $context, [$this, $validData], ['Cms']);
}
public function delete() : bool
{
if ($result = parent::delete())
{
$context = UcmItemHelper::prepareContext($this->context);
$previousData = $this->toArray();
if ('cli' !== PHP_SAPI)
{
EventHelper::trigger('afterDeleteUcm' . $context, [$previousData], ['Cms']);
}
}
return $result;
}
public function hit($pk = null)
{
if (null === $pk)
{
$pk = $this->id;
}
$session = Factory::getService('session');
$hitsKey = $this->context . '.hits';
$hits = $session->get($hitsKey, []);
if (!isset($hits[$pk]))
{
$hits[$pk] = 1;
$session->set($hitsKey, $hits);
/** @var Mysql $db */
$db = $this->getDI()->get('db');
$db->execute('UPDATE ' . $this->getSource() . ' SET hits = hits + 1 WHERE id = :id', [
'id' => $pk,
]);
if ($pk == $this->id)
{
$this->hits++;
}
}
return $this;
}
public function t($field)
{
if (Uri::isClient('administrator'))
{
return $this->{$field};
}
static $translated = [];
$k = $this->id . $field;
if (!isset($translated[$k]))
{
$translationData = parent::getTranslations();
if (isset($translationData[$field]))
{
$value = $translationData[$field];
switch ($field)
{
case 'route':
if (empty($value))
{
$value = $this->route;
}
break;
case 'image':
if (empty($value) || in_array($value, ['[]', '{}']))
{
$value = $this->image;
}
break;
case 'params':
$tranValue = $value;
$value = new Registry($this->{$field});
$value->merge($tranValue);
break;
}
}
else
{
$value = $this->{$field};
}
$translated[$k] = $value;
}
return $translated[$k];
}
public function getLink()
{
return Uri::route($this->t('route'));
}
public function summary($fallbackDescStrLen = 100)
{
$summary = trim($this->t('summary'));
if (empty($summary))
{
$summary = StringHelper::truncate($this->t('description'), $fallbackDescStrLen);
}
return $summary;
}
public function rating()
{
$rating = Rating::findFirst([
'conditions' => 'externalMerchantId = :external_merchant_id: AND networkId = :network_id: ',
'bind' => [
'external_merchant_id' => $this->externalMerchantId,
'network_id' => $this->networkId,
],
]);
return $rating;
}
/**
* @return array
*/
public function vouchers()
{
return [];
$vouchers = [];
$voucherIds = [];
if ((int)$this->parentId === 117) // Merken
{
$vouchers = $this->find([
'conditions' => 'externalMerchantId = :external_merchant_id: AND networkId = :network_id: AND parentId = 118', // Kortingscodes
'bind' => [
'external_merchant_id' => $this->externalMerchantId,
'network_id' => $this->networkId,
],
])->toArray();
if (false === empty($vouchers))
{
$voucherIds = array_column($vouchers, 'id');
}
// $ads = Ad::find([
// 'conditions' => 'externalMerchantId = :external_merchant_id: AND sourceId = :source_id:',
// 'bind' => [
// 'external_merchant_id' => $this->externalMerchantId,
// 'source_id' => $this->sourceId,
// ],
// ])->toArray();
// $vouchers += $ads;
}
// Set one if there is a prefUrl
// if (0 === count($vouchers) && (int)$this->parentId === 117 && 0 < strlen($this->prefUrl))
if ((int)$this->parentId === 117 && 0 < strlen($this->prefUrl))
{
$voucherIds[] = $this->id;
$vouchers[] = $this->find([
'conditions' => 'externalId = :external_id: AND sourceId = :source_id:',
'bind' => [
'external_id' => $this->externalMerchantId,
'source_id' => $this->sourceId,
],
])->toArray();
}
// If both still empty, try to find an alternative
if (true === empty($voucherIds) && true === empty($vouchers))
{
$path = $this->route;
$parts = explode('-', $path);
foreach ($parts as $key => $part)
{
if (false !== stristr($part, 'kortingen'))
{
unset($parts[$key]);
}
if (false !== stristr($part, 'kortingscodes'))
{
unset($parts[$key]);
}
if (false !== stristr($part, 'aanbiedingen'))
{
unset($parts[$key]);
}
if (true === is_numeric($part))
{
unset($parts[$key]);
}
}
$newRoute = implode('-', $parts);
$post = UcmItem::findFirst([
'conditions' => "route LIKE '" . $newRoute . "%' AND route != '" . $this->route . "' AND LENGTH(prefUrl) >= 1 AND state = 'P'",
]);
if (null !== $post)
{
$voucherIds[] = $post->id;
$vouchers[] = $post->toArray();
}
}
if (false === empty($vouchers))
{
// $voucherIds += array_column($vouchers, 'id');
$vouchers = $this->find([
'conditions' => 'id IN (' . implode(',', $voucherIds) . ')',
]);
}
return $vouchers;
}
public function ads()
{
$ads = [];
if ((int)$this->parentId === 117) // Merken
{
$ads = Ad::find([
'conditions' => 'externalMerchantId = :external_merchant_id: AND sourceId = :source_id:',
'bind' => [
'external_merchant_id' => $this->externalMerchantId,
'source_id' => $this->sourceId,
],
])->toArray();
}
// Nothing found, set at least one if there is a prefUrl
if (0 === count($ads) && (int)$this->parentId === 117 && 0 < strlen($this->prefUrl))
{
$ads = $this->find([
'conditions' => 'externalId = :external_id: AND sourceId = :source_id:',
'bind' => [
'external_id' => $this->externalMerchantId,
'source_id' => $this->sourceId,
],
])->toArray();
}
if (false === empty($ads))
{
$adIds = array_column($ads, 'id', 'id');
$ads = Ad::find([
'conditions' => 'id IN (' . implode(',', $adIds) . ')',
]);
}
return $ads;
}
public function getFieldsData()
{
if (empty($this->fieldsData) && $this->id)
{
/** @var \Phalcon\Mvc\Model\Resultset\Simple $values */
$values = $this->getModelsManager()
->createBuilder()
->columns('name, fieldId, value')
->from(['fieldValue' => UcmFieldValue::class])
->innerJoin(UcmField::class, 'field.id = fieldValue.fieldId', 'field')
->where('field.context = :context:', ['context' => $this->context])
->andWhere('fieldValue.itemId = :thisId:', ['thisId' => $this->id])
->getQuery()
->execute();
if (0 < $values->count())
{
$fields = [];
foreach ($values as $value)
{
$this->fieldsData[$value->name] = $value->value;
$fields[$value->fieldId] = $value->name;
}
if (Language::isMultilingual())
{
$language = Language::getLanguageQuery();
$isSite = Uri::isClient('site');
if (Uri::isClient('site') && '*' === $language)
{
return $this->fieldsData;
}
// Find translation fields values
$query = $this->getModelsManager()
->createBuilder()
->from(Translation::class)
->columns('translationId, translatedValue')
->where('translationId LIKE :translationId:', [
'translationId' => ($isSite ? $language : '%') . '.ucm_field_values.fieldId=%,itemId=' . $this->id . '%',
]);
$trans = $query->getQuery()->execute();
if ($trans->count())
{
foreach ($trans as $tran)
{
$parts = explode('.', $tran->translationId);
$langCode = $parts[0];
$refKey = explode(',', $parts[2], 2);
$fieldId = str_replace('fieldId=', '', $refKey[0]);
if (isset($fields[$fieldId]))
{
$fieldName = $fields[$fieldId];
if ($isSite)
{
$this->translationsFieldsData[$fieldName] = $tran->translatedValue;
}
else
{
$this->translationsFieldsData[$fieldName][$langCode] = $tran->translatedValue;
}
}
}
}
}
}
}
return $this->fieldsData;
}
public function getTranslationsFieldsData()
{
return $this->translationsFieldsData;
}
public function getFieldValue($fieldName, $defaultValue = null)
{
$value = isset($this->translationsFieldsData[$fieldName])
? $this->translationsFieldsData[$fieldName]
: (isset($this->fieldsData[$fieldName]) ? $this->fieldsData[$fieldName] : $defaultValue);
if (strpos($value, '{') === 0 || strpos($value, '[') === 0)
{
$value = implode(', ', json_decode($value, true) ?: []);
}
return $value;
}
public function copy()
{
if ($result = parent::copy())
{
$fieldsValues = UcmFieldValue::find(
[
'conditions' => 'itemId = :itemId:',
'bind' => [
'itemId' => $this->id,
],
]
);
if ($fieldsValues->count())
{
$values = '';
$bind = [];
foreach ($fieldsValues as $fieldsValue)
{
$values .= '(?, ?, ?),';
$bind[] = $fieldsValue->fieldId;
$bind[] = $result->id;
$bind[] = $fieldsValue->value;
}
$source = $this->getModelsManager()->getModelPrefix() . 'ucm_field_values';
$this->getDI()->get('db')->execute('INSERT INTO ' . $source . ' (fieldId, itemId, value) VALUES ' . rtrim($values, ','), $bind);
}
}
return $result;
}
protected function afterDelete()
{
parent::afterDelete();
$source = $this->getModelsManager()->getModelPrefix() . 'ucm_field_values';
$this->getDI()->get('db')->execute('DELETE FROM ' . $source . ' WHERE itemId LIKE :itemId', [
'itemId' => $this->id,
]);
}
public function getParams()
{
if (!($this->params instanceof Registry))
{
$this->params = new Registry($this->params);
}
return $this->params;
}
}
|
| #7 | CLSystems\PhalCMS\Lib\Mvc\Model\UcmItem->t
/var/www/html/clsystems.nl/cache/volt/Widget_FlashNews_Tmpl_Content_BlogStack.volt.php (4) <div class="blog-stack">
<?php foreach ($posts as $post) { ?>
<div class="uk-card uk-background-muted uk-grid-collapse uk-margin" uk-grid>
<?php $image = CLSystems\PhalCMS\Lib\Helper\Image::loadImage($post->t('image')); ?>
<?php if (!empty($image)) { ?>
<?php $ratio = $image->getRatio(); ?>
<div class="uk-card-media-left uk-cover-container uk-width-1-3">
<a class="uk-link-reset" href="<?= $post->link ?>" title="<?= $this->escaper->attributes($post->t('title')) ?>">
<div style="--aspect-ratio: <?= $ratio ?>/1">
<img data-src="<?= $image->getResize(300, 400) ?>" alt="<?= $this->escaper->attributes($post->t('title')) ?>" uk-img />
</div>
<!--<img data-src="<?= $image->getResize(300, 120) ?>" alt="<?= $this->escaper->attributes($post->t('title')) ?>" uk-img/>
<canvas width="300" height="120"></canvas>-->
</a>
</div>
<?php } ?>
<div class="uk-width-2-3">
<div class="uk-padding-small">
<h4 class="uk-h5 uk-margin-remove uk-text-truncate">
<a class="uk-link-reset" href="<?= $post->link ?>"
title="<?= $this->escaper->attributes($post->t('title')) ?>">
<?= $post->t('title') ?>
</a>
</h4>
<p class="uk-margin-remove uk-text-meta uk-text-break">
<?= strip_tags(html_entity_decode($post->summary())) ?>
</p>
<a href="<?= $post->link ?>"
class="uk-button uk-button-default uk-button-small uk-margin">
<?= CLSystems\PhalCMS\Lib\Helper\Text::_('read-more') ?>
</a>
</div>
</div>
</div>
<?php } ?>
</div>
|
| #8 | Phalcon\Mvc\View\Engine\Volt->render |
| #9 | Phalcon\Mvc\View->engineRender |
| #10 | Phalcon\Mvc\View->partial |
| #11 | Phalcon\Mvc\View->getPartial
/var/www/html/clsystems.nl/src/app/Widget/FlashNews/FlashNews.php (98) <?php
namespace CLSystems\PhalCMS\Widget\FlashNews;
use Phalcon\Paginator\Adapter\QueryBuilder as Paginator;
use CLSystems\PhalCMS\Lib\Factory;
use CLSystems\PhalCMS\Lib\Widget;
use CLSystems\PhalCMS\Lib\Mvc\Model\Post;
use CLSystems\PhalCMS\Lib\Mvc\Model\PostCategory;
class FlashNews extends Widget
{
public function getContent()
{
$cid = $this->widget->get('params.categoryIds', []);
$postsNum = $this->widget->get('params.postsNum', 10, 'uint');
if (count($cid)) {
$bindIds = [];
$nested = new PostCategory;
foreach ($cid as $id) {
if ($tree = $nested->getTree((int)$id)) {
foreach ($tree as $node) {
$bindIds[] = (int)$node->id;
}
}
}
if (empty($bindIds)) {
return null;
}
$queryBuilder = Post::query()
->createBuilder()
->from(['post' => Post::class])
->where('post.parentId IN ({cid:array})', ['cid' => array_unique($bindIds)])
->andWhere('post.state = :state:', ['state' => 'P']);
switch ($this->widget->get('params.orderBy', 'latest')) {
case 'random':
$queryBuilder->orderBy('RAND()');
break;
case 'views':
$queryBuilder->orderBy('hits desc');
break;
case 'titleAsc':
$queryBuilder->orderBy('title asc');
break;
case 'titleDesc':
$queryBuilder->orderBy('title desc');
break;
default:
$queryBuilder->orderBy('createdAt desc');
break;
}
// Init renderer
$renderer = $this->getRenderer();
$partial = 'Content/' . $this->getPartialId();
if ('BlogList' === $this->widget->get('params.displayLayout', 'FlashNews'))
{
$paginator = new Paginator(
[
'builder' => $queryBuilder,
'limit' => $postsNum,
'page' => Factory::getService('request')->get('page', ['absint'], 0),
]
);
$paginate = $paginator->paginate();
if ($paginate->getTotalItems()) {
return $renderer->getPartial(
$partial,
[
'posts' => $paginate->getItems(),
'pagination' => Factory::getService('view')->getPartial(
'Pagination/Pagination',
[
'paginator' => $paginator,
]
),
]
);
}
}
else
{
$posts = $queryBuilder->limit($postsNum?:1, 0)->getQuery()->execute();
if ($posts->count()) {
return $renderer->getPartial($partial, ['posts' => $posts]);
}
}
}
return null;
}
}
|
| #12 | CLSystems\PhalCMS\Widget\FlashNews\FlashNews->getContent
/var/www/html/clsystems.nl/src/app/Lib/Widget.php (84) <?php
namespace CLSystems\PhalCMS\Lib;
use CLSystems\PhalCMS\Lib\Mvc\View\ViewBase;
use CLSystems\Php\Registry;
use ReflectionClass;
class Widget
{
/** @var Registry */
protected $widget;
final public function __construct(Registry $widget)
{
$this->widget = $widget;
$this->onConstruct();
}
public function onConstruct()
{
}
public function getTitle()
{
return $this->widget->get('title');
}
public function getRenderData()
{
return [
'widget' => $this->widget,
];
}
public function getPartialId()
{
return $this->widget->get('params.displayLayout', $this->widget->get('manifest.name'));
}
public function getContent()
{
$content = $this->widget->get('params.content', null);
if (null !== $content && is_string($content))
{
return $content;
}
return $this->getRenderer()
->getPartial('Content/' . $this->getPartialId(), $this->getRenderData());
}
public function getRenderer()
{
static $renderers = [];
$class = get_class($this);
if (isset($renderers[$class]))
{
return $renderers[$class];
}
$renderers[$class] = ViewBase::getInstance();
$reflectionClass = new ReflectionClass($this);
$renderers[$class]->setViewsDir(
[
TPL_SITE_PATH . '/Tmpl/Widget',
TPL_SITE_PATH . '/Widget',
dirname($reflectionClass->getFileName()) . '/Tmpl/',
TPL_SYSTEM_PATH . '/Widget/',
]
);
$renderers[$class]->disable();
return $renderers[$class];
}
public function render($wrapper = null)
{
$title = $this->getTitle();
$content = $this->getContent();
if ($title || $content)
{
$widgetData = [
'widget' => $this->widget,
'title' => $title,
'content' => $content,
];
if (null === $wrapper)
{
$wrapper = 'Wrapper';
}
return $this->getRenderer()
->getPartial('Wrapper/' . $wrapper, $widgetData);
}
return null;
}
} |
| #13 | CLSystems\PhalCMS\Lib\Widget->render
/var/www/html/clsystems.nl/src/app/Lib/Helper/Widget.php (144) <?php
namespace CLSystems\PhalCMS\Lib\Helper;
use Phalcon\Autoload\Loader;
use CLSystems\PhalCMS\Lib\Mvc\Model\Translation;
use CLSystems\PhalCMS\Lib\Widget as CmsWidget;
use CLSystems\PhalCMS\Lib\Mvc\Model\Config as ConfigModel;
use CLSystems\PhalCMS\Lib\Form\Form;
use CLSystems\PhalCMS\Lib\Form\Field;
use CLSystems\Php\Registry;
class Widget
{
/** @var array */
protected static $widgets = null;
protected static function appendWidget($widgetPath, $coreWidgets)
{
$widgetName = basename($widgetPath);
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $widgetName . '\\' . $widgetName;
$configFile = $widgetPath . '/Config.php';
if (class_exists($widgetClass)
&& is_file($configFile)
)
{
$widgetConfig = new Registry;
$widgetConfig->set('isCmsCore', in_array($widgetClass, $coreWidgets));
$widgetConfig->set('manifest', $widgetConfig->parse($configFile));
self::$widgets[$widgetClass] = $widgetConfig;
}
}
public static function getWidgets()
{
if (null === self::$widgets)
{
self::$widgets = [];
$coreWidgets = Config::get('core.widgets', []);
$template = Config::getTemplate()->name;
$widgetTmplPaths = [
APP_PATH . '/Tmpl/Site/' . $template . '/Tmpl/Widget',
APP_PATH . '/Tmpl/Site/' . $template . '/Widget',
];
foreach ($widgetTmplPaths as $widgetTmplPath)
{
if (is_dir($widgetTmplPath))
{
(new Loader)
->setNamespaces(
[
'CLSystems\\PhalCMS\\Widget' => $widgetTmplPath,
]
)
->register();
foreach (FileSystem::scanDirs($widgetTmplPath) as $widgetPath)
{
self::appendWidget($widgetPath, $coreWidgets);
}
}
}
foreach (FileSystem::scanDirs(WIDGET_PATH) as $widgetPath)
{
self::appendWidget($widgetPath, $coreWidgets);
}
$plugins = Event::getPlugins(true);
if (!empty($plugins['Cms']))
{
/** @var Registry $pluginConfig */
foreach ($plugins['Cms'] as $pluginConfig)
{
$widgetPluginPath = PLUGIN_PATH . '/Cms/' . $pluginConfig->get('manifest.name') . '/Widget';
if (is_dir($widgetPluginPath))
{
foreach (FileSystem::scanDirs($widgetPluginPath) as $widgetPath)
{
self::appendWidget($widgetPath, $coreWidgets);
}
}
}
}
}
return self::$widgets;
}
public static function renderPosition($position, $wrapper = null)
{
$results = '';
$widgetItems = self::getWidgetItems();
if (isset($widgetItems[$position]))
{
foreach ($widgetItems[$position] as $widget)
{
$results .= self::render($widget, $wrapper);
}
}
return $results;
}
public static function createWidget($widgetName, $params = [], $render = true, $wrapper = null)
{
$widgets = self::getWidgets();
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $widgetName . '\\' . $widgetName;
if (!isset($widgets[$widgetClass]))
{
return false;
}
$widgetConfig = clone $widgets[$widgetClass];
$widgetConfig->set('params', $widgetConfig->parse($params));
$widgetConfig->set('id', null);
if ($render)
{
return self::render($widgetConfig, $wrapper);
}
return $widgetConfig;
}
public static function render(Registry $widgetConfig, $wrapper = null)
{
$widgets = self::getWidgets();
$name = $widgetConfig->get('manifest.name');
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $name . '\\' . $name;
if (isset($widgets[$widgetClass]))
{
$widget = new $widgetClass($widgetConfig);
if ($widget instanceof CmsWidget)
{
return $widget->render($wrapper);
}
}
return null;
}
public static function getWidgetItems()
{
static $widgetItems = null;
if (null === $widgetItems)
{
$widgetItems = [];
$widgets = self::getWidgets();
$entities = ConfigModel::find(
[
'conditions' => 'context LIKE :context:',
'bind' => [
'context' => 'cms.config.widget.item.%',
],
'order' => 'ordering ASC',
]
);
$translate = Language::isMultilingual() && Uri::isClient('site');
foreach ($entities as $widget)
{
/** @var ConfigModel $widget */
$widgetConfig = new Registry($widget->data);
$widgetConfig->set('id', $widget->id);
$name = $widgetConfig->get('manifest.name');
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $name . '\\' . $name;
if (isset($widgets[$widgetClass]))
{
if ($translate)
{
$translations = $widget->getTranslations();
if (isset($translations['data']))
{
$widgetConfig->merge($translations['data']);
}
}
// Merge manifest and some global data
$widgetConfig->merge($widgets[$widgetClass]);
$widgetItems[$widgetConfig->get('position')][] = $widgetConfig;
}
}
}
return $widgetItems;
}
public static function renderForm(Registry $widgetData)
{
$widgetId = $widgetData->get('id', 0, 'uint');
$idIndex = $widgetId ?: uniqid();
$configForm = '<div class="widget-params">';
$form = new Form('FormData',
[
[
'name' => 'id',
'type' => 'Hidden',
'value' => $widgetId,
'id' => 'FormData-id' . $idIndex,
'filters' => ['uint'],
],
[
'name' => 'name',
'type' => 'Hidden',
'required' => true,
'value' => $widgetData->get('manifest.name'),
'id' => 'FormData-name' . $idIndex,
'filters' => ['string', 'trim'],
],
[
'name' => 'title',
'type' => 'Text',
'label' => 'title',
'translate' => true,
'value' => $widgetData->get('title'),
'id' => 'FormData-title' . $idIndex,
'filters' => ['string', 'trim'],
],
[
'name' => 'position',
'type' => 'Hidden',
'required' => true,
'value' => $widgetData->get('position'),
'id' => 'FormData-position' . $idIndex,
'filters' => ['string', 'trim'],
],
]
);
$transParamsData = [];
if ($widgetId && Language::isMultilingual())
{
$transData = Translation::find(
[
'conditions' => 'translationId LIKE :translationId:',
'bind' => [
'translationId' => '%.config_data.id=' . $widgetId . '.data',
],
]
);
if ($transData->count())
{
$titleField = $form->getField('title');
foreach ($transData as $transDatum)
{
$registry = new Registry($transDatum->translatedValue);
$parts = explode('.', $transDatum->translationId);
$language = $parts[0];
$titleField->setTranslationData($registry->get('title'), $language);
foreach ($registry->get('params', []) as $name => $value)
{
$transParamsData[$name][$language] = $value;
}
}
}
}
$configForm .= $form->renderFields();
if ($widgetData->has('manifest.params'))
{
$form = new Form('FormData.params', $widgetData->get('manifest.params', []));
$form->bind($widgetData->get('params', []), $transParamsData);
foreach ($form->getFields() as $field)
{
/** @var Field $field */
$field->setId($field->getId() . $idIndex);
$configForm .= $field->render();
}
}
$configForm .= '</div>';
return $configForm;
}
}
|
| #14 | CLSystems\PhalCMS\Lib\Helper\Widget::render
/var/www/html/clsystems.nl/src/app/Lib/Helper/Widget.php (103) <?php
namespace CLSystems\PhalCMS\Lib\Helper;
use Phalcon\Autoload\Loader;
use CLSystems\PhalCMS\Lib\Mvc\Model\Translation;
use CLSystems\PhalCMS\Lib\Widget as CmsWidget;
use CLSystems\PhalCMS\Lib\Mvc\Model\Config as ConfigModel;
use CLSystems\PhalCMS\Lib\Form\Form;
use CLSystems\PhalCMS\Lib\Form\Field;
use CLSystems\Php\Registry;
class Widget
{
/** @var array */
protected static $widgets = null;
protected static function appendWidget($widgetPath, $coreWidgets)
{
$widgetName = basename($widgetPath);
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $widgetName . '\\' . $widgetName;
$configFile = $widgetPath . '/Config.php';
if (class_exists($widgetClass)
&& is_file($configFile)
)
{
$widgetConfig = new Registry;
$widgetConfig->set('isCmsCore', in_array($widgetClass, $coreWidgets));
$widgetConfig->set('manifest', $widgetConfig->parse($configFile));
self::$widgets[$widgetClass] = $widgetConfig;
}
}
public static function getWidgets()
{
if (null === self::$widgets)
{
self::$widgets = [];
$coreWidgets = Config::get('core.widgets', []);
$template = Config::getTemplate()->name;
$widgetTmplPaths = [
APP_PATH . '/Tmpl/Site/' . $template . '/Tmpl/Widget',
APP_PATH . '/Tmpl/Site/' . $template . '/Widget',
];
foreach ($widgetTmplPaths as $widgetTmplPath)
{
if (is_dir($widgetTmplPath))
{
(new Loader)
->setNamespaces(
[
'CLSystems\\PhalCMS\\Widget' => $widgetTmplPath,
]
)
->register();
foreach (FileSystem::scanDirs($widgetTmplPath) as $widgetPath)
{
self::appendWidget($widgetPath, $coreWidgets);
}
}
}
foreach (FileSystem::scanDirs(WIDGET_PATH) as $widgetPath)
{
self::appendWidget($widgetPath, $coreWidgets);
}
$plugins = Event::getPlugins(true);
if (!empty($plugins['Cms']))
{
/** @var Registry $pluginConfig */
foreach ($plugins['Cms'] as $pluginConfig)
{
$widgetPluginPath = PLUGIN_PATH . '/Cms/' . $pluginConfig->get('manifest.name') . '/Widget';
if (is_dir($widgetPluginPath))
{
foreach (FileSystem::scanDirs($widgetPluginPath) as $widgetPath)
{
self::appendWidget($widgetPath, $coreWidgets);
}
}
}
}
}
return self::$widgets;
}
public static function renderPosition($position, $wrapper = null)
{
$results = '';
$widgetItems = self::getWidgetItems();
if (isset($widgetItems[$position]))
{
foreach ($widgetItems[$position] as $widget)
{
$results .= self::render($widget, $wrapper);
}
}
return $results;
}
public static function createWidget($widgetName, $params = [], $render = true, $wrapper = null)
{
$widgets = self::getWidgets();
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $widgetName . '\\' . $widgetName;
if (!isset($widgets[$widgetClass]))
{
return false;
}
$widgetConfig = clone $widgets[$widgetClass];
$widgetConfig->set('params', $widgetConfig->parse($params));
$widgetConfig->set('id', null);
if ($render)
{
return self::render($widgetConfig, $wrapper);
}
return $widgetConfig;
}
public static function render(Registry $widgetConfig, $wrapper = null)
{
$widgets = self::getWidgets();
$name = $widgetConfig->get('manifest.name');
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $name . '\\' . $name;
if (isset($widgets[$widgetClass]))
{
$widget = new $widgetClass($widgetConfig);
if ($widget instanceof CmsWidget)
{
return $widget->render($wrapper);
}
}
return null;
}
public static function getWidgetItems()
{
static $widgetItems = null;
if (null === $widgetItems)
{
$widgetItems = [];
$widgets = self::getWidgets();
$entities = ConfigModel::find(
[
'conditions' => 'context LIKE :context:',
'bind' => [
'context' => 'cms.config.widget.item.%',
],
'order' => 'ordering ASC',
]
);
$translate = Language::isMultilingual() && Uri::isClient('site');
foreach ($entities as $widget)
{
/** @var ConfigModel $widget */
$widgetConfig = new Registry($widget->data);
$widgetConfig->set('id', $widget->id);
$name = $widgetConfig->get('manifest.name');
$widgetClass = 'CLSystems\\PhalCMS\\Widget\\' . $name . '\\' . $name;
if (isset($widgets[$widgetClass]))
{
if ($translate)
{
$translations = $widget->getTranslations();
if (isset($translations['data']))
{
$widgetConfig->merge($translations['data']);
}
}
// Merge manifest and some global data
$widgetConfig->merge($widgets[$widgetClass]);
$widgetItems[$widgetConfig->get('position')][] = $widgetConfig;
}
}
}
return $widgetItems;
}
public static function renderForm(Registry $widgetData)
{
$widgetId = $widgetData->get('id', 0, 'uint');
$idIndex = $widgetId ?: uniqid();
$configForm = '<div class="widget-params">';
$form = new Form('FormData',
[
[
'name' => 'id',
'type' => 'Hidden',
'value' => $widgetId,
'id' => 'FormData-id' . $idIndex,
'filters' => ['uint'],
],
[
'name' => 'name',
'type' => 'Hidden',
'required' => true,
'value' => $widgetData->get('manifest.name'),
'id' => 'FormData-name' . $idIndex,
'filters' => ['string', 'trim'],
],
[
'name' => 'title',
'type' => 'Text',
'label' => 'title',
'translate' => true,
'value' => $widgetData->get('title'),
'id' => 'FormData-title' . $idIndex,
'filters' => ['string', 'trim'],
],
[
'name' => 'position',
'type' => 'Hidden',
'required' => true,
'value' => $widgetData->get('position'),
'id' => 'FormData-position' . $idIndex,
'filters' => ['string', 'trim'],
],
]
);
$transParamsData = [];
if ($widgetId && Language::isMultilingual())
{
$transData = Translation::find(
[
'conditions' => 'translationId LIKE :translationId:',
'bind' => [
'translationId' => '%.config_data.id=' . $widgetId . '.data',
],
]
);
if ($transData->count())
{
$titleField = $form->getField('title');
foreach ($transData as $transDatum)
{
$registry = new Registry($transDatum->translatedValue);
$parts = explode('.', $transDatum->translationId);
$language = $parts[0];
$titleField->setTranslationData($registry->get('title'), $language);
foreach ($registry->get('params', []) as $name => $value)
{
$transParamsData[$name][$language] = $value;
}
}
}
}
$configForm .= $form->renderFields();
if ($widgetData->has('manifest.params'))
{
$form = new Form('FormData.params', $widgetData->get('manifest.params', []));
$form->bind($widgetData->get('params', []), $transParamsData);
foreach ($form->getFields() as $field)
{
/** @var Field $field */
$field->setId($field->getId() . $idIndex);
$configForm .= $field->render();
}
}
$configForm .= '</div>';
return $configForm;
}
}
|
| #15 | CLSystems\PhalCMS\Lib\Helper\Widget::renderPosition
/var/www/html/clsystems.nl/cache/volt/Tmpl_Site_PhalCMS_Block_Content.volt.php (33) <div class="uk-section uk-section-small uk-section-default">
<div class="uk-container">
<?php if (CLSystems\PhalCMS\Lib\Helper\Uri::isHome()) { ?>
<div class="uk-margin">
<?= CLSystems\PhalCMS\Lib\Helper\Widget::renderPosition('FlashNews', 'Raw') ?>
</div>
<div class="uk-margin">
<?= CLSystems\PhalCMS\Lib\Helper\Widget::renderPosition('Trending', 'HeadingLine') ?>
</div>
<div class="uk-margin">
<div uk-grid>
<div class="uk-width-2-3@m">
<div uk-margin>
<?= CLSystems\PhalCMS\Lib\Helper\Widget::renderPosition('LatestNews', 'HeadingLine') ?>
</div>
</div>
<div class="uk-width-1-3@m">
<div uk-margin>
<?= CLSystems\PhalCMS\Lib\Helper\Widget::renderPosition('Aside', 'HeadingLine') ?>
</div>
</div>
</div>
</div>
<?php } else { ?>
<div uk-grid>
<div class="uk-width-2-3@m">
<main id="main-content">
<?= $this->getContent() ?>
</main>
</div>
<div class="uk-width-1-3@m">
<aside id="aside">
<?= CLSystems\PhalCMS\Lib\Helper\Widget::renderPosition('Aside', 'HeadingLine') ?>
</aside>
</div>
</div>
<?php } ?>
</div>
</div> |
| #16 | Phalcon\Mvc\View\Engine\Volt->render |
| #17 | Phalcon\Mvc\View->engineRender |
| #18 | Phalcon\Mvc\View->partial |
| #19 | Phalcon\Mvc\View\Engine\AbstractEngine->partial
/var/www/html/clsystems.nl/cache/volt/Tmpl_Site_PhalCMS_Index.volt.php (105) <!DOCTYPE html>
<html lang="<?= CLSystems\PhalCMS\Lib\Helper\Text::_('locale.code') ?>"
dir="<?= CLSystems\PhalCMS\Lib\Helper\Text::_('locale.direction') ?>"
data-uri-home="<?= (CLSystems\PhalCMS\Lib\Helper\Uri::isHome() ? 'true' : 'false') ?>"
data-uri-root="<?= constant('DOMAIN') ?>"
data-uri-base="<?= CLSystems\PhalCMS\Lib\Helper\Uri::getBaseUriPrefix() ?>">
<head>
<meta name="partnerboostverifycode" content="32dc01246faccb7f5b3cad5016dd5033" />
<meta name='ir-site-verification-token' value='-1886971486' />
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="theme-color" content="#EC931F">
<link rel="manifest" href="<?= constant('DOMAIN') . '/manifest.json' ?>">
<!-- VDS1 -->
<?php if (isset($metadata)) { ?>
<?php if (!empty($metadata->metaKeys)) { ?>
<meta name="keywords" content="<?= $metadata->metaKeys ?>"/>
<?php } ?>
<?php if (!empty($metadata->metaDesc)) { ?>
<meta name="description" content="<?= $metadata->metaDesc ?>"/>
<?php } ?>
<?php if (!empty($metadata->contentRights)) { ?>
<meta name="rights" content="<?= $metadata->contentRights ?>"/>
<?php } ?>
<?php if (!empty($metadata->metaRobots)) { ?>
<meta name="robots" content="<?= $metadata->metaRobots ?>"/>
<?php } ?>
<?php if (!empty($metadata->metaTitle)) { ?>
<?php if ($metadata->metaTitle == $siteName) { ?>
<title><?= $catchPhrase ?> | <?= $this->escaper->html($siteName) ?></title>
<?php } else { ?>
<title><?= $metadata->metaTitle ?> | <?= $this->escaper->html($siteName) ?></title>
<?php } ?>
<?php } ?>
<?php } ?>
<link rel="canonical" href="<?= CLSystems\PhalCMS\Lib\Helper\Uri::fromServer() ?>" />
<link rel="shortcut icon" href="<?= constant('DOMAIN') . '/favicon.ico' ?>"/>
<link rel="apple-touch-icon" href="<?= constant('DOMAIN') . '/assets/images/clsystems_logo2.png' ?>"/>
<link rel="stylesheet" type="text/css" href="<?= constant('DOMAIN') . '/assets/css/uikit.min.css' ?>"/>
<link rel="stylesheet" type="text/css" href="<?= constant('DOMAIN') . '/assets/css/custom.css' ?>?<?= rand(1, 10000) ?>"/>
<script src="<?= constant('DOMAIN') . '/assets/js/jquery-3.6.0/jquery.min.js' ?>"></script>
<script src="<?= constant('DOMAIN') . '/assets/js/uikit-3.3.2/uikit.min.js' ?>"></script>
<script src="<?= constant('DOMAIN') . '/assets/js/uikit-3.3.2/uikit-icons.min.js' ?>"></script>
<?= implode(PHP_EOL, CLSystems\PhalCMS\Lib\Helper\Event::trigger('onSiteHead', ['System', 'Cms'])) ?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"name": "<?= $this->escaper->html($siteName) ?>",
"url": "<?= constant('DOMAIN') ?>",
"description": "<?= $catchPhrase ?>",
"image": "<?= constant('DOMAIN') . '/assets/images/clsystems_logo2.png' ?>",
"logo": "<?= constant('DOMAIN') . '/assets/images/clsystems_logo2.png' ?>",
"telephone": "0647794655",
"address": {
"@type": "PostalAddress",
"streetAddress": "Molenweg 13",
"addressLocality": "Putten",
"addressRegion": "GLD",
"postalCode": "3882AB",
"addressCountry": "Nederland"
}
}
</script>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "<?= $this->escaper->html($siteName) ?>",
"url": "<?= constant('DOMAIN') ?>",
"potentialAction": {
"@type": "SearchAction",
"query-input": "required name=query",
"target": "<?= constant('DOMAIN') . '/search?q={query}' ?>"
}
}
</script>
</head>
<body>
<?= implode(PHP_EOL, CLSystems\PhalCMS\Lib\Helper\Event::trigger('onSiteBeforeContent', [], ['System', 'Cms'])) ?>
<?= $this->partial('Block/BeforeContent') ?>
<?= $this->partial('Block/Content') ?>
<?= $this->partial('Block/AfterContent') ?>
<?= implode(PHP_EOL, CLSystems\PhalCMS\Lib\Helper\Event::trigger('onSiteAfterContent', [], ['System', 'Cms'])) ?>
<?= implode(PHP_EOL, CLSystems\PhalCMS\Lib\Helper\Event::trigger('onSiteAfterRender', [], ['System', 'Cms'])) ?>
</body>
</html> |
| #20 | Phalcon\Mvc\View\Engine\Volt->render |
| #21 | Phalcon\Mvc\View->engineRender |
| #22 | Phalcon\Mvc\View->processRender |
| #23 | Phalcon\Mvc\View->render |
| #24 | Phalcon\Mvc\Application->handle
/var/www/html/clsystems.nl/src/app/Lib/CmsApplication.php (118) <?php
namespace CLSystems\PhalCMS\Lib;
use Phalcon\Autoload\Loader;
use Phalcon\Http\Response;
use Phalcon\Events\Event;
use Phalcon\Mvc\Application;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\View;
use CLSystems\PhalCMS\Lib\Helper\Asset;
use CLSystems\PhalCMS\Lib\Helper\Config;
use CLSystems\PhalCMS\Lib\Helper\Uri;
use CLSystems\PhalCMS\Lib\Helper\State;
use CLSystems\PhalCMS\Lib\Helper\User;
use CLSystems\PhalCMS\Lib\Helper\Event as EventHelper;
use CLSystems\PhalCMS\Lib\Mvc\View\ViewBase;
use CLSystems\Php\Registry;
use MatthiasMullie\Minify;
use Exception;
class CmsApplication extends Application
{
public function execute()
{
try {
$eventsManager = $this->di->getShared('eventsManager');
$eventsManager->attach('application:beforeSendResponse', $this);
$plugins = EventHelper::getPlugins();
$systemEvents = [
'application:beforeSendResponse',
'dispatch:beforeExecuteRoute',
'dispatch:beforeException',
'dispatch:beforeDispatch',
'dispatch:afterDispatch',
'dispatch:afterInitialize',
];
foreach ($plugins['System'] as $className => $config) {
$handler = EventHelper::getHandler($className, $config);
foreach ($systemEvents as $systemEvent) {
$eventsManager->attach($systemEvent, $handler);
}
}
// Update view dirs
define('TPL_SITE_PATH', APP_PATH . '/Tmpl/Site/' . Config::get('siteTemplate', 'PhalCMS'));
define('TPL_ADMINISTRATOR_PATH', APP_PATH . '/Tmpl/Administrator');
define('TPL_SYSTEM_PATH', APP_PATH . '/Tmpl/System');
if (Uri::isClient('site')) {
$viewDirs = [
TPL_SITE_PATH . '/Tmpl/',
TPL_SITE_PATH . '/',
];
} else {
$viewDirs = [
TPL_ADMINISTRATOR_PATH . '/',
];
}
foreach (['System', 'Cms'] as $plgGroup) {
if (isset($plugins[$plgGroup])) {
/**
* @var string $pluginClass
* @var Registry $pluginConfig
*/
foreach ($plugins[$plgGroup] as $pluginClass => $pluginConfig) {
$pluginName = $pluginConfig->get('manifest.name');
$pluginPath = PLUGIN_PATH . '/' . $plgGroup . '/' . $pluginName;
$psrPaths = [];
if (is_dir($pluginPath . '/Tmpl')) {
$viewDirs[] = $pluginPath . '/Tmpl/';
}
if (is_dir($pluginPath . '/Lib')) {
$psrPaths['CLSystems\\PhalCMS\\Lib'] = $pluginPath . '/Lib';
}
if (is_dir($pluginPath . '/Widget')) {
$psrPaths['CLSystems\\PhalCMS\\Widget'] = $pluginPath . '/Widget';
}
if ($psrPaths) {
(new Loader)
->setNamespaces($psrPaths, true)
->register();
}
}
}
}
$viewDirs[] = TPL_SYSTEM_PATH . '/';
/** @var ViewBase $view */
$view = $this->di->getShared('view');
$requestUri = $_SERVER['REQUEST_URI'];
if (Config::get('siteOffline') === 'Y'
&& !User::getInstance()->access('super')
) {
$this->view->setMainView('Offline/Index');
if (strpos($requestUri, '/user/') !== 0) {
$requestUri = '';
}
} else {
$view->setMainView('Index');
}
$view->setViewsDir($viewDirs);
$this->setEventsManager($eventsManager);
$response = $this->handle($requestUri);
$response->send();
} catch (Exception $e) {
if (true === DEVELOPMENT_MODE) {
// Let Phalcon Debug catch this
throw $e;
}
try {
if (User::getInstance()->access('super')) {
State::setMark('exception', $e);
}
/**
* @var Dispatcher $dispatcher
* @var View $view
*/
$dispatcher = $this->getDI()->getShared('dispatcher');
$dispatcher->setControllerName(Uri::isClient('administrator') ? 'admin_error' : 'error');
$dispatcher->setActionName('show');
$dispatcher->setParams(
[
'code' => $e->getCode(),
'message' => $e->getMessage(),
]
);
$view = $this->getDI()->getShared('view');
$view->start();
$dispatcher->dispatch();
$view->render(
$dispatcher->getControllerName(),
$dispatcher->getActionName(),
$dispatcher->getParams()
);
$view->finish();
echo $view->getContent();
} catch (Exception $e2) {
debugVar($e2->getMessage());
}
}
}
protected function getCompressor($type)
{
if ('css' === $type) {
$compressor = new Minify\CSS;
$compressor->setImportExtensions(
[
'gif' => 'data:image/gif',
'png' => 'data:image/png',
'svg' => 'data:image/svg+xml',
]
);
} else {
$compressor = new Minify\JS;
}
return $compressor;
}
protected function compressAssets()
{
$basePath = PUBLIC_PATH . '/assets';
$assets = Factory::getService('assets');
foreach (Asset::getFiles() as $type => $files) {
$fileName = md5(implode(':', $files)) . '.' . $type;
$filePath = $basePath . '/compressed/' . $fileName;
$fileUri = DOMAIN . '/assets/compressed/' . $fileName . (DEVELOPMENT_MODE ? '?' . time() : '');
$hasAsset = is_file($filePath);
$ucType = ucfirst($type);
$addFunc = 'add' . $ucType;
if ($hasAsset && !DEVELOPMENT_MODE) {
call_user_func_array([$assets, $addFunc], [$fileUri, false]);
continue;
}
$compressor = self::getCompressor($type);
foreach ($files as $file) {
$compressor->add($file);
}
if (!is_dir($basePath . '/compressed/')) {
mkdir($basePath . '/compressed/', 0777, true);
}
if ($compressor->minify($filePath)) {
@chmod($filePath, 0777);
call_user_func_array([$assets, $addFunc], [$fileUri, false]);
}
unset($compressor);
}
}
public function beforeSendResponse(Event $event, CmsApplication $app, Response $response)
{
$request = $this->di->getShared('request');
// Skip asset injection for AJAX and API requests
if ($request->isAjax()) {
return;
}
// Skip asset injection for API requests
$requestUri = $_SERVER['REQUEST_URI'] ?? '';
if (strpos($requestUri, '/api/') !== false) {
return;
}
/** @var Asset $assets */
$this->compressAssets();
$assets = $this->di->getShared('assets');
// Compress CSS
ob_start();
$assets->outputCss();
$assets->outputInlineCss();
$content = str_replace('</head>', ob_get_clean() . '</head>', $response->getContent());
// Compress JS
ob_start();
$assets->outputJs();
$assets->outputInlineJs();
$code = Asset::getCode() . ob_get_clean();
// Extra code (in the footer)
$content = str_replace('</body>', $code . '</body>', $content);
$response->setContent($content);
}
}
|
| #25 | CLSystems\PhalCMS\Lib\CmsApplication->execute
/var/www/html/clsystems.nl/public/index.php (17) <?php
declare(strict_types=1);
error_reporting(E_ALL);
ini_set('display_errors', 'true');
ini_set('date.timezone', 'Europe/Amsterdam');
setlocale(LC_ALL, 'nl_NL.UTF-8', 'nl_NL@euro', 'nl_NL', 'dutch');
setlocale(LC_NUMERIC, 'C');
use CLSystems\PhalCMS\Lib\Factory;
define('BASE_PATH', dirname(__DIR__));
require_once BASE_PATH . '/src/app/Lib/Factory.php';
// Execute application
Factory::getApplication()->execute(); |