예제 #1
1
 protected function getInput()
 {
     $html = '';
     $db = JFactory::getDbo();
     $options = JUDownloadHelper::getFieldGroupOptions();
     if ($this->element['usenone'] == 'true') {
         array_unshift($options, array('value' => '0', 'text' => JText::_('COM_JUDOWNLOAD_NONE')));
     }
     if ($this->element['useinherit'] == 'true') {
         $appendInherit = "";
         if ($this->form->getValue("id")) {
             $appendInherit = " ( " . JText::_('COM_JUDOWNLOAD_NONE') . " )";
             if ($this->form->getValue("id") > 0) {
                 $catObj = JUDownloadHelper::getCategoryById($this->form->getValue("parent_id"));
                 if ($catObj->fieldgroup_id > 1) {
                     $query = "SELECT name, published FROM #__judownload_fields_groups WHERE id = " . (int) $catObj->fieldgroup_id . " AND id != 1";
                     $db->setQuery($query);
                     $fieldgroup = $db->loadObject();
                     $groupName = $fieldgroup->published != 1 ? "[" . $fieldgroup->name . "]" : $fieldgroup->name;
                     $appendInherit = "( " . $groupName . " )";
                 }
             }
         }
         array_unshift($options, array('value' => '-1', 'text' => JText::_('COM_JUDOWNLOAD_INHERIT') . $appendInherit));
     } else {
         array_unshift($options, array('value' => '', 'text' => JText::_('COM_JUDOWNLOAD_SELECT_FIELD_GROUP')));
     }
     $required_class = $this->element['required'] == 'true' ? 'required' : '';
     $attributes = "class=\"inputbox {$required_class}\"";
     $html .= JHtml::_('select.genericlist', $options, $this->name, $attributes, 'value', 'text', $this->value, $this->id);
     return $html;
 }
예제 #2
0
	public static function getCriteriaGroupIdByCategoryId($mainCatId)
	{
		$catObj = JUDownloadHelper::getCategoryById($mainCatId);
		if ($catObj)
		{
			return $catObj->criteriagroup_id;
		}

		return null;
	}
 protected function calculatorInheritStyle($cat_id)
 {
     do {
         $category = JUDownloadHelper::getCategoryById($cat_id);
         $style_id = $category->style_id;
         $cat_id = $category->parent_id;
     } while ($style_id == -1 && $cat_id != 0);
     if ($style_id == -2) {
         return $this->getStyle();
     } else {
         return $this->getStyle($style_id);
     }
 }
예제 #4
0
 protected function getInput()
 {
     $db = JFactory::getDbo();
     $query = 'SELECT id AS value, name AS text, published FROM #__judownload_criterias_groups ';
     $db->setQuery($query);
     $options = $db->loadObjectList();
     $users = JFactory::getUser();
     foreach ($options as $key => $option) {
         if ($option->published != 1) {
             $option->text = '[ ' . $option->text . ' ]';
         }
         if (!$users->authorise('core.create', 'com_judownload.criteriagroup.' . $option->value)) {
             unset($options[$key]);
         }
     }
     $required_class = $this->element['required'] == 'true' ? 'required' : '';
     $class = $this->element['class'];
     if ($this->element['usenone'] == 'true') {
         array_unshift($options, array('value' => '0', 'text' => JText::_('COM_JUDOWNLOAD_NONE')));
     }
     if ($this->element['useinherit'] == 'true') {
         $appendInherit = "";
         if ($this->form->getValue("id")) {
             if ($this->form->getValue("criteriagroup_id") > 0) {
                 $appendInherit = $this->getCriteriaGroupName($this->form->getValue("criteriagroup_id"));
             } else {
                 $category = JUDownloadHelper::getCategoryById($this->form->getValue("id"));
                 $parent = JUDownloadHelper::getCategoryById($category->parent_id);
                 $appendInherit = $this->getCriteriaGroupName($parent->criteriagroup_id);
             }
         }
         array_unshift($options, array('value' => '-1', 'text' => JText::_('COM_JUDOWNLOAD_INHERIT') . $appendInherit));
     } else {
         array_unshift($options, array('value' => '', 'text' => JText::_('COM_JUDOWNLOAD_SELECT_CRITERIAL_GROUP')));
     }
     $canChange = true;
     if ($this->form->getValue('id')) {
         $query = "SELECT COUNT(*) FROM #__judownload_criterias_values WHERE criteria_id = " . $this->form->getValue('id');
         $db->setQuery($query);
         $canChange = $db->loadResult() ? false : true;
     }
     if ($canChange) {
         $attributes = "class=\"inputbox {$class} {$required_class}\"";
         $html = JHtml::_('select.genericlist', $options, $this->name, $attributes, 'value', 'text', $this->value, $this->id);
     } else {
         $attributes = "class=\"inputbox {$class}\" disabled";
         $html = JHtml::_('select.genericlist', $options, "_" . $this->name, $attributes, 'value', 'text', $this->value, $this->id);
         $html .= "<input class=\"{$required_class}\" type=\"hidden\" value=\"" . $this->value . "\" name=\"" . $this->name . "\" />";
     }
     return $html;
 }
 protected function getInput()
 {
     $db = JFactory::getDbo();
     $query = 'SELECT id AS value, name AS text, published FROM #__judownload_criterias_groups ';
     $db->setQuery($query);
     $options = $db->loadObjectList();
     if (!empty($options)) {
         foreach ($options as $option) {
             if ($option->published != 1) {
                 $option->text = "[" . $option->text . "]";
             }
         }
     }
     $users = JFactory::getUser();
     $required_class = $this->element['required'] == 'true' ? 'required' : '';
     $class = $this->element['class'];
     $attributes = "class=\"inputbox {$class} {$required_class}\"";
     if ($this->element['usenone'] == 'true') {
         array_unshift($options, array('value' => '0', 'text' => JText::_('COM_JUDOWNLOAD_NONE')));
     }
     if ($this->element['useinherit'] == 'true') {
         $appendInherit = "";
         if ($this->form->getValue("id")) {
             if ($this->form->getValue("criteriagroup_id") > 0) {
                 $appendInherit = $this->getCriteriaGroupName($this->form->getValue("criteriagroup_id"));
             } else {
                 $category = JUDownloadHelper::getCategoryById($this->form->getValue("id"));
                 $parent = JUDownloadHelper::getCategoryById($category->parent_id);
                 $appendInherit = $this->getCriteriaGroupName($parent->criteriagroup_id);
             }
         }
         array_unshift($options, array('value' => '-1', 'text' => JText::_('COM_JUDOWNLOAD_INHERIT') . $appendInherit));
     } else {
         array_unshift($options, array('value' => '', 'text' => JText::_('COM_JUDOWNLOAD_SELECT_CRITERIAL_GROUP')));
     }
     $html = JHtml::_('select.genericlist', $options, $this->name, $attributes, 'value', 'text', $this->value, $this->id);
     return $html;
 }
