<?php
 class vB_Api_Content_Report extends vB_Api_Content_Text { protected $contenttype = 'vBForum_Report'; protected $reportChannel; protected function __construct() { parent::__construct(); $this->library = vB_Library::instance('Content_Report'); $this->reportChannel = $this->nodeApi->fetchReportChannel(); } public function add($data, $options = []) { if (!$this->library->validate($data, vB_Library_Content::ACTION_ADD)) { throw new vB_Exception_Api('no_create_permissions'); } $vboptions = vB::getDatastore()->getValue('options'); $text = ''; if (!empty($data['pagetext'])) { $text = $data['pagetext']; } else if (!empty($data['rawtext'])) { $text = $data['rawtext']; } else { throw new vB_Exception_Api('invalid_data'); } $wysiwyg = false; if (isset($options['wysiwyg'])) { $wysiwyg = (bool) $options['wysiwyg']; } $strlen = vB_String::vbStrlen($this->library->parseAndStrip($text, $wysiwyg), true); if ($strlen < $vboptions['postminchars']) { throw new vB_Exception_Api('please_enter_message_x_chars', $vboptions['postminchars']); } if ($vboptions['postmaxchars'] != 0 AND $strlen > $vboptions['postmaxchars']) { throw new vB_Exception_Api('maxchars_exceeded_x_y', [$vboptions['postmaxchars'], $strlen]); } $data['parentid'] = $this->reportChannel; $data = $this->cleanInput($data); $this->cleanOptions($options); $result = $this->library->add($data, $options, $wysiwyg); return $result['nodeid']; } public function update($nodeid, $data) { throw new vB_Exception_Api('feature_not_implemented'); } public function openClose($nodeids, $op) { $data = []; $reportNodeids = $this->getReportNodes($nodeids); if (!vB::getUserContext()->isModerator() OR !$this->library->validate($data, vB_Library_Content::ACTION_UPDATE, $reportNodeids)) { throw new vB_Exception_Api('no_permission'); } $this->library->openClose($nodeids, $op); return ['success' => true]; } public function bulkdelete($nodeids) { $data = []; $reportNodeids = $this->getReportNodes($nodeids); if (!vB::getUserContext()->isModerator() OR !$this->library->validate($data, vB_Library_Content::ACTION_UPDATE, $reportNodeids)) { throw new vB_Exception_Api('no_permission'); } $this->library->bulkdelete($nodeids); return ['success' => true]; } protected function getReportNodes($nodeids) { $nodes = []; $results = vB::getDbAssertor()->getRows('vBForum:report', ['nodeid' => $nodeids]); foreach ($results AS $node) { $nodes[] = $node['reportnodeid']; } return $nodes; } } 