Пример #1
0
	public function display($tpl = null)
	{
		$app        = JFactory::getApplication();
		$categoryId = $app->input->getInt('id', 1);

		
		$this->category = JUDownloadFrontHelperCategory::getCategory($categoryId);

		
		$error = array();
		if (!JUDownloadFrontHelperPermission::canDoCategory($this->category->id, true, $error))
		{
			$user = JFactory::getUser();
			if ($user->id)
			{
				return JError::raiseError($error['code'], $error['message']);
			}
			else
			{
				$uri      = JUri::getInstance();
				$loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false);
				$app      = JFactory::getApplication();
				$app->redirect($loginUrl, JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning');

				return false;
			}
		}

		
		$model        = $this->getModel();
		$this->model  = $model;
		$this->state  = $this->get('State');
		$this->params = $this->state->params;

		
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseError(500, implode("\n", $errors));

			return false;
		}

		
		$this->parent_id = $this->category->id;

		
		$this->subcategory_level = (int) $this->params->get('all_categories_subcategory_level', -1);

		
		$this->all_categories = $model->getCategoriesRecursive($this->category->id, $this->subcategory_level);

		
		$firstCategory                = $this->all_categories[0];
		$this->category->total_childs = $firstCategory->total_childs;

		
		$this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx'));

		$this->_prepareDocument();

		$this->_setBreadcrumb();

		parent::display($tpl);
	}