예제 #6
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);
 }
예제 #7
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;
     }
 }
예제 #8
0
 case "featured":
     echo '<td>';
     echo JHtml::_('judownloadadministrator.featured', $item->featured, $i, $canChange, 'categories');
     echo '</td>';
     break;
 case "rel_cats":
     echo '<td>';
     $rel_categories = $model->getRelatedCategories($item->id);
     if ($rel_categories) {
         echo implode(", ", $rel_categories);
     }
     echo '</td>';
     break;
 case "parent_id":
     echo '<td>';
     $_category = JUDownloadHelper::getCategoryById($item->parent_id);
     if ($_category) {
         echo $_category->title;
     }
     echo '</td>';
     break;
 case "intro_image":
 case "detail_image":
     echo '<td>';
     if ($item->images) {
         $imgObj = json_decode($item->images);
         if (isset($imgObj->{$field}) && $imgObj->{$field}) {
             $image_path = $field == "intro_image" ? $intro_image_path : $detail_image_path;
             echo '<a class="modal" href="' . $image_path . $imgObj->{$field} . '"><img src="' . $image_path . $imgObj->{$field} . '" style="max-width:30px; max-height:30px" /></a>';
         } else {
             echo ' ';
예제 #9
0
	public function PHPValidate($values)
	{
		$rootCat = JUDownloadFrontHelperCategory::getRootCategory();
		
		if (isset($this->doc) && $this->doc->cat_id)
		{
			$params = JUDownloadHelper::getParams($this->doc->cat_id);
		}
		else
		{
			$params = JUDownloadHelper::getParams(null, $this->doc_id);
		}

		$mainCatId       = $values['main'];
		$secondaryCatIds = array_filter(explode(",", $values['secondary']));

		if (!$mainCatId)
		{
			return JText::_("COM_JUDOWNLOAD_PLEASE_SELECT_A_CATEGORY");
		}

		if ($mainCatId == $rootCat->id && !$params->get('allow_add_doc_to_root', 0))
		{
			return JText::_("COM_JUDOWNLOAD_CAN_NOT_ADD_DOCUMENT_TO_ROOT_CATEGORY");
		}

		if (!JUDownloadHelper::getCategoryById($mainCatId))
		{
			return JText::_("COM_JUDOWNLOAD_INVALID_CATEGORY");
		}

		if (1 && (count($secondaryCatIds) + 1 > 1))
		{
			return JText::sprintf("COM_JUDOWNLOAD_NUMBER_OF_CATEGORY_OVER_MAX_N_CATEGORIES", 1);
		}

		if (!$this->doc_id)
		{
			
			if (!JUDownloadFrontHelperPermission::canSubmitDocument($mainCatId))
			{
				$category = JUDownloadHelper::getCategoryById($mainCatId);

				return JText::sprintf("COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_SUBMIT_DOCUMENT_TO_THIS_CATEGORY", $category->title);
			}
		}
		else
		{
			$mainCatIdDB = JUDownloadFrontHelperCategory::getMainCategoryId($this->doc_id);

			
			if ($mainCatId != $mainCatIdDB)
			{
				
				if (!JUDownloadFrontHelperPermission::canSubmitDocument($mainCatId))
				{
					$category = JUDownloadHelper::getCategoryById($mainCatId);

					return JText::sprintf("COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_SUBMIT_DOCUMENT_TO_THIS_CATEGORY", $category->title);
				}
			}

			$app = JFactory::getApplication();
			
			if ($app->isSite())
			{
				
				if ($mainCatId != $mainCatIdDB)
				{
					if (!$params->get('can_change_main_category', 1))
					{
						return false;
					}
				}

				
				if (!$params->get('can_change_secondary_categories', 1))
				{
					$secondaryCatIdsDB = $this->getSecondaryCategoryIds($this->doc_id);
					if (count($secondaryCatIds) && count($secondaryCatIdsDB))
					{
						if (array_diff($secondaryCatIds, $secondaryCatIdsDB) || array_diff($secondaryCatIdsDB, $secondaryCatIds))
						{
							return false;
						}
					}
				}
			}
		}

		return true;
	}
예제 #10
0
 protected function calculatorInheritLayout($items, $cat_id)
 {
     do {
         $category = JUDownloadHelper::getCategoryById($cat_id);
         $layout = $category->layout;
         $cat_id = $category->parent_id;
     } while ($layout == -1);
     if ($layout == -2) {
         return $this->getLayout($items);
     } else {
         return $this->getLayout($items, $layout);
     }
 }
예제 #11
0
 public function moveDocuments($document_id_arr, $tocat_id, $move_option_arr = array())
 {
     $dispatcher = JDispatcher::getInstance();
     $user = JFactory::getUser();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables');
     $catTable = JTable::getInstance("Category", "JUDownloadTable");
     if ($tocat_id) {
         if (!$catTable->load($tocat_id)) {
             JError::raiseWarning(500, JText::_('COM_JUDOWNLOAD_TARGET_CATEGORY_NOT_FOUND'));
             return false;
         }
         $table = $this->getTable();
         $db = JFactory::getDbo();
         $assetName = 'com_judownload.category.' . (int) $tocat_id;
         $query = 'SELECT id FROM #__assets WHERE name="' . $assetName . '"';
         $db->setQuery($query);
         $tocat_asset_id = $db->loadResult();
         $canCreate = $user->authorise('judl.document.create', $assetName);
         if (!$canCreate) {
             JError::raiseError(100, JText::sprintf('COM_JUDOWNLOAD_CAN_NOT_CREATE_DOCUMENT_IN_THIS_CATEGORY', $catTable->title));
             return false;
         }
     } else {
         JError::raiseWarning(500, JText::_('COM_JUDOWNLOAD_NO_TARGET_CATEGORY_SELECTED'));
         return false;
     }
     if (empty($document_id_arr)) {
         JError::raiseError(100, JText::_('COM_JUDOWNLOAD_NO_ITEM_SELECTED'));
         return false;
     }
     set_time_limit(0);
     $moved_documents = array();
     foreach ($document_id_arr as $doc_id) {
         if (!$table->load($doc_id)) {
             continue;
         }
         $assetName = 'com_judownload.document.' . (int) $doc_id;
         $canDoEdit = $user->authorise('judl.document.edit', $assetName);
         if (!$canDoEdit) {
             if (!$user->id) {
                 JError::raiseWarning(100, JText::sprintf('COM_JUDOWNLOAD_YOU_DONT_HAVE_PERMISSION_TO_ACCESS_DOCUMENT', $table->title));
                 continue;
             } else {
                 if ($user->id == $table->created_by) {
                     $canDoEditOwn = $user->authorise('judl.document.edit.own', $assetName);
                     if (!$canDoEditOwn) {
                         JError::raiseWarning(100, JText::sprintf('COM_JUDOWNLOAD_YOU_DONT_HAVE_PERMISSION_TO_ACCESS_DOCUMENT', $table->title));
                         continue;
                     }
                 }
             }
         }
         $query = "SELECT cat_id FROM #__judownload_documents_xref WHERE doc_id = " . $doc_id . " AND main=1";
         $db->setQuery($query);
         $cat_id = $db->loadResult();
         if ($tocat_id == $cat_id) {
             continue;
         }
         $result = $dispatcher->trigger($this->onContentBeforeMove, array($this->option . '.' . $this->name, $table, $tocat_id, $move_option_arr));
         if (in_array(false, $result, true)) {
             $this->setError($table->getError());
             return false;
         }
         if ($table->style_id == -1) {
             $oldTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($cat_id);
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($tocat_id);
             if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id) {
                 if (in_array('keep_template_params', $move_option_arr)) {
                     $table->style_id = $oldTemplateStyleObject->id;
                 } else {
                     $query = "UPDATE #__judownload_documents SET template_params = '' WHERE id=" . $doc_id;
                     $db->setQuery($query);
                     $db->execute();
                 }
             }
         }
         $query = "SELECT COUNT(*) FROM #__judownload_documents_xref WHERE cat_id=" . $tocat_id . " AND doc_id=" . $doc_id . " AND main=0";
         $db->setQuery($query);
         $is_secondary_cat = $db->loadResult();
         if ($is_secondary_cat) {
             $query = "DELETE FROM #__judownload_documents_xref WHERE doc_id=" . $doc_id . " AND main=1";
             $db->setQuery($query);
             $db->execute();
             $query = "UPDATE #__judownload_documents_xref SET main=1 WHERE cat_id=" . $tocat_id . " AND doc_id=" . $doc_id;
             $db->setQuery($query);
             $db->execute();
         } else {
             $query = "UPDATE #__judownload_documents_xref SET cat_id=" . $tocat_id . " WHERE doc_id=" . $doc_id . " AND main=1";
             $db->setQuery($query);
             $db->execute();
         }
         if (in_array('keep_permission', $move_option_arr)) {
             $query = 'UPDATE #__assets SET `parent_id` = ' . $tocat_asset_id . ' WHERE name="com_judownload.document.' . $doc_id . '"';
             $db->setQuery($query);
             $db->execute();
         } else {
             $query = 'UPDATE #__assets SET `parent_id` = ' . $tocat_asset_id . ', `rules` = "{}" WHERE name="com_judownload.document.' . $doc_id . '"';
             $db->setQuery($query);
             $db->execute();
         }
         $moved_documents[] = $doc_id;
         $this->cleanCache();
         $dispatcher->trigger($this->onContentAfterMove, array($this->option . '.' . $this->name, $table, $tocat_id, $move_option_arr));
     }
     $total_moved_documents = count($moved_documents);
     if ($total_moved_documents) {
         $old_field_groupid = JUDownloadHelper::getCategoryById($cat_id)->fieldgroup_id;
         $new_field_groupid = JUDownloadHelper::getCategoryById($tocat_id)->fieldgroup_id;
         $keep_extra_fields = in_array("keep_extra_fields", $move_option_arr);
         if ($keep_extra_fields) {
             $keep_extra_fields = $old_field_groupid == $new_field_groupid ? true : false;
         }
         if (!$keep_extra_fields) {
             foreach ($moved_documents as $doc_id) {
                 JUDownloadHelper::deleteFieldValuesOfDocument($doc_id);
             }
         }
         $old_criteria_groupid = JUDownloadHelper::getCategoryById($cat_id)->criteriagroup_id;
         $new_criteria_groupid = JUDownloadHelper::getCategoryById($tocat_id)->criteriagroup_id;
         $keep_rates = in_array("keep_rates", $move_option_arr);
         if ($keep_rates) {
             $keep_rates = $old_criteria_groupid == $new_criteria_groupid ? true : false;
         }
         if (!$keep_rates) {
             JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judownload/tables");
             $ratingTable = JTable::getInstance("Rating", "JUDownloadTable");
             foreach ($moved_documents as $doc_id) {
                 $query = "SELECT id FROM #__judownload_rating WHERE doc_id = " . $doc_id;
                 $db->setQuery($query);
                 $ratingIds = $db->loadColumn();
                 foreach ($ratingIds as $ratingId) {
                     $ratingTable->delete($ratingId);
                 }
             }
         }
     }
     return $total_moved_documents;
 }
예제 #12
0
 protected function getInput()
 {
     $html = '';
     $db = JFactory::getDbo();
     $core_plugin = false;
     if ($this->form->getValue("id") && $this->form->getValue("plugin_id")) {
         $query = "SELECT core FROM #__judownload_plugins WHERE id = " . $this->form->getValue("plugin_id");
         $db->setQuery($query);
         $core_plugin = $db->loadResult();
     }
     if ($core_plugin) {
         $query = "SELECT name FROM #__judownload_fields_groups WHERE id = " . $this->value;
         $db->setQuery($query);
         $group_name = $db->loadResult();
         $html .= '<span class="readonly">' . $group_name . '</span>';
         $html .= '<input type="hidden" name="' . $this->name . '" value="1" />';
     } else {
         $document = JFactory::getDocument();
         $script = "function changeFieldGroup(self, select ,value){\r\n\t\t\t\t\t\t\tif(value){\r\n\t\t\t\t\t\t\t\tif (self.value != select){ alert('" . JText::_('COM_JUDOWNLOAD_CHANGE_FIELD_GROUP_WARNING') . "');}\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\treturn true;\r\n\t\t\t\t\t\t}";
         $document->addScriptDeclaration($script);
         $app = JFactory::getApplication();
         if ($app->input->get('view') == 'field') {
             $options = JUDownloadHelper::getFieldGroupOptions(true, false);
         } else {
             $options = JUDownloadHelper::getFieldGroupOptions();
         }
         if ($this->element['usenone'] == 'true') {
             array_unshift($options, array('value' => '0', 'text' => JText::_('COM_JUDOWNLOAD_NONE')));
         }
         if ($this->element['useinherit'] == 'true') {
             $appendInherit = "";
             if ($this->form->getValue("id")) {
                 $appendInherit = " ( " . JText::_('COM_JUDOWNLOAD_NONE') . " )";
                 if ($this->form->getValue("id") > 0) {
                     $catObj = JUDownloadHelper::getCategoryById($this->form->getValue("parent_id"));
                     if ($catObj->fieldgroup_id > 1) {
                         $query = "SELECT name, published FROM #__judownload_fields_groups WHERE id = " . (int) $catObj->fieldgroup_id . " AND id != 1";
                         $db->setQuery($query);
                         $fieldgroup = $db->loadObject();
                         $groupName = $fieldgroup->published != 1 ? "[" . $fieldgroup->name . "]" : $fieldgroup->name;
                         $appendInherit = "( " . $groupName . " )";
                     }
                 }
             }
             array_unshift($options, array('value' => '-1', 'text' => JText::_('COM_JUDOWNLOAD_INHERIT') . $appendInherit));
         } else {
             array_unshift($options, array('value' => '', 'text' => JText::_('COM_JUDOWNLOAD_SELECT_FIELD_GROUP')));
         }
         $required_class = $this->element['required'] == 'true' ? 'required' : '';
         if ($app->input->get('view') == 'field') {
             $canChange = true;
             if ($this->form->getValue('id')) {
                 $query = "SELECT COUNT(*) FROM #__judownload_fields_values WHERE field_id = " . $this->form->getValue('id');
                 $db->setQuery($query);
                 $canChange = $db->loadResult() ? false : true;
             }
             if ($canChange) {
                 $attributes = "class=\"inputbox {$required_class}\"";
                 $html .= JHtml::_('select.genericlist', $options, $this->name, $attributes, 'value', 'text', $this->value, $this->id);
             } else {
                 $attributes = "class=\"inputbox\" disabled";
                 $html .= JHtml::_('select.genericlist', $options, "_" . $this->name, $attributes, 'value', 'text', $this->value, $this->id);
                 $html .= "<input class=\"{$required_class}\" type=\"hidden\" value=\"" . $this->value . "\" name=\"" . $this->name . "\" />";
             }
         } else {
             $onchange = "onchange=\"changeFieldGroup(this, " . $this->value . ", " . $this->form->getValue("fieldgroup_id") . " );\"";
             $attributes = "class=\"inputbox {$required_class}\" {$onchange}";
             $html .= JHtml::_('select.genericlist', $options, $this->name, $attributes, 'value', 'text', $this->value, $this->id);
         }
     }
     return $html;
 }
예제 #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;
	}
