Beispiel #1
0
 public function viewAction()
 {
     // We view a file, so we should disable layout
     $this->_helper->layout->disableLayout();
     $this->_helper->viewRenderer->setNoRender();
     $key = $this->_getParam('key');
     $size = $this->_getParam('size');
     $inline = $this->_getParam('inline');
     if (strpos($key, '.')) {
         $key = substr($key, 0, strpos($key, '.'));
     }
     $files = new Files();
     if (!($file = $files->getFileFromKey($key))) {
         throw new Stuffpress_Exception("No such file for key {$key}");
     }
     if ($size == 'thumbnail') {
         $folder = '/thumbnails/';
     } else {
         if ($size == 'small') {
             $folder = '/small/';
         } else {
             if ($size == 'medium') {
                 $folder = '/medium/';
             } else {
                 if ($size == 'large') {
                     $folder = '/large/';
                 } else {
                     $folder = '/';
                 }
             }
         }
     }
     $root = Zend_Registry::get("root");
     $config = Zend_Registry::get("configuration");
     if (isset($config) && isset($config->path->upload)) {
         $upload = $config->path->upload;
     } else {
         $upload = $root . "/upload/";
     }
     $path = $upload . "/{$folder}{$file->key}";
     if ($folder != '/' && !file_exists($path)) {
         $path = $upload . "/{$file->key}";
     }
     // Dump the file
     if (!$inline) {
         header("Content-Disposition: attachment; filename=\"{$file->name}\"");
     }
     header("Content-type: {$file->type}");
     header('Content-Length: ' . filesize($path));
     /*$this->getResponse()->setHeader('Expires', '', true);
        $this->getResponse()->setHeader('Cache-Control', 'public', true);
      	$this->getResponse()->setHeader('Cache-Control', 'max-age=3800');
        $this->getResponse()->setHeader('Pragma', '', true);*/
     // We turn off output buffering to avoid memory issues
     // when dumping the file
     ob_end_flush();
     readfile($path);
     // Die to make sure that we don't screw up the file
     die;
 }
 public function setcoverAction()
 {
     // Get, check and setup the parameters
     $story_id = $this->getRequest()->getParam("story");
     $source_id = $this->getRequest()->getParam("source");
     $item_id = $this->getRequest()->getParam("item");
     //Verify if the requested story exist
     $stories = new Stories();
     if (!($story = $stories->getStory($story_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Check if we are the owner
     if ($this->_application->user->id != $story->user_id) {
         return $this->_helper->json->sendJson(false);
     }
     //Verify if the requested source exist
     $sources = new Sources();
     if (!($source = $sources->getSource($source_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Check if we are the owner
     if ($this->_application->user->id != $source['user_id']) {
         return $this->_helper->json->sendJson(false);
     }
     //Verify if the requested item exist
     $data = new Data();
     if (!($item = $data->getItem($source_id, $item_id))) {
         return $this->_helper->json->sendJson(false);
     }
     // Do we have a url ?
     if (!($url = $item->getImageUrl(ImageItem::SIZE_MEDIUM))) {
         return $this->_helper->json->sendJson(false);
     }
     // Get the old image and delete it
     $files = new Files();
     if ($file = $files->getFileFromKey($story->thumbnail)) {
         $files->deleteFile($file->key);
     }
     // Ok, we can set the image
     $this->setKeyImage($story_id, $url);
     return $this->_helper->json->sendJson(true);
 }
 public function getAudioUrl($format = 'mp3')
 {
     if ($this->getType() != SourceItem::AUDIO_TYPE) {
         return false;
     }
     // If we have a URL, eturn directly
     if (strlen($this->_data['url']) > 0) {
         return $this->_data['url'];
     }
     // Get the file key
     $key = $this->_data['file'];
     // Get the file
     $files = new Files();
     $file = $files->getFileFromKey($key);
     $name = urlencode($file['name']);
     // Get the root url
     $host = trim(Zend_Registry::get("host"), '/');
     // Return the final URL
     return "http://{$host}/file/view/key/{$key}/{$name}";
 }