diff --git a/_admin.php b/_admin.php index 10e8ede..16af95b 100644 --- a/_admin.php +++ b/_admin.php @@ -1,5 +1,15 @@ auth->check(dcCore::app()->auth->makePermissions([ dcCore::app()->addBehavior('adminAfterPageCreate', ['templatorBehaviors','adminBeforePostUpdate']); dcCore::app()->addBehavior('adminBeforePageUpdate', ['templatorBehaviors','adminBeforePostUpdate']); - dcCore::app()->addBehavior('adminPostsActions', ['templatorBehaviors','adminPostsActions']); - dcCore::app()->addBehavior('adminPagesActions', ['templatorBehaviors','adminPostsActions']); + dcCore::app()->addBehavior('adminPostsActionsV2', ['templatorBehaviors','adminPostsActionsV2']); + dcCore::app()->addBehavior('adminPagesActionsV2', ['templatorBehaviors','adminPostsActionsV2']); dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts) { $sorts['templator'] = [ __('Templates engine'), [ - __('Date') => 'post_upddt', - __('Title') => 'post_title', - __('Category') => 'cat_id', + __('Date') => 'post_upddt', + __('Title') => 'post_title', + __('Category') => 'cat_id', ], 'post_upddt', 'desc', @@ -65,10 +75,9 @@ class templatorBehaviors $selected = $post_meta->isEmpty() ? '' : $post_meta->meta_id; } - $sidebar_items['options-box']['items']['templator'] = - '
' . + $sidebar_items['options-box']['items']['templator'] = '
' . '
' . __('Template') . '
' . - '

' . + '

' . form::combo('post_tpl', self::getTemplateCombo(), $selected) . '

' . '
'; } @@ -85,7 +94,7 @@ class templatorBehaviors } } - public static function adminPostsActions(dcPostsActions $pa) + public static function adminPostsActionsV2(dcPostsActions $pa) { $pa->addAction( [ @@ -114,8 +123,8 @@ class templatorBehaviors } } - dcAdminNotices::addSuccessNotice(__('Entries template updated.')); - $pa->redirect(true); + dcAdminNotices::addSuccessNotice(__('Entries template updated.')); + $pa->redirect(true); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } @@ -125,7 +134,7 @@ class templatorBehaviors dcPage::breadcrumb([ html::escapeHTML(dcCore::app()->blog->name) => '', $pa->getCallerTitle() => $pa->getRedirection(true), - __('Entry template') => '', + __('Entry template') => '', ]) ); diff --git a/_define.php b/_define.php index 60d1f7c..a6ad75c 100644 --- a/_define.php +++ b/_define.php @@ -1,11 +1,21 @@ registerModule( - 'Templator', + 'Templates engine', 'Create and select more templates for your posts', 'Osku and contributors', '1.4-dev', diff --git a/_init.php b/_init.php index 2e55c21..ad94697 100644 --- a/_init.php +++ b/_init.php @@ -1,5 +1,15 @@ ♦'; - $part = 'copy'; + $part = 'copy'; - if (preg_match('/^category-(.+)$/', $f->basename)) { - // That is ugly. - $cat_id = str_replace('category-', '', $f->basename); - $cat_id = str_replace('.html', '', $cat_id); - $cat_parents = dcCore::app()->blog->getCategoryParents($cat_id); + if (preg_match('/^category-(.+).html$/', $f->basename, $cat_id)) { + $cat_id = (int) $cat_id[1]; + $category = dcCore::app()->blog->getCategory($cat_id); $full_name = ''; + $cat_parents = dcCore::app()->blog->getCategoryParents($cat_id); while ($cat_parents->fetch()) { $full_name = $cat_parents->cat_title . ' › '; }; @@ -43,21 +42,20 @@ class templatorPager $params['cat_id'] = $cat_id; $params['post_type'] = ''; $icon = dcPage::getPF('templator/img/template-alt.png'); - $part = 'copycat';; + $part = 'copycat'; try { $counter = dcCore::app()->blog->getPosts($params, true); + if ($counter->f(0) == 0) { + $count = __('No entry'); + } elseif ($counter->f(0) == 1) { + $count = '' . $counter->f(0) . ' ' . __('entry') . ''; + } else { + $count = '' . $counter->f(0) . ' ' . __('entries') . ''; + } } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); } - - if ($counter->f(0) == 0) { - $count = __('No entry'); - } elseif ($counter->f(0) == 1) { - $count = '' . $counter->f(0) . ' ' . __('entry') . ''; - } else { - $count = '' . $counter->f(0) . ' ' . __('entries') . ''; - } } elseif (preg_match('/^widget-(.+)$/', $f->basename)) { $count = ' '; $icon = dcPage::getPF('templator/img/template-widget.png'); @@ -69,35 +67,35 @@ class templatorPager try { $counter = dcCore::app()->meta->getPostsByMeta($params, true); + $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 = __('No entry'); + } elseif ($counter->f(0) == 1) { + $count = '' . $counter->f(0) . ' ' . __('entry') . ''; + } else { + $count = '' . $counter->f(0) . ' ' . __('entries') . ''; + } } 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 = __('No entry'); - } elseif ($counter->f(0) == 1) { - $count = '' . $counter->f(0) . ' ' . __('entry') . ''; - } else { - $count = '' . $counter->f(0) . ' ' . __('entries') . ''; - } } $res = '
' . '' . '