Sample code to get albums and photos in PHP, without HTML?

mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Wed, 2006-02-22 19:54

Hi all:
I'd like to build a small sample of retrieving a list of albums and photos from those albums, and display them in an Adobe Flex application (using the Flash player), as opposed to HTML. To do this, I only need to get the albums and photos into a PHP variable, as opposed to getting the HTML that would display the photos.

Is there any sample code showing me how to do that? I've had a look around, but can't seem to find it.

Thanks,

Mike

Mike Potter
Web and open source evangelist, Adobe Systems Inc.

 
h0bbel
h0bbel's picture

Joined: 2002-07-28
Posts: 13451
Posted: Wed, 2006-02-22 20:14

There is probably a better way, but you could possibly use the RSS feed and parse that?

Adobe hmm, that looks interesting. How about a "web album" export plugin from Photoshop -> Gallery 2 ? ;-)


h0bbel - Gallery Team
If you found my help useful, please consider donating to Gallery
http://h0bbel.p0ggel.org

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Wed, 2006-02-22 20:22

Yes, I could use the RSS feed, but I'm hoping to show deeper integration with the PHP code... There's already examples out there of how Flex can consume RSS feeds, and wanted to show something a bit deeper.

I'd love to talk to someone about an export plugin from Photoshop to Gallery, but I'm a web developer, not a plugin developer. Feel free to contact me if you're interested in building something.

Mike

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-02-22 21:39

hmm, just googled the Flex stuff, it's the first time i heard of it. i'm not a flash person. if i understand correctly, it's a product line (development tools, libs, framework, etc) around Flash and doesn't do anything server-side.

if i understand correctly you want to create a Flash front-end for Gallery 2. we're all for it of course :)
we had a student working on such a thing during the the last google "summer of code" program. the goal was a to create a Flash theme for G2. themes are our front-end layer. they are responsible to render the content. they receive all the template data and can do anything with it.
so a flash theme would receive the template data and feed a Flash script with this data. via xmlhttprequest etc the flash script can then fetch new data in the background.
that's the theory. the result of the summer of code project was sadly not much more than a proof of concept. i'm not even sure if it was finished completely.
http://www.openlaszlo.org/ was chosen for the project and the results can be found here:
http://cvs.sourceforge.net/viewcvs.py/gallery-contrib/g2_themes/fluid/

I think it was the right direction, just build a flash based theme. it's the right point to add a flash front-end.

an alternative would be to use GalleryEmbed to initialize G2 and instead of doing the normal request handling, use only API methods to assemble everything yourself. e.g. GalleryCoreApi::fetchAlbumTree() etc.
but note that you can use these API methods in the theme approach too. i'd say GalleryEmbed is clearly not the right if you don't call GalleryEmbed::handlerequest() since you'd then lose the whole request handling of G2 (controllers / views). i just wanted to mention GalleryEmbed for completeness.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-02-22 21:45

maybe you don't want just a flash front-end for G2. maybe you want it just as a component of a larger flash application.
if so, you'll want to use GalleryEmbed. GalleryEmbed::handleRequest() returns the rendered HTML as well as the whole template data, ready to be rendered by your Flash stuff.

http://codex.gallery2.org/index.php/Gallery2:Embedding

ps: when do we get a CLI tool to generate jpeg thumbnails for flash movies? ;) we can generate thumbnails for pretty every format including movies and PDF documents, but there's no way for us to generate thumbnails from flash movies.

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Wed, 2006-02-22 22:04

valiant:
The Flex stuff is pretty exciting, very similar to what openlaszlo does, but inside an Eclipse based IDE (called Flex Builder). There's an enterprise data services portion as well, but that's a seperate product. Flex Builder is all you need to build a Flash application (without having to work in timelines).

You've given me some good pointers. I think GalleryEmbed is the way to go, I just wish there was some documentation or sample code oon methods like fetchAlbumTree that I could take a look at.

I'll look into a CLI to generate JPEG thumbnails for Flash movies. I'm from Adobe, not MM, so I've only been allowed to work with that product for a few months. :)

