/** * 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 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); }