/** * Validates the set data attributes against the model rules * * @return bool **/ public function validate() { $valid = parent::validate(); if ($valid) { $results = \Event::trigger('content.onContentBeforeSave', array('com_answers.comment.content', &$this, $this->isNew())); foreach ($results as $result) { if ($result === false) { $this->addError(Lang::txt('Content failed validation.')); $valid = false; } } } return $valid; }
/** * Get a count or list of the comments on an item * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed */ public function comments($what = 'list', $filters = array(), $clear = false) { if (!isset($filters['item_id'])) { $filters['item_id'] = $this->get('id'); } if (!isset($filters['item_type'])) { $filters['item_type'] = 'collection'; } if (!isset($filters['state'])) { $filters['state'] = array(1, 3); } switch (strtolower(trim($what))) { case 'count': if ($this->_cache['comments.count'] === null) { $total = Comment::all()->whereEquals('item_type', $filters['item_type'])->whereEquals('item_id', $this->get('id'))->whereIn('state', $filters['state'])->ordered()->total(); $this->_cache['comments.count'] = $total; } return $this->_cache['comments.count']; break; case 'list': case 'results': default: if (!is_array($this->_cache['comments.list'])) { $results = Comment::all()->whereEquals('item_type', $filters['item_type'])->whereEquals('item_id', $this->get('id'))->whereIn('state', $filters['state'])->ordered()->rows(); $this->_cache['comments.list'] = $results; } return $this->_cache['comments.list']; break; } }
/** * 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 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 = new Comment($this->database); $comment->load($id); $comment->state = 2; // Delete the entry itself if (!$comment->store()) { $this->setError($comment->getError()); } // Return the topics list return $this->displayTask(); }
/** * 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; }
/** * 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; }
/** * 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(); }
/** * 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; }
/** * 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; }
/** * Get a count or list of the comments on an item * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed */ public function comments($what = 'list', $filters = array(), $clear = false) { if (!isset($filters['item_id'])) { $filters['item_id'] = $this->get('id'); } if (!isset($filters['item_type'])) { $filters['item_type'] = 'collection'; } if (!isset($filters['state'])) { $filters['state'] = array(1, 3); } switch (strtolower(trim($what))) { case 'count': if ($this->_cache['comments.count'] === null) { $tbl = new Comment($this->_db); $this->_cache['comments.count'] = $tbl->count($filters); } return $this->_cache['comments.count']; break; case 'list': case 'results': default: if (!is_array($this->_cache['comments.list'])) { $tbl = new Comment($this->_db); if (!($results = $tbl->getComments('collection', $this->get('id')))) { $results = array(); } $this->_cache['comments.list'] = $results; } return $this->_cache['comments.list']; break; } }
/** * 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 ''; }
/** * Get a list or count of comments * * @param string $rtrn Data format to return * @param array $filters Filters to apply to data fetch * @param boolean $clear Clear cached data? * @return mixed */ public function replies($rtrn = 'list', $filters = array(), $clear = false) { if (!isset($filters['item_id'])) { $filters['item_id'] = $this->get('id'); } if (!isset($filters['item_type'])) { $filters['item_type'] = 'answer'; } if (!isset($filters['parent'])) { $filters['parent'] = 0; } if (!isset($filters['state'])) { $filters['state'] = array(self::APP_STATE_PUBLISHED, self::APP_STATE_FLAGGED); } switch (strtolower($rtrn)) { case 'count': if (!isset($this->_comments_count) || !is_numeric($this->_comments_count) || $clear) { $this->_comments_count = 0; if (!$this->_comments) { $c = $this->comments('list', $filters); } foreach ($this->_comments as $com) { $this->_comments_count++; if ($com->replies()) { foreach ($com->replies() as $rep) { $this->_comments_count++; if ($rep->replies()) { $this->_comments_count += $rep->replies()->total(); } } } } } return $this->_comments_count; break; case 'list': case 'results': default: if (!$this->_comments instanceof ItemList || $clear) { $tbl = new Item\Comment($this->_db); if ($this->get('replies', null) !== null) { $results = $this->get('replies'); } else { $results = $tbl->find($filters); } if ($results) { foreach ($results as $key => $result) { $results[$key] = new Comment($result); $results[$key]->set('question_id', $this->get('question_id')); } } else { $results = array(); } $this->_comments = new ItemList($results); } return $this->_comments; break; } }
/** * 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)); }
/** * Delete a review * * @return void */ public function deletereview() { $database = App::get('db'); $publication =& $this->publication; // Incoming $reviewid = Request::getInt('comment', 0); // Do we have a review ID? if (!$reviewid) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_ID')); return; } // Do we have a publication ID? if (!$publication->exists()) { $this->setError(Lang::txt('PLG_PUBLICATIONS_REVIEWS_NO_RESOURCE_ID')); return; } $review = new \Components\Publications\Tables\Review($database); $review->load($reviewid); // Permissions check if ($review->created_by != User::get('id')) { return; } $review->state = 2; $review->store(); // Delete the review's comments $comments1 = \Hubzero\Item\Comment::all()->whereEquals('parent', $reviewid)->whereEquals('item_id', $publication->get('id'))->whereEquals('item_type', 'pubreview')->ordered()->rows(); foreach ($comments1 as $comment1) { $comment1->set('state', $comment1::STATE_DELETED); $comment1->save(); } // Recalculate the average rating for the parent publication $publication->table()->calculateRating(); $publication->table()->updateRating(); App::redirect(Route::url($publication->link('reviews')), Lang::txt('PLG_PUBLICATIONS_REVIEWS_REVIEW_DELETED')); return; }
/** * Set the anonymous state of an entry * * @return void */ public function anonTask() { // Check for request forgeries Request::checkToken(['get', 'post']); $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) { App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . ($wish ? '&wish=' . $wish : ''), false)); return; } // Update record(s) foreach ($ids as $id) { // Updating a category $row = new Comment($this->database); $row->load($id); $row->anonymous = $state; $row->store(); } // Set the redirect App::redirect(Route::url('index.php?option=' . $this->_option . '&controller=' . $this->_controller . ($wish ? '&wish=' . $wish : ''), false)); }