AMFPHP | Zend AMF service for connecting to Wordpress

For a project I have in development I needed to once again create or connect to a CMS.

I’ve previously rolled my own CMS using AMFPHP, which works fine. However, I thought I’d give using Wordpress a go as a CMS system for Flash sites, with an AMFPHP connection between Flash and the wordpress database.

I stumbled on Amfphp WordPress Integration (AWI) which seemed to offer what I was after. However, it has not been updated for a long time, and supports wordpress 2.3 or so and below. The project I have on needs to take advantage of wordpress’s tagging and categorising of content, which was the main element missing from the awi project. So, I re wrote it, and added in many more methods and dropped many of the existing ones.

You can view an example of it at work here: http://www.noponies.com/dev/cloud/ Which is using a hacked version of the WP-Cumulus Wordpress plugin, from here: http://www.roytanck.com/tag-cloud/. Instead of using a PHP method to create XML, I’m just using AMFPHP to call a getTagCloud method, and using the data in a similar fashion to how the WP-Cumulus Flash file works. Clicking on either a category (white text) or a tag (grey text) calls another method that pulls the various posts that are filed under that particular category or tag. Pretty simple stuff.

Ironically after embarking on this little project, I found a few other similar ones, this one (Flexpress) here by Jonnie Spratley which can be found here http://jonniespratley.com/blueprints/ and this swc library FlexDb from here: http://ghalex.com/blog/?p=53. Always annoying to re invent the wheel.

I’ve called my project, FlashPress, which is who I intended it to target (Flash devs) or people like me.

As of version 0.2 this also works fine with Zend AMF, and I’ll update the source file with some demos of connecting using Zend AMF.

Anyway, enough rambling, you can download the latest version (0.6) here;

Source Files Version 0.6
Flash Press 0.6 (173)

Let me know if there are bugs etc. I’m not really a PHP guy, nor a MYSQL guy, so I’m definitely interested in hearing about ways to improve things.

30 Neighs about “AMFPHP | Zend AMF service for connecting to Wordpress”



Nicolas Neighed:

Nice! I recently used WP as a backend for a Flash project; I ended up using the RSS feeds and Pages to parse the content.

Here’s another similar tool to grab content from Wordpress:
http://www.tvwonline.net/lab/pressconnect/

Dale Neighed:

@Nicolas,

Yeah, I was actually reading your posts about that today, when trying to sort out some class mapping issues with Zend. That approach looks nice. RSS is by far the most simple method to get content, although I think my service gives you are few other options.

Ruben Rojas Neighed:

This is awesome. I have 2 weeks thinking in a F;ash and Wordpress integration. Really interesting.

Ruben Rojas Neighed:

The link to download do not work.

Dimitris Neighed:

Hi, I get an error trying to d/l the source files. “Neigh, the page you requested has bolted”

Dale Neighed:

Hi,

Fixed that issue, should be working fine now.

Aaron Neighed:

Awesome. I had just started paying around with this myself. Nice job!

AWI Evoluciona | .:: klr20mg ::. Una dosis diaria de .... Neighed:

[...] Fork fue creado por Dale Sattler?Ǭ†?Ǭ†que en su blog nos cuenta de todos los [...]

sacen Neighed:

Anyone got this working ? I hope someone can write up a small step by step on this : )

Dale Neighed:

What can you not get working with it?

Trevor Neighed:

Very cool. I happen to be doing the exact same thing: WP CMS with flash frontend using AMFPHP so this was massively helpful! ty =D

Trevor Neighed:

has anyone tried to pull in media (jpg/png/flv) from the wordpress media library? I noticed the database doesn’t include asset urls, but wordpress environment provides functions for retrieving it… the problem is, the amfphp service doesn’t run in the WP enviro so you don’t get access to the url generating function ..

Dale Neighed:

@Trevor

Does getting the GUID of the media item in question not give you the URL to the actual item?

That is how the url is stored in the WP database, unless you are trying to access something else?

Trevor Neighed:

