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 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]; }
public static function canViewDocument($documentId) { $documentObject = JUDownloadHelper::getDocumentById($documentId); if (!is_object($documentObject)) { return false; } $canDoCategory = JUDownloadFrontHelperPermission::canDoCategory($documentObject->cat_id, true); if (!$canDoCategory) { return false; } if ($documentObject->approved == 1) { $canEditDocument = JUDownloadFrontHelperPermission::canEditDocument($documentId); $canEditStateDocument = JUDownloadFrontHelperPermission::canEditStateDocument($documentObject); $userCanDoDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true); if ($canEditDocument || $canEditStateDocument || $userCanDoDocument) { return true; } } $isDocumentPublished = JUDownloadFrontHelperDocument::isDocumentPublished($documentId); $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentId); if ($isDocumentOwner) { $params = JUDownloadHelper::getParams(null, $documentId); if ($documentObject->approved <= 0 || $isDocumentPublished || (!$isDocumentPublished && $params->get('document_owner_can_view_unpublished_document', 0))) { return true; } } $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isModerator) { if ($documentObject->approved == 1) { if ($isDocumentPublished) { $modCanViewDocument = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($documentObject->cat_id, 'document_view'); if ($modCanViewDocument) { return true; } } else { $modCanViewDocument = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($documentObject->cat_id, 'document_view_unpublished'); if ($modCanViewDocument) { return true; } } } else { $modCanViewDocument = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($documentObject->cat_id, 'document_approve'); if ($modCanViewDocument) { return true; } } } return false; }
public function canSubmit($userID = null) { if (!$this->isPublished()) { return false; } $app = JFactory::getApplication(); if ($app->isAdmin()) { return true; } else { if ($userID) { $user = JFactory::getUser($userID); } else { $user = JFactory::getUser(); } if ($app->input->getInt('approve', 0) == 1) { if (is_object($this->doc) && $this->doc->approved <= 0) { $modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($this->doc->cat_id, 'document_approve'); if ($modCanApprove) { return true; } } } $approvalOption = $app->input->post->get("approval_option"); $approvalOptionArray = array("ignore", "approve", "delete"); if (in_array($approvalOption, $approvalOptionArray)) { if (is_object($this->doc) && $this->doc->approved <= 0) { $categoriesField = new JUDownloadFieldCore_categories(); $newMainCategory = $this->fields_data[$categoriesField->id]['main']; if ($newMainCategory) { $modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($newMainCategory, 'document_approve'); if ($modCanApprove) { return true; } } } } if ($user) { $assetName = 'com_judownload.field.' . (int) $this->id; return $user->authorise("judl.field.value.submit", $assetName); } } return false; }