Exemplo n.º 1
0
 /**
  * Allow save document.
  */
 protected function allowSave($data, $key = 'id')
 {
     $document = $this->getModel()->getItem(JRequest::getInt('id'));
     // can create new document
     if (!$document->id && JoomDOCAccessDocument::create(JoomDOCRequest::getPath())) {
         return true;
     }
     // can edit exists document
     if ($document->id && JoomDOCAccessDocument::canEdit($document)) {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Upload file or zipe archive.
  *
  * @return void
  */
 public static function upload($redirect = true)
 {
     $mainframe = JFactory::getApplication();
     /* @var $mainframe JApplication */
     $config = JoomDOCConfig::getInstance();
     // folder where upload
     $path = JoomDOCRequest::getPath();
     $folder = JoomDOCFileSystem::getFullPath($path);
     // control if given folder is subfolder of documents root
     if (!JoomDOCFileSystem::isSubFolder($folder, $config->docroot)) {
         JError::raiseError(403, JText::sprintf('JOOMDOC_UNABLE_UPLOAD_FILE'));
     }
     // unpack uploaded file (multiupload)
     $isZip = JRequest::getInt('iszip');
     // count of uploaded files
     $count = 0;
     $data = JRequest::getVar('upload', null, 'files', 'array');
     $modelDocument = JModelLegacy::getInstance(JOOMDOC_DOCUMENT, JOOMDOC_MODEL_PREFIX);
     /* @var $modelDocument JoomDOCModelDocument */
     if ($data) {
         if ($data['error'] != 0) {
             JError::raiseWarning(21, JText::sprintf('JOOMDOC_UNABLE_UPLOAD_FILE', ''));
         } elseif (!JFolder::exists($folder)) {
             JError::raiseWarning(21, JText::sprintf('JOOMDOC_PARENT_FOLDER_NO_EXISTS'), $folder);
         } else {
             if ($isZip && ($tmpFolder = JoomDOCFileSystem::createTemporaryFolder('joomdoc_unpack'))) {
                 $zip = JArchive::getAdapter('zip');
                 /* @var $zip JArchiveZip */
                 if ($zip->extract($data['tmp_name'], $tmpFolder) !== true) {
                     JError::raiseWarning(21, JText::sprintf('JOOMDOC_UNABLE_EXTRACT_FILE', $data['name']));
                 } else {
                     $rfolder = $path ? $path . DIRECTORY_SEPARATOR : '';
                     foreach (JFolder::folders($tmpFolder, '.', true, true) as $zipFolder) {
                         $newfolder = JPath::clean(str_replace($tmpFolder . DIRECTORY_SEPARATOR, $rfolder, $zipFolder));
                         if (!JoomDOCFileSystem::newFolder(JoomDOCFileSystem::getParentPath($newfolder), JFile::getName($newfolder), false, false)) {
                             return false;
                         }
                     }
                     foreach (JFolder::files($tmpFolder, '.', true, true) as $zipFile) {
                         if ($filePath = JoomDOCFileSystem::uploadFile($folder, $zipFile, str_replace($tmpFolder . DIRECTORY_SEPARATOR, '', $zipFile), true, false)) {
                             if ($config->fileDocumentAutomatically && JoomDOCAccessDocument::create($filePath)) {
                                 $modelDocument->setState('document.id', null);
                                 $modelDocument->save(array('path' => $filePath, 'title' => JFile::getName($filePath), 'state' => JOOMDOC_STATE_PUBLISHED));
                             }
                             $count++;
                         }
                     }
                 }
                 JFolder::delete($tmpFolder);
                 JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX)->flat();
             } elseif ($filePath = JoomDOCFileSystem::uploadFile($folder, $data['tmp_name'], $data['name'])) {
                 if ($config->fileDocumentAutomatically && JoomDOCAccessDocument::create($filePath)) {
                     $modelDocument->setState('document.id', null);
                     $modelDocument->save(array('path' => $filePath, 'title' => JFile::getName($filePath), 'state' => JOOMDOC_STATE_PUBLISHED));
                     $document = $modelDocument->getItem();
                 }
                 $count++;
             }
         }
     }
     if ($redirect) {
         $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_FILES_UPLOADED', $count));
         if ($config->fileDocumentAutomatically && $config->editDocumentImmediately && !$isZip && !empty($document) && JoomDOCAccessDocument::edit($document->id)) {
             if ($mainframe->isAdmin()) {
                 $mainframe->redirect(JoomDOCRoute::editDocument($document->id));
             } else {
                 $mainframe->redirect(JoomDOCRoute::edit($document->path, $document->full_alias));
             }
         } else {
             $mainframe->redirect(JoomDOCRoute::viewDocuments($path, false));
         }
     }
 }
Exemplo n.º 3
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);
 }