Example #1
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 ($category != 'pubreview' && $category != 'pubreviewcomment') {
         return null;
     }
     $this->loadLanguage();
     $msg = Lang::txt('PLG_SUPPORT_PUBLICATIONS_CONTENT_FOUND_OBJECTIONABLE');
     $database = App::get('db');
     switch ($category) {
         case 'review':
             include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'publication.php';
             include_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'review.php';
             // Delete the review
             $review = new PublicationReview($database);
             $review->load($referenceid);
             //$comment->anonymous = 1;
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $review->comment, $matches)) {
                 $format = strtolower(trim($matches[1]));
                 switch ($format) {
                     case 'html':
                         $review->comment = '<!-- {FORMAT:HTML} --><span class="warning">' . $msg . '</span>';
                         break;
                     case 'wiki':
                     default:
                         $review->comment = '<!-- {FORMAT:WIKI} -->[[Span(' . $msg . ', class="warning")]]';
                         break;
                 }
             } else {
                 $review->comment = '[[Span(' . $msg . ', class="warning")]]';
             }
             $review->store();
             // Recalculate the average rating for the parent resource
             $pub = new Publication($database);
             $pub->load($parentid);
             $pub->calculateRating();
             $pub->updateRating();
             if (!$pub->store()) {
                 $this->setError($pub->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_PUBLICATIONS_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
         case 'reviewcomment':
             $comment = \Hubzero\Item\Comment::oneOrFail($referenceid);
             if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $comment->get('content'), $matches)) {
                 $format = strtolower(trim($matches[1]));
                 switch ($format) {
                     case 'html':
                         $comment->set('content', '<!-- {FORMAT:HTML} --><span class="warning">' . $msg . '</span>');
                         break;
                     case 'wiki':
                     default:
                         $comment->set('content', '<!-- {FORMAT:WIKI} -->[[Span(' . $msg . ', class="warning")]]');
                         break;
                 }
             } else {
                 $comment->set('content', '[[Span(' . $msg . ', class="warning")]]');
             }
             if (!$comment->save()) {
                 $this->setError($comment->getError());
                 return false;
             }
             $message .= Lang::txt('PLG_SUPPORT_PUBLICATIONS_NOTIFICATION_OF_REMOVAL', $parentid);
             break;
     }
     return $message;
 }