well, the GUID is formed like a url, but it’s only relative to the server you’re running wordpress on. i’m running WP in a test environment (http://localhost/), so when i push it to production all the guid urls won’t be valid. it should really only be used as a guid, not a url. digging around, i found the best way to get the actual URL (regardless of what server it’s running on) is to use the wordpress function:

wp_get_attachment_url( $postID )

so after much digging around in wordpress’s php spaghetti, i figured out the way to include the wordpress environment (making its functions available) in an amfphp service:

in amfphp/globals.php, include /pathtoyourwordpress/wp-blog-header.php at the end. so mine looks like:

require_once “../wordpress/wp-blog-header.php”;

now in FlashPressService, i modified the WpMediaVO to have a url property, and added this line to the parseMediaData function:

$mediaitem -> url = wp_get_attachment_url( $mediaitem -> id );

Brendan Neighed:

Good work, but, I hate to be the bearer of bad news, FlashPress already exists!!!

It’s in beta and will be released as an open source package in May.

http://www.flashpress.ca
http://www.flashpressdevelopers.com
http://www.twitter.com/FlashPress

Dale Neighed:

Yeah well, I’ll just change the name or something..

Liam R Neighed:

Hey Dale,

Just thought of a little improvement to your excellent class…

as well as having getPostOrPageByName – add getPostOrPageBySlug, which instead of looking for the posts name looks for it’s slug (the nice url text ie hello-world, rather than Hello World).

It’s just a matter of adding in

/**
* Get a post’s full data by the slug of the post. Returns single WpPostVO object. Only published posts or pages are returned.
* @param string $postName – Representing the slug of the post you wish to access.
* @return WpPostVO
*/
public function getPostOrPageBySlug($postName) {
$sql = “SELECT * FROM wp_posts WHERE post_status=’publish’ AND post_name=’$postName’”;
$p = $this->parsePostData($sql);
return $p;
}

Anyway… hope you’re move to the UK is going good! – If you ever make it up to Glasgow give me a shout.

Liam

Dimitris Papaevagelou Neighed:

Well, your code is absolutely fantastic. Very fast and very well written. Some changes that i made is for the comments, how to get and how to add. As for jpg or other media i used RegExp to extract from evry post the media. As for the slug i prefferd to use the post name and then parse it with RegExp. Congrats!

Dale Neighed:

@Trevor,

I’ve finally had time to do some more work on this class. Integrating with wordpress’s native API is probably how I’ll move this forward. With the addition of some new methods where I think the native ones are lacking etc.

Dale Neighed:

@Liam,

Cheers for that snippet, I’ll add it to the class.

Import your Wordpress blog into Flash « BC BLOG Neighed:

[...] Download the code here: flashpress-src For further information visit: noponies [...]

James Neighed:

Hey, I was just wondering if you were still moving forward with using wordpress’ native API?

If not, I would be willing to take over and move forward with it. Let me know!

Dale Neighed:

@James,

Yeah, thats the plan. I’ve been doing a lot of wordpress theme and blog development work of late, and in doing so, have spent a lot of time working with the wordpress api. I definitely think that using the wp api is the way forward. I’ve got a big Flash / Wordpress integration job coming up that I’m going to be using AMFPHP for, so in doing that, I’ll update these files to use the native wordpress api.

That will happen over the next 3-4 months. You are welcome to take the code and make something new etc.

John Cardwell Neighed:

Hey – awerserm. Thanks for posting this!
Can you elaborate more on the Wordpress API. Where can one get documentation for this API? I’m looking to build a front end in flash with a WordPress CMS, too.

Dale Neighed:

Just go look at wordpress.org, in particular the http://codex.wordpress.org/Developer_Documentation All the various methods you can use are listed there. Flashpress at present does not integrate into the wordpress api, it instead directly operates on the wordpress database, using calls that are replicas of the internal wordpress calls. I do however intend to move it to using the internal wordpress calls. I just will have to spend some time getting the class mappings right, between the objects returned via amfphp and the corresponding actionscript objects.

James Neighed:

awesome man! thanks for the info. I started chopping and hacking and testing. I have a smaller sized project now that I think I am going to use the API as well. The reason I asked is because after this project, I was thinking of developing a more robust solution than the small portion of the API that I will be using but I didn’t want to if you are already in the process. Mainly because ‘why reinvent the wheel’ but also I am not a PHP programmer so I figure you would be able to do a much better job. So, for now my hack ‘em up solution will do but would love to see your finally project. I will check back occasionally. Thanks for the original files though. So far the best solution I have come across. Cheers!

Sean Neighed:

Is there any way we could get this framework to work with wordpress MU??

Now that would be extremely handy right now….
Wordpress MU assigns unique blog id’s to database tables and I would like to build some flash widgets that pull data unique to the logged in user. The flashpress framework is pretty hardcoded in regards to the sql queries.

Have u had any ideas about this Dale? Anyone?

Sean Neighed:

We would like to hire you if you’re interested in the dev of a working framework for Wordpress MU. Interested??

Please let me know as soon as possible…thanks!

Dale Neighed:

Its just a matter of moving the framework to use the internal wordpress methods to return results from the database, rather than operating on the database directly, like it does now.

It’s on the roadmap to do, but I’m struggling to find the time to make the changes.

greg Neighed:

My english is terrible so I won’t be long : THANK YOU!

Leave a neigh?