Passing data with dynamic Frogans slides

Recuperating the data for rendering a second slide

How the data travels: In FSDL-Request documents

When Frogans Player requests a file to open up a slide, it creates an FSDL-Request document and sends it to the server hosting the Frogans site. Data, like “photo=cat.jpg”, gets to the server by means of being written into an FSDL-Request document.

To recuperate the data in an FDSL Request document, your requested file will need a PHP script for parsing FSDL-Request documents. The OP3FT has written the necessary PHP classes in a document, called “FsdlRequestParser.php,” which you can upload to your hosting server for including it in any file that needs to parse an FSDL-Request document. You can download a copy of it here.

FsdlRequestParser.php will allow you to parse file data, session data and entry data. For now we’re just going to see how to parse file data.

Upload “FsdlRequestParser.php” to your hosting server

Upload the contents of this ZIP file to the server where you host your Frogans sites. When you open up the ZIP file, you’ll see a folder called  “private” which contains the FsdlRequestParser.php file. It’s best to put that folder in the same directory that contains the folders for your individual sites. This way, it can be available for all of your hosted Frogans sites.

Setting up your FSDL document to parse the data

Be sure that your FSDL document is saved on your server with the “.php” extension (like “photoslide.php”). Start off your document with a block of PHP for your XML header declaration. You can include the FsdlRequestParser.php file in this same block of PHP:

<?php
print("<?xml version='1.0' encoding='utf-8'?>"); 


// Include FSDLRequest class

    include_once('../private/FsdlRequestParser.php');    // The file should be located outside the server's document root

?>

(Note that the path “../private/FsdlRequestParser.php” requires that the file be in the folder “private” that is located at the same level as the current folder.)

Insert the following into your PHP code in order to get content of the HTTP body received by server…

 $serverRequestBody = file_get_contents("php://input");

…to create and initialize the object $fsdlRequest…

$fsdlRequest = new FsdlRequest();

    $fsdlRequestDocumentVersion = FSDLRequestDocumentVersion::VERSION_3_0;
    $receivedDocument = $serverRequestBody;
    $errorMessage = "";
    
    $result = $fsdlRequest->initialize($fsdlRequestDocumentVersion, $receivedDocument, $errorMessage);

… and then finally to get all available file data from $fsdlRequest…

$fileFields = $fsdlRequest->getFileFields();

For the purposes of this tutorial, the chunk of code at the top of your FSDL document (“photoslide.php”) should look like this:

<?php
print("<?xml version='1.0' encoding='utf-8'?>"); 


// Include FSDLRequest class

    include_once('../private/FsdlRequestParser.php');    // The file should be located outside the server's document root

$serverRequestBody = file_get_contents("php://input");

$fsdlRequest = new FsdlRequest();

    $fsdlRequestDocumentVersion = FSDLRequestDocumentVersion::VERSION_3_0;
    $receivedDocument = $serverRequestBody;
    $errorMessage = "";
    
    $result = $fsdlRequest->initialize($fsdlRequestDocumentVersion, $receivedDocument, $errorMessage);
$fileFields = $fsdlRequest->getFileFields();

?>
The $fileFields array

What we end up with is an array, called $fileFields, that contains all of the file data sent by the previous slide. In the current example, if the user had clicked on the “cat” button this data would consist of the key-value pair “photo=cat.jpg.” By the same token, if the user had clicked on the “dog” or “frog” button, the key-value pair might have been “photo=dog.jpg” or “photo=frog.jpg.”

The important thing here is that $fileFields[“photo”] is interpreted to be “cat.jpg,” “dog.jpg” or “frog.jpg,”  depending on the button that the user pressed in the previous slide.

Using your data for dynamic content

In practical terms, when you choose the file of photo of the pet of your choice, instead of writing the static…

<file fileid='photo_f'  nature='static' name='/cat.jpg' />

…you can write the dynamic…

<file fileid='photo_f'  nature='dynamic' name='/<?php echo($fileFields["photo"]); ?>' />

While this looks like a lot of work for a small result…it can be. But then consider that instead of creating three destination slides, you have only created one. And when you make modifications to your slide(s), you only have to do that once for all three circumstances. Now imagine that that you had thousands of photos to show, instead of just three.

Be the first to comment

Leave a Reply

Your email address will not be published.


*