예제 #14
0
	public function parseCommentTxt($comment, $catId = 0, $docId = 0)
	{
		$user = JFactory::getUser();
		if ($user->get('guest'))
		{
			$userName = JText::_('COM_JUDOWNLOAD_GUEST');
		}
		else
		{
			$userName = $user->name;
		}

		$catTitle = $docTitle = '';

		
		if ($catId)
		{
			$catObj   = JUDownloadHelper::getCategoryById($catId);
			$catTitle = $catObj->title;
		}

		
		if ($docId)
		{
			$docObj   = JUDownloadHelper::getDocumentById($docId);
			$docTitle = $docObj->title;
		}

		$comment = str_replace("{user_id}", $user->id, $comment);
		if ($catTitle)
		{
			$comment = str_replace("{cat_title}", $catTitle, $comment);
		}
		else
		{
			$comment = str_replace("{cat_title}", '', $comment);
		}

		if ($docTitle)
		{
			$comment = str_replace("{doc_title}", $docTitle, $comment);
		}
		else
		{
			$comment = str_replace("{doc_title}", '', $comment);
		}

		$comment = str_replace("{user_name}", $userName, $comment);

		preg_match('/{date:?(.*?)}/', $comment, $matches);
		if (!empty($matches))
		{
			if (empty($matches[1]))
			{
				$dateFormat = 'Y-m-d H:i:s';
			}
			else
			{
				$dateFormat = $matches[1];
			}

			$timeNow = JHtml::date('now', 'Y-m-d H:i:s', true);
			$date    = date($dateFormat, strtotime($timeNow));
			$comment = str_replace($matches[0], $date, $comment);
		}

		return $comment;
	}
