auth->makePermissions([ dcAuth::PERMISSION_CONTENT_ADMIN, ])); # -- Prepare queries and object -- $_filters = enhancePostContent::getFilters(); $filters_id = $filters_combo = []; foreach ($_filters as $id => $filter) { $filters_id[$id] = $filter->name; $filters_combo[$filter->name] = $id; } $action = $_POST['action'] ?? ''; $part = $_REQUEST['part'] ?? key($filters_id); if (!isset($filters_id[$part])) { return null; } $header = ''; $filter = $_filters[$part]; $records = new epcRecords(); # -- Action -- if (!empty($action)) { # --BEHAVIOR-- enhancePostContentAdminSave dcCore::app()->callBehavior('enhancePostContentAdminSave'); } try { # Update filter settings if ($action == 'savefiltersetting') { # Parse filters options $f = [ 'nocase' => !empty($_POST['filter_nocase']), 'plural' => !empty($_POST['filter_plural']), 'limit' => abs((int) $_POST['filter_limit']), 'style' => (array) $_POST['filter_style'], 'notag' => (string) $_POST['filter_notag'], 'tplValues' => (array) $_POST['filter_tplValues'], 'pubPages' => (array) $_POST['filter_pubPages'], ]; dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); dcCore::app()->blog->settings->__get(basename(__DIR__))->put($filter->id(), serialize($f)); dcCore::app()->blog->triggerBlog(); dcAdminNotices::addSuccessNotice( __('Filter successfully updated.') ); dcCore::app()->adminurl->redirect( 'admin.plugin.' . basename(__DIR__), ['part' => $part], '#settings' ); } # Add new filter record if ($action == 'savenewrecord' && !empty($_POST['new_key']) && !empty($_POST['new_value']) ) { $cur = $records->openCursor(); $cur->epc_filter = $filter->id(); $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)) { dcAdminNotices::addErrorNotice(__('Key already exists for this filter')); } else { $records->addRecord($cur); dcCore::app()->blog->triggerBlog(); dcAdminNotices::addSuccessNotice( __('Filter successfully updated.') ); } dcCore::app()->adminurl->redirect( 'admin.plugin.' . basename(__DIR__), ['part' => $part], '#record' ); } # Update filter records if ($action == 'deleterecords' && $filter->has_list && !empty($_POST['epc_id']) && is_array($_POST['epc_id']) ) { foreach ($_POST['epc_id'] as $id) { $records->delRecord($id); } dcCore::app()->blog->triggerBlog(); dcAdminNotices::addSuccessNotice( __('Filter successfully updated.') ); if (!empty($_REQUEST['redir'])) { http::redirect($_REQUEST['redir']); } else { dcCore::app()->adminurl->redirect( 'admin.plugin.' . basename(__DIR__), ['part' => $part], '#record' ); } } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } # -- Prepare page -- if ($filter->has_list) { $sorts = new adminGenericFilter(dcCore::app(), 'epc'); $sorts->add(dcAdminFilters::getPageFilter()); $sorts->add('part', $part); $params = $sorts->params(); $params['epc_filter'] = $filter->id(); try { $list = $records->getRecords($params); $counter = $records->getRecords($params, true); $pager = new adminEpcList(dcCore::app(), $list, $counter->f(0)); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } $header = $sorts->js(dcCore::app()->adminurl->get('admin.plugin.' . basename(__DIR__), ['part' => $part], '&') . '#record'); } # -- Display page -- # Page headers echo '
' . $filter->help . '
'; # Filter settings echo '