Пример #1
0
 /**
  * Add attachment to send with an email.
  *
  * Sample Code:
  * $attachment = $mailHelper->addAttachment($fileObject);
  * $attachment->filename = "CustomFilename";
  * $mailHelper->send();
  *
  * @param \Concrete\Core\File\File $fob File to attach
  *
  * @return \StdClass Pointer to the attachment
  *
  * @throws \Exception
  */
 public function addAttachment(\Concrete\Core\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;
 }
Пример #2
0
 protected function download(\Concrete\Core\File\File $file, $rcID = null)
 {
     $filename = $file->getFilename();
     $file->trackDownload($rcID);
     $fsl = $file->getFileStorageLocationObject();
     $configuration = $fsl->getConfigurationObject();
     $fv = $file->getVersion();
     if ($configuration->hasPublicURL()) {
         return \Redirect::url($fv->getURL())->send();
     } else {
         return $fv->forceDownload();
     }
 }
Пример #3
0
 /**
  * Add attachment to send with an email.
  *
  * Sample Code:
  * $attachment = $mailHelper->addAttachment($fileObject);
  * $attachment->filename = "CustomFilename";
  * $mailHelper->send();
  *
  * @param File $fob File to attach
  * @return StdClass Pointer to the attachment
  */
 public function addAttachment(\Concrete\Core\File\File $fob)
 {
     // @TODO make this work with the File Storage Locations
     $fv = $fob->getVersion();
     $path = $fob->getPath();
     $name = $fv->getFileName();
     $type = false;
     if (!function_exists('mime_content_type')) {
         function mime_content_type($path)
         {
             return false;
         }
     }
     $type = @mime_content_type($path);
     // This is deprecated. Should be stable until php5.6
     if (!$type) {
         $mt = Loader::helper('mime');
         $ext = preg_replace('/^.+\\.([^\\.]+)$/', '\\1', $path);
         $type = $mt->mimeFromExtension($ext);
     }
     $contents = @file_get_contents($path);
     if (!$contents) {
         throw new Exception(t('Unable to get the file contents for attachment.'));
     }
     $file = new StdClass();
     $file->object = $fob;
     $file->type = $type;
     $file->path = $path;
     $file->filename = $name;
     $file->contents = $contents;
     unset($contents);
     $this->attachments[] = $file;
     return $file;
     // Returns a pointer
 }
 /**
  * {@inheritDoc}
  */
 public function getVersion($fvID = NULL)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getVersion', array($fvID));
     return parent::getVersion($fvID);
 }
Пример #5
0
 /**
  * returns the FileVersion object for the provided fvID
  * if none provided returns the approved version
  * @param int $fvID
  * @return Version
  */
 public function getVersion($fvID = null)
 {
     return parent::getVersion($fvID);
 }