예제 #15
0
 public static function getFieldGroupsByCatIds($catIds, $search_sub_categories = false)
 {
     if (!$catIds) {
         return null;
     }
     $field_groups = array();
     foreach ($catIds as $catId) {
         if ($search_sub_categories) {
             $categoryTree = JUDownloadHelper::getCategoryTree($catId, true, true);
             foreach ($categoryTree as $sub_category) {
                 if ($sub_category->fieldgroup_id > 0) {
                     $field_groups[] = $sub_category->fieldgroup_id;
                 }
             }
         } else {
             $catObj = JUDownloadHelper::getCategoryById($catId);
             $field_groups[] = $catObj->fieldgroup_id ? $catObj->fieldgroup_id : 1;
         }
     }
     $field_groups = array_unique($field_groups);
     if ($field_groups) {
         return implode(",", $field_groups);
     } else {
         return null;
     }
 }
예제 #16
0
	public static function getCategoryDisplayParams($cat_id)
	{
		if (!$cat_id)
		{
			return false;
		}

		$params                = JUDownloadHelper::getParams($cat_id);
		$global_display_params = new JRegistry(isset($params->get('display_params')->cat) ? $params->get('display_params')->cat : array());
		$catObj                = JUDownloadHelper::getCategoryById($cat_id);
		$category_params       = $catObj->params;
		if ($category_params)
		{
			$category_params         = json_decode($category_params);
			$category_display_params = $category_params->display_params;
			if ($category_display_params)
			{
				foreach ($category_display_params AS $option => $value)
				{
					if ($value == -2)
					{
						unset($category_display_params->$option);
					}
				}

				$global_display_params->loadObject($category_display_params);
			}
		}

		return $global_display_params;
	}
