Exemple #1
0
	public function delete()
	{
		
		JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN'));

		
		$cid = JFactory::getApplication()->input->get('id', array(), 'array');

		if (!is_array($cid) || count($cid) < 1)
		{
			JError::raiseWarning(500, JText::_('COM_JUDOWNLOAD_NO_ITEM_SELECTED'));
			$this->setRedirect($this->getReturnPage());
		}
		else
		{
			
			$model = $this->getModel();

			
			jimport('joomla.utilities.arrayhelper');
			JArrayHelper::toInteger($cid);

			
			if ($model->delete($cid))
			{
				$this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid)));
			}
			else
			{
				$this->setMessage($model->getError());
			}

			$isDocumentPublished = JUDownloadFrontHelperDocument::isDocumentPublished($cid[0]);
			if ($isDocumentPublished)
			{
				$mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($cid[0]);
				$this->setRedirect(JRoute::_(JUDownloadHelperRoute::getCategoryRoute($mainCategoryId), false));
			}
			else
			{
				$this->setRedirect($this->getReturnPage());
			}
		}
	}
	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;
	}