Skip to content

Commit

Permalink
rexstan enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasKrais committed May 21, 2023
1 parent c345fa0 commit 8d520a3
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 111 deletions.
6 changes: 3 additions & 3 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
->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
if (class_exists('D2UModuleManager')) {
$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);
Expand Down
15 changes: 7 additions & 8 deletions lib/d2u_guestbook_backend_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use rex;
use rex_addon;
use rex_addon_interface;
use rex_config;
use rex_mailer;
use rex_yrewrite;
Expand All @@ -16,25 +15,25 @@ 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;
}
}

$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());

Expand Down
1 change: 1 addition & 0 deletions lib/d2u_guestbook_lang_helper.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**
* @api
* Offers helper functions for language issues.
*/
class d2u_guestbook_lang_helper extends \D2U_Helper\ALangHelper
Expand Down
2 changes: 1 addition & 1 deletion lib/d2u_guestbook_module_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function getModules()
$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);
Expand Down
46 changes: 23 additions & 23 deletions lib/entries.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,34 @@
class Entry
{
/** @var int Database ID */
public $id = 0;
public int $id = 0;

/** @var string name */
public $name = '';
public string $name = '';

/** @var string email address */
public $email = '';
public string $email = '';

/** @var string description */
public $description = '';
public string $description = '';

/** @var int Redaxo clang ID */
public $clang_id = 1;
public int $clang_id = 1;

/** @var int rating */
public $rating = 5;
public int $rating = 5;

/** @var bool recommendation */
public $recommendation = true;
public bool $recommendation = true;

/** @var bool Did user accept privacy policy */
public $privacy_policy_accepted = false;
public bool $privacy_policy_accepted = false;

/** @var string Online status */
public $online_status = 'online';
public string $online_status = 'online';

/** @var string create date */
public $create_date = '';
public string $create_date = '';

/**
* Constructor. Reads a contact stored in database.
Expand All @@ -58,16 +58,16 @@ public function __construct($id)
$num_rows = $result->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');
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
{
Expand All @@ -175,15 +175,15 @@ 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;
}

$result = rex_sql::factory();
$result->setQuery($query);
if (0 == $this->id) {
if (0 === $this->id) {
$this->id = (int) $result->getLastId();
$error = $result->hasError();
}
Expand Down
89 changes: 46 additions & 43 deletions modules/60/1/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
echo '<div id="d2u_guestbook_module_60_1" class="col-12 col-sm-'. $cols_sm .' col-md-'. $cols_md .' col-lg-'. $cols_lg . $offset_lg .'">';
echo '<div class="row">';

$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);
}
Expand Down Expand Up @@ -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 '</div>';
}
echo '<div class="row guestbook-page pages-'. $page_no .'">'; // Pagination div
Expand All @@ -64,22 +63,25 @@ function sendAdminNotification($yform)
echo '<div class="entry-header">';
echo '<div class="row">';
echo '<div class="col-6"><b>';
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 '<a href="mailto:'. $entry->email .'">';
echo $entry->name .' <span class="icon mail"></span>';
echo '</a>';
} else {
echo $entry->name;
}
echo '</b></div>';
echo '<div class="col-6 right">'. date('d.m.Y H:i', strtotime($entry->create_date)) .' '. $tag_open .'d2u_guestbook_oclock'. $tag_close .'</div>';
echo '</div>';
$time = strtotime($entry->create_date);
if(false !== $time) {
echo '<div class="col-6 right">'. date('d.m.Y H:i', $time) .' '. $tag_open .'d2u_guestbook_oclock'. $tag_close .'</div>';
}
echo '</div>';
echo '</div>'; // entry-header

echo '<div class="entry-body">';
echo '<div class="row">';
echo '<div class="col-12">'. nl2br($entry->description) .'</div>';
if (!$hide_rating && $entry->rating > 0) {
if (!$hide_rating && $entry->rating > 0) { /** @phpstan-ignore-line */
echo '<div class="col-12"><b>'. $tag_open .'d2u_guestbook_rating'. $tag_close .': ';
for ($j = 1; $j <= 5; ++$j) {
if ($j <= $entry->rating) {
Expand All @@ -90,39 +92,40 @@ function sendAdminNotification($yform)
}
echo '</b></div>';
}
echo '</div>';
echo '</div>';
echo '</div>'; // row
echo '</div>'; // entry-body

echo '</div>';
echo '</div>';
echo '</div>'; // col-12
}
}
echo '</div>'; // tab_guestbook

