Difference between revisions of "Swf.php"

From Organic Design wiki
m
(General structure done - ready to debug)
Line 14: Line 14:
 
'params' => '',
 
'params' => '',
 
'format' => 'embed',
 
'format' => 'embed',
 +
'version' => 6,
 
'url' => ''
 
'url' => ''
  
Line 26: Line 27:
 
if ( $format == 'embed' ) {
 
if ( $format == 'embed' ) {
 
$article = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"
 
$article = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"
codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"
+
codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=$version,0,0,0\"
 
width=$width height=$height id=\"$src\" align=\"\"
 
width=$width height=$height id=\"$src\" align=\"\"
 
type=\"application/x-shockwave-flash\" data=\"$src\">
 
type=\"application/x-shockwave-flash\" data=\"$src\">
Line 40: Line 41:
 
}
 
}
  
 +
else {
  
 +
# Compile the script into a binary SWF
 +
# - also builds hard wired common vector shapes (later converted to Ming from SVG)
  
 +
# Check weather required extentions are available (GD2 and Ming)
 +
$ext = get_loaded_extensions();
 +
if ( !in_array( 'ming', $ext ) ) xwMessage( 'Ming extention not loaded! (at least version 0.3 required)', 'red' );
  
# Hard wired common vector shapes (later converted to Ming from SVG)
+
ming_useswfversion( $version );
 +
$swf = new SWFMovie();
 +
$swf->setDimension( $width, $height );
 +
eregi( '^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$' , $background, $m );
 +
list(,$r,$g,$b) = $m;
 +
$swf->setBackground( hexdec($r), hexdec($g), hexdec($b) );
 +
$swf->setRate($frameRate);
 +
xwMessage( "SWF movie created ($width"."x$height@$fps\fps)" );
  
 
# Black block (for spacers and fills)
 
# Black block (for spacers and fills)
Line 145: Line 159:
 
$swf->addExport( $sym, 'ball' );
 
$swf->addExport( $sym, 'ball' );
  
 
+
if ( $format == 'raw' ) {
 
+
# Send the raw SWF back to the client and die
 
+
header('Content-Type: application/x-shockwave-flash');
# Check weather required extentions are available (GD2 and Ming)
+
$swf->output(9);
global $xwDebug;
+
die();
$ext = get_loaded_extensions();
+
}
if (!in_array('gd', $ext)) xwMessage("Warning: GD extention not loaded! (image processing unavailable)",'red');
 
 
else {
 
else {
$gdi = gd_info();
+
# Write the SWF to $url and render a link to it
ereg('([0-9])([0-9.]+)', $gdi['GD Version'], $m);
+
$t = ereg_replace( '\\.as$', '.swf', $title );
if ($xwDebug) xwMessage("GD Version is $m[1]$m[2]");
+
$swf->save( "$url/$t" ,9 );
if ($m[1] < 2) xwMessage("Warning: At least GD version 2 required (image processing unavailable)",'red');
+
$article = "[$url/$t $t]";
 
}
 
}
if (!in_array('ming', $ext)) xwMessage("Ming extention not loaded! (at least version 0.3 required)",'red');
 
elseif ($xwDebug) xwMessage("Ming extention ok.");
 
 
# Override <language> in properties object to 'raw' so no wiki-parsing
 
$node = $properties->create_element('language');
 
$node->set_content('raw');
 
$root = $properties->document_element();
 
$lang = xwXPathQuery($properties, "/properties/language");
 
if (is_array($lang) && count($lang)) $lang[0]->replace_node($node);
 
else $root->append_child($node);
 
 
# Get compile parameters from properties object
 
$output = count($results = xwXPathQuery($properties, "$path/output")) ? $results[0]->get_content() : 'html';
 
$width = count($results = xwXPathQuery($properties, "$path/width")) ? $results[0]->get_content() : 200;
 
$height = count($results = xwXPathQuery($properties, "$path/height")) ? $results[0]->get_content() : 150;
 
$frameRate = count($results = xwXPathQuery($properties, "$path/frameRate")) ? $results[0]->get_content() : 25;
 
$bg = count($results = xwXPathQuery($properties, "$path/background")) ? $results[0]->get_content() : '#cccccc';
 
eregi('^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$',$bg,$m);
 
list(,$r,$g,$b) = $m;
 
 
# Create new SWF
 
ming_useswfversion(6);
 
$swf = new SWFMovie();
 
$swf->setDimension($width, $height);
 
$swf->setBackground(hexdec($r), hexdec($g), hexdec($b));
 
$swf->setRate($frameRate);
 
if ($xwDebug) xwMessage("SWF movie created ($width"."x$height@$frameRate"."fps)");
 
 
eval($article);
 
ob_end_clean();
 
header('Content-Type: application/x-shockwave-flash');
 
$swf->output(9);
 
die();
 
  
 +
}
 
?>
 
?>

Revision as of 00:33, 16 March 2006

<?

  1. SWF Compiler for XmlWiki Environment
  1. Read in relevent properties
  2. - also constructs link which requests the raw compiled SWF

$src = "$script?title=$title"; foreach ( array(

'width' => 550, 'height' => 400, 'fps' => 12, 'background' => 'ffffff', 'quality' => 'medium', 'params' => , 'format' => 'embed', 'version' => 6, 'url' =>

) ) {

if ( !xwGetProperty( $properties, "$path/$key", $$key ) ) $$key = $value; $src .= "&xpath:$path/$key=" . ( $key == 'format' ) ? 'raw' : $value;

}

  1. if format is embed, just convert the content to an object-tag referring to raw-compiled-swf

