From 2ec18b5b494476f84ccdd77bc66de69d59fc4698 Mon Sep 17 00:00:00 2001
From: Jean-Christian Denis ' . __('No record matches the filter') . ' ' . __('No record') . '' . __('Key') . ' ',
+ 'value' => '' . __('Value') . ' ',
+ 'date' => '' . __('Date') . ' '
+ ];
+
+ $html_block =
+ '
%s' . implode($cols) . ' %s' . form::checkbox(['epc_id[]'], $this->rs->epc_id, ['checked' => $checked]) . ' ',
+ 'key' => '' . html::escapeHTML($this->rs->epc_key) . ' ',
+ 'value' => '' . html::escapeHTML($this->rs->epc_value) . ' ',
+ 'date' => '' . dt::dt2str(__('%Y-%m-%d %H:%M'), $this->rs->epc_upddt) . ' '
+ ];
+
+ return
+ '' .
+ implode($cols) .
+ ' ';
+ }
+}
\ No newline at end of file
diff --git a/inc/lib.epc.php b/inc/lib.epc.php
index f621321..0d6919d 100644
--- a/inc/lib.epc.php
+++ b/inc/lib.epc.php
@@ -328,6 +328,7 @@ class libEPC
if (isset($opt[$name]['pubPages'])) {
$filters[$name]['pubPages'] = (array) $opt[$name]['pubPages'];
}
+ $filters[$name]['name'] = $name;
}
$core->callBehavior('enhancePostContentBlogFilters', $filters);
diff --git a/index.php b/index.php
index ba046f8..1dab43f 100644
--- a/index.php
+++ b/index.php
@@ -21,14 +21,22 @@ dcPage::check('contentadmin');
# -- Prepare queries and object --
$_filters = libEPC::blogFilters();
-$filters_id = array();
+
+$filters_id = $filters_combo = [];
foreach($_filters as $name => $filter) {
$filters_id[$filter['id']] = $name;
+ $filters_combo[__($name)] = $filter['id'];
}
-$action = isset($_POST['action']) ? $_POST['action'] : '';
-$default_part = isset($_REQUEST['part']) ? $_REQUEST['part'] : key($filters_id);
+$action = $_POST['action'] ?? '';
+$part = $_REQUEST['part'] ?? key($filters_id);
+if (!isset($filters_id[$part])) {
+ return null;
+}
+
+$header = '';
+$filter = $_filters[$filters_id[$part]];
$records = new epcRecords($core);
# -- Action --
@@ -40,11 +48,8 @@ if (!empty($action)) {
try {
# Update filter settings
- if ($action == 'savefiltersetting'
- && isset($filters_id[$default_part])
- ) {
+ if ($action == 'savefiltersetting') {
# Parse filters options
- $name = $filters_id[$default_part];
$f = [
'nocase' => !empty($_POST['filter_nocase']),
'plural' => !empty($_POST['filter_plural']),
@@ -56,7 +61,7 @@ try {
];
$core->blog->settings->addNamespace('enhancePostContent');
- $core->blog->settings->enhancePostContent->put('enhancePostContent_' . $name, serialize($f));
+ $core->blog->settings->enhancePostContent->put('enhancePostContent_' . $filter['name'], serialize($f));
$core->blog->triggerBlog();
@@ -66,19 +71,18 @@ try {
$core->adminurl->redirect(
'admin.plugin.enhancePostContent',
- ['part' => $default_part],
+ ['part' => $part],
'#settings'
);
}
# Add new filter record
if ($action == 'savenewrecord'
- && isset($filters_id[$default_part])
&& !empty($_POST['new_key'])
&& !empty($_POST['new_value'])
) {
$cur = $records->openCursor();
- $cur->epc_filter = $filters_id[$default_part];
+ $cur->epc_filter = $filter['name'];
$cur->epc_key = html::escapeHTML($_POST['new_key']);
$cur->epc_value = html::escapeHTML($_POST['new_value']);
@@ -95,55 +99,34 @@ try {
}
$core->adminurl->redirect(
'admin.plugin.enhancePostContent',
- ['part' => $default_part],
+ ['part' => $part],
'#record'
);
}
# Update filter records
- $error = false;
- if ($action == 'saveupdaterecords'
- && isset($filters_id[$default_part])
- && $_filters[$filters_id[$default_part]]['has_list']
+ if ($action == 'deleterecords' && $filter['has_list']
+ && !empty($_POST['epc_id']) && is_array($_POST['epc_id'])
) {
- 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]);
-
- 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);
- }
- }
+ foreach($_POST['epc_id'] as $id) {
+ $records->delRecord($id);
}
$core->blog->triggerBlog();
- $redir = !empty($_REQUEST['redir']) ?
- $_REQUEST['redir'] :
- $core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $default_part]) . '#record';
- if (!$error) {
- dcPage::addSuccessNotice(
- __('Filter successfully updated.')
+ dcPage::addSuccessNotice(
+ __('Filter successfully updated.')
+ );
+
+ if (!empty($_REQUEST['redir'])) {
+ http::redirect($_REQUEST['redir']);
+ } else {
+ $core->adminurl->redirect(
+ 'admin.plugin.enhancePostContent',
+ ['part' => $part],
+ '#record'
);
}
- http::redirect(
- $redir
- );
}
} catch(Exception $e) {
$core->error->add($e->getMessage());
@@ -151,267 +134,201 @@ try {
# -- Prepare page --
-$breadcrumb = [html::escapeHTML($core->blog->name) => '', __('Enhance post content') => '', __('Filters') => ''];
+if ($filter['has_list']) {
+ $sorts = new adminGenericFilter($core, 'epc');
+ $sorts->add(dcAdminFilters::getPageFilter());
+ $sorts->add('part', $part);
-$filters_combo = [];
-foreach($filters_id as $id => $name) {
- if ($default_part == $id) {
- $breadcrumb[__($filters_id[$default_part])] = '';
+ $params = $sorts->params();
+ $params['epc_filter'] = $filter['name'];
+
+ 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());
}
- $filters_combo[__($name)] = $id;
+
+ $header = $sorts->js($core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $part], '&').'#record');
}
# -- Display page --
-# Headers
+# Page headers
echo '
' . $filter['help'] . '
'; - # Filter title and description +# Filter settings +echo ' +