Class Swift_Plugin_FileEmbedder

Description

Implements interfaces:

Swift FileEmbedder Plugin to embed remote files.

Scans a Swift_Message instance for remote files and then embeds them before sending. This also embeds local files from disk.

Located in /Swift/Plugin/FileEmbedder.php (line 22)


	
			
Variable Summary
Method Summary
void addProtocol (string $prot)
void addType (string $ext, string $type)
void beforeSendPerformed ( $e)
void clearCache ()
string embedLocalFile (array $matches)
string embedRemoteFile (array $matches)
boolean getEmbedLocalFiles ()
boolean getEmbedRemoteFiles ()
string getLocalFilePattern (string $tag_name)
array getProtocols ()
string getRemoteFilePattern (string $tag_name)
array getTagDefinition (string $tag)
string getType (string $ext)
void registerFile (string $url, string $cid, Swift_Message_EmbeddedFile $file)
void removeProtocol (string $prot)
void removeTagDefinition (string $tag)
void setEmbedLocalFiles (boolean $set)
void setEmbedRemoteFiles (boolean $set)
void setLocalFilePatternFormat (string $format)
void setRemoteFilePatternFormat (string $format)
void setTagDefinition (string $tag, string $attributes, array $extensions)
Variables
array $definitions = array(
"img" => array(
"attributes" => array("src"),"extensions"=>array("gif","png","jpg","jpeg","pjpeg")),"link"=>array("attributes"=>array("href"),"extensions"=>array("css")),"script"=>array("attributes"=>array("src"),"extensions"=>array("js")))
(line 38)

(X)HTML tag defintions listing allowed attributes and extensions.

  • access: protected
boolean $embedLocalFiles = true (line 33)

True if local files will be embedded.

  • access: protected
boolean $embedRemoteFiles = true (line 28)

True if remote files will be embedded.

  • access: protected