Mike

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2006-02-22 22:30

there's the phpdoc generated API docs http://gallery.menalto.com/apidoc/GalleryCore/Classes/GalleryCoreApi.html and the above embedding link gives an overview of the embedding perspective.
the sample wrapper script in the embedding docs shows the usage of GalleryEmbed::init and GalleryEmbed::handleRequest. I suggest you just grep / look at some G2 files to see how to use G2 functions. all methods are documented (arguments, return value) and the error status handling is always the same.

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Thu, 2006-02-23 18:28

valiant:
Thanks for the help so far. I find the APIs confusing, but I'm starting to get the hang of it.

I've got a Flash app that displays a drop down of my photo albums, now I just need to get the photos from the albums... I can't find the API that returns to me a list of photos, given the ID of the album. Any pointers?

BTW: No luck yet on tracking down a CLI to do thumbnails. Someone remembers something from a long time ago, but its unlikely that we'll find that utility. I'm still looking though.

Thanks,

Mike

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2006-02-23 19:26

i'm not quite sure why you are now using API calls only since GalleryEmbed::handleRequest() would do the whole requesting handling, show item pages / album pages, pagination, and really a lot more for you. you can still control the front-end since you decide yourself how you render the returned template data.

but ok, here's what you asked for:

 /* from modules/core/classes/GalleryTheme.class around line 860 */
                        list ($ret, $childIds) = GalleryCoreApi::fetchChildItemIds($item);
			if ($ret) {
			    return array($ret->wrap(__FILE__, __LINE__), null);
			}
...
        if (!empty($childIds)) {
	    list ($ret, $childItems) = GalleryCoreApi::loadEntitiesById($childIds);
	    if ($ret) {
		return $ret->wrap(__FILE__, __LINE__);
	    }
	}
