Esempio n. 1
0
 /**
  * Display browse table of file versions with extended filter.
  *
  * @param string $tpl used template
  */
 public function display($tpl = null)
 {
     $mainframe = JFactory::getApplication();
     /* @var $mainframe JAdministrator */
     $modelFile = $this->getModel();
     /* @var $modelFile JoomDOCModelFile */
     $this->filter = new JObject();
     $this->filter->path = JoomDOCRequest::getPath();
     $this->item = new JoomDOCFile(JoomDOCFileSystem::getFullPath($this->filter->path));
     $sessionPrefix = JoomDOCRequest::getSessionPrefix(true);
     $this->filter->offset = $mainframe->getUserStateFromRequest($sessionPrefix . 'offset', 'limitstart', 0, 'int');
     //var_dump($sessionPrefix);
     $this->filter->limit = $mainframe->getUserStateFromRequest($sessionPrefix . 'limit', 'limit', 10, 'int');
     //var_dump($this->filter->limit);
     $this->filter->listOrder = $mainframe->getUserStateFromRequest($sessionPrefix . 'listOrder', 'filter_order', 'version', 'string');
     //var_dump($this->filter->listOrder);
     $this->filter->listDirn = $mainframe->getUserStateFromRequest($sessionPrefix . 'listDirn', 'filter_order_Dir', 'asc', 'string');
     //var_dump($this->filter->listDirn);
     $this->filter->uploader = $mainframe->getUserStateFromRequest($sessionPrefix . 'uploader', 'uploader', '', 'string');
     //var_dump($this->filter->uploader);
     $this->filter->state = $mainframe->getUserStateFromRequest($sessionPrefix . 'state', 'state', 0, 'int');
     //var_dump($this->filter->state);
     $this->data = $modelFile->getData($this->filter);
     $this->document = $modelFile->getDocument($this->filter);
     $this->item->document = $this->document;
     $this->maxVersion = $modelFile->getMaxVersion($this->filter->path);
     $this->access = new JoomDOCAccessHelper($this->item);
     if (!JoomDOCAccessFileSystem::viewFileInfo($this->document ? $this->document->id : null, $this->filter->path)) {
         JError::raiseError(403, JText::sprintf('JOOMDOC_VIEW_FILE_INFO_NOT_ALLOW'));
     }
     $this->addToolbar();
     parent::display($tpl);
 }
Esempio n. 2
0
 public function updatemootree()
 {
     $app = JFactory::getApplication();
     $parent = JoomDOCRequest::getPath();
     $modelDocuments = JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX);
     $root = JoomDOCFileSystem::getFolderContent(JoomDOCFileSystem::getFullPath($parent), '', 1, true, false);
     $modelDocuments->setState(JoomDOCView::getStateName(JOOMDOC_FILTER_PATHS), $root->getPaths());
     $root->setDocuments($modelDocuments->getItems());
     $root->reorder(null, JOOMDOC_ORDER_PATH, JOOMDOC_ORDER_ASC, 0, PHP_INT_MAX);
     JRequest::setVar('ajax', true);
     $folders = JHtml::_('joomdoc.folders', $root, $parent);
     JHtml::_('joomdoc.mootree', $folders, $parent, false, true);
 }
