group admin behaviors in one class
parent
1d91b68081
commit
ad51816d7d
39
_admin.php
39
_admin.php
|
@ -27,31 +27,32 @@ if ($core->blog->settings->postwidgettext->postwidgettext_active) {
|
|||
$core->auth->check('contentadmin', $core->blog->id)
|
||||
);
|
||||
|
||||
$core->addBehavior('adminDashboardFavorites', ['postWidgetTextDashboard', 'favorites']);
|
||||
$core->addBehavior('adminBlogPreferencesForm', ['postWidgetTextAdmin', 'adminBlogPreferencesForm']);
|
||||
$core->addBehavior('adminBeforeBlogSettingsUpdate', ['postWidgetTextAdmin', 'adminBeforeBlogSettingsUpdate']);
|
||||
$core->addBehavior('adminDashboardFavorites', ['adminPostWidgetText', 'adminDashboardFavorites']);
|
||||
}
|
||||
# Pref
|
||||
$core->addBehavior('adminFiltersLists', ['postWidgetTextAdmin', 'adminFiltersLists']);
|
||||
$core->addBehavior('adminFiltersLists', ['adminPostWidgetText', 'adminFiltersLists']);
|
||||
$core->addBehavior('adminBlogPreferencesForm', ['adminPostWidgetText', 'adminBlogPreferencesForm']);
|
||||
$core->addBehavior('adminBeforeBlogSettingsUpdate', ['adminPostWidgetText', 'adminBeforeBlogSettingsUpdate']);
|
||||
|
||||
# Post
|
||||
$core->addBehavior('adminPostHeaders', ['postWidgetTextAdmin', 'headers']);
|
||||
$core->addBehavior('adminPostFormItems', ['postWidgetTextAdmin', 'form']);
|
||||
$core->addBehavior('adminAfterPostUpdate', ['postWidgetTextAdmin', 'save']);
|
||||
$core->addBehavior('adminAfterPostCreate', ['postWidgetTextAdmin', 'save']);
|
||||
$core->addBehavior('adminBeforePostDelete', ['postWidgetTextAdmin', 'delete']);
|
||||
$core->addBehavior('adminPostHeaders', ['adminPostWidgetText', 'adminPostHeaders']);
|
||||
$core->addBehavior('adminPostFormItems', ['adminPostWidgetText', 'adminPostFormItems']);
|
||||
$core->addBehavior('adminAfterPostUpdate', ['adminPostWidgetText', 'adminAfterPostSave']);
|
||||
$core->addBehavior('adminAfterPostCreate', ['adminPostWidgetText', 'adminAfterPostSave']);
|
||||
$core->addBehavior('adminBeforePostDelete', ['adminPostWidgetText', 'adminBeforePostDelete']);
|
||||
|
||||
# Plugin "pages"
|
||||
$core->addBehavior('adminPageHeaders', ['postWidgetTextAdmin', 'headers']);
|
||||
$core->addBehavior('adminPageFormItems', ['postWidgetTextAdmin', 'form']);
|
||||
$core->addBehavior('adminAfterPageUpdate', ['postWidgetTextAdmin', 'save']);
|
||||
$core->addBehavior('adminAfterPageCreate', ['postWidgetTextAdmin', 'save']);
|
||||
$core->addBehavior('adminBeforePageDelete', ['postWidgetTextAdmin', 'delete']);
|
||||
$core->addBehavior('adminPageHeaders', ['adminPostWidgetText', 'adminPostHeaders']);
|
||||
$core->addBehavior('adminPageFormItems', ['adminPostWidgetText', 'adminPostFormItems']);
|
||||
$core->addBehavior('adminAfterPageUpdate', ['adminPostWidgetText', 'adminAfterPostSave']);
|
||||
$core->addBehavior('adminAfterPageCreate', ['adminPostWidgetText', 'adminAfterPostSave']);
|
||||
$core->addBehavior('adminBeforePageDelete', ['adminPostWidgetText', 'adminBeforePostDelete']);
|
||||
|
||||
# Plugin "importExport"
|
||||
if ($core->blog->settings->postwidgettext->postwidgettext_importexport_active) {
|
||||
$core->addBehavior('exportFull', ['postWidgetTextBackup', 'exportFull']);
|
||||
$core->addBehavior('exportSingle', ['postWidgetTextBackup', 'exportSingle']);
|
||||
$core->addBehavior('importInit', ['postWidgetTextBackup', 'importInit']);
|
||||
$core->addBehavior('importSingle', ['postWidgetTextBackup', 'importSingle']);
|
||||
$core->addBehavior('importFull', ['postWidgetTextBackup', 'importFull']);
|
||||
$core->addBehavior('exportFull', ['adminPostWidgetText', 'exportFull']);
|
||||
$core->addBehavior('exportSingle', ['adminPostWidgetText', 'exportSingle']);
|
||||
$core->addBehavior('importInit', ['adminPostWidgetText', 'importInit']);
|
||||
$core->addBehavior('importSingle', ['adminPostWidgetText', 'importSingle']);
|
||||
$core->addBehavior('importFull', ['adminPostWidgetText', 'importFull']);
|
||||
}
|
|
@ -17,8 +17,6 @@ if (!defined('DC_RC_PATH')) {
|
|||
|
||||
$d = dirname(__FILE__) . '/inc/';
|
||||
|
||||
$__autoload['postWidgetText'] = $d . 'class.postwidgettext.php';
|
||||
$__autoload['postWidgetTextDashboard'] = $d . 'lib.pwt.dashboard.php';
|
||||
$__autoload['postWidgetTextAdmin'] = $d . 'lib.pwt.admin.php';
|
||||
$__autoload['postWidgetTextBackup'] = $d . 'lib.pwt.backup.php';
|
||||
$__autoload['postWidgetTextList'] = $d . 'lib.pwt.list.php';
|
||||
$__autoload['postWidgetText'] = $d . 'class.postwidgettext.php';
|
||||
$__autoload['adminPostWidgetText'] = $d . 'lib.pwt.admin.php';
|
||||
$__autoload['listPostWidgetText'] = $d . 'lib.pwt.list.php';
|
|
@ -11,16 +11,12 @@
|
|||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
|
||||
* @brief postWidgetText - admin post methods.
|
||||
* @since 2.6
|
||||
* @since 2.20
|
||||
*/
|
||||
class postWidgetTextAdmin
|
||||
class adminPostWidgetText
|
||||
{
|
||||
public static function sortbyCombo()
|
||||
{
|
||||
|
@ -68,15 +64,39 @@ class postWidgetTextAdmin
|
|||
{
|
||||
$blog_settings->postwidgettext->put('postwidgettext_active', !empty($_POST['active']));
|
||||
$blog_settings->postwidgettext->put('postwidgettext_importexport_active', !empty($_POST['importexport_active']));
|
||||
|
||||
}
|
||||
|
||||
public static function headers()
|
||||
public static function adminDashboardFavorites(dcCore $core, $favs)
|
||||
{
|
||||
$favs->register('postWidgetText', [
|
||||
'title' => __('Post widget text'),
|
||||
'url' => $core->adminurl->get('admin.plugin.postWidgetText'),
|
||||
'small-icon' => dcPage::getPF('postWidgetText/icon.png'),
|
||||
'large-icon' => dcPage::getPF('postWidgetText/icon-big.png'),
|
||||
'permissions' => $core->auth->check('usage,contentadmin', $core->blog->id),
|
||||
'active_cb' => ['adminPostWidgetText', 'adminDashboardFavoritesActive']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Favorites selection.
|
||||
*
|
||||
* @param string $request Requested page
|
||||
* @param array $params Requested parameters
|
||||
*/
|
||||
public static function adminDashboardFavoritesActive($request, $params)
|
||||
{
|
||||
return $request == 'plugin.php'
|
||||
&& isset($params['p'])
|
||||
&& $params['p'] == 'postWidgetText';
|
||||
}
|
||||
|
||||
public static function adminPostHeaders()
|
||||
{
|
||||
return dcPage::jsLoad(dcPage::getPF('postWidgetText/js/post.js'));
|
||||
}
|
||||
|
||||
public static function form($main, $sidebar, $post)
|
||||
public static function adminPostFormItems($main, $sidebar, $post)
|
||||
{
|
||||
# _POST fields
|
||||
$title = $_POST['post_wtitle'] ?? '';
|
||||
|
@ -113,7 +133,7 @@ class postWidgetTextAdmin
|
|||
'</div>';
|
||||
}
|
||||
|
||||
public static function save($cur, $post_id)
|
||||
public static function adminAfterPostSave($cur, $post_id)
|
||||
{
|
||||
$post_id = (integer) $post_id;
|
||||
|
||||
|
@ -153,7 +173,7 @@ class postWidgetTextAdmin
|
|||
}
|
||||
}
|
||||
|
||||
public static function delete($post_id)
|
||||
public static function adminBeforePostDelete($post_id)
|
||||
{
|
||||
$post_id = (integer) $post_id;
|
||||
|
||||
|
@ -168,4 +188,101 @@ class postWidgetTextAdmin
|
|||
$pwt->delWidget($w->option_id);
|
||||
}
|
||||
}
|
||||
|
||||
public static function exportSingle(dcCore $core, $exp, $blog_id)
|
||||
{
|
||||
$exp->export('postwidgettext',
|
||||
'SELECT option_type, option_content, ' .
|
||||
'option_content_xhtml, W.post_id ' .
|
||||
'FROM ' . $core->prefix . 'post_option W ' .
|
||||
'LEFT JOIN ' . $core->prefix . 'post P ' .
|
||||
'ON P.post_id = W.post_id ' .
|
||||
"WHERE P.blog_id = '" . $blog_id . "' " .
|
||||
"AND W.option_type = 'postwidgettext' "
|
||||
);
|
||||
}
|
||||
|
||||
public static function exportFull(dcCore $core, $exp)
|
||||
{
|
||||
$exp->export('postwidgettext',
|
||||
'SELECT option_type, option_content, ' .
|
||||
'option_content_xhtml, W.post_id '.
|
||||
'FROM ' . $core->prefix . 'post_option W ' .
|
||||
'LEFT JOIN ' . $core->prefix . 'post P ' .
|
||||
'ON P.post_id = W.post_id ' .
|
||||
"WHERE W.option_type = 'postwidgettext' "
|
||||
);
|
||||
}
|
||||
|
||||
public static function importInit($bk, dcCore $core)
|
||||
{
|
||||
$bk->cur_postwidgettext = $core->con->openCursor(
|
||||
$core->prefix . 'post_option'
|
||||
);
|
||||
$bk->postwidgettext = new postWidgetText($core);
|
||||
}
|
||||
|
||||
public static function importSingle($line, $bk, dcCore $core)
|
||||
{
|
||||
if ($line->__name == 'postwidgettext'
|
||||
&& isset($bk->old_ids['post'][(integer) $line->post_id])
|
||||
) {
|
||||
$line->post_id = $bk->old_ids['post'][(integer) $line->post_id];
|
||||
|
||||
$exists = $bk->postwidgettext->getWidgets([
|
||||
'post_id' => $line->post_id
|
||||
]);
|
||||
|
||||
if ($exists->isEmpty()) {
|
||||
$bk->cur_postwidgettext->clean();
|
||||
|
||||
$bk->cur_postwidgettext->post_id =
|
||||
(integer) $line->post_id;
|
||||
$bk->cur_postwidgettext->option_type =
|
||||
(string) $line->option_type;
|
||||
$bk->cur_postwidgettext->option_lang =
|
||||
(string) $line->option_lang;
|
||||
$bk->cur_postwidgettext->option_format =
|
||||
(string) $line->option_format;
|
||||
$bk->cur_postwidgettext->option_content =
|
||||
(string) $line->option_content;
|
||||
$bk->cur_postwidgettext->option_content_xhtml =
|
||||
(string) $line->option_content_xhtml;
|
||||
|
||||
$bk->postwidgettext->addWidget(
|
||||
$bk->cur_postwidgettext
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function importFull($line, $bk, dcCore $core)
|
||||
{
|
||||
if ($line->__name == 'postwidgettext') {
|
||||
$exists = $bk->postwidgettext->getWidgets([
|
||||
'post_id' => $line->post_id
|
||||
]);
|
||||
|
||||
if ($exists->isEmpty()) {
|
||||
$bk->cur_postwidgettext->clean();
|
||||
|
||||
$bk->cur_postwidgettext->post_id =
|
||||
(integer) $line->post_id;
|
||||
$bk->cur_postwidgettext->option_type =
|
||||
(string) $line->option_type;
|
||||
$bk->cur_postwidgettext->option_format =
|
||||
(string) $line->option_format;
|
||||
$bk->cur_postwidgettext->option_content =
|
||||
(string) $line->option_content;
|
||||
$bk->cur_postwidgettext->option_content =
|
||||
(string) $line->option_content;
|
||||
$bk->cur_postwidgettext->option_content_xhtml =
|
||||
(string) $line->option_content_xhtml;
|
||||
|
||||
$bk->postwidgettext->addWidget(
|
||||
$bk->cur_postwidgettext
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @brief postWidgetText, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
|
||||
* @brief postWidgetText - backup methods.
|
||||
* @since 2.6
|
||||
*/
|
||||
class postWidgetTextBackup
|
||||
{
|
||||
public static function exportSingle(dcCore $core, $exp, $blog_id)
|
||||
{
|
||||
$exp->export('postwidgettext',
|
||||
'SELECT option_type, option_content, ' .
|
||||
'option_content_xhtml, W.post_id ' .
|
||||
'FROM ' . $core->prefix . 'post_option W ' .
|
||||
'LEFT JOIN ' . $core->prefix . 'post P ' .
|
||||
'ON P.post_id = W.post_id ' .
|
||||
"WHERE P.blog_id = '" . $blog_id . "' " .
|
||||
"AND W.option_type = 'postwidgettext' "
|
||||
);
|
||||
}
|
||||
|
||||
public static function exportFull(dcCore $core, $exp)
|
||||
{
|
||||
$exp->export('postwidgettext',
|
||||
'SELECT option_type, option_content, ' .
|
||||
'option_content_xhtml, W.post_id '.
|
||||
'FROM ' . $core->prefix . 'post_option W ' .
|
||||
'LEFT JOIN ' . $core->prefix . 'post P ' .
|
||||
'ON P.post_id = W.post_id ' .
|
||||
"WHERE W.option_type = 'postwidgettext' "
|
||||
);
|
||||
}
|
||||
|
||||
public static function importInit($bk, dcCore $core)
|
||||
{
|
||||
$bk->cur_postwidgettext = $core->con->openCursor(
|
||||
$core->prefix . 'post_option'
|
||||
);
|
||||
$bk->postwidgettext = new postWidgetText($core);
|
||||
}
|
||||
|
||||
public static function importSingle($line, $bk, dcCore $core)
|
||||
{
|
||||
if ($line->__name == 'postwidgettext'
|
||||
&& isset($bk->old_ids['post'][(integer) $line->post_id])
|
||||
) {
|
||||
$line->post_id = $bk->old_ids['post'][(integer) $line->post_id];
|
||||
|
||||
$exists = $bk->postwidgettext->getWidgets([
|
||||
'post_id' => $line->post_id
|
||||
]);
|
||||
|
||||
if ($exists->isEmpty()) {
|
||||
$bk->cur_postwidgettext->clean();
|
||||
|
||||
$bk->cur_postwidgettext->post_id =
|
||||
(integer) $line->post_id;
|
||||
$bk->cur_postwidgettext->option_type =
|
||||
(string) $line->option_type;
|
||||
$bk->cur_postwidgettext->option_lang =
|
||||
(string) $line->option_lang;
|
||||
$bk->cur_postwidgettext->option_format =
|
||||
(string) $line->option_format;
|
||||
$bk->cur_postwidgettext->option_content =
|
||||
(string) $line->option_content;
|
||||
$bk->cur_postwidgettext->option_content_xhtml =
|
||||
(string) $line->option_content_xhtml;
|
||||
|
||||
$bk->postwidgettext->addWidget(
|
||||
$bk->cur_postwidgettext
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function importFull($line, $bk, dcCore $core)
|
||||
{
|
||||
if ($line->__name == 'postwidgettext') {
|
||||
$exists = $bk->postwidgettext->getWidgets([
|
||||
'post_id' => $line->post_id
|
||||
]);
|
||||
|
||||
if ($exists->isEmpty()) {
|
||||
$bk->cur_postwidgettext->clean();
|
||||
|
||||
$bk->cur_postwidgettext->post_id =
|
||||
(integer) $line->post_id;
|
||||
$bk->cur_postwidgettext->option_type =
|
||||
(string) $line->option_type;
|
||||
$bk->cur_postwidgettext->option_format =
|
||||
(string) $line->option_format;
|
||||
$bk->cur_postwidgettext->option_content =
|
||||
(string) $line->option_content;
|
||||
$bk->cur_postwidgettext->option_content =
|
||||
(string) $line->option_content;
|
||||
$bk->cur_postwidgettext->option_content_xhtml =
|
||||
(string) $line->option_content_xhtml;
|
||||
|
||||
$bk->postwidgettext->addWidget(
|
||||
$bk->cur_postwidgettext
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @brief postWidgetText, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis and Contributors
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ingroup DC_PLUGIN_POSTWIDGETTEXT
|
||||
* @brief postWidgetText - admin dashboard methods.
|
||||
* @since 2.6
|
||||
*/
|
||||
class postWidgetTextDashboard
|
||||
{
|
||||
/**
|
||||
* Favorites.
|
||||
*
|
||||
* @param dcCore $core dcCore instance
|
||||
* @param arrayObject $favs Array of favorites
|
||||
*/
|
||||
public static function favorites(dcCore $core, $favs)
|
||||
{
|
||||
$favs->register('postWidgetText', [
|
||||
'title' => __('Post widget text'),
|
||||
'url' => $core->adminurl->get('admin.plugin.postWidgetText'),
|
||||
'small-icon' => dcPage::getPF('postWidgetText/icon.png'),
|
||||
'large-icon' => dcPage::getPF('postWidgetText/icon-big.png'),
|
||||
'permissions' => $core->auth->check('usage,contentadmin', $core->blog->id),
|
||||
'active_cb' => ['postWidgetTextDashboard', 'active']
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Favorites selection.
|
||||
*
|
||||
* @param string $request Requested page
|
||||
* @param array $params Requested parameters
|
||||
*/
|
||||
public static function active($request, $params)
|
||||
{
|
||||
return $request == 'plugin.php'
|
||||
&& isset($params['p'])
|
||||
&& $params['p'] == 'postWidgetText';
|
||||
}
|
||||
}
|
|
@ -50,7 +50,7 @@ $params = $filter->params();
|
|||
try {
|
||||
$posts = $pwt->getWidgets($params);
|
||||
$counter = $pwt->getWidgets($params, true);
|
||||
$posts_list = new postWidgetTextList($core, $posts, $counter->f(0));
|
||||
$posts_list = new listPostWidgetText($core, $posts, $counter->f(0));
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
|
|
Loading…
Reference in New Issue