예제 #17
0
JHtml::_('behavior.multiselect');
if (JUDownloadHelper::isJoomla3x()) {
    $classTooltip = "hasTooltip";
    $separator = "<br/>";
    JHtml::_('bootstrap.tooltip');
} else {
    JHtml::_('behavior.tooltip');
    $separator = "::";
    $classTooltip = "hasTip";
}
$session = JFactory::getSession();
$ignored_cat_id = $session->get('moved_cat_id_arr');
$move_cat_id_arr = $session->get('moved_cat_id_arr');
$categories = array();
foreach ($move_cat_id_arr as $cat_id) {
    $categories[] = JUDownloadHelper::getCategoryById($cat_id);
}
?>

<div class="jubootstrap">

	<div id="iframe-help"></div>

	<form action="<?php 
echo JRoute::_('index.php?option=com_judownload&view=documents');
?>
" method="post" name="adminForm" id="adminForm">
		<fieldset class="adminform">
			<legend><?php 
echo JText::_('COM_JUDOWNLOAD_MOVE_CATEGORIES');
?>
예제 #18
0
	public static function getCategorySegment($categoryId, &$query, $fullPath = 0)
	{
		if (isset($query['Itemid']))
		{
			unset($query['Itemid']);
		}
		$segments = array();
		$params   = JUDownloadHelper::getParams();

		$rootCategory = JUDownloadFrontHelperCategory::getRootCategory();

		$categoryObject = JUDownloadHelper::getCategoryById($categoryId);

		if (!is_object($categoryObject))
		{
			return false;
		}

		if ($categoryObject->level == 0)
		{
			$itemIdTreeRoot = JUDownloadHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
			if ($itemIdTreeRoot > 0)
			{
				$query['Itemid'] = $itemIdTreeRoot;

				return $segments;
			}

			$query['Itemid'] = JUDownloadHelperRoute::getHomeMenuItemId();

			
			$sefRootCategory = $rootCategory->id . ':' . $params->get('sef_root_cat', 'root');
			$segments[]      = JApplication::stringURLSafe($sefRootCategory);

			return $segments;
		}
		elseif ($categoryObject->level == 1)
		{
			
			$menuItemIdsOfViewCategoryTreeLevel1 = JUDownloadHelperRoute::getMenuItemIdArrayOfViewCategoryTreeLevel1();
			if (isset($menuItemIdsOfViewCategoryTreeLevel1[$categoryObject->id]))
			{
				$query['Itemid'] = $menuItemIdsOfViewCategoryTreeLevel1[$categoryObject->id];

				return $segments;
			}

			
			$itemIdTreeRoot = JUDownloadHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
			if ($itemIdTreeRoot > 0)
			{
				$query['Itemid'] = $itemIdTreeRoot;

				$segments[] = $categoryObject->id . ":" . $categoryObject->alias;

				return $segments;
			}

			$query['Itemid'] = JUDownloadHelperRoute::getHomeMenuItemId();

			
			$sefRootCategory = $params->get('sef_root_cat', 'root');
			$segments[]      = JApplication::stringURLSafe($sefRootCategory);

			$segments[] = $categoryObject->id . ":" . $categoryObject->alias;

			return $segments;
		}
		else
		{
			
			$levelCats = JUDownloadHelper::getCatsByLevel(1, $categoryObject->id);
			if (is_array($levelCats) && count($levelCats))
			{
				$categoryIdAncestorLevel1 = $levelCats[0]->id;
			}
			$menuItemIdsOfViewCategoryTreeLevel1 = JUDownloadHelperRoute::getMenuItemIdArrayOfViewCategoryTreeLevel1();
			if (isset($menuItemIdsOfViewCategoryTreeLevel1[$categoryIdAncestorLevel1]))
			{
				$query['Itemid'] = $menuItemIdsOfViewCategoryTreeLevel1[$categoryIdAncestorLevel1];

				if ($fullPath)
				{
					$categoryPath = JUDownloadHelper::getCategoryPath($categoryId);
					if (is_array($categoryPath) && count($categoryPath))
					{
						foreach ($categoryPath as $categoryPathValue)
						{
							if ($categoryPathValue->level > 1 && $categoryPathValue->id != $categoryObject->id)
							{
								$segments[] = $categoryPathValue->alias;
							}
						}
					}
				}

				$segments[] = $categoryObject->id . ":" . $categoryObject->alias;

				return $segments;
			}

			
			$itemIdTreeRoot = JUDownloadHelperRoute::getMenuItemIdOfViewCategoryTreeRoot();
			if ($itemIdTreeRoot > 0)
			{
				$query['Itemid'] = $itemIdTreeRoot;

				if ($fullPath)
				{
					$categoryPath = JUDownloadHelper::getCategoryPath($categoryId);

					if (is_array($categoryPath) && count($categoryPath))
					{
						foreach ($categoryPath as $categoryPathValue)
						{
							if ($categoryPathValue->level > 0 && $categoryPathValue->id != $categoryObject->id)
							{
								$segments[] = $categoryPathValue->alias;
							}
						}
					}
				}

				$segments[] = $categoryObject->id . ":" . $categoryObject->alias;

				return $segments;
			}

			$query['Itemid'] = JUDownloadHelperRoute::getHomeMenuItemId();

			if ($fullPath)
			{
				
				$sefRootCategory = $params->get('sef_root_cat', 'root');
				$segments[]      = JApplication::stringURLSafe($sefRootCategory);
				$categoryPath    = JUDownloadHelper::getCategoryPath($categoryId);
				if (is_array($categoryPath) && count($categoryPath))
				{
					foreach ($categoryPath as $categoryPathValue)
					{
						if ($categoryPathValue->level > 0 && $categoryPathValue->id != $categoryObject->id)
						{
							$segments[] = $categoryPathValue->alias;
						}
					}
				}
			}

			$segments[] = $categoryObject->id . ":" . $categoryObject->alias;

			return $segments;
		}

		return $segments;
	}
