From c459a4674984b27bd7ca9c806a21f9bf0bf38e6d Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Fri, 23 Dec 2022 14:10:54 +0100 Subject: [PATCH] code review (phpstan, php-cs-fixer) --- _admin.php | 2 +- _install.php | 2 +- _widgets.php | 6 ++--- inc/class.postwidgettext.php | 6 ++--- inc/lib.pwt.admin.php | 47 +++++++++++++++++++----------------- inc/lib.pwt.list.php | 12 ++++----- index.php | 33 +++++++++++++------------ 7 files changed, 56 insertions(+), 52 deletions(-) diff --git a/_admin.php b/_admin.php index 08b3b81..93ac5ea 100644 --- a/_admin.php +++ b/_admin.php @@ -26,7 +26,7 @@ if (dcCore::app()->blog->settings->get(basename(__DIR__))->get('active')) { dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([dcAuth::PERMISSION_CONTENT_ADMIN]), dcCore::app()->blog->id) ); - dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminPostWidgetText', 'adminDashboardFavorites']); + dcCore::app()->addBehavior('adminDashboardFavoritesV2', ['adminPostWidgetText', 'adminDashboardFavoritesV2']); } # Pref dcCore::app()->addBehavior('adminFiltersListsV2', ['adminPostWidgetText', 'adminFiltersListsV2']); diff --git a/_install.php b/_install.php index 8a6e4da..fa9d36d 100644 --- a/_install.php +++ b/_install.php @@ -17,7 +17,7 @@ if (!defined('DC_CONTEXT_ADMIN')) { try { // check installed version if (!dcCore::app()->newVersion( - basename(__DIR__), + basename(__DIR__), dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') )) { return null; diff --git a/_widgets.php b/_widgets.php index 38bda88..3859122 100644 --- a/_widgets.php +++ b/_widgets.php @@ -59,7 +59,7 @@ class postWidgetTextWidget if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('active') || !dcCore::app()->ctx->exists('posts') - || !dcCore::app()->ctx->posts->post_id + || !dcCore::app()->ctx->__get('posts')->post_id ) { return null; } @@ -68,7 +68,7 @@ class postWidgetTextWidget $content = ''; $pwt = new postWidgetText(); - $rs = $pwt->getWidgets(['post_id' => dcCore::app()->ctx->posts->post_id]); + $rs = $pwt->getWidgets(['post_id' => dcCore::app()->ctx->__get('posts')->post_id]); if ($rs->isEmpty()) { return null; @@ -81,7 +81,7 @@ class postWidgetTextWidget $content = $rs->option_content_xhtml; } if ('' == $content && $w->excerpt) { - $content = dcCore::app()->ctx->posts->post_excerpt_xhtml; + $content = dcCore::app()->ctx->__get('posts')->post_excerpt_xhtml; } return $w->renderDiv( diff --git a/inc/class.postwidgettext.php b/inc/class.postwidgettext.php index 6e0f8d6..ff9b6d9 100644 --- a/inc/class.postwidgettext.php +++ b/inc/class.postwidgettext.php @@ -103,8 +103,6 @@ class postWidgetText } if ($cur->post_id == '') { throw new Exception('No such entry ID'); - - return null; } $this->lockTable(); @@ -179,8 +177,8 @@ class postWidgetText throw new Exception(__('You are not allowed to delete entries text widget')); } - $id = (int) $id; - $type = $type ?? basename(__DIR__); + $id = (int) $id; + $type ??= basename(__DIR__); if (empty($id)) { throw new Exception(__('No such ID')); diff --git a/inc/lib.pwt.admin.php b/inc/lib.pwt.admin.php index b541631..d284a69 100644 --- a/inc/lib.pwt.admin.php +++ b/inc/lib.pwt.admin.php @@ -17,6 +17,9 @@ */ class adminPostWidgetText { + private static $ie_cursor; + private static $ie_pwt; + private static function id() { return basename(dirname(__DIR__)); @@ -214,10 +217,10 @@ class adminPostWidgetText public static function importInitV2($bk) { - $bk->cur_postwidgettext = dcCore::app()->con->openCursor( + self::$ie_cursor = dcCore::app()->con->openCursor( dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME ); - $bk->{self::id()} = new postWidgetText(); + self::$ie_pwt = new postWidgetText(); } public static function importSingleV2($line, $bk) @@ -227,22 +230,22 @@ class adminPostWidgetText ) { $line->post_id = $bk->old_ids['post'][(int) $line->post_id]; - $exists = $bk->{self::id()}->getWidgets([ + $exists = self::$ie_pwt->getWidgets([ 'post_id' => $line->post_id, ]); if ($exists->isEmpty()) { - $bk->cur_postwidgettext->clean(); + self::$ie_cursor->clean(); - $bk->cur_postwidgettext->post_id = (int) $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; + self::$ie_cursor->post_id = (int) $line->post_id; + self::$ie_cursor->option_type = (string) $line->option_type; + self::$ie_cursor->option_lang = (string) $line->option_lang; + self::$ie_cursor->option_format = (string) $line->option_format; + self::$ie_cursor->option_content = (string) $line->option_content; + self::$ie_cursor->option_content_xhtml = (string) $line->option_content_xhtml; - $bk->{self::id()}->addWidget( - $bk->cur_postwidgettext + self::$ie_pwt->addWidget( + self::$ie_cursor ); } } @@ -251,22 +254,22 @@ class adminPostWidgetText public static function importFullV2($line, $bk) { if ($line->__name == self::id()) { - $exists = $bk->{self::id()}->getWidgets([ + $exists = self::$ie_pwt->getWidgets([ 'post_id' => $line->post_id, ]); if ($exists->isEmpty()) { - $bk->cur_postwidgettext->clean(); + self::$ie_cursor->clean(); - $bk->cur_postwidgettext->post_id = (int) $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; + self::$ie_cursor->post_id = (int) $line->post_id; + self::$ie_cursor->option_type = (string) $line->option_type; + self::$ie_cursor->option_format = (string) $line->option_format; + self::$ie_cursor->option_content = (string) $line->option_content; + self::$ie_cursor->option_content = (string) $line->option_content; + self::$ie_cursor->option_content_xhtml = (string) $line->option_content_xhtml; - $bk->{self::id()}->addWidget( - $bk->cur_postwidgettext + self::$ie_pwt->addWidget( + self::$ie_cursor ); } } diff --git a/inc/lib.pwt.list.php b/inc/lib.pwt.list.php index a4a2bc1..9f33a0b 100644 --- a/inc/lib.pwt.list.php +++ b/inc/lib.pwt.list.php @@ -47,13 +47,13 @@ class listPostWidgetText extends adminGenericList while ($this->rs->fetch()) { $w_title = html::escapeHTML($this->rs->option_title); if ($w_title == '') { - $w_title = '' . context::global_filter( + $w_title = '' . context::global_filters( $this->rs->option_content, - 1, - 1, - 80, - 0, - 0 + [ + 'encode_xml', + 'remove_html', + 'cut_string' => 80, + ] ) . ''; } diff --git a/index.php b/index.php index 7f1171e..78e72cb 100644 --- a/index.php +++ b/index.php @@ -54,6 +54,7 @@ try { $posts_list = new listPostWidgetText(dcCore::app(), $posts, $counter->f(0)); } catch (Exception $e) { dcCore::app()->error->add($e->getMessage()); + $posts_list = null; } # Display @@ -70,21 +71,23 @@ dcPage::breadcrumb([ ]) . dcPage::notices(); -$filter->display('admin.plugin.' . basename(__DIR__), form::hidden('p', basename(__DIR__))); +if ($posts_list) { + $filter->display('admin.plugin.' . basename(__DIR__), form::hidden('p', basename(__DIR__))); -$posts_list->display( - $filter->page, - $filter->nb, - '
' . - '%s' . - '
' . - '

' . - '

' . - '

' . - dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . basename(__DIR__), array_merge(['p' => basename(__DIR__)], $filter->values(true))) . - dcCore::app()->formNonce() . - '
' . - '
' -); + $posts_list->display( + $filter->page, + $filter->nb, + '
' . + '%s' . + '
' . + '

' . + '

' . + '

' . + dcCore::app()->adminurl->getHiddenFormFields('admin.plugin.' . basename(__DIR__), array_merge(['p' => basename(__DIR__)], $filter->values(true))) . + dcCore::app()->formNonce() . + '
' . + '
' + ); +} echo '';