use anonymous functions
This commit is contained in:
parent
862a4bff7c
commit
c0868e6532
1 changed files with 66 additions and 105 deletions
81
_admin.php
81
_admin.php
|
@ -21,68 +21,25 @@ require __DIR__ . '/_widgets.php';
|
||||||
# Admin menu
|
# Admin menu
|
||||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||||
__('Enhance post content'),
|
__('Enhance post content'),
|
||||||
'plugin.php?p=enhancePostContent',
|
dcCore::app()->adminurl->get('admin.plugin.enhancePostContent'),
|
||||||
urldecode(dcPage::getPF('enhancePostContent/icon.svg')),
|
urldecode(dcPage::getPF('enhancePostContent/icon.svg')),
|
||||||
preg_match(
|
preg_match('/' . preg_quote(dcCore::app()->adminurl->get('admin.plugin.enhancePostContent')) . '(&.*)?$/', $_SERVER['REQUEST_URI']),
|
||||||
'/plugin.php\?p=enhancePostContent(&.*)?$/',
|
|
||||||
$_SERVER['REQUEST_URI']
|
|
||||||
),
|
|
||||||
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
|
dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id)
|
||||||
);
|
);
|
||||||
|
|
||||||
dcCore::app()->addBehavior(
|
# Dashboard favorites
|
||||||
'adminDashboardFavoritesV2',
|
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs) {
|
||||||
['epcAdminBehaviors', 'adminDashboardFavorites']
|
|
||||||
);
|
|
||||||
dcCore::app()->addBehavior(
|
|
||||||
'adminBlogPreferencesFormV2',
|
|
||||||
['epcAdminBehaviors', 'adminBlogPreferencesForm']
|
|
||||||
);
|
|
||||||
dcCore::app()->addBehavior(
|
|
||||||
'adminBeforeBlogSettingsUpdate',
|
|
||||||
['epcAdminBehaviors', 'adminBeforeBlogSettingsUpdate']
|
|
||||||
);
|
|
||||||
dcCore::app()->addBehavior(
|
|
||||||
'adminFiltersListsV2',
|
|
||||||
['epcAdminBehaviors', 'adminFiltersLists']
|
|
||||||
);
|
|
||||||
|
|
||||||
class epcAdminBehaviors
|
|
||||||
{
|
|
||||||
public static function adminDashboardFavorites(dcFavorites $favs)
|
|
||||||
{
|
|
||||||
$favs->register('enhancePostContent', [
|
$favs->register('enhancePostContent', [
|
||||||
'title' => __('Enhance post content'),
|
'title' => __('Enhance post content'),
|
||||||
'url' => 'plugin.php?p=enhancePostContent',
|
'url' => dcCore::app()->adminurl->get('admin.plugin.enhancePostContent'),
|
||||||
'small-icon' => urldecode(dcPage::getPF('enhancePostContent/icon.svg')),
|
'small-icon' => urldecode(dcPage::getPF('enhancePostContent/icon.svg')),
|
||||||
'large-icon' => urldecode(dcPage::getPF('enhancePostContent/icon.svg')),
|
'large-icon' => urldecode(dcPage::getPF('enhancePostContent/icon.svg')),
|
||||||
'permissions' => dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id),
|
'permissions' => dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id),
|
||||||
'active_cb' => [
|
|
||||||
'epcAdminBehaviors',
|
|
||||||
'adminDashboardFavoritesActive',
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
});
|
||||||
|
|
||||||
public static function adminDashboardFavoritesActive($request, $params)
|
# Preference form
|
||||||
{
|
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings) {
|
||||||
return $request == 'plugin.php'
|
|
||||||
&& isset($params['p'])
|
|
||||||
&& $params['p'] == 'enhancePostContent';
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function sortbyCombo()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
__('Date') => 'epc_upddt',
|
|
||||||
__('Key') => 'epc_key',
|
|
||||||
__('Value') => 'epc_value',
|
|
||||||
__('ID') => 'epc_id',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function adminBlogPreferencesForm(dcSettings $blog_settings)
|
|
||||||
{
|
|
||||||
$active = (bool) $blog_settings->enhancePostContent->enhancePostContent_active;
|
$active = (bool) $blog_settings->enhancePostContent->enhancePostContent_active;
|
||||||
$allowedtplvalues = libEPC::blogAllowedTplValues();
|
$allowedtplvalues = libEPC::blogAllowedTplValues();
|
||||||
$allowedpubpages = libEPC::blogAllowedPubPages();
|
$allowedpubpages = libEPC::blogAllowedPubPages();
|
||||||
|
@ -113,10 +70,10 @@ class epcAdminBehaviors
|
||||||
'</div>' .
|
'</div>' .
|
||||||
'<br class="clear" />' .
|
'<br class="clear" />' .
|
||||||
'</div>';
|
'</div>';
|
||||||
}
|
});
|
||||||
|
|
||||||
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
|
# Save preference
|
||||||
{
|
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $blog_settings) {
|
||||||
$active = !empty($_POST['epc_active']);
|
$active = !empty($_POST['epc_active']);
|
||||||
$allowedtplvalues = libEPC::explode($_POST['epc_allowedtplvalues']);
|
$allowedtplvalues = libEPC::explode($_POST['epc_allowedtplvalues']);
|
||||||
$allowedpubpages = libEPC::explode($_POST['epc_allowedpubpages']);
|
$allowedpubpages = libEPC::explode($_POST['epc_allowedpubpages']);
|
||||||
|
@ -124,16 +81,20 @@ class epcAdminBehaviors
|
||||||
$blog_settings->enhancePostContent->put('enhancePostContent_active', $active);
|
$blog_settings->enhancePostContent->put('enhancePostContent_active', $active);
|
||||||
$blog_settings->enhancePostContent->put('enhancePostContent_allowedtplvalues', serialize($allowedtplvalues));
|
$blog_settings->enhancePostContent->put('enhancePostContent_allowedtplvalues', serialize($allowedtplvalues));
|
||||||
$blog_settings->enhancePostContent->put('enhancePostContent_allowedpubpages', serialize($allowedpubpages));
|
$blog_settings->enhancePostContent->put('enhancePostContent_allowedpubpages', serialize($allowedpubpages));
|
||||||
}
|
});
|
||||||
|
|
||||||
public static function adminFiltersLists($sorts)
|
# List filter
|
||||||
{
|
dcCore::app()->addBehavior('adminFiltersListsV2', function (ArrayObject $sorts) {
|
||||||
$sorts['epc'] = [
|
$sorts['epc'] = [
|
||||||
__('Enhance post content'),
|
__('Enhance post content'),
|
||||||
self::sortbyCombo(),
|
[
|
||||||
|
__('Date') => 'epc_upddt',
|
||||||
|
__('Key') => 'epc_key',
|
||||||
|
__('Value') => 'epc_value',
|
||||||
|
__('ID') => 'epc_id',
|
||||||
|
],
|
||||||
'epc_upddt',
|
'epc_upddt',
|
||||||
'desc',
|
'desc',
|
||||||
[__('records per page'), 20],
|
[__('records per page'), 20],
|
||||||
];
|
];
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue