#0 | imagesavealpha |
#1 | Phalcon\Image\Adapter\Gd->__construct
/var/www/html/discounts-n-coupons.com/src/app/Lib/Helper/Image.php (64) <?php
namespace CLSystems\PhalCMS\Lib\Helper;
//
//include_once "../../../../vendor/imagecow/imagecow/src/Image.php";
use Exception;
use Imagecow\Image as ImageHandler;
use Phalcon\Image\Adapter\Gd;
use Phalcon\Image\Enum;
class Image
{
protected $imageUri;
protected $imageFile;
protected $imageThumbUri;
public function __construct($imageFile)
{
if (strpos($imageFile, BASE_PATH . '/public/upload/') !== 0)
{
$imageFile = BASE_PATH . '/public/upload/' . $imageFile;
}
$this->imageFile = $imageFile;
$this->imageUri = str_replace(BASE_PATH . '/public', DOMAIN, $this->imageFile);
$this->imageThumbUri = dirname($this->imageUri) . '/thumbs';
}
public function getResize($width = null, $height = null)
{
if (null === $width && null === $height)
{
$width = 100;
}
preg_match('#^.*(\.[^.]*)$#', $this->imageFile, $matches);
$extension = $matches[1];
$thumbName = basename($this->imageFile, $extension) . '_' . ($width ?: 0) . 'x' . ($height ?: 0) . $extension;
$thumbPath = dirname($this->imageFile) . '/thumbs';
if (!is_file($thumbPath . '/' . $thumbName))
{
if (!is_dir($thumbPath))
{
mkdir($thumbPath, 0777, true);
}
if ($width && $height)
{
$master = Enum::AUTO;
}
elseif ($width)
{
$master = Enum::WIDTH;
}
else
{
$master = Enum::HEIGHT;
}
try
{
$handler = new Gd($this->imageFile);
$handler->resize($width, $height, $master);
//var_dump($thumbPath);
if(!is_readable($thumbPath)){
mkdir($thumbPath, 0777, true);
}
$handler->save($thumbPath . '/' . $thumbName, 100);
}
catch (Exception $exception)
{
// debugVar($exception);
try
{
$handler = ImageHandler::fromFile($this->imageFile, ImageHandler::LIB_IMAGICK);
$handler->quality(100);
$handler->resize($width, $height);
$handler->format('jpg');
$handler->save($thumbPath . '/' . $thumbName);
}
catch (Exception $exception)
{
$this->imageFile = BASE_PATH . '/public/upload/image_not_found.png';
$thumbName = basename($this->imageFile, '.png') . '_' . ($width ?: 0) . 'x' . ($height ?: 0) . '.png';
$thumbPath = dirname($this->imageFile) . '/thumbs';
$handler = new Gd($this->imageFile);
$handler->resize($width, $height, $master);
$handler->save($thumbPath . '/' . $thumbName, 100);
}
}
}
return $this->imageThumbUri . '/' . $thumbName;
}
public function getRatio($width = null)
{
$imageLoc = self::getResize($width);
if (false === empty($imageLoc))
{
[$width, $height, $type, $attr] = getimagesize($imageLoc);
if ($height === 0 || true === empty($height))
{
$height = 1;
}
$aspect = $width / $height;
}
else
{
$aspect = 1;
}
return $aspect;
}
public function getUri()
{
return $this->imageUri;
}
public function exists()
{
return is_file($this->imageFile);
}
public static function loadImage($imageString, $returnFirst = true)
{
$imageString = trim($imageString);
$imageList = [];
if (strpos($imageString, '[') === 0
|| strpos($imageString, '{') === 0
)
{
$images = json_decode($imageString, true) ?: [];
}
else
{
$images = [$imageString];
}
if ($images)
{
foreach ($images as $image)
{
$handler = new Image($image);
if ($handler->exists())
{
$imageList[] = $handler;
}
}
if ($imageList)
{
return $returnFirst ? $imageList[0] : $imageList;
}
}
return false;
}
} |
#2 | CLSystems\PhalCMS\Lib\Helper\Image->getResize
/var/www/html/discounts-n-coupons.com/src/app/Lib/Helper/Image.php (102) <?php
namespace CLSystems\PhalCMS\Lib\Helper;
//
//include_once "../../../../vendor/imagecow/imagecow/src/Image.php";
use Exception;
use Imagecow\Image as ImageHandler;
use Phalcon\Image\Adapter\Gd;
use Phalcon\Image\Enum;
class Image
{
protected $imageUri;
protected $imageFile;
protected $imageThumbUri;
public function __construct($imageFile)
{
if (strpos($imageFile, BASE_PATH . '/public/upload/') !== 0)
{
$imageFile = BASE_PATH . '/public/upload/' . $imageFile;
}
$this->imageFile = $imageFile;
$this->imageUri = str_replace(BASE_PATH . '/public', DOMAIN, $this->imageFile);
$this->imageThumbUri = dirname($this->imageUri) . '/thumbs';
}
public function getResize($width = null, $height = null)
{
if (null === $width && null === $height)
{
$width = 100;
}
preg_match('#^.*(\.[^.]*)$#', $this->imageFile, $matches);
$extension = $matches[1];
$thumbName = basename($this->imageFile, $extension) . '_' . ($width ?: 0) . 'x' . ($height ?: 0) . $extension;
$thumbPath = dirname($this->imageFile) . '/thumbs';
if (!is_file($thumbPath . '/' . $thumbName))
{
if (!is_dir($thumbPath))
{
mkdir($thumbPath, 0777, true);
}
if ($width && $height)
{
$master = Enum::AUTO;
}
elseif ($width)
{
$master = Enum::WIDTH;
}
else
{
$master = Enum::HEIGHT;
}
try
{
$handler = new Gd($this->imageFile);
$handler->resize($width, $height, $master);
//var_dump($thumbPath);
if(!is_readable($thumbPath)){
mkdir($thumbPath, 0777, true);
}
$handler->save($thumbPath . '/' . $thumbName, 100);
}
catch (Exception $exception)
{
// debugVar($exception);
try
{
$handler = ImageHandler::fromFile($this->imageFile, ImageHandler::LIB_IMAGICK);
$handler->quality(100);
$handler->resize($width, $height);
$handler->format('jpg');
$handler->save($thumbPath . '/' . $thumbName);
}
catch (Exception $exception)
{
$this->imageFile = BASE_PATH . '/public/upload/image_not_found.png';
$thumbName = basename($this->imageFile, '.png') . '_' . ($width ?: 0) . 'x' . ($height ?: 0) . '.png';
$thumbPath = dirname($this->imageFile) . '/thumbs';
$handler = new Gd($this->imageFile);
$handler->resize($width, $height, $master);
$handler->save($thumbPath . '/' . $thumbName, 100);
}
}
}
return $this->imageThumbUri . '/' . $thumbName;
}
public function getRatio($width = null)
{
$imageLoc = self::getResize($width);
if (false === empty($imageLoc))
{
[$width, $height, $type, $attr] = getimagesize($imageLoc);
if ($height === 0 || true === empty($height))
{
$height = 1;
}
$aspect = $width / $height;
}
else
{
$aspect = 1;
}
return $aspect;
}
public function getUri()
{
return $this->imageUri;
}
public function exists()
{
return is_file($this->imageFile);
}
public static function loadImage($imageString, $returnFirst = true)
{
$imageString = trim($imageString);
$imageList = [];
if (strpos($imageString, '[') === 0
|| strpos($imageString, '{') === 0
)
{
$images = json_decode($imageString, true) ?: [];
}
else
{
$images = [$imageString];
}
if ($images)
{
foreach ($images as $image)
{
$handler = new Image($image);
if ($handler->exists())
{
$imageList[] = $handler;
}
}
if ($imageList)
{
return $returnFirst ? $imageList[0] : $imageList;
}
}
return false;
}
} |
#3 | CLSystems\PhalCMS\Lib\Helper\Image->getRatio
/var/www/html/discounts-n-coupons.com/cache/volt/Widget_FlashNews_Tmpl_Content_BlogStack.volt.php (6) <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>
|
#4 | Phalcon\Mvc\View\Engine\Volt->render |
#5 | Phalcon\Mvc\View->engineRender |
#6 | Phalcon\Mvc\View->partial |
#7 | Phalcon\Mvc\View->getPartial
/var/www/html/discounts-n-coupons.com/src/app/Widget/FlashNews/FlashNews.php (122) <?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':
$db = Factory::getService('db');
$randomIds = [];
$selectedIds = $db->query("
SELECT a.id
FROM wgz1tq_ucm_items a
JOIN ( SELECT id FROM
( SELECT id
FROM ( SELECT MIN(id) + (MAX(id) - MIN(id) + 1 - 50) * RAND() AS start FROM wgz1tq_ucm_items ) AS init
JOIN wgz1tq_ucm_items y
WHERE y.id > init.start
ORDER BY y.id
LIMIT 500 -- Inflated to deal with gaps
) z ORDER BY RAND()
LIMIT 10 -- number of rows desired (change to 1 if looking for a single row)
) r ON a.id = r.id;
")->fetchAll();
foreach ($selectedIds as $selectedId)
{
$randomIds[] = $selectedId['id'];
}
$queryBuilder
->andWhere('post.id IN ({ids:array})', ['ids' => $randomIds])
->orderBy('post.id asc');
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('id 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, 0)->getQuery()->execute();
if ($posts->count()) {
return $renderer->getPartial($partial, ['posts' => $posts]);
}
}
}
return null;
}
public static function toSql(\Phalcon\Mvc\Model\Query\BuilderInterface $builder) : string
{
$data = $builder->getQuery()->getSql();
['sql' => $sql, 'bind' => $binds, 'bindTypes' => $bindTypes] = $data;
$finalSql = $sql;
foreach ($binds as $name => $value) {
$formattedValue = $value;
if (\is_object($value)) {
$formattedValue = (string)$value;
}
if (\is_string($formattedValue)) {
$formattedValue = sprintf("'%s'", $formattedValue);
}
$finalSql = str_replace(":$name:", $formattedValue, $finalSql);
}
return $finalSql;
}
}
|
#8 | CLSystems\PhalCMS\Widget\FlashNews\FlashNews->getContent
/var/www/html/discounts-n-coupons.com/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;
}
} |
#9 | CLSystems\PhalCMS\Lib\Widget->render
/var/www/html/discounts-n-coupons.com/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;
}
}
|
#10 | CLSystems\PhalCMS\Lib\Helper\Widget::render
/var/www/html/discounts-n-coupons.com/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;
}
}
|
#11 | CLSystems\PhalCMS\Lib\Helper\Widget::renderPosition
/var/www/html/discounts-n-coupons.com/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> |
#12 | Phalcon\Mvc\View\Engine\Volt->render |
#13 | Phalcon\Mvc\View->engineRender |
#14 | Phalcon\Mvc\View->partial |
#15 | Phalcon\Mvc\View\Engine\AbstractEngine->partial
/var/www/html/discounts-n-coupons.com/cache/volt/Tmpl_Site_PhalCMS_Index.volt.php (100) <!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='ir-site-verification-token' value='-2029198168' />
<meta charset="utf-8"/>
<meta name="Cache-Control" content="public; max-age=262800">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="tradetracker-site-verification" content="c70bb2eb887731a6f422e7c73327fc4c9b537044" />
<meta name="verification" content="3f8422a0391b4139f9757b9126474384" />
<meta name="theme-color" content="#4285f4">
<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><?= CLSystems\PhalCMS\Lib\Helper\Text::_('catch-phrase') ?> | <?= $this->escaper->html($siteName) ?></title>
<?php } else { ?>
<title><?= CLSystems\PhalCMS\Lib\Helper\Text::_($metadata->metaTitle) ?> | <?= CLSystems\PhalCMS\Lib\Helper\Date::getMonthYear() ?> | <?= $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') . '/assets/images/Sale-55x55.webp' ?>"/>
<link rel="apple-touch-icon" href="<?= constant('DOMAIN') . '/assets/images/Sale-55x55.webp' ?>"/>
<script src="<?= constant('DOMAIN') . '/assets/js/jquery-3.6.0/jquery.min.js' ?>"></script>
<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' ?>?<?= date('ymdH') ?>"/>
<?= implode(PHP_EOL, CLSystems\PhalCMS\Lib\Helper\Event::trigger('onSiteHead', ['System', 'Cms'])) ?>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Organization",
"name": "Discounts-N-Coupons",
"url": "https://discounts-n-coupons.com",
"description": "Are you completely addicted to discounts and coupons? Then view our very extensive range. Grab your discount quickly.",
"image": "<?= constant('DOMAIN') . '/assets/images/icon-sale-shopping-bag.webp' ?>",
"logo": "<?= constant('DOMAIN') . '/assets/images/icon-sale-shopping-bag-55x65.webp' ?>",
"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": "Discounts-N-Coupons",
"url": "https://discounts-n-coupons.com",
"potentialAction": {
"@type": "SearchAction",
"query-input": "required name=query",
"target": "https://discounts-n-coupons.com/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'])) ?>
<script defer src="<?= constant('DOMAIN') . '/assets/js/uikit-3.15.22/uikit.min.js' ?>"></script>
<script defer src="<?= constant('DOMAIN') . '/assets/js/uikit-3.15.22/uikit-icons.min.js' ?>"></script>
</body>
</html> |
#16 | Phalcon\Mvc\View\Engine\Volt->render |
#17 | Phalcon\Mvc\View->engineRender |
#18 | Phalcon\Mvc\View->processRender |
#19 | Phalcon\Mvc\View->render |
#20 | Phalcon\Mvc\Application->handle
/var/www/html/discounts-n-coupons.com/src/app/Lib/CmsApplication.php (117) <?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);
$this->handle($requestUri)->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)) {
// echo $filePath;
$chmodFile = chmod($filePath, 0777);
if (false === $chmodFile)
{
touch($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');
if ($request->isAjax()) {
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);
}
}
|
#21 | CLSystems\PhalCMS\Lib\CmsApplication->execute
/var/www/html/discounts-n-coupons.com/public/index.php (14) <?php
declare(strict_types=1);
error_reporting(E_ALL);
ini_set('display_errors', true);
use CLSystems\PhalCMS\Lib\Factory;
define('BASE_PATH', dirname(__DIR__));
require_once BASE_PATH . '/src/app/Lib/Factory.php';
// Execute application
Factory::getApplication()->execute(); |