DesignFission

Flash, Web, Javascript and everything else

Posted on by Edwin


Just going to paste a quick code snippet here. Hopefully, this is part one of a series of tutorials/snippets to show you how to use WordPress as a CMS to power a Flash frontend photo gallery.

All you need to do is to to upload this file into the wp-content/plugins/nextgen-gallery/xml folder.

Code here:

<?php

/*

//----------------------------------------------------------------+

 CUSTOM XML FOR NEXTGEN GALLERY
 By Edwin Toh (www.designfission.com)

//----------------------------------------------------------------+

*/

if ( !defined('ABSPATH') ) 

    require_once( dirname(__FILE__) . '/../ngg-config.php');

global $wpdb, $ngg, $nggdb, $wp_query;

$gallerylist = $nggdb->find_all_galleries('gid', 'asc', TRUE, 25, $start, false);

$ngg_options = get_option ('ngg_options');

$siteurl	 = site_url();

// get the gallery id

$galleryID = (int) $_GET['gid'];

// get the pictures

if ($galleryID == 0) {

	$thepictures = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 ORDER BY tt.{$ngg_options['galSort']} {$ngg_options['galSortDir']} ");

} else {

	$thepictures = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE t.gid = '$galleryID' AND tt.exclude != 1 ORDER BY tt.{$ngg_options['galSort']} {$ngg_options['galSortDir']} ");

}

// Create XML output

header("content-type:text/xml;charset=utf-8");

echo "<album>\n";

$gallerylist = $nggdb->find_all_galleries('gid', 'asc', TRUE, 0, 0, false);

if($gallerylist) {
	foreach($gallerylist as $gallery) {

		$class = ( !isset($class) || $class == 'class="alternate"' ) ? '' : 'class="alternate"';
		$gid = $gallery->gid;
		$name = (empty($gallery->title) ) ? $gallery->name : $gallery->title;
		$author_user = get_userdata( (int) $gallery->author );

		$picturelist = $nggdb->get_gallery($gid, $ngg->options['galSort'], $ngg->options['galSortDir'], false, 50, $start );

		echo "	<gallery>\n";

		echo "		<title>".stripslashes($name)."</title>\n";
		echo "		<description>".$gallery->galdesc."</description>\n";

		if (is_array ($picturelist)){

			foreach ($picturelist as $picture) {

				echo "		<image>\n";

				echo "			<title>".$picture->alttext."</title>\n";
				echo "			<description>".$picture->description."</description>\n";
				echo "			<url>".$siteurl."/".$picture->path."/".$picture->filename."</url>\n";
				echo "			<thumbnail>" . esc_url(nggGallery::i18n($picture->thumbURL)) ."</thumbnail>\n";

				echo "		</image>\n";

			}

		}

		echo "	</gallery>\n";

	}

}

echo "</album>\n";

?>

Posted on by Edwin | Posted in PHP


About Edwin

I do code.

15 Responses to NextGEN Image Gallery WordPress Plugin – XML Output

  1. casey yee says:


    This is exactly what i’m looking for, but once i install it, how do i use it? presumably i enter a url of sort to get the xml output? please let me know!

    thanks


  2. casey yee says:


    Looks like i have gotten this to work now by using:

    /wp-content/plugins/nextgen-gallery/xml/xml.php

    Looking at the code, i should be able to pass it a querystring ?gid=[galleryid], but it doesn’t seem to do anything to the output. i get the same xml as i would without the querystring parameter.

    am i missing something?

    Thanks again!


  3. Edwin says:


    Hi Casey, glad that this helped you, but I’ve since moved on to using another method to retrieve the same information. Take a look at this post: http://www.designfission.com/blog/2010/09/29/tutorial-flash-and-wordpress-part-1/

    Cheers,


  4. casey yee says:


    i’ll take a look at the article. thanks again


  5. Wordpress Plugin says:


    You saved my lots of time edwin thanks for this cool tutorial.


  6. Ferdi says:


    Hi Edwin,

    I know you’ve moved on from this, but I have an AS2 project that I’ve got loading Nextgen Gallery data using your script. It works great, the XML is formatted exactly like I need it. The only thing is that it doesn’t stop at the end of an album, but continues loading all the galleries from every album.

    Could you perhaps show me how I can limit it to only provide galleries XML for a given album id? i.e. “aid=1″ that’s all I need.

    Thanks in advance


  7. Edwin says:


    Hi Ferdi, Please read my other article http://www.designfission.com/blog/2010/09/29/tutorial-flash-and-wordpress-part-1/ to find out how to selectively retrieve content from WordPress.


  8. Ferdi says:


    Hi Edwin, thanks for the response. I tried the Flash API plugin, but It’s giving me an invalid API key error, even though I’m using the correct API key.

    Anyway, seeing as how my gallery is AS2, wouldn’t the AS3-based Flash API give me problems even if the API key error goes away?

    I’ve tried a few options, but your custom XML php script is the closest I’ve gotten, except for not being able to specify an album.


  9. Ferdi says:


    Hi Edwin, thanks for the reply. I see that option requires the Flash API plugin for WordPress. What I’m looking for is just a database query that would return XML formatted as your above script does, but with the added ability to display results by Album (“aid”).

    Flash API gave me an “Invalid API Key” error…
    If possible, I would prefer just a PHP script rather than an addditional plugin dependancy.

    Would this require a PHP developer or is there an existing PHP script like your xml.php or imageRotator.php that lists galleries by album id?


  10. Edwin says:


    Hi Ferdi, I remember facing some problems extracting a specific album with this, hence I switched to the other plugin. You can extract more than gallery images with the Flash API plugin – i.e. posts.


  11. Ferdi says:


    Thanks, I’ll give the Flash API another shot.


  12. aditya says:


    Nice Article edwin…me webdeveloper passionate about advertising like you


  13. Edwin says:


    Thanks aditya. Glad you liked the article. :)


  14. arne says:


    thanx for this article – it helped me a lot


  15. Shahar says:


    Hi,

    I use your XML output. I am trying to make a nextgen image map with your script.

    I found that i cannot retrive a specific ID of a gallery, i tried to played with it but i am missing something. could it be that the “gid” just disapear in the query.

    I tired to put a value (like 128) as a gallery that i have in the site, and still not working.

    Could you please tell me how can i solve this. i am promise that i will credit you on the nextgen image sitemap.

    Thanks
    Shahar


Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>