/** * 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')); } }
/** * Rename file/folder and versions folder. With failed roll back changes. * Rename path in database (file/document). * * @param string $oldPath relative path of file/folder to rename * @param string $newName new file/folder mame (without path) * @return boolean true/false - success/unsuccess */ public static function rename($oldPath, $newName) { $model = JModelLegacy::getInstance(JOOMDOC_DOCUMENT, JOOMDOC_MODEL_PREFIX); /* @var $model JoomDOCModelDocument */ // parent folder of affected file/folder $parentPath = JoomDOCFileSystem::getParentPath($oldPath); if ($parentPath) { $newPath = $parentPath . DIRECTORY_SEPARATOR . $newName; } else { $newPath = $newName; } // old absolute path of affected file/folder $oldPathFull = JoomDOCFileSystem::getFullPath($oldPath); // new absolute path of affected file/folder $newPathFull = JoomDOCFileSystem::getFullPath($newPath); // control if user is allowed to edit this item if (!JoomDOCAccessFileSystem::rename(false, $oldPath)) { JError::raiseError(403, JText::_('JOOMDOC_RENAME_NOT_ALLOW')); } // try to rename file or folder if (JFile::exists($oldPathFull) && !JFile::move($oldPathFull, $newPathFull) || JFolder::exists($oldPathFull) && !JFolder::move($oldPathFull, $newPathFull)) { // unable rename return false; } // rename in database $table = JTable::getInstance(JOOMDOC_FILE, JOOMDOC_TABLE_PREFIX); /* @var $table JoomDOCTableFile */ $table->rename($oldPath, $newPath); return true; }
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); }