<?
/*
this softwary by Musicman 2003
is covered by the GPL
for the exact terms and conditions please see http://www.fsf.org
*/
define('PUSHDATA', "\x96");
define('POP', "\x17");
define('GETMEMBER', "\x4e");
define('SETMEMBER', "\x4f");
define('GETVAR', "\x1c");
define('SETVAR', "\x1d");
define('INITARRAY', "\x42");
define('INITOBJECT', "\x43");
define('CALLMETHOD', "\x52");
define('CALLFUNCTION', "\x3d");
class swfdata
{ var $hdr1, $hdr2, $bgcol, $end;
var $actions;
var $push_action;
function swfdata()
{ $this->hdr1 = "FWS\5";
$this->hdr2 = "\110\1\220\0\144\0\0\14\1\0";
$this->bgcol = pack("v", (9 << 6) + 3) . "\377\377\377";
$this->end = pack("vv", 1 << 6, 0); // showframe, end
$this->push_action = '';
}
function send()
{ $this->actions .= "\0";
$len = strlen($this->actions);
if($len > 63)
$this->actions = pack("vV", (12 << 6) + 63, $len) . $this->actions;
else
$this->actions = pack("v", (12 << 6) + $len) . $this->actions;
$sz = 8 + strlen($this->hdr2) + strlen($this->bgcol) + strlen($this->actions) + strlen($this->end);
header('Content-type: application/x-shockwave-flash');
print $this->hdr1 . pack("V", $sz) . $this->hdr2 . $this->bgcol . $this->actions . $this->end;
}
function push($val)
{ if(is_integer($val))
$this->push_action .= "\7" . pack("V", $val);
else if(is_float($val))
$this->push_action .= "\6" . pack("d", $val);
else
$this->push_action .= "\0" . $val . "\0";
}
function addcode($op)
{ if($l = strlen($this->push_action))
{ $this->actions .= PUSHDATA . pack("v", $l) . $this->push_action;
$this->push_action = '';
}
$this->actions .= $op;
}
function setvar($name, $val)
{ $this->pushname($name, $member);
$this->pushdata($val);
$this->addcode($member ? SETMEMBER : SETVAR);
}
function call($name)
{ $nargs = func_num_args()-1;
for($n = $nargs ; $n > 0 ; $n--)
$this->pushdata(func_get_arg($n));
$this->push($nargs);
$this->pushname($name, $member);
$this->addcode($member ? CALLMETHOD : CALLFUNCTION);
$this->addcode(POP);
}
function pushname($name, &$member)
{ $nameparts = explode(".", $name);
$member = count($nameparts) > 1;
$this->push($nameparts[0]);
for($n = 1 ; $n < count($nameparts) ; $n++)
{ $this->addcode(($n == 1) ? GETVAR : GETMEMBER);
$this->push($nameparts[$n]);
}
}
function pushdata($val)
{ if(is_array($val) || is_object($val))
{ $first = 1;
$num_array = 1;
foreach($val as $key => $data)
{ if(!is_int($key) || ($key < 0))
{ $num_array = 0;
break;
}
if($first)
{ $lo = $hi = $key;
$first = 0;
}
else if($key < $lo)
$lo = $key;
else if($key > $hi)
$hi = $key;
}
if($num_array)
{ for($n = $hi ; $n >= 0 ; $n--)
if(isset($val[$n]))
$this->pushdata($val[$n]);
else
$this->push_action .= "\3";
$this->push($hi+1);
$this->addcode(INITARRAY);
}
else
{ foreach($val as $key => $data)
{ settype($key, "string");
$this->push($key);
$this->pushdata($data);
}
$this->push(count($val));
$this->addcode(INITOBJECT);
}
}
else
$this->push($val);
}
}
?>
Back