if ( $format == 'embed' ) { $article = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=$version,0,0,0\" width=$width height=$height id=\"$src\" align=\"\" type=\"application/x-shockwave-flash\" data=\"$src\"> <param name=flashvars value=\"$param\"> <param name=movie value=\"$src\"> <param name=quality value=\"$quality\"> <param name=bgcolor value=\"$bg\"> <embed src=\"$src\" quality=\"$quality\" bgcolor=\"$bg\" width=$width height=$height align="" flashvars=\"$param\" name=\"$src\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" /> </object>"; }

else {

  1. Compile the script into a binary SWF
  2. - also builds hard wired common vector shapes (later converted to Ming from SVG)
  1. Check weather required extentions are available (GD2 and Ming)

$ext = get_loaded_extensions(); if ( !in_array( 'ming', $ext ) ) xwMessage( 'Ming extention not loaded! (at least version 0.3 required)', 'red' );

ming_useswfversion( $version ); $swf = new SWFMovie(); $swf->setDimension( $width, $height ); eregi( '^#([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])$' , $background, $m ); list(,$r,$g,$b) = $m; $swf->setBackground( hexdec($r), hexdec($g), hexdec($b) ); $swf->setRate($frameRate); xwMessage( "SWF movie created ($width"."x$height@$fps\fps)" );

  1. Black block (for spacers and fills)

$shape = new SWFShape(); $shape->setRightFill( 0, 0, 0 ); $shape->movePenTo( 100, 100 ); $shape->drawLineTo( -100, 100 ); $shape->drawLineTo( -100, -100 ); $shape->drawLineTo( 100, -100 ); $shape->drawLineTo( 100, 100 ); $sym = new SWFSprite(); $sym->add( $shape ); $sym->nextFrame(); $swf->addExport( $sym, 'black' );

  1. White block (for spacers and fills)

$shape = new SWFShape(); $shape->setRightFill( 255, 255, 255 ); $shape->movePenTo( 0, 0 ); $shape->drawLineTo( 0, 767 ); $shape->drawLineTo( 1023, 767 ); $shape->drawLineTo( 1023, 0 ); $shape->drawLineTo( 0, 0 ); $sym = new SWFSprite(); $sym->add($shape); $sym->nextFrame(); $swf->addExport( $sym, 'white' );

  1. Selection area

$shape = new SWFShape(); $shape->setLine( 0, 255, 0, 0 ); $shape->movePenTo( 100, 100 ); $shape->drawLineTo( -100, 100 ); $shape->drawLineTo( -100, -100 ); $shape->drawLineTo( 100, -100 ); $shape->drawLineTo( 100, 100 ); $sym = new SWFSprite(); $sym->add( $shape ); $sym->nextFrame(); $swf->addExport( $sym, 'select' );

  1. Triangle

$shape = new SWFShape(); $shape->setRightFill( 0, 0, 0 ); $shape->movePenTo( 100, -100 ); $shape->drawLineTo( -100, -100 ); $shape->drawLineTo( -100, 100 ); $shape->drawLineTo( 100, -100 ); $triangle = new SWFSprite(); $triangle->add( $shape ); $triangle->nextFrame(); $swf->addExport( $triangle, 'triangle' );

  1. Linear Gradient

$shape=new SWFShape(); $grad = new SWFGradient(); $grad->addEntry( 0.0, 0, 0, 0, 0xff ); $grad->addEntry( 1.0, 0, 0, 0, 0 ); $fill = $shape->addFill( $grad, SWFFILL_LINEAR_GRADIENT ); $fill->scaleTo( 0.097 ); $fill->moveTo( -18, 0 ); $shape->setRightFill( $fill ); $shape->movePenTo( 100, -100 ); $shape->drawLineTo( -100, -100 ); $shape->drawLineTo( -100, 100 ); $shape->drawLineTo( 100, 100 ); $shape->drawLineTo( 100, -100 ); $sym = new SWFSprite(); $sym->add( $shape ); $sym->nextFrame(); $swf->addExport( $sym, 'linear' );

  1. Radial Gradient

$fill = $shape->addFill( $grad, SWFFILL_RADIAL_GRADIENT ); $fill->scaleTo( 0.2 ); $fill->moveTo( -100, 100 ); $shape->setRightFill( $fill ); $shape->movePenTo( 100, -100 ); $shape->drawLineTo( -100, -100 ); $shape->drawLineTo( -100, 100 ); $shape->drawLineTo( 100, 100 ); $shape->drawLineTo( 100, -100 ); $sym = new SWFSprite(); $sym->add( $shape ); $sym->nextFrame(); $swf->addExport( $sym, 'radial' );

  1. Ball

$sym = new SWFSprite(); $g = new SWFGradient(); $g->addEntry( 0.0, 0xff, 0xff, 0xff ); $g->addEntry( 1.0, 0, 0, 0 ); $ball = new SWFShape(); $f = $ball->addFill( $g, SWFFILL_RADIAL_GRADIENT ); $f->scaleTo( 0.2 ); $f->moveTo( 40, -60 ); $ball->setRightFill( $f ); $ball->drawCircle( 100 ); $sym->add( $ball ); $sym->nextFrame(); $swf->addExport( $sym, 'ball' );

if ( $format == 'raw' ) { # Send the raw SWF back to the client and die header('Content-Type: application/x-shockwave-flash'); $swf->output(9); die(); } else { # Write the SWF to $url and render a link to it $t = ereg_replace( '\\.as$', '.swf', $title ); $swf->save( "$url/$t" ,9 ); $article = "[$url/$t $t]"; }

} ?>