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
|
|
|
}
|
|
|
|
|
2022-11-13 20:30:48 +00:00
|
|
|
dcCore::app()->addBehavior(
|
2021-08-24 20:05:23 +00:00
|
|
|
'initWidgets',
|
|
|
|
['enhancePostContentWidget', 'adminContentList']
|
2021-08-23 23:55:52 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup DC_PLUGIN_ENHANCEPOSTCONTENT
|
|
|
|
* @brief Filter posts content - widgets methods.
|
|
|
|
* @since 2.6
|
|
|
|
*/
|
|
|
|
class enhancePostContentWidget
|
|
|
|
{
|
2021-08-24 20:05:23 +00:00
|
|
|
/**
|
|
|
|
* Admin part for widget that show extracted content
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-08-24 20:05:23 +00:00
|
|
|
* @param dcWidgets $w dcWidgets instance
|
|
|
|
*/
|
|
|
|
public static function adminContentList($w)
|
|
|
|
{
|
|
|
|
$w->create(
|
|
|
|
'epclist',
|
|
|
|
__('Enhance post content'),
|
|
|
|
['enhancePostContentWidget', 'publicContentList'],
|
|
|
|
null,
|
|
|
|
__('List filtered contents.')
|
|
|
|
);
|
|
|
|
# Title
|
2021-10-31 22:22:34 +00:00
|
|
|
$w->epclist->addTitle(__('In this article'));
|
2021-08-24 20:05:23 +00:00
|
|
|
# Text
|
|
|
|
$w->epclist->setting(
|
|
|
|
'text',
|
|
|
|
__('Description:'),
|
|
|
|
'',
|
|
|
|
'text'
|
|
|
|
);
|
|
|
|
# Type
|
2021-10-31 22:22:34 +00:00
|
|
|
$filters = libEPC::getFilters();
|
2021-11-01 09:33:43 +00:00
|
|
|
$types = [];
|
|
|
|
foreach ($filters as $id => $filter) {
|
2021-10-31 22:22:34 +00:00
|
|
|
$types[$filter->name] = $id;
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
$w->epclist->setting(
|
|
|
|
'type',
|
|
|
|
__('Type:'),
|
|
|
|
'Definition',
|
|
|
|
'combo',
|
|
|
|
$types
|
|
|
|
);
|
|
|
|
# Content
|
|
|
|
$contents = libEPC::defaultAllowedWidgetValues();
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($contents as $k => $v) {
|
2021-08-24 20:05:23 +00:00
|
|
|
$w->epclist->setting(
|
|
|
|
'content' . $v['id'],
|
|
|
|
sprintf(__('Enable filter on %s'), __($k)),
|
|
|
|
1,
|
|
|
|
'check'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
# Case sensitive
|
|
|
|
$w->epclist->setting(
|
|
|
|
'nocase',
|
|
|
|
__('Search case insensitive'),
|
|
|
|
0,
|
|
|
|
'check'
|
|
|
|
);
|
|
|
|
# Plural
|
|
|
|
$w->epclist->setting(
|
|
|
|
'plural',
|
|
|
|
__('Search also plural'),
|
|
|
|
0,
|
|
|
|
'check'
|
|
|
|
);
|
|
|
|
# Show count
|
|
|
|
$w->epclist->setting(
|
|
|
|
'show_total',
|
|
|
|
__('Show the number of appearance'),
|
|
|
|
1,
|
|
|
|
'check'
|
|
|
|
);
|
2021-10-31 22:22:34 +00:00
|
|
|
# widget options
|
|
|
|
$w->epclist
|
|
|
|
->addContentOnly()
|
|
|
|
->addClass()
|
|
|
|
->addOffline();
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Public part for widget that show extracted content
|
2021-11-01 09:33:43 +00:00
|
|
|
*
|
2021-08-24 20:05:23 +00:00
|
|
|
* @param dcWidget $w dcWidget instance
|
|
|
|
*/
|
|
|
|
public static function publicContentList($w)
|
|
|
|
{
|
2021-10-31 22:22:34 +00:00
|
|
|
if ($w->offline) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-11-13 20:30:48 +00:00
|
|
|
dcCore::app()->blog->settings->addNamespace('enhancePostContent');
|
2021-08-24 20:05:23 +00:00
|
|
|
|
|
|
|
# Page
|
2022-11-13 20:30:48 +00:00
|
|
|
if (!dcCore::app()->blog->settings->enhancePostContent->enhancePostContent_active
|
|
|
|
|| !in_array(dcCore::app()->ctx->current_tpl, ['post.html', 'page.html'])
|
2021-10-31 22:22:34 +00:00
|
|
|
) {
|
2021-08-24 20:05:23 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Content
|
|
|
|
$content = '';
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach (libEPC::defaultAllowedWidgetValues() as $k => $v) {
|
2021-08-24 20:05:23 +00:00
|
|
|
$ns = 'content' . $v['id'];
|
2021-10-31 22:22:34 +00:00
|
|
|
if ($w->$ns && is_callable($v['cb'])) {
|
2021-08-24 20:05:23 +00:00
|
|
|
$content .= call_user_func_array(
|
2021-10-31 22:22:34 +00:00
|
|
|
$v['cb'],
|
2022-11-13 20:30:48 +00:00
|
|
|
[dcCore::app(), $w]
|
2021-08-24 20:05:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($content)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Filter
|
2021-11-01 09:33:43 +00:00
|
|
|
$list = [];
|
2021-10-31 22:22:34 +00:00
|
|
|
$filters = libEPC::getFilters();
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-31 22:22:34 +00:00
|
|
|
if (isset($filters[$w->type])) {
|
|
|
|
$filters[$w->type]->nocase = $w->nocase;
|
|
|
|
$filters[$w->type]->plural = $w->plural;
|
|
|
|
$filters[$w->type]->widgetList($content, $w, $list);
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($list)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse result
|
|
|
|
$res = '';
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($list as $line) {
|
2021-08-24 20:05:23 +00:00
|
|
|
if (empty($line['matches'][0]['match'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
$res .= '<li>' . $line['matches'][0]['match'] .
|
|
|
|
($w->show_total ? ' (' . $line['total'] . ')' : '') .
|
2021-08-24 20:05:23 +00:00
|
|
|
'</li>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($res)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-08-24 21:17:43 +00:00
|
|
|
return $w->renderDiv(
|
2021-11-01 09:33:43 +00:00
|
|
|
$w->content_only,
|
|
|
|
$w->class,
|
|
|
|
'id="epc_' . $w->type . '"',
|
2021-08-24 21:17:43 +00:00
|
|
|
($w->title ? $w->renderTitle(html::escapeHTML($w->title)) : '') .
|
|
|
|
($w->text ? '<p>' . html::escapeHTML($w->text) . '</p>' : '') .
|
|
|
|
'<ul>' . $res . '</ul>'
|
|
|
|
);
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
2021-11-01 09:33:43 +00:00
|
|
|
}
|