예제 #1
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();
 }
예제 #2
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);
 }