Esempio n. 3
0
 /**
  * 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'));
     }
 }
Esempio n. 4
0
 /**
  * Revert selected Version as last Version.
  *
  * @param int $id restored Version row ID
  * @param string $path restored Version Path
  * @return JObject
  *     revertVersion   reverted Version Number
  *     oldLastVersion  archived last Version Number
  *     newLastVersion  new last Version from reverted Version number
  */
 function revert($id, $path)
 {
     $safePath = $this->_db->quote($path);
     $this->_db->setQuery('SELECT MAX(`id`) FROM `#__joomdoc_file` WHERE `path` = ' . $safePath . ' GROUP BY `path`');
     $cid = $this->_db->loadColumn();
     // the latest file version list
     // get Row with given ID and given Path which isn't last Version - candidate to revert as last Version
     $query = 'SELECT `id`, `version` FROM `#__joomdoc_file` WHERE `id` = ' . (int) $id . ' AND `path` = ' . $safePath;
     if ($cid) {
         $query .= ' AND `id` NOT IN (' . implode(', ', $cid) . ')';
     }
     $this->_db->setQuery($query);
     $candidate = $this->_db->loadObject();
     if (is_null($candidate)) {
         return false;
     }
     // get last Version number
     $query = 'SELECT MAX(`version`) FROM `#__joomdoc_file` WHERE `path` = ' . $safePath;
     $this->_db->setQuery($query);
     $lastVersion = $this->_db->loadResult();
     if (is_null($lastVersion)) {
         return false;
     }
     // full Path of last Version
     $lastVersionPath = JoomDOCFileSystem::getFullPath($path);
     // full Path of revert Version
     $revertVersionPath = JoomDOCFileSystem::getVersionPath($lastVersionPath, $candidate->version, true);
     // full Path to archive last Version
     $archiveVersionPath = JoomDOCFileSystem::getVersionPath($lastVersionPath, $lastVersion, true);
     // move last Version as archive Version
     if (!JFile::move($lastVersionPath, $archiveVersionPath)) {
         return false;
     }
     // copy revert Version as last Version
     if (!JFile::copy($revertVersionPath, $lastVersionPath)) {
         return false;
     }
     // copy revert Version DB Row
     $newLastVersionID = JoomDOCModelList::copyRow('#__joomdoc_file', 'id', $candidate->id);
     // increment new last Version number
     $newLastVersion = $lastVersion + 1;
     $query = 'UPDATE `#__joomdoc_file` SET `version` = ' . $newLastVersion . ', `state` = ' . JOOMDOC_STATE_PUBLISHED . ' WHERE `id` = ' . $newLastVersionID;
     $this->_db->setQuery($query);
     $this->_db->query();
     $output = new JObject();
     $output->revertVersion = $candidate->version;
     $output->oldLastVersion = $lastVersion;
     $output->newLastVersion = $newLastVersion;
     JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX)->flat($path);
     return $output;
 }
