/**
  * download file
  * 
  * @param string $path
  */
 public function downloadNode($path)
 {
     try {
         $splittedPath = explode('/', trim($path, '/'));
         $downloadId = array_shift($splittedPath);
         $download = $this->_getDownloadLink($downloadId);
         $this->_setDownloadLinkOwnerAsUser($download);
         $node = Filemanager_Controller_DownloadLink::getInstance()->getNode($download, $splittedPath);
         if ($node->type === Tinebase_Model_Tree_Node::TYPE_FILE) {
             $nodeController = Filemanager_Controller_Node::getInstance();
             $nodeController->resolveMultipleTreeNodesPath($node);
             $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($node->path));
             Filemanager_Controller_DownloadLink::getInstance()->increaseAccessCount($download);
             $this->_downloadFileNode($node, $pathRecord->streamwrapperpath);
         }
     } catch (Exception $e) {
         if (Tinebase_Core::isLogLevel(Zend_Log::CRIT)) {
             Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' exception: ' . $e->getMessage());
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' exception: ' . $e->getTraceAsString());
         }
         header('HTTP/1.0 404 Not found');
         $view = new Zend_View();
         $view->setScriptPath('Filemanager/views');
         header('Content-Type: text/html; charset=utf-8');
         die($view->render('notfound.phtml'));
     }
     exit;
 }
Ejemplo n.º 2
0
 /**
  * parse given path (filter value): check validity, set container type, do replacements
  */
 protected function _parsePath()
 {
     $this->_path = Tinebase_Model_Tree_Node_Path::createFromPath($this->_value);
     if (!$this->_options['ignoreAcl'] && !Tinebase_Core::getUser()->hasRight($this->_path->application->name, Tinebase_Acl_Rights_Abstract::RUN)) {
         throw new Tinebase_Exception_AccessDenied('You don\'t have the right to run this application');
     }
 }
 /**
  * remove app id (base path) from filter
  * 
  * @param array $_result
  * 
  * @todo is this really needed? perhaps we can set the correct path in Tinebase_Model_Tree_Node_PathFilter::toArray
  */
 protected function _removeAppIdFromPathFilter(&$_result)
 {
     $app = Tinebase_Application::getInstance()->getApplicationByName($this->_applicationName);
     foreach ($_result['filter'] as $idx => &$filter) {
         if ($filter['field'] === 'path') {
             if (is_array($filter['value'])) {
                 $filter['value']['path'] = Tinebase_Model_Tree_Node_Path::removeAppIdFromPath($filter['value']['path'], $app);
             } else {
                 $filter['value'] = Tinebase_Model_Tree_Node_Path::removeAppIdFromPath($filter['value'], $app);
             }
         }
     }
 }
 /**
  * download file
  * 
  * @param string $path
  * @param string $id
  * 
  * @todo allow to download a folder as ZIP file
  */
 public function downloadFile($path, $id)
 {
     $nodeController = Filemanager_Controller_Node::getInstance();
     if ($path) {
         $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($path));
         $node = $nodeController->getFileNode($pathRecord);
     } elseif ($id) {
         $node = $nodeController->get($id);
         $nodeController->resolveMultipleTreeNodesPath($node);
         $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($nodeController->addBasePath($node->path));
     } else {
         Tinebase_Exception_InvalidArgument('Either a path or id is needed to download a file.');
     }
     $this->_downloadFileNode($node, $pathRecord->streamwrapperpath);
     exit;
 }
