add event news_created

This commit is contained in:
xiaomlove
2024-04-03 04:05:04 +08:00
parent 4ad0d7a1eb
commit 8d07ad98f7
5 changed files with 46 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Console\Commands; namespace App\Console\Commands;
use App\Events\NewsCreated;
use App\Events\TorrentCreated; use App\Events\TorrentCreated;
use App\Events\UserDestroyed; use App\Events\UserDestroyed;
use App\Events\UserDisabled; use App\Events\UserDisabled;
@@ -29,6 +30,7 @@ class FireEvent extends Command
"user_destroyed" => UserDestroyed::class, "user_destroyed" => UserDestroyed::class,
"user_disabled" => UserDisabled::class, "user_disabled" => UserDisabled::class,
"user_enabled" => UserEnabled::class, "user_enabled" => UserEnabled::class,
"news_created" => NewsCreated::class,
]; ];
/** /**

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class NewsCreated
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public int $id;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(int $id)
{
$this->id = $id;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrivateChannel('channel-name');
}
}

View File

@@ -799,7 +799,7 @@ HTML;
if (is_array($arr) && isset($arr['torrent_id'], $arr['pieces_hash'])) { if (is_array($arr) && isset($arr['torrent_id'], $arr['pieces_hash'])) {
$out[$arr['pieces_hash']] = $arr['torrent_id']; $out[$arr['pieces_hash']] = $arr['torrent_id'];
} else { } else {
do_log(sprintf("%s, invalid item: %s(%s)", $logPrefix, var_export($item, true), gettype($item)), 'error'); do_log(sprintf("%s, invalid item: %s(%s)", $logPrefix, var_export($item, true), gettype($item)));
} }
} }
return $out; return $out;

View File

@@ -1,6 +1,6 @@
<?php <?php
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12'); defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.8.12');
defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-01'); defined('RELEASE_DATE') || define('RELEASE_DATE', '2024-04-03');
defined('IN_TRACKER') || define('IN_TRACKER', false); defined('IN_TRACKER') || define('IN_TRACKER', false);
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP"); defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org"); defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");

View File

@@ -48,8 +48,10 @@ if ($action == 'add')
$notify = 'no'; $notify = 'no';
sql_query("INSERT INTO news (userid, added, body, title, notify) VALUES (".sqlesc($CURUSER['id']) . ", $added, " . sqlesc($body) . ", " . sqlesc($title) . ", " . sqlesc($notify).")") or sqlerr(__FILE__, __LINE__); sql_query("INSERT INTO news (userid, added, body, title, notify) VALUES (".sqlesc($CURUSER['id']) . ", $added, " . sqlesc($body) . ", " . sqlesc($title) . ", " . sqlesc($notify).")") or sqlerr(__FILE__, __LINE__);
$Cache->delete_value('recent_news',true); $Cache->delete_value('recent_news',true);
if (mysql_affected_rows() != 1) if (mysql_affected_rows() != 1) {
stderr($lang_news['std_error'], $lang_news['std_something_weird_happened']); stderr($lang_news['std_error'], $lang_news['std_something_weird_happened']);
}
fire_event("news_created", mysql_insert_id());
header("Location: " . get_protocol_prefix() . "$BASEURL/index.php"); header("Location: " . get_protocol_prefix() . "$BASEURL/index.php");
} }