Пример #2
0
	public function display($tpl = null)
	{
		
		$model               = $this->getModel();
		$this->model         = $model;
		$this->state         = $this->get('State');
		$params              = $this->state->params;
		$this->params        = $params;
		$this->token         = JSession::getFormToken();
		$this->root_category = JUDownloadFrontHelperCategory::getRootCategory();
		$categoryId          = $this->state->get('category.id', $this->root_category->id);

		
		if (count($errors = $this->get('Errors')))
		{
			JError::raiseWarning(500, implode("\n", $errors));

			return false;
		}

		
		$error = array();
		if (!JUDownloadFrontHelperPermission::canDoCategory($categoryId, true, $error))
		{
			$user = JFactory::getUser();
			if ($user->id)
			{
				return JError::raiseError($error['code'], $error['message']);
			}
			else
			{
				$uri      = JUri::getInstance();
				$loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false);
				$app      = JFactory::getApplication();
				$app->redirect($loginUrl, JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning');

				return false;
			}
		}

		
		$topLevelCats = JUDownloadHelper::getCatsByLevel(1, $categoryId);
		if (is_array($topLevelCats) && count($topLevelCats) > 0)
		{
			$this->tl_catid = $topLevelCats[0]->id;
		}

		
		$this->category = JUDownloadFrontHelperCategory::getCategory($categoryId);

		
		$this->show_feed = JUDLPROVERSION ? $this->params->get('rss_display_icon', 1) : 0;
		$this->rss_link  = JRoute::_(JUDownloadHelperRoute::getCategoryRoute($this->category->id, null, true));

		
		if (isset($this->category->images) && !empty($this->category->images) && !empty($this->category->images->detail_image))
		{
			$this->category->images->detail_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judownload/images/category/detail/', true) . $this->category->images->detail_image;
		}
		$this->category->images->detail_image_width  = (int) $this->params->get('category_image_width', 200);
		$this->category->images->detail_image_height = (int) $this->params->get('category_image_height', 200);

		
		if ($this->params->get('category_show_description', 1))
		{
			$this->category->description = $this->category->introtext . $this->category->fulltext;
		}
		else
		{
			$this->category->description = $this->category->fulltext;
		}

		
		$categoryDescLimit = (int) $this->params->get('category_desc_limit', 0);
		if ($categoryDescLimit > 0)
		{
			$this->category->description = JUDownloadFrontHelperString::truncateHtml($this->category->description, $categoryDescLimit);
		}

		
		if ($this->params->get('plugin_support', 0))
		{
			$this->category->description = JHtml::_('content.prepare', $this->category->description, '', 'com_judownload.category');
		}

		
		$this->category->class_sfx = htmlspecialchars($this->category->class_sfx);

		
		$relatedCatOrdering  = $this->params->get('related_category_ordering', 'crel.ordering');
		$relatedCatDirection = $this->params->get('related_category_direction', 'ASC');
		$this->related_cats  = $model->getRelatedCategories($this->category->id, $relatedCatOrdering, $relatedCatDirection);

		if (is_array($this->related_cats) && count($this->related_cats) > 0)
		{
			foreach ($this->related_cats AS $relatedCategory)
			{
				if (isset($relatedCategory->images->intro_image) && !empty($relatedCategory->images->intro_image))
				{
					$relatedCategory->images->intro_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/', true) . $relatedCategory->images->intro_image;
				}
				$relatedCategory->images->intro_image_width  = (int) $this->params->get('related_category_intro_image_width', 200);
				$relatedCategory->images->intro_image_height = (int) $this->params->get('related_category_intro_image_height', 200);

				if ($this->params->get('related_category_show_introtext', 1))
				{
					$relatedCategoryDescLimit = (int) $this->params->get('related_category_introtext_character_limit', 500);
					if ($relatedCategoryDescLimit > 0)
					{
						$relatedCategory->introtext = JUDownloadFrontHelperString::truncateHtml($relatedCategory->introtext, $relatedCategoryDescLimit);
					}

					if ($params->get('plugin_support', 0))
					{
						$relatedCategory->introtext = JHtml::_('content.prepare', $relatedCategory->introtext, '', 'com_judownload.category');
					}
				}
				else
				{
					$relatedCategory->introtext = '';
				}
			}
		}

		
		$subCatOrdering      = $this->params->get('subcategory_ordering', 'title');
		$subCatDirection     = $this->params->get('subcategory_direction', 'ASC');
		$this->subcategories = $model->getSubCategories($this->category->id, $subCatOrdering, $subCatDirection);

		if (is_array($this->subcategories) && count($this->subcategories) > 0)
		{
			foreach ($this->subcategories AS $subCategory)
			{
				if (isset($subCategory->images->intro_image) && !empty($subCategory->images->intro_image))
				{
					$subCategory->images->intro_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/', true) . $subCategory->images->intro_image;
				}
				$subCategory->images->intro_image_width  = (int) $this->params->get('subcategory_intro_image_width', 200);
				$subCategory->images->intro_image_height = (int) $this->params->get('subcategory_intro_image_height', 200);

				if ($this->params->get('subcategory_show_introtext', 1))
				{
					$subCategoryDescLimit = (int) $this->params->get('subcategory_introtext_character_limit', 500);
					if ($subCategoryDescLimit > 0)
					{
						$subCategory->introtext = JUDownloadFrontHelperString::truncateHtml($subCategory->introtext, $subCategoryDescLimit);
					}
					if ($this->params->get('plugin_support', 0))
					{
						$subCategory->introtext = JHtml::_('content.prepare', $subCategory->introtext, '', 'com_judownload.category');
					}
				}
				else
				{
					$subCategory->introtext = '';
				}
			}
		}

		$this->category->can_submit_doc = JUDownloadFrontHelperPermission::canSubmitDocument($this->category->id);
		if ($this->category->can_submit_doc && $this->params->get('show_submit_document_btn_in_category', 1))
		{
			$this->category->submit_doc_link = JUDownloadFrontHelperDocument::getAddDocumentLink($this->category->id);
		}

		
		$this->items = array();

		
		if ($this->category->show_item)
		{
			$user        = JFactory::getUser();
			$uri         = JUri::getInstance();
			$this->items = $this->get('Items');
			foreach ($this->items as $item)
			{
				$documentItemid = JUDownloadHelperRoute::findItemIdOfDocument($item->id);

				$item->report_link = JRoute::_(JUDownloadHelperRoute::getReportDocumentRoute($item->id));

				
				if ($item->checked_out > 0 && $item->checked_out != $user->get('id'))
				{
					if (JUDownloadFrontHelperPermission::canCheckInDocument($item->id))
					{
						$item->checkin_link = JRoute::_('index.php?option=com_judownload&task=forms.checkin&id=' . $item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri)));
					}
				}
				else
				{
					$item->edit_link = JRoute::_('index.php?option=com_judownload&task=form.edit&id=' . $item->id . '&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id));

					if ($item->published == 1)
					{
						$item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.unpublish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id));
					}
					else
					{
						$item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.publish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id));
					}
				}

				$item->delete_link = JRoute::_('index.php?option=com_judownload&task=forms.delete&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id));

				$dispatcher = JDispatcher::getInstance();
				JPluginHelper::importPlugin('content');
				$item->event = new stdClass();
				$context     = 'com_judownload.document_list';

				$results                        = $dispatcher->trigger('onContentAfterTitle', array($context, &$item, &$item->params, 0));
				$item->event->afterDisplayTitle = trim(implode("\n", $results));

				$results                           = $dispatcher->trigger('onContentBeforeDisplay', array($context, &$item, &$item->params, 0));
				$item->event->beforeDisplayContent = trim(implode("\n", $results));

				$results                          = $dispatcher->trigger('onContentAfterDisplay', array($context, &$item, &$item->params, 0));
				$item->event->afterDisplayContent = trim(implode("\n", $results));
			}

			$this->pagination = $this->get('Pagination');
		}

		
		$this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx'));

		
		$this->_prepareData();

		$this->_prepareDocument();

		$this->_setBreadcrumb();

		parent::display($tpl);
	}
