protected function allowAdd($data = array()) { if (empty($data)) { $catId = JFactory::getApplication()->input->get('cat_id'); if (!JUDownloadFrontHelperPermission::canSubmitDocument($catId)) { return false; } } return true; }
public static function checkPassword($documentObject) { $isDocumentOwner = JUDownloadFrontHelperPermission::isDocumentOwner($documentObject->id); $isModerator = JUDownloadFrontHelperModerator::isModerator(); if ($isDocumentOwner) { $asset = 'com_judownload.document.' . $documentObject->id; $user = JFactory::getUser(); if ($user->authorise('judl.document.download.own.no_restrict', $asset)) { return true; } } if ($isModerator) { $mainCategory = JUDownloadFrontHelperCategory::getMainCategory($documentObject->id); $modCanDownload = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategory->id, 'document_download'); if ($modCanDownload) { return true; } if ($documentObject->approved < 1) { $modCanApproval = JUDownloadFrontHelperModerator::checkModeratorCanDoWithDocument($mainCategory->id, 'document_approve'); if ($modCanApproval) { return true; } } } $session = JFactory::getSession(); if ($session->get('judl-download-password-' . $documentObject->id, '') === $documentObject->download_password) { return true; } else { return false; } }
public function checkin($pks = array()) { $pks = (array) $pks; $table = $this->getTable(); $count = 0; if (empty($pks)) { $pks = array((int) $this->getState($this->getName() . '.id')); } foreach ($pks as $pk) { if ($table->load($pk)) { if ($table->checked_out > 0) { if (JUDownloadFrontHelperPermission::canCheckInComment($pk)) { if (!$table->checkin($pk)) { $this->setError($table->getError()); return false; } $count++; } else { $this->setError(JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_CHECK_IN_COMMENT')); return false; } } } else { $this->setError($table->getError()); return false; } } return $count; }
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 validateCriteria($data) { $documentId = $data['doc_id']; $params = JUDownloadHelper::getParams(null, $documentId); $dataValid = array(); $canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($documentId); if ($canRateDocument && $params->get('enable_doc_rate_in_comment_form', 1)) { $mainCatId = JUDownloadFrontHelperCategory::getMainCategoryId($documentId); $criteriaArray = JUDownloadFrontHelperCriteria::getCriteriasByCatId($mainCatId); $postCriteria = $data['criteria']; if (count($criteriaArray) > 0) { foreach ($criteriaArray AS $key => $criteria) { if ($criteria->required) { if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10) { $criteria->value = $postCriteria[$criteria->id]; } else { echo JText::_('Invalid Field ' . $criteria->title); exit; } } else { if (isset($postCriteria[$criteria->id]) && $postCriteria[$criteria->id] > 0 && $postCriteria[$criteria->id] <= 10) { $criteria->value = $postCriteria[$criteria->id]; } else { unset($criteriaArray[$key]); } } } $dataValid['criteria_array'] = $criteriaArray; } else { if ($params->get('require_doc_rate_in_comment_form', 1)) { if (($data['judl_comment_rating_single'] <= 0) && ($data['judl_comment_rating_single'] > 10)) { return false; } $dataValid['ratingValue'] = $data['judl_comment_rating_single']; } } } return $dataValid; }
* ------------------------------------------------------------------------ * JUDownload for Joomla 2.5, 3.x * ------------------------------------------------------------------------ * * @copyright Copyright (C) 2010-2015 JoomUltra Co., Ltd. All Rights Reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt * @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::_(JUDownloadHelperRoute::getFormRoute()); $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); ?> <div class="navbar"> <div class="navbar-inner"> <ul class="nav">
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 _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 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 getCatIdTree($catId, $includeItSelf = true) { $catId = (int) $catId; if (!$catId) { return null; } if (!JUDownloadFrontHelperPermission::canDoCategory($catId)) { return null; } $cat_id_arr = array(); if ($includeItSelf) { $cat_id_arr[] = $catId; } $db = JFactory::getDbo(); $query = "SELECT id FROM #__judownload_categories WHERE parent_id = " . $catId; $db->setQuery($query); $child_cat_ids = $db->loadColumn(); foreach ($child_cat_ids AS $child_cat_id) { $cat_id_arr[] = $child_cat_id; $child_cat_id_arr = $this->getCatIdTree($child_cat_id, false); if ($child_cat_id_arr) { $cat_id_arr = array_merge($cat_id_arr, $child_cat_id_arr); } } return array_unique($cat_id_arr); }
protected function canDelete($record) { $rootComment = JUDownloadFrontHelperComment::getRootComment(); if (isset($record->id) && $record->id == $rootComment->id) { return false; } $app = JFactory::getApplication(); if ($app->isSite()) { return JUDownloadFrontHelperPermission::canDeleteComment($record->id); } return parent::canDelete($record); }
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 static function canViewDashboard() { $params = JUDownloadHelper::getParams(); $public_user_dashboard = $params->get("public_user_dashboard", 0); $user = JFactory::getUser(); if ($public_user_dashboard) { $app = JFactory::getApplication(); $userId = $app->input->getInt('id', 0); if ($user->id == 0 && $userId == 0) { return false; } return true; } else { if ($user->id == 0) { return false; } else { $isOwnDashboard = JUDownloadFrontHelperPermission::isOwnDashboard(); return $isOwnDashboard; } } }
<?php if (JUDLPROVERSION && $this->params->get('can_subscribe_own_comment', 1)) { ?> <div class="comment-row"> <label class="comment-subscribe-lbl" for="comment-reply-subscribe-<?php echo $this->commentObj->id ?>"> <input name="subscribe" id="comment-reply-subscribe-<?php echo $this->commentObj->id ?>" class="comment-subscribe" type="checkbox" value="1"/> <?php echo JText::_('COM_JUDOWNLOAD_COMMENT_SUBSCRIBE'); ?> </label> </div> <?php } if (JUDownloadFrontHelperPermission::showCaptchaWhenComment($this->item->id)) { echo JUDownloadFrontHelperCaptcha::getCaptcha(true); } ?> </div> <div class="comment-form-submit clearfix"> <button type="button" class="btn btn-default btn-primary" onclick="Joomla.submitbutton('document.addComment', 'judl-comment-reply-form-<?php echo $this->commentObj->id; ?>');"><?php echo JText::_('COM_JUDOWNLOAD_SUBMIT'); ?> </button> <input type="reset" name="reply-reset" class="btn btn-default" value="<?php echo JText::_('COM_JUDOWNLOAD_RESET'); ?>"> </div> <div> <input type="hidden" name="task" value=""/>
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 display($tpl = null) { $this->model = $this->getModel(); $this->state = $this->get('State'); $this->params = $this->state->get('params'); $user = JFactory::getUser(); $uri = JUri::getInstance(); $this->items = $this->get('Items'); foreach ($this->items as $item) { $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, &$this->item, &$this->params, 0)); $item->event->afterDisplayTitle = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentBeforeDisplay', array($context, &$this->item, &$this->params, 0)); $item->event->beforeDisplayContent = trim(implode("\n", $results)); $results = $dispatcher->trigger('onContentAfterDisplay', array($context, &$this->item, &$this->params, 0)); $item->event->afterDisplayContent = trim(implode("\n", $results)); } $this->pagination = $this->get('Pagination'); $this->token = JSession::getFormToken(); if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->show_feed = JUDLPROVERSION ? $this->params->get('rss_display_icon', 1) : 0; $app = JFactory::getApplication(); $rootCategory = JUDownloadFrontHelperCategory::getRootCategory(); $this->categoryId = $app->input->getInt('id', $rootCategory->id); $this->fetchAllSubCat = $app->input->getInt('all', 0); $rssLink = JRoute::_(JUDownloadHelperRoute::getFeaturedRoute($this->categoryId, $this->fetchAllSubCat, false, true)); $this->rss_link = JRoute::_($rssLink, false); $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareData(); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
public function saveComment($postData = array()) { $user = JFactory::getUser(); $nowDate = JFactory::getDate()->toSql(); $title = htmlspecialchars($postData['title']); $comment = htmlspecialchars($postData['comment'], ENT_NOQUOTES); if ($user->get('guest')) { $guestName = strip_tags($postData['guest_name']); $guestEmail = strip_tags($postData['guest_email']); } else { $guestName = ''; $guestEmail = ''; } $website = isset($postData['website']) ? strip_tags($postData['website']) : ''; $docId = (int) $postData['doc_id']; $params = JUDownloadHelper::getParams(null, $docId); $totalVotes = 0; $helpfulVotes = 0; $ipAddress = JUDownloadFrontHelper::getIpAddress(); $parentId = (int) $postData['parent_id']; $rootComment = JUDownloadFrontHelperComment::getRootComment(); if ($parentId == $rootComment->id) { $approved = JUDownloadFrontHelperPermission::canAutoApprovalComment($docId); $level = 1; if ($params->get('filter_comment_language', 0)) { $language = $postData['comment_language']; } else { $language = '*'; } } else { $approved = JUDownloadFrontHelperPermission::canAutoApprovalReplyComment($docId); $parentComment = $this->getCommentObject($parentId); $level = $parentComment->level + 1; $language = '*'; } if ($approved) { $approved = 1; $published = 1; } else { $approved = 0; $published = 0; } $dataComment = array('title' => $title, 'comment' => $comment, 'user_id' => $user->id, 'guest_name' => $guestName, 'guest_email' => $guestEmail, 'website' => $website, 'doc_id' => $docId, 'created' => $nowDate, 'total_votes' => $totalVotes, 'helpful_votes' => $helpfulVotes, 'ip_address' => $ipAddress, 'approved' => $approved, 'published' => $published, 'parent_id' => $parentId, 'level' => $level, 'language' => $language ); JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_judownload/tables'); $commentTable = JTable::getInstance('Comment', 'JUDownloadTable'); $commentTable->setLocation($postData['parent_id'], 'last-child'); $commentTable->bind($dataComment); if (!$commentTable->check() || !$commentTable->store()) { $this->setError($commentTable->getError()); return false; } $canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($docId); if ($canRateDocument && $params->get('enable_doc_rate_in_comment_form', 1) && ($commentTable->parent_id == $rootComment->id)) { $postData['approved'] = $approved; $criteriaArray = array(); if (isset($postData['criteria_array'])) { if (JUDownloadHelper::hasMultiRating()) { $criteriaArray = $postData['criteria_array']; $saveRating = $this->saveRating($postData, $docId, $criteriaArray, $commentTable->id); } } else { if (isset($postData['ratingValue'])) { $saveRating = $this->saveRating($postData, $docId, $criteriaArray, $commentTable->id); } } if (!$saveRating) { $this->setError(JText::_('COM_JUDOWNLOAD_SAVE_RATING_FAILED')); return false; } } if (JUDLPROVERSION && isset($postData['subscribe']) && $postData['subscribe']) { $subscriptionData = array(); $subscriptionData['user_id'] = $user->id; $subscriptionData['type'] = 'comment'; $subscriptionData['comment_id'] = $commentTable->id; $subscriptionData['name'] = ($user->id == 0) ? $guestName : $user->username; $subscriptionData['email'] = ($user->id == 0) ? $guestEmail : $user->email; $subscriptionData['item_id'] = $commentTable->id; $subscriptionData['ip_address'] = $ipAddress; $subscriptionData['created'] = $nowDate; $subscriptionData['published'] = ($user->id == 0 && $params->get('activate_subscription_by_email', 1)) ? 0 : 1; require_once JPATH_SITE . '/components/com_judownload/models/subscribe.php'; JModelLegacy::addIncludePath(JPATH_SITE . '/components/com_judownload/models'); $subscribeModel = JModelLegacy::getInstance('Subscribe', 'JUDownloadModel'); if (!$subscribeModel->add($subscriptionData)) { $this->setError(JText::_('COM_JUDOWNLOAD_SUBSCRIBE_FAILED')); return false; } } if ($commentTable->parent_id == $rootComment->id) { JUDownloadFrontHelperMail::sendEmailByEvent('comment.create', $commentTable->id); $logData = array( 'item_id' => $commentTable->id, 'doc_id' => $docId, 'user_id' => $user->id, 'event' => 'comment.create' ); $commentSubmitType = 'create'; } else { JUDownloadFrontHelperMail::sendEmailByEvent('comment.reply', $commentTable->id); $logData = array( 'user_id' => $user->id, 'event' => 'comment.reply', 'item_id' => $commentTable->id, 'doc_id' => $docId, 'value' => 0, 'reference' => $commentTable->parent_id, ); $commentSubmitType = 'reply'; } JUDownloadFrontHelperLog::addLog($logData); $dispatcher = JDispatcher::getInstance(); JPluginHelper::importPlugin('judownload'); $dispatcher->trigger('onCommentSubmit', array($commentTable, $commentSubmitType)); return $commentTable->id; }
public static function isDocumentPublished($documentId) { $documentObject = JUDownloadHelper::getDocumentById($documentId); if (!is_object($documentObject)) { return false; } $catPublished = JUDownloadFrontHelperPermission::canDoCategory($documentObject->cat_id); if (!$catPublished) { return false; } $db = JFactory::getDbo(); $nullDate = $db->getNullDate(); $nowDate = JFactory::getDate()->toSql(); $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judownload_documents'); $query->where('approved = 1'); $query->where('published = 1'); $query->where('(publish_up = ' . $db->quote($nullDate) . ' OR publish_up <= ' . $db->quote($nowDate) . ')'); $query->where('(publish_down = ' . $db->quote($nullDate) . ' OR publish_down >= ' . $db->quote($nowDate) . ')'); $query->where('id =' . $documentId); $db->setQuery($query); $result = $db->loadResult(); if ($result) { return true; } return false; }
public function display($tpl = null) { $app = JFactory::getApplication(); $categoryId = $app->input->getInt('id', 1); $this->category = JUDownloadFrontHelperCategory::getCategory($categoryId); $error = array(); if (!JUDownloadFrontHelperPermission::canDoCategory($this->category->id, true, $error)) { $user = JFactory::getUser(); if ($user->id) { return JError::raiseError($error['code'], $error['message']); } else { $uri = JUri::getInstance(); $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false); $app = JFactory::getApplication(); $app->redirect($loginUrl, JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_ACCESS_THIS_PAGE'), 'warning'); return false; } } $model = $this->getModel(); $this->model = $model; $this->state = $this->get('State'); $this->params = $this->state->params; if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $this->parent_id = $this->category->id; $this->subcategory_level = (int) $this->params->get('all_categories_subcategory_level', -1); $this->all_categories = $model->getCategoriesRecursive($this->category->id, $this->subcategory_level); $firstCategory = $this->all_categories[0]; $this->category->total_childs = $firstCategory->total_childs; $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
public function getOutput($options = array()) { if (!$this->isPublished()) { return ""; } $options = new JRegistry($options); $this->initMultipleRatingField(); $this->loadDefaultAssets(); if ($this->doc->cat_id) { $this->criteriaGroupId = JUDownloadFrontHelperCriteria::getCriteriaGroupIdByCategoryId($this->doc->cat_id); } if (JUDownloadHelper::hasMultiRating()) { if ($this->criteriaGroupId) { $this->criteriaObjectList = JUDownloadFrontHelperCriteria::getCriteriasByCatId($this->doc->cat_id); } } $this->selectedStar = round($this->doc->rating * $this->totalStars / 10, 2); if ($this->isDetailsView($options)) { $this->canRateDocument = JUDownloadFrontHelperPermission::canRateDocument($this->doc_id); $document = JFactory::getDocument(); $document->addStyleSheet(JUri::root(true) . "/components/com_judownload/assets/css/jquery.rating.css"); $document->addScript(JUri::root(true) . "/components/com_judownload/assets/js/jquery.MetaData.js"); $document->addScript(JUri::root(true) . "/components/com_judownload/assets/js/jquery.rating.js"); $singleRatingScript = ' jQuery(document).ready(function ($) { $(".judl-single-rating").rating({ callback: function (value) { var str = $(this).attr("name"); var patt = /^judl-document-rating-result-(.*)$/i; var result = str.match(patt); var documentId = result[1]; var ratingValue = $(this).val(); var objectDocument = {}; var token = $("#judl-single-rating-token").attr("name"); objectDocument.doc_id = documentId; objectDocument.ratingValue = ratingValue; if ($.isNumeric(documentId) && (ratingValue > 0 && ratingValue <= 10)) { $.ajax({ type: "POST", url : "index.php?option=com_judownload&task=document.singleRating&" + token + "=1", data: objectDocument }).done(function (msg) { alert(msg); }); } } }); });'; if ($this->canRateDocument) { $document->addScriptDeclaration($singleRatingScript); } } if (is_object($this->multiRating)) { return $this->multiRating->getOutput($options); } else { $this->setVariable('options', $options); $this->setVariable('className', __CLASS__); return $this->fetch('output.php', __CLASS__); } }
public function remoteFile() { $app = JFactory::getApplication(); if (!$this->isValidUploadURL() || !JUDownloadFrontHelperPermission::canUploadFromUrl($app->input->get('doc_id', null))) { $result = array(); $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_YOU_ARE_NOT_AUTHORIZED_TO_UPLOAD_FILE'); JUDownloadHelper::obCleanData(); echo json_encode($result); exit; } $type = $app->input->get('type', ''); $result = array(); $file_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/"); $file_directory_tmp = $file_directory . "tmp/"; if (!JFolder::exists($file_directory_tmp)) { JFolder::create($file_directory_tmp); $file_index = $file_directory_tmp . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($file_index, $buffer); } if (!is_writable($file_directory_tmp)) { $file_directory_tmp = sys_get_temp_dir() . "/plupload/"; } if ($type === 'loadtransfer') { $source_url = $app->input->get('source_url', '', 'string'); if (!$source_url) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_SOURCE_URL_IS_MISSING'); } $file = $this->loadTransfer($source_url); if ($file) { $file_name = end(explode("/", $source_url)); $file_extension = end(explode(".", $file_name)); do { $target_name = md5(JUDownloadHelper::generateRandomString(10)) . "." . $file_extension; } while (JFile::exists($file_directory_tmp . $target_name)); $result['success'] = 1; $result['size'] = (int) $file[1]; $result['type'] = (string) $file[2]; $result['name'] = $file_name; $result['target_name'] = $target_name; } else { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_FILE'); } } elseif ($type === 'transferfile') { $target_name = $app->input->get('target_name', '', 'string'); $source_url = $app->input->get('source_url', '', 'string'); if (!$source_url) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_SOURCE_URL'); } elseif (!$target_name) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_INVALID_TARGET_NAME'); } elseif ($this->remoteDownload($source_url, $file_directory_tmp . $target_name, 1024)) { $result['success'] = 1; $result['alert'] = JText::_('COM_JUDOWNLOAD_DOWNLOAD_REMOTE_FILE_SUCCESSFULLY'); } else { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_FAIL_TO_DOWNLOAD_REMOTE_FILE'); } } elseif ($type === 'getprocess') { $target_name = $app->input->get('target_name', '', 'string'); $file_size = $app->input->getInt('file_size', 0); $current_size = filesize($file_directory_tmp . $target_name); if ($current_size === false || !$file_size) { $result['success'] = 0; $result['alert'] = JText::_('COM_JUDOWNLOAD_FAIL_TO_GET_FILE_TRANSFER_STATUS'); } else { if ($current_size >= $file_size) { $percent = 100; } else { $percent = round($current_size / $file_size * 100); } $result['success'] = 1; $result['alert'] = ''; $result['percent'] = $percent; } } if ($type === 'cancel') { $target_name = $app->input->get('target_name', '', 'string'); if (JFile::exists($file_directory_tmp . $target_name)) { JFile::delete($file_directory_tmp . $target_name); } } JUDownloadHelper::obCleanData(); echo json_encode($result); exit; }
public function filterField($values) { $oldImages = $values; $app = JFactory::getApplication(); $newImages = $app->input->files->get('field_' . $this->id); $gallery = $gallery['old'] = $gallery['new'] = array(); $params = JUDownloadHelper::getParams(null, $this->doc_id); $maxUploadImage = 4; $count = 0; if ($this->doc_id) { $db = JFactory::getDbo(); $query = 'SELECT id FROM #__judownload_images WHERE doc_id = ' . (int) $this->doc_id; $db->setQuery($query); $imageIds = $db->loadColumn(); foreach ($oldImages AS $key => $image) { if (!in_array($image['id'], $imageIds)) { continue; } if ($maxUploadImage > 0 && $count >= $maxUploadImage) { break; } $gallery['old'][] = $image; if (!$image['remove']) { $count++; } } } $error = array(); if ($newImages && (($count < $maxUploadImage && $maxUploadImage > 0) || $maxUploadImage <= 0)) { $legal_extensions = "jpeg,jpg,png,gif,bmp"; $legal_mime = "image/jpeg,image/pjpeg,image/png,image/gif,image/bmp,image/x-windows-bmp"; $image_min_width = $params->get("image_min_width", 50); $image_min_height = $params->get("image_min_height", 50); $image_max_width = $params->get("image_max_width", 1024); $image_max_height = $params->get("image_max_height", 1024); $image_max_size = $params->get("image_max_size", 400) * 1024; $num_files_exceed_limit = 0; $num_files_invalid_dimension = 0; foreach ($newImages AS $image) { if ($image['name']) { $image['name'] = str_replace(' ', '_', JFile::makeSafe($image['name'])); if ($count >= $maxUploadImage) { $num_files_exceed_limit++; continue; } if (!JUDownloadFrontHelperPermission::canUpload($image, $error, $legal_extensions, $image_max_size, true, $legal_mime, '', $legal_extensions)) { continue; } $image_dimension = getimagesize($image['tmp_name']); if ($image_dimension[0] < $image_min_width || $image_dimension[1] < $image_min_height || $image_dimension[0] > $image_max_width || $image_dimension[1] > $image_max_height) { $num_files_invalid_dimension++; continue; } $gallery['new'][] = $image; $count++; } } $app = JFactory::getApplication(); if ($error) { foreach ($error AS $key => $count) { switch ($key) { case 'WARN_SOURCE': case 'WARN_FILENAME': case 'WARN_FILETYPE': case 'WARN_FILETOOLARGE' : case 'WARN_INVALID_IMG' : case 'WARN_INVALID_MIME' : case 'WARN_IEXSS' : $error_str = JText::plural("COM_JUDOWNLOAD_N_FILE_" . $key, $count); break; } $app->enqueueMessage($error_str, 'notice'); } } if ($num_files_exceed_limit) { $image_upload_limit = JUDownloadHelper::formatBytes($image_max_size * 1024); $app->enqueueMessage(JText::plural('COM_JUDOWNLOAD_N_IMAGES_ARE_NOT_SAVED_BECAUSE_THEY_EXCEEDED_FILE_SIZE_LIMIT', $num_files_exceed_limit, $image_upload_limit), 'notice'); } if ($num_files_invalid_dimension) { $app->enqueueMessage(JText::plural('COM_JUDOWNLOAD_N_IMAGES_ARE_NOT_SAVED_BECAUSE_THEY_ARE_NOT_VALID_DIMENSION', $num_files_invalid_dimension, $image_min_width, $image_max_width, $image_min_height, $image_max_height), 'notice'); } } $gallery['count'] = $count; return $gallery; }
<?php echo JHtml::_('tabs.start', 'judownload-files', array('useCookie' => 1)); ?> <?php echo JHtml::_('tabs.panel', JText::_('COM_JUDOWNLOAD_UPLOADER_TAB'), 'file-uploader'); ?> <div id="judl-uploader" style="margin: 10px;"> <p><?php echo JText::_("COM_JUDOWNLOAD_YOUR_BROWSER_DOESNT_HAVE_FLASH_SILVERLIGHT_OR_HTML5_SUPPORT"); ?> </p> </div> <?php if (JUDownloadFrontHelperPermission::canUploadFromUrl($this->item->id)) { echo JHtml::_('tabs.panel', JText::_('COM_JUDOWNLOAD_FIELD_REMOTE_UPLOAD'), 'remote-file'); ?> <div id="remote-file" class="remote-file"> <div class="progress progress-striped"> <div class="bar" style="width: 0%;"></div> </div> <div class="clearfix"> <input type="text" class="source-url input-xlarge" size="78" value="" placeholder="<?php echo JText::_("COM_JUDOWNLOAD_FILE_URL"); ?> " /> <input class="btn btn-primary process-remote-file" type="button" value="<?php echo JText::_("COM_JUDOWNLOAD_TRANSFER_FILE"); ?> " />
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; }
public function display($tpl = null) { $this->state = $this->get('State'); $this->token = JSession::getFormToken(); $this->params = $this->state->params; $app = JFactory::getApplication(); $submit_simple_search = $app->input->getString('submit_simple_search', ''); if (isset($submit_simple_search) && $submit_simple_search == "search") { $model = $this->getModel(); $model->resetState(); } $this->model = $this->getModel(); $user = JFactory::getUser(); $uri = JUri::getInstance(); $this->items = $this->get('Items'); foreach ($this->items as $item) { $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->searchword = trim($app->input->getString('searchword', '')); $this->searchword = JUDownloadFrontHelper::UrlDecode($this->searchword); $this->cat_id = $app->input->getInt('cat_id', 0); $this->sub_cat = $app->input->getInt('sub_cat', 0); if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode("\n", $errors)); return false; } $nestedCategories = JUDownloadFrontHelperCategory::getCategoriesRecursive(1, false, false, true); $options = array(); $parent_cat_level = 0; foreach ($nestedCategories AS $key => $categoryObj) { if ($key == 0) { $parent_cat_level = $categoryObj->level; } $options[] = JHtml::_('select.option', $categoryObj->id, str_repeat('-.', ($categoryObj->level - $parent_cat_level)) . $categoryObj->title); } $this->cat_select_list = JHtml::_('select.genericList', $options, 'cat_id', '', 'value', 'text', $this->cat_id); $this->pageclass_sfx = htmlspecialchars($this->params->get('pageclass_sfx')); $this->_prepareData(); $this->_prepareDocument(); $this->_setBreadcrumb(); parent::display($tpl); }
$additionFields[] = 'license_id'; $additionFields[] = 'confirm_license'; } $specialFields = JUDownloadFrontHelperField::getFields($this->item, null, array("created", "title", "version", "featured", "downloads"), array(), $additionFields); ?> <tr class="<?php echo $item_class; ?>"> <?php if ($this->params->get('allow_zip_file', 1) && $this->params->get('allow_download_multi_docs', 0)) { ?> <td class="id"> <?php if ($this->item->total_files > 0 || (isset($specialFields['external_link']) && !empty($specialFields['external_link']))) { $canDownloadDocument = JUDownloadFrontHelperPermission::canDownloadDocument($this->item->id, false); if (!$canDownloadDocument) { ?> <input type="checkbox" name="doc_id[]" class="judl-cb-disabled" disabled value="<?php echo $this->item->id; ?>" id="cb<?php echo $this->index; ?>"/> <?php } else { if ($this->item->params->get('valid-password')) { ?> <input type="checkbox" checked="checked" name="doc_id[]" class="judl-cb" value="<?php echo $this->item->id; ?>" id="cb<?php echo $this->index; ?>"/> <?php } else