protected function allowAdd($data = array()) { if (empty($data)) { $catId = JFactory::getApplication()->input->get('cat_id'); if (!JUDownloadFrontHelperPermission::canSubmitDocument($catId)) { return false; } } return true; }
public function loadCategories() { $app = JFactory::getApplication(); $rootCat = JUDownloadFrontHelperCategory::getRootCategory(); $type = $app->input->get('type', ''); $catId = $app->input->getInt('id', 0); $catObj = JUDownloadHelper::getCategoryById($catId); $params = JUDownloadHelper::getParams($catId); $date = JFactory::getDate(); $back = false; if ($catId != 0) { if ($type == 'category') { $back = true; } elseif ($catId == $rootCat->id && $params->get('allow_add_doc_to_root', 0) || $catId != $rootCat->id) { $back = true; } } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->SELECT('title, id, published, parent_id, publish_up, publish_down'); $query->FROM('#__judownload_categories'); $query->WHERE('parent_id = ' . $catId); $query->ORDER('lft'); $db->setQuery($query); $rows = $db->loadObjectList(); $html = ""; if ($back) { $html .= '<option value="' . $catObj->parent_id . '" data-update="noupdate">' . JText::_('COM_JUDOWNLOAD_BACK_TO_PARENT_CATEGORY') . '</option>'; } foreach ($rows as $row) { if ($type == 'document') { $canDoCreate = JUDownloadFrontHelperPermission::canSubmitDocument($row->id); if (!$canDoCreate) { continue; } } if ($row->published != 1 || $row->publish_up > $date->toSql() || $row->publish_down > $db->getNullDate() && $row->publish_down <= $date->toSql()) { $row->title = "[" . $row->title . "]"; } $html .= "<option value=\"" . $row->id . "\">" . $row->title . "</option>"; } $data['path'] = JUDownloadHelper::generateCategoryPath($catId, 'li'); $data['html'] = $html; return json_encode($data); }
public function display($tpl = null) { $model = $this->getModel(); $this->model = $model; $this->state = $this->get('State'); $params = $this->state->params; $this->params = $params; $this->token = JSession::getFormToken(); $this->root_category = JUDownloadFrontHelperCategory::getRootCategory(); $categoryId = $this->state->get('category.id', $this->root_category->id); if (count($errors = $this->get('Errors'))) { JError::raiseWarning(500, implode("\n", $errors)); return false; } $error = array(); if (!JUDownloadFrontHelperPermission::canDoCategory($categoryId, true, $error)) { $user = JFactory::getUser(); if ($user->id) { return JError::raiseError($error['code'], $error['message']); } else { $uri = JUri::getInstance(); $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false); $app = JFactory::getApplication(); $app->redirect($loginUrl, JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning'); return false; } } $topLevelCats = JUDownloadHelper::getCatsByLevel(1, $categoryId); if (is_array($topLevelCats) && count($topLevelCats) > 0) { $this->tl_catid = $topLevelCats[0]->id; } $this->category = JUDownloadFrontHelperCategory::getCategory($categoryId); $this->show_feed = JUDLPROVERSION ? $this->params->get('rss_display_icon', 1) : 0; $this->rss_link = JRoute::_(JUDownloadHelperRoute::getCategoryRoute($this->category->id, null, true)); if (isset($this->category->images) && !empty($this->category->images) && !empty($this->category->images->detail_image)) { $this->category->images->detail_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judownload/images/category/detail/', true) . $this->category->images->detail_image; } $this->category->images->detail_image_width = (int) $this->params->get('category_image_width', 200); $this->category->images->detail_image_height = (int) $this->params->get('category_image_height', 200); if ($this->params->get('category_show_description', 1)) { $this->category->description = $this->category->introtext . $this->category->fulltext; } else { $this->category->description = $this->category->fulltext; } $categoryDescLimit = (int) $this->params->get('category_desc_limit', 0); if ($categoryDescLimit > 0) { $this->category->description = JUDownloadFrontHelperString::truncateHtml($this->category->description, $categoryDescLimit); } if ($this->params->get('plugin_support', 0)) { $this->category->description = JHtml::_('content.prepare', $this->category->description, '', 'com_judownload.category'); } $this->category->class_sfx = htmlspecialchars($this->category->class_sfx); $relatedCatOrdering = $this->params->get('related_category_ordering', 'crel.ordering'); $relatedCatDirection = $this->params->get('related_category_direction', 'ASC'); $this->related_cats = $model->getRelatedCategories($this->category->id, $relatedCatOrdering, $relatedCatDirection); if (is_array($this->related_cats) && count($this->related_cats) > 0) { foreach ($this->related_cats AS $relatedCategory) { if (isset($relatedCategory->images->intro_image) && !empty($relatedCategory->images->intro_image)) { $relatedCategory->images->intro_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/', true) . $relatedCategory->images->intro_image; } $relatedCategory->images->intro_image_width = (int) $this->params->get('related_category_intro_image_width', 200); $relatedCategory->images->intro_image_height = (int) $this->params->get('related_category_intro_image_height', 200); if ($this->params->get('related_category_show_introtext', 1)) { $relatedCategoryDescLimit = (int) $this->params->get('related_category_introtext_character_limit', 500); if ($relatedCategoryDescLimit > 0) { $relatedCategory->introtext = JUDownloadFrontHelperString::truncateHtml($relatedCategory->introtext, $relatedCategoryDescLimit); } if ($params->get('plugin_support', 0)) { $relatedCategory->introtext = JHtml::_('content.prepare', $relatedCategory->introtext, '', 'com_judownload.category'); } } else { $relatedCategory->introtext = ''; } } } $subCatOrdering = $this->params->get('subcategory_ordering', 'title'); $subCatDirection = $this->params->get('subcategory_direction', 'ASC'); $this->subcategories = $model->getSubCategories($this->category->id, $subCatOrdering, $subCatDirection); if (is_array($this->subcategories) && count($this->subcategories) > 0) { foreach ($this->subcategories AS $subCategory) { if (isset($subCategory->images->intro_image) && !empty($subCategory->images->intro_image)) { $subCategory->images->intro_image_src = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/', true) . $subCategory->images->intro_image; } $subCategory->images->intro_image_width = (int) $this->params->get('subcategory_intro_image_width', 200); $subCategory->images->intro_image_height = (int) $this->params->get('subcategory_intro_image_height', 200); if ($this->params->get('subcategory_show_introtext', 1)) { $subCategoryDescLimit = (int) $this->params->get('subcategory_introtext_character_limit', 500); if ($subCategoryDescLimit > 0) { $subCategory->introtext = JUDownloadFrontHelperString::truncateHtml($subCategory->introtext, $subCategoryDescLimit); } if ($this->params->get('plugin_support', 0)) { $subCategory->introtext = JHtml::_('content.prepare', $subCategory->introtext, '', 'com_judownload.category'); } } else { $subCategory->introtext = ''; } } } $this->category->can_submit_doc = JUDownloadFrontHelperPermission::canSubmitDocument($this->category->id); if ($this->category->can_submit_doc && $this->params->get('show_submit_document_btn_in_category', 1)) { $this->category->submit_doc_link = JUDownloadFrontHelperDocument::getAddDocumentLink($this->category->id); } $this->items = array(); if ($this->category->show_item) { $user = JFactory::getUser(); $uri = JUri::getInstance(); $this->items = $this->get('Items'); foreach ($this->items as $item) { $documentItemid = JUDownloadHelperRoute::findItemIdOfDocument($item->id); $item->report_link = JRoute::_(JUDownloadHelperRoute::getReportDocumentRoute($item->id)); if ($item->checked_out > 0 && $item->checked_out != $user->get('id')) { if (JUDownloadFrontHelperPermission::canCheckInDocument($item->id)) { $item->checkin_link = JRoute::_('index.php?option=com_judownload&task=forms.checkin&id=' . $item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri))); } } else { $item->edit_link = JRoute::_('index.php?option=com_judownload&task=form.edit&id=' . $item->id . '&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); if ($item->published == 1) { $item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.unpublish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); } else { $item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.publish&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); } } $item->delete_link = JRoute::_('index.php?option=com_judownload&task=forms.delete&id=' . $item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($item->id)); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('content'); $item->event = new stdClass(); $context = 'com_judownload.document_list'; $results = $dispatcher->trigger('onContentAfterTitle', array($context, &$item, &$item->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array($context, &$item, &$item->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array($context, &$item, &$item->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); } $this->pagination = $this->get('Pagination'); } $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareData(); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
protected function getAllCategoryOptions() { $rootCat = JUDownloadFrontHelperCategory::getRootCategory(); JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judownload/tables"); $categoryTable = JTable::getInstance('Category', 'JUDownloadTable'); $categoryTree = $categoryTable->getTree($rootCat->id); foreach ($categoryTree AS $key => $cat) { $canSubmitDocument = JUDownloadFrontHelperPermission::canSubmitDocument($cat->id); if (!$canSubmitDocument) { unset($categoryTree[$key]); continue; } if ($cat->published != 1) { $categoryTree[$key]->title = "[" . $cat->title . "]"; } $categoryTree[$key]->title = str_repeat('|—', $cat->level) . $categoryTree[$key]->title; } if (isset($this->doc) && $this->doc->cat_id) { $params = JUDownloadHelper::getParams($this->doc->cat_id); } else { $params = JUDownloadHelper::getParams(null, $this->doc_id); } if ($params->get('allow_add_doc_to_root', 0)) { array_unshift($categoryTree, JHtml::_('select.option', $rootCat->id, JText::_('COM_JUDOWNLOAD_ROOT'), 'id', 'title')); } return $categoryTree; }