Пример #3
0
	public static function isDocumentPublished($documentId)
	{
		$documentObject = JUDownloadHelper::getDocumentById($documentId);
		if (!is_object($documentObject))
		{
			return false;
		}
		$catPublished = JUDownloadFrontHelperPermission::canDoCategory($documentObject->cat_id);
		if (!$catPublished)
		{
			return false;
		}

		$db       = JFactory::getDbo();
		$nullDate = $db->getNullDate();
		$nowDate  = JFactory::getDate()->toSql();

		$query = $db->getQuery(true);
		$query->select('COUNT(*)');
		$query->from('#__judownload_documents');
		
		$query->where('approved = 1');
		
		$query->where('published = 1');
		$query->where('(publish_up = ' . $db->quote($nullDate) . ' OR publish_up <= ' . $db->quote($nowDate) . ')');
		$query->where('(publish_down = ' . $db->quote($nullDate) . ' OR publish_down >= ' . $db->quote($nowDate) . ')');
		$query->where('id =' . $documentId);
		$db->setQuery($query);
		$result = $db->loadResult();

		if ($result)
		{
			return true;
		}

		return false;
	}
Пример #4
0
	public function getCatIdTree($catId, $includeItSelf = true)
	{
		$catId = (int) $catId;
		if (!$catId)
		{
			return null;
		}

		if (!JUDownloadFrontHelperPermission::canDoCategory($catId))
		{
			return null;
		}

		$cat_id_arr = array();

		if ($includeItSelf)
		{
			$cat_id_arr[] = $catId;
		}

		$db    = JFactory::getDbo();
		$query = "SELECT id FROM #__judownload_categories WHERE parent_id = " . $catId;
		$db->setQuery($query);
		$child_cat_ids = $db->loadColumn();

		foreach ($child_cat_ids AS $child_cat_id)
		{
			$cat_id_arr[]     = $child_cat_id;
			$child_cat_id_arr = $this->getCatIdTree($child_cat_id, false);

			if ($child_cat_id_arr)
			{
				$cat_id_arr = array_merge($cat_id_arr, $child_cat_id_arr);
			}
		}

		return array_unique($cat_id_arr);
	}
Пример #5
0
	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;
	}
Пример #6
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];
	}