use anonymous function

This commit is contained in:
Jean-Christian Paul Denis 2022-12-01 00:41:34 +01:00
parent d5109b2f94
commit 93c2607544
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
2 changed files with 44 additions and 71 deletions

View File

@ -45,5 +45,34 @@ dcCore::app()->url->register(
'epccss',
'epc.css',
'^epc\.css',
['publicEnhancePostContent', 'css']
function($args)
{
$css = [];
$filters = libEPC::getFilters();
foreach ($filters as $id => $filter) {
if ('' == $filter->class || '' == $filter->style) {
continue;
}
$res = '';
foreach ($filter->class as $k => $class) {
$styles = $filter->style;
$style = html::escapeHTML(trim($styles[$k]));
if ('' != $style) {
$res .= $class . ' {' . $style . '} ';
}
}
if (!empty($res)) {
$css[] = '/* CSS for enhancePostContent ' . $id . " */ \n" . $res . "\n";
}
}
header('Content-Type: text/css; charset=UTF-8');
echo implode("\n", $css);
exit;
}
);

View File

@ -18,78 +18,22 @@ require __DIR__ . '/_widgets.php';
dcCore::app()->blog->settings->addNamespace('enhancePostContent');
if (dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_active) {
dcCore::app()->addBehavior(
'publicHeadContentV2',
['publicEnhancePostContent', 'publicHeadContent']
);
dcCore::app()->addBehavior(
'publicBeforeContentFilterV2',
['publicEnhancePostContent', 'publicContentFilter']
);
if (!dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_active) {
return null;
}
/**
* @ingroup DC_PLUGIN_ENHANCEPOSTCONTENT
* @brief Filter posts content - public methods.
* @since 2.6
*/
class publicEnhancePostContent
{
/**
* Add filters CSS to page header
*/
public static function publicHeadContent()
{
echo dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('epccss'));
}
// Add filters CSS to page header
dcCore::app()->addBehavior('publicHeadContent', function() {
echo dcUtils::cssLoad(dcCore::app()->blog->url . dcCore::app()->url->getURLFor('epccss'));
});
// Filter template blocks content
dcCore::app()->addBehavior('publicBeforeContentFilterV2', function($tag, $args) {
$filters = libEPC::getFilters();
public static function css($args)
{
$css = [];
$filters = libEPC::getFilters();
foreach ($filters as $id => $filter) {
if ('' == $filter->class || '' == $filter->style) {
continue;
}
$res = '';
foreach ($filter->class as $k => $class) {
$styles = $filter->style;
$style = html::escapeHTML(trim($styles[$k]));
if ('' != $style) {
$res .= $class . ' {' . $style . '} ';
}
}
if (!empty($res)) {
$css[] = '/* CSS for enhancePostContent ' . $id . " */ \n" . $res . "\n";
}
foreach ($filters as $id => $filter) {
if (!libEPC::testContext($tag, $args, $filter)) {
continue;
}
header('Content-Type: text/css; charset=UTF-8');
echo implode("\n", $css);
exit;
$filter->publicContent($tag, $args);
}
/**
* Filter template blocks content
*
* @param string $tag Tempalte block name
* @param array $args Tempalte Block arguments
*/
public static function publicContentFilter($tag, $args)
{
$filters = libEPC::getFilters();
foreach ($filters as $id => $filter) {
if (!libEPC::testContext($tag, $args, $filter)) {
continue;
}
$filter->publicContent($tag, $args);
}
}
}
});