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_CONTEXT_ADMIN')) {
|
2021-08-24 20:05:23 +00:00
|
|
|
return null;
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dcPage::check('contentadmin');
|
|
|
|
|
|
|
|
# -- Prepare queries and object --
|
|
|
|
|
2021-10-31 22:22:34 +00:00
|
|
|
$_filters = libEPC::getFilters();
|
2021-10-24 21:38:49 +00:00
|
|
|
|
|
|
|
$filters_id = $filters_combo = [];
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($_filters as $id => $filter) {
|
|
|
|
$filters_id[$id] = $filter->name;
|
2021-10-31 22:22:34 +00:00
|
|
|
$filters_combo[$filter->name] = $id;
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
$action = $_POST['action'] ?? '';
|
2021-10-24 21:38:49 +00:00
|
|
|
$part = $_REQUEST['part'] ?? key($filters_id);
|
|
|
|
|
|
|
|
if (!isset($filters_id[$part])) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
$header = '';
|
2021-10-31 22:22:34 +00:00
|
|
|
$filter = $_filters[$part];
|
2021-08-23 23:55:52 +00:00
|
|
|
$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
|
2021-10-24 21:38:49 +00:00
|
|
|
if ($action == 'savefiltersetting') {
|
2021-08-24 20:05:23 +00:00
|
|
|
# Parse filters options
|
|
|
|
$f = [
|
2021-10-23 19:39:47 +00:00
|
|
|
'nocase' => !empty($_POST['filter_nocase']),
|
|
|
|
'plural' => !empty($_POST['filter_plural']),
|
2021-11-06 13:46:37 +00:00
|
|
|
'limit' => abs((int) $_POST['filter_limit']),
|
2021-10-23 19:39:47 +00:00
|
|
|
'style' => (array) $_POST['filter_style'],
|
|
|
|
'notag' => (string) $_POST['filter_notag'],
|
2021-08-24 20:05:23 +00:00
|
|
|
'tplValues' => (array) $_POST['filter_tplValues'],
|
2021-10-23 19:39:47 +00:00
|
|
|
'pubPages' => (array) $_POST['filter_pubPages']
|
2021-08-24 20:05:23 +00:00
|
|
|
];
|
|
|
|
|
2021-10-23 19:39:47 +00:00
|
|
|
$core->blog->settings->addNamespace('enhancePostContent');
|
2021-10-31 22:22:34 +00:00
|
|
|
$core->blog->settings->enhancePostContent->put('enhancePostContent_' . $filter->id(), serialize($f));
|
2021-08-24 20:05:23 +00:00
|
|
|
|
|
|
|
$core->blog->triggerBlog();
|
|
|
|
|
|
|
|
dcPage::addSuccessNotice(
|
|
|
|
__('Filter successfully updated.')
|
|
|
|
);
|
2021-09-04 17:03:02 +00:00
|
|
|
|
|
|
|
$core->adminurl->redirect(
|
2021-11-01 09:33:43 +00:00
|
|
|
'admin.plugin.enhancePostContent',
|
2021-10-24 21:38:49 +00:00
|
|
|
['part' => $part],
|
2021-09-04 17:03:02 +00:00
|
|
|
'#settings'
|
2021-08-24 20:05:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Add new filter record
|
|
|
|
if ($action == 'savenewrecord'
|
2021-10-23 19:39:47 +00:00
|
|
|
&& !empty($_POST['new_key'])
|
|
|
|
&& !empty($_POST['new_value'])
|
|
|
|
) {
|
2021-11-01 09:33:43 +00:00
|
|
|
$cur = $records->openCursor();
|
2021-10-31 22:22:34 +00:00
|
|
|
$cur->epc_filter = $filter->id();
|
2021-10-23 19:39:47 +00:00
|
|
|
$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(
|
2021-11-01 09:33:43 +00:00
|
|
|
'admin.plugin.enhancePostContent',
|
2021-10-24 21:38:49 +00:00
|
|
|
['part' => $part],
|
2021-09-04 17:03:02 +00:00
|
|
|
'#record'
|
2021-08-24 20:05:23 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
# Update filter records
|
2021-11-01 09:33:43 +00:00
|
|
|
if ($action == 'deleterecords' && $filter->has_list
|
2021-10-24 21:38:49 +00:00
|
|
|
&& !empty($_POST['epc_id']) && is_array($_POST['epc_id'])
|
2021-10-23 19:39:47 +00:00
|
|
|
) {
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($_POST['epc_id'] as $id) {
|
2021-10-24 21:38:49 +00:00
|
|
|
$records->delRecord($id);
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$core->blog->triggerBlog();
|
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
dcPage::addSuccessNotice(
|
|
|
|
__('Filter successfully updated.')
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!empty($_REQUEST['redir'])) {
|
|
|
|
http::redirect($_REQUEST['redir']);
|
|
|
|
} else {
|
|
|
|
$core->adminurl->redirect(
|
2021-11-01 09:33:43 +00:00
|
|
|
'admin.plugin.enhancePostContent',
|
2021-10-24 21:38:49 +00:00
|
|
|
['part' => $part],
|
|
|
|
'#record'
|
2021-09-04 22:43:09 +00:00
|
|
|
);
|
|
|
|
}
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
2021-11-01 09:33:43 +00:00
|
|
|
} catch (Exception $e) {
|
2021-08-24 20:05:23 +00:00
|
|
|
$core->error->add($e->getMessage());
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# -- Prepare page --
|
|
|
|
|
2021-10-31 22:22:34 +00:00
|
|
|
if ($filter->has_list) {
|
2021-10-24 21:38:49 +00:00
|
|
|
$sorts = new adminGenericFilter($core, 'epc');
|
|
|
|
$sorts->add(dcAdminFilters::getPageFilter());
|
|
|
|
$sorts->add('part', $part);
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
$params = $sorts->params();
|
2021-10-31 22:22:34 +00:00
|
|
|
$params['epc_filter'] = $filter->id();
|
2021-10-24 21:38:49 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
$list = $records->getRecords($params);
|
|
|
|
$counter = $records->getRecords($params, true);
|
|
|
|
$pager = new adminEpcList($core, $list, $counter->f(0));
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$core->error->add($e->getMessage());
|
2021-08-24 20:05:23 +00:00
|
|
|
}
|
2021-10-24 21:38:49 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
$header = $sorts->js($core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $part], '&') . '#record');
|
2021-08-23 23:55:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# -- Display page --
|
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
# Page headers
|
2021-08-23 23:55:52 +00:00
|
|
|
echo '
|
2021-08-24 20:05:23 +00:00
|
|
|
<html><head><title>' . __('Enhance post content') . '</title>' .
|
|
|
|
dcPage::jsPageTabs() .
|
2021-10-21 20:22:02 +00:00
|
|
|
dcPage::jsLoad(dcPage::getPF('enhancePostContent/js/index.js')) .
|
2021-10-24 21:38:49 +00:00
|
|
|
$header .
|
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
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
# Page title
|
|
|
|
dcPage::breadcrumb([
|
|
|
|
__('Plugins') => '',
|
|
|
|
__('Enhance post content') => '',
|
2021-10-31 22:22:34 +00:00
|
|
|
$filter->name => ''
|
2021-10-24 21:38:49 +00:00
|
|
|
]) .
|
2021-08-24 20:05:23 +00:00
|
|
|
dcPage::notices() .
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
# Filters select menu list
|
|
|
|
'<form method="get" action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '" id="filters_menu">' .
|
2021-10-28 20:57:04 +00:00
|
|
|
'<p class="anchor-nav"><label for="part" class="classic">' . __('Select filter:') . ' </label>' .
|
2021-10-24 21:38:49 +00:00
|
|
|
form::combo('part', $filters_combo, $part) . ' ' .
|
|
|
|
'<input type="submit" value="' . __('Ok') . '" />' .
|
|
|
|
form::hidden('p', 'enhancePostContent') . '</p>' .
|
2021-09-04 19:54:48 +00:00
|
|
|
'</form>';
|
2021-08-23 23:55:52 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
# Filter title and description
|
|
|
|
echo '
|
2021-10-31 22:22:34 +00:00
|
|
|
<h3>' . $filter->name . '</h3>
|
|
|
|
<p>' . $filter->help . '</p>';
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
# Filter settings
|
|
|
|
echo '
|
|
|
|
<div class="multi-part" id="setting" title="' . __('Settings') . '">
|
|
|
|
<form method="post" action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '#setting">
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
<div class="two-boxes odd">
|
|
|
|
<h4>' . __('Pages to be filtered') . '</h4>';
|
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach (libEPC::blogAllowedPubPages() as $k => $v) {
|
2021-08-24 20:05:23 +00:00
|
|
|
echo '
|
2021-10-24 21:38:49 +00:00
|
|
|
<p><label for="filter_pubPages' . $v . '">' .
|
|
|
|
form::checkbox(
|
|
|
|
['filter_pubPages[]', 'filter_pubPages' . $v],
|
|
|
|
$v,
|
2021-10-31 22:22:34 +00:00
|
|
|
in_array($v, $filter->pubPages)
|
2021-10-24 21:38:49 +00:00
|
|
|
) .
|
|
|
|
__($k) . '</label></p>';
|
|
|
|
}
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
echo '
|
|
|
|
</div><div class="two-boxes even">
|
|
|
|
<h4>' . __('Filtering') . '</h4>
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
<p><label for="filter_nocase">' .
|
2021-10-31 22:22:34 +00:00
|
|
|
form::checkbox('filter_nocase', '1', $filter->nocase) .
|
2021-10-24 21:38:49 +00:00
|
|
|
__('Case insensitive') . '</label></p>
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
<p><label for="filter_plural">' .
|
2021-10-31 22:22:34 +00:00
|
|
|
form::checkbox('filter_plural', '1', $filter->plural) .
|
2021-10-24 21:38:49 +00:00
|
|
|
__('Also use the plural') . '</label></p>
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
<p><label for="filter_limit">' .
|
|
|
|
__('Limit the number of replacement to:') . '</label>' .
|
2021-11-06 13:46:37 +00:00
|
|
|
form::number('filter_limit', ['min' => 0, 'max' => 99, 'default' => (int) $filter->limit]) . '
|
2021-10-24 21:38:49 +00:00
|
|
|
</p>
|
|
|
|
<p class="form-note">' . __('Leave it blank or set it to 0 for no limit') . '</p>
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
</div><div class="two-boxes odd">
|
|
|
|
<h4>' . __('Contents to be filtered') . '</h4>';
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach (libEPC::blogAllowedTplValues() as $k => $v) {
|
2021-10-24 21:38:49 +00:00
|
|
|
echo '
|
|
|
|
<p><label for="filter_tplValues' . $v . '">' .
|
|
|
|
form::checkbox(
|
|
|
|
['filter_tplValues[]', 'filter_tplValues' . $v],
|
|
|
|
$v,
|
2021-10-31 22:22:34 +00:00
|
|
|
in_array($v, $filter->tplValues)
|
2021-10-24 21:38:49 +00:00
|
|
|
) .
|
|
|
|
__($k) . '</label></p>';
|
|
|
|
}
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
echo '
|
|
|
|
</div><div class="two-boxes even">
|
|
|
|
<h4>' . __('Style') . '</h4>';
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
foreach ($filter->class as $k => $v) {
|
2021-08-24 20:05:23 +00:00
|
|
|
echo '
|
2021-10-24 21:38:49 +00:00
|
|
|
<p><label for="filter_style' . $k . '">' .
|
|
|
|
sprintf(__('Class "%s":'), $v) . '</label>' .
|
|
|
|
form::field(
|
2021-11-01 09:33:43 +00:00
|
|
|
['filter_style[]', 'filter_style' . $k],
|
2021-10-24 21:38:49 +00:00
|
|
|
60,
|
|
|
|
255,
|
2021-10-31 22:22:34 +00:00
|
|
|
html::escapeHTML($filter->style[$k])
|
2021-10-24 21:38:49 +00:00
|
|
|
) .
|
|
|
|
'</p>';
|
|
|
|
}
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
echo '
|
2021-10-31 22:22:34 +00:00
|
|
|
<p class="form-note">' . sprintf(__('The inserted HTML tag looks like: %s'), html::escapeHTML(str_replace('%s', '...', $filter->replace))) . '</p>
|
2021-10-24 21:38:49 +00:00
|
|
|
|
|
|
|
<p><label for="filter_notag">' . __('Ignore HTML tags:') . '</label>' .
|
2021-10-31 22:22:34 +00:00
|
|
|
form::field('filter_notag', 60, 255, html::escapeHTML($filter->notag)) . '
|
2021-10-24 21:38:49 +00:00
|
|
|
</p>
|
|
|
|
<p class="form-note">' . __('This is the list of HTML tags where content will be ignored.') . ' ' .
|
2021-10-31 22:22:34 +00:00
|
|
|
('' != $filter->htmltag ? '' : sprintf(__('Tag "%s" always be ignored.'), $filter->htmltag)) . '</p>
|
2021-10-24 21:38:49 +00:00
|
|
|
</div>
|
|
|
|
<div class="clear">
|
|
|
|
<p>' .
|
|
|
|
$core->formNonce() .
|
|
|
|
form::hidden(['action'], 'savefiltersetting') .
|
|
|
|
form::hidden(['part'], $part) . '
|
|
|
|
<input type="submit" name="save" value="' . __('Save') . '" />
|
|
|
|
</p>
|
|
|
|
</div>
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
</form>
|
|
|
|
</div>';
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
# Filter records list
|
2021-10-31 22:22:34 +00:00
|
|
|
if ($filter->has_list) {
|
2021-11-01 09:33:43 +00:00
|
|
|
$pager_url = $core->adminurl->get('admin.plugin.enhancePostContent', array_diff_key($sorts->values(true), ['page' => ''])) . '&page=%s#record';
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
echo '
|
|
|
|
<div class="multi-part" id="record" title="' . __('Records') . '">';
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
$sorts->display(['admin.plugin.enhancePostContent', '#record'], form::hidden('p', 'enhancePostContent') . form::hidden('part', $part));
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
$pager->display(
|
|
|
|
$sorts,
|
|
|
|
$pager_url,
|
2021-10-24 21:38:49 +00:00
|
|
|
'<form action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '#record" method="post" id="form-records">' .
|
|
|
|
'%s' .
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-10-24 21:38:49 +00:00
|
|
|
'<div class="two-cols">' .
|
|
|
|
'<p class="col checkboxes-helpers"></p>' .
|
2021-08-24 20:05:23 +00:00
|
|
|
|
2021-11-01 09:33:43 +00:00
|
|
|
'<p class="col right">' .
|
2021-10-24 21:38:49 +00:00
|
|
|
form::hidden('action', 'deleterecords') .
|
|
|
|
'<input id="del-action" type="submit" name="save" value="' . __('Delete selected records') . '" /></p>' .
|
2021-11-01 09:33:43 +00:00
|
|
|
$core->adminurl->getHiddenFormFields('admin.plugin.enhancePostContent', array_merge(['p' => 'enhancePostContent'], $sorts->values(true))) .
|
2021-10-24 21:38:49 +00:00
|
|
|
form::hidden('redir', $core->adminurl->get('admin.plugin.enhancePostContent', $sorts->values(true))) .
|
|
|
|
$core->formNonce() .
|
|
|
|
'</div>' .
|
|
|
|
'</form>'
|
|
|
|
);
|
|
|
|
|
|
|
|
echo '</div>';
|
|
|
|
|
|
|
|
# New record
|
|
|
|
echo '
|
|
|
|
<div class="multi-part" id="newrecord" title="' . __('New record') . '">
|
|
|
|
<form action="' . $core->adminurl->get('admin.plugin.enhancePostContent') . '#record" method="post" id="form-create">' .
|
|
|
|
|
|
|
|
'<p><label for="new_key">' . __('Key:') . '</label>' .
|
2021-11-01 09:33:43 +00:00
|
|
|
form::field('new_key', 60, 255, ['extra_html' => 'required']) .
|
2021-10-24 21:38:49 +00:00
|
|
|
'</p>' .
|
|
|
|
|
|
|
|
'<p><label for="new_value">' . __('Value:') . '</label>' .
|
2021-11-01 09:33:43 +00:00
|
|
|
form::field('new_value', 60, 255, ['extra_html' => 'required']) .
|
2021-10-24 21:38:49 +00:00
|
|
|
'</p>
|
|
|
|
|
|
|
|
<p class="clear">' .
|
|
|
|
form::hidden(['action'], 'savenewrecord') .
|
|
|
|
form::hidden(['part'], $part) .
|
|
|
|
$core->formNonce() . '
|
|
|
|
<input id="new-action" 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-11-01 09:33:43 +00:00
|
|
|
echo '</body></html>';
|