public function uploader() { error_reporting(0); JLoader::register('PluploadHandler', JPATH_SITE . '/components/com_judownload/helpers/pluploadhandler.php'); $targetDir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/") . "tmp"; $cleanupTargetDir = true; $maxFileAge = 5 * 3600; $this->cleanup($targetDir, $maxFileAge); if (!JFolder::exists($targetDir)) { JFolder::create($targetDir); $indexHtml = $targetDir . 'index.html'; $buffer = "<!DOCTYPE html><title></title>"; JFile::write($indexHtml, $buffer); } if (!is_writable($targetDir)) { $targetDir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "plupload"; if (!file_exists($targetDir)) { @mkdir($targetDir); } } PluploadHandler::no_cache_headers(); PluploadHandler::cors_headers(); if (!PluploadHandler::handle(array('target_dir' => $targetDir, 'cleanup' => $cleanupTargetDir, 'max_file_age' => $maxFileAge, 'cb_check_file' => array(__CLASS__, 'canUpload')))) { die(json_encode(array('OK' => 0, 'error' => array('code' => PluploadHandler::get_error_code(), 'message' => PluploadHandler::get_error_message())))); } else { die(json_encode(array('OK' => 1))); } }
public function setup(SimpleXMLElement $element, $value, $group = null) { $return = parent::setup($element, $value, $group); if ($return) { $directory = JUDownloadFrontHelper::getDirectory((string) $this->element['rel'], (string) $this->element['defaultRel']) . "default/"; $this->directory = $directory; } return $return; }
public static function getJUAvatar($id) { $user = JUDownloadFrontHelper::getUser($id, true); if ($user && isset($user->avatar)) { $avatar = JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('avatar_directory', 'media/com_judownload/images/avatar/', true) . $user->avatar; } else { $avatar = self::getDefaultAvatar(); } return $avatar; }
protected function getInput() { $params = JUDownloadHelper::getParams(); $max_upload = ini_get('upload_max_filesize'); $src = JUri::root() . JUDownloadFrontHelper::getDirectory("collection_icon_directory", "media/com_judownload/images/collection/", true) . $this->value; $html = "<div class=\"avatar\" style=\"float: left;\">"; if ($this->value) { $html .= "<div class=\"clearfix\"><img src=\"" . $src . "\" width=\"" . $params->get('collection_icon_width', 100) . "px\" height=\"" . $params->get('collection_icon_height', 100) . "px\" /></div>"; $html .= "<label><input type=\"checkbox\" name=\"remove_icon\" value=\"1\" /> " . JText::_('COM_JUDOWNLOAD_REMOVE_ICON') . "</label>"; } $html .= "<div class=\"clearfix\"><input type=\"file\" name=\"collection_icon\" id=\"" . $this->id . "\" />"; $html .= "<input type=\"hidden\" name=\"" . $this->name . "\" value=\"" . $this->value . "\" /></div>"; $html .= "<div class=\"clearfix\"><i>" . JText::_('COM_JUDOWNLOAD_MAX_UPLOAD_FILESIZE') . " <strong>" . JUDownloadHelper::formatBytes($this->convertBytes($max_upload)) . "</strong></i></div>"; $html .= "</div>"; return $html; }
public function display($tpl = null) { if (count($errors = $this->get('Errors'))) { JError::raiseError(500, implode('<br />', $errors)); return false; } $app = JFactory::getApplication(); $this->type = $app->input->get('type', ''); if (!$this->type || $this->type == 'icon') { $this->icon_url = JUri::root(true) . "/" . JUDownloadFrontHelper::getDirectory("document_image_directory", "media/com_judownload/images/document/", true) . "default/"; $this->icon_directory = JPath::clean(JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_image_directory", "media/com_judownload/images/document/") . "default/"); } elseif ($this->type == 'marker') { $this->icon_url = JUri::root(true) . "/media/com_judownload/markers/"; $this->icon_directory = JPath::clean(JPATH_ROOT . "/media/com_judownload/images/markers/"); } $this->folders = $this->getFolders(); $this->folder = $app->input->get('folder', '', 'string'); if (!in_array($this->folder, $this->folders)) { $this->folder = ''; } $this->icons = $this->getIcons(); $this->setDocument(); parent::display($tpl); }
protected function getInput() { $params = JUDownloadHelper::getParams(); $max_upload = ini_get('upload_max_filesize'); if ($this->value) { $src = JUri::root(true) . "/" . JUDownloadFrontHelper::getDirectory("avatar_directory", "media/com_judownload/images/avatar/", true) . $this->value; } else { $src = JUri::root(true) . "/" . JUDownloadFrontHelper::getDirectory("avatar_directory", "media/com_judownload/images/avatar/", true) . "default/" . $params->get('default_avatar', 'default-avatar.png'); } $html = '<div class="avatar" style="float: left;">'; $html .= '<div class="clearfix"><img src="' . $src . '" alt="Avatar" style="width:' . $params->get("avatar_width", 120) . 'px; height:' . $params->get("avatar_height", 120) . 'px;" /></div>'; if ($this->value) { $html .= '<label for="remove-avatar">' . JText::_("COM_JUDOWNLOAD_REMOVE_AVATAR") . ' <input id="remove-avatar" type="checkbox" name="remove_avatar" value="1" /></label>'; } $html .= '<div class="clearfix"><input type="file" name="avatar" id="' . $this->id . '" />'; $html .= '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '" /></div>'; $html .= '<div class="clearfix"><i>' . JText::_("COM_JUDOWNLOAD_MAX_UPLOAD_FILESIZE") . ' <strong>' . JUDownloadHelper::formatBytes($this->convertBytes($max_upload)) . '</strong></i></div>'; $html .= '</div>'; return $html; }
public function delete(&$pks) { $dispatcher = JDispatcher::getInstance(); $pks = (array) $pks; $table = $this->getTable(); JPluginHelper::importPlugin('content'); $modelDocument = JModelLegacy::getInstance('Document', 'JUDownloadModel'); $documentTable = JTable::getInstance("Document", "JUDownloadTable"); $canDeleteCatIds = $canNotDeleteCatIds = $canDeleteDocIds = $canNotDeleteDocIds = array(); $db = JFactory::getDbo(); while (!empty($pks)) { $pk = array_shift($pks); $table->reset(); if ($table->load($pk)) { $deleteCurrentCat = true; if ($this->canDelete($table)) { $query = $db->getQuery(true); $query->SELECT('doc_id'); $query->FROM('#__judownload_documents_xref'); $query->WHERE('cat_id=' . $pk . ' AND main=1'); $db->setQuery($query); $docIds = $db->loadColumn(); if ($docIds) { foreach ($docIds as $docId) { $documentTable->reset(); if ($documentTable->load($docId)) { if ($modelDocument->canDelete($documentTable)) { $canDeleteDocIds[] = $docId; } else { $canNotDeleteDocIds[] = $docId; $deleteCurrentCat = false; } } } } } else { $deleteCurrentCat = false; } if (!$deleteCurrentCat) { $canNotDeleteCatIds[] = $pk; } else { $canDeleteCatIds[] = $pk; } $query = $db->getQuery(true); $query->select('id'); $query->from('#__judownload_categories'); $query->where('lft > ' . (int) $table->lft); $query->where('rgt < ' . (int) $table->rgt); $query->order('lft'); $db->setQuery($query); $childIds = $db->loadColumn(); foreach ($childIds as $childId) { if (!in_array($childId, $pks)) { array_push($pks, $childId); } } } } if ($canNotDeleteCatIds) { foreach ($canNotDeleteCatIds as $caNotDeleteCatId) { $categories = $table->getPath($caNotDeleteCatId); if ($categories) { foreach ($categories as $category) { $canDeleteCatIdIndex = array_search($category->id, $canDeleteCatIds); if ($canDeleteCatIdIndex !== false) { unset($canDeleteCatIds[$canDeleteCatIdIndex]); $canNotDeleteCatIds[] = $category->id; } } } } } $canDeleteDocIds = array_unique($canDeleteDocIds); if ($canDeleteDocIds) { foreach ($canDeleteDocIds as $docId) { if (!$documentTable->delete($docId)) { $this->setError($documentTable->getError()); return false; } } } $canDeleteCatIds = array_unique($canDeleteCatIds); if ($canDeleteCatIds) { foreach ($canDeleteCatIds as $pk) { if ($table->load($pk)) { $context = $this->option . '.' . $this->name; $result = $dispatcher->trigger($this->event_before_delete, array($context, $table)); if (in_array(false, $result, true)) { $this->setError($table->getError()); return false; } if (!$table->delete($pk, false)) { $this->setError($table->getError()); return false; } else { $query = "DELETE FROM #__judownload_categories_relations WHERE cat_id=" . $pk; $db->setQuery($query); $db->execute(); $query = "DELETE FROM #__judownload_documents_xref WHERE main=0 AND cat_id=" . $pk; $db->setQuery($query); $db->execute(); $query = "SELECT mod_id FROM #__judownload_moderators_xref WHERE cat_id = " . $pk; $db->setQuery($query); $moderatorIds = $db->loadColumn(); $query = "DELETE FROM #__judownload_moderators_xref WHERE cat_id=" . $pk; $db->setQuery($query); $db->execute(); if ($moderatorIds) { $modTable = JTable::getInstance("Moderator", "JUDownloadTable"); foreach ($moderatorIds as $moderatorId) { $query = $db->getQuery(true); $query->select('COUNT(*)'); $query->from('#__judownload_moderators AS m'); $query->join('', '#__judownload_moderators_xref AS mxref ON m.id = mxref.mod_id'); $query->where('m.id =' . $moderatorId); $db->setQuery($query); $totalModeratedCats = $db->loadResult(); if ($totalModeratedCats <= 0) { $modTable->reset(); if ($modTable->load(array($moderatorId))) { $modTable->delete(); } } } } $images = json_decode($table->images); if (is_object($images)) { if ($images->intro_image) { $intro_image = JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/') . $images->intro_image; $ori_intro_image = JUDownloadFrontHelper::getDirectory('category_intro_image_directory', 'media/com_judownload/images/category/intro/') . "original/" . $images->intro_image; if (JFile::exists(JPATH_ROOT . "/" . $ori_intro_image)) { JFile::delete(JPATH_ROOT . "/" . $ori_intro_image); } if (JFile::exists(JPATH_ROOT . "/" . $intro_image)) { JFile::delete(JPATH_ROOT . "/" . $intro_image); } } if ($images->detail_image) { $detail_image = JUDownloadFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judownload/images/category/detail/') . $images->detail_image; $ori_detail_image = JUDownloadFrontHelper::getDirectory('category_detail_image_directory', 'media/com_judownload/images/category/detail/') . "original/" . $images->detail_image; if (JFile::exists(JPATH_ROOT . "/" . $detail_image)) { JFile::delete(JPATH_ROOT . "/" . $detail_image); } if (JFile::exists(JPATH_ROOT . "/" . $ori_detail_image)) { JFile::delete(JPATH_ROOT . "/" . $ori_detail_image); } } } if ($table->level == 0 || $table->level == 1) { $query = "DELETE FROM #__judownload_emails_xref WHERE cat_id = " . $table->id; $db->setQuery($query); $db->execute(); } JUDownloadHelper::deleteLogs('category', $pk); $query = "DELETE FROM #__judownload_fields_ordering WHERE `item_id` = " . $table->id . " AND `type` = 'category'"; $db->setQuery($query); $db->execute(); $dispatcher->trigger($this->event_after_delete, array($context, $table)); } } } } if ($canDeleteCatIds) { $app = JFactory::getApplication(); $app->enqueueMessage(JText::plural('COM_JUDOWNLOAD_CATEGORIES_N_ITEMS_DELETED', count($canDeleteCatIds))); } $canNotDeleteCatIds = array_unique($canNotDeleteCatIds); if ($canNotDeleteCatIds) { JError::raiseWarning(500, JText::plural('COM_JUDOWNLOAD_CATEGORIES_N_ITEMS_NOT_DELETED', count($canNotDeleteCatIds))); } $this->cleanCache(); return true; }
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); }
/** * ------------------------------------------------------------------------ * 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'); $this->model->uploadFileScript($this->item->id, "#judl-files"); $file_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/"); ?> <fieldset class="adminform"> <div id="judl-files" class="judl-files"> <ul id="file-list" class="file-list nav clearfix"> <?php if ($this->files) { $canChangeDownloads = ''; if (!JFactory::getUser()->authorise('core.admin', 'com_judownload')) { $canChangeDownloads = 'readonly="readonly"'; } foreach ($this->files as $key => $file) { if ($file['id']) { $file_exists = JFile::exists($file_directory . $this->item->id . "/" . $file['file_name']); } ?>
public static function getFeed($feedDocuments, &$document) { $db = JFactory::getDbo(); $app = JFactory::getApplication(); $params = JUDownloadHelper::getParams(); $image = $params->get('rss_thumbnail_source', 'icon'); $feedEmail = $params->get('rss_email', 'none'); $siteEmail = $app->get('mailfrom'); foreach ($feedDocuments AS $doc) { $title = $doc->title; $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); $categoryId = JUDownloadFrontHelperCategory::getMainCategoryId($doc->id); $category = JUDownloadFrontHelperCategory::getCategory($categoryId); $feedItem = new JFeedItem(); $feedItem->title = $title; $feedItem->link = JRoute::_(JUDownloadHelperRoute::getDocumentRoute($doc->id)); if ($feedEmail != 'none') { $user = JFactory::getUser($doc->created_by); $feedItem->author = $doc->created_by_alias ? $doc->created_by_alias : $user->name; if ($feedEmail == 'site') { $feedItem->authorEmail = $siteEmail; } elseif ($feedEmail === 'author') { $feedItem->authorEmail = $doc->email ? $doc->email : $user->email; } } $feedItem->category = $category->title; @$date = $doc->publish_up ? date('r', strtotime($doc->publish_up)) : ''; $feedItem->date = $date; $feedItem->description = ""; if ($params->get('rss_show_thumbnail', 1)) { if ($image == 'icon' && $doc->icon) { $imageUrl = JUri::root() . JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/", true) . $doc->icon; } else { $query = "SELECT file_name FROM #__judownload_images WHERE doc_id = " . $doc->id . " ORDER BY ordering ASC LIMIT 1"; $db->setQuery($query); $firstImage = $db->loadResult(); $imageUrl = JUri::root() . JUDownloadFrontHelper::getDirectory("document_small_image_directory", "media/com_judownload/images/gallery/small/", true) . $firstImage; } $feedItem->description = "<img src='" . $imageUrl . "' align=\"" . $params->get('rss_thumbnail_alignment', 'left') . "\" />"; } $feedItem->description .= $doc->introtext; $document->addItem($feedItem); } }
public function getPhysicalFilePath($fileId, $version = '') { $fileDirectory = JUDownloadFrontHelper::getDirectory('file_directory', 'media/com_judownload/files/'); $fileObject = $this->getFileObject($fileId); $documentObject = JUDownloadHelper::getDocumentById($fileObject->doc_id); if ($version === '' || $version === $documentObject->version) { $filePath = JPATH_SITE . '/' . $fileDirectory . $fileObject->doc_id . '/' . $fileObject->file_name; $filePath = JPath::clean($filePath); return $filePath; } else { $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('file_path') ->from('#__judownload_versions') ->where('file_id = ' . $fileId) ->where('version = ' . $db->quote($version)); $db->setQuery($query, 0, 1); $versionFilePath = $db->loadResult(); if ($versionFilePath) { $filePath = JPATH_SITE . '/' . $fileDirectory . $fileObject->doc_id . '/' . $versionFilePath; $filePath = JPath::clean($filePath); return $filePath; } else { $query = $db->getQuery(true); $query->select('date') ->from('#__judownload_versions') ->where('doc_id = ' . $fileObject->doc_id) ->where('version = ' . $db->quote($version)); $db->setQuery($query, 0, 1); $versionDate = $db->loadResult(); if ($versionDate) { $query = $db->getQuery(true); $query->select('file_path') ->from('#__judownload_versions') ->where('file_id = ' . $fileId) ->where('date < ' . $db->quote($versionDate)) ->where('file_path != ""') ->order('date DESC, version DESC'); $db->setQuery($query, 0, 1); $nearestVersionFilePath = $db->loadResult(); if ($nearestVersionFilePath) { $filePath = JPATH_SITE . '/' . $fileDirectory . $fileObject->doc_id . '/' . $nearestVersionFilePath; $filePath = JPath::clean($filePath); return $filePath; } } } } }
public static function generateImageNameByDocument($doc_id, $file_name) { if (!$doc_id || !$file_name) { return ""; } $dir_document_ori = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_original_image_directory", "media/com_judownload/images/gallery/original/") . $doc_id . "/"; $info = pathinfo($file_name); $document = JUDownloadHelper::getDocumentById($doc_id); $replace = array('id' => $document->id, 'category' => '', 'document' => $document->title, 'image_name' => $info['filename']); $base_file_name = JUDownloadHelper::parseImageNameByTags($replace, 'document', null, $document->id) . "." . $info['extension']; $img_file_name = $base_file_name; $img_path_ori = $dir_document_ori . $img_file_name; while (JFile::exists($img_path_ori)) { $img_file_name = JUDownloadHelper::generateRandomString(3) . "-" . $base_file_name; $img_path_ori = $dir_document_ori . $img_file_name; } return $img_file_name; }
public function downloadFile() { JSession::checkToken('get') or die(JText::_('JINVALID_TOKEN')); $app = JFactory::getApplication(); $fileId = $app->input->get('fileId', 0); $db = JFactory::getDbo(); $query = 'SELECT `doc_id`, `file_name`, `rename` FROM #__judownload_files WHERE id = ' . $fileId; $db->setQuery($query); $file = $db->loadObject(); if ($file) { $documentObject = JUDownloadHelper::getDocumentById($file->doc_id); $fileDirectory = JUDownloadFrontHelper::getDirectory('file_directory', 'media/com_judownload/files/'); $version = $app->input->get('version', ''); if (!$version || $version === $documentObject->version) { $filePath = JPATH_SITE . '/' . $fileDirectory . $file->doc_id . '/' . $file->file_name; } else { $query = "SELECT file_path FROM #__judownload_versions WHERE file_id = " . $fileId . " AND version = " . $db->quote($version); $db->setQuery($query); $versionFilePath = $db->loadResult(); if (!$versionFilePath) { return false; } $filePath = JPATH_SITE . '/' . $fileDirectory . $file->doc_id . '/' . $versionFilePath; } $filePath = JPath::clean($filePath); $downloadResult = JUDownloadHelper::downloadFile($filePath, $file->rename, 'php', '2048', true, true); if ($downloadResult !== true) { $this->setError($downloadResult); return false; } } return true; }
public function loadDefaultAssets($loadJS = true, $loadCSS = true) { static $loaded = array(); if ($this->folder && !isset($loaded[$this->folder])) { $document = JFactory::getDocument(); if ($loadJS) { $document->addScript(JUri::root() . "components/com_judownload/fields/" . $this->folder . "/judlgallery.js"); $big_image_dir = JUDownloadFrontHelper::getDirectory("document_big_image_directory", "media/com_judownload/images/gallery/big/", true) . $this->doc_id . "/"; $params = JUDownloadHelper::getParams(null, $this->doc_id); $requiredImage = $this->isRequired() ? 1 : 0; $maxImages = 4; $script = ' jQuery(document).ready(function($){ options = { juri_root : "' . JUri::root() . '", requiredImage: ' . (int) $requiredImage . ', maxImages : ' . (int) $maxImages . ', big_image_dir: "' . $big_image_dir . '", is_site : 0 }; $("#image-gallery").judlgallery(options); }); '; $document->addScriptDeclaration($script); } if ($loadCSS) { $document->addStyleSheet(JUri::root() . "components/com_judownload/fields/" . $this->folder . "/style.css"); } $loaded[$this->folder] = true; } }
</div> </div> <div class="form-group" style="margin-bottom: 0"> <div class="col-xs-offset-2 col-xs-10" > <input class="btn" onclick="updateEFImageData('{{ef_id}}'); return false;" type="button" value="<?php echo JText::_("COM_JUDOWNLOAD_UPDATE"); ?>" /> <input class="btn" onclick="eFImageFormClose('{{ef_id}}'); return false;" type="button" value="<?php echo JText::_("COM_JUDOWNLOAD_CANCEL"); ?>" /> </div> </div> </div> </div> </script> <?php $html = "<div id=\"" . $this->getId() . "\" " . $this->getAttribute(null, null, "input") . ">"; $html .= "<ul class=\"image-list nav\">"; $image_url = JUri::root() . JUDownloadFrontHelper::getDirectory("field_attachment_directory", "media/com_judownload/field_attachments/", true) . "images/" . $this->id . "_" . $this->doc_id . "/"; if ($images) { foreach ($images AS $key => $image) { $link = $image_url . $image->name; $publish_class = $image->published == 0 ? "unpublished" : ""; $html .= "<li>"; $html .= "<div class=\"img-element $publish_class\">"; $html .= "<img class=\"img-item\" alt=\"Image\" src=\"" . $link . "\" />"; $html .= "<span class=\"view-image\" title=\"" . JText::_('COM_JUDOWNLOAD_VIEW_IMAGE') . "\">" . JText::_('COM_JUDOWNLOAD_VIEW_IMAGE') . "</span>"; if ($publish_class) { $html .= '<span class="published-image" name="published" title="' . JText::_('COM_JUDOWNLOAD_CLICK_TO_UNPUBLISH') . '">' . JText::_('COM_JUDOWNLOAD_PUBLISHED') . '</span>'; } else
public function getExportData($exportColumns, $filter) { $db = JFactory::getDbo(); $exportData = array(); $selectFields = $this->getDocumentTableFieldsName(); foreach ($selectFields as $index => $field) { if ($field == 'id') { continue; } if (isset($this->field_name_id_array[$field])) { $fieldId = $this->field_name_id_array[$field]; if (!in_array($fieldId, $exportColumns)) { unset($selectFields[$index]); } else { $indexField = array_search($fieldId, $exportColumns); unset($exportColumns[$indexField]); } } else { if (!in_array($field, $exportColumns)) { unset($selectFields[$index]); } else { $indexField = array_search($field, $exportColumns); unset($exportColumns[$indexField]); } } } if (in_array($this->field_name_id_array['description'], $exportColumns)) { $selectFields[] = 'introtext'; $selectFields[] = 'fulltext'; $indexField = array_search($this->field_name_id_array['description'], $exportColumns); unset($exportColumns[$indexField]); } $query = $this->_prepareQuery($selectFields, $filter); $limit = 0; if (!empty($filter['csv_limit_export']) && is_numeric($filter['csv_limit_export'])) { $limit = $filter['csv_limit_export']; } $db->setQuery($query, 0, $limit); $documents = $db->loadObjectList(); if (!empty($documents)) { foreach ($documents as $document) { $docId = $document->id; $mainCatId = JUDownloadFrontHelperCategory::getMainCategoryId($docId); $data = get_object_vars($document); if (!in_array($this->field_name_id_array['id'], $exportColumns)) { unset($data['id']); } if (isset($data['introtext'])) { $data['description'] = !empty($data['fulltext']) ? $data['introtext'] . "<hr id=\"system-readmore\" />" . $data['fulltext'] : $data['introtext']; unset($data['introtext']); unset($data['fulltext']); } if (in_array($this->field_name_id_array['rating'], $exportColumns)) { $query = $db->getQuery(true); $query->select('score')->from('#__judownload_rating')->where('doc_id = ' . $docId); $db->setQuery($query); $data['rating'] = $db->loadResult(); } foreach ($exportColumns as $fieldId) { if (is_numeric($fieldId) && $fieldId != $this->field_name_id_array['id'] && $fieldId != $this->field_name_id_array['tags']) { $query = $db->getQuery(true); $query->select('value')->from('#__judownload_fields_values')->where('doc_id = ' . $docId)->where('field_id = ' . $fieldId); $db->setQuery($query); $data['field_' . $fieldId] = $db->loadColumn(); } } if (in_array($this->field_name_id_array['tags'], $exportColumns)) { $query = $db->getQuery(true); $query->select('t.title')->from('#__judownload_tags AS t')->join('', '#__judownload_tags_xref AS txref ON txref.tag_id = t.id')->where('txref.doc_id = ' . $docId); $db->setQuery($query); $tags = $db->loadColumn(); $data['tags'] = $tags; } if (in_array('main_cat', $exportColumns)) { $data['main_cat'] = $mainCatId; } if (in_array('secondary_cats', $exportColumns)) { $query = $db->getQuery(true); $query->select("c.id"); $query->from("#__judownload_categories AS c"); $query->join("", "#__judownload_documents_xref AS dxref ON (c.id = dxref.cat_id)"); $query->where("dxref.doc_id = " . $docId); $query->where("dxref.main = 0"); $query->order('dxref.ordering ASC'); $db->setQuery($query); $cats = $db->loadColumn(); if (!empty($cats)) { $data['secondary_cats'] = $cats; } else { $data['secondary_cats'] = ''; } } if (in_array('gallery', $exportColumns)) { $query = $db->getQuery(true); $query->select('file_name')->from('#__judownload_images')->where('doc_id = ' . $docId); $db->setQuery($query); $imagesName = $db->loadColumn(); foreach ($imagesName as $index => $imageName) { $imagesName[$index] = JUDownloadFrontHelper::getDirectory('document_original_image_directory', 'media/com_judownload/images/gallery/original/', true) . $docId . '/' . $imageName; } $data['gallery'] = $imagesName; } if (in_array('files', $exportColumns)) { $query = $db->getQuery(true); $query->select('file_name')->from('#__judownload_files')->where('doc_id = ' . $docId); $db->setQuery($query); $filesName = $db->loadColumn(); foreach ($filesName as $index => $fileName) { $filesName[$index] = JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/", true) . $docId . '/' . $fileName; } $data['files'] = $filesName; } if (in_array('related_docs', $exportColumns)) { $query = $db->getQuery(true); $query->select('doc_id_related')->from('#__judownload_documents_relations')->where('doc_id = ' . $docId); $db->setQuery($query); $relatedDocs = $db->loadColumn(); $data['related_docs'] = $relatedDocs; } $exportData[] = $this->filterExportFieldValue($data); } } $columns = array_keys($exportData[0]); array_unshift($exportData, $columns); return $exportData; }
/** * ------------------------------------------------------------------------ * 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'); $small_image_dir = JUDownloadFrontHelper::getDirectory("document_small_image_directory", "media/com_judownload/images/gallery/small/", true) . $this->doc_id . "/"; $params = JUDownloadHelper::getParams(); $requiredImage = $this->isRequired(); ?> <!-- New gallery image template --> <script id="gallery-template" type="text/x-handlebars-template"> <li> <input type="file" name="field_<?php echo $this->id; ?>[]" class="validate-images" {{multiple}}/> <a href="#" class="btn btn-mini btn-xs btn-danger remove_image" onclick="return false;"><i class="icon-minus"></i> <?php echo JText::_('COM_JUDOWNLOAD_REMOVE'); ?></a> </li> </script> <!-- Gallery image form template --> <script id="imageform-template" type="text/x-handlebars-template">
public function deleteMainData($pk, $deleteSelf = false) { $db = JFactory::getDbo(); JUDownloadHelper::deleteFieldValuesOfDocument($pk); $query = "DELETE FROM #__judownload_documents_relations WHERE doc_id = " . $pk; $db->setQuery($query); $db->execute(); $query = "DELETE FROM #__judownload_changelogs WHERE doc_id = " . $pk; $db->setQuery($query); $db->execute(); $query = "DELETE FROM #__judownload_files WHERE doc_id = " . $pk; $db->setQuery($query); $db->execute(); $query = "DELETE FROM #__judownload_versions WHERE doc_id = " . $pk; $db->setQuery($query); $db->execute(); $file_dir = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/") . $pk . "/"; if (JFolder::exists($file_dir)) { JFolder::delete($file_dir); } $query = "DELETE FROM #__judownload_documents_xref WHERE doc_id = " . $pk; $db->setQuery($query); $db->execute(); if ($deleteSelf) { return parent::delete($pk); } return true; }
{ $class = ""; } $description = ''; if ($image->title) { $description .= "<h4 class='img-title'>" . htmlspecialchars($image->title, ENT_QUOTES) . "</h4>"; } if ($image->description) { $description .= "<div class='img-description'>" . htmlspecialchars($image->description, ENT_QUOTES) . '</div>'; } ?> <li class="image<?php echo $class; ?>"> <a href="<?php echo JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('document_big_image_directory', 'media/com_judownload/images/gallery/big/', true) . $this->doc_id . '/' . $image->file_name; ?>" class="fancybox" rel="gallery"> <img src="<?php echo JUri::root(true) . '/' . JUDownloadFrontHelper::getDirectory('document_small_image_directory', 'media/com_judownload/images/gallery/small/', true) . $this->doc_id . '/' . $image->file_name; ?>" width="<?php echo $params->get('document_small_image_width', 100); ?>" height="<?php echo $params->get('document_small_image_height', 100); ?>" alt="<?php echo htmlspecialchars($image->title, ENT_QUOTES); ?>"/> </a> <div class="title" style="display: none;"><?php echo $description; ?></div> </li> <?php } ?> </ul>
public function resizeCollectionIcons($limitStart, $limit) { $db = JFactory::getDbo(); $query = "SELECT icon FROM #__judownload_collections WHERE icon != ''"; $db->setQuery($query, $limitStart, $limit); $images = $db->loadObjectList(); if (count($images)) { $collection_icon_path = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("collection_icon_directory", "media/com_judownload/images/collection/"); foreach ($images as $image) { $ori_image_path = $collection_icon_path . "original/" . $image->icon; if (JFile::exists($ori_image_path)) { $image_path = $collection_icon_path . $image->icon; if (JFile::exists($image_path)) { JFile::delete($image_path); } JUDownloadHelper::renderImages($ori_image_path, $image_path, 'collection'); } } } }
* 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'); ?> <script type="text/javascript"> var default_icon = "<?php echo JUDownloadHelper::getDefaultDocumentIcon(); ?>"; var document_icon_url = "<?php echo JUri::root(true) . "/". JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/", true); ?>"; function jSelectDocument_related() { var $ul = jQuery(".related-document-list").find(".related-documents"); var $document = $ul.find("li#document-" + arguments[0]); if (!$document.length && arguments[0] != <?php echo (int)$this->item->id; ?>) { var $li = '<li id="document-' + arguments[0] + '">'; $li += '<div class="document-inner">'; var icon_src = arguments[2] ? document_icon_url + arguments[2] : default_icon; if (icon_src) { $li += '<img class="image" src="' + icon_src + '" title="' + arguments[1] + '" width="<?php echo $this->params->get('document_icon_width', 150)?>px" height="<?php echo $this->params->get('document_icon_height', 150); ?>px" />'; } var href = 'index.php?option=com_judownload&task=document.edit&id=' + arguments[0]; $li += '<a class="rel-document-title" target="_blank" href="' + href + '">' + arguments[1] + '</a>'; $li += '<a class="remove-rel-document" href="#" title="<?php echo JText::_('COM_JUDOWNLOAD_REMOVE_DOCUMENT'); ?>" ><?php echo JText::_('COM_JUDOWNLOAD_REMOVE_DOCUMENT'); ?></a>'; $li += '<input type="hidden" name="related_documents[]" value="' + arguments[0] + '" />'; $li += '</div>';
$app = JFactory::getApplication(); $db = JFactory::getDbo(); $user = JFactory::getUser(); $userId = $user->id; $rootCat = JUDownloadFrontHelperCategory::getRootCategory(); $cat_id = $app->input->getInt('cat_id', $rootCat->id); $listOrder_cat = $this->escape($this->state->get('filter.ordering_cat')); $listDirn_cat = $this->escape($this->state->get('filter.direction_cat')); $search_cat = $this->escape($this->state->get('filter.search_cat')); $saveOrder_cat = $listOrder_cat == 'lft' && $this->canDoCat->get('judl.category.edit.state'); $model = $this->getModel(); $list_cat = $model->getListCategory($cat_id, $listOrder_cat, $listDirn_cat); $ordering = $listOrder_cat == 'lft'; $this->ordering = array(); $intro_image_path = JUri::root(true) . "/" . JUDownloadFrontHelper::getDirectory("category_intro_image_directory", "media/com_judownload/images/category/intro/"); $detail_image_path = JUri::root(true) . "/" . JUDownloadFrontHelper::getDirectory("category_detail_image_directory", "media/com_judownload/images/category/detail/"); foreach ($list_cat as $cat) { $this->ordering[] = $cat->id; } $originalOrders = array(); ?> <div class="clearfix"> <div class="input-append pull-left"> <label for="filter_search" class="filter-search-lbl element-invisible"><?php echo JText::_('JSEARCH_FILTER_LABEL'); ?> </label> <input type="text" size="40" name="filter_search_cat" id="filter_search_cat" placeholder="<?php echo JText::_('COM_JUDOWNLOAD_SEARCH_BY_CATEGORY_NAME'); ?>
<tr> <th><?php echo JText::_('COM_JUDOWNLOAD_DIRECTORIES'); ?> </th> <th style="width:100px"><?php echo JText::_('COM_JUDOWNLOAD_STATUS'); ?> </th> </tr> </thead> <tbody> <?php foreach ($configs as $config) { $value = JUDownloadFrontHelper::getDirectory($config['name'], $config['default']); $status = is_writable(JPATH_ROOT . "/" . $value) ? "<span class='badge badge-success'>" . JText::_('COM_JUDOWNLOAD_WRITEABLE') . "</span>" : "<span class='badge badge-important'>" . JText::_('COM_JUDOWNLOAD_UNWRITEABLE') . "</span>"; echo "<tr>"; echo "<td>" . $value . "</td>"; echo "<td>" . $status . "</td>"; echo "</tr>"; } ?> </tbody> </table> <table class="table table-striped table-bordered"> <thead> <tr> <th><?php echo JText::_('COM_JUDOWNLOAD_LIBRARIES');
protected function removeIcon() { $iconDirectory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/"); if (JFile::exists($iconDirectory . $this->doc->icon)) { JFile::delete($iconDirectory . $this->doc->icon); } if (JFile::exists($iconDirectory . "original/" . $this->doc->icon)) { JFile::delete($iconDirectory . "original/" . $this->doc->icon); } }