Esempio n. 1
0
 protected function _getAssetParentId(JTable $table = null, $id = null)
 {
     $assetId = null;
     if (isset($this->cat_id) && $this->cat_id) {
         $cat_id = $this->cat_id;
     } elseif ($this->id) {
         $cat_id = JUDownloadHelper::getDocumentById($this->id)->cat_id;
     }
     if ($cat_id) {
         $query = $this->_db->getQuery(true);
         $query->select($this->_db->quoteName('asset_id'));
         $query->from($this->_db->quoteName('#__judownload_categories'));
         $query->where($this->_db->quoteName('id') . ' = ' . $cat_id);
         $this->_db->setQuery($query);
         if ($result = $this->_db->loadResult()) {
             $assetId = (int) $result;
         }
     }
     if ($assetId === null) {
         $query = $this->_db->getQuery(true);
         $query->select($this->_db->quoteName('id'));
         $query->from($this->_db->quoteName('#__assets'));
         $query->where($this->_db->quoteName('name') . ' = ' . $this->_db->quote('com_judownload'));
         $this->_db->setQuery($query);
         if ($result = $this->_db->loadResult()) {
             $assetId = (int) $result;
         }
     }
     if ($assetId) {
         return $assetId;
     } else {
         return parent::_getAssetParentId($table, $id);
     }
 }
Esempio n. 2
0
 public function back()
 {
     $app = JFactory::getApplication();
     $doc_id = $app->input->getInt('doc_id', 0);
     $cat_id = JUDownloadFrontHelperCategory::getRootCategory()->id;
     if ($doc_id) {
         $docObj = JUDownloadHelper::getDocumentById($doc_id);
         if (isset($docObj->cat_id) && $docObj->cat_id) {
             $cat_id = $docObj->cat_id;
         }
     }
     $this->setRedirect("index.php?option=com_judownload&view=listcats&cat_id={$cat_id}");
 }
 public function getInput()
 {
     $db = JFactory::getDbo();
     $groups = array();
     $app = JFactory::getApplication();
     $appendInherit = '';
     if ($app->input->get("view") == "document") {
         if ($this->form->getValue("id")) {
             $doc = JUDownloadHelper::getDocumentById($this->form->getValue("id"));
             $appendInherit = "(" . $this->calculatorInheritStyle($doc->cat_id) . ")";
         }
     } else {
         if ($this->form->getValue("parent_id")) {
             $appendInherit = "(" . $this->calculatorInheritStyle($this->form->getValue("parent_id")) . ")";
         }
     }
     $appendDefault = "(" . $this->getStyle() . ")";
     $groups['inherit'] = array();
     $groups['inherit']['id'] = $this->id . '_inherit';
     $groups['inherit']['text'] = '---' . JText::_('COM_JUDOWNLOAD_INHERIT') . '---';
     $groups['inherit']['items'] = array();
     $groups['inherit']['items'][] = JHtml::_('select.option', '-2', JText::_('COM_JUDOWNLOAD_DEFAULT') . ' ' . $appendDefault);
     $groups['inherit']['items'][] = JHtml::_('select.option', '-1', JText::_('COM_JUDOWNLOAD_INHERIT') . ' ' . $appendInherit);
     $query = $db->getQuery(true);
     $query->select('style.*');
     $query->select('plg.title AS template_title, plg.folder');
     $query->from('#__judownload_template_styles AS style');
     $query->join('', '#__judownload_templates AS tpl ON tpl.id = style.template_id');
     $query->join('', '#__judownload_plugins AS plg ON plg.id = tpl.plugin_id');
     $query->where('style.lft > 0');
     $query->order('style.lft ASC');
     $db->setQuery($query);
     $styles = $db->loadObjectList();
     for ($i = 0, $n = count($styles); $i < $n; $i++) {
         $styles[$i]->text = str_repeat('- ', $styles[$i]->level - 1) . $styles[$i]->title . " [ " . $styles[$i]->template_title . " ]";
     }
     $groups['style'] = array();
     $groups['style']['id'] = 'template_style';
     $groups['style']['text'] = JText::_('COM_JUDOWNLOAD_TEMPLATE_STYLES');
     $groups['style']['items'] = array();
     foreach ($styles as $style) {
         $groups['style']['items'][] = JHtml::_('select.option', $style->id, $style->text);
     }
     $html = JHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => "", 'list.select' => $this->value));
     return $html;
 }
Esempio n. 4
0
 public function display($tpl = null)
 {
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode('<br />', $errors));
         return false;
     }
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->model = $this->getModel();
     $this->app = JFactory::getApplication();
     $cat_id = $this->item->cat_id ? $this->item->cat_id : $this->app->input->get('cat_id');
     $this->params = JUDownloadHelper::getParams(null, $this->item->id);
     if ($cat_id == JUDownloadFrontHelperCategory::getRootCategory()->id && !$this->params->get('allow_add_doc_to_root', 0)) {
         JError::raiseError(500, JText::_('COM_JUDOWNLOAD_CAN_NOT_ADD_DOCUMENT_TO_ROOT_CATEGORY'));
         return false;
     }
     if ($tempDocument = JUDownloadHelper::getTempDocument($this->item->id)) {
         $editPendingDocLink = '<a href="index.php?option=com_judownload&task=document.edit&approve=1&id=' . $tempDocument->id . '">' . $tempDocument->title . '</a>';
         JError::raiseNotice('', JText::sprintf('COM_JUDOWNLOAD_THIS_DOCUMENT_HAS_PENDING_DOCUMENT_X_PLEASE_APPROVE_PENDING_DOCUMENT_FIRST', $editPendingDocLink));
     }
     if ($this->item->approved < 0) {
         $oriDocId = abs($this->item->approved);
         $oriDocObj = JUDownloadHelper::getDocumentById($oriDocId);
         $editOriDocLink = '<a href="index.php?option=com_judownload&task=document.edit&id=' . $oriDocId . '">' . $oriDocObj->title . '</a>';
         JError::raiseNotice('', JText::sprintf('COM_JUDOWNLOAD_ORIGINAL_DOCUMENT_X', $editOriDocLink));
     }
     $this->script = $this->get('Script');
     $this->plugins = $this->get('Plugins');
     $this->fieldsetDetails = $this->model->getCoreFields('details');
     $this->fieldsetPublishing = $this->model->getCoreFields('publishing');
     $this->fieldsetTemplateStyleAndLayout = $this->model->getCoreFields('template_style');
     $this->fieldsetMetadata = $this->model->getCoreFields('metadata');
     $this->fieldCatid = JUDownloadFrontHelperField::getField('cat_id', $this->item);
     $this->fieldGallery = JUDownloadFrontHelperField::getField('gallery', $this->item);
     $this->files = $this->get('Files');
     $this->changeLogs = $this->get('ChangeLogs');
     $this->versions = $this->get('Versions');
     $this->extraFields = $this->get('ExtraFields');
     $this->fieldsData = $this->app->getUserState("com_judownload.edit.document.fieldsdata", array());
     $this->relatedDocuments = $this->get('RelatedDocuments');
     $this->canDo = JUDownloadHelper::getActions('com_judownload', 'category', $this->item->cat_id);
     $this->addToolBar();
     $this->setDocument();
     parent::display($tpl);
 }
Esempio n. 5
0
 protected function getInput()
 {
     $hint = $this->translateHint ? JText::_($this->hint) : $this->hint;
     $size = !empty($this->size) ? ' size="' . $this->size . '"' : '';
     $maxLength = !empty($this->maxLength) ? ' maxlength="' . $this->maxLength . '"' : '';
     $class = !empty($this->class) ? ' class="' . $this->class . '"' : '';
     $readonly = $this->readonly ? ' readonly' : '';
     $disabled = $this->disabled ? ' disabled' : '';
     $required = $this->required ? ' required aria-required="true"' : '';
     $hint = $hint ? ' placeholder="' . $hint . '"' : '';
     $autocomplete = !$this->autocomplete ? ' autocomplete="off"' : ' autocomplete="' . $this->autocomplete . '"';
     $autocomplete = $autocomplete == ' autocomplete="on"' ? '' : $autocomplete;
     $autofocus = $this->autofocus ? ' autofocus' : '';
     $spellcheck = $this->spellcheck ? '' : ' spellcheck="false"';
     $pattern = !empty($this->pattern) ? ' pattern="' . $this->pattern . '"' : '';
     $inputmode = !empty($this->inputmode) ? ' inputmode="' . $this->inputmode . '"' : '';
     $dirname = !empty($this->dirname) ? ' dirname="' . $this->dirname . '"' : '';
     $onchange = !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : '';
     $documentObject = JUDownloadHelper::getDocumentById($this->value);
     $documentLink = JRoute::_('index.php?option=com_judownload&amp;task=document.edit&amp;id=' . $documentObject->id);
     $html[] = '<div class="btn"><a href="' . $documentLink . '" target="_blank">' . $documentObject->title . '</a></div>';
     $html[] = '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '"' . $dirname . ' value="' . htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8') . '"' . $class . $size . $disabled . $readonly . $hint . $onchange . $maxLength . $required . $autocomplete . $autofocus . $spellcheck . $inputmode . $pattern . ' />';
     return implode($html);
 }