Ejemplo n.º 5
0
 /**
  * download file
  * 
  * @param string $_path
  * 
  * @todo allow to download a folder as ZIP file
  */
 public function downloadFile($path)
 {
     $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(0);
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . ' Download file ' . $path);
     }
     $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath(Filemanager_Controller_Node::getInstance()->addBasePath($path));
     $node = Filemanager_Controller_Node::getInstance()->getFileNode($pathRecord);
     // cache for 3600 seconds
     $maxAge = 3600;
     header('Cache-Control: private, max-age=' . $maxAge);
     header("Expires: " . gmdate('D, d M Y H:i:s', Tinebase_DateTime::now()->addSecond($maxAge)->getTimestamp()) . " GMT");
     // overwrite Pragma header from session
     header("Pragma: cache");
     header('Content-Disposition: attachment; filename="' . $node->name . '"');
     header("Content-Type: " . $node->contenttype);
     $handle = fopen($pathRecord->streamwrapperpath, 'r');
     fpassthru($handle);
     fclose($handle);
     Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
     exit;
 }
 /**
  * delete node
  * 
  * @param string $_flatpath
  * @return boolean
  * @throws Tinebase_Exception_NotFound
  */
 protected function _deleteNode($_flatpath)
 {
     $flatpathWithBasepath = $this->addBasePath($_flatpath);
     list($parentPathRecord, $nodeName) = Tinebase_Model_Tree_Node_Path::getParentAndChild($flatpathWithBasepath);
     $pathRecord = Tinebase_Model_Tree_Node_Path::createFromPath($flatpathWithBasepath);
     $this->_checkPathACL($parentPathRecord, 'delete');
     if (!$parentPathRecord->container) {
         // check acl for deleting toplevel container
         $this->_checkPathACL($pathRecord, 'delete');
     }
     $success = $this->_deleteNodeInBackend($pathRecord);
     if ($success && !$parentPathRecord->container) {
         if (!is_object($pathRecord->container)) {
             throw new Tinebase_Exception_NotFound('Container not found');
         }
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Delete container ' . $pathRecord->container->name);
         }
         Tinebase_Container::getInstance()->delete($pathRecord->container->getId());
     }
     return $success;
 }
 /**
  * get container path
  * 
  * @param Tinebase_Model_Container $container
  * @return string
  */
 public function getContainerPath(Tinebase_Model_Container $container)
 {
     $treeNodePath = new Tinebase_Model_Tree_Node_Path(array('application' => Tinebase_Application::getInstance()->getApplicationById($container->application_id)));
     $treeNodePath->setContainer($container);
     return $treeNodePath->statpath;
 }
 /**
  * testSetContainerInPathRecord
  * 
  * @todo move this to Tinebase?
  */
 public function testSetContainerInPathRecord()
 {
     $flatpath = Filemanager_Controller_Node::getInstance()->addBasePath('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/' . $this->_getPersonalFilemanagerContainer()->name);
     $path = Tinebase_Model_Tree_Node_Path::createFromPath($flatpath);
     $path->setContainer($this->_getSharedContainer());
     $this->assertEquals('/' . $this->_application->getId() . '/folders/shared/' . $this->_getSharedContainer()->getId(), $path->statpath);
     // move it back
     $path->setContainer($this->_getPersonalFilemanagerContainer());
     $this->assertEquals('/' . $this->_application->getId() . '/folders/personal/' . Tinebase_Core::getUser()->getId() . '/' . $this->_getPersonalFilemanagerContainer()->getId(), $path->statpath, 'wrong statpath: ' . print_r($path->toArray(), TRUE));
 }
 /**
  * move folder container
  *
  * @param Tinebase_Model_Tree_Node_Path $source
  * @param Tinebase_Model_Tree_Node_Path $destination
  * @param boolean $forceOverwrite
  * @return Tinebase_Model_Tree_Node
  */
 protected function _moveFolderContainer($source, $destination, $forceOverwrite = FALSE)
 {
     if ($source->isToplevelPath()) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Moving container ' . $source->container->name . ' to ' . $destination->flatpath);
         }
         $this->_checkACLContainer($source->container, 'update');
         $backend = $this->getAdapterBackend($destination->statpath);
         $container = $source->container;
         if ($container->name !== $destination->name) {
             try {
                 $existingContainer = Tinebase_Container::getInstance()->getContainerByName($this->_applicationName, $destination->name, $destination->containerType, Tinebase_Core::getUser());
                 if (!$forceOverwrite) {
                     $fene = new Expressodriver_Exception_NodeExists('container exists');
                     $fene->addExistingNodeInfo($backend->stat($destination->statpath));
                     throw $fene;
                 } else {
                     if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                         Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Removing existing folder node and container ' . $destination->flatpath);
                     }
                     $backend->rmdir($destination->statpath, TRUE);
                 }
             } catch (Tinebase_Exception_NotFound $tenf) {
                 // ok
             }
             $container->name = $destination->name;
             $container = Tinebase_Container::getInstance()->update($container);
         }
     } else {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Creating container ' . $destination->name);
         }
         $container = $this->_createContainer($destination->name, $destination->containerType);
     }
     $destination->setContainer($container);
 }