예제 #1
0
	public function getItem()
	{
		$params = $this->getState('params');

		
		$documentId = (int) $this->getState('document.id');
		
		if (!$documentId)
		{
			JError::raiseError(404, JText::_('COM_JUDOWNLOAD_DOCUMENT_NOT_FOUND'));

			return false;
		}

		
		$user = JFactory::getUser();
		
		$db = JFactory::getDbo();
		
		$query = $db->getQuery(true);
		$query->select('d.*, c.id AS cat_id');
		$query->from('#__judownload_documents AS d');

		$query->join('', '#__judownload_documents_xref AS dxref ON d.id = dxref.doc_id AND dxref.main=1');
		$query->join('', '#__judownload_categories AS c ON c.id = dxref.cat_id');

		
		$query->select('(SELECT COUNT(*) FROM #__judownload_files AS f WHERE f.doc_id = d.id AND f.published = 1) AS total_files');

		
		$query->select('(SELECT COUNT(*) FROM #__judownload_comments AS cm WHERE cm.doc_id = d.id AND cm.approved = 1 AND cm.published = 1) AS total_comments');

		
		$query->select('(SELECT COUNT(*) FROM #__judownload_subscriptions AS sub WHERE sub.item_id = d.id AND sub.type = "document" AND sub.published = 1) AS total_subscriptions');

		
		$query->select('(SELECT COUNT(*) FROM #__judownload_reports AS r WHERE r.item_id = d.id AND r.type = "document") AS total_reports');

		
		$query->select('(SELECT GROUP_CONCAT(catids.id ORDER BY dx_catids.main DESC, dx_catids.ordering ASC SEPARATOR ",") FROM (#__judownload_categories AS catids JOIN #__judownload_documents_xref AS dx_catids ON catids.id = dx_catids.cat_id) WHERE d.id = dx_catids.doc_id GROUP BY d.id) AS cat_ids');
		
		$query->select('(SELECT GROUP_CONCAT(cattitles.title ORDER BY dx_cattitles.main DESC, dx_cattitles.ordering ASC SEPARATOR "|||") FROM (#__judownload_categories AS cattitles JOIN #__judownload_documents_xref AS dx_cattitles ON cattitles.id = dx_cattitles.cat_id) WHERE d.id = dx_cattitles.doc_id GROUP BY d.id) AS cat_titles');

		

		
		$accessLevel = implode(',', $user->getAuthorisedViewLevels());
		$db          = JFactory::getDbo();
		$date        = JFactory::getDate();
		$nullDate    = $db->quote($db->getNullDate());
		$nowDate     = $db->quote($date->toSql());

		
		$fieldQuery = $db->getQuery(true);
		$fieldQuery->select('field.id');
		$fieldQuery->from('#__judownload_fields AS field');
		$fieldQuery->where('field.group_id != 1');
		$fieldQuery->where('field.details_view = 1');

		$fieldQuery->where('field.published = 1');
		$fieldQuery->where('field.publish_up <= ' . $nowDate);
		$fieldQuery->where('(field.publish_down = ' . $nullDate . ' OR field.publish_down > ' . $nowDate . ')');

		
		$fieldQuery->where('(field.access IN (' . $accessLevel . ') OR field.who_can_download_can_access = 1)');

		$category = JUDownloadFrontHelperCategory::getMainCategory($documentId);
		if (is_object($category))
		{
			$fieldQuery->where('field.group_id = ' . $category->fieldgroup_id);
		}

		$fieldQuery->join('', '#__judownload_fields_groups AS field_group ON field.group_id = field_group.id');
		$fieldQuery->where('field_group.published = 1');
		$fieldQuery->where('field_group.access IN (' . $accessLevel . ')');

		$fieldQuery->group('field.id');

		$db->setQuery($fieldQuery);

		
		$fields = $db->loadObjectList();
		foreach ($fields AS $field)
		{
			$query->select('IFNULL (fields_values_' . $field->id . '.value, "") AS field_values_' . $field->id);
			$query->join('LEFT', '#__judownload_fields_values AS fields_values_' . $field->id . ' ON fields_values_' . $field->id . '.doc_id = d.id AND fields_values_' . $field->id . '.field_id = ' . $field->id);
		}

		$query->where('d.id = ' . $documentId);
		$db->setQuery($query);
		$documentObject = $db->loadObject();
		
		if (!is_object($documentObject))
		{
			JError::raiseError(404, JText::_('COM_JUDOWNLOAD_DOCUMENT_NOT_FOUND'));

			return false;
		}

		
		$documentObject->params = JUDownloadFrontHelperDocument::getDocumentDisplayParams($documentObject->id);

		
		if (!$user->get('guest'))
		{
			$canEditDocument      = JUDownloadFrontHelperPermission::canEditDocument($documentObject->id);
			$canDeleteDocument    = JUDownloadFrontHelperPermission::canDeleteDocument($documentObject->id);
			$canEditStateDocument = JUDownloadFrontHelperPermission::canEditStateDocument($documentObject);
			$documentObject->params->set('access-edit', $canEditDocument);
			$documentObject->params->set('access-edit-state', $canEditStateDocument);
			$documentObject->params->set('access-delete', $canDeleteDocument);
		}

		
		$canReportDocument   = JUDownloadFrontHelperPermission::canReportDocument($documentObject->id);
		$canContactDocument  = JUDownloadFrontHelperPermission::canContactDocument($documentObject->id);
		$canRateDocument     = JUDownloadFrontHelperPermission::canRateDocument($documentObject->id);
		$canDownloadDocument = JUDownloadFrontHelperPermission::canDownloadDocument($documentObject->id, false);
		$canCommentDocument  = JUDownloadFrontHelperPermission::canComment($documentObject->id);

		$documentObject->params->set('access-report', $canReportDocument);
		$documentObject->params->set('access-contact', $canContactDocument);
		$documentObject->params->set('access-rate', $canRateDocument);
		$documentObject->params->set('access-download', $canDownloadDocument);
		$documentObject->params->set('access-comment', $canCommentDocument);

		$hasPassword = JUDownloadFrontHelperDocument::documentHasPassword($documentObject);
		$documentObject->params->set('has-password', $hasPassword);
		if ($hasPassword)
		{
			$validPassword = JUDownloadFrontHelperPassword::checkPassword($documentObject);
		}
		else
		{
			$validPassword = true;
		}

		$documentObject->params->set('valid-password', $validPassword);

		if ($canDownloadDocument && !$validPassword)
		{
			$documentObject->allow_enter_password = JUDownloadFrontHelperPassword::allowEnterPassword($documentObject->id);
		}

		$token                         = JSession::getFormToken();
		$return                        = base64_encode(urlencode(JUri::getInstance()));
		$documentObject->download_link = JRoute::_('index.php?option=com_judownload&task=download.download&doc_id=' . $documentObject->id . '&' . $token . '=1');
		$documentObject->download_link .= '&amp;return=' . $return;

		if ($params->get('show_rule_messages', 'modal') != 'hide')
		{
			$downloadRuleErrorMessages = JUDownloadFrontHelperDocument::getDownloadRuleErrorMessages($documentObject->id);
			if ($downloadRuleErrorMessages !== true)
			{
				$documentObject->error_msg = $downloadRuleErrorMessages;
			}
		}

		$documentObject->template_params = new JRegistry($documentObject->template_params);

		
		if ($params->get('show_new_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->publish_up, $params->get('num_day_to_show_as_new', 10)))
		{
			$documentObject->label_new = true;
		}
		else
		{
			$documentObject->label_new = false;
		}

		
		if ($params->get('show_updated_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->updated, $params->get('num_day_to_show_as_updated', 10)))
		{
			$documentObject->label_updated = true;
		}
		else
		{
			$documentObject->label_updated = false;
		}

		
		if ($params->get('show_hot_label', 1) && JUDownloadFrontHelperDocument::checkHotDocument($documentObject->publish_up, $params->get('num_download_per_day_to_be_hot', 10), $documentObject->downloads))
		{
			$documentObject->label_hot = true;
		}
		else
		{
			$documentObject->label_hot = false;
		}

		
		if ($params->get('show_featured_label', 1) && $documentObject->featured)
		{
			$documentObject->label_featured = true;
		}
		else
		{
			$documentObject->label_featured = false;
		}

		
		$documentObject->next_item     = $this->getNextPrevItem($documentObject, 'next');
		$documentObject->prev_item     = $this->getNextPrevItem($documentObject, 'prev');
		$documentObject->is_subscriber = $this->isSubscriber($user->id, $documentObject->id, 'document');

		return $documentObject;
	}
예제 #2
0
	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];
	}
예제 #3
0
	public static function appendDataToDocumentObjList(&$documentObjectList, $params, $usingForMod = false)
	{
		if (is_array($documentObjectList) && count($documentObjectList))
		{
			$user   = JFactory::getUser();
			$token  = JSession::getFormToken();
			$return = base64_encode(urlencode(JUri::getInstance()));

			foreach ($documentObjectList AS $documentObject)
			{
				
				JUDownloadHelper::getDocumentById($documentObject->id, false, $documentObject);

				$documentObject->params = JUDownloadFrontHelperDocument::getDocumentDisplayParams($documentObject->id);

				if (!isset($documentObject->total_files))
				{
					$documentObject->total_files = JUDownloadFrontHelperDocument::getTotalPublishedFilesOfDocument($documentObject->id);
				}

				
				if (!$user->get('guest'))
				{
					$canEditDocument      = JUDownloadFrontHelperPermission::canEditDocument($documentObject->id);
					$canEditStateDocument = JUDownloadFrontHelperPermission::canEditStateDocument($documentObject);
					$canDeleteDocument    = JUDownloadFrontHelperPermission::canDeleteDocument($documentObject->id);
					$documentObject->params->set('access-edit', $canEditDocument);
					$documentObject->params->set('access-edit-state', $canEditStateDocument);
					$documentObject->params->set('access-delete', $canDeleteDocument);
				}

				
				if ($params->get('show_report_btn_in_listview', 1) || $usingForMod)
				{
					$canReportDocument = JUDownloadFrontHelperPermission::canReportDocument($documentObject->id);
					$documentObject->params->set('access-report', $canReportDocument);
				}

				if ($params->get('show_download_btn_in_listview', 1) || $usingForMod)
				{
					$canDownloadDocument = JUDownloadFrontHelperPermission::canDownloadDocument($documentObject->id, false);
					$documentObject->params->set('access-download', $canDownloadDocument);

					$hasPassword = JUDownloadFrontHelperDocument::documentHasPassword($documentObject);
					$documentObject->params->set('has-password', $hasPassword);

					if ($hasPassword)
					{
						$validPassword = JUDownloadFrontHelperPassword::checkPassword($documentObject);
					}
					else
					{
						$validPassword = true;
					}

					$documentObject->params->set('valid-password', $validPassword);

					if ($canDownloadDocument && !$validPassword)
					{
						$documentObject->allow_enter_password = JUDownloadFrontHelperPassword::allowEnterPassword($documentObject->id);
					}

					$documentObject->download_link = JRoute::_('index.php?option=com_judownload&task=download.download&doc_id=' . $documentObject->id . '&' . $token . '=1');
					$documentObject->download_link .= '&amp;return=' . $return;

					if ($params->get('show_rule_messages', 'modal') != 'hide')
					{
						$downloadRuleErrorMessages = JUDownloadFrontHelperDocument::getDownloadRuleErrorMessages($documentObject->id);
						if ($downloadRuleErrorMessages !== true)
						{
							$documentObject->error_msg = $downloadRuleErrorMessages;
						}
					}
				}

				
				if ($documentObject->published != 1)
				{
					$documentObject->label_unpublished = true;
				}
				else
				{
					$documentObject->label_unpublished = false;
				}

				
				$documentObject->label_pending = false;
				$nowDate                       = JFactory::getDate()->toSql();
				if (intval($documentObject->publish_up) > 0)
				{
					if (strtotime($documentObject->publish_up) > strtotime($nowDate))
					{
						$documentObject->label_pending = true;
					}
				}

				
				$documentObject->label_expired = false;
				if (intval($documentObject->publish_down) > 0)
				{
					if (intval($documentObject->publish_up) > 0)
					{
						if (strtotime($documentObject->publish_up) <= strtotime($nowDate))
						{
							if (strtotime($documentObject->publish_down) < strtotime($nowDate))
							{
								$documentObject->label_expired = true;
							}
						}
					}
					else
					{
						if (strtotime($documentObject->publish_down) < strtotime($nowDate))
						{
							$documentObject->label_expired = true;
						}
					}
				}

				
				if ($params->get('show_new_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->publish_up, $params->get('num_day_to_show_as_new', 10)))
				{
					$documentObject->label_new = true;
				}
				else
				{
					$documentObject->label_new = false;
				}

				
				if ($params->get('show_updated_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->updated, $params->get('num_day_to_show_as_updated', 10)))
				{
					$documentObject->label_updated = true;
				}
				else
				{
					$documentObject->label_updated = false;
				}

				
				if ($params->get('show_hot_label', 1) && JUDownloadFrontHelperDocument::checkHotDocument($documentObject->publish_up, $params->get('num_download_per_day_to_be_hot', 10), $documentObject->downloads))
				{
					$documentObject->label_hot = true;
				}
				else
				{
					$documentObject->label_hot = false;
				}

				
				if ($params->get('show_featured_label', 1) && $documentObject->featured)
				{
					$documentObject->label_featured = true;
				}
				else
				{
					$documentObject->label_featured = false;
				}
			}
		}
	}
예제 #4
0
	public function getAlert()
	{
		$app        = JFactory::getApplication();
		$documentId = $app->input->post->getInt('doc_id', 0);
		
		if ($documentId > 0)
		{
			
			$session = JFactory::getSession();

			
			$timeNow      = JFactory::getDate()->toSql();
			$timeNowStamp = strtotime($timeNow);

			
			$params                 = JUDownloadHelper::getParams(null, $documentId);
			$blockEnterPasswordTime = $params->get('block_enter_password_time', 600);
			$maxWrongPasswordTimes  = $params->get('max_wrong_password_times', 5);

			
			$ss_wrongPasswordTimes = 'judl-wrong-password-' . $documentId;
			$ss_blockDownloadTime  = 'judl-block-download-time-' . $documentId;

			
			$wrongPasswordTimes = $session->get($ss_wrongPasswordTimes, 0);

			$documentObject = JUDownloadHelper::getDocumentById($documentId);
			$error          = false;
			
			if (!is_object($documentObject))
			{
				$error = true;
			}

			
			$documentHasPassword = JUDownloadFrontHelperDocument::documentHasPassword($documentObject);
			if (!$documentHasPassword)
			{
				$error = true;
			}

			
			if ($error)
			{
				$html = '<div class="alert alert-error">';
				$html .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
				$html .= JText::_('COM_JUDOWNLOAD_INVALID_DOCUMENT');
				$html .= '</div>';
				JUDownloadHelper::obCleanData();
				echo $html;
				exit;
			}

			$checkPasswordStatus = true;

			if ($maxWrongPasswordTimes < 1)
			{
				$maxWrongPasswordTimes = 1;
			}

			
			if ($wrongPasswordTimes >= $maxWrongPasswordTimes)
			{
				if ($blockEnterPasswordTime == 0)
				{
					
					$checkPasswordStatus = false;
				}
				else
				{
					$lastTime = $session->get($ss_blockDownloadTime, 0);
					$interval = $timeNowStamp - $lastTime;
					if ($interval >= 0)
					{
						if ($interval <= $blockEnterPasswordTime)
						{
							$checkPasswordStatus = false;
						}
						else
						{
							
							$session->clear($ss_wrongPasswordTimes);
							$session->clear($ss_blockDownloadTime);
							$checkPasswordStatus = true;
						}
					}
					else
					{
						
						$session->clear($ss_wrongPasswordTimes);
						$session->clear($ss_blockDownloadTime);
						$checkPasswordStatus = true;
					}
				}
			}
			elseif ($wrongPasswordTimes > 0)
			{
				$checkPasswordStatus = false;
			}

			if ($checkPasswordStatus)
			{
				
				$html = '<div class="alert alert-info">';
				$html .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
				$html .= JText::_('COM_JUDOWNLOAD_PLEASE_ENTER_PASSWORD_TO_DOWNLOAD_DOCUMENT');
				$html .= '</div>';
			}
			else
			{
				
				$html = '<div class="alert alert-error">';
				$html .= '<button type="button" class="close" data-dismiss="alert">&times;</button>';
				$html .= JText::plural('COM_JUDOWNLOAD_YOU_HAVE_ENTERED_WRONG_PASSWORD_N_TIME', $wrongPasswordTimes);
				$html .= '<br/>' . JText::plural('COM_JUDOWNLOAD_YOU_WILL_BE_LOCKED_OUT_AFTER_N_FAILED_ATTEMPT', $maxWrongPasswordTimes);
				$html .= '</div>';
			}

			JUDownloadHelper::obCleanData();
			echo $html;
			exit;
		}
	}