Esempio n. 6
0
	public function parse(&$segments)
	{
		$total = count($segments);
		$vars  = array();

		for ($i = 0; $i < $total; $i++)
		{
			$segments[$i] = preg_replace('/:/', '-', $segments[$i], 1);
		}

		$params     = JUDownloadHelper::getParams();
		$app        = JFactory::getApplication('site');
		$menu       = $app->getMenu();
		$activeMenu = $menu->getActive();

		$indexLastSegment = $total - 1;
		$endSegment       = end($segments);

		
		$searchViewApproveComment = array_search(JApplication::stringURLSafe('mod-comment'), $segments);
		if ($searchViewApproveComment !== false)
		{
			$vars['view'] = 'modcomment';
			if (isset($segments[$searchViewApproveComment + 1]))
			{
				$vars['id'] = (int) $segments[$searchViewApproveComment + 1];
			}

			if (isset($segments[$searchViewApproveComment + 2]))
			{
				if ($segments[$searchViewApproveComment + 2] == JApplication::stringURLSafe('approve'))
				{
					$vars['approve'] = 1;
				}
			}

			$previousIndexSegment = $total - 1;

			if (isset($segments[$previousIndexSegment]))
			{
				$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				if ($isLayout)
				{
					$previousIndexSegment -= 1;
				}
			}

			return $vars;
		}

		
		if (isset($segments[0]) && $segments[0] == JApplication::stringURLSafe('comment'))
		{
			if (isset($segments[2]))
			{
				switch ($segments[2])
				{
					case JApplication::stringURLSafe('edit') :
						$vars['task'] = 'modcomment.edit';
						if (isset($segments[1]))
						{
							$vars['id'] = (int) $segments[1];
						}
						break;
					case JApplication::stringURLSafe('approve') :
						$vars['task'] = 'modpendingcomment.edit';
						if (isset($segments[1]))
						{
							$vars['id'] = (int) $segments[1];
						}
						break;
					case JApplication::stringURLSafe('subscribe') :
						$vars['task'] = 'subscribe.save';
						if (isset($segments[1]))
						{
							$vars['comment_id'] = (int) $segments[1];
						}
						break;
					case JApplication::stringURLSafe('unsubscribe') :
						$vars['task'] = 'subscribe.remove';
						if (isset($segments[3]))
						{
							$vars['sub_id'] = (int) $segments[3];
						}
						if (isset($segments[4]))
						{
							$vars['code'] = $segments[4];
						}
						break;
					case JApplication::stringURLSafe('delete') :
						$vars['task'] = 'document.deleteComment';
						if (isset($segments[1]))
						{
							$vars['comment_id'] = (int) $segments[1];
						}
						break;
					default :
						break;
				}

				if (isset($vars['task']))
				{
					return $vars;
				}
			}
		}

		
		$searchViewReportComment = array_search(JApplication::stringURLSafe('comment'), $segments);
		if ($searchViewReportComment !== false)
		{
			
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewReportComment, $validArrayIndex))
			{
				if (isset($segments[$searchViewReportComment + 2]))
				{
					if ($segments[$searchViewReportComment + 2] == JApplication::stringURLSafe('report'))
					{
						$vars['view'] = 'report';
						if (isset($segments[$searchViewReportComment + 1]))
						{
							$vars['comment_id'] = (int) $segments[$searchViewReportComment + 1];
						}

						$previousIndexSegment = $total - 1;

						if (isset($segments[$previousIndexSegment]))
						{
							$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
							if ($isLayout)
							{
								$previousIndexSegment -= 1;
							}
						}

						return $vars;
					}
				}
			}
		}

		
		$searchViewModeratorPermission = array_search(JApplication::stringURLSafe('mod-permission'), $segments);
		if ($searchViewModeratorPermission !== false)
		{
			
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewModeratorPermission, $validArrayIndex))
			{
				$vars['view'] = 'modpermission';
				if (isset($segments[$searchViewModeratorPermission + 1]))
				{
					$vars['id'] = (int) $segments[$searchViewModeratorPermission + 1];
				}

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		if (isset($segments[0]) && $segments[0] == JApplication::stringURLSafe('user-subscriptions'))
		{
			if (isset($segments[2]))
			{
				if ($segments[2] == JApplication::stringURLSafe('unsubscribe'))
				{
					$vars['task'] = 'usersubscriptions.unsubscribe';
					if (isset($segments[1]))
					{
						$vars['sub_id'] = (int) $segments[1];
					}

					return $vars;
				}
			}
		}

		
		if (isset($segments[0]) && $segments[0] == JApplication::stringURLSafe('email'))
		{
			if (isset($segments[1]) && $segments[1] == JApplication::stringURLSafe('download-attachment'))
			{
				$vars['task'] = 'email.downloadattachment';

				if (isset($segments[2]))
				{
					$vars['mail_id'] = (int) $segments[2];
				}

				if (isset($segments[3]))
				{
					$vars['file'] = $segments[3];
				}

				if (isset($segments[4]))
				{
					$vars['code'] = $segments[4];
				}

			}

			return $vars;
		}

		
		$searchViewModeratorPermissions = array_search(JApplication::stringURLSafe('mod-permissions'), $segments);
		if ($searchViewModeratorPermissions !== false)
		{
			
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewModeratorPermissions, $validArrayIndex))
			{
				$vars['view'] = 'modpermissions';

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewProfile = array_search(JApplication::stringURLSafe('profile'), $segments);
		if ($searchViewProfile !== false)
		{
			
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewProfile, $validArrayIndex))
			{
				$vars['view'] = 'profile';

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewModeratorPendingDocuments = array_search(JApplication::stringURLSafe('mod-pending-documents'), $segments);
		if ($searchViewModeratorPendingDocuments !== false)
		{
			
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewModeratorPendingDocuments, $validArrayIndex))
			{
				$vars['view'] = 'modpendingdocuments';

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewModeratorPendingComments = array_search(JApplication::stringURLSafe('mod-pending-comments'), $segments);
		if ($searchViewModeratorPendingComments !== false)
		{
			
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewModeratorPendingComments, $validArrayIndex))
			{
				$vars['view'] = 'modpendingcomments';

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewModeratorComments = array_search(JApplication::stringURLSafe('mod-comments'), $segments);
		if ($searchViewModeratorComments !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewModeratorComments, $validArrayIndex))
			{
				$vars['view'] = 'modcomments';

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewModeratorDocuments = array_search(JApplication::stringURLSafe('mod-documents'), $segments);
		if ($searchViewModeratorDocuments !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewModeratorDocuments, $validArrayIndex))
			{
				$vars['view'] = 'moddocuments';

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		if (isset($segments[0]) && $segments[0] == JApplication::stringURLSafe('subscribe'))
		{
			if (isset($segments[1]) && $segments[1] == JApplication::stringURLSafe('activate'))
			{
				$vars['task'] = 'subscribe.activate';

				if (isset($segments[2]))
				{
					$vars['code'] = $segments[2];
				}

				if (isset($segments[3]))
				{
					$vars['id'] = (int) $segments[3];
				}

				if (isset($segments[4]))
				{
					$vars['doc_id'] = (int) $segments[4];
				}

				return $vars;
			}
		}

		
		$searchViewSearch = array_search(JApplication::stringURLSafe('search'), $segments);
		if ($searchViewSearch !== false)
		{
			$validArrayIndex = array(0, 1, 2, 3);
			if (in_array($searchViewSearch, $validArrayIndex))
			{
				$vars['view'] = 'search';

				if (isset($segments[$searchViewSearch - 1]))
				{
					if ($segments[$searchViewSearch - 1] == JApplication::stringURLSafe('all'))
					{
						$vars['sub_cat'] = 1;
						if (isset($segments[$searchViewSearch - 2]))
						{
							$vars['cat_id'] = (int) $segments[$searchViewSearch - 2];
						}
					}
					else
					{
						$vars['cat_id'] = (int) $segments[$searchViewSearch - 1];
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]) && $previousIndexSegment > $searchViewSearch)
				{
					$vars['searchword'] = $segments[$previousIndexSegment];
					$previousIndexSegment -= 1;
				}

				return $vars;
			}
		}

		
		$searchViewCategories = array_search(JApplication::stringURLSafe('categories'), $segments);
		if ($searchViewCategories !== false)
		{
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewCategories, $validArrayIndex))
			{
				$vars['view'] = 'categories';
				if (isset($segments[$searchViewCategories + 1]))
				{
					$vars['id'] = (int) $segments[$searchViewCategories + 1];
				}

				if (isset($segments[$searchViewCategories + 2]))
				{
					JUDownloadHelperRoute::parseLayout($segments[$searchViewCategories + 2], $vars, $params);
				}

				return $vars;
			}
		}

		
		$searchViewAdvancedSearch = array_search(JApplication::stringURLSafe('advanced-search'), $segments);
		if ($searchViewAdvancedSearch !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewAdvancedSearch, $validArrayIndex))
			{
				$vars['view'] = 'advsearch';

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewCommentTree = array_search(JApplication::stringURLSafe('comment-tree'), $segments);
		if ($searchViewCommentTree !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewCommentTree, $validArrayIndex))
			{
				$vars['view'] = 'commenttree';

				if (isset($segments[$searchViewCommentTree + 1]))
				{
					$vars['id'] = (int) $segments[$searchViewCommentTree + 1];
				}

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewDocuments = array_search(JApplication::stringURLSafe('modal-documents'), $segments);
		if ($searchViewDocuments !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewDocuments, $validArrayIndex))
			{
				$vars['view'] = 'documents';

				if (isset($segments[$searchViewDocuments + 1]))
				{
					$vars['tmpl'] = $segments[$searchViewDocuments + 1];
				}

				if (isset($segments[$searchViewDocuments + 2]))
				{
					$vars['function'] = $segments[$searchViewDocuments + 2];
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewDownloadError = array_search(JApplication::stringURLSafe('error-download'), $segments);
		if ($searchViewDownloadError !== false)
		{
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewDownloadError, $validArrayIndex))
			{
				$vars['view'] = 'downloaderror';

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]) && $previousIndexSegment > $searchViewDownloadError)
				{
					$vars['return'] = $segments[$previousIndexSegment];
				}

				return $vars;
			}
		}

		
		$searchViewLicense = array_search(JApplication::stringURLSafe('license'), $segments);
		if ($searchViewLicense !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewLicense, $validArrayIndex))
			{
				$vars['view'] = 'license';
				if (isset($segments[$searchViewLicense + 1]))
				{
					$vars['id'] = (int) $segments[$searchViewLicense + 1];
				}

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewMaintenance = array_search(JApplication::stringURLSafe('maintenance'), $segments);
		if ($searchViewMaintenance !== false)
		{
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewMaintenance, $validArrayIndex))
			{
				$vars['view'] = 'maintenance';

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewSearchBy = array_search(JApplication::stringURLSafe('search-by'), $segments);
		if ($searchViewSearchBy !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewSearchBy, $validArrayIndex))
			{
				$vars['view'] = 'searchby';

				if (isset($segments[$searchViewSearchBy + 1]))
				{
					$vars['field_id'] = (int) $segments[$searchViewSearchBy + 1];
				}

				if (isset($segments[$searchViewSearchBy + 2]))
				{
					$vars['value'] = $segments[$searchViewSearchBy + 2];
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewTag = array_search(JApplication::stringURLSafe('tag'), $segments);
		if ($searchViewTag !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchViewTag, $validArrayIndex))
			{
				$vars['view'] = 'tag';

				if (isset($segments[$searchViewTag + 1]))
				{
					$vars['id'] = (int) $segments[$searchViewTag + 1];
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewTags = array_search(JApplication::stringURLSafe('tags'), $segments);
		if ($searchViewTags !== false)
		{
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewTags, $validArrayIndex))
			{
				$vars['view'] = 'tags';

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewTopComments = array_search(JApplication::stringURLSafe('top-comments'), $segments);
		if ($searchViewTopComments !== false)
		{
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewTopComments, $validArrayIndex))
			{
				$vars['view'] = 'topcomments';

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchViewTree = array_search(JApplication::stringURLSafe('tree'), $segments);
		if ($searchViewTree !== false)
		{
			$validArrayIndex = array(0, 1);
			if (in_array($searchViewTree, $validArrayIndex))
			{
				$vars['view']         = 'tree';
				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('root'))
					{
						$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
						$vars['id']   = $rootCategory->id;
					}
					else
					{
						$vars['id'] = (int) $segments[$previousIndexSegment];
					}
					$previousIndexSegment -= 1;
				}
				else
				{
					if ($activeMenu && isset($activeMenu->query) && isset($activeMenu->query['view']) && isset($activeMenu->query['id']) &&
						$activeMenu->query['view'] == 'tree'
					)
					{
						$vars['id'] = $activeMenu->query['id'];
					}
				}

				return $vars;
			}
		}

		
		$orderTypeTopDocuments = array();
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('latest-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('top-featured-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('recent-modified-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('recent-updated-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('popular-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('most-downloaded-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('most-rated-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('top-rated-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('latest-rated-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('most-commented-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('latest-commented-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('recent-viewed-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('alpha-ordered-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('random-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('random-fast-documents');
		
		$orderTypeTopDocuments[] = JApplication::stringURLSafe('random-featured-documents');

		if (!empty($orderTypeTopDocuments))
		{
			foreach ($orderTypeTopDocuments as $orderTypeTopDocumentItem)
			{
				$searchViewTopDocuments = array_search($orderTypeTopDocumentItem, $segments);
				if ($searchViewTopDocuments !== false)
				{
					break;
				}
			}

			if ($searchViewTopDocuments !== false)
			{
				$validArrayIndex = array(0, 1, 2);
				if (in_array($searchViewTopDocuments, $validArrayIndex))
				{
					$vars['view'] = 'topdocuments';

					switch ($segments[$searchViewTopDocuments])
					{
						case JApplication::stringURLSafe('latest-documents'):
							$vars['ordertype'] = 'new';
							break;
						case JApplication::stringURLSafe('top-featured-documents'):
							$vars['ordertype'] = 'featured';
							break;
						case JApplication::stringURLSafe('recent-modified-documents'):
							$vars['ordertype'] = 'recent_modified';
							break;
						case JApplication::stringURLSafe('recent-updated-documents'):
							$vars['ordertype'] = 'recent_updated';
							break;
						case JApplication::stringURLSafe('popular-documents'):
							$vars['ordertype'] = 'popular';
							break;
						case JApplication::stringURLSafe('most-downloaded-documents'):
							$vars['ordertype'] = 'most_downloaded';
							break;
						case JApplication::stringURLSafe('most-rated-documents'):
							$vars['ordertype'] = 'most_rated';
							break;
						case JApplication::stringURLSafe('top-rated-documents'):
							$vars['ordertype'] = 'top_rated';
							break;
						case JApplication::stringURLSafe('latest-rated-documents'):
							$vars['ordertype'] = 'latest_rated';
							break;
						case JApplication::stringURLSafe('most-commented-documents'):
							$vars['ordertype'] = 'most_commented';
							break;
						case JApplication::stringURLSafe('latest-commented-documents'):
							$vars['ordertype'] = 'latest_commented';
							break;
						case JApplication::stringURLSafe('recent-viewed-documents'):
							$vars['ordertype'] = 'recently_viewed';
							break;
						case JApplication::stringURLSafe('alpha-ordered-documents'):
							$vars['ordertype'] = 'alpha_ordered';
							break;
						case JApplication::stringURLSafe('random-documents'):
							$vars['ordertype'] = 'random';
							break;
						case JApplication::stringURLSafe('random-fast-documents'):
							$vars['ordertype'] = 'random_fast';
							break;
						case JApplication::stringURLSafe('random-featured-documents'):
							$vars['ordertype'] = 'random_featured';
							break;
						default:
							$vars['ordertype'] = 'new';
							break;
					}

					if (isset($segments[$searchViewTopDocuments - 1]))
					{
						if ($segments[$searchViewTopDocuments - 1] == JApplication::stringURLSafe('root'))
						{
							$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
							$vars['id']   = $rootCategory->id;
						}
						else
						{
							$vars['id'] = (int) $segments[$searchViewTopDocuments - 1];
						}
					}
					else
					{
						if ($activeMenu && isset($activeMenu->query) && isset($activeMenu->query['view']) && isset($activeMenu->query['id']) &&
							$activeMenu->query['view'] == 'tree'
						)
						{
							$vars['id'] = $activeMenu->query['id'];
						}
					}

					if (isset($segments[$searchViewTopDocuments + 1]))
					{
						if ($segments[$searchViewTopDocuments + 1] == JApplication::stringURLSafe('all'))
						{
							$vars['all'] = 1;
						}
					}

					$previousIndexSegment = $total - 1;

					$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
					if ($isPaged)
					{
						$previousIndexSegment -= 1;
					}

					if (isset($segments[$previousIndexSegment]))
					{
						if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
						{
							$vars['format'] = 'feed';
							$previousIndexSegment -= 1;
						}
					}

					if (isset($segments[$previousIndexSegment]))
					{
						$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
						if ($isLayout)
						{
							$previousIndexSegment -= 1;
						}
					}

					return $vars;
				}
			}
		}

		
		$searchSefRedirectUrl = array_search(JApplication::stringURLSafe('redirect-url'), $segments);
		if ($searchSefRedirectUrl !== false)
		{
			$vars['task'] = 'document.redirecturl';
			if (isset($segments[$searchSefRedirectUrl - 1]))
			{
				$vars['field_id'] = (int) $segments[$searchSefRedirectUrl - 1];
			}

			if (isset($segments[$searchSefRedirectUrl - 2]))
			{
				$vars['doc_id'] = (int) $segments[$searchSefRedirectUrl - 2];
			}

			return $vars;
		}

		
		$searchSefTaskRawData = array_search(JApplication::stringURLSafe('raw-data'), $segments);
		if ($searchSefTaskRawData !== false)
		{
			$vars['task'] = 'rawdata';

			if (isset($segments[$searchSefTaskRawData - 1]))
			{
				$vars['field_id'] = (int) $segments[$searchSefTaskRawData - 1];
			}

			if (isset($segments[$searchSefTaskRawData - 2]))
			{
				$vars['doc_id'] = (int) $segments[$searchSefTaskRawData - 2];
			}

			return $vars;
		}

		$searchSefCollection = array_search(JApplication::stringURLSafe('collection'), $segments);
		if ($searchSefCollection !== false)
		{
			if (isset($segments[$searchSefCollection + 1]))
			{
				if ($segments[$searchSefCollection + 1] == JApplication::stringURLSafe('add'))
				{
					$vars['task'] = 'collection.add';

					return $vars;
				}
			}
		}

		$searchSefCollection = array_search(JApplication::stringURLSafe('collection'), $segments);
		if ($searchSefCollection !== false)
		{
			if (isset($segments[$searchSefCollection + 2]))
			{
				if ($segments[$searchSefCollection + 2] == JApplication::stringURLSafe('edit'))
				{
					if (isset($segments[$searchSefCollection - 1]))
					{
						$vars['user_id'] = (int) $segments[$searchSefCollection - 1];
					}
					$vars['id']   = (int) $segments[$searchSefCollection + 1];
					$vars['task'] = 'collection.edit';

					return $vars;
				}
			}
		}

		$searchSefCollection = array_search(JApplication::stringURLSafe('collection'), $segments);
		if ($searchSefCollection !== false)
		{
			if (isset($segments[$searchSefCollection + 2]))
			{
				if ($segments[$searchSefCollection + 2] == JApplication::stringURLSafe('delete'))
				{
					$vars['cid']  = (int) $segments[$searchSefCollection + 1];
					$vars['task'] = 'collections.delete';

					return $vars;
				}
			}
		}

		$searchSefCollection = array_search(JApplication::stringURLSafe('collection'), $segments);
		if ($searchSefCollection !== false)
		{
			if (isset($segments[$searchSefCollection + 1]))
			{
				if ($segments[$searchSefCollection + 1] == JApplication::stringURLSafe('new-collection'))
				{
					$vars['id']   = 0;
					$vars['view'] = 'collection';
					JUDownloadHelperRoute::parseLayout($segments[$searchSefCollection + 2], $vars, $params);

					return $vars;
				}
			}
		}

		$searchSefCollection = array_search(JApplication::stringURLSafe('collection'), $segments);
		if ($searchSefCollection !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefCollection, $validArrayIndex))
			{
				$vars['view'] = 'collection';
				if (isset($segments[$searchSefCollection - 1]))
				{
					if ($segments[$searchSefCollection - 1] != 'root')
					{
						$vars['user_id'] = (int) $segments[$searchSefCollection - 1];
					}
				}

				if (isset($segments[$searchSefCollection + 1]))
				{
					$vars['id'] = (int) $segments[$searchSefCollection + 1];
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchSefReportDocument = array_search(JApplication::stringURLSafe('report'), $segments);
		if ($searchSefReportDocument !== false)
		{
			$vars['view'] = 'report';
			if (isset($segments[$searchSefReportDocument - 1]))
			{
				$vars['doc_id'] = (int) $segments[$searchSefReportDocument - 1];
			}

			$previousIndexSegment = $total - 1;

			if (isset($segments[$previousIndexSegment]))
			{
				$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				if ($isLayout)
				{
					$previousIndexSegment -= 1;
				}
			}

			return $vars;
		}

		
		$searchSefSubscribeDocumentForGuest = array_search(JApplication::stringURLSafe('guest-subscribe'), $segments);
		if ($searchSefSubscribeDocumentForGuest !== false)
		{
			$vars['view'] = 'subscribe';
			if (isset($segments[$searchSefSubscribeDocumentForGuest - 1]))
			{
				$vars['doc_id'] = (int) $segments[$searchSefSubscribeDocumentForGuest - 1];
			}

			$previousIndexSegment = $total - 1;

			if (isset($segments[$previousIndexSegment]))
			{
				$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				if ($isLayout)
				{
					$previousIndexSegment -= 1;
				}
			}

			return $vars;
		}

		
		$searchSefListAll = array_search('list-all', $segments);
		if ($searchSefListAll !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefListAll, $validArrayIndex))
			{
				$vars['view'] = 'listall';
				if (isset($segments[$searchSefListAll - 1]))
				{
					if ($segments[$searchSefListAll - 1] == JApplication::stringURLSafe('root'))
					{
						$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
						$vars['id']   = $rootCategory->id;
					}
					else
					{
						$vars['id'] = (int) $segments[$searchSefListAll - 1];
					}
				}
				else
				{
					if ($activeMenu && isset($activeMenu->query) && isset($activeMenu->query['view']) && isset($activeMenu->query['id']) &&
						$activeMenu->query['view'] == 'tree'
					)
					{
						$vars['id'] = $activeMenu->query['id'];
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				return $vars;
			}
		}

		
		$searchSefListAlpha = array_search(JApplication::stringURLSafe('list-alpha'), $segments);
		if ($searchSefListAlpha !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefListAlpha, $validArrayIndex))
			{
				$vars['view'] = 'listalpha';
				if (isset($segments[$searchSefListAlpha - 1]))
				{
					if ($segments[$searchSefListAlpha - 1] == JApplication::stringURLSafe('root'))
					{
						$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
						$vars['id']   = $rootCategory->id;
					}
					else
					{
						$vars['id'] = (int) $segments[$searchSefListAlpha - 1];
					}
				}
				else
				{
					if ($activeMenu && isset($activeMenu->query) && isset($activeMenu->query['view']) && isset($activeMenu->query['id']) &&
						$activeMenu->query['view'] == 'tree'
					)
					{
						$vars['id'] = $activeMenu->query['id'];
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
					if ($isLayout)
					{
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($previousIndexSegment > $searchSefListAlpha)
					{
						$vars['alpha'] = $segments[$previousIndexSegment];
					}
				}

				return $vars;
			}
		}

		
		$searchSefFeatured = array_search(JApplication::stringURLSafe('featured'), $segments);
		if ($searchSefFeatured !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefFeatured, $validArrayIndex))
			{
				$vars['view'] = 'featured';
				if (isset($segments[$searchSefFeatured - 1]))
				{
					if ($segments[$searchSefFeatured - 1] == JApplication::stringURLSafe('root'))
					{
						$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
						$vars['id']   = $rootCategory->id;
					}
					else
					{
						$vars['id'] = (int) $segments[$searchSefFeatured - 1];
					}
				}
				else
				{
					if ($activeMenu && isset($activeMenu->query) && isset($activeMenu->query['view']) && isset($activeMenu->query['id']) &&
						$activeMenu->query['view'] == 'tree'
					)
					{
						$vars['id'] = $activeMenu->query['id'];
					}
				}

				if (isset($segments[$searchSefFeatured + 1]))
				{
					if ($segments[$searchSefFeatured + 1] == JApplication::stringURLSafe('all'))
					{
						$vars['all'] = 1;
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		
		$searchSefCollections = array_search(JApplication::stringURLSafe('collections'), $segments);
		if ($searchSefCollections !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefCollections, $validArrayIndex))
			{
				$vars['view'] = 'collections';
				if (isset($segments[$searchSefCollections - 1]))
				{
					if ($segments[$searchSefCollections - 1] != JApplication::stringURLSafe('root'))
					{
						$vars['id'] = (int) $segments[$searchSefCollections - 1];
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		
		$searchSefDashboard = array_search(JApplication::stringURLSafe('dashboard'), $segments);
		if ($searchSefDashboard !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefDashboard, $validArrayIndex))
			{
				$vars['view'] = 'dashboard';
				if (isset($segments[$searchSefDashboard - 1]))
				{
					if ($segments[$searchSefDashboard - 1] != JApplication::stringURLSafe('root'))
					{
						$vars['id'] = (int) $segments[$searchSefDashboard - 1];
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		
		$searchSefUserComments = array_search(JApplication::stringURLSafe('comments'), $segments);
		if ($searchSefUserComments !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefUserComments, $validArrayIndex))
			{
				$vars['view'] = 'usercomments';
				if (isset($segments[$searchSefUserComments - 1]))
				{
					if ($segments[$searchSefUserComments - 1] != JApplication::stringURLSafe('root'))
					{
						$vars['id'] = (int) $segments[$searchSefUserComments - 1];
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		
		$searchSefUserDocuments = array_search(JApplication::stringURLSafe('documents'), $segments);
		if ($searchSefUserDocuments !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefUserDocuments, $validArrayIndex))
			{
				$vars['view'] = 'userdocuments';
				if (isset($segments[$searchSefUserDocuments - 1]))
				{
					if ($segments[$searchSefUserDocuments - 1] != JApplication::stringURLSafe('root'))
					{
						$vars['id'] = (int) $segments[$searchSefUserDocuments - 1];
					}
				}

				if (isset($segments[$searchSefUserDocuments + 1]))
				{
					if ($segments[$searchSefUserDocuments + 1] == JApplication::stringURLSafe('published'))
					{
						$vars['filter'] = 'published';
					}
					elseif ($segments[$searchSefUserDocuments + 1] == JApplication::stringURLSafe('unpublished'))
					{
						$vars['filter'] = 'unpublished';
					}
					elseif ($segments[$searchSefUserDocuments + 1] == JApplication::stringURLSafe('pending'))
					{
						$vars['filter'] = 'pending';
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					if ($segments[$previousIndexSegment] == JApplication::stringURLSafe('rss'))
					{
						$vars['format'] = 'feed';
						$previousIndexSegment -= 1;
					}
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		
		$searchSefUserSubscriptions = array_search(JApplication::stringURLSafe('user-subscriptions'), $segments);
		if ($searchSefUserSubscriptions !== false)
		{
			$validArrayIndex = array(0, 1, 2);
			if (in_array($searchSefUserSubscriptions, $validArrayIndex))
			{
				$vars['view'] = 'usersubscriptions';

				if (isset($segments[$searchSefUserSubscriptions - 1]))
				{
					if ($segments[$searchSefUserSubscriptions - 1] != JApplication::stringURLSafe('root'))
					{
						$vars['id'] = (int) $segments[$searchSefUserSubscriptions - 1];
					}
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		$searchSefSearchBy = array_search(JApplication::stringURLSafe('search-by'), $segments);
		if ($searchSefSearchBy !== false)
		{
			$validArrayIndex = array(0, 1);
			if (in_array($searchSefSearchBy, $validArrayIndex))
			{
				$vars['view'] = 'searchby';
				if (isset($segments[$searchSefSearchBy + 1]))
				{
					$vars['field_id'] = (int) $segments[$searchSefSearchBy + 1];
				}

				if (isset($segments[$searchSefSearchBy + 2]))
				{
					$vars['value'] = $segments[$searchSefSearchBy + 2];
				}

				$previousIndexSegment = $total - 1;

				$isPaged = JUDownloadHelperRoute::parsePagination($vars, $segments, $params);
				if ($isPaged)
				{
					$previousIndexSegment -= 1;
				}

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		
		$searchSefContact = array_search(JApplication::stringURLSafe('contact'), $segments);
		if ($searchSefContact !== false)
		{
			if ($searchSefContact == $indexLastSegment || $searchSefContact == ($indexLastSegment - 1))
			{
				$vars['view'] = 'contact';

				if (isset($segments[$searchSefContact - 1]))
				{
					$vars['doc_id'] = (int) $segments[$searchSefContact - 1];
				}

				$previousIndexSegment = $total - 1;

				if (isset($segments[$previousIndexSegment]))
				{
					$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
				}

				return $vars;
			}
		}

		$searchSefCheckIn = array_search(JApplication::stringURLSafe('checkin'), $segments);
		if ($searchSefCheckIn !== false)
		{
			$vars['task'] = 'forms.checkin';
			if (isset($segments[$searchSefCheckIn - 1]))
			{
				$vars['id'] = (int) $segments[$searchSefCheckIn - 1];
			}

			return $vars;
		}

		$searchSefAdd = array_search(JApplication::stringURLSafe('add'), $segments);
		if ($searchSefAdd !== false)
		{
			$vars['task'] = 'form.add';
			if (isset($segments[$searchSefAdd - 1]))
			{
				$vars['cat_id'] = (int) $segments[$searchSefAdd - 1];
			}

			return $vars;
		}

		$searchSefEdit = array_search(JApplication::stringURLSafe('edit'), $segments);
		if ($searchSefEdit !== false)
		{
			$vars['task'] = 'form.edit';
			if (isset($segments[$searchSefEdit - 1]))
			{
				$vars['id'] = (int) $segments[$searchSefEdit - 1];
			}

			return $vars;
		}

		$searchSefDelete = array_search(JApplication::stringURLSafe('delete'), $segments);
		if ($searchSefDelete !== false)
		{
			$vars['task'] = 'forms.delete';
			if (isset($segments[$searchSefDelete - 1]))
			{
				$vars['id'] = (int) $segments[$searchSefDelete - 1];
			}

			return $vars;
		}

		$searchNewDocument = array_search(JApplication::stringURLSafe('new-document'), $segments);
		if ($searchNewDocument !== false)
		{
			$vars['view']   = 'form';
			$vars['layout'] = 'edit';
			if (isset($segments[$searchNewDocument - 1]))
			{
				$vars['cat_id'] = (int) $segments[$searchNewDocument - 1];
			}

			return $vars;
		}

		$searchSefApprove = array_search(JApplication::stringURLSafe('approve'), $segments);
		if ($searchSefApprove !== false)
		{
			if ($searchSefApprove == $indexLastSegment)
			{
				$vars['task']    = 'modpendingdocument.edit';
				$vars['approve'] = 1;
			}
			else
			{
				$vars['view']    = 'form';
				$vars['layout']  = 'edit';
				$vars['approve'] = 1;
			}

			if (isset($segments[$searchSefApprove - 1]))
			{
				$vars['id'] = (int) $segments[$searchSefApprove - 1];
			}

			return $vars;
		}

		$searchSefPublish = array_search(JApplication::stringURLSafe('publish'), $segments);
		if ($searchSefPublish !== false)
		{
			$vars['task'] = 'forms.publish';
			if (isset($segments[$searchSefPublish - 1]))
			{
				$vars['id'] = (int) $segments[$searchSefPublish - 1];
			}

			return $vars;
		}

		$searchSefUnPublish = array_search(JApplication::stringURLSafe('unpublish'), $segments);
		if ($searchSefUnPublish !== false)
		{
			$vars['task'] = 'forms.unpublish';
			if (isset($segments[$searchSefUnPublish - 1]))
			{
				$vars['id'] = (int) $segments[$searchSefUnPublish - 1];
			}

			return $vars;
		}

		$searchSefSubscribe = array_search(JApplication::stringURLSafe('subscribe'), $segments);
		if ($searchSefSubscribe !== false)
		{
			$vars['task'] = 'subscribe.save';
			if (isset($segments[$searchSefSubscribe - 1]))
			{
				$vars['doc_id'] = (int) $segments[$searchSefSubscribe - 1];
			}

			return $vars;
		}

		$searchSefUnSubscribe = array_search(JApplication::stringURLSafe('unsubscribe'), $segments);
		if ($searchSefUnSubscribe !== false)
		{
			$vars['task'] = 'subscribe.remove';

			if (isset($segments[$searchSefUnSubscribe + 1]))
			{
				$vars['sub_id'] = (int) $segments[$searchSefUnSubscribe + 1];
			}

			if (isset($segments[$searchSefUnSubscribe + 2]))
			{
				$vars['code'] = $segments[$searchSefUnSubscribe + 2];
			}

			return $vars;
		}

		$searchSefDownload = array_search(JApplication::stringURLSafe('download'), $segments);
		if ($searchSefDownload !== false)
		{
			$vars['task'] = 'download.download';

			if (isset($segments[$searchSefDownload - 3]))
			{
				if ($segments[$searchSefDownload - 3] == JApplication::stringURLSafe('file'))
				{
					$vars['file_id'] = (int) $segments[$searchSefDownload - 2];
					if ($segments[$searchSefDownload - 1] != JApplication::stringURLSafe('latest'))
					{
						$vars['version'] = $segments[$searchSefDownload - 1];
					}

					return $vars;
				}
			}

			if (isset($segments[$searchSefDownload - 1]))
			{
				if ($segments[$searchSefDownload - 1] != JApplication::stringURLSafe('latest'))
				{
					$vars['version'] = $segments[$searchSefDownload - 1];
				}

				if (isset($segments[$searchSefDownload - 2]))
				{
					$vars['doc_id'] = (int) $segments[$searchSefDownload - 2];
				}
			}

			return $vars;
		}

		
		$previousIndexSegment = $indexLastSegment;

		
		if (isset($segments[$previousIndexSegment]))
		{
			$isPaged = preg_match('/' . preg_quote(JApplication::stringURLSafe('page') . '-') . '[0-9]*+/', $segments[$previousIndexSegment]);
			if ($isPaged)
			{
				if ($indexLastSegment == 0)
				{
					if (is_object($activeMenu) && $activeMenu->component == 'com_judownload')
					{
						$vars = $activeMenu->query;
						JUDownloadHelperRoute::parsePagination($vars, $segments, $params);

						return $vars;
					}
				}
				$previousIndexSegment -= 1;
			}
		}

		
		if (isset($segments[$previousIndexSegment]))
		{
			$isFeed = $segments[$previousIndexSegment] == JApplication::stringURLSafe('rss') ? true : false;
			if ($isFeed)
			{
				$vars['format'] = 'feed';
				if ($indexLastSegment == 0)
				{
					if (is_object($activeMenu) && $activeMenu->component == 'com_judownload')
					{
						$vars           = $activeMenu->query;
						$vars['format'] = 'feed';

						return $vars;
					}
				}
				$previousIndexSegment -= 1;
			}
		}

		
		if (isset($segments[$previousIndexSegment]))
		{
			$isLayout = JUDownloadHelperRoute::parseLayout($segments[$previousIndexSegment], $vars, $params);
			if ($isLayout)
			{
				$previousIndexSegment -= 1;
			}
		}

		
		if (!empty($segments))
		{
			$reverseSegments = array_reverse($segments);
			foreach ($reverseSegments as $segmentItemKey => $segmentItem)
			{
				if (preg_match('/^\d+\-.+/', $segmentItem))
				{
					$indexAlias = $indexLastSegment - $segmentItemKey;
					break;
				}
			}

			if (isset($indexAlias) && isset($segments[$indexAlias]))
			{
				if (strpos($segments[$indexAlias], '-') === false)
				{
					$itemId    = (int) $segments[$indexAlias];
					$itemAlias = substr($segments[$indexAlias], strlen($itemId) + 1);
				}
				else
				{
					list($itemId, $itemAlias) = explode('-', $segments[$indexAlias], 2);
				}

				if (is_numeric($itemId))
				{
					$categoryObject = JUDownloadHelper::getCategoryById($itemId);
					if (is_object($categoryObject) && isset($categoryObject->alias) && $categoryObject->alias == $itemAlias)
					{
						$vars['view'] = 'category';
						$vars['id']   = $itemId;

						JUDownloadHelperRoute::parsePagination($vars, $segments, $params);

						return $vars;
					}

					$documentObject = JUDownloadHelper::getDocumentById($itemId);
					if (is_object($documentObject) && isset($documentObject->alias) && $documentObject->alias == $itemAlias)
					{
						$vars['id'] = $itemId;
						if (isset($vars['layout']))
						{
							if ($vars['layout'] == 'edit')
							{
								$vars['view'] = 'form';
							}
							else
							{
								$vars['view'] = 'document';
							}
						}

						if (!isset($vars['view']))
						{
							$vars['view'] = 'document';
						}

						if ($vars['view'] == 'document')
						{
							if (isset($segments[$indexAlias + 1]))
							{
								if ($segments[$indexAlias + 1] == JApplication::stringURLSafe('print'))
								{
									$vars['print']  = 1;
									$vars['tmpl']   = 'component';
									$vars['layout'] = 'print';
								}
								elseif ($segments[$indexAlias + 1] == JApplication::stringURLSafe('changelogs'))
								{
									$vars['layout'] = 'changelogs';
								}
								elseif ($segments[$indexAlias + 1] == JApplication::stringURLSafe('versions'))
								{
									$vars['layout'] = 'versions';
								}

							}
						}

						JUDownloadHelperRoute::parsePagination($vars, $segments, $params);

						return $vars;
					}

					if (is_object($categoryObject) && isset($categoryObject->id) && $categoryObject->id)
					{
						$vars['view'] = 'category';
						$vars['id']   = $itemId;

						JUDownloadHelperRoute::parsePagination($vars, $segments, $params);

						return $vars;
					}

					if (is_object($documentObject) && isset($documentObject->id) && $documentObject->id)
					{
						$vars['id'] = $itemId;

						if (isset($vars['layout']))
						{
							if ($vars['layout'] == 'edit')
							{
								$vars['view'] = 'form';
							}
							else
							{
								$vars['view'] = 'document';
							}
						}

						if (!isset($vars['view']))
						{
							$vars['view'] = 'document';
						}

						if ($vars['view'] == 'document')
						{
							if (isset($segments[$indexAlias + 1]))
							{
								if ($segments[$indexAlias + 1] == JApplication::stringURLSafe('print'))
								{
									$vars['print']  = 1;
									$vars['tmpl']   = 'component';
									$vars['layout'] = 'print';
								}
								elseif ($segments[$indexAlias + 1] == JApplication::stringURLSafe('changelogs'))
								{
									$vars['layout'] = 'changelogs';
								}
								elseif ($segments[$indexAlias + 1] == JApplication::stringURLSafe('versions'))
								{
									$vars['layout'] = 'versions';
								}
							}
						}

						JUDownloadHelperRoute::parsePagination($vars, $segments, $params);

						return $vars;
					}
				}
			}
		}

		if (is_object($activeMenu) && $activeMenu->component == 'com_judownload')
		{
			$vars = $activeMenu->query;
		}

		return $vars;
	}
Esempio n. 7
0
	public static function getFields($doc, $view = null, $includedOnlyFields = array(), $ignoredFields = array(), $additionFields = array())
	{
		$user        = JFactory::getUser();
		$accessLevel = implode(',', $user->getAuthorisedViewLevels());
		$date        = JFactory::getDate();
		$db          = JFactory::getDbo();

		
		if (is_object($doc) && !isset($doc->cat_id))
		{
			$doc = JUDownloadHelper::getDocumentById($doc->id);
		}

		
		if (is_numeric($doc))
		{
			$doc = JUDownloadHelper::getDocumentById($doc);
		}

		$catId = $doc->cat_id;

		

		
		$catObjStoreId = md5(__METHOD__ . "::catObj::$catId::$accessLevel");
		if (!isset(self::$cache[$catObjStoreId]))
		{
			$query = $db->getQuery(true);
			$query->select('c.id, c.field_ordering_type');
			$query->select('fg.id AS field_group_id, fg.field_ordering_type AS fg_field_ordering_type');
			$query->from('#__judownload_categories AS c');
			$query->join('LEFT', '#__judownload_fields_groups AS fg ON (fg.id = c.fieldgroup_id AND fg.published = 1 AND fg.access IN (' . $accessLevel . '))');
			$query->where('c.id = ' . $catId);
			$db->setQuery($query);
			self::$cache[$catObjStoreId] = $db->loadObject();
		}
		$catObj = self::$cache[$catObjStoreId];

		
		if (empty($catObj))
		{
			return false;
		}

		
		
		if ($catObj->field_ordering_type == 1)
		{
			$item_id        = $catObj->id;
			$type           = 'category';
			$field_group_id = $catObj->field_group_id;
		}
		
		else
		{
			
			if ($catObj->fg_field_ordering_type == 1)
			{
				$item_id        = $catObj->field_group_id;
				$type           = 'fieldgroup';
				$field_group_id = $catObj->field_group_id;
			}
			
			else
			{
				$item_id        = 0;
				$type           = '';
				$field_group_id = $catObj->field_group_id;
			}
		}

		$fieldsStoreId = md5(__METHOD__ . "::fieldsObj::$item_id::$type::$field_group_id::$view::" . "::" . serialize($includedOnlyFields) . "::" . serialize($ignoredFields) . "::" . serialize($additionFields));
		if (!isset(self::$cache[$fieldsStoreId]))
		{
			$query = $db->getQuery(true);
			$query->select("field.*, plg.folder");
			$query->from("#__judownload_fields AS field");
			$query->join("", "#__judownload_plugins AS plg ON (field.plugin_id = plg.id)");
			if ($item_id)
			{
				$query->select("fordering.ordering");
				$query->join("LEFT", "#__judownload_fields_ordering AS fordering ON (fordering.field_id = field.id AND fordering.item_id = " . (int) $item_id . " AND fordering.type = '$type')");
				$query->order("fordering.ordering");
			}
			$query->join("", "#__judownload_fields_groups AS fg ON (fg.id = field.group_id)");
			$query->where('fg.access IN (' . $accessLevel . ')');

			
			$nullDate = $db->quote($db->getNullDate());
			$nowDate  = $db->quote($date->toSql());
			$query->where('field.published = 1');
			$query->where('field.publish_up <= ' . $nowDate);
			$query->where('(field.publish_down = ' . $nullDate . ' OR field.publish_down > ' . $nowDate . ')');

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

			
			if ($field_group_id > 1)
			{
				$query->where("(field.group_id = 1 OR field.group_id = " . (int) $field_group_id . ")");
			}
			
			else
			{
				$query->where("field.group_id = 1");
			}

			
			$additionFieldsStr = "";
			if ($additionFields)
			{
				$additionFieldIds = $additionFieldNames = array();
				foreach ($additionFields AS $additionField)
				{
					if ($additionField && is_numeric($additionField))
					{
						$additionFieldIds[$additionField] = $additionField;
					}
					elseif ($additionField)
					{
						$additionFieldNames[$additionField] = $additionField;
					}
				}

				if ($additionFieldIds)
				{
					$additionFieldsStr .= " OR field.id IN (" . implode(",", $additionFieldIds) . ")";
				}

				if ($additionFieldNames)
				{
					$additionFieldsStr .= " OR field.field_name IN ('" . implode("','", $additionFieldNames) . "')";
				}
			}

			
			$app         = JFactory::getApplication();
			$languageTag = JFactory::getLanguage()->getTag();
			if ($app->getLanguageFilter())
			{
				$query->where("(field.language IN (" . $db->quote($languageTag) . "," . $db->quote('*') . "," . $db->quote('') . ")" . $additionFieldsStr . ")");
			}

			
			if ($view == 1)
			{
				$query->where("(field.list_view = 1" . $additionFieldsStr . ")");
			}
			elseif ($view == 2)
			{
				$query->where("(field.details_view = 1" . $additionFieldsStr . ")");
			}

			
			if ($ignoredFields)
			{
				$ignoreFieldIds = $ignoreFieldNames = array();
				foreach ($ignoredFields AS $ignoredField)
				{
					if ($ignoredField && is_numeric($ignoredField))
					{
						$ignoreFieldIds[$ignoredField] = $ignoredField;
					}
					elseif ($ignoredField)
					{
						$ignoreFieldNames[$ignoredField] = $ignoredField;
					}
				}

				if ($ignoreFieldIds)
				{
					$query->where("field.id NOT IN (" . implode(",", $ignoreFieldIds) . ")");
				}

				if ($ignoreFieldNames)
				{
					$query->where("field.field_name NOT IN ('" . implode("','", $ignoreFieldNames) . "')");
				}
			}

			
			if ($includedOnlyFields)
			{
				$includedFieldIds = $includedFieldNames = array();
				foreach ($includedOnlyFields AS $includedField)
				{
					if ($includedField && is_numeric($includedField))
					{
						$includedFieldIds[$includedField] = $includedField;
					}
					elseif ($includedField)
					{
						$includedFieldNames[$includedField] = $includedField;
					}
				}

				if ($includedFieldIds)
				{
					$query->where("field.id IN (" . implode(",", $includedFieldIds) . ")");
				}

				if ($includedFieldNames)
				{
					$query->where("field.field_name IN ('" . implode("','", $includedFieldNames) . "')");
				}
			}

			$query->group('field.id');
			
			$query->order("fg.ordering, field.ordering");
			$db->setQuery($query);

			$fields = $db->loadObjectList();

			
			$newFields = array();
			foreach ($fields AS $key => $field)
			{
				
				if (isset($field->ordering) && is_null($field->ordering))
				{
					$newFields[] = $field;
					unset($fields[$key]);
				}
			}
			
			if (!empty($newFields))
			{
				$fields = array_merge($fields, $newFields);
			}

			self::$cache[$fieldsStoreId] = $fields;
		}
		$fields = self::$cache[$fieldsStoreId];

		
		if (!$fields)
		{
			return false;
		}

		$fieldObjectList = array();
		if (count($fields))
		{
			foreach ($fields AS $_field)
			{
				$field = clone $_field;

				
				if ($field->field_name != "")
				{
					$newKey = $field->field_name;
				}
				else
				{
					$newKey = $field->id;
				}

				$fieldObjectList[$newKey] = self::getField($field, $doc);

				unset($field);
			}
		}

		return $fieldObjectList;
	}
Esempio n. 8
0
	public static function getDownloadRuleErrorMessages($docId)
	{
		$error_messages = array();
		$user           = JFactory::getUser();

		$asset = 'com_judownload.document.' . $docId;
		if ($user->authorise('judl.document.download', $asset))
		{
			return true;
		}
		else
		{
			$error_messages[] = JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_DOWNLOAD');
		}

		$docObj = JUDownloadHelper::getDocumentById($docId);

		$dispatcher = JDispatcher::getInstance();
		JPluginHelper::importPlugin('judownload');
		$pluginTriggerResults = $dispatcher->trigger('canDownload', array($docObj));

		foreach ($pluginTriggerResults AS $result)
		{
			
			if ($result === true)
			{
				return true;
			}
			else
			{
				
				if (is_string($result))
				{
					$error_messages[] = $result;
				}
			}
		}

		return $error_messages;
	}
Esempio n. 9
0
	public function getInput($fieldValue = null)
	{
		if (!$this->isPublished())
		{
			return "";
		}

		if ((JUDownloadHelper::getDocumentSubmitType($this->doc_id) == 'submit' && $this->canSubmit())
			|| (JUDownloadHelper::getDocumentSubmitType($this->doc_id) == 'edit' && $this->canEdit())
		)
		{
			$disabled = false;
		}
		else
		{
			$disabled = true;
		}

		$document = JFactory::getDocument();
		$rootCat  = JUDownloadFrontHelperCategory::getRootCategory();
		JText::script('COM_JUDOWNLOAD_TOTAL_CATS_OVER_MAXIMUM_N_CATS');
		JText::script('COM_JUDOWNLOAD_CATEGORY_X_ALREADY_EXIST');
		$app = JFactory::getApplication();
		
		if (isset($this->doc) && $this->doc->cat_id)
		{
			$params = JUDownloadHelper::getParams($this->doc->cat_id);
		}
		else
		{
			$params = JUDownloadHelper::getParams(null, $this->doc_id);
		}

		$db              = JFactory::getDbo();
		$docId           = $this->doc_id;
		$documentObject  = JUDownloadHelper::getDocumentById($docId);
		$secondaryCatIds = $secondaryCatIdsStr = "";

		
		if ($fieldValue && !empty($fieldValue['main']))
		{
			$categoryId = (int) $fieldValue['main'];
			if ($fieldValue['secondary'])
			{
				$secondaryCatIdsStr = $fieldValue['secondary'];
				$secondaryCatIds    = explode(",", $secondaryCatIdsStr);
			}
			$query = $db->getQuery(true);
			$query->select("c.id, c.parent_id");
			$query->from("#__judownload_categories AS c");
			$query->select("field_group.id AS fieldgroup_id, field_group.name AS fieldgroup_name");
			$query->join("LEFT", "#__judownload_fields_groups AS field_group ON (field_group.id = c.fieldgroup_id AND field_group.published = 1)");
			$query->where("c.id = " . $categoryId);
			$db->setQuery($query);
			$mainCategory = $db->loadObject();
		}
		
		elseif ($docId)
		{
			$categories = $this->value;
			foreach ($categories AS $category)
			{
				if ($category->main == 1)
				{
					$mainCategory = $category;

					$query = $db->getQuery(true);
					$query->select("field_group.id, field_group.name");
					$query->from("#__judownload_fields_groups AS field_group");
					$query->join("", "#__judownload_categories AS c on c.fieldgroup_id = field_group.id");
					$query->where("c.id = " . $mainCategory->id);
					$query->where("field_group.published = 1");
					$db->setQuery($query);
					$fieldGroup = $db->loadObject();
					if (is_object($fieldGroup))
					{
						$mainCategory->fieldgroup_name = $fieldGroup->name;
						$mainCategory->fieldgroup_id   = $fieldGroup->id;
					}
					else
					{
						$mainCategory->fieldgroup_name = null;
						$mainCategory->fieldgroup_id   = null;
					}
				}
				else
				{
					$secondaryCatIds[] = $category->id;
				}
			}

			if ($secondaryCatIds)
			{
				$secondaryCatIdsStr = implode(",", $secondaryCatIds);
			}
		}
		
		elseif ($app->input->getInt('cat_id'))
		{
			$categoryId   = $app->input->getInt('cat_id');
			$mainCategory = JUDownloadHelper::getCategoryById($categoryId);
			$query        = "SELECT id, name FROM #__judownload_fields_groups WHERE id= " . $mainCategory->fieldgroup_id . " AND published = 1";
			$db->setQuery($query);
			$fieldGroup = $db->loadObject();
			if (is_object($fieldGroup))
			{
				$mainCategory->fieldgroup_name = $fieldGroup->name;
				$mainCategory->fieldgroup_id   = $fieldGroup->id;
			}
			else
			{
				$mainCategory->fieldgroup_name = null;
				$mainCategory->fieldgroup_id   = null;
			}
		}
		
		else
		{
			$mainCategory                  = new stdClass();
			$mainCategory->id              = '';
			$mainCategory->parent_id       = $rootCat->id;
			$mainCategory->fieldgroup_name = null;
			$mainCategory->fieldgroup_id   = null;
		}

		$document->addStyleSheet(JUri::root() . "components/com_judownload/fields/" . $this->folder . "/core_categories.css");

		if (!$disabled)
		{
			$document->addScript(JUri::root() . "components/com_judownload/fields/" . $this->folder . "/core_categories.js");

			if (JUDownloadHelper::isJoomla3x())
			{
				$jsIsJoomla3x = 1;
			}
			else
			{
				$jsIsJoomla3x = 0;
			}

			$script = "jQuery(document).ready(function($){
								$('.category_selection').docChangeCategory({
									doc_id: '" . $docId . "',
									is_joomla_3x: '" . $jsIsJoomla3x . "',
									main_cat_id: '" . $mainCategory->id . "',
									fieldgroup_id: '" . $mainCategory->fieldgroup_id . "',
									fieldgroup_name : '" . $mainCategory->fieldgroup_name . "',
									max_cats : " . (int) 1 . "
								});
						});";

			$document->addScriptDeclaration($script);
		}

		$this->addAttribute("class", "categories", "input");
		$this->addAttribute("class", $this->getInputClass(), "input");

		$this->setVariable('mainCategory', $mainCategory);
		$this->setVariable('secondaryCatIds', $secondaryCatIds);
		$this->setVariable('documentObject', $documentObject);
		$this->setVariable('disabled', $disabled);
		$this->setVariable('secondaryCatIdsStr', $secondaryCatIdsStr);
		$this->setVariable('rootCat', $rootCat);
		$this->setVariable('params', $params);

		return $this->fetch('input.php', __CLASS__);
	}
Esempio n. 10
0
 public function getDocumentSubmitType($documentId, $documentObject = null, $isNew = null)
 {
     if (!is_null($isNew)) {
         if ($isNew) {
             return 'submit';
         }
     }
     if ($documentId == 0) {
         return 'submit';
     }
     if (!is_object($documentObject)) {
         $documentObject = JUDownloadHelper::getDocumentById($documentId);
     }
     if ($documentObject->approved == 0) {
         return 'submit';
     } else {
         return 'edit';
     }
 }
Esempio n. 11
0
 public function insertUpdateDocument($data, $isInsert = true)
 {
     $db = JFactory::getDbo();
     $iconDir = JPATH_ROOT . '/' . JUDownloadFrontHelper::getDirectory('document_icon_directory', 'media/com_judownload/images/document/');
     $originalDir = $iconDir . 'original/';
     $newMainCatId = $data['main_cat'];
     $gallery = $data['gallery'];
     $files = $data['files'];
     $fieldsData = $data['fieldsData'];
     $relatedDocs = $data['related_docs'];
     $data = $data['data'];
     $messages = array();
     if (!$isInsert) {
         $docObj = JUDownloadHelper::getDocumentById($data['id']);
         if ($docObj->cat_id != $newMainCatId) {
             $oldFieldGroup = JUDownloadHelper::getCategoryById($docObj->cat_id);
             $newFieldGroup = JUDownloadHelper::getCategoryById($newMainCatId);
             if ($oldFieldGroup->fieldgroup_id != $newFieldGroup->fieldgroup_id) {
                 $query = $db->getQuery(true);
                 $query->select("field.*");
                 $query->from("#__judownload_fields AS field");
                 $query->select("plg.folder");
                 $query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id");
                 $query->join("", "#__judownload_categories AS c ON (c.fieldgroup_id = field.group_id AND field.group_id != 1)");
                 $query->join("", "#__judownload_documents_xref AS dxref ON (dxref.cat_id = c.id AND dxref.main = 1)");
                 $query->join("", "#__judownload_documents AS d ON dxref.doc_id = d.id");
                 $query->where("d.id = " . $data['id']);
                 $query->group('field.id');
                 $query->order('field.ordering');
                 $db->setQuery($query);
                 $fields = $db->loadObjectList();
                 foreach ($fields as $field) {
                     $fieldObj = JUDownloadFrontHelperField::getField($field, $data['id']);
                     $fieldObj->onDelete();
                 }
             }
         }
     }
     $iconPath = '';
     $iconFieldId = $this->field_name_id_array['icon'];
     if (!empty($data['icon'])) {
         $iconPath = $data['icon'];
         unset($data['icon']);
     }
     if (!empty($fieldsData[$iconFieldId])) {
         $iconPath = $fieldsData[$iconFieldId];
         unset($fieldsData[$iconFieldId]);
     }
     $table = JTable::getInstance("Document", "JUDownloadTable");
     if (!$table->bind($data) || !$table->check() || !$table->store()) {
         return array('doc_id' => 0, 'messages' => $table->getErrors());
     }
     $docId = $table->id;
     $categoriesField = new JUDownloadFieldCore_categories(null, $docId);
     $categoriesField->is_new_doc = $isInsert;
     $result = $categoriesField->storeValue($fieldsData[$this->field_name_id_array['cat_id']]);
     if (!$result) {
         $table->delete($docId);
         return array('doc_id' => 0, 'messages' => $db->getErrorMsg());
     }
     $query = $db->getQuery(true);
     $query->select("field.*");
     $query->from("#__judownload_fields AS field");
     $query->select("plg.folder");
     $query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id");
     $query->join("", "#__judownload_categories AS c ON (c.fieldgroup_id = field.group_id OR field.group_id = 1)");
     $query->join("", "#__judownload_documents_xref AS dxref ON (dxref.cat_id = c.id AND dxref.main = 1)");
     $query->join("", "#__judownload_documents AS d ON dxref.doc_id = d.id");
     $query->where("d.id = {$docId}");
     $query->where("field.field_name != 'id'");
     $query->where("field.field_name != 'cat_id'");
     $query->group('field.id');
     $query->order('ordering ASC');
     $db->setQuery($query);
     $fields = $db->loadObjectList();
     $docObj = JUDownloadHelper::getDocumentById($docId);
     foreach ($fields as $field) {
         if (isset($fieldsData[$field->id])) {
             $fieldObj = JUDownloadFrontHelperField::getField($field, $docObj);
             $fieldObj->fields_data = $fieldsData;
             $fieldValue = $fieldsData[$field->id];
             $fieldObj->is_new_doc = $isInsert;
             $fieldValue = $fieldObj->onImportDocument($fieldValue);
             $fieldObj->storeValue($fieldValue);
         }
     }
     if ($iconPath) {
         $iconPath = JUDownloadHelper::getPhysicalPath($iconPath);
         if (!$iconPath) {
             $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $iconPath);
         } else {
             if ($data['id'] > 0) {
                 if ($table->icon) {
                     if (JFile::exists($iconDir . $table->icon)) {
                         JFile::delete($iconDir . $table->icon);
                         JFile::delete($originalDir . $table->icon);
                     }
                 }
             }
             $iconName = basename($iconPath);
             $iconName = $docId . "_" . JUDownloadHelper::fileNameFilter($iconName);
             if (JFile::copy($iconPath, $originalDir . $iconName) && JUDownloadHelper::renderImages($originalDir . $iconName, $iconDir . $iconName, 'document_icon', true, null, $data['id'])) {
                 $table->icon = $iconName;
                 $table->store();
             }
         }
     }
     $imageTable = JTable::getInstance("Image", "JUDownloadTable");
     if (!empty($gallery)) {
         $dir_document_ori = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_original_image_directory", "media/com_judownload/images/gallery/original/") . $docId . "/";
         $dir_document_small = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_small_image_directory", "media/com_judownload/images/gallery/small/") . $docId . "/";
         $dir_document_big = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("document_big_image_directory", "media/com_judownload/images/gallery/big/") . $docId . "/";
         if (!JFolder::exists($dir_document_ori)) {
             $file_index = $dir_document_ori . 'index.html';
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         if (!JFolder::exists($dir_document_small)) {
             $file_index = $dir_document_small . 'index.html';
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         if (!JFolder::exists($dir_document_big)) {
             $file_index = $dir_document_big . 'index.html';
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         $image_ordering = 1;
         $date = JFactory::getDate();
         foreach ($gallery as $imagePath) {
             $imagePath = JUDownloadHelper::getPhysicalPath($imagePath);
             if (!$imagePath) {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $imagePath);
                 continue;
             }
             $imageName = basename($imagePath);
             $imageName = JUDownloadHelper::generateImageNameByDocument($docId, $imageName);
             if (JFile::copy($imagePath, $dir_document_ori . $imageName) && JUDownloadHelper::renderImages($dir_document_ori . $imageName, $dir_document_small . $imageName, 'document_small', true, null, $data['id']) && JUDownloadHelper::renderImages($dir_document_ori . $imageName, $dir_document_big . $imageName, 'document_big', true, null, $data['id'])) {
                 $imageObj = new stdClass();
                 $imageObj->id = 0;
                 $imageObj->file_name = $imageName;
                 $imageObj->doc_id = $docId;
                 $imageObj->ordering = $image_ordering;
                 $imageObj->created = $date->toSql();
                 $imageObj->published = 1;
                 if (!$imageTable->bind($imageObj) || !$imageTable->check() || !$imageTable->store()) {
                     $messages[] = implode(' | ', $imageTable->getErrors());
                     JFile::delete($dir_document_ori . $imageName);
                     JFile::delete($dir_document_small . $imageName);
                     JFile::delete($dir_document_big . $imageName);
                 } else {
                     $image_ordering++;
                 }
             } else {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_CAN_NOT_COPY_FILE_FROM_S_TO_S', $imagePath, $dir_document_ori . $imageName);
             }
         }
     }
     $fileTable = JTable::getInstance("File", "JUDownloadTable");
     if (!empty($files)) {
         $file_directory = JPATH_SITE . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/");
         if (!JFolder::exists($file_directory . $docId . "/")) {
             $file_index = $file_directory . $docId . "/index.html";
             $buffer = "<!DOCTYPE html><title></title>";
             JFile::write($file_index, $buffer);
         }
         $file_ordering = 1;
         foreach ($files as $filePath) {
             $filePath = JUDownloadHelper::getPhysicalPath($filePath);
             if (!$filePath) {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_FILE_S_NOT_FOUND', $filePath);
                 continue;
             }
             $query = $db->getQuery(true);
             $query->select('COUNT(*)')->from('#__judownload_files')->where('doc_id = ' . $docId)->where('`rename` = ' . $db->quote(basename($filePath)));
             $db->setQuery($query);
             $count = $db->loadResult();
             if ($count) {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_EXISTED_FILE_S', $filePath);
                 continue;
             }
             $fileObject = array();
             $fileObject['id'] = 0;
             $fileObject['doc_id'] = $docId;
             $fileObject['ordering'] = $file_ordering;
             $fileObject['rename'] = basename($filePath);
             $fileObject['file_name'] = md5($fileObject['rename'] . JUDownloadHelper::generateRandomString(10)) . "." . JFile::getExt($fileObject['rename']);
             $fileObject['published'] = 1;
             $this->addFileInfo($fileObject, $filePath, $file_directory);
             $dest = $file_directory . $docId . "/" . $fileObject['file_name'];
             if ($fileTable->bind($fileObject) && $fileTable->check() && $fileTable->store()) {
                 if (!JFile::copy($filePath, $dest)) {
                     $fileTable->delete($fileTable->id);
                     $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_CAN_NOT_COPY_FILE_FROM_S_TO_S', $filePath, $dest);
                 }
                 $file_ordering++;
             } else {
                 $messages[] = implode(' | ', $fileTable->getErrors());
             }
         }
     }
     if (!empty($relatedDocs)) {
         $ordering = 1;
         foreach ($relatedDocs as $relatedDocId) {
             $document = JUDownloadHelper::getDocumentById($relatedDocId);
             if ($document) {
                 $relatedDocObj = new stdClass();
                 $relatedDocObj->id = 0;
                 $relatedDocObj->doc_id = $docId;
                 $relatedDocObj->doc_id_related = $relatedDocId;
                 $relatedDocObj->ordering = $ordering;
                 $query = $db->getQuery(true);
                 $query->select('id')->from('#__judownload_documents_relations')->where('doc_id = ' . $docId)->where('doc_id_related = ' . $relatedDocId);
                 $db->setQuery($query);
                 $existedId = $db->loadResult();
                 if ($existedId) {
                     $relatedDocObj->id = $existedId;
                     $db->updateObject('#__judownload_documents_relations', $relatedDocObj, 'id');
                 } else {
                     $db->insertObject('#__judownload_documents_relations', $relatedDocObj);
                 }
                 $relationId = $db->insertid();
                 if ($relationId > 0) {
                     $ordering++;
                 } else {
                     $messages[] = $db->getErrorMsg();
                 }
             } else {
                 $messages[] = JText::sprintf('COM_JUDOWNLOAD_CSV_PROCESS_INVALID_RELATED_DOCUMENT_N', $relatedDocId);
             }
         }
     }
     return array('doc_id' => $docId, 'messages' => $messages);
 }
Esempio n. 12
0
        ?>
" name="documentid[]" id="doc<?php 
        echo $i;
        ?>
" />
					<?php 
    }
    ?>
				</td>
				<?php 
    foreach ($this->model->fields_use as $field) {
        echo '<td>';
        switch ($field->field_name) {
            case "title":
                if (!$item->main) {
                    $main_cat_id = JUDownloadHelper::getDocumentById($item->id)->cat_id;
                    ?>
								<a href="<?php 
                    echo JRoute::_('index.php?option=com_judownload&view=listcats&cat_id=' . $main_cat_id);
                    ?>
"><?php 
                    echo JUDownloadHelper::generateCategoryPath($main_cat_id);
                    ?>
 </a> >
							<?php 
                }
                if ($item->checked_out) {
                    echo JHtml::_('jgrid.checkedout', $i, $item->checked_out_name, $item->checked_out_time, 'documents.', $canCheckin || $user->authorise('core.manage', 'com_checkin'), 'doc');
                }
                if ($canEdit || $canEditOwn) {
                    ?>
Esempio n. 13
0
	public static function getCurrentTemplateStyle($view = '', $id = null)
	{
		$app    = JFactory::getApplication();
		$jInput = $app->input;

		
		if (!$view)
		{
			$view = $jInput->getString('view', '');
		}

		
		if ($jInput->getString('option', '') != 'com_judownload')
		{
			$view = '';
		}

		
		if (!$id)
		{
			switch ($view)
			{
				case 'form':
					$id           = $jInput->getInt('id', 0);
					$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
					$cat_id       = $jInput->getInt('cat_id', $rootCategory->id);
					break;
				case 'document':
					$id = $jInput->getInt('id', 0);
					break;
				case 'category':
					$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();
					$id           = $jInput->getInt('id', $rootCategory->id);
					break;
			}
		}

		switch ($view)
		{
			
			case 'form':
				if ($id)
				{
					$templateStyleObject         = self::getTemplateStyleOfDocument($id);
					$documentObject              = JUDownloadHelper::getDocumentById($id);
					$templateStyleObject->params = self::getTemplateStyleParams($templateStyleObject->id, $documentObject->template_params);
				}
				else
				{
					$templateStyleObject         = self::getTemplateStyleOfCategory($cat_id);
					$categoryObject              = JUDownloadHelper::getCategoryById($cat_id);
					$templateStyleObject->params = self::getTemplateStyleParams($templateStyleObject->id, $categoryObject->template_params);
				}
				break;
			case 'document':
				$templateStyleObject         = self::getTemplateStyleOfDocument($id);
				$documentObject              = JUDownloadHelper::getDocumentById($id);
				$templateStyleObject->params = self::getTemplateStyleParams($templateStyleObject->id, $documentObject->template_params);
				break;
			
			case 'category':
				$templateStyleObject         = self::getTemplateStyleOfCategory($id);
				$categoryObject              = JUDownloadHelper::getCategoryById($id);
				$templateStyleObject->params = self::getTemplateStyleParams($templateStyleObject->id, $categoryObject->template_params);
				break;
			
			default:
				$templateStyleObject         = self::getDefaultTemplateStyle();
				$templateStyleObject->params = self::getTemplateStyleParams($templateStyleObject->id);
				break;
		}

		return $templateStyleObject;
	}
Esempio n. 14
0
 public static function getDocumentSubmitType($documentId)
 {
     if ($documentId == 0) {
         return 'submit';
     }
     $documentObject = JUDownloadHelper::getDocumentById($documentId);
     if ($documentObject->approved == 0) {
         return 'submit';
     } else {
         return 'edit';
     }
 }
Esempio n. 15
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];
	}
Esempio n. 16
0
	public function loadDocument($doc, $resetCache = false)
	{
		
		if (is_numeric($doc) && $doc > 0)
		{
			$doc = clone JUDownloadHelper::getDocumentById($doc, $resetCache);
		}

		if (is_object($doc) || is_null($doc))
		{
			$this->doc = $doc;
		}
	}
Esempio n. 17
0
	public static function getMainCategoryId($documentId, $resetCache = false)
	{
		$docObj = JUDownloadHelper::getDocumentById($documentId, $resetCache);

		if (is_object($docObj))
		{
			return $docObj->cat_id;
		}

		return null;
	}
Esempio n. 18
0
	public function download()
	{
		
		JSession::checkToken('request') or die(JText::_('JINVALID_TOKEN'));

		
		$model = $this->getModel();

		
		$model->deleteExpiredTmpFiles();

		
		$app = JFactory::getApplication();
		
		$submittedCategoryId = $app->input->getInt('cat_id', 0);
		$documentIds         = $app->input->get('doc_id', null, null);
		$fileIds             = $app->input->get('file_id', null, null);
		$version             = $app->input->get('version', '', 'string');

		$serverTime      = JFactory::getDate()->toSql();
		$serverTimeStamp = strtotime($serverTime);

		$valuesStoreId = (array) $app->getUserState('com_judownload.download.storeid');

		$params                 = JUDownloadHelper::getParams();
		$noCountingDownloadTime = (int) $params->get('no_counting_download_time', 300);
		
		if ($noCountingDownloadTime > 0)
		{
			if (!empty($valuesStoreId))
			{
				foreach ($valuesStoreId AS $keyStoreId => $valueStoreId)
				{
					if ($serverTimeStamp - $keyStoreId > $noCountingDownloadTime)
					{
						unset($valuesStoreId[$keyStoreId]);
					}
				}
			}

			$app->setUserState('com_judownload.download.storeid', $valuesStoreId);
		}

		
		$dispatcher = JDispatcher::getInstance();
		JPluginHelper::importPlugin('judownload');

		
		if (isset($fileIds))
		{
			
			if (is_array($fileIds))
			{
				
				$fileIdArray = $fileIds;
			}
			else
			{
				
				$fileIdArray = explode(',', $fileIds);
			}

			
			if (count($fileIdArray) > 0)
			{
				
				if (count($fileIdArray) > 1)
				{
					
					$documentId = (int) $documentIds;
					if (!$documentIds)
					{
						$message = JText::_('COM_JUDOWNLOAD_NO_DOCUMENT_DETECTED');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}

					
					$fileObjectList   = $model->getAllFilesOfDocument($documentId);
					$validFileIdArray = array();
					foreach ($fileObjectList AS $fileObject)
					{
						if (in_array($fileObject->id, $fileIdArray))
						{
							$validFileIdArray[] = $fileObject->id;
						}
					}
				}
				
				else
				{
					$fileObject = $model->getFileObject($fileIdArray[0]);
					$documentId = $fileObject->doc_id;
					if (isset($documentIds))
					{
						$documentIdPost = (int) $documentIds;
						if ($documentIdPost != $documentId)
						{
							$message = JText::_('COM_JUDOWNLOAD_INVALID_DATA');
							$this->setRedirect($this->getReturnPage(), $message, 'error');

							return false;
						}
					}
					$validFileIdArray = $fileIdArray;
					
					$physicalFilePath = $model->getPhysicalFilePath($validFileIdArray[0]);
					$physicalFilePath = JPath::clean($physicalFilePath);
					if (!JFile::exists($physicalFilePath))
					{
						$message = JText::_('COM_JUDOWNLOAD_FILE_DOES_NOT_EXIST');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}
				}

				
				$canDownloadDocument = $model->canDownloadDocument($documentId);
				if ($canDownloadDocument)
				{
					if (count($validFileIdArray) > 0)
					{
						
						$externalField = new JUDownloadFieldCore_external_link();
						$document      = JUDownloadHelper::getDocumentById($documentId);
						if ($externalField->isPublished() && $document->external_link != '')
						{
							$dispatcher->trigger('onAfterDownloadDocument', array($documentId, array(), 0));

							
							$logData = array(
								'user_id'   => JFactory::getUser()->id,
								'event'     => 'document.download',
								'item_id'   => $documentId,
								'doc_id'    => $documentId,
								'value'     => 0,
								'reference' => 'external'
							);
							JUDownloadFrontHelperLog::addLog($logData);

							
							JUDownloadFrontHelperMail::sendEmailByEvent('document.download', $documentId);

							
							$model->updateDocumentDownloadCounter($documentId);

							
							$this->setRedirect(JRoute::_($document->external_link, false));

							return true;
						}

						if (count($validFileIdArray) > 1)
						{
							$params = JUDownloadHelper::getParams(null, (int) $documentId);
							
							if (!$params->get('allow_zip_file', 1))
							{
								$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
								$this->setRedirect($this->getReturnPage(), $message, 'error');

								return false;
							}
						}

						
						foreach ($validFileIdArray AS $validFileId)
						{
							$canDownloadFile = $model->canDownloadFile($validFileId, false);
							if (!$canDownloadFile)
							{
								$fileObject = $model->getFileObject($validFileId);
								$message    = JText::sprintf('COM_JUDOWNLOAD_YOU_CAN_NOT_DOWNLOAD_FILE_X', $fileObject->rename);
								$this->setRedirect($this->getReturnPage(), $message, 'error');

								return false;
							}
						}

						if ($noCountingDownloadTime > 0)
						{
							sort($validFileIdArray);
							$storeID = md5('file' . serialize($validFileIdArray) . $version);
							if (in_array($storeID, $valuesStoreId))
							{
								$generalCheck = true;
							}
							else
							{
								
								$generalCheck = $model->generalCheckDownload();
							}
						}
						else
						{
							$generalCheck = $model->generalCheckDownload();
						}

						if (!$generalCheck)
						{
							$message = $model->getError();
							$this->setRedirect($this->getReturnPage(), $message, 'error');

							return false;
						}

						if ($model->download('file', $validFileIdArray, $documentId, $version) === false)
						{
							$message = $model->getError();
							$this->setRedirect($this->getReturnPage(), $message, 'error');

							return false;
						}

					}
					
					else
					{
						$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}
				}
				
				else
				{
					$message          = implode("<br/>", $model->getErrors());
					$params           = JUDownloadHelper::getParams(null, $documentId);
					$display_messages = $params->get('show_rule_messages', 'modal');
					if ($display_messages == "redirect")
					{
						$return = $app->input->get('return', null, 'base64');
						$this->setRedirect(JRoute::_('index.php?option=com_judownload&view=downloaderror&return=' . $return, false), $message, 'error');
					}
					else
					{
						$this->setRedirect($this->getReturnPage(), $message, 'error');
					}

					return false;
				}
			}
			
			else
			{
				$message = JText::_('COM_JUDOWNLOAD_NO_FILE_TO_DOWNLOAD');
				$this->setRedirect($this->getReturnPage(), $message, 'error');

				return false;
			}
		}
		
		else
		{
			
			if (is_array($documentIds))
			{
				$documentIdArray = $documentIds;
			}
			else
			{
				$documentIdArray = explode(',', $documentIds);
			}

			if (count($documentIdArray) > 0)
			{
				
				if (count($documentIdArray) > 1)
				{
					$categoryId = $submittedCategoryId;
					
					if (!$categoryId)
					{
						$message = JText::_('COM_JUDOWNLOAD_NO_CATEGORY_DETECTED');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}

					$params = JUDownloadHelper::getParams(null, $categoryId);
					
					if (!$params->get('allow_download_multi_docs', 0))
					{
						$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}

					
					$validDocumentIdArray = array();

					
					$documentIdsInCat = $model->getChildDocumentIds($categoryId);

					foreach ($documentIdsInCat AS $documentIdInCat)
					{
						if (in_array($documentIdInCat, $documentIdArray))
						{
							$validDocumentIdArray[] = $documentIdInCat;
						}
					}
				}
				
				else
				{
					$documentId = $documentIdArray[0];
					$categoryId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId);

					$validDocumentIdArray = $documentIdArray;
					$documentIdInCat      = JUDownloadHelper::getDocumentById($documentId);
					$externalField        = new JUDownloadFieldCore_external_link();
					if ($externalField->isPublished() && $documentIdInCat->external_link != '')
					{
						$dispatcher->trigger('onAfterDownloadDocument', array($documentId, array(), 0));

						
						$logData = array(
							'user_id'   => JFactory::getUser()->id,
							'event'     => 'document.download',
							'item_id'   => $documentId,
							'doc_id'    => $documentId,
							'value'     => 0,
							'reference' => 'external'
						);
						JUDownloadFrontHelperLog::addLog($logData);

						
						JUDownloadFrontHelperMail::sendEmailByEvent('document.download', $documentId);

						
						$model->updateDocumentDownloadCounter($documentId);

						
						$this->setRedirect(JRoute::_($documentIdInCat->external_link, false));

						return true;
					}
				}

				if (count($validDocumentIdArray) > 1)
				{
					$params = JUDownloadHelper::getParams($categoryId);
					
					if (!$params->get('allow_zip_file', 1))
					{
						$message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA');
						$this->setRedirect($this->getReturnPage(), $message, 'error');

						return false;
					}
				}
				elseif (count($validDocumentIdArray) == 1)
				{
					$filesInDocument = JUDownloadFrontHelperDocument::getFilesByDocumentId((int) $validDocumentIdArray[0]);
					if (count($filesInDocument) > 1)
					{
						if (!$params->get('allow_zip_file', 1))
						{
							$linkFiles = JUDownloadHelperRoute::getDocumentRoute((int) $validDocumentIdArray[0]);
							$linkFiles .= '#judl-files';
							$app->redirect(JRoute::_($linkFiles, false));
						}
					}
				}

				
				foreach ($validDocumentIdArray AS $documentId)
				{
					$canDownloadDocument = $model->canDownloadDocument($documentId);
					if (!$canDownloadDocument)
					{
						$message          = implode("<br/>", $model->getErrors());
						$params           = JUDownloadHelper::getParams(null, $documentId);
						$display_messages = $params->get('show_rule_messages', 'modal');
						if ($display_messages == "redirect")
						{
							$return = $app->input->get('return', null, 'base64');
							$this->setRedirect(JRoute::_('index.php?option=com_judownload&view=downloaderror&return=' . $return, false), $message, 'error');
						}
						else
						{
							$this->setRedirect($this->getReturnPage(), $message, 'error');
						}

						return false;
					}
				}

				
				if ($noCountingDownloadTime > 0)
				{
					sort($validDocumentIdArray);
					$storeID = md5('document' . serialize($validDocumentIdArray) . $version);
					if (in_array($storeID, $valuesStoreId))
					{
						$generalCheck = true;
					}
					else
					{
						
						$generalCheck = $model->generalCheckDownload();
					}
				}
				else
				{
					$generalCheck = $model->generalCheckDownload();
				}

				if (!$generalCheck)
				{
					$message = $model->getError();
					$this->setRedirect($this->getReturnPage(), $message, 'error');

					return false;
				}

				
				if (count($validDocumentIdArray) == 1)
				{
					if (count($filesInDocument) == 1)
					{
						
						if (!$params->get('allow_zip_file', 1))
						{
							$fileObject = $filesInDocument[0];
							$fileId     = $fileObject->id;
							if ($model->download('file', array($fileId), $validDocumentIdArray[0], $version) === false)
							{
								$message = $model->getError();
								$this->setRedirect($this->getReturnPage(), $message, 'error');

								return false;
							}
						}
					}
				}

				if ($model->download('document', $validDocumentIdArray, $categoryId, $version) === false)
				{
					$message = $model->getError();
					$this->setRedirect($this->getReturnPage(), $message, 'error');

					return false;
				}
			}
			
			else
			{
				$message = JText::_('COM_JUDOWNLOAD_NO_DOCUMENT_TO_DOWNLOAD');
				$this->setRedirect($this->getReturnPage(), $message, 'error');

				return false;
			}
		}
	}
Esempio n. 19
0
	public function onCopy($toDocumentId, &$fieldData = array())
	{
		if ($this->doc_id && isset($fieldData[$this->id]))
		{
			$copiedDocumentObject = JUDownloadHelper::getDocumentById($toDocumentId);
			$fieldData[$this->id] = $copiedDocumentObject->icon;
		}
	}
Esempio n. 20
0
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.multiselect');
if (JUDownloadHelper::isJoomla3x()) {
    $classTooltip = "hasTooltip";
    $separator = "<br/>";
    JHtml::_('bootstrap.tooltip');
} else {
    JHtml::_('behavior.tooltip');
    $separator = "::";
    $classTooltip = "hasTip";
}
$session = JFactory::getSession();
$copied_document_id = $session->get('copied_document_id');
$documents = array();
foreach ($copied_document_id as $doc_id) {
    $documents[] = JUDownloadHelper::getDocumentById($doc_id);
}
?>
<script type="text/javascript">
	Joomla.submitbutton = function (task) {
		var category = document.getElementsByName("categories[]")[0].value;
		if (task == 'documents.copyDocuments' && category == '') {
			alert("<?php 
echo JText::_('COM_JUDOWNLOAD_PLEASE_SELECT_CATEGORY');
?>
");
			return false;
		}

		Joomla.submitform(task, document.getElementById('adminForm'));
	};
Esempio n. 21
0
 public function docChangeCategory()
 {
     $app = JFactory::getApplication();
     if ($app->input->get('action', '') == 'update-maincat') {
         $ori_cat_id = $app->input->getInt('ori_cat_id', 0);
         $ori_cat = JUDownloadHelper::getCategoryById($ori_cat_id);
         $data['ori_field_group_id'] = 0;
         $data['new_field_group_id'] = 0;
         $data['new_field_group_name'] = "";
         $data['path'] = "";
         if ($ori_cat) {
             $data['ori_field_group_id'] = $ori_cat->fieldgroup_id;
         }
         $new_cat_id = $app->input->getInt('new_cat_id', 0);
         $rootCat = JUDownloadFrontHelperCategory::getRootCategory();
         $params = JUDownloadHelper::getParams();
         if ($rootCat->id == $new_cat_id && !$params->get('allow_add_doc_to_root', 0)) {
             return "";
         }
         $new_cat = JUDownloadHelper::getCategoryById($new_cat_id);
         if ($new_cat) {
             $db = JFactory::getDbo();
             $query = "SELECT id, name FROM #__judownload_fields_groups WHERE id = " . $new_cat->fieldgroup_id . " AND published = 1";
             $db->setQuery($query);
             $fieldgroup = $db->loadObject();
             if ($fieldgroup) {
                 $data['new_field_group_id'] = $fieldgroup->id;
                 $data['new_field_group_name'] = $fieldgroup->name;
             }
             $data['path'] = JUDownloadHelper::generateCategoryPath($new_cat_id);
         }
         if ($data['ori_field_group_id'] != $data['new_field_group_id']) {
             $data['msg_field_group'] = JText::_('COM_JUDOWNLOAD_CHANGE_MAIN_CATEGORY_CAUSE_CHANGE_FIELD_GROUP_WARNING');
         }
         $documentId = $app->input->getInt('id', 0);
         $data['message_style'] = JText::_('COM_JUDOWNLOAD_INHERIT');
         if ($documentId) {
             $documentObject = JUDownloadHelper::getDocumentById($documentId);
             if ($documentObject->style_id == -1) {
                 $oldStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($documentId->cat_id);
                 $newStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($new_cat->id);
                 if ($oldStyleObject->template_id != $newStyleObject->template_id) {
                     $data['msg_style'] = JText::_('COM_JUDOWNLOAD_CHANGE_MAIN_CATEGORY_CAUSE_CHANGE_TEMPLATE_WARNING');
                 }
             }
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($new_cat->id);
             $data['message_style'] = JText::_('COM_JUDOWNLOAD_INHERIT') . ' (' . $newTemplateStyleObject->title . ' [' . $newTemplateStyleObject->template_title . ' ]' . ')';
         }
         return json_encode($data);
     } elseif ($app->input->getInt('action', '') == 'insert_secondary_cat') {
         $cat_id_str = $app->input->get('secondary_cat_id', '', 'string');
         $html = '';
         if (!empty($cat_id_str)) {
             $cat_id_arr = explode(",", $cat_id_str);
             foreach ($cat_id_arr as $key => $cat_id) {
                 $html .= "<li id=\"cat-" . $cat_id . "\"><a class=\"drag-icon\"></a><span>" . JUDownloadHelper::generateCategoryPath($cat_id) . "</span><a href=\"#\" onclick=\"return false\" class=\"remove-secondary-cat\" ><i class=\"icon-minus fa fa-minus-circle\"></i> " . JText::_('COM_JUDOWNLOAD_REMOVE') . "</a></li>";
             }
         }
         return $html;
     }
 }
Esempio n. 22
0
 protected function getInput()
 {
     $clientId = $this->element['client_id'];
     if (is_null($clientId) && $this->form instanceof JForm) {
         $clientId = $this->form->getValue('client_id');
     }
     $clientId = (int) $clientId;
     $client = JApplicationHelper::getClientInfo($clientId);
     $extn = (string) $this->element['extension'];
     if (empty($extn) && $this->form instanceof JForm) {
         $extn = $this->form->getValue('extension');
     }
     $extn = preg_replace('#\\W#', '', $extn);
     $template = (string) $this->element['template'];
     $template = preg_replace('#\\W#', '', $template);
     if ($this->form instanceof JForm) {
         $template_style_id = $this->form->getValue('template_style_id');
     }
     $template_style_id = preg_replace('#\\W#', '', $template_style_id);
     $view = (string) $this->element['view'];
     $view = preg_replace('#\\W#', '', $view);
     if ($extn && $view && $client) {
         $lang = JFactory::getLanguage();
         $lang->load($extn . '.sys', JPATH_ADMINISTRATOR, null, false, false) || $lang->load($extn . '.sys', JPATH_ADMINISTRATOR . '/components/' . $extn, null, false, false) || $lang->load($extn . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extn . '.sys', JPATH_ADMINISTRATOR . '/components/' . $extn, $lang->getDefault(), false, false);
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('e.element, e.name');
         $query->from('#__extensions AS e');
         $query->where('e.client_id = ' . (int) $clientId);
         $query->where('e.type = ' . $db->quote('template'));
         $query->where('e.enabled = 1');
         if ($template) {
             $query->where('e.element = ' . $db->quote($template));
         }
         if ($template_style_id) {
             $query->join('LEFT', '#__template_styles AS s ON s.template=e.element');
             $query->where('s.id=' . (int) $template_style_id);
         }
         $db->setQuery($query);
         $templates = $db->loadObjectList('element');
         if ($db->getErrorNum()) {
             JError::raiseWarning(500, $db->getErrorMsg());
         }
         $component_path = JPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl');
         $component_layouts = array();
         $groups = array();
         $items = array();
         if ($this->element['useinherit']) {
             $groups['inherit'] = array();
             $groups['inherit']['id'] = $this->id . '_inherit';
             $groups['inherit']['text'] = '---' . JText::_('COM_JUDOWNLOAD_INHERIT') . '---';
             $groups['inherit']['items'] = array();
         }
         if (is_dir($component_path) && ($component_layouts = JFolder::files($component_path, '^[^_]*\\.xml$', false, true))) {
             $groups['_'] = array();
             $groups['_']['id'] = $this->id . '__';
             $groups['_']['text'] = JText::sprintf('JOPTION_FROM_COMPONENT');
             $groups['_']['items'] = array();
             foreach ($component_layouts as $i => $file) {
                 if (!($xml = simplexml_load_file($file))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 if (!($menu = $xml->xpath('layout[1]'))) {
                     unset($component_layouts[$i]);
                     continue;
                 }
                 $menu = $menu[0];
                 $value = JFile::stripext(JFile::getName($file));
                 $component_layouts[$i] = $value;
                 $text = isset($menu['option']) ? JText::_($menu['option']) : (isset($menu['title']) ? JText::_($menu['title']) : $value);
                 $groups['_']['items'][] = JHtml::_('select.option', '_:' . $value, $text);
                 $items['_'][$value] = $text;
             }
         }
         $attr = $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
         if ($this->element['useinherit']) {
             $appendInherit = "";
             $app = JFactory::getApplication();
             if ($app->input->get('view', '') == "document" && $this->form->getValue("id")) {
                 $doc = JUDownloadHelper::getDocumentById($this->form->getValue("id"));
                 if ($doc) {
                     $appendInherit = $this->calculatorInheritLayout($items, $doc->cat_id);
                 }
             } elseif ($app->input->get('view', '') == "category") {
                 if ($this->form->getValue("parent_id")) {
                     $appendInherit = $this->calculatorInheritLayout($items, $this->form->getValue("parent_id"));
                 }
             }
             $appendGlodbal = $this->getLayout($items);
             $groups['inherit']['items'][] = JHtml::_('select.option', '-2', 'Global config ' . $appendGlodbal);
             $groups['inherit']['items'][] = JHtml::_('select.option', '-1', 'Inherit category ' . $appendInherit);
         }
         $selected = array($this->value);
         return JHtml::_('select.groupedlist', $groups, $this->name, array('id' => $this->id, 'group.id' => 'id', 'list.attr' => $attr, 'list.select' => $selected));
     } else {
         return '';
     }
 }
Esempio n. 23
0
	public function updateRating($data)
	{
		$user          = JFactory::getUser();
		$created       = JFactory::getDate()->toSql();
		$criteriaArray = isset($data['criteria_array']) ? $data['criteria_array'] : array();
		$docId         = $data['doc_id'];
		$commentId     = $data['comment_id'];

		$ratingObj      = $this->getRating($docId, $commentId);
		$ratingId       = $ratingObj->id;
		$ratingScoreOld = $ratingObj->score;
		$ratingScoreNew = JUDownloadFrontHelperRating::calculateRatingScore($data, $docId, $criteriaArray);

		
		$dataRating = array(
			'id'    => $ratingId, 'user_id' => $user->id, 'comment_id' => $commentId,
			'score' => $ratingScoreNew, 'created' => $created, 'doc_id' => $docId
		);

		JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
		$ratingTable = JTable::getInstance('Rating', 'JUDownloadTable');
		$ratingTable->bind($dataRating);

		if (!$ratingTable->check())
		{
			return false;
		}

		$ratingStore = $ratingTable->store();
		if (!$ratingStore)
		{
			return false;
		}

		if ($ratingStore && count($criteriaArray) > 0)
		{
			$oldCriteriaIdArr = $this->getCriteriasId($ratingId);
			$criteriaIdArr    = array();
			foreach ($criteriaArray AS $criteria)
			{
				$criteriaIdArr[] = $criteria->id;
			}
			
			$flagUpdate = false;
			if (count(array_diff($criteriaIdArr, $oldCriteriaIdArr)) == 0)
			{
				$flagUpdate = true;
			}
			if ($flagUpdate == false)
			{
				$this->deleteCriteriasByRatingId($ratingId);
			}
			foreach ($criteriaArray AS $criteria)
			{
				if ($flagUpdate == true)
				{
					$this->updateCriteriaValue($ratingId, $criteria->id, $criteria->value);
				}
				else
				{
					JUDownloadMultiRating::insertCriteriaValue($ratingId, $criteria->id, $criteria->value);
				}
			}
		}
		$documentItem = JUDownloadHelper::getDocumentById($docId);
		$rating       = (($documentItem->rating * $documentItem->total_votes) + $ratingScoreNew - $ratingScoreOld) / $documentItem->total_votes;

		
		$db    = JFactory::getDbo();
		$query = $db->getQuery(true);
		$query->update('#__judownload_documents');
		$query->set('rating = ' . $rating);
		$query->where('id = ' . $docId);
		$db->setQuery($query);
		$db->execute();

		$session      = JFactory::getSession();
		$timeNow      = JFactory::getDate()->toSql();
		$timeNowStamp = strtotime($timeNow);
		
		$inputCookie   = JFactory::getApplication()->input->cookie;
		$config        = JFactory::getConfig();
		$cookie_domain = $config->get('cookie_domain', '');
		$cookie_path   = $config->get('cookie_path', '/');
		
		$inputCookie->set('judl-document-rated-' . $docId, $timeNowStamp, time() + 864000, $cookie_path, $cookie_domain);
		
		$session->set('judl-document-rated-' . $docId, $timeNowStamp);

		
		$logData = array(
			'user_id'   => $user->id,
			'event'     => 'document.rate',
			'item_id'   => $docId,
			'doc_id'    => $docId,
			'value'     => $ratingScoreNew,
			'reference' => $ratingTable->id
		);

		JUDownloadFrontHelperLog::addLog($logData);

		return true;

	}
Esempio n. 24
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;
				}
			}
		}
	}
Esempio n. 25
0
	public static function getDocumentSegment($documentId, &$query, $params)
	{
		if (isset($query['Itemid']))
		{
			unset($query['Itemid']);
		}

		$fullPathDocument = $params->get('sef_document_full_path', 0);

		$documentObject = JUDownloadHelper::getDocumentById($documentId);
		$mainCategoryId = $documentObject->cat_id;
		$segment        = JUDownloadHelperRoute::getCategorySegment($mainCategoryId, $query, $fullPathDocument);
		$segment[]      = $documentId . ":" . (isset($documentObject->alias) ? $documentObject->alias : '');

		return $segment;
	}
Esempio n. 26
0
	public static function canRateDocument($documentId)
	{
		$documentObject = JUDownloadHelper::getDocumentById($documentId);
		if (!is_object($documentObject))
		{
			return false;
		}

		$params = JUDownloadHelper::getParams(null, $documentId);
		if (!$params->get('enable_document_rate', 1))
		{
			return false;
		}

		$userCanViewDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true);
		if (!$userCanViewDocument)
		{
			return false;
		}

		$ratingField = new JUDownloadFieldCore_rating();
		if (!$ratingField->canView())
		{
			return false;
		}

		$user            = JFactory::getUser();
		$criteriaGroupId = JUDownloadFrontHelperCriteria::getCriteriaGroupIdByCategoryId($documentObject->cat_id);
		if ($criteriaGroupId == 0 || !JUDownloadHelper::hasMultiRating())
		{
			$assetName = 'com_judownload.category.' . $documentObject->cat_id;
			
			if ($user->authorise('judl.single.rate', $assetName) || (JUDownloadFrontHelperPermission::canDownloadDocument($documentId) && $params->get('can_download_can_rate', 0)))
			{
				if ($user->authorise('judl.single.rate.many_times', $assetName))
				{
					return true;
				}
				else
				{
					
					if ($user->get('guest'))
					{
						$session = JFactory::getSession();
						if (!$session->has('judl-document-rated-' . $documentId))
						{
							return true;
						}
					}
					
					else
					{
						$totalVoteTimes = JUDownloadFrontHelperRating::getTotalDocumentVotesOfUser($user->id, $documentId);
						if ($totalVoteTimes == 0)
						{
							return true;
						}
					}
				}
			}
		}
		else
		{
			$assetName = 'com_judownload.criteriagroup.' . $criteriaGroupId;
			
			if ($user->authorise('judl.criteria.rate', $assetName) || (JUDownloadFrontHelperPermission::canDownloadDocument($documentId) && $params->get('can_download_can_rate', 0)))
			{
				if ($user->authorise('judl.criteria.rate.many_times', $assetName))
				{
					return true;
				}
				else
				{
					
					if ($user->get('guest'))
					{
						$session = JFactory::getSession();
						if (!$session->has('judl-document-rated-' . $documentId))
						{
							return true;
						}
					}
					
					else
					{
						$totalVoteTimes = JUDownloadFrontHelperRating::getTotalDocumentVotesOfUser($user->id, $documentId);
						if ($totalVoteTimes == 0)
						{
							return true;
						}
					}
				}
			}
		}

		return false;
	}
Esempio n. 27
0
		<th style="width: 15%"><?php 
echo JText::_('COM_JUDOWNLOAD_FIELD_DOWNLOADED');
?>
</th>
	</tr>
	</thead>
	<tbody>
	<?php 
foreach ($lastDownloadedDocuments as $item) {
    $link = 'index.php?option=com_judownload&amp;task=document.edit&amp;id=' . $item->document_id;
    $checked_out = $item->checked_out ? JHtml::_('jgrid.checkedout', $item->document_id, $item->checked_out_name, $item->checked_out_time, 'documents.', false) : '';
    ?>
		<tr>
			<td><?php 
    if ($item->log_reference == 'external') {
        $documentObject = JUDownloadHelper::getDocumentById($item->document_id);
        echo $documentObject->external_link;
    } else {
        echo JUDownloadHelper::getFileNames($item->log_reference, false);
    }
    ?>
			</td>
			<td><?php 
    echo $checked_out;
    ?>
				<a href="<?php 
    echo $link;
    ?>
" title="<?php 
    echo $item->document_title;
    ?>
Esempio n. 28
0
 public function downloadFile()
 {
     JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     $fileId = $app->input->get('fileId', 0);
     $db = JFactory::getDbo();
     $query = 'SELECT `doc_id`, `file_name`, `rename` FROM #__judownload_files WHERE id = ' . $fileId;
     $db->setQuery($query);
     $file = $db->loadObject();
     if ($file) {
         $documentObject = JUDownloadHelper::getDocumentById($file->doc_id);
         $fileDirectory = JUDownloadFrontHelper::getDirectory('file_directory', 'media/com_judownload/files/');
         $version = $app->input->get('version', '');
         if (!$version || $version === $documentObject->version) {
             $filePath = JPATH_SITE . '/' . $fileDirectory . $file->doc_id . '/' . $file->file_name;
         } else {
             $query = "SELECT file_path FROM #__judownload_versions WHERE file_id = " . $fileId . " AND version = " . $db->quote($version);
             $db->setQuery($query);
             $versionFilePath = $db->loadResult();
             if (!$versionFilePath) {
                 return false;
             }
             $filePath = JPATH_SITE . '/' . $fileDirectory . $file->doc_id . '/' . $versionFilePath;
         }
         $filePath = JPath::clean($filePath);
         $downloadResult = JUDownloadHelper::downloadFile($filePath, $file->rename, 'php', '2048', true, true);
         if ($downloadResult !== true) {
             $this->setError($downloadResult);
             return false;
         }
     }
     return true;
 }