/** * Allow add new document. */ protected function allowAdd($data = array()) { // relative path of file we want add document $path = JoomDOCRequest::getPath(); if ($this->getModel()->searchIdByPath($path)) { // file already has document return false; } if (!JoomDOCAccessDocument::create(JoomDOCFileSystem::getParentPath($path))) { // parent document or global config doesn't allow add document return false; } return true; }
/** * Delete document. */ public function delete() { // set document ID into request JRequest::setVar('cid', array($this->getModel()->searchIdByPath(JoomDOCRequest::getPath()))); // move token from GET into POST if (JOOMDOC_ISJ3) { //fix for J3 API. JRequest::setVar not works, because JSession::checkToken uses input object... $app = JFactory::getApplication(); $app->input->post->set(JRequest::getVar('token', '', 'get', 'string'), 1); } JRequest::setVar(JRequest::getVar('token', '', 'get', 'string'), 1, 'post'); parent::delete(); $this->setRedirect(JoomDOCRoute::viewDocuments(JoomDOCFileSystem::getParentPath(JoomDOCRequest::getPath()), false)); }
/** * Rename file/folder. */ public function rename() { $renamePath = JString::trim(JRequest::getString('renamePath')); if (JoomDOCAccessFileSystem::rename(false, $renamePath)) { if ($success = JoomDOCFileSystem::rename($renamePath, JString::trim($newName = JRequest::getString('newName')))) { //if renamed directory, do refresh, else it will appear empty $newPath = ($parentPath = JoomDOCFileSystem::getParentPath($renamePath)) ? $parentPath . DIRECTORY_SEPARATOR . JRequest::getString('newName') : $newName; if (JFolder::exists(JoomDOCFileSystem::getFullPath($newPath))) { $mainfrane = JFactory::getApplication(); $mainfrane->enqueueMessage(JText::sprintf('JOOMDOC_REFRESHED', JoomDOCFileSystem::refresh())); } } $this->setRedirect(JoomDOCRoute::viewDocuments(), JText::_($success ? 'JOOMDOC_RENAME_SUCCESS' : 'JOOMDOC_RENAME_FAILED'), $success ? 'message' : 'error'); } else { JError::raiseError(403, JText::_('JOOMDOC_UNABLE_RENAME')); } }
/** * Copy/move files and documents database rows. * * @param string $oldPath old file relative path * @param string $newPath new file relative path * @param boolean $move false copy, true move */ function copyMove($oldPath, $newPath, $move) { $app = JFactory::getApplication(); /* @var $app JApplication */ $toflat = array($oldPath, $newPath); $oldPath = $this->_db->quote($oldPath); $newParentPath = JoomDOCFileSystem::getParentPath($newPath); $newParentPathQuote = $this->_db->quote($newParentPath); $newPath = $this->_db->quote($newPath); if (!$move) { // get IDs of all old rows $this->_db->setQuery('SELECT `id` FROM `#__joomdoc_file` WHERE `path` = ' . $oldPath); $fileIDs = $this->_db->loadColumn(); $this->_db->setQuery('SELECT `id` FROM `#__joomdoc` WHERE `path` = ' . $oldPath); $docIDs = $this->_db->loadColumn(); // copy all old rows foreach ($fileIDs as $id) { $newFileIDs[] = JoomDOCModelList::copyRow('#__joomdoc_file', 'id', $id); } foreach ($docIDs as $id) { $newDocIDs[] = JoomDOCModelList::copyRow('#__joomdoc', 'id', $id); } // update path in new rows if (isset($newFileIDs)) { $this->_db->setQuery('UPDATE `#__joomdoc_file` SET `path` = ' . $newPath . ' WHERE `id` IN (' . implode(', ', $newFileIDs) . ')'); $this->_db->query(); } // update path and parent path in new rows if (isset($newDocIDs)) { $newDocIDs = implode(',', $newDocIDs); $this->_db->setQuery('UPDATE `#__joomdoc` SET `path` = ' . $newPath . ', `parent_path` = ' . $newParentPathQuote . ' WHERE `id` IN (' . $newDocIDs . ')'); $this->_db->query(); $this->_db->setQuery('SELECT `id`, `alias` FROM `#__joomdoc` WHERE `id` IN (' . $newDocIDs . ')'); $newDocs = $this->_db->loadObjectList(); } } else { // for move only update paths $this->_db->setQuery('UPDATE `#__joomdoc_file` SET `path` = ' . $newPath . ' WHERE `path` = ' . $oldPath); $this->_db->query(); $this->_db->setQuery('UPDATE `#__joomdoc` SET `path` = ' . $newPath . ', `parent_path` = ' . $newParentPathQuote . ' WHERE `path` = ' . $oldPath); $this->_db->query(); $this->_db->setQuery('SELECT `id`, `alias` FROM `#__joomdoc` WHERE `path` = ' . $newPath); $newDocs = $this->_db->loadObjectList(); } if (isset($newDocs)) { // get alias of last version of new parent $this->_db->setQuery('SELECT `alias` FROM `#__joomdoc` WHERE `path` = ' . $newParentPathQuote . ' ORDER BY `version` DESC'); $parentAlias = $this->_db->loadResult(); if (is_null($parentAlias)) { $parentAlias = $newParentPath; } foreach ($newDocs as $newDoc) { // new full alias from new parent alias and new document alias $newDoc->full_alias = $parentAlias . '/' . $newDoc->alias; // update path, parent path and full alias in new document $this->_db->setQuery('UPDATE `#__joomdoc` SET `full_alias` = ' . $this->_db->quote($newDoc->full_alias) . ' WHERE `id` = ' . $newDoc->id); $this->_db->query(); } } JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX)->flat($toflat); }
/** * Display page with folder content. * * @param $tpl used template * @return void */ public function display($tpl = null) { $mainframe = JFactory::getApplication(); /* @var $mainframe JSite */ $document = JFactory::getDocument(); /* @var $documents JDocumentHTML */ $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $modelDocument = JModelLegacy::getInstance(JOOMDOC_DOCUMENT, JOOMDOC_MODEL_PREFIX); /* @var $modelDocument JoomDOCModelDocument */ $modelDocuments = JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_SITE_PREFIX); /* @var $modelDocuments JoomDOCSiteModelDocuments */ $modelFile = JModelLegacy::getInstance(JOOMDOC_FILE, JOOMDOC_MODEL_PREFIX); /* @var $modelFile JoomDOCModelFile */ $this->filter = $this->getLayout() == 'modal' ? $mainframe->getUserStateFromRequest(JoomDOCRequest::getSessionPrefix() . 'filter', 'filter', '', 'string') : ''; $path = JoomDOCRequest::getPath(); // convert to absolute path, if path si empty use document root path $path = $path ? JoomDOCFileSystem::getFullPath($path) : $config->path; // request path value isn't subfolder of document root if (!JoomDOCFileSystem::isSubFolder($path, $config->path)) { JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR ' . $path . ' ' . $config->path)); } $this->searchablefields = $this->get('searchablefields'); $this->publishedfields = $this->get('publishedfields'); foreach ($this->searchablefields as $field) { $field->name = 'joomdoc_field' . $field->id; } if ($config->useSearch || $this->getLayout() == 'modal') { $this->search = new JObject(); // load setting from request or Joomla session storage (server session, database, apc etc.) $this->search->search = $this->getSearchParam('joomdoc_search', 0, 'int'); if ($config->searchKeyword == 1) { $this->search->keywords = $this->getSearchParam('joomdoc_keywords', $this->filter, 'string'); } elseif ($config->searchKeyword == 2) { // separate keywords for each area $this->search->keywords_title = $this->getSearchParam('joomdoc_keywords_title', $this->filter, 'string'); $this->search->keywords_text = $this->getSearchParam('joomdoc_keywords_text', $this->filter, 'string'); $this->search->keywords_meta = $this->getSearchParam('joomdoc_keywords_meta', $this->filter, 'string'); $this->search->keywords_full = $this->getSearchParam('joomdoc_keywords_full', $this->filter, 'string'); foreach ($this->searchablefields as $field) { if ($field->type == JOOMDOC_FIELD_TEXT || $field->type == JOOMDOC_FIELD_TEXTAREA || $field->type == JOOMDOC_FIELD_EDITOR) { $this->search->set('keywords_field' . $field->id, $this->getSearchParam('joomdoc_keywords_field' . $field->id, $this->filter, 'string')); } } } // selected parent (folder) $this->search->parent = $config->searchShowParent ? $this->getSearchParam('path', '', 'string') : ''; // path to load items list, if not select parent use document root $this->search->path = JoomDOCFileSystem::getFullPath($this->search->parent); // search areas (document title or file path), text and metadata, file content $this->search->areaTitle = $config->searchShowTitle ? $this->getSearchParam('joomdoc_area_title', 1, 'int', true, 'joomdoc_search') : 0; $this->search->areaText = $config->searchShowText ? $this->getSearchParam('joomdoc_area_text', 1, 'int', true, 'joomdoc_search') : 0; $this->search->areaMeta = $config->searchShowMetadata ? $this->getSearchParam('joomdoc_area_meta', 1, 'int', true, 'joomdoc_search') : 0; $this->search->areaFull = $config->searchShowFulltext ? $this->getSearchParam('joomdoc_area_full', 1, 'int', true, 'joomdoc_search') : 0; // searching type (any/all word, complet phrase, regular expresion $this->search->type = $this->getSearchParam('joomdoc_type', $config->searchDefaultType, 'int'); // ordering $this->search->ordering = $this->getSearchParam('joomdoc_ordering', $config->searchDefaultOrder, 'string'); foreach ($this->searchablefields as $field) { if ($field->type == JOOMDOC_FIELD_TEXT) { $this->search->fields[$field->id] = array('type' => $field->type, 'value' => $this->getSearchParam($field->name, 1, 'int', true, 'joomdoc_search')); } elseif ($field->type == JOOMDOC_FIELD_CHECKBOX || $field->type == JOOMDOC_FIELD_MULTI_SELECT || $field->type == JOOMDOC_FIELD_SUGGEST) { $this->search->fields[$field->id] = array('type' => $field->type, 'value' => $this->getSearchParam($field->name, array(), 'array')); } else { $this->search->fields[$field->id] = array('type' => $field->type, 'value' => $this->getSearchParam($field->name, '', 'string')); } } // set ordering from search setting switch ($this->search->ordering) { case JOOMDOC_ORDER_NEWEST: /* Newest items */ // files order upload date and documents order publish up date descending $documentOrdering = JOOMDOC_ORDER_PUBLISH_UP; $fileOrdering = JOOMDOC_ORDER_UPLOAD; $orderingDirection = JOOMDOC_ORDER_DESC; break; case JOOMDOC_ORDER_OLDEST: /* Oldest items */ // files order upload date and documents order publish up date ascending $documentOrdering = JOOMDOC_ORDER_PUBLISH_UP; $fileOrdering = JOOMDOC_ORDER_UPLOAD; $orderingDirection = JOOMDOC_ORDER_ASC; break; case JOOMDOC_ORDER_HITS: /* Most popular (downloaded) */ // files order hits descending $documentOrdering = null; $fileOrdering = JOOMDOC_ORDER_HITS; $orderingDirection = JOOMDOC_ORDER_DESC; break; case JOOMDOC_ORDER_TITLE: /* Alphabetical */ // files order path and documents order title ascending $documentOrdering = JOOMDOC_ORDER_TITLE; $fileOrdering = JOOMDOC_ORDER_PATH; $orderingDirection = JOOMDOC_ORDER_ASC; break; } } $searchActive = $config->useSearch && $this->search->search; if (!$searchActive) { // if search isnt't set use ordering from configuration $documentOrdering = $config->documentOrdering; $fileOrdering = $config->fileOrdering; $orderingDirection = $config->orderingDirection; } // get content of selected folder $this->root = JoomDOCFileSystem::getFolderContent($path, '', $searchActive); if (JoomDOCFileSystem::isFolder($this->root)) { // selected path is folder $modelDocuments->setState(JoomDOCView::getStateName(JOOMDOC_FILTER_PATHS), $this->root->getPaths(false)); // get child documents $modelDocuments->setState(JoomDOCView::getStateName(JOOMDOC_FILTER_SEARCH), $config->useSearch || $this->getLayout() == 'modal' ? $this->search : null); $this->documents = $modelDocuments->getItems($searchActive); $this->listfields = $modelDocuments->getListFields(); $this->state = $modelDocuments->getState(); // add documents to given subfolders and files $this->root->setDocuments($this->documents); $this->access = new JoomDOCAccessHelper($this->root); // control permissions to access folder if (!$this->access->canEnterFolder) { JError::raiseError(403, JText::_('JOOMDOC_UNABLE_ACCESS_FOLDER')); } $this->pagination = new JPagination($modelDocuments->getTotal($searchActive), $mainframe->getUserStateFromRequest('com_joomdoc.documents.limitstart', 'limitstart', 0, 'int'), $mainframe->getUserStateFromRequest('com_joomdoc.documents.limit', 'limit', $mainframe->getCfg('list_limit'), 'int')); // reorder $this->root->reorder($documentOrdering, $fileOrdering, $orderingDirection, $this->pagination->limitstart, $this->pagination->limit, $this->pagination->total, $config->foldersFirstSite); // set root parent $this->root->parent = $modelDocument->getParent(JoomDOCFileSystem::getParentPath($this->root->getRelativePath())); $this->root->document = $modelDocument->getItemByPath($this->root->getRelativePath()); } elseif (JoomDOCFileSystem::isFile($this->root)) { // use different layout $this->setLayout('file'); // search document by path $this->root->document = $modelDocument->getItemByPath($this->root->getRelativePath()); $this->publishedfields = $modelDocument->getPublishedFields(); $this->access = new JoomDOCAccessHelper($this->root); // document unpublished $this->root->parent = $modelDocument->getParent(JoomDOCFileSystem::getParentPath($this->root->getRelativePath())); } else { JError::raiseError(404, JText::_('JERROR_LAYOUT_PAGE_NOT_FOUND')); } // control root access if ($this->access->docid) { // item with document if (!$this->access->canAnyEditOp && $this->root->document->published == JOOMDOC_STATE_UNPUBLISHED) { // root unpublished and user hasn't admin rights JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR')); } if ($this->root->document->state == JOOMDOC_STATE_TRASHED) { // root trashed JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR')); } } elseif (isset($this->root->document->file_state)) { // item without document but with file if ($this->root->document->file_state == JOOMDOC_STATE_TRASHED) { // file is trashed JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR')); } } elseif (!$this->access->inRoot && !$searchActive && $this->getLayout() != 'modal') { // item without file can be total root but it's not root JError::raiseError(404, JText::_('JERROR_ALERTNOAUTHOR')); } // take a configuration of an active menu item $active = $mainframe->getMenu()->getActive(); $this->pageHeading = $this->pageclassSfx = ''; if ($active) { if ($active->params->get('show_page_heading')) { $this->pageHeading = JString::trim($active->params->get('page_heading')); if (!$this->pageHeading) { $this->pageHeading = JString::trim($active->params->get('page_title')); } } $this->pageclassSfx = JString::trim($active->params->get('pageclass_sfx')); $titles[] = JString::trim($active->params->get('page_title')); $metakeywords[] = JString::trim($active->params->get('menu-meta_keywords')); $metadescriptions[] = JString::trim($active->params->get('menu-meta_description')); } // take candidates for metadata sort on priority if ($this->access->docid and $this->root->document->published == JOOMDOC_STATE_PUBLISHED) { //use document only if published. (but for owner is published always). // from document data $params = new JRegistry($this->root->document->params); $titles[] = JString::trim($this->root->document->title); $metakeywords[] = JString::trim($params->get('metakeywords')); $metadescriptions[] = JString::trim($params->get('metadescription')); $metadescriptions[] = JoomDOCHelper::getMetaDescriptions($this->root->document->description); } // default candidates $titles[] = $this->access->name; $titles[] = $config->defaultTitle; $metakeywords[] = $config->defaultMetakeywords; $metadescriptions[] = $config->defaultMetadescription; // set meta data from candidates acording to priority // set meta keywords $document->setMetaData('keywords', JoomDOCHelper::getFirstNoEmpty($metakeywords)); // set page title $document->setTitle(JoomDOCHelper::getCompletTitle(JoomDOCHelper::getFirstNoEmpty($titles))); // set head meta description $document->setDescription(JoomDOCHelper::getFirstNoEmpty($metadescriptions)); $modelDocuments->setPathway($this->root->getRelativePath()); if ($this->access->canCopyMove) { JoomDOCHelper::clipboardInfo(); } parent::display($tpl); }
/** * Filter folder list for frontend (published, ACL etc) * * @param JoomDOCFolder $root * @param string $parent * @return array */ public static function folders($root, $parent) { $folders = array(); $root->initIteration(); $parents = array(JoomDOCFileSystem::getRelativePath($parent)); while ($root->hasNext()) { $item = $root->getNext(); $access = new JoomDOCAccessHelper($item); $itemParent = JoomDOCFileSystem::getParentPath($access->relativePath); if (!(empty($itemParent) || in_array($itemParent, $parents))) { // parent has to be visible continue; } if ($access->docid && $item->document->published == JOOMDOC_STATE_UNPUBLISHED) { // item has to published continue; } $folder = new JObject(); // prepare data for MooTree $folder->set('ident', $access->relativePath); $folder->set('route', JoomDOCRoute::viewDocuments($access->relativePath, $access->alias)); $folder->set('title', $access->docid ? $item->document->title : $item->getFileName()); $folder->set('entry', $access->canEnterFolder); $folders[] = $folder; $parents[] = $access->relativePath; // save into visible parents } return $folders; }
public static function copyMove($move = false) { $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ $tableFile = JTable::getInstance(JOOMDOC_FILE, JOOMDOC_TABLE_PREFIX); /* @var $tableFile JoomDOCTableFile */ // current folder copy into $folder = JoomDOCRequest::getPath(); $folderAbsolutePath = JoomDOCFileSystem::getFullPath($folder); // current folder acces $folderCanCreateSubfolders = JoomDOCAccessFileSystem::newFolder(false, $folder); $folderCanUploadFiles = JoomDOCAccessFileSystem::uploadFile(false, $folder); // items to copy $paths = JoomDOCFileSystem::getOperationPaths(); foreach ($paths as $path) { $absolutePath = JoomDOCFileSystem::getFullPath($path); $parent = JoomDOCFileSystem::getParentPath($absolutePath); $parentLength = JString::strlen($parent); $items = array($absolutePath); if (JFolder::exists($absolutePath)) { if (!$folderCanCreateSubfolders) { // copied/moved item is folder and current folder aren't allowed to create subfolders $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_CPMV_UNABLE_SUBFOLDERS', $folder, $path), 'notice'); continue; } // unable copy/move folder into own subfolder if (JoomDOCFileSystem::isSubFolder($folderAbsolutePath, $absolutePath)) { $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_CPMV_UNABLE_INTO_SELF', $folder, $path), 'notice'); continue; } $items = array_merge($items, JFolder::folders($absolutePath, '', true, true, array('.svn', 'CVS', '.DS_Store', '__MACOSX', JOOMDOC_VERSION_DIR))); $items = array_merge($items, JFolder::files($absolutePath, '', true, true)); } elseif (!JFile::exists($absolutePath)) { continue; } foreach ($items as $item) { $itemRelativePath = JoomDOCFileSystem::getRelativePath($item); if (!JoomDOCAccessFileSystem::copyMove(false, $itemRelativePath)) { $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_CPMV_UNABLE', $itemRelativePath), 'notice'); continue; } // get relative path from copied path parent $relativePath = JString::substr($item, $parentLength); // destination is current folder + relative path $destination = $folderAbsolutePath . $relativePath; $destinationRelativePath = JoomDOCFileSystem::getRelativePath($destination); if (JFolder::exists($item)) { // is folder only create if (JFolder::exists($destination)) { $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_CPMV_FOLDER_EXISTS', $destinationRelativePath), 'notice'); continue; } JFolder::create($destination); } if (JFile::exists($item)) { if (!$folderCanUploadFiles) { // copied/moved item is file or contain files and current folder aren't allowed to upload files $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_CPMV_UNABLE_UPLOAD', $itemRelativePath, $folder), 'notice'); continue; } if (JFile::exists($destination)) { $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_CPMV_FILE_EXISTS', $destinationRelativePath), 'notice'); continue; } JFile::copy($item, $destination); // get file versions } // copy/move table rows $tableFile->copyMove($itemRelativePath, $destinationRelativePath, $move); } if ($move) { // move item delete source after copy JoomDOCFileSystem::deleteItem($absolutePath); } } JoomDOCFileSystem::resetOperation(); }
/** * Set document publish state. * * @param int $value new state value * @param string $msg message after success */ public function setPublish($value, $msg) { $path = JoomDOCRequest::getPath(); $success = $this->getModel()->setPublish($path, $value); $this->setRedirect(JRoute::_(JoomDOCRoute::viewDocuments(JoomDOCFileSystem::getParentPath($path))), JText::_($success ? $msg : 'JOOMDOC_UNABLE_SET_STATE'), $success ? 'message' : 'error'); }
JModelLegacy::addIncludePath(JOOMDOC_SITE_MODELS); JTable::addIncludePath(JOOMDOC_TABLES); $document = JFactory::getDocument(); /* @var $document JDocument */ $document->addStyleSheet(JOOMDOC_ASSETS . 'css/general.css?' . JOOMDOC_VERSION_ALIAS); // Module and JoomDOC comfiguration. $moduleConfig = JoomDOCModuleExplorerConfig::getInstance($params, $module->id); $globalConfig = JoomDOCConfig::getInstance(); $modelDocuments = JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_SITE_PREFIX); /* @var $modelDocuments JoomDOCSiteModelDocuments */ // Only folders are loaded. $parent = $moduleConfig->parent ? JoomDOCFileSystem::getFullPath($moduleConfig->parent) : $globalConfig->docroot; if (!JFolder::exists($parent)) { // invalid or expired module config $parent = ''; } // reset to root $path = JoomDOCRequest::getPath(); // on file detail get parent folder path if (JFile::exists(JoomDOCFileSystem::getFullPath($path)) && JFolder::exists(JoomDOCFileSystem::getFullPath(JoomDOCFileSystem::getParentPath($path)))) { $path = JoomDOCFileSystem::getParentPath($path); } $root = JoomDOCFileSystem::getFolderContent($parent, '', 1, true, false, $path); // Model searchs in database for founded paths. $modelDocuments->setState(JoomDOCView::getStateName(JOOMDOC_FILTER_PATHS), $root->getPaths()); // Filesystem extends items informations from documents. $root->setDocuments($modelDocuments->getItems()); // Filesystem reordes items for given setting. $root->reorder(null, JOOMDOC_ORDER_PATH, JOOMDOC_ORDER_ASC, 0, PHP_INT_MAX); // Active module template displayed. require JModuleHelper::getLayoutPath('mod_joomdoc_explorer', $moduleConfig->layout);
public function onContentSearch($text, $phrase = '', $ordering = '', $areas = null) { if (!JString::trim($text) || is_array($areas) && !array_intersect($areas, array_keys(plgSearchJoomDOC::onContentSearchAreas()))) { return array(); } // import component JoomDOC framework $jdcAdm = JPATH_ADMINISTRATOR . '/components/com_joomdoc/'; $jdcSit = JPATH_SITE . '/components/com_joomdoc/'; $jdcLib = $jdcAdm . 'libraries/joomdoc/'; $includes['JoomDOCRoute'] = $jdcLib . 'application/route.php'; $includes['JoomDOCMenu'] = $jdcLib . 'application/menu.php'; $includes['JoomDOCConfig'] = $jdcLib . 'application/config.php'; $includes['JoomDOCFileSystem'] = $jdcLib . 'filesystem/filesystem.php'; $includes['JoomDOCString'] = $jdcLib . 'utilities/string.php'; $includes['JoomDOCHelper'] = $jdcLib . 'utilities/helper.php'; $includes['JoomDOCModelList'] = $jdcLib . 'application/component/modellist.php'; $includes[] = $jdcAdm . 'defines.php'; foreach ($includes as $classname => $include) { $include = JPath::clean($include); if (!JFile::exists($include)) { // JoomDOC is propably uninstalled or corupted return array(); } is_string($classname) ? JLoader::register($classname, $include) : (include_once $include); } JModelLegacy::addIncludePath(JPath::clean($jdcAdm . 'models')); JTable::addIncludePath(JPath::clean($jdcAdm . 'tables')); $db = JFactory::getDbo(); $nullDate = $db->getNullDate(); // prepare SQL WHERE criteria $wheres = array(); // according to type of searching switch ($phrase) { case 'exact': // exactly phrase $keywords = $db->q('%' . JString::strtolower(JString::trim($text)) . '%'); $items[] = 'LOWER(`document`.`title`) LIKE ' . $keywords; $items[] = 'LOWER(`document`.`description`) LIKE ' . $keywords; $items[] = 'LOWER(`document`.`path`) LIKE ' . $keywords; $items[] = 'LOWER(`document`.`content`) LIKE ' . $keywords; $where[] = '(' . implode(') OR (', $items) . ') '; break; case 'all': case 'any': default: // all words or any word or default $keywords = explode(' ', $text); // split to words $wheres = array(); // search for each word foreach ($keywords as $keyword) { $keyword = JString::trim($keyword); if ($keyword) { $keyword = $db->q('%' . JString::strtolower($keyword) . '%'); $items[] = 'LOWER(`document`.`title`) LIKE ' . $keyword; $items[] = 'LOWER(`document`.`description`) LIKE ' . $keyword; $items[] = 'LOWER(`document`.`path`) LIKE ' . $keyword; $items[] = 'LOWER(`document`.`content`) LIKE ' . $keyword; $parts[] = implode(' OR ', $items); } } if (isset($parts)) { if ($phrase == 'all') { $where[] = '(' . implode(') AND (', $parts) . ') '; } else { $where[] = '(' . implode(') OR (', $parts) . ') '; } } break; } $where[] = '(' . JoomDOCModelList::getDocumentPublished() . ')'; $where = ' WHERE ' . implode(' AND ', $where) . ' '; // prepare SQL ORDER BY criteria switch ($ordering) { case 'oldest': // oldest items first (oldest documents created or oldest file uploaded) $order = ' ORDER BY `document`.`created` ASC, `document`.`upload` ASC '; break; case 'popular': // most hits items first $order = ' ORDER BY `document`.`hits` DESC, `document`.`title` ASC, `document`.`path` ASC '; break; case 'alpha': // alphabetically (document title or file name) $order = ' ORDER BY `document`.`title` ASC, `document`.`path` ASC '; break; case 'category': // by parent folder (parent folder name or document title) $order = ' ORDER BY `parent`.`title` ASC, `parent`.`path` ASC '; break; case 'newest': default: // newest items first (newest documents created or file uploaded) $order = ' ORDER BY `document`.`created` DESC, `document`.`upload` DESC '; break; } $query = 'SELECT `document`.`title`,`document`.`path`, '; $query .= '`document`.`description`, `document`.`content`, '; $query .= '`document`.`created`,`document`.`upload`, '; $query .= '`parent`.`title` AS `ptitle`, '; // document folder title $query .= '`document`.`full_alias` '; $query .= 'FROM `#__joomdoc_flat` AS `document` '; $query .= 'LEFT JOIN `#__joomdoc_flat` AS `parent` ON `document`.`parent_path` = `parent`.`path` '; // document folder $query .= $where . ' GROUP BY `document`.`path` ' . $order; $rows = $db->setQuery($query)->loadObjectList(); foreach ($rows as $row) { $GLOBALS['joomDOCPath'] = $row->path; $row->title = JString::trim($row->title) ? $row->title : JFile::getName($row->path); $row->text = JString::trim($row->description) ? $row->description : $row->content; $row->created = $row->created == $nullDate ? $row->upload : $row->created; $row->section = JString::trim($row->ptitle) ? $row->ptitle : JoomDOCFileSystem::getParentPath($row->path); if ($this->params->get('document_link', 1) == 1) { $row->href = JRoute::_(JoomDOCRoute::viewDocuments($row->path, empty($row->full_alias) ? $row->path : $row->full_alias)); } else { $row->href = JRoute::_(JoomDOCRoute::download($row->path, empty($row->full_alias) ? $row->path : $row->full_alias)); } $row->browsernav = 2; // open document title in the same window } unset($GLOBALS['joomDOCPath']); return $rows; }
* @subpackage JoomDOC * @author ARTIO s.r.o., info@artio.net, http:://www.artio.net * @copyright Copyright (C) 2011 Artio s.r.o.. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; /* @var $this JoomDOCViewDocuments */ JHtml::_('behavior.modal'); $config = JoomDOCConfig::getInstance(); if ($this->access->docid) { $this->root->document->description = JoomDOCHelper::applyContentPlugins($this->root->document->description, $this->root->getRelativePath(), $config->edocsDetail); } echo '<form action="' . JRoute::_(JoomDOCRoute::viewDocuments($this->access->relativePath, $this->access->alias)) . '" method="post" name="adminForm" id="adminForm">'; echo '<div id="document"' . ($this->access->isFavorite ? 'class="favorite"' : '') . '>'; if (!$this->access->inRoot && $this->access->relativePath) { echo '<a class="back" href="' . JRoute::_(JoomDOCRoute::viewDocuments(JoomDOCFileSystem::getParentPath($this->access->relativePath), $this->root->parent ? $this->root->parent->full_alias : null)) . '" title="">' . JText::_('JOOMDOC_BACK') . '</a>'; } echo '<h1>'; if ($this->access->canDownload) { if ($this->access->licenseID) { echo '<a class="modal download" rel="{handler: \'iframe\', size: {x: ' . JOOMDOC_LIGHTBOX_WIDTH . ', y: ' . JOOMDOC_LIGHTBOX_HEIGHT . '}, onClose: function() {}}" href="' . JRoute::_(JoomDOCRoute::viewLicense($this->access->licenseID, $this->access->licenseAlias, $this->access->relativePath, $this->access->alias)) . '">'; } else { echo '<a class="download" href="' . JRoute::_(JoomDOCRoute::download($this->access->relativePath, $this->access->alias)) . '" title="">'; } } //display document title only if published for current user. echo ($this->access->docid and $this->root->document->published == JOOMDOC_STATE_PUBLISHED) ? $this->root->document->title : $this->root->getFileName(); if ($this->access->canDownload) { echo '</a>'; } echo '</h1>';
/** * Get ID of document of last path parent. * * @param string $path relative file path * @return int document ID, null of not found */ public function getParentDocumentID($path) { static $results; // last parent path of path $parentPath = $subParentPath = JoomDOCFileSystem::getParentPath($path); // search in cache if (is_array($results)) { foreach ($results as $result) { if ($result->subparentPath == $subParentPath) { return $result->documentID; } } } // generate parents tree while ($parentPath) { $where[] = '`path` = ' . $this->_db->quote($parentPath); $parentPath = JoomDOCFileSystem::getParentPath($parentPath); } if (isset($where)) { // search last parent path with document $this->_db->setQuery('SELECT `id`, `path` FROM (SELECT `id`, `path` FROM `#__joomdoc` WHERE (' . implode(' OR ', $where) . ') ORDER BY `id` ASC /* latest version */ ) AS s ORDER BY `path` DESC /* nearest parent */'); $row = $this->_db->loadObject(); // cache result $result = new JObject(); $result->parentPath = $row ? $row->path : false; $result->subparentPath = $subParentPath; $result->documentID = $row ? $row->id : false; $results[] = $result; return $result->documentID; } return false; }
/** * Overloaded bind function to pre-process the params. * * @param array Named array * @return null|string null is operation was satisfactory, otherwise returns an error */ public function bind($array, $ignore = '') { if (isset($array['params']) && is_array($array['params'])) { $registry = new JRegistry(); $registry->loadArray($array['params']); $array['params'] = (string) $registry->toString(); } $this->favorite = isset($array['favorite']) ? 1 : 0; $this->download = isset($array['download']) ? 1 : 0; if (isset($array['rules']) && is_array($array['rules'])) { $rules = new JRules($array['rules']); $this->setRules($rules); } parent::bind($array, $ignore); $this->parent_path = JoomDOCFileSystem::getParentPath($this->path); return true; }