Beispiel #1
0
 public static function render($source, $target, $assetFile, $config)
 {
     $finfo = binarypool_fileinfo::getFileinfo($source);
     if ($finfo['mime'] === 'application/pdf') {
         return binarypool_render_pdf::render($source, $target, $assetFile, $config);
     } else {
         return binarypool_render_eps::render($source, $target, $assetFile, $config);
     }
 }
Beispiel #2
0
 public function save($local_file, $remote_file)
 {
     $url = $this->absolutize($remote_file);
     // Cache the fileinfo
     binarypool_fileinfo::setCache($url, binarypool_fileinfo::getFileinfo($local_file));
     $this->removeCache($remote_file);
     $this->flushCache($remote_file);
     $retval = $this->client->putObjectFile($local_file, $this->cfg['bucket'], $remote_file, S3::ACL_PUBLIC_READ, array(), binarypool_mime::getMimeType($local_file));
     if ($retval === false) {
         throw new binarypool_exception(105, 500, "Could not copy file to its final destination on S3: {$remote_file}");
     }
     return $retval;
 }
Beispiel #3
0
 /**
  * Resize an image file into an output file.
  *
  * Config must provide the following keys:
  * - width: Maximum width of the output image.
  * - height: Maximum height of the output image.
  */
 public static function render($source, $target, $assetFile, $config)
 {
     $info = binarypool_fileinfo::getFileinfo($source);
     $mime = $info['mime'];
     $target = self::getTargetFile($source, $mime, $target);
     if (!self::needsConversion($mime, $config, $source)) {
         $log = new api_log();
         $log->debug("Using original file for {$target}");
         copy($source, $target);
     } else {
         $maxWidth = $config['width'];
         $maxHeight = $config['height'];
         self::convert($source, $target, $mime, $maxWidth, $maxHeight);
     }
     return $target;
 }
Beispiel #4
0
 /**
  * Load asset file into memory.
  *
  * @param $file: Filename to load data from.
  */
 private function load($file)
 {
     // Load document into RAM, do checks
     $dom = new DOMDocument();
     if (!$dom->loadXML($this->storage->getFile($file))) {
         throw new binarypool_exception(113, 500, "Invalid asset file: {$file}");
     }
     $xp = new DOMXPath($dom);
     if ($this->getXPathValue($xp, '/registry/@version') != '3.0') {
         throw new binarypool_exception(113, 500, "Invalid asset file: {$file}");
     }
     // Get asset properties
     $this->created = intval($this->getXPathValue($xp, '/registry/created'));
     $this->expiry = intval($this->getXPathValue($xp, '/registry/expiry'));
     // Get callbacks
     $this->callbacks = array();
     $res = $xp->query('/registry/callback');
     foreach ($res as $item) {
         $this->addCallback($item->nodeValue);
     }
     // Get base path
     $assetDirectory = dirname($file);
     $this->basepath = $this->getXPathValue($xp, '/registry/basepath');
     if (!$this->basepath) {
         $path = $this->getXPathValue($xp, '/registry/items/item/location');
         $this->basepath = substr($path, 0, strrpos($path, '/') + 1);
     }
     // Load renditions & original
     $this->renditions = array();
     $nodes = $xp->query('/registry/items/item');
     foreach ($nodes as $node) {
         $isOriginal = $node->getAttribute('isRendition') == 'false';
         $renditionName = $xp->query('rendition', $node)->item(0)->nodeValue;
         $renditionLocationNode = $xp->query('location', $node)->item(0);
         $this->locationAbsolute = $renditionLocationNode->getAttribute('absolute') == 'true';
         $renditionLocation = $renditionLocationNode->nodeValue;
         if (!$this->locationAbsolute) {
             $renditionLocation = substr($renditionLocation, strrpos($renditionLocation, '/'));
             $renditionLocation = $assetDirectory . $renditionLocation;
             $renditionLocationAbs = $this->storage->absolutize($renditionLocation);
         } else {
             $renditionLocationAbs = $renditionLocation;
         }
         $hashNodes = $xp->query('hash', $node);
         $hash = '';
         if ($hashNodes->length == 0) {
             $fileinfo = binarypool_fileinfo::getFileinfo($renditionLocationAbs);
             $hash = $fileinfo['hash'];
         } else {
             $hash = $hashNodes->item(0)->nodeValue;
         }
         $fileinfo = array('mime' => $xp->query('mimetype', $node)->item(0)->nodeValue, 'size' => intval($xp->query('size', $node)->item(0)->nodeValue), 'hash' => $hash);
         binarypool_fileinfo::setCache($renditionLocationAbs, $fileinfo);
         if ($isOriginal) {
             $this->setOriginal($renditionLocationAbs);
             $this->type = $node->getAttribute('type');
         } else {
             $this->setRendition($renditionName, $renditionLocationAbs);
         }
     }
 }