/** * Check the item in the collection should be filtered out * If return is false, the item will be discarded at 100% * If return is true, isn't sure that the item will be added * 'cause another plugin can prevent this * * Plugins who check per-item acl or blacklist should hook here * * @param X_Page_Item_PItem $item * @param string $provider * @param Zend_Controller_Action $controller * @return boolean true if item is ok, false if item should be discarded */ public function filterShareItems(X_Page_Item_PItem $item, $provider, Zend_Controller_Action $controller) { $providerClass = X_VlcShares_Plugins::broker()->getPluginClass($provider); $providerObj = X_VlcShares_Plugins::broker()->getPlugins($provider); if (is_a($providerObj, 'X_VlcShares_Plugins_FileSystem')) { if ($item->getType() == X_Page_Item_PItem::TYPE_ELEMENT) { $itemLocation = $item->getCustom('X_VlcShares_Plugins_FileSystem:location'); /* @var $urlHelper Zend_Controller_Action_Helper_Url */ $urlHelper = $controller->getHelper('url'); $path = $providerObj->resolveLocation($itemLocation); $thumb = new Application_Model_FsThumb(); Application_Model_FsThumbsMapper::i()->fetchByPath($path, $thumb); if ($thumb->isNew()) { $thumbUrl = X_Env::completeUrl($urlHelper->direct('thumb', 'fsthumbs', 'default', array('l' => X_Env::encode($itemLocation), 't' => 'dummy.jpg'))); } else { $thumbUrl = X_Env::completeUrl(Zend_Controller_Front::getInstance()->getBaseUrl() . $thumb->getUrl()); } //$item->setDescription($itemLocation); $item->setThumbnail($thumbUrl); } } return true; }
function thumbAction() { // time to get params from get /* @var $request Zend_Controller_Request_Http */ $request = $this->getRequest(); if (!is_writable(APPLICATION_PATH . "/../public/images/fsthumbs/thumbs/")) { throw new Exception('"/public/images/fsthumbs/thumbs/" must be writable'); } $l = $request->getParam('l', false); if ($l == false) { throw new Exception(X_Env::_('p_fsthumbs_invalidlocation')); } $ldec = X_Env::decode($l); $itemRealPath = $this->fsPlugin->resolveLocation($ldec); if ($itemRealPath == false) { throw new Exception(X_Env::_('p_fsthumbs_invalidlocation')); } // cache check and redirect if possible $imagePath = "/images/fsthumbs/thumbs/{$l}.jpg"; // else thumb creation and then redirect if (!file_exists(APPLICATION_PATH . "/../public{$imagePath}")) { if (X_VlcShares_Plugins::helpers()->ffmpeg()->isEnabled()) { // create the thumb $ffmpegPath = $this->options->helpers->ffmpeg->path; $destPath = APPLICATION_PATH . "/../public{$imagePath}"; $secOffset = intval($this->plugin->config('capture.seconds', '2')) + (int) rand(0, 10) - 5; if ($secOffset < 1) { $secOffset = 1; } $imageDim = $this->plugin->config('thumbs.size', '320x240'); if (!preg_match('/(\\d{3})x(\\d{3})/', $imageDim)) { X_Debug::e("Thumb size is not a valid value (IIIxIII): {$imageDim}"); $imageDim = '320x240'; } // thumb creation should be always completed ignore_user_abort(true); // semaphore is needed for folders with lots files and low-end cpus $lockFile = fopen(__FILE__, 'r+'); flock($lockFile, LOCK_EX); $exec = "{$ffmpegPath} -itsoffset -{$secOffset} -i \"{$itemRealPath}\" -vcodec mjpeg -vframes 1 -an -f rawvideo -s {$imageDim} \"{$destPath}\""; $return = X_Env::execute($exec); // remove lock flock($lockFile, LOCK_UN); fclose($lockFile); $filesize = @filesize($destPath); if ($filesize == 0) { // it's better to replace the thumbs created with // a placeholder file to prevent a new creation @copy(APPLICATION_PATH . "/../public/images/fsthumbs/nothumbs.jpg", $destPath); clearstatcache(true, $destPath); $filesize = @filesize($destPath); } $thumb = new Application_Model_FsThumb(); // try to load an old entry in db, this prevent error when files are removed but not the reference in db Application_Model_FsThumbsMapper::i()->fetchByPath($itemRealPath, $thumb); $thumb->setCreated(time())->setPath($itemRealPath)->setUrl($imagePath)->setSize(@filesize($destPath)); try { Application_Model_FsThumbsMapper::i()->save($thumb); X_Debug::i('Thumb stored'); } catch (Exception $e) { X_Debug::e("Error while storing thumb data: {$e->getMessage()}"); } //X_Debug::i(var_export($return, true)); // -itsoffset -30 -i test.avi -vcodec mjpeg -vframes 1 -an -f rawvideo -s 320x240 test.jpg } else { $imagePath = "/images/fsthumbs/nothumbs.jpg"; } } // if it is wiimc i have to return here the image directly, not a redirect if (X_VlcShares_Plugins::helpers()->devices()->isWiimc()) { $this->getResponse()->clearAllHeaders(); ob_end_clean(); $this->getResponse()->setHeader('Content-Type', 'image/jpeg')->setHeader('Content-Length', @filesize(APPLICATION_PATH . "/../public{$imagePath}")); $this->getResponse()->sendHeaders(); readfile(APPLICATION_PATH . "/../public{$imagePath}"); } else { $this->_helper->redirector->gotoUrlAndExit($imagePath, array('prependBase' => true, 'code' => 302)); } }