2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2012-06-22 18:13:57 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class LiveFeed extends Extension
|
|
|
|
{
|
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event)
|
|
|
|
{
|
2020-10-26 15:13:28 +00:00
|
|
|
$sb = $event->panel->create_new_block("Live Feed");
|
2019-05-28 16:59:38 +00:00
|
|
|
$sb->add_text_option("livefeed_host", "IP:port to send events to: ");
|
|
|
|
}
|
2012-06-22 18:13:57 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onUserCreation(UserCreationEvent $event)
|
|
|
|
{
|
|
|
|
$this->msg("New user created: {$event->username}");
|
|
|
|
}
|
2012-06-22 18:13:57 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onImageAddition(ImageAdditionEvent $event)
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
$this->msg(
|
|
|
|
make_http(make_link("post/view/".$event->image->id))." - ".
|
|
|
|
"new post by ".$user->name
|
|
|
|
);
|
|
|
|
}
|
2012-06-22 19:04:12 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onTagSet(TagSetEvent $event)
|
|
|
|
{
|
|
|
|
$this->msg(
|
|
|
|
make_http(make_link("post/view/".$event->image->id))." - ".
|
|
|
|
"tags set to: ".Tag::implode($event->tags)
|
|
|
|
);
|
|
|
|
}
|
2012-06-22 18:13:57 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onCommentPosting(CommentPostingEvent $event)
|
|
|
|
{
|
|
|
|
global $user;
|
|
|
|
$this->msg(
|
|
|
|
make_http(make_link("post/view/".$event->image_id))." - ".
|
|
|
|
$user->name . ": " . str_replace("\n", " ", $event->comment)
|
|
|
|
);
|
|
|
|
}
|
2012-06-22 18:13:57 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function get_priority(): int
|
|
|
|
{
|
|
|
|
return 99;
|
|
|
|
}
|
2012-06-22 18:13:57 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
private function msg(string $data)
|
|
|
|
{
|
|
|
|
global $config;
|
2016-07-30 21:11:49 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$host = $config->get_string("livefeed_host", "127.0.0.1:25252");
|
2012-06-22 18:13:57 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
if (!$host) {
|
|
|
|
return;
|
|
|
|
}
|
2012-06-22 18:13:57 +00:00
|
|
|
|
|
|
|
try {
|
2019-05-28 16:59:38 +00:00
|
|
|
$parts = explode(":", $host);
|
2012-06-22 18:13:57 +00:00
|
|
|
$host = $parts[0];
|
2020-01-26 13:19:35 +00:00
|
|
|
$port = (int)$parts[1];
|
2012-06-22 18:13:57 +00:00
|
|
|
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
|
2019-05-28 16:59:38 +00:00
|
|
|
if (! $fp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fwrite($fp, "$data\n");
|
2012-06-22 18:13:57 +00:00
|
|
|
fclose($fp);
|
2023-01-11 11:15:26 +00:00
|
|
|
} catch (\Exception $e) {
|
2014-03-30 12:26:48 +00:00
|
|
|
/* logging errors shouldn't break everything */
|
2012-06-22 18:13:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|