Пример #1
0
	public function getItems()
	{
		$user       = JFactory::getUser();
		$token      = JSession::getFormToken();
		$items      = parent::getItems();
		$documentId = (int) $this->getState('document.id');
		$params     = $this->getState('params');
		if (count($items) > 0)
		{
			$commentsRecursive = array();
			foreach ($items AS $item)
			{
				$commentsRecursive[] = $item;
				$commentsRecursive   = array_merge($commentsRecursive, $this->getCommentRecursive($item->id));
			}

			$items = $commentsRecursive;
		}

		foreach ($items AS $item)
		{
			$item->comment_edit = $item->comment;
			$item->comment      = JUDownloadFrontHelper::BBCode2Html($item->comment);
			$item->comment      = JUDownloadFrontHelperComment::parseCommentText($item->comment, $documentId);

			
			$item->can_reply     = JUDownloadFrontHelperPermission::canReplyComment($documentId, $item->id);
			$item->can_vote      = JUDownloadFrontHelperPermission::canVoteComment($documentId, $item->id);
			$item->can_report    = JUDownloadFrontHelperPermission::canReportComment($documentId, $item->id);
			$item->can_subscribe = false;
			$item->can_edit      = false;
			$item->can_delete    = false;
			$isOwnerComment      = JUDownloadFrontHelperPermission::isCommentOwner($item->id);
			if ($isOwnerComment)
			{
				$item->can_edit    = JUDownloadFrontHelperPermission::canEditComment($item->id);
				$item->can_delete  = JUDownloadFrontHelperPermission::canDeleteComment($item->id);
				$item->link_delete = JRoute::_('index.php?option=com_judownload&task=document.deleteComment&comment_id=' . $item->id . '&' . $token . '=1');

				if ($params->get('can_subscribe_own_comment', 1))
				{
					$item->can_subscribe = true;
					if ($this->isSubscriber($user->id, $item->id, 'comment'))
					{
						$item->is_subscriber = true;
						$secret              = JFactory::getConfig()->get('secret');
						$type                = 'comment';
						$code                = md5($user->id . $user->email . $type . $secret);

						$subscriptionObject = JUDownloadFrontHelper::getSubscriptionObjectByType($user->id, $item->id, $type);

						$item->subscribe_link = JRoute::_('index.php?option=com_judownload&task=subscribe.remove&sub_id=' . (int) $subscriptionObject->id .
							'&code=' . $code . '&' . $token . '=1');

					}
					else
					{
						$item->is_subscriber  = false;
						$item->subscribe_link = JRoute::_('index.php?option=com_judownload&task=subscribe.save' .
							'&comment_id=' . $item->id . '&' . $token . '=1');
					}
				}
			}

			$item->voted_value = $this->getCommentVotedValue($item->id);
		}

		return $items;
	}
Пример #2
0
 protected function canDelete($record)
 {
     $rootComment = JUDownloadFrontHelperComment::getRootComment();
     if (isset($record->id) && $record->id == $rootComment->id) {
         return false;
     }
     $app = JFactory::getApplication();
     if ($app->isSite()) {
         return JUDownloadFrontHelperPermission::canDeleteComment($record->id);
     }
     return parent::canDelete($record);
 }
Пример #3
0
	public function deleteComment()
	{
		
		JSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
		$app           = JFactory::getApplication();
		$commentId     = $app->input->getInt('comment_id', 0);
		$commentObject = JUDownloadFrontHelperComment::getCommentObject($commentId);
		$documentId    = $commentObject->doc_id;

		
		$canDeleteComment = JUDownloadFrontHelperPermission::canDeleteComment($commentId);
		if ($canDeleteComment)
		{
			$commentModel = $this->getModel('Modcomment', 'JUDownloadModel');

			if ($commentModel->delete($commentId))
			{
				$this->setMessage(JText::_('COM_JUDOWNLOAD_DELETE_COMMENT_SUCCESSFULLY'));
				$this->setRedirect(JRoute::_(JUDownloadHelperRoute::getDocumentRoute($documentId), false));

				return true;
			}
		}

		$this->setMessage(JText::_('COM_JUDOWNLOAD_DELETE_COMMENT_FAILED'), 'error');
		$this->setRedirect(JRoute::_(JUDownloadHelperRoute::getDocumentRoute($documentId), false));

		return false;
	}