示例#1
0
 /**
  * Delete a record
  *
  * @param   boolean  $isSpam
  * @return  void
  */
 public function removeTask($isSpam = false)
 {
     // Check for request forgeries
     Request::checkToken();
     // Incoming
     $id = Request::getInt('id', 0);
     $parentid = Request::getInt('parentid', 0);
     // Ensure we have an ID to work with
     if (!$id) {
         App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false));
         return;
     }
     $email = 1;
     // Turn off/on
     $gratitude = 1;
     // Turn off/on
     $message = '';
     // Load the report
     $report = new ReportAbuse($this->database);
     $report->load($id);
     $report->reviewed = Date::toSql();
     $report->reviewed_by = User::get('id');
     $report->note = Request::getVar('note', '');
     // Get the reported item
     $results = Event::trigger('support.getReportedItem', array($report->referenceid, $report->category, $parentid));
     // Check the results returned for a reported item
     $reported = null;
     if ($results) {
         foreach ($results as $result) {
             if ($result) {
                 $reported = $result[0];
             }
         }
     }
     // Remove the reported item and any other related processes that need be performed
     $results = Event::trigger('support.deleteReportedItem', array($report->referenceid, $parentid, $report->category, $message));
     if ($results) {
         foreach ($results as $result) {
             if ($result) {
                 $message .= $result;
             }
         }
     }
     if ($isSpam) {
         $results = Event::trigger('antispam.onAntispamTrain', array($reported->text, $isSpam));
     }
     // Mark abuse report as deleted
     $report->state = 2;
     if (!$report->store()) {
         throw new Exception($report->getError(), 500);
     }
     // Notify item owner
     if ($email) {
         $user = User::getInstance($reported->author);
         // Email "from" info
         $from = array('name' => Config::get('sitename') . ' ' . Lang::txt('COM_SUPPORT'), 'email' => Config::get('mailfrom'), 'multipart' => md5(date('U')));
         // Email subject
         $subject = Lang::txt('COM_SUPPORT_REPORT_ABUSE_EMAIL_SUBJECT', Config::get('sitename'));
         // Plain text
         $eview = new View(array('base_path' => PATH_CORE . DS . 'components' . DS . 'com_support' . DS . 'site', 'name' => 'emails', 'layout' => 'abuse_plain'));
         $eview->option = $this->_option;
         $eview->controller = $this->_controller;
         $eview->reported = $reported;
         $eview->report = $report;
         $eview->author = $user;
         $plain = $eview->loadTemplate(false);
         $plain = str_replace("\n", "\r\n", $plain);
         // HTML
         $eview->setLayout('abuse_html');
         $html = $eview->loadTemplate();
         $html = str_replace("\n", "\r\n", $html);
         // Build message
         $message = new Message();
         $message->setSubject($subject)->addFrom($from['email'], $from['name'])->addTo($user->get('email'), $user->get('name'))->addHeader('X-Component', 'com_support')->addHeader('X-Component-Object', 'abuse_item_removal');
         $message->addPart($plain, 'text/plain');
         $message->addPart($html, 'text/html');
         // Send the email
         if (Utilities::checkValidEmail($user->get('email'))) {
             $message->send();
         }
     }
     // Check the HUB configuration to see if banking is turned on
     $upconfig = Component::params('com_members');
     $banking = $upconfig->get('bankAccounts');
     // Give some points to whoever reported abuse
     if ($banking && $gratitude) {
         $BC = \Hubzero\Bank\Config::values();
         $ar = $BC->get('abusereport');
         // How many points?
         if ($ar) {
             $ruser = User::getInstance($report->created_by);
             if (is_object($ruser) && $ruser->get('id')) {
                 $BTL = new \Hubzero\Bank\Teller($ruser->get('id'));
                 $BTL->deposit($ar, Lang::txt('COM_SUPPORT_ACKNOWLEDGMENT_FOR_VALID_REPORT'), 'abusereport', $id);
             }
         }
     }
     // Redirect
     App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller, false), Lang::txt('COM_SUPPORT_REPORT_ITEM_TAKEN_DOWN'));
 }
