/**
  * the singleton pattern
  *
  * @return Filemanager_Controller_Node
  */
 public static function getInstance()
 {
     if (self::$_instance === NULL) {
         self::$_instance = new Filemanager_Controller_Node();
     }
     return self::$_instance;
 }
 /**
  * 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;
 }
 /**
  * testGetFileList
  */
 public function testGetFileList()
 {
     $downloadLink = $this->testCreateDownloadLink();
     $basePath = '/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/' . Tinebase_Container::getInstance()->getDefaultContainer('Filemanager_Model_Node')->name;
     $directories = array($basePath . '/one', $basePath . '/two');
     Filemanager_Controller_Node::getInstance()->createNodes($directories, Tinebase_Model_Tree_Node::TYPE_FOLDER);
     $fileList = $this->_getUit()->getFileList($downloadLink, array());
     $this->assertGreaterThan(1, count($fileList));
     $this->assertNotNull($fileList->filter('name', 'one')->getFirstRecord());
 }
 /**
  * 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;
 }
Exemplo 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;
 }
 /**
  * save node
  * save node here in json fe just updates meta info (name, description, relations, customfields, tags, notes),
  * if record already exists (after it had been uploaded)
  * @param array with record data 
  * @return array
  */
 public function saveNode($recordData)
 {
     if (isset($recordData['created_by']) || array_key_exists('created_by', $recordData)) {
         return $this->_save($recordData, Filemanager_Controller_Node::getInstance(), 'Node');
     } else {
         // on upload complete
         return $recordData;
     }
 }
 /**
  * resolve root tree node
  *
  * @param  Filemanager_Model_DownloadLink $download
  * @return Tinebase_Model_Tree_Node
  */
 protected function _getRootNode(Filemanager_Model_DownloadLink $download)
 {
     // ACL is checked here, download link user should be already set by frontend
     $node = Filemanager_Controller_Node::getInstance()->get($download->node_id);
     return $node;
 }
 /**
  * setup the test paths
  * 
  * @param string|array $_types
  */
 protected function _setupTestPath($_types)
 {
     $testPaths = array();
     $types = (array) $_types;
     foreach ($types as $type) {
         switch ($type) {
             case Tinebase_Model_Container::TYPE_PERSONAL:
                 $testPaths[] = Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->getId() . '/' . $this->_getPersonalFilemanagerContainer()->getId() . '/unittestdir_personal';
                 break;
             case Tinebase_Model_Container::TYPE_SHARED:
                 $testPaths[] = Tinebase_Model_Container::TYPE_SHARED . '/' . $this->_getSharedContainer()->getId();
                 $testPaths[] = Tinebase_Model_Container::TYPE_SHARED . '/' . $this->_getSharedContainer()->getId() . '/unittestdir_shared';
                 break;
             case Tinebase_Model_Container::TYPE_OTHERUSERS:
                 $personas = Zend_Registry::get('personas');
                 $testPaths[] = Tinebase_Model_Container::TYPE_PERSONAL . '/' . $personas['sclever']->getId() . '/' . $this->_getOtherUserContainer()->getId() . '/unittestdir_other';
                 break;
         }
     }
     foreach ($testPaths as $path) {
         $path = Filemanager_Controller_Node::getInstance()->addBasePath($path);
         $this->_objects['paths'][] = $path;
         $this->_fsController->mkdir($path);
     }
 }
Exemplo n.º 9
0
 /**
  * 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->_personalContainer->name);
     $path = Tinebase_Model_Tree_Node_Path::createFromPath($flatpath);
     $path->setContainer($this->_sharedContainer);
     $this->assertEquals('/' . $this->_application->getId() . '/folders/shared/' . $this->_sharedContainer->getId(), $path->statpath);
     // move it back
     $path->setContainer($this->_personalContainer);
     $this->assertEquals('/' . $this->_application->getId() . '/folders/personal/' . Tinebase_Core::getUser()->getId() . '/' . $this->_personalContainer->getId(), $path->statpath, 'wrong statpath: ' . print_r($path->toArray(), TRUE));
 }
Exemplo n.º 10
0
 /**
  * delete node(s)
  * 
  * @param string|array $filenames string->single file, array->multiple
  * @return array
  */
 public function deleteNodes($filenames)
 {
     Filemanager_Controller_Node::getInstance()->deleteNodes((array) $filenames);
     return array('status' => 'success');
 }