/** * Delete a comment * * @return string */ private function _deletecomment() { // Ensure the user is logged in if (User::isGuest()) { return $this->_login(); } // Incoming $id = Request::getInt('comment', 0); if (!$id) { return $this->_post(); } // Initiate a whiteboard comment object $comment = \Hubzero\Item\Comment::oneOrFail($id); $comment->set('state', 2); // Delete the entry itself if (!$comment->save()) { $this->setError($comment->getError()); } // Record the activity /*$recipients = array( ['group', $this->group->get('gidNumber')], ['collection', $post->get('collection_id')], ['user', $comment->get('created_by')], ['user', $post->item()->get('created_by')] ); foreach ($this->group->get('managers') as $recipient) { $recipients[] = ['user', $recipient]; } $title = $post->item()->get('title'); $title = ($title ? $title : $post->item()->get('description', '#' . $post->get('id'))); $title = \Hubzero\Utility\String::truncate(strip_tags($title), 70); Event::trigger('system.logActivity', [ 'activity' => [ 'action' => 'deleted', 'scope' => 'collections.comment', 'scope_id' => $comment->get('id'), 'description' => Lang::txt('PLG_GROUPS_COLLECTIONS_ACTIVITY_COMMENT_DELETED', $comment->get('id'), '<a href="' . Route::url($entry->link()) . '">' . $title . '</a>'), 'details' => array( 'collection_id' => $post->get('collection_id'), 'post_id' => $post->get('id'), 'item_id' => $comment->get('item_id') ) ], 'recipients' => $recipients ]);*/ // Return the topics list return $this->_post(); }
/** * Delete a reply * * @return void */ public function deletereply() { $publication =& $this->publication; // Incoming $replyid = Request::getInt('comment', 0); // Do we have a review ID? if (!$replyid) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_COMMENT_ERROR_NO_REFERENCE_ID')); return; } // Do we have a publication ID? if (!$publication->exists()) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID')); return; } // Delete the review $reply = \Hubzero\Item\Comment::oneOrFail($replyid); // Permissions check if ($reply->get('created_by') != User::get('id')) { return; } $reply->set('state', $reply::STATE_DELETED); $reply->save(); // Redirect App::redirect(Route::url($publication->link('reviews')), Lang::txt('PLG_PUBLICATIONS_REVIEWS_COMMENT_DELETED')); }
/** * 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; } $this->loadLanguage(); $database = App::get('db'); switch ($category) { case 'wish': include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wishlist.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish' . DS . 'plan.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'owner.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'ownergroup.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish' . DS . 'rank.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_wishlist' . DS . 'tables' . DS . 'wish' . DS . 'attachment.php'; // Delete the wish $wish = new \Components\Wishlist\Tables\Wish($database); $wish->delete_wish($referenceid); // also delete all votes for this wish $objR = new \Components\Wishlist\Tables\Wish\Rank($database); $objR->remove_vote($referenceid); $message .= Lang::txt('PLG_SUPPORT_WISHLIST_NOTIFICATION_OF_WISH_REMOVAL', $parentid); break; case 'wishcomment': $comment = \Hubzero\Item\Comment::oneOrFail($referenceid); $comment->set('state', $comment::STATE_DELETED); if (!$comment->save()) { $this->setError($comment->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_WISHLIST_NOTIFICATION_OF_COMMENT_REMOVAL', $parentid); break; } return $message; }
/** * 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($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 = \Hubzero\Item\Comment::oneOrFail($referenceid); $comment->set('state', $comment::STATE_DELETED); if (!$comment->save()) { $this->setError($comment->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_ANSWERS_NOTIFY_COMMENT_REMOVED', $parentid); break; } return $message; }
/** * Set the anonymous state of an entry * * @return void */ public function anonTask() { // Check for request forgeries Request::checkToken(['get', 'post']); if (!User::authorise('core.edit.state', $this->_option)) { App::abort(403, Lang::txt('JERROR_ALERTNOAUTHOR')); } $state = $this->getTask() == 'anonymize' ? 1 : 0; // Incoming $wish = Request::getInt('wish', 0); $ids = Request::getVar('id', array()); $ids = !is_array($ids) ? array($ids) : $ids; // Check for an ID if (count($ids) < 1) { return $this->cancelTask(); } // Update record(s) foreach ($ids as $id) { // Updating a category $row = Comment::oneOrFail($id); $row->set('anonymous', $state); if (!$row->save()) { Notify::error($row->getError()); } } // Set the redirect $this->cancelTask(); }
/** * Delete a reply * * @return void */ public function deletereply() { // Is the user logged in? if (User::isGuest()) { $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_LOGIN_NOTICE')); return; } $resource =& $this->resource; // Incoming $replyid = Request::getInt('comment', 0); // Do we have a review ID? if (!$replyid) { $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_COMMENT_ERROR_NO_REFERENCE_ID')); return; } // Do we have a resource ID? if (!$resource->id) { $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_RESOURCE_ID')); return; } // Delete the review $reply = \Hubzero\Item\Comment::oneOrFail($replyid); // Permissions check if ($reply->get('created_by') != User::get('id') && !User::authorise('core.admin')) { return; } $reply->set('state', \Hubzero\Item\Comment::STATE_DELETED); $reply->save(); App::Redirect(Route::url('index.php?option=' . $this->_option . '&id=' . $resource->id . '&active=reviews', false)); }
/** * 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; } $this->loadLanguage(); $database = App::get('db'); switch ($category) { case 'review': include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'resource.php'; include_once PATH_CORE . DS . 'components' . DS . 'com_resources' . DS . 'tables' . DS . 'review.php'; // Delete the review $review = new \Components\Resources\Tables\Review($database); $review->load($referenceid); $review->state = 2; $review->store(); // Recalculate the average rating for the parent resource $resource = new \Components\Resources\Tables\Resource($database); $resource->load($parentid); $resource->calculateRating(); if (!$resource->store()) { $this->setError($resource->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid); break; case 'reviewcomment': $comment = \Hubzero\Item\Comment::oneOrFail($referenceid); $comment->set('state', $comment::STATE_DELETED); if (!$comment->save()) { $this->setError($comment->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_RESOURCES_NOTIFICATION_OF_REMOVAL', $parentid); break; } return $message; }
/** * Delete a comment * * @return string */ private function _deletecomment() { // Ensure the user is logged in if (User::isGuest()) { return $this->_login(); } // Incoming $id = Request::getInt('comment', 0); if (!$id) { return $this->_post(); } // Initiate a whiteboard comment object $comment = \Hubzero\Item\Comment::oneOrFail($id); $comment->set('state', $comment::STATE_DELETED); // Delete the entry itself if (!$comment->save()) { $this->setError($comment->getError()); } // Return the topics list return $this->_post(); }
/** * Delete a comment * * @return string */ public function deletecommentTask() { // Ensure the user is logged in if (User::isGuest()) { return $this->loginTask(); } // Incoming $id = Request::getInt('comment', 0); if (!$id) { return $this->displayTask(); } // Initiate a whiteboard comment object $comment = Comment::oneOrFail($id); $comment->set('state', $comment::STATE_DELETED); // Delete the entry itself if (!$comment->save()) { $this->setError($comment->getError()); } // Log activity $post = new Post(Request::getInt('post', 0)); $title = $post->item()->get('title'); $title = $title ? $title : $post->item()->get('description', '#' . $post->get('id')); $title = \Hubzero\Utility\String::truncate(strip_tags($title), 70); $url = 'index.php?option=' . $this->_option . '&controller=' . $this->_controller . '&post=' . $post->get('id'); $item = '<a href="' . Route::url($url) . '">' . $title . '</a>'; Event::trigger('system.logActivity', ['activity' => ['action' => 'deleted', 'scope' => 'collections.comment', 'scope_id' => $comment->get('id'), 'description' => Lang::txt('COM_COLLECTIONS_ACTIVITY_COMMENT_DELETED', $comment->get('id'), $item), 'details' => array('collection_id' => $post->get('collection_id'), 'post_id' => $post->get('id'), 'item_id' => $comment->get('item_id'), 'url' => Route::url($url))], 'recipients' => array(['collection', $post->get('collection_id')], ['user', $row->get('created_by')], ['user', $post->item()->get('created_by')])]); // Return the topics list return $this->displayTask(); }
/** * Retrieves a row from the database * * @param string $refid ID of the database table row * @param string $parent If the element has a parent element * @param string $category Element type (determines table to look in) * @param string $message If the element has a parent element * @return array */ public function deleteReportedItem($refid, $parent, $category, $message) { if (!in_array($category, array('wishcomment', 'answercomment', 'reviewcomment', 'citations', 'citationscomment', 'collection', 'itemcomment', 'coursescomment'))) { return null; } $this->loadLanguage(); $msg = Lang::txt('PLG_SUPPORT_COMMENTS_CONTENT_FOUND_OBJECTIONABLE'); $comment = \Hubzero\Item\Comment::oneOrFail($refid); 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")]]'); } $comment->set('state', $comment::STATE_PUBLISHED); $comment->save(); return ''; }
/** * 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; }