Building Blocks

27Sep/093

SlideshowPro Director via AMFPHP

I really like SlideshowPro Director. With version 1.0.9.9 and below, you could simply access it as an XML service. This was great. Very fast. Past that they reworked the application and introduced an API. This is probably a good move for many, but the API is geared towards PHP websites that want to utilize SSP Director for html/js/css purposes. What I need to do is access the resources through Actionscript 3. My first thought was use AMFPHP and simple access the API through PHP that way, but when accessing the API that way, it was dreadfully slow. It would pause while loading for a good 10 seconds sometimes. The overhead of the PHP backend and the API just don't cut it for use as an Actionscript service.

The solution was to simply skip the middle man and go at the database directly. Now it is lightening fast using this AMFPHP service endpoint:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class GalleryService
{
 
    function GalleryService()
    {
        $this->methodTable = array
        (
            "getAlbumById" => array
            (
                "access" => "remote",
                "description" => "Pings back a message"
            )
        );
    }
 
    function getAlbumById($albumNumber)
    {
		$dbhost = 'YOUR_MYSQL_HOST';
		$dbuser = 'YOUR_USER_NAME';
		$dbpass = 'YOUR_PASSWORD';
                $dbname = 'YOUR_SSP_DATABASE_NAME';
		$result_array = array();
		$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                      ('Error connecting to mysql');
 
		$dbname = 'slideshow';
		mysql_select_db($dbname);
                //be sure to guard against injection by casting the album id to int (thanks Shaun!)
		$query = "SELECT * FROM ssp_images WHERE aid=" . (int) $albumNumber;
 
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result)){
			$result_array[] = 'YOUR_PATH_TO_SSP_ROOT/albums/album-' . $row['aid'] . '/lg/' . $row['src'];
		}
		mysql_close();
 
        return $result_array; //an array of url strings
    }
}
?>

There are all sorts of options you could do for this. You could set up value objects and send those back to Flash. All I needed for my purposes was the array of url strings. Simple, fast, and effective. Now we can manage our galleries with Director, and are free from the constraints of the official SlideshowPro for presentation.

What I really want is an official AMF service through Director. They are using CakePHP, and there are AMF solutions for that. Hopefully that would supply a fast, officially sanctioned AMF solution. Until than, the above works just fine.

Creative Commons License
The SlideshowPro Director via AMFPHP by Joel Hooks, unless otherwise expressly stated, is licensed under a Creative Commons Attribution 3.0 United States License.
  • dert

    [info] You have got an error in RSS so I'm unable to subscribe to your blog. Probably because of closing CDATA tag before ending html script tag.

  • dert

    [info] You have got an error in RSS so I'm unable to subscribe to your blog. Probably because of closing CDATA tag before ending html script tag.

  • Kristoferjoseph

    You have a typo in line #27 You should not be resetting $dbname to the string 'slideshow'.
    Delete that line and the script is perfect