class MailhandlerAttachmentEnclosure in Mailhandler 7.2
Same name and namespace in other branches
- 6.2 plugins/mailhandler/commands/MailhandlerCommandsFiles.class.php \MailhandlerAttachmentEnclosure
Attachment enclosure, can be part of the result array.
Hierarchy
- class \MailhandlerAttachmentEnclosure extends \FeedsEnclosure
Expanded class hierarchy of MailhandlerAttachmentEnclosure
File
- plugins/
mailhandler/ commands/ MailhandlerCommandsFiles.class.php, line 52 - MailhandlerCommandsFiles class.
View source
class MailhandlerAttachmentEnclosure extends FeedsEnclosure {
/**
* The Content-ID.
*
* @var string
*/
protected $cid;
/**
* The file content.
*
* @var string
*/
protected $data;
/**
* Constructs an attachment enclosure.
*
* @param string $filename
* The file name.
* @param string $mime_type
* The mime type.
* @param string $data
* The file content.
* @param string $cid
* (optional) The Content-ID.
*/
public function __construct($filename, $mime_type, $data, $cid = NULL) {
parent::__construct($filename, $mime_type);
$this->data = $data;
$this->cid = $cid;
}
/**
* Get the Content-ID.
*
* @return string
* The Content-ID or NULL if it is not defined.
*/
public function getContentId() {
return $this->cid;
}
/**
* Get the file content.
*
* @return string
* The file content.
*/
public function getContent() {
return $this->data;
}
/**
* {@inheritdoc}
*
* Save the attachment data the same way as the parent class for remote files.
*/
public function getFile($destination, $replace = FILE_EXISTS_RENAME) {
$file = FALSE;
if ($this
->getValue()) {
// Prepare destination directory.
file_prepare_directory($destination, FILE_MODIFY_PERMISSIONS | FILE_CREATE_DIRECTORY);
// Save the file.
if (file_uri_target($destination)) {
$destination = trim($destination, '/') . '/';
}
try {
$filename = $this
->getLocalValue();
if (module_exists('transliteration')) {
require_once drupal_get_path('module', 'transliteration') . '/transliteration.inc';
$filename = transliteration_clean_filename($filename);
}
$file = file_save_data($this
->getContent(), $destination . $filename, $replace);
} catch (Exception $e) {
watchdog_exception('Feeds', $e, nl2br(check_plain($e)));
}
// We couldn't make sense of this enclosure, throw an exception.
if (!$file) {
throw new Exception(t('Invalid enclosure %enclosure', array(
'%enclosure' => $this
->getValue(),
)));
}
return $file;
}
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MailhandlerAttachmentEnclosure:: |
protected | property | The Content-ID. | |
MailhandlerAttachmentEnclosure:: |
protected | property | The file content. | |
MailhandlerAttachmentEnclosure:: |
public | function | Get the file content. | |
MailhandlerAttachmentEnclosure:: |
public | function | Get the Content-ID. | |
MailhandlerAttachmentEnclosure:: |
public | function | Save the attachment data the same way as the parent class for remote files. | |
MailhandlerAttachmentEnclosure:: |
public | function | Constructs an attachment enclosure. |