This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/livefeed/main.php

71 lines
1.8 KiB
PHP
Raw Normal View History

2012-06-22 18:13:57 +00:00
<?php
/*
* Name: Live Feed
* Author: Shish <webmaster@shishnet.org>
* License: GPLv2
* Visibility: admin
* Description: Logs user-safe (no IPs) data to a UDP socket, eg IRCCat
* Documentation:
*/
class LiveFeed extends Extension {
public function onSetupBuilding(SetupBuildingEvent $event) {
$sb = new SetupBlock("Live Feed");
2012-06-22 21:30:22 +00:00
$sb->add_text_option("livefeed_host", "IP:port to send events to: ");
2012-06-22 18:13:57 +00:00
$event->panel->add_block($sb);
}
public function onUserCreation(UserCreationEvent $event) {
2012-06-22 18:32:41 +00:00
$this->msg("New user created: {$event->username}");
2012-06-22 18:13:57 +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
);
}
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
}
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
}
public function onImageInfoSet(ImageInfoSetEvent $event) {
2012-06-22 18:13:57 +00:00
# $this->msg("Image info set");
}
2017-09-19 17:55:43 +00:00
public function get_priority(): int {return 99;}
2012-06-22 18:13:57 +00:00
2019-01-06 10:40:39 +00:00
private function msg(string $data) {
2012-06-22 18:13:57 +00:00
global $config;
2012-06-22 18:13:57 +00:00
$host = $config->get_string("livefeed_host", "127.0.0.1:25252");
if(!$host) { return; }
try {
$parts = explode(":", $host);
$host = $parts[0];
$port = $parts[1];
$fp = fsockopen("udp://$host", $port, $errno, $errstr);
if (! $fp) { return; }
fwrite($fp, "$data\n");
fclose($fp);
} catch (Exception $e) {
/* logging errors shouldn't break everything */
2012-06-22 18:13:57 +00:00
}
}
}