public static function canComment($documentId, $email = '') { $canViewDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true); if ($canViewDocument == false) { return false; } $userIdPassed = self::checkBlackListUserId(); if (!$userIdPassed) { return false; } $userIpPassed = self::checkBlackListUserIP(); if (!$userIpPassed) { return false; } $params = JUDownloadHelper::getParams(null, $documentId); $user = JFactory::getUser(); $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentId); $ownerCanCommentOnDocument = $params->get('document_owner_can_comment', 0); if ($isDocumentOwner && $ownerCanCommentOnDocument) { $ownerCanCommentManyTimes = $params->get('document_owner_can_comment_many_times', 0); if ($ownerCanCommentManyTimes) { return true; } else { $totalCommentsOnDoc = JUDownloadFrontHelperComment::getTotalCommentsOnDocumentOfUser($documentId, $user->id); if ($totalCommentsOnDoc == 0) { return true; } } } $asset = 'com_judownload.document.' . $documentId; if ($user->authorise('judl.comment.create', $asset) || (JUDownloadFrontHelperPermission::canDownloadDocument($documentId) && $params->get('can_download_can_comment', 0))) { if ($user->authorise('judl.comment.create.many_times', $asset)) { return true; } else { if (!$user->get('guest')) { $totalCommentsOnDoc = JUDownloadFrontHelperComment::getTotalCommentsOnDocumentOfUser($documentId, $user->id); if ($totalCommentsOnDoc == 0) { return true; } } else { if ($email != '') { $totalCommentsPerOneDocumentForGuest = JUDownloadFrontHelperComment::getTotalCommentsOnDocumentForGuest($documentId, $email); if ($totalCommentsPerOneDocumentForGuest == 0) { return true; } } else { return true; } } } } return false; }
public function canDownloadDocument($documentId, $checkPassword = true) { $storeId = md5(__METHOD__ . "::$documentId::" . (int) $checkPassword); if (!isset($this->cache[$storeId])) { $mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId); $canDoCategory = JUDownloadFrontHelperPermission::canDoCategory($mainCategoryId); if (!$canDoCategory) { $this->cache[$storeId] = false; return $this->cache[$storeId]; } $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentId); if ($isDocumentOwner) { $asset = 'com_judownload.document.' . $documentId; $user = JFactory::getUser(); if ($user->authorise('judl.document.download.own.no_restrict', $asset)) { $this->cache[$storeId] = true; return $this->cache[$storeId]; } } $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isModerator) { $documentObject = JUDownloadHelper::getDocumentById($documentId); if ($documentObject->approved < 1) { $modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategoryId, 'document_approve'); if ($modCanApprove) { $this->cache[$storeId] = true; return $this->cache[$storeId]; } } $modCanDownload = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategoryId, 'document_download'); if ($modCanDownload) { $this->cache[$storeId] = true; return $this->cache[$storeId]; } } if ($isDocumentOwner) { $userCanDoDocument = true; } else { $userCanDoDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true); } if (!$userCanDoDocument) { $this->cache[$storeId] = false; return $this->cache[$storeId]; } if (!$isModerator || ($isModerator && !$modCanDownload)) { $validDownloadRules = JUDownloadFrontHelperDocument::getDownloadRuleErrorMessages($documentId); if ($validDownloadRules !== true) { $message = array(); $message = array_merge($message, $validDownloadRules); $this->setError(implode("<br/>", $message)); $this->cache[$storeId] = false; return $this->cache[$storeId]; } } $documentObject = JUDownloadHelper::getDocumentById($documentId); $hasPassword = JUDownloadFrontHelperDocument::documentHasPassword($documentObject); if ($hasPassword && $checkPassword) { $validPassword = JUDownloadFrontHelperPassword::checkPassword($documentObject); if (!$validPassword) { $this->setError(JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_PASSWORD')); $this->cache[$storeId] = false; return $this->cache[$storeId]; } } $this->cache[$storeId] = true; return $this->cache[$storeId]; } return $this->cache[$storeId]; }