Esempio n. 5
0
 /**
  * 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);
 }
Esempio n. 6
0
    /**
     * 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;
    }
Esempio n. 7
0
 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();
 }
Esempio n. 8
0
        //echo $i.' | '.$item->id.' | '.$item->version.' | '.$this->maxVersion;
        echo '<td>' . JHtml::_('grid.id', ++$i, $item->id, $item->version == $this->maxVersion) . '</td>';
    }
    echo '<td>' . $item->version . '</td>';
    if ($showDownload) {
        echo '<td>';
        if ($item->state == JOOMDOC_STATE_PUBLISHED) {
            echo '<a href="' . JRoute::_(JoomDOCRoute::download($item->path, null, $item->version)) . '" title="" target="_blank">';
            echo $download;
            echo '</a>';
        } elseif ($item->state == JOOMDOC_STATE_TRASHED) {
            echo $trashed;
        }
        echo '</td>';
    }
    echo '<td nowrap="nowrap">' . JoomDOCFileSystem::getFileSize(JoomDOCFileSystem::getFullPath($item->path)) . '</td>';
    echo '<td nowrap="nowrap">' . JoomDOCHelper::uploaded($item->upload, false) . '</td>';
    echo '<td nowrap="nowrap">' . $item->name . '</td>';
    echo '<td class="center" nowrap="nowrap">' . JoomDOCHelper::number($item->hits) . '</td>';
    echo '</tr>';
}
echo '</tbody>';
echo '<tfoot>';
echo '<tr>';
$pagination = new JPagination($this->filter->total, $this->filter->offset, $this->filter->limit);
echo '<td colspan="20">' . $pagination->getListFooter() . '</td>';
echo '</tr>';
echo '</tfoot>';
echo '</table>';
echo JHtml::_('form.token');
echo '<input type="hidden" name="task" value="" />';
Esempio n. 9
0
 public function run()
 {
     $db = JFactory::getDbo();
     /* @var $db JDatabase */
     $mainframe = JFactory::getApplication();
     /* @var $mainframe JApplication */
     // selected source docman or joomdoc
     $component = JRequest::getString('component');
     // current database prefix
     $pr = $mainframe->getCfg('dbprefix');
     // all DocMAN or JoomDOC2 tables
     if ($component == 'docman') {
         $tables = array($pr . 'docman', $pr . 'docman_groups', $pr . 'docman_history', $pr . 'docman_licenses', $pr . 'docman_log');
     } else {
         $tables = array($pr . 'joomdoc2', $pr . 'joomdoc2_groups', $pr . 'joomdoc2_history', $pr . 'joomdoc2_licenses', $pr . 'joomdoc2_log');
     }
     // all tables in Joomla database
     $joomla = $db->getTableList();
     // check if all tables exists, are required
     if (array_intersect($tables, $joomla) != $tables) {
         return $this->setRedirect(JoomDOCRoute::viewJoomDOC(), JText::sprintf('JOOMDOC_MIGRATION_TABLES_UNAVAILABLE', implode(', ', $tables)), 'error');
     }
     // relative path folder where DocMAN or JoomDOC stored files, is required
     $docbase = JPath::clean(JPATH_ROOT . '/' . JRequest::getString('docbase'));
     if (!JFolder::exists($docbase)) {
         return $this->setRedirect(JoomDOCRoute::viewJoomDOC(), JText::sprintf('JOOMDOC_MIGRATION_DOCBASE_UNAVAILABLE', $docbase), 'error');
     }
     // statictis counters
     $newFolders = $newFiles = 0;
     /* copy DocMAN or JoomDOC2 licenses into JoomDOC3 */
     $license = JTable::getInstance(JOOMDOC_LICENSE, JOOMDOC_TABLE_PREFIX);
     /* @var $license JoomDOCTableLicense */
     $table = $component == 'docman' ? 'docman_licenses ' : 'joomdoc2_licenses ';
     // total of licenses in DocMAN or JoomDOC2
     $db->setQuery('SELECT COUNT(*) FROM #__' . $table);
     $total = $db->loadResult();
     // map Ids of licenses from DocMAN or JoomDOC2 into Ids of licenses in new JoomDOC3 structure
     $licensesMap = array();
     for ($i = 0; $i < $total; $i += 100) {
         // migrate licenses in batch process
         $db->setQuery('SELECT * FROM #__' . $table, $i, 100);
         $items = $db->loadObjectList();
         foreach ($items as $item) {
             // prepare new JoomDOC3 license
             $license->id = 0;
             $license->alias = null;
             $license->state = JOOMDOC_STATE_PUBLISHED;
             // copy data from DocMAN or JoomDOC2 license into JoomDOC3
             $license->title = $item->name;
             $license->text = $item->license;
             $license->store();
             // store licenses maping for using in new JoomDOC3 documents
             $licensesMap[$item->id] = $license->id;
         }
     }
     $document = JTable::getInstance(JOOMDOC_DOCUMENT, JOOMDOC_TABLE_PREFIX);
     /* @var $document JoomDOCTableDocument */
     // convert DocMAN or JoomDOC categories into JoomDOC3 folders
     $parents = array(0 => '');
     // root of categories tree
     // do for levels of categories tree
     // store map of Joomla categories and DocMAN/JoomDOC2 documents to JoomDOC3 paths
     $categoriesMap = $documentsMap = array();
     do {
         // name of Joomla category section - identify component
         $section = $db->quote($component == 'docman' ? 'com_docman' : 'com_joomdoc');
         $parentsIds = implode(', ', array_keys($parents));
         // load total of DocMAN or JoomDOC2 categories in one level of categories tree
         if ($component == 'docman' && in_array($pr . 'docman_categories', $joomla)) {
             // since DocMAN 1.5
             $db->setQuery('SELECT COUNT(*) FROM #__docman_categories WHERE parent_id IN (' . $parentsIds . ')');
         } else {
             $db->setQuery('SELECT COUNT(*) FROM #__categories WHERE section = ' . $section . ' AND parent_id IN (' . $parentsIds . ')');
         }
         try {
             $total = $db->loadResult();
         } catch (Exception $e) {
             // new format of table jos_categories without section column
             $c = $db->replacePrefix('#__categories');
             $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_MIGRATION_OLD_CATEGORIES', $c, $c, $c, $c), 'notice');
             return;
         }
         $nextLevel = isset($nextLevel) ? array() : array(0 => '');
         // in the first batch process uncategorized documents
         for ($i = 0; $i < $total; $i += 100) {
             // load DocMAN or JoomDOC2 categories tree level full node list in batch process
             if ($component == 'docman' && in_array($pr . 'docman_categories', $joomla)) {
                 // since DocMAN 1.5
                 $db->setQuery('SELECT id, title, parent_id, description, published, ordering, access FROM #__docman_categories WHERE parent_id IN (' . $parentsIds . ')', $i, 100);
             } else {
                 $db->setQuery('SELECT id, title, parent_id, description, published, ordering, access FROM #__categories WHERE section = ' . $section . ' AND parent_id IN (' . $parentsIds . ')', $i, 100);
             }
             $children = $db->loadObjectList('id');
             foreach ($children as $id => $kid) {
                 /* @var $kid JTableCategory */
                 // create folder name from category title
                 $folder = JFilterOutput::stringURLSafe($kid->title);
                 // create document for folder
                 $document->id = 0;
                 $document->parent_path = $parents[$kid->parent_id];
                 $document->path = ($document->parent_path ? $document->parent_path . DIRECTORY_SEPARATOR : '') . $folder;
                 // copy data form category into document
                 $document->title = $kid->title;
                 $document->alias = null;
                 $document->description = $kid->description;
                 $document->state = $kid->published == JOOMDOC_STATE_PUBLISHED ? JOOMDOC_STATE_PUBLISHED : JOOMDOC_STATE_UNPUBLISHED;
                 $document->ordering = $kid->ordering;
                 $document->access = $kid->access ? $kid->access : 1;
                 if (!JFolder::exists(JoomDOCFileSystem::getFullPath($document->path))) {
                     // create folder only if doesn't exists
                     JoomDOCFileSystem::newFolder($document->parent_path, $folder, false, false);
                 } else {
                     // folder exist, search last exists document
                     $db->setQuery('SELECT id FROM #__joomdoc WHERE path = ' . $db->Quote($document->path) . ' ORDER BY version DESC');
                     $document->id = $db->loadResult();
                 }
                 if (JFolder::exists(JoomDOCFileSystem::getFullPath($document->path))) {
                     if ($document->store(false, false)) {
                         $newFolders++;
                         // current kid will be in parents for next level of categories tree
                         $nextLevel[$id] = $document->path;
                         $categoriesMap[$kid->id] = $document->path;
                     }
                 }
             }
         }
         // next level parents
         $parents = $nextLevel;
         if (count($parents)) {
             /* Convert DocMAN or JoomDOC2 categories documents into JoomDOC3 files in folder */
             $table = $component == 'docman' ? 'docman' : 'joomdoc2';
             $parentsIds = implode(', ', array_keys($parents));
             // load total of DocMAN or JoomDOC2 documents for categories in current level
             $db->setQuery('SELECT COUNT(*) FROM #__' . $table . ' WHERE catid IN (' . $parentsIds . ')');
             $total = $db->loadResult();
             // DocMAN or JoomDOC2 documents from categories in current tree level - batch process
             for ($i = 0; $i < $total; $i += 100) {
                 $db->setQuery('SELECT * FROM #__' . $table . ' WHERE catid IN (' . $parentsIds . ')', $i, 100);
                 $items = $db->loadObjectList();
                 foreach ($items as $item) {
                     // create document for successfully uploaded file
                     $document->id = 0;
                     $document->parent_path = $parents[$item->catid];
                     $document->path = $document->parent_path . DIRECTORY_SEPARATOR . $item->dmfilename;
                     // copy data from DocMAN or JoomDOC2 document into JoomDOC3 document
                     $document->title = $item->dmname;
                     $document->alias = null;
                     $document->description = $item->dmdescription;
                     $document->publish_up = $item->dmdate_published;
                     $document->created_by = $item->dmsubmitedby;
                     $document->state = $item->published == JOOMDOC_STATE_PUBLISHED ? JOOMDOC_STATE_PUBLISHED : JOOMDOC_STATE_UNPUBLISHED;
                     $document->modified = $item->dmlastupdateon;
                     $document->modified_by = $item->dmlastupdateby;
                     $document->access = $item->access ? $item->access : 1;
                     $document->license = isset($licensesMap[$item->dmlicense_id]) ? $licensesMap[$item->dmlicense_id] : 0;
                     if (JFile::exists(JoomDOCFileSystem::getFullPath($document->path))) {
                         // if file exists search for last document
                         $db->setQuery('SELECT id FROM #__joomdoc WHERE path = ' . $db->quote($document->path) . ' ORDER BY version DESC');
                         $document->id = $db->loadResult();
                     }
                     if (JoomDOCFileSystem::uploadFile(JoomDOCFileSystem::getFullPath($parents[$item->catid]), $docbase . DIRECTORY_SEPARATOR . $item->dmfilename, $item->dmfilename, true, false)) {
                         // upload into JoomDOC3 tree structure
                         if ($document->store(false, false)) {
                             $newFiles++;
                             // copy document hits into JoomDOC3 file
                             $db->setQuery('UPDATE #__joomdoc_file SET hits = ' . $item->dmcounter . ' WHERE path = ' . $db->quote($document->path));
                             $db->query();
                             $documentsMap[$item->id] = $document->path;
                         }
                     }
                 }
             }
         }
     } while (count($parents));
     // reindex at the end
     JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX)->flat();
     /* Migrate DocMAN/JoomDOC2 URLs to JoomDOC3 in JoomSEF and Joomla tables*/
     $entities = array(array('table' => 'menu', 'html' => false, 'columns' => array('link', 'params'), 'where' => ' WHERE client_id != 1 '), array('table' => 'content', 'html' => true, 'columns' => array('introtext', '`fulltext`')), array('table' => 'modules', 'html' => true, 'columns' => array('content')), array('table' => 'sefurls', 'html' => false, 'columns' => array('origurl')));
     foreach ($entities as $entity) {
         // check if table is available
         // backup table with name eq. jos_content_joomdoc3_migration_backup
         $backup = $pr . $entity['table'] . '_joomdoc3_migration_backup';
         // check if backup already exists
         $db->setQuery('SHOW TABLES LIKE ' . $db->quote($backup));
         if ($db->loadResult() === null) {
             // create clone of backuped table
             $db->setQuery('CREATE TABLE IF NOT EXISTS ' . $backup . ' LIKE #__' . $entity['table']);
             try {
                 $db->query();
             } catch (Exception $e) {
                 continue;
                 // JoomSEF not installed
             }
             // copy data of table into backup
             $db->setQuery('INSERT INTO ' . $backup . ' SELECT * FROM #__' . $entity['table']);
             $db->query();
             // inform user about backup available
             $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_MIGRATION_BACKUPED', $pr . $entity['table'], $backup));
         }
         // get total of rows
         $db->setQuery('SELECT COUNT(*) FROM #__' . $entity['table'] . (empty($entity['where']) ? '' : $entity['where']));
         $total = $db->loadResult();
         for ($i = 0; $i < $total; $i += 500) {
             // load URLs in batch process
             $db->setQuery('SELECT id, ' . implode(', ', $entity['columns']) . ' FROM #__' . $entity['table'] . (empty($entity['where']) ? '' : $entity['where']), $i, 500);
             // load as multidimensional array
             $items = $db->loadRowList();
             foreach ($items as $item) {
                 // information if any change was made
                 $affected = false;
                 $count = count($item);
                 // process columns without id
                 for ($j = 1; $j < $count; $j++) {
                     $urls = array();
                     if ($entity['html']) {
                         // content is HTML code from editor (article, module)
                         $matches = array();
                         if (preg_match_all('/href="([^"]*)"/', $item[$j], $matches)) {
                             $urls = $matches[1];
                         }
                     } else {
                         // URL is whole content (JoomSEF, menu)
                         $urls = array($item[$j]);
                     }
                     // analyse URLs
                     foreach ($urls as $url) {
                         $uri = JFactory::getURI($url);
                         /* @var $uri JURI Joomla support for working with URLs */
                         if ($uri->getVar('option') == 'com_joomdoc' || $uri->getVar('option') == 'com_docman') {
                             // JoomDOC3 option same as JoomDOC2
                             $uri->setVar('option', 'com_joomdoc');
                             // ID of DocMAN/JoomDOC2 category or document
                             $gid = $uri->getVar('gid');
                             // unused in new URL
                             $uri->delVar('gid');
                             // analyse DocMAN/JoomDOC task value to recognise typoe of URL
                             switch ($uri->getVar('task')) {
                                 case 'cat_view':
                                     /* display DocMAN/JoomDOC2 category */
                                     $uri->setVar('view', JOOMDOC_DOCUMENTS);
                                     $uri->delVar('task');
                                     // don't use task wit wire together
                                     break;
                                 case 'doc_details':
                                     /* display DocMAN/JoomDOC2 document */
                                 /* display DocMAN/JoomDOC2 document */
                                 case 'doc_view':
                                     $uri->setVar('view', JOOMDOC_DOCUMENTS);
                                     $uri->delVar('task');
                                     // don't use task with view together
                                     break;
                                 case 'doc_download':
                                     $uri->setVar('task', JoomDOCHelper::getTask(JOOMDOC_DOCUMENT, JOOMDOC_TASK_DOWNLOAD));
                                     break;
                                 case 'doc_edit':
                                     $uri->setVar('task', JoomDOCHelper::getTask(JOOMDOC_DOCUMENT, JOOMDOC_TASK_EDIT));
                                     break;
                                 case 'doc_delete':
                                     $uri->setVar('task', JoomDOCHelper::getTask(JOOMDOC_DOCUMENT, JOOMDOC_TASK_DELETE));
                                     break;
                                 default:
                                     /* URLs not supported by JoomDOC3 redirect to root */
                                     $uri->setVar('view', JOOMDOC_DOCUMENTS);
                                     break;
                             }
                             if (isset($documentsMap[$gid])) {
                                 $uri->setVar('path', $documentsMap[$gid]);
                             }
                             // menu items to open documents list store for using in next entities
                             if ($entity['table'] == 'menu' && $uri->getVar('view') == JOOMDOC_DOCUMENTS) {
                                 $registry = new JRegistry($item[2]);
                                 // load menu item configuration
                                 $registry->set('virtual_folder', 0);
                                 // disable JoomDOC3 virtual folder
                                 $item[2] = $registry->toString();
                                 /* back to database format */
                             }
                             $new = $uri->toString();
                             // back to string
                             if ($entity['html']) {
                                 // safe for valid HTML code
                                 $new = str_replace('&', '&amp;', $new);
                             }
                             // remove encoding in path added with JURI - prevent for making duplicity with JoomSEF
                             $new = str_replace('%2F', '/', $new);
                             $item[$j] = str_replace($url, $new, $item[$j]);
                             // update in data
                             // row will be updated
                             $affected = true;
                         }
                     }
                 }
                 if ($affected) {
                     $cols = array();
                     for ($j = 1; $j < $count; $j++) {
                         $cols[] = $entity['columns'][$j - 1] . ' = ' . $db->quote($item[$j]);
                     }
                     $db->setQuery('UPDATE #__' . $entity['table'] . ' SET ' . implode(', ', $cols) . ' WHERE id = ' . $item[0]);
                     $db->query();
                 }
             }
         }
     }
     // final report
     $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_MIGRATION_REPORT', $newFolders, $newFiles));
     $this->setRedirect(JoomDOCRoute::viewMigration());
 }