string $localFilePatternFormat = "~
(<(?:%s)\\s+[^>]*? #Opening tag followed by (possible) attributes
(?:%s)=((?:\"|')?)) #Permitted attributes followed by (possible) quotation marks
((?:/|[a-z]:\\\\|[a-z]:/)[\\x01-\\x7F]*?(?:%s)?) #Local, absolute path
(\\2[^>]*>) #Remaining attributes followed by end of tag
~isx"
(line 74)

A PCRE regexp which will be passed via sprintf() to produce a complete pattern.

  • access: protected
array $mimeTypes = array(
"gif" => "image/gif",
"png" => "image/png",
"jpeg" => "image/jpeg",
"jpg" => "image/jpeg",
"pjpeg" => "image/pjpeg",
"js" => "text/javascript",
"css" => "text/css")
(line 84)

A list of extensions mapping to their usual MIME types.

  • access: protected
array $protocols = array(
"http" => "http",
"https" => "https",
"ftp" => "ftp"
)
(line 55)

Protocols which may be used to download a remote file.

  • access: protected
array $registeredFiles = array() (line 96)

Child IDs of files already embedded.

  • access: protected
string $remoteFilePatternFormat = "~
(<(?:%s)\\s+[^>]*? #Opening tag followed by (possible) attributes
(?:%s)=((?:\"|')?)) #Permitted attributes followed by (possible) quotation marks
((?:%s)://[\\x01-\\x7F]*?(?:%s)?) #Remote URL (matching a permitted protocol)
(\\2[^>]*>) #Remaining attributes followed by end of tag
~isx"
(line 64)

A PCRE regexp which will be passed via sprintf() to produce a complete pattern.

  • access: protected
Methods
addProtocol (line 169)

Add a new protocol which can be used to download files.

Protocols should not include the "://" portion. This method expects alphanumeric characters only.

  • access: public
void addProtocol (string $prot)
  • string $prot: The protocol name (e.g. http or ftp)
addType (line 117)

Add a new MIME type defintion (or overwrite an existing one).

  • access: public
void addType (string $ext, string $type)
  • string $ext: The extension (sans the dot)
  • string $type: The MIME type (e.g. image/jpeg)
beforeSendPerformed (line 403)

Swift's BeforeSendListener required method.

Runs just before Swift sends a message. Here is where we do all the replacements.

  • access: public
void beforeSendPerformed ( $e)
clearCache (line 393)

Empty out the cache of registered files.

  • access: public
void clearCache ()
embedLocalFile (line 359)

Callback method for preg_replace().

Embeds files which have been found during scanning.

  • return: The tag with it's path replaced with a CID
  • access: protected
string embedLocalFile (array $matches)
  • array $matches: Backreferences from preg_replace()
embedRemoteFile (line 317)

Callback method for preg_replace().

Embeds files which have been found during scanning.

  • return: The tag with it's URL replaced with a CID
  • access: protected
string embedRemoteFile (array $matches)
  • array $matches: Backreferences from preg_replace()
getEmbedLocalFiles (line 307)

Returns true if local files can be embedded, or false if not.

  • access: public
boolean getEmbedLocalFiles ()
getEmbedRemoteFiles (line 291)

Returns true if remote files can be embedded, or false if not.

  • access: public
boolean getEmbedRemoteFiles ()
getLocalFilePattern (line 254)

Get the PCRE pattern for a local file based on the tag name.

  • access: public
string getLocalFilePattern (string $tag_name)
  • string $tag_name: The name of the tag
getLocalFilePatternFormat (line 138)

Gets the sprintf() format string for the PCRE pattern to scan for remote files.

  • access: public
string getLocalFilePatternFormat ()
getProtocols (line 186)

Get a list of all registered protocols.

  • access: public
array getProtocols ()
getRemoteFilePattern (line 237)

Get the PCRE pattern for a remote file based on the tag name.

  • access: public
string getRemoteFilePattern (string $tag_name)
  • string $tag_name: The name of the tag
getRemoteFilePatternFormat (line 160)

Gets the sprintf() format string for the PCRE pattern to scan for remote files.

  • access: public
string getRemoteFilePatternFormat ()
getTagDefinition (line 226)

Get a tag definition.

Returns an array with indexes "attributes" and "extensions". Each element is an array listing the values within it.

  • access: public
array getTagDefinition (string $tag)
  • string $tag: The name of the tag
getType (line 103)

Get the MIME type based upon the extension.

  • access: public
string getType (string $ext)
  • string $ext: The extension (sans the dot).
registerFile (line 272)

Register a file which has been downloaded so it doesn't need to be downloaded twice.

  • access: public
void registerFile (string $url, string $cid, Swift_Message_EmbeddedFile $file)
  • string $url: The remote URL
  • string $cid: The ID as attached in the message
  • Swift_Message_EmbeddedFile $file: The file object itself
removeProtocol (line 178)

Remove a protocol from the list of allowed protocols once added.

  • access: public
void removeProtocol (string $prot)
  • string $prot: The name of the protocol (e.g. http)
removeTagDefinition (line 215)

Remove a tag definition for remote files.

  • access: public
void removeTagDefinition (string $tag)
  • string $tag: The name of the tag
setEmbedLocalFiles (line 299)

Turn on or off local file embedding.

  • access: public
void setEmbedLocalFiles (boolean $set)
  • boolean $set
setEmbedRemoteFiles (line 283)

Turn on or off remote file embedding.

  • access: public
void setEmbedRemoteFiles (boolean $set)
  • boolean $set
setLocalFilePatternFormat (line 130)

Set the PCRE pattern which finds -full- HTML tags and copies the path for a local file into a backreference.

The pattern contains three %s replacements for sprintf(). First replacement is the tag name (e.g. img) Second replacement is the attribute name (e.g. src) Third replacement is the file extension (e.g. jpg) This pattern should contain the full URL in backreference index 3.

  • access: public
void setLocalFilePatternFormat (string $format)
  • string $format: sprintf() format string containing a PCRE regexp.
setRemoteFilePatternFormat (line 152)

Set the PCRE pattern which finds -full- HTML tags and copies the URL for the remote file into a backreference.

The pattern contains four %s replacements for sprintf(). First replacement is the tag name (e.g. img) Second replacement is the attribute name (e.g. src) Third replacement is the protocol (e.g. http) Fourth replacement is the file extension (e.g. jpg) This pattern should contain the full URL in backreference index 3.

  • access: public
void setRemoteFilePatternFormat (string $format)
  • string $format: sprintf() format string containing a PCRE regexp.
setTagDefinition (line 197)

Add, or modify a tag definition.

This affects how the plugins scans for files to download.

  • access: public
void setTagDefinition (string $tag, string $attributes, array $extensions)
  • string $tag: The name of a tag to search for (e.g. img)
  • string $attributes: The name of attributes to look for (e.g. src). You can pass an array if there are multiple possibilities.
  • array $extensions: A list of extensions to allow (sans dot). If there's only one you can just pass a string.

Documentation generated on Wed, 26 Mar 2008 20:33:07 +1100 by phpDocumentor 1.3.1