2021-08-23 23:55:52 +00:00
|
|
|
<?php
|
2021-09-02 18:35:25 +00:00
|
|
|
/**
|
|
|
|
* @brief enhancePostContent, a plugin for Dotclear 2
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-09-02 18:35:25 +00:00
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-09-02 18:35:25 +00:00
|
|
|
* @author Jean-Christian Denis and Contributors
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-09-02 18:35:25 +00:00
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-08-23 23:55:52 +00:00
|
|
|
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
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-08-24 20:05:23 +00:00
|
|
|
* @param dcCore $core dcCore instance
|
|
|
|
*/
|
|
|
|
public static function publicHeadContent(dcCore $core)
|
|
|
|
{
|
2021-10-30 20:05:31 +00:00
|
|
|
echo dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('epccss'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function css($args)
|
|
|
|
{
|
2021-11-01 09:33:43 +00:00
|
|
|
$css = [];
|
2021-10-31 22:22:34 +00:00
|
|
|
$filters = libEPC::getFilters();
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($filters as $id => $filter) {
|
2021-11-13 10:54:37 +00:00
|
|
|
if ('' == $filter->class || '' == $filter->style) {
|
2021-08-24 20:05:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
$res = '';
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($filter->class as $k => $class) {
|
2021-10-31 22:22:34 +00:00
|
|
|
$styles = $filter->style;
|
2021-11-01 09:33:43 +00:00
|
|
|
$style = html::escapeHTML(trim($styles[$k]));
|
2021-08-24 20:05:23 +00:00
|
|
|
if ('' != $style) {
|
2021-11-01 09:33:43 +00:00
|
|
|
$res .= $class . ' {' . $style . '} ';
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
if (!empty($res)) {
|
2021-11-01 09:33:43 +00:00
|
|
|
$css[] = '/* CSS for enhancePostContent ' . $id . " */ \n" . $res . "\n";
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-10-30 20:05:31 +00:00
|
|
|
|
|
|
|
header('Content-Type: text/css; charset=UTF-8');
|
|
|
|
|
|
|
|
echo implode("\n", $css);
|
|
|
|
|
|
|
|
exit;
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
/**
|
|
|
|
* Filter template blocks content
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-08-24 20:05:23 +00:00
|
|
|
* @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)
|
|
|
|
{
|
2021-10-31 22:22:34 +00:00
|
|
|
$filters = libEPC::getFilters();
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($filters as $id => $filter) {
|
2021-10-31 22:22:34 +00:00
|
|
|
if (!libEPC::testContext($tag, $args, $filter)) {
|
2021-08-24 20:05:23 +00:00
|
|
|
continue;
|
|
|
|
}
|
2021-10-31 22:22:34 +00:00
|
|
|
$filter->publicContent($tag, $args);
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-01 09:33:43 +00:00
|
|
|
}
|