public function testGetFeedOnItemWithFile() { $filename = 'test.jpg'; $mimeType = 'image/jpeg'; $size = '1024'; // Dispatching seems to be required to get the view scripts loaded $this->dispatch('items/browse'); $item = new Item(); $item->id = 100; // Some sneaky stuff here to trick ItemAtom into seeing a file for // an item without saving them. $file = new File(); $file->id = 100; $file->filename = $filename; $file->mime_type = $mimeType; $file->size = $size; $item->Files = array($file); $atom = new Output_ItemAtom(array($item)); $feed = $atom->getFeed(); $dom = new Zend_Dom_Query($feed); $this->_assertAtomFeed($dom); $href = $file->getWebPath('original'); $queryResult = $dom->queryXpath("/atom:feed/atom:entry/atom:link[@rel='enclosure' and @type='{$mimeType}' and @length='{$size}' and @href='{$href}']"); $this->assertCount(1, $queryResult, 'The feed did not contain a correct file enclosure.'); }
/** * Get the provided file's URL. * * @package Omeka\Function\View\Navigation * @uses File::getWebPath() * @param File $file * @param string $format * @return string */ function file_display_url(File $file, $format = 'fullsize') { if (!$file->exists()) { return false; } return $file->getWebPath($format); }
/** * Default display of audio files via <object> tags. * * @param File $file * @param array $options The set of default options for this includes: * width, height, autoplay, controller, loop * @param string $type The Internet media type of the file * @return string */ private function _audio($file, array $options, $type) { $path = html_escape($file->getWebPath('original')); $html = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="' . $options['width'] . '" height="' . $options['height'] . '">' . '<param name="src" value="' . $path . '" />' . '<param name="controller" value="' . ($options['controller'] ? 'true' : 'false') . '" />' . '<param name="autoplay" value="' . ($options['autoplay'] ? 'true' : 'false') . '" />' . '<param name="loop" value="' . ($options['loop'] ? 'true' : 'false') . '" />' . '<object type="' . $type . '" data="' . $path . '" width="' . $options['width'] . '" height="' . $options['height'] . '" autoplay="' . ($options['autoplay'] ? 'true' : 'false') . '">' . '<param name="src" value="' . $path . '" />' . '<param name="controller" value="' . ($options['controller'] ? 'true' : 'false') . '" />' . '<param name="autoplay" value="' . ($options['autoplay'] ? 'true' : 'false') . '" />' . '<param name="autostart" value="' . ($options['autoplay'] ? '1' : '0') . '" />' . '<param name="loop" value="' . ($options['loop'] ? 'true' : 'false') . '" />' . '</object>' . '</object>'; return $html; }
/** * Get the path to an original or derivative file for an image. * * @param File $file * @param string $derivativeType * @return string|null Null if not exists. * @see UniversalViewer_View_Helper_IiifInfo::_getImagePath() */ protected function _getImagePath($file, $derivativeType = 'original') { // Check if the file is an image. if (strpos($file->mime_type, 'image/') === 0) { // Don't use the webpath to avoid the transfer through server. $filepath = FILES_DIR . DIRECTORY_SEPARATOR . $file->getStoragePath($derivativeType); if (file_exists($filepath)) { return $filepath; } else { $filepath = $file->getWebPath($derivativeType); return $filepath; } } }
/** * Retrieve valid XHTML for displaying a wma audio file or equivalent. * Currently this loads the video inside of an <object> tag, but that * provides less flexibility than a flash wrapper, which seems to be a * standard Web2.0 practice for video sharing. This limitation can be * overcome by a plugin that used a flash wrapper for displaying video. * * @param File $file * @param array $options * @return string */ public function wma($file, array $options = array()) { $path = html_escape($file->getWebPath('original')); $html = '<object type="audio/x-ms-wma" width="' . $options['width'] . '" height="' . $options['height'] . '" data="' . $path . '" autoStart="' . $options['autostart'] . '">' . '<param name="FileName" value="' . $path . '" />' . '<param name="autoStart" value="' . ($options['autostart'] ? 'true' : 'false') . '" />' . '<param name="ShowControls" value="' . ($options['ShowControls'] ? 'true' : 'false') . '" />' . '<param name="ShowStatusBar" value="' . ($options['ShowStatusBar'] ? 'true' : 'false') . '" />' . '<param name="ShowDisplay" value="' . ($options['ShowDisplay'] ? 'true' : 'false') . '" />' . '</object>'; return $html; }
/** * Get an array of the width and height of the image file. * * @internal The process uses the saved constraints. It they are changed but * the derivative haven't been rebuilt, the return will be wrong (but * generally without consequences for BookReader). * * @param File $file * @param string $imageType * @return array Associative array of width and height of the image file. * If the file is not an image, the width and the height will be null. * @see UniversalViewer_View_Helper_IiifManifest::_getImageSize() */ protected function _getImageSize($file, $imageType = 'original') { static $sizeConstraints = array(); if (!isset($sizeConstraints[$imageType])) { $sizeConstraints[$imageType] = get_option($imageType . '_constraint'); } $sizeConstraint = $sizeConstraints[$imageType]; // Check if this is an image. if (empty($file) || strpos($file->mime_type, 'image/') !== 0) { $width = null; $height = null; } else { $metadata = json_decode($file->metadata, true); if (empty($metadata['video']['resolution_x']) || empty($metadata['video']['resolution_y'])) { $msg = __('The image #%d ("%s") is not stored correctly.', $file->id, $file->original_filename); _log($msg, Zend_Log::NOTICE); if (isset($metadata['video']['resolution_x']) || isset($metadata['video']['resolution_y'])) { throw new Exception($msg); } // Get the resolution directly. // The storage adapter should be checked for external storage. $storageAdapter = $file->getStorage()->getAdapter(); $filepath = get_class($storageAdapter) == 'Omeka_Storage_Adapter_Filesystem' ? FILES_DIR . DIRECTORY_SEPARATOR . $file->getStoragePath($imageType) : $file->getWebPath($imageType); list($width, $height, $type, $attr) = getimagesize($filepath); if (empty($width) || empty($height)) { throw new Exception($msg); } } else { $sourceWidth = $metadata['video']['resolution_x']; $sourceHeight = $metadata['video']['resolution_y']; // Use the original size when possible. if ($imageType == 'original') { $width = $sourceWidth; $height = $sourceHeight; } else { // Source is landscape. if ($sourceWidth > $sourceHeight) { $width = $sizeConstraint; $height = round($sourceHeight * $sizeConstraint / $sourceWidth); } elseif ($sourceWidth < $sourceHeight) { $width = round($sourceWidth * $sizeConstraint / $sourceHeight); $height = $sizeConstraint; } else { $width = $sizeConstraint; $height = $sizeConstraint; } } } } return array('width' => $width, 'height' => $height); }
/** * add_file_display_callback() callback for Google Docs. * * @see Scripto_IndexController::init() * @param File $file */ public static function googleDocs($file) { $uri = Zend_Uri::factory('http://docs.google.com/viewer'); $uri->setQuery(array('url' => $file->getWebPath(get_option('scripto_file_source')), 'embedded' => 'true')); echo vsprintf('<iframe src="%s" id="scripto-iframe" class="%s"></iframe>', array($uri->getUri(), get_option('scripto_iframe_class'))); }
/** * add_file_display_callback() callback for Google Docs. * * @see Scripto_IndexController::init() * @param File $file */ public static function googleDocs($file) { $uri = Zend_Uri::factory('http://docs.google.com/viewer'); $uri->setQuery(array('url' => $file->getWebPath('original'), 'embedded' => 'true')); echo '<iframe src="' . $uri->getUri() . '" width="500" height="600" style="border: none;"></iframe>'; }