function testRemotefile404()
 {
     $http_mock = $this->getHttpMock();
     $http_mock->expectOnce('download', array($this->url, $this->tmpfile));
     $http_mock->setReturnValue('download', array('code' => 404, 'body' => false));
     $fproxy = new binarypool_fileobject($this->url, $http_mock);
     $this->assertFalse($fproxy->exists());
     $this->assertEqual($fproxy->isRemote(), true);
 }
Example #2
0
 /**
  * Actually resolves the mime type - called from getMimeType
  * if the file has not been seen before
  */
 private static function resolveMimeType($file)
 {
     $fproxy = new binarypool_fileobject($file);
     if (!$fproxy->exists()) {
         return null;
     }
     $strategies = array('Hardcoded', 'Finfo', 'CmdLineFileCustom', 'CmdLineFile', 'GetImageSize');
     foreach ($strategies as $strategy) {
         $mime = call_user_func('binarypool_mime::getMimeTypeWith' . $strategy, $fproxy->file);
         if (!is_null($mime)) {
             return $mime;
         }
     }
     return null;
 }
Example #3
0
 /**
  * Returns information about a file. Handles URLs as well as local files.
  *
  * @param $file: A file path or URL.
  */
 public static function getFileinfo($file)
 {
     if (isset(self::$fileinfoCache[$file])) {
         return self::$fileinfoCache[$file];
     }
     $mime = null;
     $size = null;
     $sha1 = null;
     $fproxy = new binarypool_fileobject($file);
     if ($fproxy->exists()) {
         $mime = binarypool_mime::getMimeType($fproxy->file);
         $size = intval(filesize($fproxy->file));
         $sha1 = sha1_file($fproxy->file);
     }
     $info = array('mime' => $mime, 'size' => $size, 'hash' => $sha1);
     self::$fileinfoCache[$file] = $info;
     return $info;
 }
Example #4
0
 protected function writeSymlink($target, $link)
 {
     // Remove the HTTP cache
     $url = $this->absolutize($link);
     binarypool_fileobject::forgetCache($url);
     $json = json_encode(array('link' => $target, 'mtime' => $this->time));
     $s3_bucket = $this->cfg['bucket'];
     $this->removeCache($link);
     $this->flushCache($link);
     return $this->client->putObject($json, $s3_bucket, $link, S3::ACL_PUBLIC_READ, array(), 'application/x-symlink');
 }
Example #5
0
 /**
  * Returns the XML representation of a single item.
  *
  * @param $file: Absolute file name on the disk for this item.
  * @param $rendition: Rendition name. null if this is the original.
  */
 private function getItem($file, $rendition)
 {
     $fproxy = new binarypool_fileobject($file);
     if (!$fproxy->exists()) {
         throw new binarypool_exception(102, 404, "Referenced file in asset does not exist: {$file}");
     }
     $fileinfo = binarypool_fileinfo::getFileinfo($file);
     $mime = $fileinfo['mime'];
     $size = $fileinfo['size'];
     $hash = $fileinfo['hash'];
     $type = is_null($this->type) ? binarypool_render::getType($mime) : $this->type;
     $info = binarypool_mime::getImageSize($file, $mime, $type);
     $isRendition = is_null($rendition) ? 'false' : 'true';
     $isLandscape = $info['width'] > $info['height'] ? 'true' : 'false';
     $xml = '<item type="' . $type . '" isRendition="' . $isRendition . '">';
     $xml .= '<webobject isVisual="true" isAudioOnly="false" unit="' . htmlspecialchars($info['unit']) . '">';
     $xml .= '<objectWidth>' . $info['width'] . '</objectWidth>';
     $xml .= '<objectHeight>' . $info['height'] . '</objectHeight>';
     $xml .= '</webobject>';
     $xml .= '<imageinfo isLandscape="' . $isLandscape . '" unit="' . htmlspecialchars($info['unit']) . '">';
     $xml .= '<width>' . $info['width'] . '</width>';
     $xml .= '<height>' . $info['height'] . '</height>';
     $xml .= '</imageinfo>';
     if ($isRendition) {
         $xml .= '<rendition>' . htmlspecialchars($rendition) . '</rendition>';
     }
     if ($this->locationAbsolute) {
         $xml .= '<location absolute="true">' . $file . '</location>';
     } else {
         $xml .= '<location>' . htmlspecialchars($this->basepath . basename($file)) . '</location>';
     }
     $xml .= '<importsource />';
     $xml .= '<mimetype>' . htmlspecialchars($mime) . '</mimetype>';
     $xml .= '<size>' . $size . '</size>';
     $xml .= '<hash>' . htmlspecialchars($hash) . '</hash>';
     $xml .= '</item>';
     return $xml;
 }
 /**
  * Download the asset file and change all rendition locations to absolute
  * values.
  *
  * This is necessary for the transformation stage to make sure that we
  * can request the asset files from the binarypool server but serve
  * them from S3 directly.
  */
 protected function getTransformedIndexFile($file)
 {
     $url = $this->s3->absolutize($file);
     $fproxy = new binarypool_fileobject($url);
     if (!$fproxy->exists()) {
         return null;
     }
     $dom = new DOMDocument();
     $dom->load($fproxy->file);
     $xp = new DOMXPath($dom);
     $locs = $xp->query('/registry/items/item/location');
     foreach ($locs as $loc) {
         if (!$loc->hasAttribute('absolute') || $loc->getAttribute('absolute') !== 'true') {
             if ($this->s3->fileExists($loc->nodeValue)) {
                 $loc->setAttribute('absolute', 'true');
                 $loc->nodeValue = $this->s3->absolutize($loc->nodeValue);
             }
         }
     }
     file_put_contents($fproxy->file, $dom->saveXML());
     return $fproxy->file;
 }