Пример #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
	public static function canCheckInComment($commentId)
	{
		JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judownload/tables");
		$commentTable = JTable::getInstance('Comment', 'JUDownloadTable');
		$commentTable->load($commentId);

		if (property_exists($commentTable, 'checked_out') && property_exists($commentTable, 'checked_out_time') && $commentTable->checked_out > 0)
		{
			$user           = JFactory::getUser();
			$isModerator    = JUDownloadFrontHelperModerator::isModerator();
			$isCommentOwner = JUDownloadFrontHelperPermission::isCommentOwner($commentId);
			
			if ($isModerator || $isCommentOwner || $commentTable->checked_out == $user->id)
			{
				$canEditComment = JUDownloadFrontHelperPermission::canEditComment($commentId);
				if ($canEditComment)
				{
					return true;
				}
			}
		}

		return false;
	}