/**
  * Delete document's (move to trash).
  * Method expected array cid in request with document's id's.
  * On end redirect to document's list view.
  *
  * @return void
  */
 public function delete()
 {
     //parent::delete(); why it was here?
     JRequest::checkToken() or die(JText::_('JINVALID_TOKEN'));
     $mainframe = JFactory::getApplication();
     /* @var $mainframe JAdministrator */
     $cid = JRequest::getVar('cid', array(), '', 'array');
     if (!is_array($cid) || !count($cid)) {
         JError::raiseWarning(500, JText::_('COM_JOOMDOC_ERROR_NO_ITEMS_SELECTED'));
     } else {
         $model = $this->getModel();
         /* @var $model JoomDOCModelDocument */
         JArrayHelper::toInteger($cid);
         foreach ($cid as $id) {
             JoomDOCAccessDocument::delete($id) ? $canDelete[] = $id : ($cannotDelete[] = $id);
         }
         if (isset($cannotDelete)) {
             $mainframe->enqueueMessage(JText::sprintf('JOOMDOC_UNABLE_DELETE_DOCUMENTS', implode(',', $cannotDelete)), 'error');
         }
         if (isset($canDelete)) {
             $mainframe->enqueueMessage(JText::sprintf('COM_JOOMDOC_N_ITEMS_DELETED', $model->trash($canDelete)));
         }
     }
     $this->setRedirect(JoomDOCRoute::viewDocuments());
 }
 /**
  * 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;
 }
Beispiel #3
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));
         }
     }
 }
Beispiel #4
0
 $i = 0;
 while ($this->root->hasNext()) {
     // previous item
     $prevItemDocid = JoomDOCHelper::getDocumentID($this->root->getNext(JOOMDOC_ORDER_PREV));
     // next item
     $nextItemDocid = JoomDOCHelper::getDocumentID($this->root->getNext(JOOMDOC_ORDER_NEXT));
     // current item
     $item = $this->root->getNext();
     //var_dump($item);
     // access rules
     $access = new JoomDOCAccessHelper($item);
     // save files/folders names for next using
     $access->isFile ? $files[] = $access->name : ($folders[] = $access->name);
     echo '<div class="object" style="float: left; width: 140px; height: 110px; margin-right: 10px;">';
     if ($access->docid && $access->isChecked) {
         echo JHtml::_('jgrid.checkedout', $i, $item->document->editor, $item->document->checked_out_time, 'documents.', JoomDOCAccessDocument::manage($item->document->checked_out) && JoomDOCAccess::manage());
     }
     if (!$access->isTrashed) {
         echo '<input type="checkbox" name="paths[]" id="cbb' . $i . '" value="' . $this->escape($access->relativePath) . '" class="blind" />';
     }
     if (!$access->isChecked && !$access->isLocked && !$access->isTrashed) {
         echo '<input type="checkbox" name="cid[]" id="cb' . $i . '" value="' . $access->docid . '" onclick="Joomla.isChecked(this.checked);JoomDOC.check(this,' . $i . ')" />';
     }
     /*if ($access->canRename && !$access->isTrashed) {
           echo '<a href="javascript:void(0)" class="rename hasTip" id="openRename' . $i . '" onclick="JoomDOC.openRename(' . $i . ')" title="' . $this->getTooltip($access->relativePath, 'JOOMDOC_RENAME') . '"></a>';
       }*/
     echo '<script type="text/javascript">
     		
     		 $$(".dblc").addEvent("click", function() { return false;}).addEvent("dblclick", function() { 
     			window.location = this.href;
                 return false;})
Beispiel #5
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);
 }
Beispiel #6
0
 /**
  * Access view documents versions.
  *
  * @param int $docid document ID
  * @return boolean
  */
 public static function viewVersions($docid = null)
 {
     return JoomDOCAccessDocument::authorise(JOOMDOC_CORE_VIEW_VERSIONS, $docid, null);
 }
Beispiel #7
0
 /**
  * Set document state by file path.
  *
  * @param string $path file path
  * @param int $value new state value
  * @return boolean
  */
 public function setPublish($path, $value)
 {
     if ($candidate = $this->searchRelativePathByFullAlias($path)) {
         $path = $candidate;
     }
     if (($id = $this->searchIdByPath($path)) && JoomDOCAccessDocument::editState($id, $this->searchCheckedOutByPath($path))) {
         $this->_db->setQuery('UPDATE `#__joomdoc` SET `state` = ' . $value . ' WHERE `id` = ' . $id);
         $success = $this->_db->query();
         JModelLegacy::getInstance(JOOMDOC_DOCUMENTS, JOOMDOC_MODEL_PREFIX)->flat($path);
         return $success;
     }
     return false;
 }