Ejemplo n.º 1
0
 /**
  * Returns a path to the specified item, resized and/or cropped to meet max width and height. $obj can either be
  * a string (path) or a file object.
  * Returns an object with the following properties: src, width, height
  *
  * @param File|string $obj
  * @param int $maxWidth
  * @param int $maxHeight
  * @param bool $crop
  * @return \stdClass Object that has the following properties: src, width, height
  */
 public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false)
 {
     $storage = $this->getStorageLocation();
     $filesystem = $storage->getFileSystemObject();
     $configuration = $storage->getConfigurationObject();
     $fh = \Core::make('helper/file');
     if ($obj instanceof File) {
         try {
             $fr = $obj->getFileResource();
             $fID = $obj->getFileID();
             $filename = md5(implode(':', array($fID, $maxWidth, $maxHeight, $crop, $fr->getTimestamp()))) . '.' . $fh->getExtension($fr->getPath());
         } catch (\Exception $e) {
             $filename = '';
         }
     } else {
         $filename = md5(implode(':', array($obj, $maxWidth, $maxHeight, $crop, filemtime($obj)))) . '.' . $fh->getExtension($obj);
     }
     $abspath = '/cache/' . $filename;
     if (!$filesystem->has($abspath)) {
         if ($obj instanceof File && $fr->exists()) {
             $image = \Image::load($fr->read());
         } else {
             $image = \Image::open($obj);
         }
         // create image there
         $this->create($image, $abspath, $maxWidth, $maxHeight, $crop);
     }
     $src = $configuration->getPublicURLToFile($abspath);
     $thumb = new \stdClass();
     $thumb->src = $src;
     // this is a hack, but we shouldn't go out on the network if we don't have to. We should probably
     // add a method to the configuration to handle this. The file storage locations should be able to handle
     // thumbnails.
     if ($configuration instanceof DefaultConfiguration) {
         $dimensionsPath = $configuration->getRootPath() . $abspath;
     } else {
         $dimensionsPath = $src;
     }
     try {
         //try and get it locally, otherwise use http
         $dimensions = getimagesize($dimensionsPath);
         $thumb->width = $dimensions[0];
         $thumb->height = $dimensions[1];
     } catch (\Exception $e) {
     }
     return $thumb;
 }
Ejemplo n.º 2
0
 /**
  * Returns a path to the specified item, resized and/or cropped to meet max width and height. $obj can either be
  * a string (path) or a file object.
  * Returns an object with the following properties: src, width, height
  *
  * @param File|string $obj
  * @param int $maxWidth
  * @param int $maxHeight
  * @param bool $crop
  * @return \stdClass Object that has the following properties: src, width, height
  */
 public function getThumbnail($obj, $maxWidth, $maxHeight, $crop = false)
 {
     $storage = $this->getStorageLocation();
     $filesystem = $storage->getFileSystemObject();
     $configuration = $storage->getConfigurationObject();
     $fh = \Core::make('helper/file');
     if ($obj instanceof File) {
         try {
             $fr = $obj->getFileResource();
             $fID = $obj->getFileID();
             $filename = md5(implode(':', array($fID, $maxWidth, $maxHeight, $crop, $fr->getTimestamp()))) . '.' . $fh->getExtension($fr->getPath());
         } catch (\Exception $e) {
             $filename = '';
         }
     } else {
         $filename = md5(implode(':', array($obj, $maxWidth, $maxHeight, $crop, filemtime($obj)))) . '.' . $fh->getExtension($obj);
     }
     $abspath = '/cache/' . $filename;
     if (!$filesystem->has($abspath)) {
         if ($obj instanceof File && $fr->exists()) {
             $image = \Image::load($fr->read());
         } else {
             $image = \Image::open($obj);
         }
         // create image there
         $this->create($image, $abspath, $maxWidth, $maxHeight, $crop);
     }
     $src = $configuration->getPublicURLToFile($abspath);
     $thumb = new \stdClass();
     $thumb->src = $src;
     //this is terrible
     try {
         //try and get it locally, otherwise use http
         $dimensions = getimagesize($abspath);
     } catch (\Exception $e) {
         //$dimensions = getimagesize($src);
     }
     $thumb->width = $dimensions[0];
     $thumb->height = $dimensions[1];
     return $thumb;
 }
Ejemplo n.º 3
0
 /**
  * Add attachment to send with an email.
  *
  * Sample Code:
  * $attachment = $mailHelper->addAttachment($fileObject);
  * $attachment->filename = "CustomFilename";
  * $mailHelper->send();
  *
  * @param \Concrete\Core\Entity\File\File $fob File to attach
  *
  * @return \StdClass Pointer to the attachment
  *
  * @throws \Exception
  */
 public function addAttachment(\Concrete\Core\Entity\File\File $fob)
 {
     // Get file version.
     $fv = $fob->getVersion();
     // Get file data.
     $mimetype = $fv->getMimeType();
     $filename = $fv->getFilename();
     $resource = $fob->getFileResource();
     $content = $resource->read();
     // Create attachment.
     $mp = new MimePart($content);
     $mp->type = $mimetype;
     $mp->disposition = Mime::DISPOSITION_ATTACHMENT;
     $mp->encoding = Mime::ENCODING_BASE64;
     $mp->filename = $filename;
     // Add mimepart to attachments.
     $this->attachments[] = $mp;
 }