<?php
 class vB_Systemevent_Item_Content_Notification extends vB_Systemevent_Item { protected int $nodeid = 0; protected int $triggeruserid = 0; protected bool $isnew = false; protected string $contenttype = ''; protected array $words = []; protected string $failedapproval = ''; protected array $serializefields = ['triggeruserid', 'contenttype', 'nodeid', 'isnew', 'words', 'failedapproval']; public static function create(int $triggeruserid, string $contenttype, int $nodeid, int $isnew) : self { $item = new self(); $item->triggeruserid = $triggeruserid; $item->contenttype = $contenttype; $item->nodeid = $nodeid; $item->isnew = $isnew; return $item; } public function getIsNew() { return $this->isnew; } public function getNodeid() { return $this->nodeid; } public function addMonitorWords($data) { $textfields = ['title', 'rawtext', 'reason']; if (empty($data['rawtext']) AND !empty($data['description'])) { $textfields[] = 'description'; } foreach ($textfields AS $field) { if (!empty($data[$field])) { $monitoredWords = vB_String::getMonitoredWords($data[$field]); if ($monitoredWords) { $this->words[$field] = $monitoredWords; } } } } public function addUnapproved() { if ($this->failedapproval != 'spam') { $this->failedapproval = 'unapproved'; } } public function addSpam() { $this->failedapproval = 'spam'; } public function run() : void { $notificationLib = vB_Library::instance('notification'); if ($this->isnew) { $contentLib = vB_Library_Content::getContentLib($this->contenttype); $node = $contentLib->getFullContent($this->nodeid); $node = reset($node); if ($contentLib->isVisitorMessage($this->nodeid) AND !empty($node['setfor'])) { $notificationLib->triggerNotificationEvent('new-visitormessage', ['sentbynodeid' => $this->nodeid], $node['setfor']); } else if ($node['starter'] > 0) { $notificationLib->triggerNotificationEvent('new-content', ['sentbynodeid' => $this->nodeid]); } } foreach ($this->words AS $subtype => $monitoredWords) { $notificationLib->triggerNotificationEvent('node-monitored-word-found', [ 'sentbynodeid' => $this->nodeid, 'sender' => $this->triggeruserid, 'customdata' => [ 'maintype' => 'node', 'subtypes' => [$subtype], 'words' => $monitoredWords, ], ]); } if ($this->failedapproval) { $notificationLib->triggerNotificationEvent('node-' . $this->failedapproval . '-post', [ 'sentbynodeid' => $this->nodeid, 'sender' => $this->triggeruserid, ]); } $notificationLib->insertNotificationsToDB(); } } 