jump to navigation

Embed Helper for flash & applets May 27, 2006

Posted by rossoft in CakePHP.
trackback

For inserting flash and Java tags. Examples:

<?=$embed->flash(“http://www.loksalga.net/phpros/plantillas/loksalga/images/logo.swf”,709,129,false)?>
<?=$embed->applet(“Circle.class”,”http://www.cs.mu.oz.au/371/java/”,320,240,array(’sleeptime’=>100))?>

<?php
/**
 * Embed Helper
 * Create <OBJECT> and <EMBED> tags for Flash & Java Applets
 *
 * @author RosSoft
 * @version 0.1
 * @license MIT
 */

class EmbedHelper extends Helper
{    

    /**
     * Returns an HTML <object> tag for Flash Movies
     * @param string $url Url to movie
     * @param integer $width Width in pixels
     * @param integer $height Height in pixels
     * @param string $bgcolor Background color in hex like #000000. If null, then the background will be transparent
     * @param boolean $menu Enable flash menu on right click
     * @return string
     */
    function flash($url,$width,$height,$bgcolor=false,$menu=false)
    {
        ob_start();
        ?>
        <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
        width="<?=$width?>" height="<?=$height?>"
        codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
            <param name="movie" value="<?=$url?>" />
            <param name="quality" value="high" />
           
            <?php
            if ($bgcolor !== false && $bgcolor !== null)
            {
            ?><param name="bgcolor" value="<?=$bgcolor?>" /><?php
            }
            else
            {
            ?><param name="wmode" value="transparent" /><?php
            }
            ?>
           
            <?php
            $flash_menu=($menu) ? $flash_menu="true" : $flash_menu="false";
            ?>
            <param name="menu" value="<?=$flash_menu?>" />
           
           
            <embed src="<?=$url?>" quality="high"
            <?php
            if ($bgcolor !== false && $bgcolor !== null)
            {
            ?>bgcolor="<?=$bgcolor?>"<?php
            }
            else
            {
            ?>wmode="transparent"<?php
            }
            ?>
                width="<?=$width?>" height="<?=$height?>"
                name="detectiontest" aligh="middle"
                play="true" loop="false" quality="high"
                menu="<?=$flash_menu?>"
                allowScriptAccess="sameDomain"
                type="application/x-shockwave-flash"
                pluginspage="http://www.macromedia.com/go/getflashplayer">
            </embed>
        </object>
        <?php
        return ob_get_clean();       
    }
    

    /**
     * Returns an HTML <applet> tag for Java Applets
     * @param string $code Applet Code Class
     * @param string $archive Archive of the applet
     * @param integer $width Width in pixels
     * @param integer $height Height in pixels
     * @param array $params Hash array of parameters (name=>value)
     * @return string
     */
   
    function applet($code,$archive, $width,$height,$params=array())
    {
        ob_start();
        ?>
        <applet code="<?=$code?>" archive="<?=$archive?>"
          width="<?=$width?>" height="<?=$height?>">
          <?php
          foreach ($params as $n=>$v)
          {
              echo "<param name=\"$n\" value=\"$v\" />";                     
          }
        ?>
        </applet>
        <?php
        return ob_get_clean();
    }
}
/*
 * TODO: Call in (window.load):
theObjects = document.getElementsByTagName("object");
for (var i = 0; i < theObjects.length; i++) {
theObjects[i].outerHTML = theObjects[i].outerHTML;
}
*/

 
?>

Comments»

1. Grant Cox - May 30, 2006

I personally use SWFObject for all my Flash embedding needs. I don’t yet have it wrapped in a Helper, but it’s fairly simple syntax anyway (no need for manual object/embed tag soup).

http://blog.deconcept.com/swfobject/

Downside is that you need Javascript enabled, but it gives plugin detection, and you don’t need to click the Flash in IE to enable it (EOLAS patent issue).

2. Lorenz Talulla - June 21, 2007

Chto s holodami ne v lada. Lorenz Talulla.

3. Ece Anastasie - July 5, 2007

Before you started toki. Ece Anastasie.

4. Akio Ludvig - July 14, 2007

You used to have a brai. Akio Ludvig.

5. Josue Helka - July 22, 2007

Take me to your daddy’s far. Josue Helka.

6. Nurit Hailey - September 19, 2007

our way to beautiful gir. Nurit Hailey.

7. Huda Swithun - October 21, 2007

but your much on my mind, you often get declin. Huda Swithun.