public static function checkPassword($documentObject) { $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentObject->id); $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isDocumentOwner) { $asset = 'com_judownload.document.' . $documentObject->id; $user = JFactory::getUser(); if ($user->authorise('judl.document.download.own.no_restrict', $asset)) { return true; } } if ($isModerator) { $mainCategory = JUDownloadFrontHelperCategory::getMainCategory($documentObject->id); $modCanDownload = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategory->id, 'document_download'); if ($modCanDownload) { return true; } if ($documentObject->approved < 1) { $modCanApproval = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategory->id, 'document_approve'); if ($modCanApproval) { return true; } } } $session = JFactory::getSession(); if ($session->get('judl-download-password-' . $documentObject->id, '') === $documentObject->download_password) { return true; } else { return false; } }
public static function showCaptchaWhenComment($documentId) { if (!$documentId) { return false; } $user = JFactory::getUser(); $params = JUDownloadHelper::getParams(null, $documentId); $ownerDocument = JUDownloadFrontHelperPermission::isDocumentOwner($documentId); if ($ownerDocument && $params->get('document_owner_use_captcha_when_comment', 1)) { return false; } $assetName = 'com_judownload.document.' . $documentId; if ($user->authorise('judl.comment.no_captcha', $assetName)) { return false; } return true; }
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]; }