示例#2
0
 /**
  * Removes an item reported as abusive
  *
  * @param      integer $referenceid ID of the database table row
  * @param      integer $parentid    If the element has a parent element
  * @param      string  $category    Element type (determines table to look in)
  * @param      string  $message     Message to user to append to
  * @return     string
  */
 public function deleteReportedItem($referenceid, $parentid, $category, $message)
 {
     if (!$this->_canHandle($category)) {
         return null;
     }
     $database = App::get('db');
     switch ($category) {
         case 'answer':
             $database->setQuery("UPDATE `#__answers_responses` SET state='2' WHERE id=" . $referenceid);
             if (!$database->query()) {
                 $this->setError($database->getErrorMsg());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_ANSWERS_NOTIFY_ANSWER_REMOVED', $parentid);
             break;
         case 'question':
             $upconfig = Component::params('com_members');
             $banking = $upconfig->get('bankAccounts');
             $reward = 0;
             if ($banking) {
                 $reward = $this->getReward($parentid);
             }
             $responders = array();
             // Get all the answers for this question
             $database->setQuery("SELECT r.id, r.created_by FROM `#__answers_responses` AS r WHERE r.question_id=" . $referenceid);
             $answers = $database->loadObjectList();
             if ($answers) {
                 foreach ($answers as $answer) {
                     // Delete response
                     $database->setQuery("UPDATE `#__answers_responses` SET state='2' WHERE id=" . $answer->id);
                     if (!$database->query()) {
                         $this->setError($database->getErrorMsg());
                         return false;
                     }
                     // Collect responders names
                     $responders[] = $answer->created_by;
                 }
             }
             $database->setQuery("UPDATE `#__answers_questions` SET state='2', reward='0' WHERE id=" . $referenceid);
             if (!$database->query()) {
                 $this->setError($database->getErrorMsg());
                 return false;
             }
             if ($banking && $reward) {
                 // Send email to people who answered question with reward
                 if ($responders) {
                     foreach ($responders as $r) {
                         $zuser = User::getInstance($r);
                         if (is_object($zuser)) {
                             if (\Components\Support\Helpers\Utilities::checkValidEmail($zuser->get('email')) && $email) {
                                 $admin_email = Config::get('mailfrom');
                                 $sub = Lang::txt('PLG_SUPPORT_ANSWERS_SUBJECT', Config::get('sitename'), $referenceid);
                                 $from = Lang::txt('PLG_SUPPORT_ANSWERS_TITLE', Config::get('sitename'));
                                 $hub = array('email' => $admin_email, 'name' => $from);
                                 $mes = Lang::txt('PLG_SUPPORT_ANSWERS_BODY') . "\r\n";
                                 $mes .= '----------------------------' . "\r\n\r\n";
                                 $mes .= Lang::txt('PLG_SUPPORT_ANSWERS_QUESTION', $referenceid) . "\r\n";
                                 \Components\Support\Helpers\Utilities::sendEmail($hub, $zuser->get('email'), $sub, $mes);
                             }
                         }
                     }
                 }
                 // get id of asker
                 $database->setQuery("SELECT created_by FROM `#__answers_questions` WHERE id=" . $parentid);
                 $asker = $database->loadResult();
                 if ($asker) {
                     $quser = User::getInstance($asker);
                     if (is_object($quser)) {
                         $asker_id = $quser->get('id');
                     }
                     if (isset($asker_id)) {
                         // Remove hold
                         $sql = "DELETE FROM `#__users_transactions` WHERE category='answers' AND type='hold' AND referenceid=" . $parentid . " AND uid='" . $asker_id . "'";
                         $database->setQuery($sql);
                         if (!$database->query()) {
                             $this->setError($database->getErrorMsg());
                             return false;
                         }
                         // Make credit adjustment
                         $BTL_Q = new \Hubzero\Bank\Teller($database, $asker_id);
                         $credit = $BTL_Q->credit_summary();
                         $adjusted = $credit - $reward;
                         $BTL_Q->credit_adjustment($adjusted);
                     }
                 }
             }
             $message .= Lang::txt('PLG_SUPPORT_ANSWERS_NOTIFY_QUESTION_REMOVED', $parentid);
             break;
         case 'answercomment':
             $comment = new \Hubzero\Item\Comment($database);
             $comment->load($referenceid);
             $comment->state = 2;
             if (!$comment->store()) {
                 $this->setError($comment->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_ANSWERS_NOTIFY_COMMENT_REMOVED', $parentid);
             break;
     }
     return $message;
 }