2021-08-23 23:55:52 +00:00
|
|
|
<?php
|
|
|
|
# -- BEGIN LICENSE BLOCK ----------------------------------
|
|
|
|
#
|
|
|
|
# This file is part of enhancePostContent, a plugin for Dotclear 2.
|
|
|
|
#
|
2021-08-24 09:32:53 +00:00
|
|
|
# Copyright (c) 2009-2021 Jean-Christian Denis and contributors
|
2021-08-23 23:55:52 +00:00
|
|
|
#
|
|
|
|
# Licensed under the GPL version 2.0 license.
|
|
|
|
# A copy of this license is available in LICENSE file or at
|
|
|
|
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
#
|
|
|
|
# -- END LICENSE BLOCK ------------------------------------
|
|
|
|
|
|
|
|
if (!defined('DC_RC_PATH')) {
|
2021-08-24 20:05:23 +00:00
|
|
|
return null;
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
require dirname(__FILE__) . '/_widgets.php';
|
2021-08-23 23:55:52 +00:00
|
|
|
|
|
|
|
$core->blog->settings->addNamespace('enhancePostContent');
|
|
|
|
|
|
|
|
if ($core->blog->settings->enhancePostContent->enhancePostContent_active) {
|
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
$core->addBehavior(
|
|
|
|
'publicHeadContent',
|
|
|
|
['publicEnhancePostContent', 'publicHeadContent']
|
|
|
|
);
|
|
|
|
$core->addBehavior(
|
|
|
|
'publicBeforeContentFilter',
|
|
|
|
['publicEnhancePostContent', 'publicContentFilter']
|
|
|
|
);
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_ENHANCEPOSTCONTENT
|
|
|
|
* @brief Filter posts content - public methods.
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
|
|
|
class publicEnhancePostContent
|
|
|
|
{
|
2021-08-24 20:05:23 +00:00
|
|
|
/**
|
|
|
|
* Add filters CSS to page header
|
|
|
|
*
|
|
|
|
* @param dcCore $core dcCore instance
|
|
|
|
*/
|
|
|
|
public static function publicHeadContent(dcCore $core)
|
|
|
|
{
|
|
|
|
$filters = libEPC::blogFilters();
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
foreach($filters as $name => $filter) {
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
if (empty($filter['class'])
|
|
|
|
|| empty($filter['style'])) {
|
|
|
|
continue;
|
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
$res = '';
|
|
|
|
foreach($filter['class'] as $k => $class) {
|
|
|
|
$style = html::escapeHTML(trim($filter['style'][$k]));
|
|
|
|
if ('' != $style) {
|
|
|
|
$res .= $class . " {" . $style . "} ";
|
|
|
|
}
|
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
if (!empty($res)) {
|
|
|
|
echo
|
|
|
|
"\n<!-- CSS for enhancePostContent " . $name . " --> \n" .
|
|
|
|
"<style type=\"text/css\"> " . $res . "</style> \n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
/**
|
|
|
|
* Filter template blocks content
|
|
|
|
*
|
|
|
|
* @param dcCore $core dcCore instance
|
|
|
|
* @param string $tag Tempalte block name
|
|
|
|
* @param array $args Tempalte Block arguments
|
|
|
|
*/
|
|
|
|
public static function publicContentFilter(dcCore $core, $tag, $args)
|
|
|
|
{
|
|
|
|
$filters = libEPC::blogFilters();
|
|
|
|
$records = new epcRecords($core);
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
foreach($filters as $name => $filter) {
|
|
|
|
|
|
|
|
if (!isset($filter['publicContentFilter'])
|
|
|
|
|| !is_callable($filter['publicContentFilter'])
|
|
|
|
|| !libEPC::testContext($tag,$args,$filter)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($filter['has_list']) {
|
|
|
|
$filter['list'] = $records->getRecords(array(
|
|
|
|
'epc_filter' => $name)
|
|
|
|
);
|
|
|
|
if ($filter['list']->isEmpty()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
call_user_func_array(
|
|
|
|
$filter['publicContentFilter'],
|
|
|
|
[$core, $filter, $tag, $args]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|