blog->settings->addNamespace('enhancePostContent'); $s = $core->blog->settings->enhancePostContent; # -- Prepare queries and object -- $_filters = libEPC::blogFilters(); $filters_id = array(); foreach($_filters as $name => $filter) { $filters_id[$filter['id']] = $name; } $action = isset($_POST['action']) ? $_POST['action'] : ''; $default_part = isset($_REQUEST['part']) ? $_REQUEST['part'] : key($filters_id); $records = new epcRecords($core); # -- Action -- if (!empty($action)) { # --BEHAVIOR-- enhancePostContentAdminSave $core->callBehavior('enhancePostContentAdminSave', $core); } 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.') ); $core->adminurl->redirect( 'admin.plugin.enhancePostContent', ['part' => $default_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_key = html::escapeHTML($_POST['new_key']); $cur->epc_value = html::escapeHTML($_POST['new_value']); if ($records->isRecord($cur->epc_filter, $cur->epc_key)) { dcPage::addErrorNotice(__('Key already exists for this filter')); } else { $records->addRecord($cur); $core->blog->triggerBlog(); dcPage::addSuccessNotice( __('Filter successfully updated.') ); } $core->adminurl->redirect( 'admin.plugin.enhancePostContent', ['part' => $default_part], '#record' ); } # Update filter records $error = false; 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]); 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); } } } $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.') ); } http::redirect( $redir ); } } catch(Exception $e) { $core->error->add($e->getMessage()); } # -- Prepare page -- $breadcrumb = [html::escapeHTML($core->blog->name) => '', __('Enhance post content') => '', __('Filters') => '']; $filters_combo = []; foreach($filters_id as $id => $name) { if ($default_part == $id) { $breadcrumb[__($filters_id[$default_part])] = ''; } $filters_combo[__($name)] = $id; } # -- Display page -- # Headers echo '
' . $filter['help'] . '
'; # Filter settings echo '' . __('No record') . '
'; } else { echo ' '; } echo '