Esempio n. 10
0
 /**
  * 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);
 }
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);
Esempio n. 12
0
 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);
 }
Esempio n. 13
0
JLoader::register('JoomDOCFolder', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/filesystem/folder.php');
JLoader::register('JoomDOCFile', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/filesystem/file.php');
JLoader::register('JoomDOCAccessHelper', JOOMDOC_ADMINISTRATOR . '/libraries/joomdoc/access/helper.php');
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');
// 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 = JoomDOCModuleConfig::getInstance($params, $module->id);
$globalConfig = JoomDOCConfig::getInstance();
$modelDocuments = JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_SITE_PREFIX);
/* @var $modelDocuments JoomDOCSiteModelDocuments */
$listFields = $modelDocuments->getListFields();
// Only files are loaded.
$root = JoomDOCFileSystem::getFolderContent($moduleConfig->parent ? JoomDOCFileSystem::getFullPath($moduleConfig->parent) : $globalConfig->docroot, '', true, false, true);
// 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($moduleConfig->documentOrdering, $moduleConfig->fileOrdering, JOOMDOC_ORDER_DESC, 0, $moduleConfig->limit, $moduleConfig->limit);
// Active module template displayed.
require JModuleHelper::getLayoutPath('mod_joomdoc', $moduleConfig->layout);