...
/* and then you can do stuff with childIds, e.g. render them, get the url to the image with */
global $gallery; 
$urlGenerator =& $gallery->getUrlgenerator(); 
$url = $urlGenerator->generate(array('view' => 'core.DownloadItem', 'itemId' => '$childItem->getId()), array('forceFullUrl' => true, 'htmlEntities' => false));
/* etc. */

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Thu, 2006-02-23 19:45

Does handleRequest not return HTML? I don't want HTML, I just want PHP information, then I'm going to pass the PHP through AMFPHP to the Flash front end, and build my own Gallery viewer in Flash. I'll have to handle pagination in my Flash app, as opposed to the backend.

I should have something to show off later today or tomorrow.

Thanks for that code... Very helpful.

Mike

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Thu, 2006-02-23 21:34

valiant:

Just a quick note of thanks for helping me out.

I've now got a Flash based front end to my local install of Gallery (see attachment). Its basic right now, but I'm hoping to release the code, and then get others to work on it and improve it. Currently, the app populates a drop down menu of your albums (I'll probably convert this to a tree rather than a drop down, since you can have nested albums (not currently supported in my app)) and then shows you a grid of your photos from that album. Plain and boring, but nice to know that I built something in about 6 hours that connects to Gallery and shows photos in a Flash interface. (Most of the time was spent learning Flex and the Gallery APIs).

I'll clean up the code in the next day or so and want to post it. What's the best spot to post code so others can start working on it too?

Thanks!

Mike

Web Evangelist, Adobe Systems Inc.

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Thu, 2006-02-23 21:37

Woops, didn't attach...
Let's try that again. Two images, one Gallery-Web to show the website view, and the other Gallery to show the Flash view.

Mike

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2006-02-23 21:50
mikeypotter wrote:
Does handleRequest not return HTML? I don't want HTML, I just want PHP information, then I'm going to pass the PHP through AMFPHP to the Flash front end, and build my own Gallery viewer in Flash.

in G2.1 (opposed to G2.0.2), GalleryEmbed::handleRequest() not only returns headHtml, bodyHtml but also templateData which is basically just a nested data structure of all data required to render your page in Flash.

also, i'd like to emphasize that GalleryEmbed is only recommended if you actually integrate G2 as a part of a bigger framework / application. If all your flash front-end does is present G2 and a GUI to it, then i strongly recommend the theme approach that was chosen for the summer of code project with openlazlo.

6h? sounds productive :)
i sure look forward to a nice flash front-end. i'm adding some websites for inspiration to http://codex.gallery2.org/index.php/Gallery2:Theme_Ideas and there are right now 2 flash based websites that are pretty awesome. i'm sure one could do the same with g2 and a flash theme.

the best place to publish your code is http://codex.gallery2.org/index.php/Gallery2:UserContributions (everyone can edit the codex once you're registered there). and if you plan to continue to develop this flash g2 integration, we can give you a cvs / svn account for sf.net/projects/gallery-contrib .

 
Banta

Joined: 2006-04-18
Posts: 35
Posted: Tue, 2006-04-18 03:04

Hello,

I'm new here and this is my first post. I came across this by googlin for a Flex Photo gallery sollution. Your posted images are definately the path I am looking for. Being new to Flex and Gallery, I am blown away at all the features possible with gallery. This is beyond anything I had hoped for in a gallery managment system.

Anyway, can you post some code or samples on how you were able to get the basics into your Flex application. Point me in the right direction and I'll be a happy camper.

Looking forward to your response and any advice you can give me to get me started. I know little about any of this but, getting my info into a Flex app is going to be a huge step for me.

Thanks in advance
___________
Banta

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Tue, 2006-04-18 20:22

I do have some sample code that I could post, but its nowhere near complete. The main problem right now is getting access to a public server that has Gallery installed and where I can put my code. I'm working on that, it'll likely be May when that's done.

I'm happy to email you the code directly if you want to try it out, but you'll need experience with Flex, Gallery and AMFPHP in order to get started. Contact me at

if you'd like it.

Mike

 
mikeypotter

Joined: 2006-02-22
Posts: 12
Posted: Fri, 2006-05-12 15:21

I've updated the code for Flex Beta 3. The code, a screenshot and instructions on how to get started are on my blog at http://blogs.adobe.com/mikepotter/

AMFPHP is required to get this working properly, so there is a dependency on external software.

Mike

 
geezee

Joined: 2006-06-11
Posts: 4
Posted: Sun, 2006-06-11 19:19

Hey all, I jsut registered to the site so I maybe could help some Gallery 2 junkies. Quite awhile back I spent an afternoon playing with some flash components and data connectors in order to display Gallery 2 images with as little code as possible. I am not a big fan of the Flash business components but still like to challenge myself on a lazy Sunday. I wrote a small bit of actionscript and hoooked up the components to a modified version of the rss.php file (packed in posted archive as rss1.php & rss2.php). I do not remember exactly what I changed in the rss1.php file, but it was something small about how id for the existing galleries are returned. The rss2.php jsut builds the return of thumbs when a specific gallery has been selected. I am sure you could take the rss.php and do a difference on it to see. you will also need to put the regExp class in a namespace of com.general, or change it. I can easily make this even simpler now but here are the files now for anyone who wants them in the state they are.

Anyways, I was looking today to see if anyone has built something in Flash and still not much is out there. I saw the Flex example but Flex may not be so easy for some to use. So I thought I owuld post my files and hope that maybe they can help someone.

I have also decided to use my own components set to write a new and skinnable Gallery 2 component for free use (was my original plan way back). I have used Gallery 2 for a long time and it is the least I could do for the community. Well I love Gallery 2 ( as does my wife) and hope it sticks around for years to come.

http://fundamentalflaws.com/Gallery2_flash.rar

 
JohnnyC

Joined: 2006-08-22
Posts: 22
Posted: Sun, 2008-08-31 17:44

I've contacted mikeypotter, and he's informed me that his samples are no longer available. If anyone happened to download it, please make it available somewhere. Also, the link to the files from the previous post seem to be dead. Anyone know where I can get them now? Thanks!