Thursday, January 17, 2013

Embed Flash with PHP.

Its been a while. I figured I should put something up. Here is a class I wrote to put Flash on a page with PHP. Enjoy.


<?php
/**
 * Description of flash
 * @author Joseph Tveter
 *
 * This will build the object to embed a swf in.
 */
include_once 'view/html/HTML.php';
class flash {
    private $embedAttrs = array(
        "src"               => "flash_obj.swf",
        "quality"           => "high",
        "bgcolor"           => "#ffffff",
        "width"             => "1024",
        "height"            => "600",
        "name"              => "flash_obj",
        "align"             => "middle",
        "allowScriptAccess" => "sameDomain",
        "allowFullScreen"   => "false",
        "type"              => "application/x-shockwave-flash",
        "pluginspage"       => "http://www.adobe.com/go/getflashplayer",
        "vspace"            => "",
        "hspace"            => "",
        "class"             => "",
        "title"             => "",
        "accesskey"         => "",
        "tabindex"          => "",
        "flashvars"         => "",
    );
    private $params = array(
        "allowScriptAccess" => "sameDomain",
        "allowFullScreen"   => "false",
        "movie"             => "lobby.swf",
        "quality"           => "high",
        "bgcolor"           => "#ffffff",
    );
   
    private $objAttrs = array(
        "classid"            => "clsid:d27cdb6e-ae6d-11cf-96b8-444553540042",
        "codebase"           => "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0",
        "width"              => "1024",
        "height"             => "600",
        "id"                 => "flash_obj",
        "align"              => "middle",
        "onafterupdate"      => "",
        "onbeforeupdate"     => "",
        "onblur"             => "",
        "oncellchange"       => "",
        "onclick"            => "",
        "ondblclick"         => "",
        "ondrag"             => "",
        "ondragend"          => "",
        "ondragenter"        => "",
        "ondragleave"        => "",
        "ondragover"         => "",
        "ondrop"             => "",
        "onfinish"           => "",
        "onfocus"            => "",
        "onhelp"             => "",
        "onmousedown"        => "",
        "onmouseup"          => "",
        "onmouseover"        => "",
        "onmousemove"        => "",
        "onmouseout"         => "",
        "onkeypress"         => "",
        "onkeydown"          => "",
        "onkeyup"            => "",
        "onload"             => "",
        "onlosecapture"      => "",
        "onpropertychange"   => "",
        "onreadystatechange" => "",
        "onrowsdelete"       => "",
        "onrowenter"         => "",
        "onrowexit"          => "",
        "onrowsinserted"     => "",
        "onstart"            => "",
        "onscroll"           => "",
        "onbeforeeditfocus"  => "",
        "onactivate"         => "",
        "onbeforedeactivate" => "",
        "ondeactivate"       => "",
        "type"               => "",
        "vspace"             => "",
        "hspace"             => "",
        "class"              => "",
        "title"              => "",
        "accesskey"          => "",
        "name"               => "",
        "tabindex"           => "",
        "devicefont"         => "",
        "flashvars"          => "",
        );
   
    public function __construct($args) {
        foreach($args as $k => $v){
            foreach($this->embedAttrs as $key => $val){
               if($k == $key){
                   $this->embedAttrs[$k] = $v;
               }
            }
            foreach($this->params as $key => $val){
                if($k == $key){
                    $this->params[$k] = $v;
                }
            }
            foreach($this->objAttrs as $key => $val){
                if($k == $key){
                    $this->objAttrs[$k] = $v;
                }
            }
        }
    }
   
    public function draw(){
        $html = new HTML("object");
        foreach($this->objAttrs as $k => $v){
            if($v != ""){
                $html->addValue($k, $v);
            }
        }
       
        foreach($this->params as $k => $v){
            if($v != ""){
                $pram = new HTML("param");
                $pram->addValue("name", $k);
                $pram->addValue("value", $v);
                $html->addChild($pram);
            }
        }
        $embed = new html("embed");
        foreach($this->embedAttrs as $k => $v){
            if($v != ""){
                $embed->addValue($k, $v);
            }
        }
        $html->addChild($embed);
        return $html;
    }
}

?>

Wednesday, October 31, 2012

I felt inspired to go back to my animation roots for an evening.

When I heard that Disney is reacquiring the Star Wars Franchise I felt inspired to edit the Imperial March to Steamboat Wilie.  Enjoy.
http://www.youtube.com/watch?v=xdqH85LSuGE

Wednesday, October 24, 2012

Web Page Update

Updated the Fractured Nations page.  I now have a timeline till go live.
www.fracturednations.com

Tuesday, October 16, 2012

E-mail attachments with php

      So the boss wanted to get a bunch of stats out of the database on a daily basis.  Our server guy has been doing it for her, and he complains that it takes time, which it does.  And he does not pull all the data she wants because some of it needs to be cleaned before it will display nicely.  So I figured it would be better done with a php script set to execute in a daily CRON.  I got put to this because she really wanted  the data that was dirty.  I could see my way threw the project but I had to figure out one or two things.  The main being how do you sent an email with an attachment with code.  So the next few posts will be addressing e-mailing with code, and data cleaning.


Monday, September 17, 2012

