Änderungen
/* Beispiel-Code */
== Beispiel-Code ==
<source lang="php"><?php// Addon for monitoring log class LogMonitor extends Addon { public static $shortName = "log_monitor"; public function __construct($language) { $this->name = self::$shortName; parent::__construct(); $this->info = Array( 'name' => "Log-Monitor", 'version' => "1.0", 'company' => "sourceWAY.de", 'url' => "https://sourceway.de/", ); } public function delete() { return $this->deleteDir(realpath(__DIR__)); } public function hooks() { return Array( Array("UserLogEntry", "log", 0), ); } public function log($params) { $user = $params['user']; $log = $params['log']; if ($this->interestingUser($user) || $this->interestingText($log)) { Telegram::sendMessage($this->buildMsg($user, $log)); } } private function buildMsg($user, $log) { global $raw_cfg; if (!($user instanceof User)) { return false; } return '<a href="' . $raw_cfg['PAGEURL'] . 'admin/?p=customers&edit=' . $user->get()['ID'] . '">' . htmlentities($user->get()['name']) . '</a>: ' . htmlentities($log); } private function interestingUser($user) { if (!($user instanceof User)) { return false; } $ex = explode(",", $this->options["user"]); foreach ($ex as &$v) { $v = intval(trim($v)); } return in_array($user->get()["ID"], $ex); } private function interestingText($log) { $log = trim($log); $ex = explode(",", $this->options["text"]); foreach ($ex as $v) { if (strpos($log, trim($v)) !== false && !empty(trim($v))) { return true; } } return false; } public function getSettings() { return Array( "user" => Array("placeholder" => "1,5,7,...", "label" => "Zu überwachende Benutzer (mehrere mit Komma trennen)", "type" => "text"), "text" => Array("placeholder" => "Domain,...", "label" => "Zu überwachender Text (mehrere mit Komma trennen)", "type" => "text"), ); }}</source>