diff --git a/index.php b/index.php index 311a6be..bc70305 100644 --- a/index.php +++ b/index.php @@ -76,17 +76,22 @@ try { && 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_key = html::escapeHTML($_POST['new_key']); $cur->epc_value = html::escapeHTML($_POST['new_value']); - $records->addRecord($cur); + if ($records->isRecord($cur->epc_filter, $cur->epc_key)) { + dcPage::addErrorNotice(__('Key already exists for this filter')); + } else { + $records->addRecord($cur); - $core->blog->triggerBlog(); + $core->blog->triggerBlog(); - dcPage::addSuccessNotice( - __('Filter successfully updated.') - ); + dcPage::addSuccessNotice( + __('Filter successfully updated.') + ); + } $core->adminurl->redirect( 'admin.plugin.enhancePostContent', ['part' => $default_part], @@ -95,6 +100,7 @@ try { } # Update filter records + $error = false; if ($action == 'saveupdaterecords' && isset($filters_id[$default_part]) && $_filters[$filters_id[$default_part]]['has_list']) { @@ -112,7 +118,12 @@ try { $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]); - $records->updRecord($id, $cur); + 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); + } } } @@ -121,10 +132,11 @@ try { $redir = !empty($_REQUEST['redir']) ? $_REQUEST['redir'] : $core->adminurl->get('admin.plugin.enhancePostContent', ['part' => $default_part]) . '#record'; - - dcPage::addSuccessNotice( - __('Filter successfully updated.') - ); + if (!$error) { + dcPage::addSuccessNotice( + __('Filter successfully updated.') + ); + } http::redirect( $redir ); @@ -135,10 +147,7 @@ try { # -- Prepare page -- -$breadcrumb = [ - html::escapeHTML($core->blog->name) => '', - __('Enhance post content') => $p_url -]; +$breadcrumb = [html::escapeHTML($core->blog->name) => '', __('Enhance post content') => '', __('Filters') => '']; $filters_combo = []; foreach($filters_id as $id => $name) { @@ -153,7 +162,7 @@ foreach($filters_id as $id => $name) { # Headers echo '