예제 #19
0
	public static function optimizeListDocumentQuery(&$query, $massSelect = false)
	{
		$user = JFactory::getUser();
		$query->select('cmain.id AS cat_id');
		$query->join('', '#__judownload_documents_xref AS dxmain ON d.id = dxmain.doc_id AND dxmain.main = 1');
		$query->join('', '#__judownload_categories AS cmain ON cmain.id = dxmain.cat_id');

		
		$categoryIdArrayCanAccess = JUDownloadFrontHelperCategory::getAccessibleCategoryIds();
		if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0)
		{
			$query->where('cmain.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')');
		}
		else
		{
			$query->where('cmain.id IN("")');
		}

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

			
			$commentsField = new JUDownloadFieldCore_comments();
			if ($commentsField->canView(array("view" => "list")))
			{
				$isModerator = JUDownloadFrontHelperModerator::isModerator();
				if (!$isModerator && !$user->authorise('core.admin', 'com_judownload'))
				{
					$params                = JUDownloadHelper::getParams();
					$negative_vote_comment = $params->get('negative_vote_comment');
					if (is_numeric($negative_vote_comment) && $negative_vote_comment > 0)
					{
						$query->select('(SELECT COUNT(*) FROM #__judownload_comments AS cm WHERE cm.doc_id = d.id AND cm.approved = 1 AND cm.published = 1 AND cm.level = 1
										AND (cm.total_votes - cm.helpful_votes) < ' . $negative_vote_comment . ' ) AS total_comments');
					}
					else
					{
						$query->select('(SELECT COUNT(*) FROM #__judownload_comments AS cm WHERE cm.doc_id = d.id AND cm.approved = 1 AND cm.published = 1 AND cm.level = 1) AS total_comments');
					}
				}
			}

			
			$subscriptionsField = new JUDownloadFieldCore_subscriptions();
			if ($subscriptionsField->canView(array("view" => "list")))
			{
				$query->select('(SELECT COUNT(*) FROM #__judownload_subscriptions AS sub WHERE sub.item_id = d.id AND sub.type = "document" AND sub.published = 1) AS total_subscriptions');
			}

			
			$reportsField = new JUDownloadFieldCore_reports();
			if ($reportsField->canView(array("view" => "list")))
			{
				$query->select('(SELECT COUNT(*) FROM #__judownload_reports AS r WHERE r.item_id = d.id AND r.type = "document") AS total_reports');
			}

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

			$tagsField = new JUDownloadFieldCore_tags();
			if ($tagsField->canView(array("view" => "list")))
			{
				
				
				$query->select('IFNULL ((SELECT GROUP_CONCAT(tagids.id ORDER BY tx_tagids.ordering ASC SEPARATOR ",") FROM (#__judownload_tags AS tagids JOIN #__judownload_tags_xref AS tx_tagids ON tagids.id = tx_tagids.tag_id) WHERE d.id = tx_tagids.doc_id GROUP BY d.id), "") AS tag_ids');
				
				$query->select('IFNULL ((SELECT GROUP_CONCAT(tagtitles.title ORDER BY tx_tagtitles.ordering ASC SEPARATOR "|||") FROM (#__judownload_tags AS tagtitles JOIN #__judownload_tags_xref AS tx_tagtitles ON tagtitles.id = tx_tagtitles.tag_id) WHERE d.id = tx_tagtitles.doc_id GROUP BY d.id), "") AS tag_titles');
			}

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

			
			$fieldQuery = $db->getQuery(true);
			$fieldQuery->select('field.id');
			$fieldQuery->from('#__judownload_fields AS field');
			$fieldQuery->where('field.field_name = ""');
			$fieldQuery->where('field.list_view = 1');

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

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

			$view = $app->input->get('view', '');
			if ($view == 'category' || $view == 'tree')
			{
				$cat_id   = $app->input->getInt('id', 0);
				$category = JUDownloadHelper::getCategoryById($cat_id);
				if (is_object($category))
				{
					$fieldQuery->where('field.group_id = ' . $category->fieldgroup_id);
				}
			}
			else
			{
				$fieldQuery->join('', '#__judownload_categories AS c ON (field.group_id = c.fieldgroup_id OR field.group_id = 1)');

				if (is_array($categoryIdArrayCanAccess) && count($categoryIdArrayCanAccess) > 0)
				{
					$fieldQuery->where('c.id IN(' . implode(",", $categoryIdArrayCanAccess) . ')');
				}
				else
				{
					$fieldQuery->where('c.id IN("")');
				}
			}

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

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

			$db->setQuery($fieldQuery);

			
			$fields = $db->loadObjectList();
			foreach ($fields AS $field)
			{
				$query->select('IFNULL (fields_values_' . $field->id . '.value, "") AS field_values_' . $field->id);
				$query->join('LEFT', '#__judownload_fields_values AS fields_values_' . $field->id . ' ON fields_values_' . $field->id . '.doc_id = d.id AND fields_values_' . $field->id . '.field_id = ' . $field->id);
			}
		}
	}
