PHP Turbine
7 generates Flash rich media and Adobe PDF documents from PHP scripts.
Turbine allows you to generate media with content obtained from a variety
of sources like image, video, XML documents, databases, other Flash
movies, plain text files, etc.
Turbine
is an integrator of dynamic content into rich media, allowing a clean
separation between Presentation from Content. With PHP Turbine 7 you
can build whole new rich media applications - fully live content multimedia
sites!
Turbine is based on a sophisticated media-independent architecture that
allows output to media formats like Flash, PDF, SVG and image formats*.
Turbine
can be seen as in this diagram:
PHP Turbine
7 includes the following capabilities:
Includes
a PHP scripting Interface
Easy
to use Turbine Media Markup Language that can express all the rich
media capabilities: text, images, shapes, movie clips, buttons, scripting,
video and audio
Full
Flash MX support with extensive component integration
Can
dynamically generate Flash movies - the Turbine architecture also
allows generation to other media types, like SVG or image (not included)
Can
dynamically generate Adobe PDF documents
Extensive
data integration capabilities - from XML, database RecordSets to plain
old text files, local or remote
Dynamic
Chart generation for Flash and PDF - chart types can be customized
and new types created
Sophisticated
text capabilities like text flow areas coupled with HTML-like formatting
Includes
images from a variety of formats, from local or remote locations
Integrates
video from AVI, QuickTime, FLV and Animated GIFs in Flash movies
Integrates
MP3, WAV and FLV audio for streaming or event sound generation in
Flash movies
Includes
on-the-fly Action Script (ECMA-262 Script or JavaScript) compiler
for Flash movies
Can
generate media to local files - allowing for batch automation
Auto-generation
of the HTML media plug-in page
Server
output media caching
Show
template errors immediately on the generated media - allowing for
easier and faster development cycles
Optimizes
generated media sizes
Encrypts
PDF documents allowing permissions to be specified
Embeds
fonts used in the PDF document
* SVG
and image output to be available later on the Turbine product line as
separate plug-ins. The PDF plug-in is already available.
How
does PHP Turbine Work?
Turbine
works at the server-side, where data can be more flexibly accessed and
integrated on media templates. The following steps are usually involved
when using Turbine:
1) A
web browser user requests a PHP script where Turbine runs
2) The web server runs the PHP script which will create a Turbine
object
3) The PHP script and/or Turbine access databases, text, image, video
or audio content from any available data sources, either local or
remote HTTP locations
4) The fetched content is integrated in Flash or XML media templates
5) A Flash movie is generated and sent to the web browser. Alternatively
a PDF document is generated and sent to the web browser.
Turbine's
approach represents a performance advantage because the PHP script that
does the content access also generates the media, avoiding multiple
server accesses, and thus improving web server response times.
Since Turbine runs on the server-side, data access is much easier and
faster, content integration with a variety of media types and formats,
most of which are not supported by Flash, are possible and straightforward.
A
Simple Example
Let's see a basic example - we'll create a Flash movie that will serve
as our template, into which we'll insert a message with the current
date. First we'll create the Flash .swf movie - open the Flash Editor
and get a new, blank movie (File > New). Somewhere on your movie
insert a Text Block (static or dynamic) like this:
Current Time is:
{text}
After this,
save the movie for example with the name time.fla (File > Save) and
then Publish into a .swf file (File > Publish) - it will be saved
as time.swf - copy this file (or save it directly) into a directory
where PHP scripts can be executed.
Then, on the chosen directory we create a file named time.php and edit
it with any text editor, to include this script:
<?
# create the turbine object:
$turbine = new Turbine7();
#
assign a variable:
$turbine->setVariable("text", date("M d Y H:i:s",
time()) );
#
select the Flash .swf template to use:
$turbine->load("time.swf");
#
now generate the movie to the web browser:
$turbine->generateFlash();
#
we could alternatively generate a PDF document:
# turbine->generatePDF();
?>
Be careful
to have the starting <? as the first characters on your PHP file
- no spaces, new-lines or other characters should be insert before this
or between these blocks. The final ?> must also be the last characters
on your script, so that no more characters are included.
Now request
the time.php script through your web browser and you will get a Flash
movie with the time information obtained in the PHP script integrated
into the Flash .swf template - a Flash movie such as this will appear:
We could
also use a template file written in an XML language named Turbine Media
Markup Language (MML for short), which we'll see later.
We could
also generate a PDF document based on the same code - the only difference
would be the generatePDF command instead of the generateFlash command.
This simple
example integrates text into Flash templates - imagine what can be done
with images, audio and video, Flash components, database content...
Output
Formats
Turbine is multi-media and multi-format: It generates Rich Media Flash,
PDF and other formats from common XML, image, video and audio sources.
Turbine can "mix" text, image, audio and video, outputting
the result to the most appropriate and convenient media format. For
instance, when dealing with video, audio and animation, the most convenient
output media would be Flash, but when the emphasis is readability and
security, then the preferred output format would be PDF.
The next
list describes which features are specific and available for each output
format supported by Turbine:
Macromedia
Flash format :
Supports
audio, video, images, text and shapes
Supports
sophisticated transparencies and gradients
Supports
multimedia interactivity
Supports
client side scripting
Supports
compressed images, audio and video, as well as a global file compression
Supports
content streaming
Doesn't
support encryption and document permissions
Adobe
PDF format:
Supports
text with font embedding and subsetting
Supports
images and shapes
Supports
compressed images, as well as a global file compression
Supports
encryption and document permissions
Doesn't
support transparency and gradients
Doesn't
support audio and video
Doesn't
support client side scripting
In general,
text-based, printable content is more suited for PDF, while Flash is
better suited for interactive multi-media content.
Templates
Turbine
can use two types of templates where text, audio and visual media can
be integrated:
Common
Flash .swf movies generated by the Macromedia Flash authoring tool
or any other third party .swf authoring tools like Adobe's Live Motion
or Swish (although for Flash components, the Macromedia authoring
tool must be used).
By using visual editors one can enter the Turbine variables or commands
in the exact place and instant, simplifying content integration with
Flash rich media capabilities.
XML
templates can be used on situations where the flexibility and format-independence
provided by XML is preferable. Templates can be specified in the powerful
Turbine Media Markup Language (TMML or MML for short). Although on
this case visual media authoring is not available, one can take advantage
of all the benefits associated with XML.
On some
scenarios using visual templates is clearly advisable, for example if
the content is to be integrated on complex movies, with several scenes,
transitions or animation. On other scenarios, the simplicity and openness
of XML documents can be preferred.
And there are also scenarios where a mix of Flash and MML would be even
better - in fact this is also supported - MML commands can be issued
inside Flash .swf templates in a dynamic or input Text Fields - when
the Flash template is loaded, these MML commands will be executed in
the middle of the Flash .swf template. As we'll see, MML tags are pervasive
and can be used in a number of different places, inside the Turbine
engine.
Data
and Media Integration
Turbine
includes advanced data and media (image, audio, video) integration capabilities.
Data can be integrated into templates from the following sources:
Database
data sources like MySQL or ODBC RecordSets
Text
Files from local or remote HTTP locations
Variable=value
formatted text files from local or remote HTTP locations
XML
files, local or remote
Any
data available to PHP scripting
The following
types of media can be loaded:
Images
in PNG, GIF, BMP, TIF and JPEG formats, from local files or remote
HTTP locations
Audio
in MP3, WAV or FLV formats, local and remote
Video
in AVI, QuickTime MOV, FLV and Animated GIF formats, local or remote
All these
different data and media types can be combined and composed together,
to create rich media experiences.
Building
User Interfaces with Flash Components
Flash MX
introduced Flash components - reusable elements that simplify user interface
development in Flash media. Turbine 7 includes powerful component support
- components can be included and displayed where appropriated (either
in a Flash editor or on MML) and filled with any data accessible to
your script.
For example
- let's see how to display and fill a list box - on the Flash editor,
create an empty Flash movie and drag'n'drop a ListBox component, from
the Components panel (Flash UI Components area). Set its instance name
to (for example) "list". Then Save, for example as listbox.fla
and then Publish to listbox.swf. Next, create an PHP script with this
content, on the same directory :
<?
# create the turbine object:
$turbine = new Turbine7();
#
create a DataSet with some values:
$turbine->makeDataSet("listValues", "value");
$turbine->addDataSetRow("Red");
$turbine->addDataSetRow("Green");
$turbine->addDataSetRow("Blue");
$turbine->addDataSetRow("Crimson");
$turbine->addDataSetRow("Fuchsia");
$turbine->addDataSetRow("Cyan");
$turbine->addDataSetRow("Black");
$turbine->addDataSetRow("White");
#
select the Flash .swf template to use:
$turbine->load("listbox.swf");
#
pass the listValues DataSet into the component:
$turbine->injectData("listValues", "list");
#
now generate the movie to the web browser:
$turbine->generateFlash();
?>
After requesting
this script in a browser, we get a ListBox component, filled with the
values created on the script:
This way,
presentation and data can be cleanly kept separated - presentation on
the Flash .swf template (for which we could also have used a MML template),
while data is handled by the PHP script (we could have fetched data
from many other sources - database queries, XML, files, other HTTP queries).
Please
note that Flash components are not rendered nor work when exporting
to Adobe PDF.
The
Turbine Window
As a fact
of life, during the development process, errors inevitably occur - Turbine
communicates errors in two ways:
PHP
Scripting errors are displayed on the normal PHP way, in an HTML page
that the web server sends to the browser.
Template
errors on Flash or MML files are displayed right in the generated
Flash movie, inside the Turbine Window - which is a window that appears
on the generated movies with error and warning messages related with
template problems. When generating to PDF, these errors and warning
messages will appear in red on the top of the page. All the tag errors
are listed with the offending line number, for easier and faster problem
detection.
Besides displaying errors, the Turbine Window can also be used as
a Trace window and a mini-debugger (for variable watching). The Turbine
window looks like this:
The Turbine
Window is transparent and appears above the generated movie. In Flash
6+ movies, the last window location is automatically recorded and
reused. You can see this in action on the above Flash movie: move
the window and refresh the page, it will appear where you left it.
The button immediately to the right of the window title allows you
to display the contents of the last selected variable or object -
for example type _root in the Turbine Window, then select the word
_root with the cursor and click on that button - it will display the
variables and objects available inside the _root object.
The
source for the Turbine Window is included inside the installation
directory, on the debug.fla file, to be customized in any desired
way. For PDF output, the simple debug.mml file is used instead to
display error text.