auth->setPermissionType(initTemplator::PERMISSION_TEMPLATOR, __('manage templates')); dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem( __('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']), dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ dcAuth::PERMISSION_CONTENT_ADMIN, initTemplator::PERMISSION_TEMPLATOR, ]), dcCore::app()->blog->id) ); if (dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ dcAuth::PERMISSION_CONTENT_ADMIN, initTemplator::PERMISSION_TEMPLATOR, ]), dcCore::app()->blog->id)) { dcCore::app()->addBehavior('adminPostHeaders', ['templatorBehaviors','adminPostHeaders']); dcCore::app()->addBehavior('adminPostFormItems', ['templatorBehaviors','adminPostFormItems']); dcCore::app()->addBehavior('adminPageHeaders', ['templatorBehaviors','adminPostHeaders']); dcCore::app()->addBehavior('adminPageFormItems', ['templatorBehaviors','adminPostFormItems']); dcCore::app()->addBehavior('adminAfterPostCreate', ['templatorBehaviors','adminBeforePostUpdate']); dcCore::app()->addBehavior('adminBeforePostUpdate', ['templatorBehaviors','adminBeforePostUpdate']); dcCore::app()->addBehavior('adminAfterPageCreate', ['templatorBehaviors','adminBeforePostUpdate']); dcCore::app()->addBehavior('adminBeforePageUpdate', ['templatorBehaviors','adminBeforePostUpdate']); 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', ], 'post_upddt', 'desc', [__('Entries per page'), 30], ]; }); } class templatorBehaviors { public static function adminPostHeaders() { return dcPage::jsLoad(dcPage::getPF('templator/js/admin.js')); } public static function adminPostFormItems(ArrayObject $main_items, ArrayObject $sidebar_items, $post) { $selected = ''; if ($post) { $post_meta = dcCore::app()->meta->getMetadata(['meta_type' => 'template', 'post_id' => $post->post_id]); $selected = $post_meta->isEmpty() ? '' : $post_meta->meta_id; } $sidebar_items['options-box']['items']['templator'] = '
' . form::combo('post_tpl', self::getTemplateCombo(), $selected) . '
' . '