// Page selection
if ($page_no > 1) {
echo "<script>
// show only first page
jQuery(document).ready(function($) {
$('.guestbook-page').hide();
$('.pages-1').show();
});
// hide pages and show selected page
function changePage(pageno) {
$('.guestbook-page').slideUp();
$('.active-page').removeClass('active-page');
$('.pages-' + pageno).slideDown();
$('#page-' + pageno).addClass('active-page');
if($page_no > 0) {
echo '</div>'; // row guestbook-page
if($page_no > 1) {
// Page selection
echo "<script>
// show only first page
jQuery(document).ready(function($) {
$('.guestbook-page').hide();
$('.pages-1').show();
});
// hide pages and show selected page
function changePage(pageno) {
$('.guestbook-page').slideUp();
$('.active-page').removeClass('active-page');
$('.pages-' + pageno).slideDown();
$('#page-' + pageno).addClass('active-page');
}
</script>";
echo '<div class="row">';
echo '<div class="col-12 page-selection">'. $tag_open .'d2u_guestbook_page'. $tag_close .': ';
for ($i = 1; $i <= $page_no; ++$i) {
echo '<a href="javascript:changePage('. $i .')" class="page'. (1 === $i ? ' active-page' : '') .'" id="page-'. $i .'">'. $i .'</a>';
}
</script>";
echo '<div class="row">';
echo '<div class="col-12 page-selection">'. $tag_open .'d2u_guestbook_page'. $tag_close .': ';
for ($i = 1; $i <= $page_no; ++$i) {
echo '<a href="javascript:changePage('. $i .')" class="page'. (1 == $i ? ' active-page' : '') .'" id="page-'. $i .'">'. $i .'</a>';
}
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
}
}
}
echo '</div>'; // tab_guestbook

// Entry Form
echo '<div id="tab_write" class="tab-pane fade guestbook-tab">';
Expand Down Expand Up @@ -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||<br>* '. $tag_open .'d2u_guestbook_form_required'. $tag_close .'<br><br>
php|validate_timer|Spamprotection|<input name="validate_timer" type="hidden" value="'. microtime(true) .'" />|
hidden|online_status|offline
Expand Down Expand Up @@ -208,9 +211,9 @@ function d2u_guestbook_module_60_1_click_stars(wert) {

echo '</div>'; // tab_content

echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>'; // col-12
echo '</div>'; // row
echo '</div>'; // d2u_guestbook_module_60_1
?>
<script>
// Allow activation of bootstrap tab via URL
Expand Down
10 changes: 5 additions & 5 deletions modules/60/1/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ a.recommendation:hover {
border-top: navi_color_bg 1px solid;
padding: 0.75em;
}
guestbook-page {
display: inline-block;
}
#tab_guestbook.tab-pane {
#d2u_guestbook_module_60_1 .tab-pane {
border: navi_color_bg 1px solid;
padding: 1em 1em 0 1em;
padding: 15px 15px 0 15px;
}
#d2u_guestbook_module_60_1 #tab_write {
padding-bottom: 15px;
}
.page-selection {
background-color: article_color_box;
Expand Down
6 changes: 3 additions & 3 deletions modules/60/2/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$tag_close = $sprog->getConfig('wildcard_close_tag');

$d2u_guestbook = rex_addon::get('d2u_guestbook');
$show_link = ($d2u_guestbook->hasConfig('guestbook_article_id') && '' != $d2u_guestbook->getConfig('guestbook_article_id')) ? true : false;
$show_link = ($d2u_guestbook->hasConfig('guestbook_article_id') && 0 < (int) $d2u_guestbook->getConfig('guestbook_article_id')) ? true : false;

$rating = round(D2U_Guestbook\Entry::getRating(), 1);
$num_recommendations = D2U_Guestbook\Entry::getRecommendation();
Expand All @@ -20,7 +20,7 @@
echo '<p>'. \Sprog\Wildcard::get('d2u_guestbook_no_entries') . '</p>';
} else {
if ($show_link) {
echo '<a href="'. rex_getUrl($d2u_guestbook->getConfig('guestbook_article_id')) .'" class="recommendation">';
echo '<a href="'. rex_getUrl((int) $d2u_guestbook->getConfig('guestbook_article_id')) .'" class="recommendation">';
}
echo '<div class="recommendation-stars">';
for ($i = 1; $i <= 5; ++$i) {
Expand All @@ -35,7 +35,7 @@
echo '</div>';
if ($show_link) {
echo '</a>';
echo '<a href="'. rex_getUrl($d2u_guestbook->getConfig('guestbook_article_id')) .'">';
echo '<a href="'. rex_getUrl((int) $d2u_guestbook->getConfig('guestbook_article_id')) .'">';
}
echo $tag_open .'d2u_guestbook_recommended_pre'. $tag_close .' '. $num_recommendations .' '. $tag_open .'d2u_guestbook_recommended_post'. $tag_close;
if ($show_link) {
Expand Down
Loading

0 comments on commit 8d520a3

Please sign in to comment.