From 57fee61b96be312d74e725e750d71e29d8ac3042 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Wed, 7 Dec 2022 01:07:56 +0100 Subject: [PATCH] refresh admin, group index (WIP) --- _admin.php | 15 +- _prepend.php | 1 + advanced.php | 71 ---- edit.php | 81 ---- inc/admin.pager.templator.php | 29 +- inc/class.templator.media.php | 10 + index.php | 763 ++++++++++++++++++++++++---------- js/form.js | 14 - js/posts.js | 10 + js/script.js | 15 - template_posts.php | 147 ------- 11 files changed, 598 insertions(+), 558 deletions(-) delete mode 100644 advanced.php delete mode 100644 edit.php create mode 100644 inc/class.templator.media.php delete mode 100644 js/form.js create mode 100644 js/posts.js delete mode 100644 js/script.js delete mode 100644 template_posts.php diff --git a/_admin.php b/_admin.php index c0accfd..10e8ede 100644 --- a/_admin.php +++ b/_admin.php @@ -7,7 +7,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { dcCore::app()->auth->setPermissionType(initTemplator::PERMISSION_TEMPLATOR, __('manage templates')); dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( - __('Templates'), + __('Templates engine'), dcCore::app()->adminurl->get('admin.plugin.templator'), urldecode(dcPage::getPF('templator/icon.png')), preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.templator')) . '(&.*)?$/', $_SERVER['REQUEST_URI']), @@ -34,6 +34,19 @@ if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ dcCore::app()->addBehavior('adminPostsActions', ['templatorBehaviors','adminPostsActions']); dcCore::app()->addBehavior('adminPagesActions', ['templatorBehaviors','adminPostsActions']); + dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts) { + $sorts['templator'] = [ + __('Templates engine'), + [ + __('Date') => 'post_upddt', + __('Title') => 'post_title', + __('Category') => 'cat_id', + ], + 'post_upddt', + 'desc', + [__('Entries per page'), 30], + ]; + }); } class templatorBehaviors diff --git a/_prepend.php b/_prepend.php index a4500cb..e80a1a6 100644 --- a/_prepend.php +++ b/_prepend.php @@ -5,6 +5,7 @@ if (!defined('DC_RC_PATH')) { } Clearbricks::lib()->autoload([ 'dcTemplator' => __DIR__ . '/inc/class.templator.php', + 'templatorMedia' => __DIR__ . '/inc/class.templator.media.php', 'pagerTemplator' => __DIR__ . '/inc/admin.pager.templator.php', ]); diff --git a/advanced.php b/advanced.php deleted file mode 100644 index a80c49c..0000000 --- a/advanced.php +++ /dev/null @@ -1,71 +0,0 @@ -meta->getMetadata(['meta_type' => 'template']); -$tags = dcCore::app()->meta->computeMetaStats($tags); -$tags->sort('meta_id_lower', 'asc'); - -$last_letter = null; -$cols = ['','']; -$col = 0; - -while ($tags->fetch()) { - $letter = mb_strtoupper(mb_substr($tags->meta_id, 0, 1)); - - if ($last_letter != $letter) { - if ($tags->index() >= round($tags->count() / 2)) { - $col = 1; - } - $cols[$col] .= '' . $letter . ''; - } - - $img = '%1$s'; - if (array_key_exists($tags->meta_id, dcCore::app()->templator->tpl)) { - $img_status = sprintf($img, __('available template'), 'check-on.png'); - } else { - $img_status = sprintf($img, __('missing template'), 'check-off.png'); - } - - $cols[$col] .= '' . - '' . $tags->meta_id . ' ' . $img_status . '' . - '' . $tags->count . ' ' . - (($tags->count == 1) ? __('entry') : __('entries')) . '' . - ''; - - $last_letter = $letter; -} - -$table = '
%s
'; - -echo -'' . __('Templator') . '' . -dcPage::cssLoad(dcPage::getPF('tags/style.css')) . -'' . -dcPage::breadcrumb([ - html::escapeHTML(dcCore::app()->blog->name) => '', - __('Additional templates') => '', -]) . -dcPage::notices() . -'

' . __('New template') . '

'; - -if ($cols[0]) { - echo '
'; - printf($table, $cols[0]); - if ($cols[1]) { - printf($table, $cols[1]); - } - echo '
'; -} else { - echo '

' . __('No specific templates on this blog.') . '

'; -} - -dcPage::helpBlock('templator'); - -echo ''; \ No newline at end of file diff --git a/edit.php b/edit.php deleted file mode 100644 index 6a984f4..0000000 --- a/edit.php +++ /dev/null @@ -1,81 +0,0 @@ -templator->getSourceContent($name); - $name = $file['f']; - } - - if (preg_match('/^category-(.+).html$/', $name, $cat_id)) { - $category = dcCore::app()->blog->getCategory($cat_id[1]); - $full_name = ''; - $cat_parents = dcCore::app()->blog->getCategoryParents($cat_id[1]); - while ($cat_parents->fetch()) { - $full_name = $cat_parents->cat_title . ' › '; - }; - $full_name = $full_name . dcCore::app()->blog->getCategory($cat_id)->cat_title; - $name .= ' (' . $full_name . $category->cat_title . ')'; - } - } catch (Exception $e) { - $file = $file_default; - - throw $e; - } - # Write file - if (!empty($_POST['write'])) { - $file['c'] = $_POST['file_content']; - dcCore::app()->templator->writeTpl($file['f'], $file['c']); - } -} catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); -} -?> - - - <?php echo __('Templator'); ?> - - - - - - -' . html::escapeHTML(dcCore::app()->blog->name) . ' › ' . __('Supplementary templates') . '' . __('Edit the template') . ''; - -if (($file['c'] !== null)) { - echo - '
' . - '
' . - '
' . __('File editor') . '' . - '

' . sprintf(__('Editing file %s'), '' . $name) . '

' . - '

' . form::textarea('file_content', 72, 30, html::escapeHTML($file['c']), 'maximal', '', !$file['w']) . '

'; - - if ($file['w']) { - echo - '

' . - dcCore::app()->formNonce() . - form::hidden(['file_id'], html::escapeHTML($file['f'])) . - '

'; - } else { - echo '

' . __('This file is not writable. Please check your files permissions.') . '

'; - } - - echo - '
'; -} - -?> - - \ No newline at end of file diff --git a/inc/admin.pager.templator.php b/inc/admin.pager.templator.php index 3be0836..8441c15 100644 --- a/inc/admin.pager.templator.php +++ b/inc/admin.pager.templator.php @@ -23,12 +23,12 @@ class pagerTemplator $count = ''; $params = []; $link = 'media_item.php?id=' . $f->media_id; - $link_edit = $p_url . '&edit=' . $fname; + $link_edit = dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'edit', 'file' => $f->basename]); $icon = dcPage::getPF('templator/img/template.png'); $class = 'media-item media-col-' . ($i % 2); $details = $special = ''; $widget_icon = ''; - $copy_url = '&copy='; + $part = 'copy'; if (preg_match('/^category-(.+)$/', $f->basename)) { // That is ugly. @@ -43,7 +43,7 @@ class pagerTemplator $params['cat_id'] = $cat_id; $params['post_type'] = ''; $icon = dcPage::getPF('templator/img/template-alt.png'); - $copy_url = '&copycat='; + $part = 'copycat';; try { $counter = dcCore::app()->blog->getPosts($params, true); @@ -72,12 +72,17 @@ class pagerTemplator } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } + $url = dcCore::app()->adminurl->get('admin.plugin.templator', [ + 'part' => 'posts', + 'file' => $fname, + 'redir' => dcCore::app()->adminurl->get('admin.plugin.templator', ['part' => 'files']), + ]); if ($counter->f(0) == 0) { - $count = ' '; + $count = __('No entry'); } elseif ($counter->f(0) == 1) { - $count = '' . $counter->f(0) . ' ' . __('entry') . ''; + $count = '' . $counter->f(0) . ' ' . __('entry') . ''; } else { - $count = '' . $counter->f(0) . ' ' . __('entries') . ''; + $count = '' . $counter->f(0) . ' ' . __('entries') . ''; } } @@ -85,14 +90,14 @@ class pagerTemplator '' . '