/** * Display page with folder content. * * @param $tpl used template * @return void */ public function display($tpl = null) { $mainframe = JFactory::getApplication(); /* @var $mainframe JAdministrator */ $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $model = $this->getModel(); /* @var $model JoomDOCModelDocuments */ $document = JFactory::getDocument(); /* @var $document JDocumentHTML */ if ($this->getLayout() != 'modal') { //$mainframe->enqueueMessage(JText::_('JOOMDOC_KEEP_FLAT')); } // relative path from request or user session $path = JoomDOCRequest::getPath(); if ($path == JText::_('JOOMDOC_ROOT')) { $path = ''; } // convert to absolute path $path = JoomDOCFileSystem::getFullPath($path); //if folder not exists (e.g. was renamed), fallback to root if (!JFolder::exists($path)) { $path = JoomDOCFileSystem::getFullPath(''); } $this->filter = $mainframe->getUserStateFromRequest(JoomDOCRequest::getSessionPrefix() . 'filter', 'filter', '', 'string'); $this->root = JoomDOCFileSystem::getFolderContent($path, ''); // control if select folder is subfolder of docroot if ((!JoomDOCFileSystem::isSubFolder($path, $config->docroot) || $this->root === false) && $config->docroot !== false) { JError::raiseError(403, JText::_('JOOMDOC_UNABLE_ACCESS_FOLDER')); } // search filter setting $this->search = new JObject(); $this->search->keywords = $this->filter; // search areas (search everywhere - don't use frontend detail setting) $this->search->areaTitle = $this->search->areaText = $this->search->areaFull = true; $this->search->areaMeta = false; // looking for any word $this->search->type = JOOMDOC_SEARCH_ANYKEY; $model->setState(JoomDOCView::getStateName(JOOMDOC_FILTER_PATHS), $this->root->getPaths()); $model->setState(JoomDOCView::getStateName(JOOMDOC_FILTER_SEARCH), $this->search); $model->setState(JOOMDOC_FILTER_STATE, $mainframe->getUserStateFromRequest(JoomDOCRequest::getSessionPrefix() . 'state', 'state', JOOMDOC_STATE_PUBLISHED, 'int')); $this->documents = $model->getItems(); $this->state = $model->getState(); $this->pagination = new JPagination($model->getTotal(), $this->state->get(JOOMDOC_FILTER_START), $this->state->get(JOOMDOC_FILTER_LIMIT)); $this->access = new JoomDOCAccessHelper($this->root); $this->root->setDocuments($this->documents); $this->root->reorder($this->state->get(JOOMDOC_FILTER_ORDERING), $this->state->get(JOOMDOC_FILTER_ORDERING), $this->state->get(JOOMDOC_FILTER_DIRECTION), $this->pagination->limitstart, $this->pagination->limit, $this->pagination->total, $config->foldersFirstAdmin); // control permissions to access folder if (!$this->access->canEnterFolder) { $mainframe->setUserState('joomdoc_documents_path', null); JError::raiseError(403, JText::_('JOOMDOC_UNABLE_ACCESS_FOLDER')); } $this->addToolbar(); JoomDOCHelper::setSubmenu(JOOMDOC_DOCUMENTS, true); JoomDOCHelper::clipboardInfo(); JoomDOCHelper::folderInfo($this->access->absolutePath); parent::display($tpl); }
/** * Document edit page. * * @param string $tpl used template name * @return void */ public function display($tpl = null) { $mainframe = JFactory::getApplication(); /* @var $mainframe JAdministrator */ $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $model = $this->getModel(); /* @var $model JoomDOCModelDocument */ $this->form = $model->getForm(); $this->document = $model->getItem(); $this->state = $model->getState(); $this->access = new JoomDOCAccessHelper($this->document); if (!isset($this->document->id) || empty($this->document->id)) { $this->form->setValue('path', null, $mainframe->getUserState('path')); $this->form->setValue('title', null, JFile::getName($mainframe->getUserState('path'))); } $this->addToolbar(); parent::display($tpl); }
/** * 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); }
/** * Folders navigator with MooTree. * * @param array $folders data in this format: JObject('ident' => 'relative path', 'route' => 'URL to open folder', 'title' => 'Folder name', 'entry' => 'Is accessible') * @param string $parent root folder * @param bool $expandable if tree is hide-able (only for J2.5 admin layout) * @param bool $ajax generate one tree list only * @return string source of tree */ public static function mooTree($folders = null, $parent = '', $expandable = false, $ajax = false) { $config = JoomDOCConfig::getInstance(); $document = JFactory::getDocument(); $mainframe = JFactory::getApplication(); $document->addScript(JURI::root(true) . '/media/system/js/mootree' . (JDEBUG ? '-uncompressed' : '') . '.js'); $document->addStyleSheet(JURI::root(true) . '/media/system/css/mootree.css'); $path = JoomDOCRequest::getPath(); $code = ''; if (!$ajax) { $code .= '<div id="MooTree" style="position: relative; overflow: visible;"></div>'; // here MooTree will draw tree $code .= '<ul id="MooTreeSrc">'; // start of source of tree } if (is_null($folders)) { $folders = JoomDOCFileSystem::getNonTrashedParents($parent, 1, $ajax ? null : $path); if (empty($folders)) { return ''; } // nothing to do foreach ($folders as $i => $item) { $folder = new JObject(); $folder->set('ident', $item); $folder->set('route', JoomDOCRoute::viewDocuments($item)); $folder->set('title', basename($item)); $folder->set('entry', JoomDOCAccessFileSystem::enterFolder(false, $item)); $folders[$i] = $folder; } } foreach ($folders as $i => $folder) { // all folders into deep $currentLevel = count(explode(DIRECTORY_SEPARATOR, $folder->get('ident'))); // level of folder deep (folders in doc root have 1) if (!empty($lastLevel)) { // not for root folder if ($currentLevel > $lastLevel) { $code .= '<ul>'; } elseif ($currentLevel < $lastLevel) { $code .= str_repeat('</li></ul>', $lastLevel - $currentLevel) . '</li>'; // end of subfolder, close previous subfolders } else { $code .= '</li>'; } // at the same level as previous } if ($folder->get('entry')) { $code .= '<li id="' . str_replace(DIRECTORY_SEPARATOR, '-', $folder->get('ident')) . '"' . ($folder->get('ident') == $path ? ' class="selected"' : '') . '> <a href="' . JRoute::_($folder->get('route')) . '" target="folderframe" name="' . $folder->get('ident') . '">' . $folder->get('title') . '</a>'; } // current item, tag leave open to append subfolder $lastLevel = $currentLevel; } if (empty($lastLevel)) { $lastLevel = 0; } $code .= str_repeat('</li></ul>', $lastLevel); // end of source tree if ($ajax) { ob_clean(); die($code); } // start MooTree after completely loading page $js = "\n\t\t\twindow.addEvent('domready', function() {\n\t\t\t\tvar tree = new MooTreeControl(\n\t\t\t\t{\n\t\t\t\t\tdiv: 'MooTree', \n\t\t\t\t\tmode: 'folders', \n\t\t\t\t\tgrid: true, \n\t\t\t\t\ttheme: '" . htmlspecialchars(JURI::root(true), ENT_QUOTES) . "/media/system/images/mootree.gif', \n\t\t\t\t\tloader: { // set up Ajax loader\n\t\t\t\t\t\ticon: null, \n\t\t\t\t\t\ttext: '" . JText::_('JOOMDOC_LOADING', true) . "', \n\t\t\t\t\t\tcolor:'#FF0000'\n \t\t\t\t},\n\t\t\t\t\tonClick: function(node) { // event after click on folder\n\t\t\t\t\t\twindow.location = node.data.url; \n\t\t\t\t\t},\n\t\t\t\t\tonExpand: function(node, state) { // event after expand tree node\n\t\t\t\t\t\tif (state && treeLoading < 0) { // opening\n\t\t\t\t\t\t\tnode.loading = true;\n\t\t\t\t\t\t\tnode.clear(); // clear the node to append loader\n\t\t\t\t\t\t\tnode.insert(node.control.loader); // insert loader into the node\n\t\t\t\t\t\t\tnew Request({\n\t\t\t\t\t\t\t\tmethod: 'GET',\n\t\t\t\t\t\t\t\turl: '" . JRoute::_(JoomDOCRoute::updatemootree(), false) . "',\n\t\t\t\t\t\t\t\tdata: {\n\t\t\t\t\t\t\t\t\tpath: node.data.name\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tonSuccess: function(html, xml) {\n\t\t\t\t\t\t\t\t\tnode.clear(); // clear loader from the node\n\t\t\t\t\t\t\t\t\tnode.loading = false;\n\t\t\t\t\t\t\t\t\tvar ul = new Element('ul#MooTreeSrc');\n\t\t\t\t\t\t\t\t\tul.set('html', html);\n\t\t\t\t\t\t\t\t\t\$\$('body').adopt(ul);\n\t\t\t\t\t\t\t\t\ttree.adopt('MooTreeSrc', node);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}).send();\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttreeLoading --;\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\ttext: '" . ($parent ? $parent : $config->explorerRoot) . "', \n\t\t\t\t \topen: true, \n\t\t\t\t \tdata: {\n\t\t\t\t\t\turl: '" . JRoute::_(JoomDOCRoute::viewDocuments($mainframe->isSite() ? $parent : 'JoomDOC'), false) . "', \n\t\t\t\t\t\ttarget: 'folderframe'\n \t\t\t\t}\n \t\t\t}\n\t\t\t);\n\t\t\ttree.adopt('MooTreeSrc'); // load source in ul structure\n\t\t\ttree.selected = tree.get('node_" . htmlspecialchars(str_replace(DIRECTORY_SEPARATOR, '-', $path), ENT_QUOTES) . "');\n\t\t"; //make current folder highlighted if ($path) { $toSelect = JoomDOCFileSystem::getFullPath($path); if (JFile::exists($toSelect)) { $toSelect = JoomDOCFileSystem::getParentPath($toSelect); } // select parent folder if file is selected $toSelect = JoomDOCFileSystem::getRelativePath($toSelect); $js .= "\n\t\t\t\ttree.get('node_" . htmlspecialchars(str_replace(DIRECTORY_SEPARATOR, '-', $toSelect), ENT_QUOTES) . "').selected = true;\n\t\t\t"; } // open actual folder path $breadCrumbs = JoomDOCFileSystem::getPathBreadCrumbs($path); foreach ($breadCrumbs as $i => $breadCrumb) { if ($i) { $js .= "\n\t\t\t\t\tvar node = tree.get('node_" . htmlspecialchars(str_replace(DIRECTORY_SEPARATOR, '-', $breadCrumb->path), ENT_QUOTES) . "');\n\t\t\t\t\tif (node) node.toggle(false, true);\n\t\t\t\t"; } } $js .= '}); var treeLoading = ' . (count($breadCrumbs) - 2) . ';'; //tree expandable - only in admin view and J2.5. In joomla 3.0, tree is fixed part of sidebar if ($expandable) { $js .= "window.addEvent('domready', function() {\n\n \t\t\t//add show/hide button to pathway\n \t\t\tels = Elements.from('<span class=\"hideMooTree\">" . JText::_('JOOMDOC_SHOW_HIDE_TREE') . "</span>');\n \t\t\tels.inject(\$('pathway'), 'bottom');\n\n \t\t\t//add own wrapper for fx.Slide, so we can set float and wifth by css\n \t\t\tmyWrapper = new Element('div', {id: 'MooTreeWrap'}).wraps(\$('MooTree'), 'top');\n \t\t\n \t\t\t//create fx.Slide instance and store it inside element 'storage' (MooTools)\n \t\t\t\$('MooTree').store('slide', new Fx.Slide(\$('MooTree'), {\n \t\t\t\tmode: 'horizontal', \n \t\t\t\tduration: 1000, \n \t\t\t\ttransition: Fx.Transitions.Pow.easeOut, \n \t\t\t\tresetHeight: true, \n \t\t\t\t\t\t\twrapper: myWrapper}).show());\n\n \t\t\t//hide MooTree, if stored so in HTML5 localstorage\n \t\t\tif (window.localStorage && localStorage.getItem('hidden')=='true')\n\t\t\t\t\t\t\t\t\$('MooTree').retrieve('slide').hide();\n\n \t\t\t//add event to remember opened/closed state in localStorage\n els.addEvent('click', function() {\n\t\n \t\t\t\tif (\$('MooTree').retrieve('slide').open){ \n \t\t\t\t\t\$('MooTree').retrieve('slide').slideOut();\n \t\t\t\t\tlocalStorage.setItem('hidden', 'true'); } \n \t\t\t\telse {\n \t\t\t\t\t\$('MooTree').retrieve('slide').slideIn();\n \t\t\t\t\tlocalStorage.setItem('hidden', 'false');}\n\n });\n \t\t\t\t\t\n });"; } $document->addScriptDeclaration($js); return $code; }
public static function refresh($folder = null) { static $count; if (is_null($count)) { $count = 0; } if (JoomDOCAccessFileSystem::refresh()) { $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $model = JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX); /* @var $model JoomDOCModelDocuments */ $file = JTable::getInstance(JOOMDOC_FILE, JOOMDOC_TABLE_PREFIX); /* @var $file JoomDOCTableFile */ $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ if (is_null($folder)) { $folder = $config->docroot; } if (JFolder::exists($folder)) { // scandir for folders $folderpaths = JFolder::folders($folder, '.', false, true); foreach ($folderpaths as $folderpath) { // for folders the same recursive $foldername = JFile::getName($folderpath); if ($foldername[0] != '.') { // no hidden folders JoomDOCFileSystem::refresh($folderpath); } } // scandir for files $filepaths = JFolder::files($folder, '.', false, true); foreach ($filepaths as $i => $filepath) { $filename = JFile::getName($filepath); if ($filename[0] == '.') { // no hidden files unset($filepaths[$i]); } else { $filepaths[$i] = JoomDOCFileSystem::getRelativePath($filepath); } } if ($folder != $config->docroot) { // docroot hasn't db row $filepaths[] = JoomDOCFileSystem::getRelativePath($folder); } // search exist's paths in db $exists = $model->searchPaths($filepaths); foreach ($filepaths as $filepath) { if (!in_array($filepath, $exists)) { // file not in db $file->path = $filepath; $file->store(); $count++; } } } } return $count; }
<?php /** * @version $Id$ * @package Joomla.Administrator * @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 JoomDOCViewFile */ jimport('joomla.html.pagination'); JHtml::_('behavior.modal'); $config = JoomDOCConfig::getInstance(); $showDownload = JoomDOCAccessFileSystem::download($this->document ? $this->document->id : null, $this->filter->path); // texts translations $download = JText::_('JOOMDOC_DOWNLOAD_FILE'); $content = JText::_('JOOMDOC_FILE_CONTENT'); $trashed = JText::_('JTRASHED'); //var_dump($this->filter->state); echo '<form name="adminForm" id="adminForm" action="' . JURI::getInstance()->toString() . '" method="post">'; //Joomla 3.0 display sidemenu manually if (JOOMDOC_ISJ3) { $options = array(); $options[0] = JText::_('JOOMDOC_FILE_PUBLISHED_TRASHED'); $options[JOOMDOC_STATE_PUBLISHED] = JText::_('JOOMDOC_FILE_PUBLISHED'); $options[JOOMDOC_STATE_TRASHED] = JText::_('JOOMDOC_FILE_TRASHED'); JHtmlSidebar::addFilter(JText::_('JOPTION_SELECT_PUBLISHED'), 'state', JHtml::_('select.options', $options, 'value', 'text', $this->filter->state, true)); echo '<div id="j-sidebar-nav" class="span2">'; //render sidebar
/** * Get MySQL query fragment to control if document can be display on frontend. */ public static function getDocumentPublished() { $db = JFactory::getDbo(); /* @var $db JDatabaseMySQL */ $user = JFactory::getUser(); /* @var $user JUser logged user */ $date = JFactory::getDate(); /* @var $date JDate current date */ $config = JoomDOCConfig::getInstance(); $nullDate = $db->Quote($db->getNullDate()); /* @var $nullDate string empty date as MySQL datetime */ $nowDate = $db->Quote($date->toSql()); /* @var $nowDate current date date as MySQL datetime in GMT0 */ // document publish state $published[] = '`document`.`state` = ' . JOOMDOC_STATE_PUBLISHED; // document publishing interval $published[] = '(`document`.`publish_up` = ' . $nullDate . ' OR `document`.`publish_up` <= ' . $nowDate . ')'; $published[] = '(`document`.`publish_down` = ' . $nullDate . ' OR `document`.`publish_down` >= ' . $nowDate . ')'; // user group access if ($config->documentAccess == 2) { $groups = array($user->id ? $user->id : -1); } else { $groups = $user->getAuthorisedViewLevels(); } if (count($groups)) { JArrayHelper::toInteger($groups); $published[] = '`document`.`access` IN (' . implode(',', $groups) . ')'; } // all criteria have to pass $published = implode(' AND ', $published); // or logged user owes document $published = '(' . $published . ') OR `document`.`created_by` = ' . $user->id; return $published; }
JLoader::register('JoomDOCHelper', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/utilities/helper.php'); JLoader::register('JoomDOCAccessFileSystem', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/access/filesystem.php'); JLoader::register('JoomDOCAccess', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/access/joomdoc.php'); JLoader::register('JoomDOCAccessDocument', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/access/document.php'); JLoader::register('JHTMLJoomDOC', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/html/joomdoc.php'); JLoader::register('JoomDOCRequest', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/environment/request.php'); // Paths to load JoomDOC core classes (model, tables) sets. JModelLegacy::addIncludePath(JOOMDOC_MODELS); 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);
public function __construct(&$item) { $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ $user = JFactory::getUser(); $this->isFile = JoomDOCFileSystem::isFile($item); $this->isFolder = JoomDOCFileSystem::isFolder($item); $isFileSystemItem = $this->isFile || $this->isFolder; $this->docid = $isFileSystemItem ? JoomDOCHelper::getDocumentID($item) : $item->id; if (isset($item->document)) { $document = new JObject(); $document->setProperties($item->document); } elseif (!$isFileSystemItem) { if ($item instanceof JObject) { $document = $item; } else { $document = new JObject($item); $document->setProperties($item); } } else { $document = new JObject(); } $this->isTrashed = $isFileSystemItem ? @$item->file_state == JOOMDOC_STATE_TRASHED : $document->get('file_state') == JOOMDOC_STATE_TRASHED; if ($mainframe->isSite() && $document->get('state') == JOOMDOC_STATE_TRASHED) { $this->docid = null; } $this->relativePath = $isFileSystemItem ? $item->getRelativePath() : $item->path; $this->absolutePath = $isFileSystemItem ? $item->getAbsolutePath() : JoomDOCFileSystem::getFullPath($this->relativePath); $this->inRoot = $this->absolutePath == $config->path; $this->name = $isFileSystemItem ? $item->getFileName() : JFile::getName($this->relativePath); $this->alias = JoomDOCHelper::getDocumentAlias($item); $this->isChecked = JoomDOCHelper::isChecked($item); $this->isLocked = false; $this->fileType = JoomDOCHelper::getFileType($this->name); $this->canViewFileInfo = JoomDOCAccessFileSystem::viewFileInfo($this->docid, $this->relativePath); $this->fileVersion = JoomDOCHelper::getMaxVersion($this->relativePath); $this->canRename = JoomDOCAccessFileSystem::rename($this->docid, $this->relativePath); $this->canWebDav = JoomDOCAccessFileSystem::editWebDav($this->docid, $this->relativePath); $this->canEdit = $this->docid && JoomDOCAccessDocument::canEdit($document); $this->canCreate = !$this->docid && JoomDOCAccessDocument::create($this->relativePath); if ($config->documentAccess == 2 && $mainframe->isSite()) { $this->canDownload = $this->isFile && $document && $user->id == $document->get('access') && $document->get('download'); } else { $this->canDownload = $this->isFile && JoomDOCAccessFileSystem::download($this->docid, $this->relativePath); } $this->canEnterFolder = JoomDOCAccessFileSystem::enterFolder($this->docid, $this->relativePath); $this->canOpenFolder = $this->isFolder && $this->canEnterFolder; $this->canOpenFile = $this->isFile; $this->canEditStates = JoomDOCAccessDocument::editState($this->docid, $document->get('checked_out')); $this->canEditState = $this->docid && JoomDOCAccessDocument::editState($this->docid, $document->get('checked_out')); if ($mainframe->isAdmin()) { $this->canEditState = JoomDOCAccessDocument::editState(); } $this->canCopyMove = JoomDOCAccessFileSystem::copyMove($this->docid, $this->relativePath); $this->canDeleteDocs = JoomDOCAccessDocument::delete($this->docid); $this->canDeleteDoc = $this->docid && JoomDOCAccessDocument::delete($this->docid); $this->canDeleteFile = JoomDOCAccessFileSystem::deleteFile($this->docid, $this->relativePath); $this->canUpload = JoomDOCAccessFileSystem::uploadFile($this->docid, $this->relativePath); $this->canCreateFolder = JoomDOCAccessFileSystem::newFolder($this->docid, $this->relativePath); $this->canViewVersions = JoomDOCAccessDocument::viewVersions($this->docid); $this->canShowFileDates = $config->showCreated || $config->showModified; $this->canShowFileInfo = $config->showFilesize || $config->showHits; $this->canShowAllDesc = $config->showFolderDesc && $config->showFileDesc; $this->isFavorite = $document->get('favorite') == 1; $this->canDisplayFavorite = $this->isFavorite && $config->displayFavorite; $this->canAnyEditOp = $config->accessHandling && ($this->canEdit || $this->canWebDav || $this->canEditState || $this->canCreate || $this->canDeleteFile || $this->canDeleteDoc); if (!$this->docid || !$document->get('license_id')) { $license = JoomDOCHelper::license($this->relativePath); if ($license) { $this->licenseID = $license->id; $this->licenseAlias = $license->alias; $this->licenseTitle = $license->title; } } elseif ($document->get('license_state') == JOOMDOC_STATE_PUBLISHED) { $this->licenseID = $document->get('license_id'); $this->licenseAlias = $document->get('license_alias'); $this->licenseTitle = $document->get('license_title'); } $this->canManageVersions = false; $this->canUntrash = JoomDOCAccessFileSystem::untrash($this->docid, $this->relativePath); }
/** * Get CSS class name for file extension icon. * * @param string $filename file name or 'folder' * @param string $theme icon theme. if not provided, frontend configuration is used * @param int $size icon size * * @return string CSS class name for icon, empty string if icon is not available */ public static function getFileIconClass($filename, $theme = null, $size = 32) { if (!$theme) { $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $theme = $config->iconTheme; } static $cache = array(); static $generals; static $declared = array(); if (!isset($generals)) { //some icons can have "general name", for example "24-audio.png", use this array to map it to extensions (see Gion etc) $general = array('archive' => 'tar,gzip,zip,rar', 'audio' => 'wav,ogg,mp3,flac', 'video' => 'mpg,mpeg,avi,flv,3gp,mov', 'image' => 'ai,eps,jpg,jpeg,gif,png,bmp', 'doc' => 'doc,docx,rtf,odt,txt', 'xls' => 'xls,xlsx,csv,ods', 'htm' => 'htm,html', 'txt' => 'txt,ini'); $generals = array(); foreach ($general as $genName => $exts) { foreach (explode(',', $exts) as $ext) { $generals[$ext] = $genName; } } } if (!isset($cache[$theme])) { // EQ: /components/com_joomdoc/assets/images/icons/default $cache[$theme][$size] = array(); $filesCache[$theme] = array(); $iconsFolder = JOOMDOC_PATH_ICONS . DIRECTORY_SEPARATOR . $theme; if (JFolder::exists($iconsFolder)) { $icons = JFolder::files($iconsFolder, '\\.(png|gif)$'); foreach ($icons as $icon) { /* Parse size and extensions from file name. EQ: "16-ai-eps-jpg-gif-png.png", can be also "16-folder", "16-audio", etc. */ if (preg_match_all('/([0-9]+)|(\\-([a-z0-9]+))/', $icon, $match)) { // Icon size. EQ: 16 $iconSize = $match[1][0]; // Extensions EQ: ai,eps,jpg,gif,png $exts = array_splice($match[3], 1); // Store to cache. we will create classname when really needed with optinal resize below. $classname = implode('-', $exts); foreach ($exts as $ext) { $cache[$theme][$ext][$iconSize] = array($classname, JOOMDOC_ICONS . $theme . '/' . $icon); } } } } } $extension = $filename == 'folder' ? 'folder' : JFile::getExt($filename); $pickedExtension = false; //pick icon for this extension if (isset($cache[$theme][$extension])) { //by exact extension specified $pickedExtension = $extension; } if (!$pickedExtension and isset($generals[$extension])) { //ok, try "general" icons array if (isset($cache[$theme][$generals[$extension]])) { $pickedExtension = $generals[$extension]; } //still nothing, try to find similar icon based on general array (for example use "doc" icon for "txt" file) if (!$pickedExtension) { foreach ($generals as $genExt => $genName) { if ($genName == $generals[$extension] and isset($cache[$theme][$generals[$genExt]])) { $pickedExtension = $cache[$theme][$generals[$genExt]]; } } } } if (!$pickedExtension) { //no icon for this filetype return ''; } //ok, we have icon, now pick proper size if (!isset($cache[$theme][$pickedExtension][$size])) { //o-ou, this size missing $pickedSize = false; ksort($cache[$theme][$pickedExtension]); //sort from smallest foreach ($cache[$theme][$pickedExtension] as $iconSize => $icon) { if ($iconSize > $size) { //pick closest bigger icon $pickedSize = $iconSize; break; } } if (!$pickedSize) { //bigger not exists krsort($cache[$theme][$pickedExtension]); foreach ($cache[$theme][$pickedExtension] as $iconSize => $icon) { if ($iconSize < $size) { //pick closest smaller icon $pickedSize = $iconSize; break; } } } } else { $pickedSize = $size; } if (!$pickedSize) { //no size, this is weird.. return ''; } $classname = 'joomdoc-' . $pickedSize . '-' . $cache[$theme][$pickedExtension][$pickedSize][0]; if (empty($declared[$classname])) { $backgroundSize = $pickedSize != $size ? 'background-size: ' . $size . 'px ' . $size . 'px;' : ''; //add background-size property, if icon is different size (works in all browsers and IE>=9) $document = JFactory::getDocument(); /* Icon CSS style declaration. EQ: .joomdoc-16-ai-eps-jpg-gif-png { background-image: url("/components/com_joomdoc/assets/images/icons/default/16-ai-eps-jpg-gif-png.png"); } */ $document->addStyleDeclaration('.' . $classname . "\t" . ' { background-image: url("' . $cache[$theme][$pickedExtension][$pickedSize][1] . '") !important; ' . $backgroundSize . '}' . "\r\n"); $declared[$classname] = true; } return $classname; }
/** * Get SQL query for documents list. * * @return string */ protected function getListQuery() { $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ $config = JoomDOCConfig::getInstance(); // have concrete paths of search files if (count($paths = $this->getState(JOOMDOC_FILTER_PATHS))) { // cleanup paths and quote $paths = $this->getQuotedArray($paths); if (count($paths) && (!isset($this->docids) && !isset($this->fileids))) { $paths = implode(', ', $paths); // search latest version of files document $this->_db->setQuery('SELECT MIN(`id`) FROM `#__joomdoc` WHERE `path` IN (' . $paths . ') GROUP BY `path`'); $this->docids = $this->_db->loadColumn(); // search lastest version ids of file $this->_db->setQuery('SELECT MAX(`id`) FROM `#__joomdoc_file` WHERE `path` IN (' . $paths . ') GROUP BY `path`'); $this->fileids = $this->_db->loadColumn(); $this->_db->setQuery('SELECT `path`, SUM(`hits`) AS `hits` FROM `#__joomdoc_file` WHERE `path` IN (' . $paths . ') GROUP BY `path`'); $this->hits = $this->_db->loadObjectList('path'); } } if (!isset($this->docids) && !isset($this->fileids)) { $this->docids = $this->fileids = array(); } if ($mainframe->isSite()) { /* on site control document access */ $published = JoomDOCModelList::getDocumentPublished(); $query = 'SELECT `document`.`id`, `document`.`title`, `document`.`description`, `document`.`full_alias`, `document`.`modified`, `document`.`created`, `document`.`created_by`, `document`.`state`, `document`.`params`, `document`.`favorite`, `document`.`ordering`, `document`.`publish_up`, (' . $published . ') AS `published`, `file`.`upload`, `file`.`path`, `file`.`state` AS `file_state`, `document`.`checked_out`, `license`.`id` AS `license_id`, `license`.`title` AS `license_title`, `license`.`alias` AS `license_alias`, `license`.`state` AS `license_state` '; } else { $query = 'SELECT `file`.`upload`, `file`.`path`, `file`.`state` AS `file_state`, `document`.`id`, `document`.`title`, `document`.`ordering`, `document`.`access`, `document`.`publish_up`, `document`.`publish_down`, `document`.`state` AS `published`, `document`.`checked_out`, `document`.`checked_out_time`, `document`.`created_by`, `document`.`state`, `document`.`favorite`, `document`.`parent_path`, `editor`.`name` AS `editor`, `access`.`' . ($config->documentAccess == 1 ? 'title' : 'name') . '` AS `access_title`, `document`.`full_alias`, `license`.`id` AS `license_id`, `license`.`title` AS `license_title`, `license`.`alias` AS `license_alias`, `file`.`id` AS `file_id` '; } // complet query from/join state $query .= 'FROM `#__joomdoc_file` AS `file` '; $query .= 'LEFT JOIN `#__joomdoc` AS `document` ON `file`.`path` = `document`.`path` '; // user who checked out document $query .= 'LEFT JOIN `#__users` AS `editor` ON `editor`.`id` = `document`.`checked_out` '; // document access name, in Joomla 1.6.x is used different table then Joomla 1.5.x $query .= 'LEFT JOIN `#__' . ($config->documentAccess == 1 ? 'viewlevels' : 'users') . '` AS `access` ON `access`.`id` = `document`.`access` '; // document license $query .= 'LEFT JOIN `#__joomdoc_license` AS `license` ON `license`.`id` = `document`.`license` '; // filter for files if (count($this->fileids)) { $where[] = '(`file`.`id` IN (' . implode(', ', $this->fileids) . ') OR `file`.`id` IS NULL)'; } // filter for documents if (count($this->docids)) { $where[] = '(`document`.`id` IN (' . implode(', ', $this->docids) . ') OR `document`.`id` IS NULL)'; } // without output if (!count($this->fileids) && !count($this->docids)) { $where[] = '0'; } // in frontend only published files in backend according to user filter if ($mainframe->isSite()) { $where[] = '`file`.`state` = ' . JOOMDOC_STATE_PUBLISHED; } elseif ($this->state->get(JOOMDOC_FILTER_STATE) != 0) { $where[] = '`file`.`state` = ' . $this->state->get(JOOMDOC_FILTER_STATE); } $filter = $this->getState(JOOMDOC_FILTER_SEARCH); // filter for keywords if (!empty($filter) && ($filter->keywords || !empty($filter->fields))) { $extra = array(); if (!empty($filter->fields)) { foreach ($filter->fields as $id => $data) { if ($data['type'] == JOOMDOC_FIELD_DATE || $data['type'] == JOOMDOC_FIELD_RADIO || $data['type'] == JOOMDOC_FIELD_SELECT) { if ($data['value'] !== '') { $where[] = '`document`.`field' . $id . '` = ' . $this->_db->quote($data['value']); } } elseif ($data['type'] == JOOMDOC_FIELD_CHECKBOX || $data['type'] == JOOMDOC_FIELD_MULTI_SELECT || $data['type'] == JOOMDOC_FIELD_SUGGEST) { foreach ($data['value'] as $var => $val) { if ($val !== '') { $where[] = '`document`.`field' . $id . '` LIKE ' . $this->_db->quote('%"' . $val . '"%'); } } } else { if ($data['value']) { $extra[] = $id; // text field (text, textarea, editor) use in keyword searching } } } } $keywords = JString::strtolower($filter->keywords); if ($filter->type == JOOMDOC_SEARCH_ANYKEY || $filter->type == JOOMDOC_SEARCH_ALLKEY) { // search for any/all word from keywords // split to unique words $keywords = explode(' ', $keywords); } else { // search for full phrase $keywords = array($keywords); } // cleanup and quote words $keywords = $this->getQuotedArray($keywords, $filter->type != JOOMDOC_SEARCH_REGEXP); foreach ($keywords as $keyword) { $criteria = array(); foreach ($extra as $id) { if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`document`.`field' . $id . '` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`document`.`field' . $id . '`) LIKE ' . $keyword; } } if ($filter->areaTitle) { // document title or file path if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`document`.`title` REGEXP ' . $keyword; $criteria[] = '`file`.`path` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`document`.`title`) LIKE ' . $keyword; $criteria[] = 'LOWER(`file`.`path`) LIKE ' . $keyword; } } if ($filter->areaText) { // document description if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`document`.`description` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`document`.`description`) LIKE ' . $keyword; } } if ($filter->areaFull) { // file content if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`file`.`content` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`file`.`content`) LIKE ' . $keyword; } } if ($filter->areaMeta) { // need non escaped form $keyword = JString::substr($keyword, 1, JString::strlen($keyword) - 2); if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $metakeywords = $this->_db->quote('.*"metakeywords":"' . $keyword . '".*'); $metadescription = $this->_db->quote('.*"metadescription":"' . $keyword . '".*'); } else { $metakeywords = $this->_db->quote('%"metakeywords":"' . $keyword . '"%'); $metadescription = $this->_db->quote('%"metadescription":"' . $keyword . '"%'); } if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`document`.`params` REGEXP ' . $metakeywords; $criteria[] = '`document`.`params` REGEXP ' . $metadescription; } else { $criteria[] = 'LOWER(`document`.`params`) LIKE ' . $metakeywords; $criteria[] = 'LOWER(`document`.`params`) LIKE ' . $metadescription; } } // find word in one of items if (count($criteria)) { $oneWordFilter[] = '(' . implode(' OR ', $criteria) . ')'; } } if (isset($oneWordFilter)) { if ($filter->type == JOOMDOC_SEARCH_ALLKEY) { // all words $where[] = '(' . implode(' AND ', $oneWordFilter) . ')'; } else { // any word $where[] = '(' . implode(' OR ', $oneWordFilter) . ')'; } } } if (isset($where)) { $query .= ' WHERE ' . implode(' AND ', $where); } if (in_array($this->state->get(JOOMDOC_FILTER_ORDERING), array(JOOMDOC_ORDER_PATH, JOOMDOC_ORDER_UPLOAD, JOOMDOC_ORDER_HITS, JOOMDOC_ORDER_TITLE, JOOMDOC_ORDER_ORDERING))) { // $query .= ' ORDER BY `' . $this->_db->getEscaped($this->state->get(JOOMDOC_FILTER_ORDERING) . '` ' . JString::strtoupper($this->state->get(JOOMDOC_FILTER_DIRECTION))); } return $query; }
/** * Search file relative path by document full alias. * * @param string $fullAlias value from table #__joomdoc column full_alias * @return string value from table #__joomdoc column columns parent_path and path */ public function searchRelativePathByFullAlias($fullAlias) { if (!JString::trim($fullAlias)) { return null; } $config = JoomDOCConfig::getInstance(); if ($config->virtualFolder) { // if turn on virtual folder try to complete full document alias if ($rootPath = JoomDOCFileSystem::getRelativePath($config->path)) { // search for full alias of virtual root parent $rootFullAlias = $this->searchFullAliasByPath($rootPath); if ($rootFullAlias) { // add parent full alias on begin of document virtual full alias $fullAlias = $rootFullAlias . DIRECTORY_SEPARATOR . $fullAlias; } else { // add virtual root path parent on begin of document virtual full alias $fullAlias = $rootPath . DIRECTORY_SEPARATOR . $fullAlias; } } } // search for file relative path by document full alias $this->_db->setQuery('SELECT `path` FROM `#__joomdoc` WHERE `full_alias` = ' . $this->_db->quote($fullAlias) . ' ORDER BY `version` DESC', 0, 1); return $this->_db->loadResult(); }
/** * Get SQL query for documents list. * * @return string */ protected function getListQuery($searchActive = false) { $config = JoomDOCConfig::getInstance(); $mainframe = JFactory::getApplication(); /* @var $mainframe JApplication */ // have concrete paths of search files $paths = $this->getState(JOOMDOC_FILTER_PATHS); // cleanup paths and quote $paths = $this->getQuotedArray($paths); if (count($paths)) { if (JRequest::getVar('com_joomdoc_scope') != 'mod_joomdoc_explorer') { $this->_db->setQuery('SELECT `path`, SUM(`hits`) AS `hits` FROM `#__joomdoc_file` ' . ($searchActive ? '' : 'WHERE `path` IN (' . implode(', ', $paths) . ')') . ' GROUP BY `path`'); $this->hits = $this->_db->loadObjectList('path'); } } if (!isset($this->docids) && !isset($this->fileids)) { $this->docids = $this->fileids = array(); } $published = JoomDOCModelList::getDocumentPublished(); $fields = $this->getListFields(); $query = 'SELECT `id`, `title`, `description`, `full_alias`, `modified`, `created`, `created_by`, `state`, `params`, `favorite`, `ordering`, `publish_up`, (' . $published . ') AS `published`, `upload`, `parent_path`, `path`, `file_state`, `license_id`, `license_title`, `license_alias`, `license_state`, `access`, `download`, `file_id` '; foreach ($this->getListFields() as $field) { $query .= ', `field' . $field->id . '` '; } // load from flat index $query .= 'FROM `#__joomdoc_flat` AS `document`'; // filter for files if (!$searchActive) { $where[] = !empty($paths) ? '`path` IN (' . implode(', ', $paths) . ')' : 0; } // published files only $where[] = '`file_state` = ' . JOOMDOC_STATE_PUBLISHED; $filter = $this->getState(JOOMDOC_FILTER_SEARCH); // filter for keywords if ($searchActive) { $extra = array(); if ($filter->parent) { $where[] = 'LOWER(`document`.`path`) LIKE ' . $this->_db->q(JString::strtolower($filter->parent) . '%'); } if (!empty($filter->fields)) { foreach ($filter->fields as $id => $data) { if ($data['type'] == JOOMDOC_FIELD_DATE || $data['type'] == JOOMDOC_FIELD_RADIO || $data['type'] == JOOMDOC_FIELD_SELECT) { if ($data['value'] !== '') { $where[] = '`field' . $id . '` = ' . $this->_db->quote($data['value']); } } elseif ($data['type'] == JOOMDOC_FIELD_CHECKBOX || $data['type'] == JOOMDOC_FIELD_MULTI_SELECT || $data['type'] == JOOMDOC_FIELD_SUGGEST) { foreach ($data['value'] as $var => $val) { if ($val !== '') { // J!2.5 uses native JSON, J!3 converts JSON UCS-2BE into UTF-8 by MBString $where[] = '(`field' . $id . '` LIKE ' . $this->_db->quote('%"' . $val . '"%') . ' OR `field' . $id . '` LIKE ' . $this->_db->quote('%' . $this->_db->escape(json_encode($val)) . '%') . ')'; } } } else { if ($data['value'] || $config->searchKeyword == 2) { $extra[] = $id; // text field (text, textarea, editor) use in keyword searching } } } } if ($config->searchKeyword == 1) { // single keyword for all areas $keywords['global'] = JString::strtolower($filter->keywords); } elseif ($config->searchKeyword == 2) { // separate keyword for every area if ($config->searchShowTitle) { // document title $keywords['title'] = JString::strtolower($filter->keywords_title); } if ($config->searchShowText) { // document description $keywords['text'] = JString::strtolower($filter->keywords_text); } if ($config->searchShowMetadata) { // document metadata $keywords['meta'] = JString::strtolower($filter->keywords_meta); } if ($config->searchShowFulltext) { // file content $keywords['full'] = JString::strtolower($filter->keywords_full); } foreach ($extra as $id) { // custom text fields keyword $keywords['field' . $id] = JString::strtolower($filter->get('keywords_field' . $id)); } } if ($filter->type == JOOMDOC_SEARCH_ANYKEY || $filter->type == JOOMDOC_SEARCH_ALLKEY) { // search for any/all word from keywords // split to unique words foreach ($keywords as $type => $keys) { $keywords[$type] = explode(' ', $keys); } } else { // search for full phrase foreach ($keywords as $type => $keys) { $keywords[$type] = array($keys); } } // cleanup and quote words foreach ($keywords as $type => $keys) { $keywords[$type] = $this->getQuotedArray($keys, $filter->type != JOOMDOC_SEARCH_REGEXP); } foreach ($keywords as $type => $keys) { foreach ($keys as $keyword) { $criteria = array(); foreach ($extra as $id) { if ($type == 'global' || $type == 'field' . $id) { if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`field' . $id . '` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`field' . $id . '`) LIKE ' . $keyword; } } } if ($filter->areaTitle && $type == 'global' || $type == 'title') { // document title or file path if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`title` REGEXP ' . $keyword; $criteria[] = '`path` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`title`) LIKE ' . $keyword; $criteria[] = 'LOWER(`path`) LIKE ' . $keyword; } } if ($filter->areaText && $type == 'global' || $type == 'text') { // document description if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`description` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`description`) LIKE ' . $keyword; } } if ($filter->areaFull && $type == 'global' || $type == 'full') { // file content if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`content` REGEXP ' . $keyword; } else { $criteria[] = 'LOWER(`content`) LIKE ' . $keyword; } } if ($filter->areaMeta && $type == 'globa' || $type == 'meta') { // need non escaped form $keyword = JString::substr($keyword, 1, JString::strlen($keyword) - 2); if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $metakeywords = $this->_db->quote('.*"metakeywords":"' . $keyword . '".*'); $metadescription = $this->_db->quote('.*"metadescription":"' . $keyword . '".*'); } else { $metakeywords = $this->_db->quote('%"metakeywords":"' . $keyword . '"%'); $metadescription = $this->_db->quote('%"metadescription":"' . $keyword . '"%'); } if ($filter->type == JOOMDOC_SEARCH_REGEXP) { $criteria[] = '`params` REGEXP ' . $metakeywords; $criteria[] = '`params` REGEXP ' . $metadescription; } else { $criteria[] = 'LOWER(`params`) LIKE ' . $metakeywords; $criteria[] = 'LOWER(`params`) LIKE ' . $metadescription; } } // find word in one of items if (count($criteria)) { $oneWordFilter[] = '(' . implode(' OR ', $criteria) . ')'; } } } if (isset($oneWordFilter)) { if ($filter->type == JOOMDOC_SEARCH_ALLKEY) { // all words $where[] = '(' . implode(' AND ', $oneWordFilter) . ')'; } else { // any word $where[] = '(' . implode(' OR ', $oneWordFilter) . ')'; } } } if (isset($where)) { $query .= ' WHERE ' . implode(' AND ', $where); } return $query; }
function getRegisteredInfo($artioDownloadID = null) { static $regInfo; if (is_null($regInfo)) { $regInfo = new stdClass(); $config = JoomDOCConfig::getInstance(); if (is_null($artioDownloadID)) { $artioDownloadID = ARTIO_UPGRADE_DOWNLOAD_ID; } if ($artioDownloadID) { // Send the request to ARTIO server to check registration $data = array('download_id' => $artioDownloadID); $response =& $this->post(ARTIO_UPGRADE_LICENSE_URL, null, $data); if ($response === false || $response->code != 200) { JError::raiseNotice(100, JText::_('Error reg check fail')); return null; } else { // Parse the response - get individual lines $lines = explode("\n", $response->content); // Get the code $pos = strpos($lines[0], ' '); if ($pos === false) { JError::raiseNotice(100, JText::_('Error reg check fail')); return null; } $regInfo->code = intval(substr($lines[0], 0, $pos)); if ($regInfo->code == 10 || $regInfo->code == 20) { // Download id found if (count($lines) < 3) { // Wrong response JError::raiseNotice(100, JText::_('Error reg check fail')); return null; } // Parse the date $match = array(); if (preg_match('/([0-9]*)\\/([0-9]*)\\/([0-9]*)/', JString::trim($lines[1]), $match)) { $regInfo->date = JHtml::date($match[3] . '-' . $match[1] . '-' . $match[2], JText::_('DATE_FORMAT_LC4'), false); } // Parse the name $regInfo->name = JString::trim($lines[2]); // Parse the company $regInfo->company = isset($lines[3]) ? JString::trim($lines[3]) : ''; // Is upgrade expired? if ($regInfo->code == 20) { JError::raiseNotice(100, JText::_('Info upgrade license expired')); } // Is upgrade inactive if ($regInfo->code == 30) { JError::raiseNotice(100, JText::_('Info upgrade not active')); $regInfo->date = JText::_('not activated yet'); } } else { if ($regInfo->code == 40) { // Domain does not match JError::raiseNotice(100, JText::_('DOMAIN_DOES_NOT_MATCH')); return null; } else { if ($regInfo->code == 90) { // Download id not found, do nothing JError::raiseNotice(100, JText::_('Error download id not found')); } else { // Wrong response JError::raiseNotice(100, JText::_('Error reg check fail')); return null; } } } } } else { // Download ID not set JError::raiseNotice(100, JText::_('Download id not set')); return null; } } return $regInfo; }
/** * Overload the store method for the documents table. * * @param boolean Toggle whether null values should be updated. * @return boolean True on success, false on failure. * @since 1.6 */ public function store($updateNulls = false, $reindex = true) { $date = JFactory::getDate(); /* @var $date JDate current date */ $currentDate = $date->toSql(); /* @var $currentDate string current date as MySQL datetime in GMT0 */ $user = JFactory::getUser(); /* @var $user JUser current logged user */ $config = JoomDOCConfig::getInstance(); /* @var $config JoomDOCConfig */ $app = JFactory::getApplication(); /* @var $app JApplication */ if ($this->id) { // for exists document store modifier $this->modified = $currentDate; $this->modified_by = $user->get('id'); } else { if (!intval($this->created)) { $this->created = $currentDate; } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } // add on end in list $this->_db->setQuery('SELECT MAX(`ordering`) FROM `#__joomdoc` WHERE `parent_path` = ' . $this->_db->quote($this->parent_path)); $this->ordering = (int) $this->_db->loadResult() + 1; } // if user doesn't set alias use title if (!JString::trim($this->alias)) { $this->alias = $this->title; } // convert alias to safe string if ($app->getCfg('unicodeslugs') == 1) { $this->alias = JFilterOutput::stringURLUnicodeSlug($this->alias); } else { $this->alias = JFilterOutput::stringURLSafe($this->alias); } $this->full_alias = $this->alias; if ($this->parent_path) { // search alias of parent document $this->_db->setQuery('SELECT `full_alias` FROM `#__joomdoc` WHERE `path` = ' . $this->_db->Quote($this->parent_path) . ' ORDER BY `version` DESC', 0, 1); $parentAlias = $this->_db->loadResult(); // create full alias with parent path if (!JString::trim($parentAlias)) { // if parent alias not available use parent path $parentAlias = JoomDOCString::stringURLSafe($this->parent_path); } if (JString::trim($parentAlias)) { $this->full_alias = $parentAlias . '/' . $this->alias; } } $this->_db->setQuery('SELECT MIN(`id`) FROM `#__joomdoc` WHERE `parent_path` = ' . $this->_db->Quote($this->path) . ' GROUP BY `path`'); $cid = $this->_db->loadColumn(); if ($cid) { // update alias in child documents $query = 'SELECT `id`, `alias`, `full_alias` FROM `#__joomdoc` WHERE `id` IN (' . implode(', ', $cid) . ')'; $this->_db->setQuery($query); $childs = $this->_db->loadObjectList(); foreach ($childs as $child) { $fullAlias = $this->full_alias . '/' . $child->alias; if ($child->full_alias != $fullAlias) { $query = 'UPDATE `#__joomdoc` SET `full_alias` = ' . $this->_db->Quote($fullAlias) . ' WHERE `id` = ' . (int) $child->id; $this->_db->setQuery($query); $this->_db->query(); } } } foreach (get_object_vars($this) as $var => $val) { if ($var[0] != '_' && (is_array($val) || is_object($val))) { $registry = new JRegistry($val); $this->{$var} = $registry->toString(); } } $success = parent::store($updateNulls); if ($success && $reindex) { JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX)->flat($this->path); } return $success; }