protected function _prepareData() { $this->token = JSession::getFormToken(); $this->session = JFactory::getSession(); $this->item->changelogs = JUDownloadFrontHelper::getChangeLogField($this->item->id); $this->item->versions = $this->model->getVersions($this->item->id); $this->item->related_documents = $this->model->getRelatedDocuments($this->item->id); if (count($this->item->related_documents)) { foreach ($this->item->related_documents AS $documentRelated) { $documentRelated->link = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($documentRelated->id)); $documentRelated->icon = JUDownloadHelper::getDocumentIcon($documentRelated->icon); } } $this->item->files = JUDownloadFrontHelperDocument::getFilesByDocumentId($this->item->id); $this->can_download_document = JUDownloadFrontHelperPermission::canDownloadDocument($this->item->id, false); $this->display_download_rule_msg = $this->params->get('show_rule_messages', 'modal'); $additionFields = array(); if (trim($this->item->external_link)) { $additionFields[] = 'external_link'; } if ($this->item->license_id && $this->item->confirm_license) { $additionFields[] = 'license_id'; $additionFields[] = 'confirm_license'; } $this->item->fieldGallery = JUDownloadFrontHelperField::getField('gallery', $this->item); $this->item->fields = JUDownloadFrontHelperField::getFields($this->item, 2, array(), array('gallery'), $additionFields); $this->item->license = JUDownloadFrontHelper::getLicense($this->item->license_id); $user = JFactory::getUser(); $uri = JUri::getInstance(); if ($this->item->checked_out > 0 && $this->item->checked_out != $user->get('id')) { if (JUDownloadFrontHelperPermission::canCheckInDocument($this->item->id)) { $this->item->checkin_link = JRoute::_('index.php?option=com_judownload&task=forms.checkin&id=' . $this->item->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri))); } } else { $this->item->edit_link = JRoute::_('index.php?option=com_judownload&task=form.edit&id=' . $this->item->id . '&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id)); if ($this->item->published == 1) { $this->item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.unpublish&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id)); } else { $this->item->editstate_link = JRoute::_('index.php?option=com_judownload&task=forms.publish&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id)); } } $this->item->delete_link = JRoute::_('index.php?option=com_judownload&task=forms.delete&id=' . $this->item->id . '&return=' . base64_encode(urlencode($uri)) . '&' . JSession::getFormToken() . '=1&Itemid=' . JUDownloadHelperRoute::findItemIdOfDocument($this->item->id)); if ($this->item->is_subscriber) { $this->item->unsubscribe_link = $this->model->getUnsubscribeLink($this->item->id); } else { $this->item->subscribe_link = $this->model->getSubscribeLink($this->item->id); } $this->item->contact_link = JRoute::_(JUDownloadHelperRoute::getContactRoute($this->item->id)); $this->item->report_link = JRoute::_(JUDownloadHelperRoute::getReportDocumentRoute($this->item->id)); $this->item->print_link = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($this->item->id) . '&layout=print&tmpl=component&print=1'); $this->item->comment = new stdClass(); $this->item->comment->total_comments_no_filter = $this->model->getTotalCommentsOfDocument($this->item->id); $this->root_comment = JUDownloadFrontHelperComment::getRootComment(); $langArray = JHtml::_('contentlanguage.existing'); $JAll = new JObject(); $JAll->text = JText::_('JALL'); $JAll->value = '*'; array_unshift($langArray, $JAll); $this->langArray = $langArray; $this->item->comment->items = $this->get('Items'); foreach ($this->item->comment->items AS $comment) { if (JUDownloadFrontHelperPermission::canCheckInComment($comment->id)) { $uri = JUri::getInstance(); $comment->checkout_link = 'index.php?option=com_judownload&task=modcomments.checkin&cid=' . $comment->id . '&' . JSession::getFormToken() . '=1' . '&return=' . base64_encode(urlencode($uri)); } else { $comment->checkout_link = ''; } } $this->item->comment->pagination = $this->get('Pagination'); $this->item->comment->total_comments = $this->get('Total'); $this->item->comment->parent_id = $this->root_comment->id; $this->website_field_in_comment_form = $this->params->get('website_field_in_comment_form', 0); $this->min_comment_characters = $this->params->get('min_comment_characters', 20); $this->max_comment_characters = $this->params->get('max_comment_characters', 1000); $this->allow_vote_comment = $this->params->get('allow_vote_comment', 1); $this->allow_vote_down_comment = $this->params->get('allow_vote_down_comment', 1); $this->order_comment_name_array = $this->model->getCommentOrderingOptions(); $this->order_comment_dir_array = array( 'ASC' => JText::_('COM_JUDOWNLOAD_ASC'), 'DESC' => JText::_('COM_JUDOWNLOAD_DESC') ); $this->total_stars = $this->params->get('number_rating_stars', 5); $this->filter_comment_stars = array('' => JText::_('COM_JUDOWNLOAD_ANY_STAR')); for ($i = 0; $i <= $this->total_stars; $i++) { $score = ($i == 0) ? 0 : round((($i - 1) * 10) / $this->total_stars, 5) . ',' . round(($i * 10) / $this->total_stars, 5); $this->filter_comment_stars[$score] = JText::plural('COM_JUDOWNLOAD_N_STAR', $i); } if ($this->params->get('filter_comment_language', 0)) { $this->list_lang_comment = $this->escape($this->state->get('list.lang')); } $this->list_order_comment = $this->escape($this->state->get('list.ordering')); $this->list_dir_comment = $this->escape($this->state->get('list.direction')); $this->filter_comment_star = $this->state->get('list.star_filter', ''); $this->website = $this->title = $this->email = $this->comment = $this->name = ''; $this->language = '*'; $form = $this->session->get('judownload_commentform_' . $this->item->id, null); $this->form = $form; if (!empty($form) && $form['parent_id'] == $this->root_comment->id) { $this->title = $form['title']; $this->name = $form['guest_name']; $this->email = $form['guest_email']; $this->comment = $form['comment']; $this->website = (isset($form['website'])) ? $form['website'] : ''; $this->language = $form['comment_language']; } }
public function delete() { JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN')); $cid = JFactory::getApplication()->input->get('id', array(), 'array'); if (!is_array($cid) || count($cid) < 1) { JError::raiseWarning(500, JText::_('COM_JUDOWNLOAD_NO_ITEM_SELECTED')); $this->setRedirect($this->getReturnPage()); } else { $model = $this->getModel(); jimport('joomla.utilities.arrayhelper'); JArrayHelper::toInteger($cid); if ($model->delete($cid)) { $this->setMessage(JText::plural($this->text_prefix . '_N_ITEMS_DELETED', count($cid))); } else { $this->setMessage($model->getError()); } $isDocumentPublished = JUDownloadFrontHelperDocument::isDocumentPublished($cid[0]); if ($isDocumentPublished) { $mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($cid[0]); $this->setRedirect(JRoute::_(JUDownloadHelperRoute::getCategoryRoute($mainCategoryId), false)); } else { $this->setRedirect($this->getReturnPage()); } } }
public function getItem() { $params = $this->getState('params'); $documentId = (int) $this->getState('document.id'); if (!$documentId) { JError::raiseError(404, JText::_('COM_JUDOWNLOAD_DOCUMENT_NOT_FOUND')); return false; } $user = JFactory::getUser(); $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('d.*, c.id AS cat_id'); $query->from('#__judownload_documents AS d'); $query->join('', '#__judownload_documents_xref AS dxref ON d.id = dxref.doc_id AND dxref.main=1'); $query->join('', '#__judownload_categories AS c ON c.id = dxref.cat_id'); $query->select('(SELECT COUNT(*) FROM #__judownload_files AS f WHERE f.doc_id = d.id AND f.published = 1) AS total_files'); $query->select('(SELECT COUNT(*) FROM #__judownload_comments AS cm WHERE cm.doc_id = d.id AND cm.approved = 1 AND cm.published = 1) AS total_comments'); $query->select('(SELECT COUNT(*) FROM #__judownload_subscriptions AS sub WHERE sub.item_id = d.id AND sub.type = "document" AND sub.published = 1) AS total_subscriptions'); $query->select('(SELECT COUNT(*) FROM #__judownload_reports AS r WHERE r.item_id = d.id AND r.type = "document") AS total_reports'); $query->select('(SELECT GROUP_CONCAT(catids.id ORDER BY dx_catids.main DESC, dx_catids.ordering ASC SEPARATOR ",") FROM (#__judownload_categories AS catids JOIN #__judownload_documents_xref AS dx_catids ON catids.id = dx_catids.cat_id) WHERE d.id = dx_catids.doc_id GROUP BY d.id) AS cat_ids'); $query->select('(SELECT GROUP_CONCAT(cattitles.title ORDER BY dx_cattitles.main DESC, dx_cattitles.ordering ASC SEPARATOR "|||") FROM (#__judownload_categories AS cattitles JOIN #__judownload_documents_xref AS dx_cattitles ON cattitles.id = dx_cattitles.cat_id) WHERE d.id = dx_cattitles.doc_id GROUP BY d.id) AS cat_titles'); $accessLevel = implode(',', $user->getAuthorisedViewLevels()); $db = JFactory::getDbo(); $date = JFactory::getDate(); $nullDate = $db->quote($db->getNullDate()); $nowDate = $db->quote($date->toSql()); $fieldQuery = $db->getQuery(true); $fieldQuery->select('field.id'); $fieldQuery->from('#__judownload_fields AS field'); $fieldQuery->where('field.group_id != 1'); $fieldQuery->where('field.details_view = 1'); $fieldQuery->where('field.published = 1'); $fieldQuery->where('field.publish_up <= ' . $nowDate); $fieldQuery->where('(field.publish_down = ' . $nullDate . ' OR field.publish_down > ' . $nowDate . ')'); $fieldQuery->where('(field.access IN (' . $accessLevel . ') OR field.who_can_download_can_access = 1)'); $category = JUDownloadFrontHelperCategory::getMainCategory($documentId); if (is_object($category)) { $fieldQuery->where('field.group_id = ' . $category->fieldgroup_id); } $fieldQuery->join('', '#__judownload_fields_groups AS field_group ON field.group_id = field_group.id'); $fieldQuery->where('field_group.published = 1'); $fieldQuery->where('field_group.access IN (' . $accessLevel . ')'); $fieldQuery->group('field.id'); $db->setQuery($fieldQuery); $fields = $db->loadObjectList(); foreach ($fields AS $field) { $query->select('IFNULL (fields_values_' . $field->id . '.value, "") AS field_values_' . $field->id); $query->join('LEFT', '#__judownload_fields_values AS fields_values_' . $field->id . ' ON fields_values_' . $field->id . '.doc_id = d.id AND fields_values_' . $field->id . '.field_id = ' . $field->id); } $query->where('d.id = ' . $documentId); $db->setQuery($query); $documentObject = $db->loadObject(); if (!is_object($documentObject)) { JError::raiseError(404, JText::_('COM_JUDOWNLOAD_DOCUMENT_NOT_FOUND')); return false; } $documentObject->params = JUDownloadFrontHelperDocument::getDocumentDisplayParams($documentObject->id); if (!$user->get('guest')) { $canEditDocument = JUDownloadFrontHelperPermission::canEditDocument($documentObject->id); $canDeleteDocument = JUDownloadFrontHelperPermission::canDeleteDocument($documentObject->id); $canEditStateDocument = JUDownloadFrontHelperPermission::canEditStateDocument($documentObject); $documentObject->params->set('access-edit', $canEditDocument); $documentObject->params->set('access-edit-state', $canEditStateDocument); $documentObject->params->set('access-delete', $canDeleteDocument); } $canReportDocument = JUDownloadFrontHelperPermission::canReportDocument($documentObject->id); $canContactDocument = JUDownloadFrontHelperPermission::canContactDocument($documentObject->id); $canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($documentObject->id); $canDownloadDocument = JUDownloadFrontHelperPermission::canDownloadDocument($documentObject->id, false); $canCommentDocument = JUDownloadFrontHelperPermission::canComment($documentObject->id); $documentObject->params->set('access-report', $canReportDocument); $documentObject->params->set('access-contact', $canContactDocument); $documentObject->params->set('access-rate', $canRateDocument); $documentObject->params->set('access-download', $canDownloadDocument); $documentObject->params->set('access-comment', $canCommentDocument); $hasPassword = JUDownloadFrontHelperDocument::documentHasPassword($documentObject); $documentObject->params->set('has-password', $hasPassword); if ($hasPassword) { $validPassword = JUDownloadFrontHelperPassword::checkPassword($documentObject); } else { $validPassword = true; } $documentObject->params->set('valid-password', $validPassword); if ($canDownloadDocument && !$validPassword) { $documentObject->allow_enter_password = JUDownloadFrontHelperPassword::allowEnterPassword($documentObject->id); } $token = JSession::getFormToken(); $return = base64_encode(urlencode(JUri::getInstance())); $documentObject->download_link = JRoute::_('index.php?option=com_judownload&task=download.download&doc_id=' . $documentObject->id . '&' . $token . '=1'); $documentObject->download_link .= '&return=' . $return; if ($params->get('show_rule_messages', 'modal') != 'hide') { $downloadRuleErrorMessages = JUDownloadFrontHelperDocument::getDownloadRuleErrorMessages($documentObject->id); if ($downloadRuleErrorMessages !== true) { $documentObject->error_msg = $downloadRuleErrorMessages; } } $documentObject->template_params = new JRegistry($documentObject->template_params); if ($params->get('show_new_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->publish_up, $params->get('num_day_to_show_as_new', 10))) { $documentObject->label_new = true; } else { $documentObject->label_new = false; } if ($params->get('show_updated_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->updated, $params->get('num_day_to_show_as_updated', 10))) { $documentObject->label_updated = true; } else { $documentObject->label_updated = false; } if ($params->get('show_hot_label', 1) && JUDownloadFrontHelperDocument::checkHotDocument($documentObject->publish_up, $params->get('num_download_per_day_to_be_hot', 10), $documentObject->downloads)) { $documentObject->label_hot = true; } else { $documentObject->label_hot = false; } if ($params->get('show_featured_label', 1) && $documentObject->featured) { $documentObject->label_featured = true; } else { $documentObject->label_featured = false; } $documentObject->next_item = $this->getNextPrevItem($documentObject, 'next'); $documentObject->prev_item = $this->getNextPrevItem($documentObject, 'prev'); $documentObject->is_subscriber = $this->isSubscriber($user->id, $documentObject->id, 'document'); return $documentObject; }
* @author JoomUltra Co., Ltd * @website http://www.joomultra.com * @----------------------------------------------------------------------@ */ // No direct access to this file defined('_JEXEC') or die('Restricted access'); //@todo properties has called in view $user = JFactory::getUser(); $isOwnDashboard = JUDownloadFrontHelperPermission::isOwnDashboard(); JLoader::register('JUDownloadAvatarHelper', JPATH_SITE . '/components/com_judownload/helpers/avatar.php'); $avatar = JUDownloadAvatarHelper::getJUAvatar($user->id); $userId = JUDownloadFrontHelper::getDashboardUserId(); $linkDashboard = JRoute::_(JUDownloadHelperRoute::getDashboardRoute($userId)); $linkUserProfile = JRoute::_(JUDownloadHelperRoute::getUserProfileRoute()); $linkCreateDocument = JRoute::_(JUDownloadFrontHelperDocument::getAddDocumentLink()); $linkUserComments = JRoute::_(JUDownloadHelperRoute::getUserCommentsRoute($userId)); $linkUserCollection = JRoute::_(JUDownloadHelperRoute::getCollectionsRoute($userId)); $linkUserDocuments = JRoute::_(JUDownloadHelperRoute::getUserDocumentsRoute($userId)); $linkUserSubscriptions = JRoute::_(JUDownloadHelperRoute::getUserSubscriptionsRoute($userId)); $linkLogOutReturn = JRoute::_('index.php',false); ?> <nav class="navbar navbar-default" role="navigation"> <div class="container-fluid"> <ul class="nav navbar-nav"> <li class="go-home"> <a class="hasTooltip" title="<?php echo JText::_('COM_JUDOWNLOAD_DASHBOARD_HOME'); ?>" href="<?php echo $linkDashboard ?>"> <i class="fa fa-home"></i> </a> </li>
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); }
public static function canAutoApprovalDocumentWhenEdit($documentId, $newMainCategoryId) { $documentObject = JUDownloadHelper::getDocumentById($documentId); if ($documentObject->approved == 1) { $originalDocumentId = $documentObject->id; $originalDocumentObject = $documentObject; $mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($originalDocumentObject->id); $params = JUDownloadHelper::getParams($newMainCategoryId); } elseif ($documentObject->approved < 0) { $tempDocumentObject = $documentObject; $originalDocumentId = abs($documentObject->approved); $originalDocumentObject = JUDownloadHelper::getDocumentById($originalDocumentId); $mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($originalDocumentObject->id); $params = JUDownloadHelper::getParams($newMainCategoryId); } else { return false; } $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($originalDocumentObject->id); $autoApprovalForDocumentOwner = $params->get('document_owner_can_edit_document_auto_approval', 1); if ($isDocumentOwner && $autoApprovalForDocumentOwner) { return true; } $user = JFactory::getUser(); if ($mainCategoryId == $newMainCategoryId) { if ($user->authorise('judl.document.edit.auto_approval', 'com_judownload.category.' . $mainCategoryId)) { return true; } } else { if ($user->authorise('judl.document.create.auto_approval', 'com_judownload.category.' . $newMainCategoryId)) { return true; } } if (!$user->get('guest')) { $autoApprovalDocumentThreshold = (int) $params->get('auto_approval_document_threshold', 0); if ($autoApprovalDocumentThreshold > 0) { $totalApprovedDocumentsOfUser = JUDownloadFrontHelperDocument::getTotalDocumentsOfUserApprovedByMod($user->id); if ($totalApprovedDocumentsOfUser >= $autoApprovalDocumentThreshold) { return true; } } } return false; }
public static function getDocumentLayout($docId) { $storeId = md5(__METHOD__ . "::" . $docId); if (!isset(self::$cache[$storeId])) { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('layout'); $query->from('#__judownload_documents'); $query->where('id =' . $docId); $db->setQuery($query); $layout = $db->loadResult(); if ($layout == -2) { $params = JUDownloadHelper::getParams(null, $docId); $layout = $params->get('layout_document', '_:default'); } elseif ($layout == -1) { $parentId = (int) JUDownloadFrontHelperCategory::getMainCategoryId($docId); if ($parentId == 0) { $params = JUDownloadHelper::getParams(null, $docId); $layout = $params->get('layout_document', '_:default'); } else { $layout = JUDownloadFrontHelperDocument::getDocumentLayoutFromCategory($parentId); } } else { $layout = trim($layout); } self::$cache[$storeId] = $layout; } return self::$cache[$storeId]; }
public static function appendDataToDocumentObjList(&$documentObjectList, $params, $usingForMod = false) { if (is_array($documentObjectList) && count($documentObjectList)) { $user = JFactory::getUser(); $token = JSession::getFormToken(); $return = base64_encode(urlencode(JUri::getInstance())); foreach ($documentObjectList AS $documentObject) { JUDownloadHelper::getDocumentById($documentObject->id, false, $documentObject); $documentObject->params = JUDownloadFrontHelperDocument::getDocumentDisplayParams($documentObject->id); if (!isset($documentObject->total_files)) { $documentObject->total_files = JUDownloadFrontHelperDocument::getTotalPublishedFilesOfDocument($documentObject->id); } if (!$user->get('guest')) { $canEditDocument = JUDownloadFrontHelperPermission::canEditDocument($documentObject->id); $canEditStateDocument = JUDownloadFrontHelperPermission::canEditStateDocument($documentObject); $canDeleteDocument = JUDownloadFrontHelperPermission::canDeleteDocument($documentObject->id); $documentObject->params->set('access-edit', $canEditDocument); $documentObject->params->set('access-edit-state', $canEditStateDocument); $documentObject->params->set('access-delete', $canDeleteDocument); } if ($params->get('show_report_btn_in_listview', 1) || $usingForMod) { $canReportDocument = JUDownloadFrontHelperPermission::canReportDocument($documentObject->id); $documentObject->params->set('access-report', $canReportDocument); } if ($params->get('show_download_btn_in_listview', 1) || $usingForMod) { $canDownloadDocument = JUDownloadFrontHelperPermission::canDownloadDocument($documentObject->id, false); $documentObject->params->set('access-download', $canDownloadDocument); $hasPassword = JUDownloadFrontHelperDocument::documentHasPassword($documentObject); $documentObject->params->set('has-password', $hasPassword); if ($hasPassword) { $validPassword = JUDownloadFrontHelperPassword::checkPassword($documentObject); } else { $validPassword = true; } $documentObject->params->set('valid-password', $validPassword); if ($canDownloadDocument && !$validPassword) { $documentObject->allow_enter_password = JUDownloadFrontHelperPassword::allowEnterPassword($documentObject->id); } $documentObject->download_link = JRoute::_('index.php?option=com_judownload&task=download.download&doc_id=' . $documentObject->id . '&' . $token . '=1'); $documentObject->download_link .= '&return=' . $return; if ($params->get('show_rule_messages', 'modal') != 'hide') { $downloadRuleErrorMessages = JUDownloadFrontHelperDocument::getDownloadRuleErrorMessages($documentObject->id); if ($downloadRuleErrorMessages !== true) { $documentObject->error_msg = $downloadRuleErrorMessages; } } } if ($documentObject->published != 1) { $documentObject->label_unpublished = true; } else { $documentObject->label_unpublished = false; } $documentObject->label_pending = false; $nowDate = JFactory::getDate()->toSql(); if (intval($documentObject->publish_up) > 0) { if (strtotime($documentObject->publish_up) > strtotime($nowDate)) { $documentObject->label_pending = true; } } $documentObject->label_expired = false; if (intval($documentObject->publish_down) > 0) { if (intval($documentObject->publish_up) > 0) { if (strtotime($documentObject->publish_up) <= strtotime($nowDate)) { if (strtotime($documentObject->publish_down) < strtotime($nowDate)) { $documentObject->label_expired = true; } } } else { if (strtotime($documentObject->publish_down) < strtotime($nowDate)) { $documentObject->label_expired = true; } } } if ($params->get('show_new_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->publish_up, $params->get('num_day_to_show_as_new', 10))) { $documentObject->label_new = true; } else { $documentObject->label_new = false; } if ($params->get('show_updated_label', 1) && JUDownloadFrontHelper::isWithinXDays($documentObject->updated, $params->get('num_day_to_show_as_updated', 10))) { $documentObject->label_updated = true; } else { $documentObject->label_updated = false; } if ($params->get('show_hot_label', 1) && JUDownloadFrontHelperDocument::checkHotDocument($documentObject->publish_up, $params->get('num_download_per_day_to_be_hot', 10), $documentObject->downloads)) { $documentObject->label_hot = true; } else { $documentObject->label_hot = false; } if ($params->get('show_featured_label', 1) && $documentObject->featured) { $documentObject->label_featured = true; } else { $documentObject->label_featured = false; } } } }
public function loadTemplate($tpl = null) { $this->_output = null; $app = JFactory::getApplication(); $template = JFactory::getApplication()->getTemplate(); if ($this->getName() == 'category' || $this->getName() == 'tree') { $layoutUrl = $app->input->getString('layout', ''); if (isset($layoutUrl) && $layoutUrl != '') { $layout = $layoutUrl; } else { $layout = null; } $catId = $app->input->getInt('id', 1); $layout = JUDownloadFrontHelperCategory::getCategoryViewLayout($layout, $catId); $this->setLayout($layout); } elseif ($this->getName() == 'document') { $layoutUrl = $app->input->getString('layout', ''); if (isset($layoutUrl) && $layoutUrl != '') { $layout = $layoutUrl; } else { $layout = null; } $docId = $app->input->getInt('id', 0); if ($docId > 0) { $layout = JUDownloadFrontHelperDocument::getDocumentViewLayout($layout, $docId); $this->setLayout($layout); } } $layout = $this->getLayout(); $layoutTemplate = $this->getLayoutTemplate(); $file = isset ($tpl) ? $layout . '_' . $tpl : $layout; $file = preg_replace('/[^A-Z0-9_\.-]/i', '', $file); $tpl = isset ($tpl) ? preg_replace('/[^A-Z0-9_\.-]/i', '', $tpl) : $tpl; $lang = JFactory::getLanguage(); $lang->load('tpl_' . $template, JPATH_BASE, null, false, false) || $lang->load('tpl_' . $template, JPATH_THEMES . "/$template", null, false, false); $component = JApplicationHelper::getComponentName(); $component = preg_replace('/[^A-Z0-9_\.-]/i', '', $component); $app = JFactory::getApplication(); $id = $app->input->getInt('id', 0); $user = JFactory::getUser(); if ($previewStyle = (int) $app->input->getInt('tplStyle', 0)) { if ($user->id == 0) { $uri = JUri::getInstance(); $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false); $app->enqueueMessage(JText::_("COM_JUDOWNLOAD_YOU_MUST_LOGIN_AS_SUPER_ADMIN_TO_PREVIEW_TEMPLATE_STYLE"), 'Notice'); $app->redirect($loginUrl); return false; } else { if (!$user->authorise('core.admin', 'com_judownload')) { $app->enqueueMessage(JText::_("COM_JUDOWNLOAD_YOU_MUST_LOGIN_AS_SUPER_ADMIN_TO_PREVIEW_TEMPLATE_STYLE"), 'Notice'); } } } if ($user->authorise('core.admin', 'com_judownload') && $previewStyle = (int) $app->input->getInt('tplStyle', 0)) { $currentTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleObject($previewStyle); } else { $currentTemplateStyleObject = JUDownloadFrontHelperTemplate::getCurrentTemplateStyle($this->getName(), $id); } $JUTemplate = trim($currentTemplateStyleObject->folder); $JUTemplate = strtolower($JUTemplate); $this->template_params = $currentTemplateStyleObject->params; if (!$JUTemplate) { $JUTemplate = 'default'; } $this->template = $JUTemplate; $JUTemplatePath = JUDownloadFrontHelperTemplate::getTemplatePathWithoutRoot($currentTemplateStyleObject->template_id); $topLevelTemplate = $JUTemplatePath[0]->folder ? $JUTemplatePath[0]->folder : 'default'; $asset_file = JPATH_SITE . '/components/com_judownload/templates/' . $topLevelTemplate . '/load_assets.php'; if (JFile::exists($asset_file)) { include_once $asset_file; } $JUTemplatePathFull = array(); $JUTemplatePathFull[] = $this->_basePath . '/templates/default/' . $this->getName(); $JUTemplatePathFull[] = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . 'default' . '/' . $this->getName(); $JUTemplatePath = array_reverse($JUTemplatePath); foreach ($JUTemplatePath AS $JUTemplatePathItem) { $JUTemplatePathFull[] = $this->_basePath . '/templates/' . $JUTemplatePathItem->folder . '/' . $this->getName(); $JUTemplatePathFull[] = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $JUTemplatePathItem->folder . '/' . $this->getName(); } foreach ($JUTemplatePathFull AS $item) { $this->_addPath('template', $item); } if (isset ($layoutTemplate) && $layoutTemplate != '_' && $layoutTemplate != $template) { $this->_path['template'] = str_replace($template, $layoutTemplate, $this->_path['template']); } $jversion_arr = explode(".", JVERSION); $priVersion = $jversion_arr[0]; $subVersion = $jversion_arr[1]; $fileToFind = $this->_createFileName('template', array('name' => $file . '.j' . $priVersion . $subVersion)); $this->_template = JPath::find($this->_path['template'], $fileToFind); if ($this->_template == false) { $fileToFind = $this->_createFileName('template', array('name' => $file . '.j' . $priVersion . 'x')); $this->_template = JPath::find($this->_path['template'], $fileToFind); } if ($this->_template == false) { $fileToFind = $this->_createFileName('template', array('name' => $file)); $this->_template = JPath::find($this->_path['template'], $fileToFind); } if ($this->_template == false) { $fallbackPaths = array(); $fallbackPaths[] = $this->_basePath . '/templates/default/' . $this->getName(); $fallbackPaths[] = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . 'default' . '/' . $this->getName(); foreach ($fallbackPaths AS $fallbackPath) { $fallbackPath = trim($fallbackPath); if (substr($fallbackPath, -1) != DIRECTORY_SEPARATOR) { $fallbackPath .= DIRECTORY_SEPARATOR; } array_unshift($fallbackPaths, $fallbackPath); } $fileToFind = $this->_createFileName('', array('name' => 'default.j' . $priVersion . $subVersion . (isset($tpl) ? '_' . $tpl : $tpl))); $this->_template = JPath::find($fallbackPaths, $fileToFind); if ($this->_template == false) { $fileToFind = $this->_createFileName('', array('name' => 'default.j' . $priVersion . 'x' . (isset($tpl) ? '_' . $tpl : $tpl))); $this->_template = JPath::find($fallbackPaths, $fileToFind); } if ($this->_template == false) { $fileToFind = $this->_createFileName('', array('name' => 'default' . (isset($tpl) ? '_' . $tpl : $tpl))); $this->_template = JPath::find($fallbackPaths, $fileToFind); } } if ($this->_template != false) { unset ($tpl); unset ($file); if (isset ($this->this)) { unset ($this->this); } ob_start(); include $this->_template; $this->_output = ob_get_contents(); ob_end_clean(); return $this->_output; } else { return JError::raiseError(500, JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file)); } }
public function canDownloadDocument($documentId, $checkPassword = true) { $storeId = md5(__METHOD__ . "::$documentId::" . (int) $checkPassword); if (!isset($this->cache[$storeId])) { $mainCategoryId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId); $canDoCategory = JUDownloadFrontHelperPermission::canDoCategory($mainCategoryId); if (!$canDoCategory) { $this->cache[$storeId] = false; return $this->cache[$storeId]; } $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentId); if ($isDocumentOwner) { $asset = 'com_judownload.document.' . $documentId; $user = JFactory::getUser(); if ($user->authorise('judl.document.download.own.no_restrict', $asset)) { $this->cache[$storeId] = true; return $this->cache[$storeId]; } } $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isModerator) { $documentObject = JUDownloadHelper::getDocumentById($documentId); if ($documentObject->approved < 1) { $modCanApprove = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategoryId, 'document_approve'); if ($modCanApprove) { $this->cache[$storeId] = true; return $this->cache[$storeId]; } } $modCanDownload = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategoryId, 'document_download'); if ($modCanDownload) { $this->cache[$storeId] = true; return $this->cache[$storeId]; } } if ($isDocumentOwner) { $userCanDoDocument = true; } else { $userCanDoDocument = JUDownloadFrontHelperPermission::userCanDoDocument($documentId, true); } if (!$userCanDoDocument) { $this->cache[$storeId] = false; return $this->cache[$storeId]; } if (!$isModerator || ($isModerator && !$modCanDownload)) { $validDownloadRules = JUDownloadFrontHelperDocument::getDownloadRuleErrorMessages($documentId); if ($validDownloadRules !== true) { $message = array(); $message = array_merge($message, $validDownloadRules); $this->setError(implode("<br/>", $message)); $this->cache[$storeId] = false; return $this->cache[$storeId]; } } $documentObject = JUDownloadHelper::getDocumentById($documentId); $hasPassword = JUDownloadFrontHelperDocument::documentHasPassword($documentObject); if ($hasPassword && $checkPassword) { $validPassword = JUDownloadFrontHelperPassword::checkPassword($documentObject); if (!$validPassword) { $this->setError(JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_PASSWORD')); $this->cache[$storeId] = false; return $this->cache[$storeId]; } } $this->cache[$storeId] = true; return $this->cache[$storeId]; } return $this->cache[$storeId]; }
public function canView($options = array()) { $storeId = md5(__METHOD__ . "::" . $this->doc_id . "::" . $this->id . "::" . serialize($options)); if (!isset(self::$cache[$storeId])) { if (!$this->isPublished()) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } $app = JFactory::getApplication(); $languageFilter = $app->getLanguageFilter(); if ($languageFilter) { $languageTag = JFactory::getLanguage()->getTag(); if (($this->language != $languageTag && $this->language != '*' && $this->language != '')) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } } if ($this->doc_id) { $document_display_params = JUDownloadFrontHelperDocument::getDocumentDisplayParams($this->doc_id); $document_display_fields = $document_display_params->get('fields'); } $options = (array) $options; $field_name = $this->field_name ? $this->field_name : $this->id; if ($this->isDetailsView($options)) { if (isset($document_display_fields->$field_name) && isset($document_display_fields->$field_name->details_view)) { if (!$document_display_fields->$field_name->details_view) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } } elseif (!$this->details_view) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } } else { if (isset($document_display_fields->$field_name) && isset($document_display_fields->$field_name->list_view)) { if (!$document_display_fields->$field_name->list_view) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } } elseif (!$this->list_view) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } } if (isset($this->doc) && $this->doc->cat_id) { $params = JUDownloadHelper::getParams($this->doc->cat_id); } else { $params = JUDownloadHelper::getParams(null, $this->doc_id); } $show_empty_field = $params->get('show_empty_field', 0); if ($this->doc_id && !$show_empty_field) { $field_value = $this->value; if (is_null($field_value)) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } if (is_string($field_value) && trim($field_value) === '') { self::$cache[$storeId] = false; return self::$cache[$storeId]; } if (is_array($field_value) && count($field_value) == 0) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } } $user = JFactory::getUser(); if ($user) { $viewLevels = JAccess::getAuthorisedViewLevels($user->id); $fieldGroupObj = JUDownloadFrontHelperField::getFieldGroupById($this->group_id); if (!in_array($fieldGroupObj->access, $viewLevels)) { self::$cache[$storeId] = false; return self::$cache[$storeId]; } else { if (in_array($this->access, $viewLevels)) { self::$cache[$storeId] = true; return self::$cache[$storeId]; } else { if ($this->doc_id && $this->who_can_download_can_access) { $canDownloadDocument = JUDownloadFrontHelperPermission::canDownloadDocument((int) $this->doc_id, true); return $canDownloadDocument; } } } } self::$cache[$storeId] = false; return self::$cache[$storeId]; } return self::$cache[$storeId]; }
public function download() { JSession::checkToken('request') or die(JText::_('JINVALID_TOKEN')); $model = $this->getModel(); $model->deleteExpiredTmpFiles(); $app = JFactory::getApplication(); $submittedCategoryId = $app->input->getInt('cat_id', 0); $documentIds = $app->input->get('doc_id', null, null); $fileIds = $app->input->get('file_id', null, null); $version = $app->input->get('version', '', 'string'); $serverTime = JFactory::getDate()->toSql(); $serverTimeStamp = strtotime($serverTime); $valuesStoreId = (array) $app->getUserState('com_judownload.download.storeid'); $params = JUDownloadHelper::getParams(); $noCountingDownloadTime = (int) $params->get('no_counting_download_time', 300); if ($noCountingDownloadTime > 0) { if (!empty($valuesStoreId)) { foreach ($valuesStoreId AS $keyStoreId => $valueStoreId) { if ($serverTimeStamp - $keyStoreId > $noCountingDownloadTime) { unset($valuesStoreId[$keyStoreId]); } } } $app->setUserState('com_judownload.download.storeid', $valuesStoreId); } $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('judownload'); if (isset($fileIds)) { if (is_array($fileIds)) { $fileIdArray = $fileIds; } else { $fileIdArray = explode(',', $fileIds); } if (count($fileIdArray) > 0) { if (count($fileIdArray) > 1) { $documentId = (int) $documentIds; if (!$documentIds) { $message = JText::_('COM_JUDOWNLOAD_NO_DOCUMENT_DETECTED'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } $fileObjectList = $model->getAllFilesOfDocument($documentId); $validFileIdArray = array(); foreach ($fileObjectList AS $fileObject) { if (in_array($fileObject->id, $fileIdArray)) { $validFileIdArray[] = $fileObject->id; } } } else { $fileObject = $model->getFileObject($fileIdArray[0]); $documentId = $fileObject->doc_id; if (isset($documentIds)) { $documentIdPost = (int) $documentIds; if ($documentIdPost != $documentId) { $message = JText::_('COM_JUDOWNLOAD_INVALID_DATA'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } $validFileIdArray = $fileIdArray; $physicalFilePath = $model->getPhysicalFilePath($validFileIdArray[0]); $physicalFilePath = JPath::clean($physicalFilePath); if (!JFile::exists($physicalFilePath)) { $message = JText::_('COM_JUDOWNLOAD_FILE_DOES_NOT_EXIST'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } $canDownloadDocument = $model->canDownloadDocument($documentId); if ($canDownloadDocument) { if (count($validFileIdArray) > 0) { $externalField = new JUDownloadFieldCore_external_link(); $document = JUDownloadHelper::getDocumentById($documentId); if ($externalField->isPublished() && $document->external_link != '') { $dispatcher->trigger('onAfterDownloadDocument', array($documentId, array(), 0)); $logData = array( 'user_id' => JFactory::getUser()->id, 'event' => 'document.download', 'item_id' => $documentId, 'doc_id' => $documentId, 'value' => 0, 'reference' => 'external' ); JUDownloadFrontHelperLog::addLog($logData); JUDownloadFrontHelperMail::sendEmailByEvent('document.download', $documentId); $model->updateDocumentDownloadCounter($documentId); $this->setRedirect(JRoute::_($document->external_link, false)); return true; } if (count($validFileIdArray) > 1) { $params = JUDownloadHelper::getParams(null, (int) $documentId); if (!$params->get('allow_zip_file', 1)) { $message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } foreach ($validFileIdArray AS $validFileId) { $canDownloadFile = $model->canDownloadFile($validFileId, false); if (!$canDownloadFile) { $fileObject = $model->getFileObject($validFileId); $message = JText::sprintf('COM_JUDOWNLOAD_YOU_CAN_NOT_DOWNLOAD_FILE_X', $fileObject->rename); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } if ($noCountingDownloadTime > 0) { sort($validFileIdArray); $storeID = md5('file' . serialize($validFileIdArray) . $version); if (in_array($storeID, $valuesStoreId)) { $generalCheck = true; } else { $generalCheck = $model->generalCheckDownload(); } } else { $generalCheck = $model->generalCheckDownload(); } if (!$generalCheck) { $message = $model->getError(); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } if ($model->download('file', $validFileIdArray, $documentId, $version) === false) { $message = $model->getError(); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } else { $message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } else { $message = implode("<br/>", $model->getErrors()); $params = JUDownloadHelper::getParams(null, $documentId); $display_messages = $params->get('show_rule_messages', 'modal'); if ($display_messages == "redirect") { $return = $app->input->get('return', null, 'base64'); $this->setRedirect(JRoute::_('index.php?option=com_judownload&view=downloaderror&return=' . $return, false), $message, 'error'); } else { $this->setRedirect($this->getReturnPage(), $message, 'error'); } return false; } } else { $message = JText::_('COM_JUDOWNLOAD_NO_FILE_TO_DOWNLOAD'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } else { if (is_array($documentIds)) { $documentIdArray = $documentIds; } else { $documentIdArray = explode(',', $documentIds); } if (count($documentIdArray) > 0) { if (count($documentIdArray) > 1) { $categoryId = $submittedCategoryId; if (!$categoryId) { $message = JText::_('COM_JUDOWNLOAD_NO_CATEGORY_DETECTED'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } $params = JUDownloadHelper::getParams(null, $categoryId); if (!$params->get('allow_download_multi_docs', 0)) { $message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } $validDocumentIdArray = array(); $documentIdsInCat = $model->getChildDocumentIds($categoryId); foreach ($documentIdsInCat AS $documentIdInCat) { if (in_array($documentIdInCat, $documentIdArray)) { $validDocumentIdArray[] = $documentIdInCat; } } } else { $documentId = $documentIdArray[0]; $categoryId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId); $validDocumentIdArray = $documentIdArray; $documentIdInCat = JUDownloadHelper::getDocumentById($documentId); $externalField = new JUDownloadFieldCore_external_link(); if ($externalField->isPublished() && $documentIdInCat->external_link != '') { $dispatcher->trigger('onAfterDownloadDocument', array($documentId, array(), 0)); $logData = array( 'user_id' => JFactory::getUser()->id, 'event' => 'document.download', 'item_id' => $documentId, 'doc_id' => $documentId, 'value' => 0, 'reference' => 'external' ); JUDownloadFrontHelperLog::addLog($logData); JUDownloadFrontHelperMail::sendEmailByEvent('document.download', $documentId); $model->updateDocumentDownloadCounter($documentId); $this->setRedirect(JRoute::_($documentIdInCat->external_link, false)); return true; } } if (count($validDocumentIdArray) > 1) { $params = JUDownloadHelper::getParams($categoryId); if (!$params->get('allow_zip_file', 1)) { $message = JText::_('COM_JUDOWNLOAD_INVALID_DOWNLOAD_DATA'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } elseif (count($validDocumentIdArray) == 1) { $filesInDocument = JUDownloadFrontHelperDocument::getFilesByDocumentId((int) $validDocumentIdArray[0]); if (count($filesInDocument) > 1) { if (!$params->get('allow_zip_file', 1)) { $linkFiles = JUDownloadHelperRoute::getDocumentRoute((int) $validDocumentIdArray[0]); $linkFiles .= '#judl-files'; $app->redirect(JRoute::_($linkFiles, false)); } } } foreach ($validDocumentIdArray AS $documentId) { $canDownloadDocument = $model->canDownloadDocument($documentId); if (!$canDownloadDocument) { $message = implode("<br/>", $model->getErrors()); $params = JUDownloadHelper::getParams(null, $documentId); $display_messages = $params->get('show_rule_messages', 'modal'); if ($display_messages == "redirect") { $return = $app->input->get('return', null, 'base64'); $this->setRedirect(JRoute::_('index.php?option=com_judownload&view=downloaderror&return=' . $return, false), $message, 'error'); } else { $this->setRedirect($this->getReturnPage(), $message, 'error'); } return false; } } if ($noCountingDownloadTime > 0) { sort($validDocumentIdArray); $storeID = md5('document' . serialize($validDocumentIdArray) . $version); if (in_array($storeID, $valuesStoreId)) { $generalCheck = true; } else { $generalCheck = $model->generalCheckDownload(); } } else { $generalCheck = $model->generalCheckDownload(); } if (!$generalCheck) { $message = $model->getError(); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } if (count($validDocumentIdArray) == 1) { if (count($filesInDocument) == 1) { if (!$params->get('allow_zip_file', 1)) { $fileObject = $filesInDocument[0]; $fileId = $fileObject->id; if ($model->download('file', array($fileId), $validDocumentIdArray[0], $version) === false) { $message = $model->getError(); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } } } if ($model->download('document', $validDocumentIdArray, $categoryId, $version) === false) { $message = $model->getError(); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } else { $message = JText::_('COM_JUDOWNLOAD_NO_DOCUMENT_TO_DOWNLOAD'); $this->setRedirect($this->getReturnPage(), $message, 'error'); return false; } } }