Example #1
0
 /**
  * Save an abuse report and displays a "Thank you" message
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $this->view->cat = Request::getVar('category', '');
     $this->view->refid = Request::getInt('referenceid', 0);
     $this->view->returnlink = Request::getVar('link', '');
     $no_html = Request::getInt('no_html', 0);
     // Trim and addslashes all posted items
     $incoming = array_map('trim', $_POST);
     // Initiate class and bind posted items to database fields
     $row = new ReportAbuse($this->database);
     if (!$row->bind($incoming)) {
         if ($no_html) {
             echo json_encode(array('success' => false, 'message' => $row->getError(), 'id' => $this->view->refid, 'category' => $this->view->cat));
             return;
         }
         Request::setVar('id', $this->view->refid);
         $this->setError($row->getError());
         $this->displayTask();
         return;
     }
     $row->report = Sanitize::clean($row->report);
     $row->report = nl2br($row->report);
     $row->created_by = User::get('id');
     $row->created = Date::toSql();
     $row->state = 0;
     // Check content
     if (!$row->check()) {
         if ($no_html) {
             echo json_encode(array('success' => false, 'message' => $row->getError(), 'id' => $this->view->refid, 'category' => $this->view->cat));
             return;
         }
         Request::setVar('id', $this->view->refid);
         $this->setError($row->getError());
         $this->displayTask();
         return;
     }
     // Store new content
     if (!$row->store()) {
         if ($no_html) {
             echo json_encode(array('success' => false, 'message' => $row->getError(), 'id' => $this->view->refid, 'category' => $this->view->cat));
             return;
         }
         Request::setVar('id', $this->view->refid);
         $this->setError($row->getError());
         $this->displayTask();
         return;
     }
     // Get the search result totals
     $results = Event::trigger('support.onReportItem', array($this->view->refid, $this->view->cat));
     // Send notification email
     if ($this->config->get('abuse_notify', 1)) {
         $reported = new \stdClass();
         $reported->author = 0;
         // Get the search result totals
         $results = Event::trigger('support.getReportedItem', array($this->view->refid, $this->view->cat, 0));
         // Check the results returned for a reported item
         if ($results) {
             foreach ($results as $result) {
                 if ($result) {
                     $reported = $result[0];
                     break;
                 }
             }
         }
         // Get any set emails that should be notified of ticket submission
         $defs = str_replace("\r", '', $this->config->get('abuse_emails', '{config.mailfrom}'));
         $defs = str_replace('\\n', "\n", $defs);
         $defs = explode("\n", $defs);
         $defs = array_map('trim', $defs);
         $message = new \Hubzero\Mail\Message();
         $message->setSubject(Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT_ABUSE_REPORT'))->addFrom(Config::get('mailfrom'), Config::get('sitename') . ' ' . Lang::txt(strtoupper($this->_option)))->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'abuse_item_report');
         // Plain text email
         $eview = new \Hubzero\Mail\View(array('name' => 'emails', 'layout' => 'abuse_plain'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->report = $row;
         $eview->reported = $reported;
         $eview->author = null;
         $plain = $eview->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         $message->addPart($plain, 'text/plain');
         // HTML email
         $eview->setLayout('abuse_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         $message->addPart($html, 'text/html');
         // Loop through the addresses
         foreach ($defs as $def) {
             // Check if the address should come from Joomla config
             if ($def == '{config.mailfrom}') {
                 $def = Config::get('mailfrom');
             }
             // Check for a valid address
             if (Validate::email($def)) {
                 $message->addTo($def);
             }
         }
         // Send e-mail
         if (!$message->send()) {
             $this->setError(Lang::txt('Uh-oh'));
         }
     }
     if ($no_html) {
         echo json_encode(array('success' => true, 'report_id' => $row->id, 'message' => Lang::txt('COM_SUPPORT_REPORT_NUMBER_REFERENCE', $row->id), 'id' => $this->view->refid, 'category' => $this->view->cat));
         return;
     }
     // Set the page title
     $this->_buildTitle();
     $this->view->title = $this->_title;
     $this->view->report = $row;
     // Set the pathway
     $this->_buildPathway();
     // Output HTML
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     $this->view->display();
 }