From 07bf32b240a999581627aadcc58c044a577dc62a Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 16 Jan 2009 18:41:40 +0100 Subject: new html_flashobject() function for simple and XHTML valid flash embeds darcs-hash:20090116174140-7ad00-4eb1fe3269d10cb21819a5b220484b7114cbb4de.gz --- inc/html.php | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ inc/lang/en/lang.php | 1 + inc/parser/xhtml.php | 28 ++++++++----------- 3 files changed, 89 insertions(+), 17 deletions(-) (limited to 'inc') diff --git a/inc/html.php b/inc/html.php index 982d01860..43ab397d0 100644 --- a/inc/html.php +++ b/inc/html.php @@ -1434,4 +1434,81 @@ function html_form_output($data) { $data->printForm(); } +/** + * Embed a flash object in HTML + * + * This will create the needed HTML to embed a flash movie in a cross browser + * compatble way using valid XHTML + * + * The parameters $params, $flashvars and $atts need to be associative arrays. + * No escaping needs to be done for them. The alternative content *has* to be + * escaped because it is used as is. If no alternative content is given + * $lang['noflash'] is used. + * + * @author Andreas Gohr + * @link http://latrine.dgx.cz/how-to-correctly-insert-a-flash-into-xhtml + * + * @param string $swf - the SWF movie to embed + * @param int $width - width of the flash movie in pixels + * @param int $height - height of the flash movie in pixels + * @param array $params - additional parameters () + * @param array $flashvars - parameters to be passed in the flashvar parameter + * @param array $atts - additional attributes for the tag + * @param string $alt - alternative content (is NOT automatically escaped!) + * @returns string - the XHTML markup + */ +function html_flashobject($swf,$width,$height,$params=null,$flashvars=null,$atts=null,$alt=''){ + global $lang; + + $out = ''; + + // prepare the object attributes + if(is_null($atts)) $atts = array(); + $atts['width'] = (int) $width; + $atts['height'] = (int) $heigh; + if(!$atts['width']) $atts['width'] = 425; + if(!$atts['height']) $atts['height'] = 350; + + // add object attributes for standard compliant browsers + $std = $atts; + $std['type'] = 'application/x-shockwave-flash'; + $std['data'] = $swf; + + // add object attributes for IE + $ie = $atts; + $ie['classid'] = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; + + // open object (with conditional comments) + $out .= ''.NL; + $out .= ''.NL; + $out .= ''.NL; + $out .= ''.NL; + + // print params + if(is_array($params)) foreach($params as $key => $val){ + $out .= ' '.NL; + } + + // add flashvars + if(is_array($flashvars)){ + $out .= ' '.NL; + } + + // alternative content + if($alt){ + $out .= $alt.NL; + }else{ + $out .= $lang['noflash'].NL; + } + + // finish + $out .= ''.NL; + $out .= ''.NL; + + return $out; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : diff --git a/inc/lang/en/lang.php b/inc/lang/en/lang.php index e206f2fc9..0f270d3ee 100644 --- a/inc/lang/en/lang.php +++ b/inc/lang/en/lang.php @@ -149,6 +149,7 @@ $lang['created'] = 'created'; $lang['restored'] = 'old revision restored'; $lang['external_edit'] = 'external edit'; $lang['summary'] = 'Edit summary'; +$lang['noflash'] = 'The Adobe Flash Plugin is needed to display this content.'; $lang['mail_newpage'] = 'page added:'; $lang['mail_changed'] = 'page changed:'; diff --git a/inc/parser/xhtml.php b/inc/parser/xhtml.php index 565459220..bad1a21de 100644 --- a/inc/parser/xhtml.php +++ b/inc/parser/xhtml.php @@ -966,26 +966,20 @@ class Doku_Renderer_xhtml extends Doku_Renderer { // return the title of the flash if (!$title) { // just show the sourcename - $title = $this->_xmlEntities(basename(noNS($src))); + $title = basename(noNS($src)); } - return $title; + return $this->_xmlEntities($title); } - $ret .= '_xmlEntities($width).'"'; - if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; - $ret .= '>'.DOKU_LF; - $ret .= ''.DOKU_LF; - $ret .= ''.DOKU_LF; - $ret .= '_xmlEntities($width).'"'; - if ( !is_null($height) ) $ret .= ' height="'.$this->_xmlEntities($height).'"'; - $ret .= ' type="application/x-shockwave-flash"'. - ' pluginspage="http://www.macromedia.com/go/getflashplayer">'.DOKU_LF; - $ret .= ''.DOKU_LF; - + $att = array(); + $att['class'] = "media$align"; + if($align == 'right') $att['align'] = 'right'; + if($align == 'left') $att['align'] = 'left'; + $ret .= html_flashobject($src,$width,$height, + array('quality' => 'high'), + null, + $att, + $this->_xmlEntities($title)); }elseif($title){ // well at least we have a title to display $ret .= $this->_xmlEntities($title); -- cgit v1.2.3