Weird Dream Last Night

So my wife and I have been looking at house plans with the intent of building one day.  And I have been scripting a lot.  I don't know exactly what triggered it but I had a dream we were building the house and I was laying out the floor with CSS and Javascript.  I made it self cleaning.  To bad it can't really be done this way.

<div id="kitchenFloor" class="Pergo Mahogany WideStrips" onwalk="selfClean()"></div>

function selfClean()
{
     var floor = house.getElementById("kitchenFloor");
     if(floor.mud == true)
     {
          //remove Mud
          floor.mud = false;
     }
}

Tuesday, September 11, 2012

HTML form element class object in PHP

Form Elements as easy as

$elem = new FormElement("yourElement", "Hello World Element");
echo $elem->HTML();

This Will print
--------------------------
<div class=''>Hello World Element</div>
<input id="yourElement" name="yourElement" type="text" form="form" onblur="Validate('yourElement')"/>
<div name='err' class='error'></div>
--------------------------
The last div named 'err' can be used to display errors from the validation.


<?php

/**
 * Description of FormElement
 * Form Element HTML Object
 * @author Joseph Tveter
 *
 * $name        is the name and id of the form element.
 * $cmd         is the HTML tag
 * $label       is the Label the User will see for the field the default is that it will not be there.
 * $pos         is the position of the label.  The default is "top", but it will also accept "right", "left", and "bottom"
 * $formName    is the name of the form the element is attached to. The default is "form"
 * $type        is the type of input tag it is. The default is "text"
 * $onblur      is the javascript function called onblur. default will call the function called "Validate" with the name of the field.  false will not include this field.
 * $val         is the value the tag has or will return.  The default is ""
 * $req         is weather to make the field required or not. The default is false
 * $disabled    is weather to make the field disabled or not. The default is false
 * $size        is the size of the input field. The default is ""
 * $maxLength   is the Maximum Length of the input field. The default is ""
 * $fullclass   is the class assigned to the div wrapper around the label and form element. The default is ""
 * $titleClass  is the class assigned to the label. The default is ""
 * $elementClass is the class of the form element.  The default is ""
 */
class FormElement extends HTML
{
    public function __construct($name, $label = "", $cmd = "input", $pos = "top", $formName = "form", $type = "text", $onblur = "default", $val = "", $req = false, $disabled = false, $size = "", $maxLength = "", $elementClass = "", $fullclass = "", $titleClass = "")
    {
        parent::__construct("div");
        if($fullclass != "")
        {
            parent::addValue("class", $fullclass);
        }
     
        $input = new HTML($cmd);
        $input->addValue("id", $name);
        $input->addValue("name", $name);
        $input->addValue("type", $type);
        $input->addValue("form", $formName);
     
        if($onblur != "default")
        {
            if($onblur != false)
            {
                $input->addValue("onblur", $onblur);
            }
        }
        else
        {
            $input->addValue("onblur", "Validate('$name')");
        }
     
        if($val != "")
        {
            $input->addValue('value', $val);
        }
     
        if($disabled == true)
        {
            $input->addValue('disabled', "disabled");
        }
     
        if($req == true)
        {
            $input->addValue("required", "required");
        }
     
        if($size != "")
        {
            $input->addValue("size", $size);
        }
     
        if($maxLength != "")
        {
            $input->addValue("maxlength", $maxLength);
        }
     
        if($elementClass != "")
        {
            $input->addValue("class", $elementClass);
        }
     
     
        if($label != "")
        {
            switch($pos)
            {
                case "":
                    parent::addChild("<div class='$titleClass'>$label</div>");
                    parent::addChild($input->HTML());
                    parent::addChild("<div name='err' class='error'></div>");
                break;
         
                case "top":      
                    parent::addChild("<div class='$titleClass'>$label</div>");
                    parent::addChild($input->HTML());
                    parent::addChild("<div name='err' class='error'></div>");
                break;
         
                case "bottom":
                    parent::addChild($input->HTML());
                    parent::addChild("<div class='$titleClass'>$label</div>");
                    parent::addChild("<div name='err' class='error'></div>");
                break;
         
                case "right":
                    $input->addChild("<span class='$titleClass'>$label</span>");
                    parent::addChild($input->HTML());
                    parent::addChild("<div name='err' class='error'></div>");
                break;
         
                case "left":
                    parent::addChild("<label for='$name' class='$titleClass'>$label</label>");
                    parent::addChild($input->HTML());
                    parent::addChild("<div name='err' class='error'></div>");
                break;
            }
        }
        else
        {
            parent::addChild($input->HTML());
        }
    }
}

?>

HTML Form Class Object


I got your form right here.

$form = new form("myform");
echo $form->HTML();

This will print
----------------------
<form id="myform" name="myform" action="index.php" method="post">
</form>
---------------------


<?php
/**
 * Description of form
 * HTML form Object
 * @author Joseph Tveter
 */
class form extends HTML
{
    public function __construct($name = "form", $action = "index.php", $method = "post")
    {
        parent::__construct("form");
        parent::addValue("id", $name);
        parent::addValue("name", $name);
        parent::addValue("action", $action);
        parent::addValue("method", $method);
    }
}

?>