/** * 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'] = 'review'; } 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 \Hubzero\Base\ItemList || $clear) { $tbl = new \Hubzero\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 ResourcesModelComment($result); } } else { $results = array(); } $this->_comments = new \Hubzero\Base\ItemList($results); } return $this->_comments; break; } }
/** * 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 comments($rtrn = 'list', $filters = array(), $clear = false) { $tbl = new \Hubzero\Item\Comment($this->_db); if (!isset($filters['item_id'])) { $filters['item_id'] = $this->get('id'); } if (!isset($filters['item_type'])) { $filters['item_type'] = 'wish'; } if (!isset($filters['parent'])) { $filters['parent'] = 0; } if (!isset($filters['state'])) { $filters['state'] = array(static::APP_STATE_PUBLISHED, static::APP_STATE_FLAGGED); } switch (strtolower($rtrn)) { case 'count': if (!is_numeric($this->_cache['comments.count']) || $clear) { $this->_cache['comments.count'] = 0; if (!$this->_cache['comments.list']) { $c = $this->comments('list', $filters); } foreach ($c as $com) { $this->_cache['comments.count']++; if ($com->replies()->total()) { foreach ($com->replies() as $rep) { $this->_cache['comments.count']++; if ($rep->replies()->total()) { $this->_cache['comments.count'] += $rep->replies()->total(); } } } } } return $this->_cache['comments.count']; break; case 'authors': if (!is_array($this->_cache['comments.authors']) || $clear) { $this->_cache['comments.authors'] = array(); if (!$this->_cache['comments.authors']) { $c = $this->comments('list', $filters); } foreach ($c as $com) { $this->_cache['comments.authors'][] = $com->get('added_by'); if ($com->replies()->total()) { foreach ($com->replies() as $rep) { $this->_cache['comments.authors'][] = $rep->get('added_by'); if ($rep->replies()->total()) { foreach ($rep->replies() as $res) { $this->_cache['comments.authors'][] = $res->get('added_by'); } } } } } $this->_cache['comments.authors'] = array_unique($this->_cache['comments.authors']); } return $this->_cache['comments.authors']; break; case 'list': case 'results': default: if (!$this->_cache['comments.list'] instanceof ItemList || $clear) { if ($results = $tbl->find($filters)) { foreach ($results as $key => $result) { $results[$key] = new Comment($result); } } else { $results = array(); } $this->_cache['comments.list'] = new ItemList($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 = new \Hubzero\Item\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->_post(); }
/** * 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 $reply = new \Hubzero\Item\Comment($database); $comments1 = $reply->find(array('parent' => $reviewid, 'item_type' => 'pubreview', 'item_id' => $publication->get('id'))); if (count($comments1) > 0) { foreach ($comments1 as $comment1) { $reply->setState($comment1->id, 2); } } // 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; }
/** * 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\Rank($database); $objR->remove_vote($referenceid); $message .= Lang::txt('PLG_SUPPORT_WISHLIST_NOTIFICATION_OF_WISH_REMOVAL', $parentid); break; case 'wishcomment': $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_WISHLIST_NOTIFICATION_OF_COMMENT_REMOVAL', $parentid); break; } return $message; }
/** * Mark a comment as deleted * NOTE: Does not actually delete data. Simply marks record. * * @return void */ protected function _delete() { // Ensure the user is logged in if (User::isGuest()) { $this->_login(); } // Incoming $id = Request::getInt('comment', 0); if (!$id) { return $this->_redirect(); } // Initiate a blog comment object $comment = new \Hubzero\Item\Comment($this->database); $comment->load($id); if (User::get('id') != $comment->created_by && !$this->params->get('access-delete-comment')) { App::redirect($this->url); return; } // Delete the entry itself if (!$comment->setState($id, 2)) { $this->setError($comment->getError()); } App::redirect($this->url, Lang::txt('PLG_COURSES_REVIEWS_REMOVED'), 'message'); }
if (!User::isGuest()) { $jxuser = new \Hubzero\User\Profile(); $jxuser->load(User::get('id')); $anonymous = 0; } ?> <img src="<?php echo $jxuser->getPicture($anonymous); ?> " alt="" /> </p> <fieldset> <?php if (!User::isGuest()) { if ($replyto = Request::getInt('replyto', 0)) { $reply = new \Hubzero\Item\Comment($this->database); $reply->load($replyto); $name = Lang::txt('COM_KB_ANONYMOUS'); if (!$reply->anonymous) { $xuser = new \Hubzero\User\Profile(); $xuser->load($reply->created_by); if (is_object($xuser) && $xuser->get('name')) { $name = '<a href="' . Route::url($xuser->getLink()) . '">' . $this->escape(stripslashes($xuser->get('name'))) . '</a>'; } } ?> <blockquote cite="c<?php echo $this->replyto->id; ?> "> <p>
/** * 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; }
/** * Get all replies for an item * * @param object $item Item to look for reports on * @param string $category Item type * @param integer $level Depth * @param boolean $abuse Abuse flag * @return array */ public static function getComments($id, $item, $category, $level, $abuse = false) { $database = App::get('db'); $level++; $hc = new \Hubzero\Item\Comment($database); $comments = $hc->find(array('parent' => $level == 1 ? 0 : $item->id, 'item_id' => $id, 'item_type' => $category)); if ($comments) { foreach ($comments as $comment) { $comment->replies = self::getComments($id, $comment, 'review', $level, $abuse); if ($abuse) { $comment->abuse_reports = self::getAbuseReports($comment->id, 'review'); } } } return $comments; }
/** * 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; } $database = App::get('db'); $this->loadLanguage(); $msg = Lang::txt('PLG_SUPPORT_COMMENTS_CONTENT_FOUND_OBJECTIONABLE'); $comment = new \Hubzero\Item\Comment($database); $comment->load($refid); if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $comment->content, $matches)) { $format = strtolower(trim($matches[1])); switch ($format) { case 'html': $comment->content = '<!-- {FORMAT:HTML} --><span class="warning">' . $msg . '</span>'; break; case 'wiki': default: $comment->content = '<!-- {FORMAT:WIKI} -->[[Span(' . $msg . ', class="warning")]]'; break; } } else { $comment->content = '[[Span(' . $msg . ', class="warning")]]'; } $comment->state = 1; $comment->store(); return ''; }
/** * Delete a review * * @return void */ public function deletereview() { $database = App::get('db'); $resource =& $this->resource; // Incoming $reviewid = Request::getInt('comment', 0); // Do we have a review ID? if (!$reviewid) { $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_ID')); return; } // Do we have a resource ID? if (!$resource->id) { $this->setError(Lang::txt('PLG_RESOURCES_REVIEWS_NO_RESOURCE_ID')); return; } $review = new \Components\Resources\Tables\Review($database); $review->load($reviewid); // Permissions check if ($review->user_id != User::get('id') && !User::authorise('core.admin')) { return; } $review->state = 2; $review->store(); // Delete the review's comments $reply = new \Hubzero\Item\Comment($database); $comments1 = $reply->find(array('parent' => $reviewid, 'item_type' => 'review', 'item_id' => $resource->id)); if (count($comments1) > 0) { foreach ($comments1 as $comment1) { $reply->setState($comment1->id, 2); } } // Recalculate the average rating for the parent resource $resource->calculateRating(); $resource->updateRating(); 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 = 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_RESOURCES_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 ($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 = new \Hubzero\Item\Comment($database); $comment->load($referenceid); //$comment->state = 2; if (preg_match('/^<!-- \\{FORMAT:(.*)\\} -->/i', $comment->content, $matches)) { $format = strtolower(trim($matches[1])); switch ($format) { case 'html': $comment->content = '<!-- {FORMAT:HTML} --><span class="warning">' . $msg . '</span>'; break; case 'wiki': default: $comment->content = '<!-- {FORMAT:WIKI} -->[[Span(' . $msg . ', class="warning")]]'; break; } } else { $comment->content = '[[Span(' . $msg . ', class="warning")]]'; } if (!$comment->store()) { $this->setError($comment->getError()); return false; } $message .= Lang::txt('PLG_SUPPORT_PUBLICATIONS_NOTIFICATION_OF_REMOVAL', $parentid); break; } return $message; }