Skip to content

Commit

Permalink
fix: mass message bypass notification settings + mass message bypass …
Browse files Browse the repository at this point in the history
…purification
  • Loading branch information
samerton committed Mar 9, 2024
1 parent bfb08ad commit 32b67ee
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 4 additions & 2 deletions core/classes/Core/Alert.php
Expand Up @@ -53,10 +53,11 @@ public static function create(int $user_id, string $type, array $text_short, arr
* @param int $userId
* @param string $title
* @param string $content
* @param string|null $link Optional link to redirect the user to on click
* @param string|null $link Optional link to redirect the user to on click
* @param bool $skipPurify If true the content will not be purified before displaying to user - use with care
* @return void
*/
public static function send(int $userId, string $title, string $content, ?string $link = '')
public static function send(int $userId, string $title, string $content, ?string $link = '', bool $skipPurify = false)
{
DB::getInstance()->insert('alerts', [
'user_id' => $userId,
Expand All @@ -66,6 +67,7 @@ public static function send(int $userId, string $title, string $content, ?string
'content' => $title,
'content_rich' => $content,
'created' => date('U'),
'bypass_purify' => $skipPurify,
]);
}

Expand Down
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class AddPurifyBypassColumToAlertsTable extends AbstractMigration
{
public function change(): void
{
$this->table('nl2_alerts')
->addColumn('bypass_purify', 'boolean', ['default' => false])
->update();
}
}
4 changes: 3 additions & 1 deletion modules/Core/classes/Core/Notification.php
Expand Up @@ -13,6 +13,7 @@ class Notification {

private int $_authorId;
private array $_recipients = [];
private bool $_skipPurify;
private string $_title;
private string $_type;

Expand Down Expand Up @@ -45,6 +46,7 @@ public function __construct(
}

$this->_authorId = $authorId;
$this->_skipPurify = $skipPurify;
$this->_title = $title;
$this->_type = $type;

Expand Down Expand Up @@ -83,7 +85,7 @@ public function send(): void {
}

private function sendAlert(int $userId, string $content): void {
Alert::send($userId, $this->_title, $content);
Alert::send($userId, $this->_title, $content, null, $this->_skipPurify);
}

private function sendEmail(int $userId, string $content): void {
Expand Down
4 changes: 3 additions & 1 deletion modules/Core/pages/panel/mass_message.php
Expand Up @@ -132,11 +132,13 @@
[...$excludedUsers, ...$includedUsers]
);
} else {
$where = $clause ? "WHERE $clause" : '';

$users = DB::getInstance()->query(
<<<SQL
SELECT u.id FROM nl2_users u
$join
WHERE $clause
$where
SQL
);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/Core/pages/user/alerts.php
Expand Up @@ -155,7 +155,7 @@
'DELETE' => $language->get('general', 'delete'),
'DELETE_LINK' => URL::build('/user/alerts/', 'view=' . $alert->id . '&delete'),
'ALERT_TITLE' => Output::getClean($alert->content),
'ALERT_CONTENT' => Output::getPurified($alert->content_rich),
'ALERT_CONTENT' => $alert->bypass_purify ? $alert->content_rich : Output::getPurified($alert->content_rich),
'ALERT_DATE' => date(DATE_FORMAT, $alert->created),
'ALERT_DATE_NICE' => $timeAgo->inWords($alert->created, $language),
'ALERT_READ' => $alert->read,
Expand Down

0 comments on commit 32b67ee

Please sign in to comment.