2021-08-23 23:55:52 +00:00
|
|
|
<?php
|
2021-09-02 18:35:25 +00:00
|
|
|
/**
|
|
|
|
* @brief enhancePostContent, a plugin for Dotclear 2
|
|
|
|
*
|
|
|
|
* @package Dotclear
|
|
|
|
* @subpackage Plugin
|
|
|
|
*
|
|
|
|
* @author Jean-Christian Denis and Contributors
|
|
|
|
*
|
|
|
|
* @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_CONTEXT_ADMIN')) {
|
2021-08-24 20:05:23 +00:00
|
|
|
return null;
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dcPage::check('contentadmin');
|
|
|
|
|
|
|
|
$core->blog->settings->addNamespace('enhancePostContent');
|
|
|
|
$s = $core->blog->settings->enhancePostContent;
|
|
|
|
|
|
|
|
# -- Prepare queries and object --
|
|
|
|
|
|
|
|
$_filters = libEPC::blogFilters();
|
|
|
|
$filters_id = array();
|
|
|
|
foreach($_filters as $name => $filter) {
|
2021-08-24 20:05:23 +00:00
|
|
|
$filters_id[$filter['id']] = $name;
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$action = isset($_POST['action']) ? $_POST['action'] : '';
|
|
|
|
$default_part = isset($_REQUEST['part']) ? $_REQUEST['part'] : key($filters_id);
|
|
|
|
|
|
|
|
$records = new epcRecords($core);
|
|
|
|
|
|
|
|
# -- Action --
|
|
|
|
|
|
|
|
if (!empty($action)) {
|
2021-08-24 20:05:23 +00:00
|
|
|
# --BEHAVIOR-- enhancePostContentAdminSave
|
|
|
|
$core->callBehavior('enhancePostContentAdminSave', $core);
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
try {
|
|
|
|
# Update filter settings
|
|
|
|
if ($action == 'savefiltersetting'
|
|
|
|
&& isset($filters_id[$default_part])) {
|
|
|
|
# Parse filters options
|
|
|
|
$name = $filters_id[$default_part];
|
|
|
|
$f = [
|
|
|
|
'nocase' => !empty($_POST['filter_nocase']),
|
|
|
|
'plural' => !empty($_POST['filter_plural']),
|
|
|
|
'limit' => abs((integer) $_POST['filter_limit']),
|
|
|
|
'style' => (array) $_POST['filter_style'],
|
|
|
|
'notag' => (string) $_POST['filter_notag'],
|
|
|
|
'tplValues' => (array) $_POST['filter_tplValues'],
|
|
|
|
'pubPages' => (array) $_POST['filter_pubPages']
|
|
|
|
];
|
|
|
|
|
|
|
|
$s->put('enhancePostContent_' . $name, serialize($f));
|
|
|
|
|
|
|
|
$core->blog->triggerBlog();
|
|
|
|
|
|
|
|
dcPage::addSuccessNotice(
|
|
|
|
__('Filter successfully updated.')
|
|
|
|
);
|
2021-09-04 17:03:02 +00:00
|
|
|
|
|
|
|
$core->adminurl->redirect(
|
|
|
|
'admin.plugin.enhancePostContent',
|
|
|
|
['part' => $default_part],
|
|
|
|
'#settings'
|
2021-08-24 20:05:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add new filter record
|
|
|
|
if ($action == 'savenewrecord'
|
|
|
|
&& isset($filters_id[$default_part])
|
|
|
|
&& !empty($_POST['new_key'])
|
|
|
|
&& !empty($_POST['new_value'])) {
|
2021-09-04 22:43:09 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
$cur = $records->openCursor();
|
|
|
|
$cur->epc_filter = $filters_id[$default_part];
|
|
|
|
$cur->epc_key = html::escapeHTML($_POST['new_key']);
|
|
|
|
$cur->epc_value = html::escapeHTML($_POST['new_value']);
|
2021-09-04 22:43:09 +00:00
|
|
|
if ($records->isRecord($cur->epc_filter, $cur->epc_key)) {
|
|
|
|
dcPage::addErrorNotice(__('Key already exists for this filter'));
|
|
|
|
} else {
|
|
|
|
$records->addRecord($cur);
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-09-04 22:43:09 +00:00
|
|
|
$core->blog->triggerBlog();
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-09-04 22:43:09 +00:00
|
|
|
dcPage::addSuccessNotice(
|
|
|
|
__('Filter successfully updated.')
|
|
|
|
);
|
|
|
|
}
|
2021-09-04 17:03:02 +00:00
|
|
|
$core->adminurl->redirect(
|
|
|
|
'admin.plugin.enhancePostContent',
|
|
|
|
['part' => $default_part],
|
|
|
|
'#record'
|
2021-08-24 20:05:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Update filter records
|
2021-09-04 22:43:09 +00:00
|
|
|
$error = false;
|
2021-08-24 20:05:23 +00:00
|
|
|
if ($action == 'saveupdaterecords'
|
|
|
|
&& isset($filters_id[$default_part])
|
|
|
|
&& $_filters[$filters_id[$default_part]]['has_list']) {
|
|
|
|
foreach($_POST['epc_id'] as $k => $id) {
|
|
|
|
|
|
|
|
$k = abs((integer) $k);
|
|
|
|
$id = abs((integer) $id);
|
|
|
|
|
|
|
|
if (empty($_POST['epc_key'][$k])
|
|
|
|
|| empty($_POST['epc_value'][$k])) {
|
|
|
|
$records->delRecord($id);
|
|
|
|
} elseif ($_POST['epc_key'][$k] != $_POST['epc_old_key'][$k]
|
|
|
|
|| $_POST['epc_value'][$k] != $_POST['epc_old_value'][$k]) {
|
|
|
|
$cur = $records->openCursor();
|
|
|
|
$cur->epc_filter = $filters_id[$default_part];
|
|
|
|
$cur->epc_key = html::escapeHTML($_POST['epc_key'][$k]);
|
|
|
|
$cur->epc_value = html::escapeHTML($_POST['epc_value'][$k]);
|
2021-09-04 22:43:09 +00:00
|
|
|
if ($records->isRecord($cur->epc_filter, $cur->epc_key, $id)) {
|
|
|
|
dcPage::addErrorNotice(__('Key already exists for this filter'));
|
|
|
|
$error = true;
|
|
|
|
} else {
|
|
|
|
$records->updRecord($id, $cur);
|
|
|
|
}
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$core->blog->triggerBlog();
|
|
|
|
|
|
|
|
$redir = !empty($_REQUEST['redir']) ?
|
|
|
|
$_REQUEST['redir'] :
|
2021-09-04 17:03:02 +00:00
|
|
|
$core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $default_part]) . '#record';
|
2021-09-04 22:43:09 +00:00
|
|
|
if (!$error) {
|
|
|
|
dcPage::addSuccessNotice(
|
|
|
|
__('Filter successfully updated.')
|
|
|
|
);
|
|
|
|
}
|
2021-08-24 20:05:23 +00:00
|
|
|
http::redirect(
|
|
|
|
$redir
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch(Exception $e) {
|
|
|
|
$core->error->add($e->getMessage());
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# -- Prepare page --
|
|
|
|
|
2021-09-04 22:43:09 +00:00
|
|
|
$breadcrumb = [html::escapeHTML($core->blog->name) => '', __('Enhance post content') => '', __('Filters') => ''];
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-09-04 19:54:48 +00:00
|
|
|
$filters_combo = [];
|
2021-08-23 23:55:52 +00:00
|
|
|
foreach($filters_id as $id => $name) {
|
2021-08-24 20:05:23 +00:00
|
|
|
if ($default_part == $id) {
|
|
|
|
$breadcrumb[__($filters_id[$default_part])] = '';
|
|
|
|
}
|
2021-09-04 19:54:48 +00:00
|
|
|
$filters_combo[__($name)] = $id;
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# -- Display page --
|
|
|
|
|
|
|
|
# Headers
|
|
|
|
echo '
|
2021-08-24 20:05:23 +00:00
|
|
|
<html><head><title>' . __('Enhance post content') . '</title>' .
|
2021-09-04 22:43:09 +00:00
|
|
|
//dcPage::jsLoad('js/_posts_list.js') .
|
2021-08-24 20:05:23 +00:00
|
|
|
dcPage::jsToolbar() .
|
|
|
|
dcPage::jsPageTabs() .
|
2021-10-21 20:22:02 +00:00
|
|
|
dcPage::jsLoad(dcPage::getPF('enhancePostContent/js/index.js')) .
|
2021-08-23 23:55:52 +00:00
|
|
|
|
|
|
|
# --BEHAVIOR-- enhancePostContentAdminHeader
|
2021-08-24 20:05:23 +00:00
|
|
|
$core->callBehavior('enhancePostContentAdminHeader', $core) . '
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
</head><body>' .
|
2021-08-23 23:55:52 +00:00
|
|
|
|
|
|
|
# Title
|
2021-08-24 20:05:23 +00:00
|
|
|
dcPage::breadcrumb($breadcrumb) .
|
|
|
|
dcPage::notices() .
|
2021-08-23 23:55:52 +00:00
|
|
|
|
|
|
|
# Filters list
|
2021-09-04 19:54:48 +00:00
|
|
|
'<form method="post" action="' . $p_url . '&tab=settings">' .
|
2021-09-04 22:43:09 +00:00
|
|
|
'<p class="anchor-nav"><label for="epc_tab" class="classic">' . __('Select filter:') . ' </label>' .
|
2021-09-04 19:54:48 +00:00
|
|
|
form::combo('part', $filters_combo, $default_part) . ' ' .
|
|
|
|
$core->formNonce() .
|
|
|
|
'<input type="submit" value="' . __('Ok') . '" /></p>' .
|
|
|
|
'</form>';
|
2021-08-23 23:55:52 +00:00
|
|
|
|
|
|
|
# Filter content
|
|
|
|
if (isset($filters_id[$default_part])) {
|
|
|
|
|
2021-08-24 20:05:23 +00:00
|
|
|
$name = $filters_id[$default_part];
|
|
|
|
$filter = $_filters[$name];
|
|
|
|
|
|
|
|
# Filter title and description
|
|
|
|
echo '
|
|
|
|
<h3>' . __($filters_id[$default_part]) . '</h3>
|
|
|
|
<p>' . $filter['help'] . '</p>';
|
|
|
|
|
|
|
|
# Filter settings
|
|
|
|
echo '
|
|
|
|
<div class="multi-part" id="setting" title="' . __('Settings') . '">
|
|
|
|
<form method="post" action="' . $p_url . '&part=' . $default_part . '&tab=setting"><div>';
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<div class="two-boxes odd">
|
|
|
|
<h4>' . __('Pages to be filtered') . '</h4>';
|
|
|
|
|
|
|
|
foreach(libEPC::blogAllowedPubPages() as $k => $v) {
|
|
|
|
echo '
|
|
|
|
<p><label for="filter_pubPages' . $v . '">' .
|
|
|
|
form::checkbox(
|
|
|
|
['filter_pubPages[]', 'filter_pubPages' . $v],
|
|
|
|
$v,
|
|
|
|
in_array($v, $filter['pubPages'])
|
|
|
|
) .
|
|
|
|
__($k) . '</label></p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
|
|
|
'</div>';
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<div class="two-boxes even">
|
|
|
|
<h4>' . __('Filtering') . '</h4>
|
|
|
|
|
|
|
|
<p><label for="filter_nocase">' .
|
|
|
|
form::checkbox('filter_nocase', '1', $filter['nocase']) .
|
|
|
|
__('Case insensitive') . '</label></p>
|
|
|
|
|
|
|
|
<p><label for="filter_plural">' .
|
|
|
|
form::checkbox('filter_plural', '1', $filter['plural']) .
|
|
|
|
__('Also use the plural') . '</label></p>
|
|
|
|
|
|
|
|
<p><label for="filter_limit">' .
|
|
|
|
__('Limit the number of replacement to:') . '</label>' .
|
|
|
|
form::field('filter_limit', 4, 10, html::escapeHTML($filter['limit'])) . '
|
|
|
|
</p>
|
|
|
|
<p class="form-note">' . __('Leave it blank or set it to 0 for no limit') . '</p>
|
|
|
|
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<div class="two-boxes odd">
|
|
|
|
<h4>' . __('Contents to be filtered') . '</h4>';
|
|
|
|
|
|
|
|
foreach(libEPC::blogAllowedTplValues() as $k => $v) {
|
|
|
|
echo '
|
|
|
|
<p><label for="filter_tplValues' . $v . '">' .
|
|
|
|
form::checkbox(
|
|
|
|
['filter_tplValues[]', 'filter_tplValues' . $v],
|
|
|
|
$v,
|
|
|
|
in_array($v, $filter['tplValues'])
|
|
|
|
) .
|
|
|
|
__($k) . '</label></p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo
|
|
|
|
'</div>';
|
|
|
|
|
|
|
|
echo
|
|
|
|
'<div class="two-boxes even">
|
|
|
|
<h4>' . __('Style') . '</h4>';
|
|
|
|
|
|
|
|
foreach($filter['class'] as $k => $v) {
|
|
|
|
echo '
|
|
|
|
<p><label for="filter_style' . $k . '">' .
|
|
|
|
sprintf(__('Class "%s":'), $v) . '</label>' .
|
|
|
|
form::field(
|
|
|
|
['filter_style[]', 'filter_style'.$k],
|
|
|
|
60,
|
|
|
|
255,
|
|
|
|
html::escapeHTML($filter['style'][$k])
|
|
|
|
) .
|
|
|
|
'</p>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<p class="form-note">' . sprintf(__('The inserted HTML tag looks like: %s'), html::escapeHTML(str_replace('%s', '...', $filter['replace']))) . '</p>
|
|
|
|
|
|
|
|
<p><label for="filter_notag">' . __('Ignore HTML tags:') . '</label>' .
|
|
|
|
form::field('filter_notag', 60, 255, html::escapeHTML($filter['notag'])) . '
|
|
|
|
</p>
|
|
|
|
<p class="form-note">' . __('This is the list of HTML tags where content will be ignored.') . ' ' .
|
|
|
|
(empty($filter['htmltag']) ? '' : sprintf(__('Tag "%s" always be ignored.'), $filter['htmltag'])) . '</p>
|
|
|
|
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
echo '</div>
|
|
|
|
<div class="clear">
|
|
|
|
<p>' .
|
|
|
|
$core->formNonce() .
|
|
|
|
form::hidden(['action'], 'savefiltersetting') . '
|
|
|
|
<input type="submit" name="save" value="' . __('Save') . '" />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</form>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
# Filter records list
|
|
|
|
if ($filter['has_list']) {
|
2021-10-21 21:07:29 +00:00
|
|
|
$sorts = new adminGenericFilter($core, 'epc');
|
|
|
|
$sorts->add(dcAdminFilters::getPageFilter());
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-21 21:07:29 +00:00
|
|
|
$params = $sorts->params();
|
2021-08-24 20:05:23 +00:00
|
|
|
$params['epc_filter'] = $name;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$list = $records->getRecords($params);
|
|
|
|
$counter = $records->getRecords($params, true);
|
2021-09-04 22:43:09 +00:00
|
|
|
|
|
|
|
$pager_url = $p_url .
|
2021-10-21 21:07:29 +00:00
|
|
|
'&nb=' . $sorts->nb .
|
2021-09-04 22:43:09 +00:00
|
|
|
'&sortby=%s' .
|
2021-10-21 21:07:29 +00:00
|
|
|
'&order=%s' .
|
2021-09-04 22:43:09 +00:00
|
|
|
'&page=%s' .
|
|
|
|
'&part=' . $default_part .
|
|
|
|
'#record';
|
|
|
|
|
2021-10-21 21:21:32 +00:00
|
|
|
$pager = new dcPager($sorts->page, $counter->f(0), $sorts->nb, 10);
|
2021-10-21 21:07:29 +00:00
|
|
|
$pager->base_url = sprintf($pager_url, $sorts->sortby, $sorts->order, '%s');
|
2021-08-24 20:05:23 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
$core->error->add($e->getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<div class="multi-part" id="record" title="' . __('Records') . '">';
|
|
|
|
|
|
|
|
if ($core->error->flag() || $list->isEmpty()) {
|
|
|
|
echo '<p>' . __('No record') . '</p>';
|
|
|
|
} else {
|
|
|
|
echo '
|
2021-10-21 21:21:32 +00:00
|
|
|
<form action="' . sprintf($pager_url, $sorts->sortby, $sorts->order, $sorts->page) . '" method="post">' .
|
|
|
|
|
|
|
|
$pager->getLinks() . '
|
|
|
|
|
2021-09-04 19:54:48 +00:00
|
|
|
<div class="table-outer">
|
|
|
|
<table><caption class="hidden">' . __('Records') . '</caption>
|
2021-10-21 21:07:29 +00:00
|
|
|
<thead><tr>';
|
|
|
|
|
|
|
|
$lines = [
|
|
|
|
__('Key') => 'epc_key',
|
|
|
|
__('Value') => 'epc_value',
|
|
|
|
__('Date') => 'epc_date'
|
|
|
|
];
|
|
|
|
foreach($lines as $k => $v) {
|
|
|
|
echo '<th><a href="' . sprintf($pager_url, $v, $sorts->sortby == $v ? $sorts->order == 'asc' ? 'desc' : 'asc' : $sorts->order, $sorts->page) . '">' .$k . '</a></th>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
2021-08-24 20:05:23 +00:00
|
|
|
</tr></thead>
|
|
|
|
<tbody>';
|
|
|
|
|
|
|
|
while($list->fetch()) {
|
|
|
|
echo '
|
|
|
|
<tr class="line">
|
|
|
|
<td class="nowrap">' .
|
|
|
|
form::hidden(['epc_id[]'], $list->epc_id) .
|
|
|
|
form::hidden(['epc_old_key[]'], html::escapeHTML($list->epc_key)) .
|
|
|
|
form::hidden(['epc_old_value[]'], html::escapeHTML($list->epc_value)) .
|
|
|
|
form::field(['epc_key[]'], 30, 225, html::escapeHTML($list->epc_key), '') . '</td>
|
|
|
|
<td class="maximal">' .
|
2021-09-04 19:54:48 +00:00
|
|
|
form::field(['epc_value[]'], 90, 225, html::escapeHTML($list->epc_value), '') . '</td>
|
|
|
|
<td class="nowrap count">' .
|
2021-08-24 20:05:23 +00:00
|
|
|
dt::dt2str(__('%Y-%m-%d %H:%M'), $list->epc_upddt,$core->auth->getInfo('user_tz')) . '</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '
|
|
|
|
</tbody>
|
2021-09-04 19:54:48 +00:00
|
|
|
</table></div>
|
2021-10-21 21:21:32 +00:00
|
|
|
<p class="form-note">' . __('In order to remove a record, leave empty its key or value.') . '</p>' .
|
|
|
|
|
|
|
|
$pager->getLinks() . '
|
2021-08-24 20:05:23 +00:00
|
|
|
|
|
|
|
<div class="clear">
|
|
|
|
<p>' .
|
|
|
|
$core->formNonce() .
|
2021-10-21 21:07:29 +00:00
|
|
|
form::hidden(['redir'], sprintf($pager_url, $sorts->sortby, $sorts->order, $sorts->page)) .
|
2021-08-24 20:05:23 +00:00
|
|
|
form::hidden(['action'], 'saveupdaterecords') . '
|
|
|
|
<input type="submit" name="save" value="' . __('Save') . '" />
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</form>';
|
|
|
|
}
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
# New record
|
|
|
|
echo '
|
|
|
|
<div class="multi-part" id="newrecord" title="' . __('New record') . '">
|
2021-09-04 22:43:09 +00:00
|
|
|
<form action="' .
|
|
|
|
$core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $default_part]) .
|
|
|
|
'#record" method="post">' .
|
2021-08-24 20:05:23 +00:00
|
|
|
|
|
|
|
'<p><label for="new_key">' . __('Key:') . '</label>' .
|
|
|
|
form::field('new_key', 60, 255) .
|
|
|
|
'</p>' .
|
|
|
|
|
|
|
|
'<p><label for="new_value">' . __('Value:') . '</label>' .
|
|
|
|
form::field('new_value', 60, 255) .
|
|
|
|
'</p>
|
|
|
|
|
|
|
|
<p class="clear">' .
|
|
|
|
form::hidden(['action'], 'savenewrecord') .
|
|
|
|
$core->formNonce() . '
|
|
|
|
<input type="submit" name="save" value="' . __('Save') . '" />
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
</div>';
|
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# --BEHAVIOR-- enhancePostContentAdminPage
|
2021-08-24 20:05:23 +00:00
|
|
|
$core->callBehavior('enhancePostContentAdminPage', $core);
|
2021-08-23 23:55:52 +00:00
|
|
|
|
|
|
|
dcPage::helpBlock('enhancePostContent');
|
|
|
|
|
2021-09-04 19:54:48 +00:00
|
|
|
echo '</body></html>';
|