Difference between revisions of "Swf.php"
(nearly there I think :-)) |
m |
||
Line 197: | Line 197: | ||
$t = ereg_replace( '\\.as$', '.swf', $title ); | $t = ereg_replace( '\\.as$', '.swf', $title ); | ||
$swf->save( "$htdocs$url" ,9 ); | $swf->save( "$htdocs$url" ,9 ); | ||
− | $article = " | + | $article = "<a href=\"http://$server$url\">$server$url</a>"; |
} | } | ||
} | } | ||
?> | ?> |
Revision as of 06:11, 16 March 2006
<?
- SWF Compiler for XmlWiki Environment
$htdocs = $_SERVER['DOCUMENT_ROOT']; $server = $_SERVER['HTTP_HOST'];
xwSetProperty( $properties, 'language', 'raw' );
- Read in relevent properties
- - also supplies defaults
- - and constructs link which requests the raw compiled SWF
$tag = ereg( '(\\w+)$', $path, $m ) ? $m[1] : 'swf'; $src = "$script?title=$title&xpath:/properties:language=raw&xpath:/properties:data=$tTitle&xpath:/properties:$tag"; foreach ( array(
'width' => 550, 'height' => 400, 'fps' => 12, 'background' => 'ffffff', 'quality' => 'medium', 'params' => , 'format' => 'embed', 'version' => 6, 'url' =>
) as $key => $value ) { if ( !xwGetProperty( $properties, "xpath:$path/$key", $$key ) ) $$key = $value; $src .= "&xpath:$path:$key=".( ( $key == 'format' ) ? 'raw' : $$key ); }
- 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 {
- 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' );
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)" );
- Import images
foreach ( xwGetListByTagname( $properties, 'import', $import ) as $image ) { $ref = strtolower( ereg_replace( '^.*/', , $image ) ); $ref = ereg_replace( '\\..+$', , $ref ); $file = "$htdocs$image"; shell_exec( "/var/www/wiki/png2dbl $file $htdocs$ref.dbl" ); $img = new SWFBitmap( fopen( "$htdocs$ref.dbl", 'rb' ) );
- $img = new SWFBitmap( popen( "/usr/bin/libming/bin/png2dbl $file /dev/tty", 'rb' ) );
$sym = new SWFSprite(); $sym->add( $img ); $sym->nextFrame(); $swf->addExport( $sym, $ref ); }
- 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' );
- 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' );
- 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' );
- 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' );
- 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' );
- 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' );
- 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' );
- Add actionscript in frames 1-3
$swf->add( new SWFAction( $article ) ); $swf->nextFrame(); $swf->add( new SWFAction( 'reduce();' ) ); $swf->nextFrame(); $swf->add( new SWFAction( 'gotoAndPlay(1);' ) ); $swf->nextFrame();
if ( $format == 'raw' ) { # Send the raw SWF back to the client and die ob_end_clean(); 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( "$htdocs$url" ,9 ); $article = "<a href=\"http://$server$url\">$server$url</a>"; }
} ?>