From 8d520a3cd45b2d03829d788283f5bb0687d7db30 Mon Sep 17 00:00:00 2001 From: Tobias Krais Date: Sun, 21 May 2023 20:22:09 +0200 Subject: [PATCH] rexstan enhancements --- install.php | 6 +- lib/d2u_guestbook_backend_helper.php | 15 +++-- lib/d2u_guestbook_lang_helper.php | 1 + lib/d2u_guestbook_module_manager.php | 2 +- lib/entries.php | 46 +++++++------- modules/60/1/output.php | 89 ++++++++++++++-------------- modules/60/1/style.css | 10 ++-- modules/60/2/output.php | 6 +- modules/60/3/output.php | 19 +++--- pages/entries.php | 8 +-- pages/index.php | 2 +- pages/settings.php | 12 ++-- pages/setup.php | 5 +- update.php | 8 +-- 14 files changed, 118 insertions(+), 111 deletions(-) diff --git a/install.php b/install.php index d66f657..84a16a5 100644 --- a/install.php +++ b/install.php @@ -16,8 +16,8 @@ ->ensure(); // Standard settings -if (!$this->hasConfig('guestbook_article_id')) { - $this->setConfig('guestbook_article_id', rex_article::getSiteStartArticleId()); +if (!rex_config::has('d2u_guestbook', 'guestbook_article_id')) { + rex_config::set('d2u_guestbook', 'guestbook_article_id', rex_article::getSiteStartArticleId()); } // Update modules @@ -25,7 +25,7 @@ $modules = []; $modules[] = new D2UModule('60-1', 'D2U Guestbook - Gästebuch mit Bootstrap 4 Tabs', - 13); + 14); $modules[] = new D2UModule('60-2', 'D2U Guestbook - Infobox Bewertung', 3); diff --git a/lib/d2u_guestbook_backend_helper.php b/lib/d2u_guestbook_backend_helper.php index 941b80a..8dca86e 100644 --- a/lib/d2u_guestbook_backend_helper.php +++ b/lib/d2u_guestbook_backend_helper.php @@ -4,7 +4,6 @@ use rex; use rex_addon; -use rex_addon_interface; use rex_config; use rex_mailer; use rex_yrewrite; @@ -16,14 +15,14 @@ class d2u_guestbook_backend_helper { /** * Send mail to admin address when news guestbook entry is created. - * @param mixed $yform + * @param \rex_yform_action_callback $yform */ - public static function sendAdminNotification($yform) + public static function sendAdminNotification($yform):void { - if (isset($yform->params['values']) && '' != rex_config::get('d2u_guestbook', 'request_form_email')) { + if (isset($yform->params['values']) && '' !== (string) rex_config::get('d2u_guestbook', 'request_form_email')) { $fields = []; foreach ($yform->params['values'] as $value) { - if ('' != $value->name) { + if ('' !== $value->name) { $fields[$value->name] = $value->value; } } @@ -31,10 +30,10 @@ public static function sendAdminNotification($yform) $mail = new rex_mailer(); $mail->isHTML(false); $mail->CharSet = 'utf-8'; - $mail->From = rex_config::get('d2u_guestbook', 'request_form_email'); - $mail->Sender = rex_config::get('d2u_guestbook', 'request_form_email'); + $mail->From = (string) rex_config::get('d2u_guestbook', 'request_form_email'); + $mail->Sender = (string) rex_config::get('d2u_guestbook', 'request_form_email'); - $mail->addAddress(rex_config::get('d2u_guestbook', 'request_form_email')); + $mail->addAddress((string) rex_config::get('d2u_guestbook', 'request_form_email')); $mail->addReplyTo($fields['email'], $fields['name']); $mail->Subject = 'New Guestbook entry - Neuer Gästebuch eintrag - '. (rex_addon::get('yrewrite')->isAvailable() ? rex_yrewrite::getCurrentDomain()->getUrl() : rex::getServer()); diff --git a/lib/d2u_guestbook_lang_helper.php b/lib/d2u_guestbook_lang_helper.php index a80fc3d..b9594fd 100644 --- a/lib/d2u_guestbook_lang_helper.php +++ b/lib/d2u_guestbook_lang_helper.php @@ -1,5 +1,6 @@ getRows(); if ($num_rows > 0) { - $this->id = $result->getValue('id'); - $this->clang_id = $result->getValue('clang_id'); - $this->name = stripslashes($result->getValue('name')); - $this->email = $result->getValue('email'); - $this->rating = $result->getValue('rating'); - $this->recommendation = 1 == $result->getValue('recommendation') ? true : false; + $this->id = (int) $result->getValue('id'); + $this->clang_id = (int) $result->getValue('clang_id'); + $this->name = stripslashes((string) $result->getValue('name')); + $this->email = (string) $result->getValue('email'); + $this->rating = (int) $result->getValue('rating'); + $this->recommendation = 1 === (int) $result->getValue('recommendation') ? true : false; $this->privacy_policy_accepted = 1 === (int) $result->getValue('privacy_policy_accepted') ? true : false; - $this->description = stripslashes(htmlspecialchars_decode($result->getValue('description'))); - $this->online_status = $result->getValue('online_status'); - $this->create_date = $result->getValue('create_date'); + $this->description = stripslashes(htmlspecialchars_decode((string) $result->getValue('description'))); + $this->online_status = (string) $result->getValue('online_status'); + $this->create_date = (string) $result->getValue('create_date'); } } @@ -125,7 +125,7 @@ public static function getAll($online_only = false) $entries = []; for ($i = 0; $i < $result->getRows(); ++$i) { - $entries[] = new self($result->getValue('id')); + $entries[] = new self((int) $result->getValue('id')); $result->next(); } return $entries; @@ -161,7 +161,7 @@ public static function getRecommendation() /** * Updates or inserts the object into database. - * @return in error code if error occurs + * @return bool true if error occurs */ public function save() { @@ -175,7 +175,7 @@ public function save() ."privacy_policy_accepted = '". ($this->privacy_policy_accepted ? 'yes' : 'no') ."', " ."description = '". addslashes(htmlspecialchars($this->description)) ."', " ."online_status = '". $this->online_status ."' "; - if (0 == $this->id) { + if (0 === $this->id) { $query = 'INSERT INTO '. $query . ', create_date = CURRENT_TIMESTAMP'; } else { $query = 'UPDATE '. $query .' WHERE id = '. $this->id; @@ -183,7 +183,7 @@ public function save() $result = rex_sql::factory(); $result->setQuery($query); - if (0 == $this->id) { + if (0 === $this->id) { $this->id = (int) $result->getLastId(); $error = $result->hasError(); } diff --git a/modules/60/1/output.php b/modules/60/1/output.php index b32f31b..19c7734 100644 --- a/modules/60/1/output.php +++ b/modules/60/1/output.php @@ -11,14 +11,14 @@ echo '
'; echo '
'; -$hide_rating = 'REX_VALUE[1]' == 'true' ? true : false; +$hide_rating = 'REX_VALUE[1]' === 'true' ? true : false; /** @phpstan-ignore-line */ if (!function_exists('sendAdminNotification')) { /** * Send mail to admin address when news guestbook entry is created. - * @param mixed $yform + * @param \rex_yform_action_callback $yform */ - function sendAdminNotification($yform) + function sendAdminNotification($yform):void { \D2U_Guestbook\d2u_guestbook_backend_helper::sendAdminNotification($yform); } @@ -50,10 +50,9 @@ function sendAdminNotification($yform) } else { for ($i = 0; $i < count($entries); ++$i) { $entry = $entries[$i]; - - if (0 == $i % rex_config::get('d2u_guestbook', 'no_entries_page', 10)) { + if (0 === $i % (int) rex_config::get('d2u_guestbook', 'no_entries_page', 10)) { ++$page_no; - if (1 != $page_no) { + if (1 !== $page_no) { echo '
'; } echo '
'; // Pagination div @@ -64,7 +63,7 @@ function sendAdminNotification($yform) echo '
'; echo '
'; echo '
'; - if ('' != $entry->email && 'true' == rex_config::get('d2u_guestbook', 'allow_answer', 'false')) { + if ('' !== $entry->email && 'true' === (string) rex_config::get('d2u_guestbook', 'allow_answer', 'false')) { echo ''; echo $entry->name .' '; echo ''; @@ -72,14 +71,17 @@ function sendAdminNotification($yform) echo $entry->name; } echo '
'; - echo '
'. date('d.m.Y H:i', strtotime($entry->create_date)) .' '. $tag_open .'d2u_guestbook_oclock'. $tag_close .'
'; - echo '
'; + $time = strtotime($entry->create_date); + if(false !== $time) { + echo '
'. date('d.m.Y H:i', $time) .' '. $tag_open .'d2u_guestbook_oclock'. $tag_close .'
'; + } echo '
'; + echo '
'; // entry-header echo '
'; echo '
'; echo '
'. nl2br($entry->description) .'
'; - if (!$hide_rating && $entry->rating > 0) { + if (!$hide_rating && $entry->rating > 0) { /** @phpstan-ignore-line */ echo '
'. $tag_open .'d2u_guestbook_rating'. $tag_close .': '; for ($j = 1; $j <= 5; ++$j) { if ($j <= $entry->rating) { @@ -90,39 +92,40 @@ function sendAdminNotification($yform) } echo '
'; } - echo '
'; - echo '
'; + echo '
'; // row + echo ''; // entry-body - echo ''; - echo ''; + echo ''; // col-12 } -} -echo ''; // tab_guestbook - -// Page selection -if ($page_no > 1) { - echo ""; + echo '
'; + echo '
'. $tag_open .'d2u_guestbook_page'. $tag_close .': '; + for ($i = 1; $i <= $page_no; ++$i) { + echo ''. $i .''; } - "; - echo '
'; - echo '
'. $tag_open .'d2u_guestbook_page'. $tag_close .': '; - for ($i = 1; $i <= $page_no; ++$i) { - echo ''. $i .''; - } - echo '
'; - echo '
'; + echo '
'; + echo '
'; + } + } } +echo ''; // tab_guestbook // Entry Form echo '
'; @@ -170,7 +173,7 @@ function d2u_guestbook_module_60_1_click_stars(wert) { textarea|description|'. $tag_open .'d2u_guestbook_form_message'. $tag_close .' choice|recommendation|'. $tag_open .'d2u_guestbook_form_recommendation'. $tag_close .'|{"'. $tag_open .'d2u_guestbook_no'. $tag_close .'":"0","'. $tag_open .'d2u_guestbook_yes'. $tag_close .'":"1"}|1|0| checkbox|privacy_policy_accepted|'. $tag_open .'d2u_guestbook_form_privacy_policy'. $tag_close . ' *|0,1|0 - '. ($hide_rating ? 'hidden|rating|0' : 'text|rating|'. $tag_open .'d2u_guestbook_form_rating'. $tag_close .' '. $stars.'|0||{"style":"display:none"}') .' + '. ($hide_rating ? 'hidden|rating|0' : 'text|rating|'. $tag_open .'d2u_guestbook_form_rating'. $tag_close .' '. $stars.'|0||{"style":"display:none"}') /** @phpstan-ignore-line */ .' html||
* '. $tag_open .'d2u_guestbook_form_required'. $tag_close .'

php|validate_timer|Spamprotection|| hidden|online_status|offline @@ -208,9 +211,9 @@ function d2u_guestbook_module_60_1_click_stars(wert) { echo '
'; // tab_content -echo ''; -echo ''; -echo ''; +echo ''; // col-12 +echo ''; // row +echo ''; // d2u_guestbook_module_60_1 ?>