class SWFObject in SWF Embed 7
Same name and namespace in other branches
- 6 swfembed.module \SWFObject
Generic data object for describing an SWF configuration.
Hierarchy
- class \SWFObject
Expanded class hierarchy of SWFObject
File
- ./
swfembed.module, line 112 - The main file for swfembed.
View source
class SWFObject {
/**
* List of parameters to send to the HTML embed or object tag.
*
* @var array
*/
protected $params = array();
/**
* List of flashVars to send to the SWF file.
*
* @var array
*/
protected $flashVars = array();
/**
* HTML fragment to display if Flash is not enabled.
*
* @var string
*/
protected $noFlash = '';
/**
* Height and width of the SWF file.
*
* @var int
*/
protected $dimensions = array(
'height' => NULL,
'width' => NULL,
);
protected $swfFallbacks = array();
/**
* The path to the flash object.
* @var string
*/
protected $flashObject = '';
/**
* The path or full URL for the express installation SWF object.
* @var string
*/
protected $expressRedirectURL = NULL;
/**
* The minimum version number required by the flash player.
*
* Format: '1.2.3'
*
* @var string
*/
protected $minimumVersion = '';
/**
* The id of the div for including the flash div
*
* @var string
*/
protected $id = '';
/**
* Constructor
*
* @param $flash_object
* The path to the flash object (swf). No checking is done on this path.
*/
function __construct($flash_object) {
$this->flashObject = $flash_object;
$id_counter =& drupal_static('swfembed_id_counter', 1);
// We use an underscore so that this can be accessed as an object
// property in JS.
$this->id = 'swf_' . $id_counter++;
}
/**
* Get the id for the div
*/
function getId() {
return $this->id;
}
/**
* Get the flash object file path.
*/
function getFlashObject() {
return $this->flashObject;
}
/**
* Set the flash object file path.
*
* @param $flash_object
* The path to the flash object.
*/
function setFlashObject($flash_object) {
$this->flashObject = $flash_object;
return $this;
}
/**
* Set the height of this swf object.
*
* If not specified, the system will try to determine the height of the file
* if it can.
*
* @param $height
* The height in pixels of the file.
* @return
* The called object.
*/
public function height($height) {
$this->dimensions['height'] = $height;
return $this;
}
/**
* Set the width of this swf object.
*
* If not specified, the system will try to determine the width of the file
* if it can.
*
* @param $width
* The width in pixels of the file.
* @return
* The called object.
*/
public function width($width) {
$this->dimensions['width'] = $width;
return $this;
}
/**
* Returns the height the SWF file should use.
*
* If no height has been specified explicitly, the system will try to determine
* the proper height based on the file if it can.
*
* @return
* The height of the SWF file in pixels.
*/
public function getHeight() {
return $this
->getDimension('height');
}
/**
* Returns the width the SWF file should use.
*
* If no width has been specified explicitly, the system will try to determine
* the proper width based on the file if it can.
*
* @return
* The width of the SWF file in pixels.
*/
public function getWidth() {
return $this
->getDimension('width');
}
/**
* Get a single dimension for this SWF file.
*
* If an explicitly dimension is specified, that will be used. If not,
* the dimensions will be derived from the SWF file, if possible.
*
* If the dimension is not explicitly specified, it will be specified by this
* function.
*
* @param $key
* The dimension to use, either height or width.
* @return
* The value in pixels of that dimension.
*/
protected function getDimension($key) {
$derived = array();
if (empty($this->dimensions[$key])) {
list($derived['width'], $derived['width']) = getimagesize($this
->getFlashObject());
// We only want to bother analyzing the image once, but if a dimension
// has already been set explicitly then we don't want to overwrite it.
foreach (array(
'height',
'width',
) as $field) {
if (empty($this->dimensions[$field])) {
$this->dimensions[$field] = $derived[$field];
}
}
}
return $this->dimensions[$key];
}
/**
* Specify a flash variable to pass along to the player.
*
* Flash variables are specific to each SWF file. These are passed in using
* a single parameter. The flashvars are compacted and URL encoded.
* Example:
* <code>
* <param name="flashvars" value="name=value&name2=value2"/>
* </code>
*
* @param $name
* The name of the flash variable.
* @param $val
* The value for this variable.
* @return
* The called object.
*/
public function flashVar($name, $val) {
$this->flashVars[$name] = $val;
return $this;
}
/**
* Specify a parameter to pass to the HTML object or embed tag.
*
* These will be converted into a name/value pair encoded in a param tag.
*
* Example:
* <code>
* <param name="NAME" value="VALUE"/>
* </code>
*
* @param $name
* The param to define.
* @param $val
* The value of the param.
* @return
* The called object.
*/
public function param($name, $val) {
$this->params[$name] = $val;
return $this;
}
/**
* Gets a list of all flash variables relevant to this SWF file.
*
* @return
* An array of flashVars as an associative array.
*/
public function getFlashVars() {
return $this->flashVars;
}
/**
* Gets a list of all parameters.
*
* @return
* An array of params as an associative array.
*/
public function getParams() {
return $this->params;
}
/**
* Specify the text that will be used if Flash is disabled or not available.
*
* This may be any HTML fragment. WARNING: This fragment is assumed to already
* be filtered. It will not be filtered again. It is up to you to ensure
* that any HTML has been run through filter_xss(), check_plain(), or similar
* before you use it.
*
* @param $html
* The HTML fragment to use.
* @return
* The flashy object.
*/
public function noFlash($html) {
$this->noFlash = $html;
return $this;
}
/**
* Retrieves the HTML fragment to use if Flash is not available.
*
* @return
* The HTML fragment to use.
*/
public function getNoFlash() {
return $this->noFlash;
}
/**
* Set a URL for express installation.
*
* If you want to use express install, you should read the Adobe documentation
* and/or find a suitable SWF express installer.
* @see http://www.adobe.com/products/flashplayer/download/detection_kit/
*
* @param $url
* The URL for the express installer. No manipulation of the URL is done.
*/
public function expressRedirectURL($url) {
$this->expressRedirectURL = $url;
return $this;
}
/**
* Get the express installer redirect URL.
*
* @return
* The URL.
*/
public function getExpressRedirectURL() {
return $this->expressRedirectURL;
}
/**
* Set the minimum version of the Flash player.
* This will check the client flash player to make sure it is at least at the
* minimum version. A version number can be of any of these three forms:
* - Major: 9
* - Major.Minor: 9.1
* - Major.Minor.Release: 9.1.124
*
* @param $version
* The version string.
* @return
* The called object.
*/
public function minimumVersion($version) {
$this->minimumVersion = $version;
return $this;
}
/**
* Get the minimum Flash player version.
*
* @return
* Flash player version as a string.
*/
public function getMinimumVersion() {
return $this->minimumVersion;
}
/**
* Sets additional SWF files to use if we don't we have the minimum version of flash
*
* @param $version
* @param $file
* @return The called object
*/
public function swfFallback($version, $file) {
$this->swfFallbacks[] = array(
'file' => $file,
'version' => $version,
);
return $this;
}
/**
* Gets the fallback swf array
*
* @return The array of fallback swf information
*/
public function getSwfFallbacks() {
return $this->swfFallbacks;
}
/**
* Convert this to an array ready for serializing.
* This is a special-purpose method for turning this object into a configuration
* array. It is not a general purpose serialization method.
*
* @return
* An associative array for serializing to JavaScript.
*/
public function toArray() {
return array(
'height' => $this
->getHeight(),
'width' => $this
->getWidth(),
'flashvars' => $this
->getFlashVars(),
'params' => $this
->getParams(),
'noflash' => $this
->getNoFlash(),
'url' => $this
->getFlashObject(),
'swfFallbacks' => $this
->getSwfFallbacks(),
'expressInstall' => $this
->getExpressRedirectURL(),
'version' => $this
->getMinimumVersion(),
);
}
/**
* Render this flash object using the theme system.
*
* The HTML returned from this method will be just the no-flash placeholder.
* The theme function also handles enquing the necessary Javascript to make
* the Flash swap-out work client-side.
*
* @return unknown
*/
public function render() {
return theme('swfembed_embed', array(
'swf' => $this,
));
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SWFObject:: |
protected | property | Height and width of the SWF file. | |
SWFObject:: |
protected | property | The path or full URL for the express installation SWF object. | |
SWFObject:: |
protected | property | The path to the flash object. | |
SWFObject:: |
protected | property | List of flashVars to send to the SWF file. | |
SWFObject:: |
protected | property | The id of the div for including the flash div | |
SWFObject:: |
protected | property | The minimum version number required by the flash player. | |
SWFObject:: |
protected | property | HTML fragment to display if Flash is not enabled. | |
SWFObject:: |
protected | property | List of parameters to send to the HTML embed or object tag. | |
SWFObject:: |
protected | property | ||
SWFObject:: |
public | function | Set a URL for express installation. | |
SWFObject:: |
public | function | Specify a flash variable to pass along to the player. | |
SWFObject:: |
protected | function | Get a single dimension for this SWF file. | |
SWFObject:: |
public | function | Get the express installer redirect URL. | |
SWFObject:: |
function | Get the flash object file path. | ||
SWFObject:: |
public | function | Gets a list of all flash variables relevant to this SWF file. | |
SWFObject:: |
public | function | Returns the height the SWF file should use. | |
SWFObject:: |
function | Get the id for the div | ||
SWFObject:: |
public | function | Get the minimum Flash player version. | |
SWFObject:: |
public | function | Retrieves the HTML fragment to use if Flash is not available. | |
SWFObject:: |
public | function | Gets a list of all parameters. | |
SWFObject:: |
public | function | Gets the fallback swf array | |
SWFObject:: |
public | function | Returns the width the SWF file should use. | |
SWFObject:: |
public | function | Set the height of this swf object. | |
SWFObject:: |
public | function | Set the minimum version of the Flash player. This will check the client flash player to make sure it is at least at the minimum version. A version number can be of any of these three forms: | |
SWFObject:: |
public | function | Specify the text that will be used if Flash is disabled or not available. | |
SWFObject:: |
public | function | Specify a parameter to pass to the HTML object or embed tag. | |
SWFObject:: |
public | function | Render this flash object using the theme system. | |
SWFObject:: |
function | Set the flash object file path. | ||
SWFObject:: |
public | function | Sets additional SWF files to use if we don't we have the minimum version of flash | |
SWFObject:: |
public | function | Convert this to an array ready for serializing. This is a special-purpose method for turning this object into a configuration array. It is not a general purpose serialization method. | |
SWFObject:: |
public | function | Set the width of this swf object. | |
SWFObject:: |
function | Constructor |