diff --git a/_admin.php b/_admin.php index b1a6773..124816c 100644 --- a/_admin.php +++ b/_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']); } \ No newline at end of file diff --git a/_prepend.php b/_prepend.php index 169e4c9..e4d8572 100644 --- a/_prepend.php +++ b/_prepend.php @@ -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'; \ No newline at end of file +$__autoload['postWidgetText'] = $d . 'class.postwidgettext.php'; +$__autoload['adminPostWidgetText'] = $d . 'lib.pwt.admin.php'; +$__autoload['listPostWidgetText'] = $d . 'lib.pwt.list.php'; \ No newline at end of file diff --git a/inc/lib.pwt.admin.php b/inc/lib.pwt.admin.php index eadfdd6..eef6acd 100644 --- a/inc/lib.pwt.admin.php +++ b/inc/lib.pwt.admin.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 ''; } - 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 + ); + } + } + } } \ No newline at end of file diff --git a/inc/lib.pwt.backup.php b/inc/lib.pwt.backup.php deleted file mode 100644 index c46e2da..0000000 --- a/inc/lib.pwt.backup.php +++ /dev/null @@ -1,121 +0,0 @@ -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 - ); - } - } - } -} \ No newline at end of file diff --git a/inc/lib.pwt.dashboard.php b/inc/lib.pwt.dashboard.php deleted file mode 100644 index 4a7aa3f..0000000 --- a/inc/lib.pwt.dashboard.php +++ /dev/null @@ -1,56 +0,0 @@ -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'; - } -} \ No newline at end of file diff --git a/index.php b/index.php index 53a3b41..dd8be85 100644 --- a/index.php +++ b/index.php @@ -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());