예제 #20
0
}
?>
					</td>
				</tr>
				<tr>
					<td>
						<?php 
echo JText::_("COM_JUDOWNLOAD_SELECTED_SECONDARY_CATEGORIES");
?>
					</td>
					<td>
						<?php 
if (isset($this->review['config']['secondary_cats_assign'])) {
    $catName = array();
    foreach ($this->review['config']['secondary_cats_assign'] as $catId) {
        $catObj = JUDownloadHelper::getCategoryById($catId);
        $catName[] = $catObj->title;
    }
    echo implode(', ', $catName);
}
?>
					</td>
				</tr>
				<tr>
					<td>
						<?php 
echo JText::_("COM_JUDOWNLOAD_DEFAULT_META_KEYWORD");
?>
					</td>
					<td>
						<?php 
예제 #21
0
 public function edit($key = null, $urlVar = null)
 {
     $app = JFactory::getApplication();
     $cat_id = $app->input->getInt('id', 0);
     $category = JUDownloadHelper::getCategoryById($cat_id);
     if ($category->parent_id == 0) {
         $this->setRedirect("index.php?option=com_judownload&view=listcats", JText::_('COM_JUDOWNLOAD_YOU_CAN_NOT_EDIT_ROOT_CATEGORY'), "error");
     } else {
         parent::edit($key = null, $urlVar = null);
     }
 }
예제 #22
0
 public function getAllChildCats($catArr)
 {
     $childCatIds = array();
     $db = JFactory::getDbo();
     foreach ($catArr as $catId) {
         $catObject = JUDownloadHelper::getCategoryById($catId);
         $query = $db->getQuery(true);
         $query->select('id')->from('#__judownload_categories')->where('lft >= ' . $catObject->lft)->where('rgt <= ' . $catObject->rgt);
         $db->setQuery($query);
         $childCatIdArr = $db->loadColumn();
         $childCatIds = array_merge($childCatIds, $childCatIdArr);
     }
     $childCatIdStr = implode(',', $childCatIds);
     return $childCatIdStr;
 }
예제 #23
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;
	}