[solved] How to get a list of G2 image URL's? Like external Image block but only the URL

dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Tue, 2009-07-21 12:41

Hi there,

for my G2 integration I could really do with a simple list of URL's of one or more images of my Gallery 2.
Basically what I need exactly is a XML list that looks like this:

<images>
<image href="http://url.to.gallery/album1">test1.jpg</image>
<image href="http://url.to.gallery/album2">test2.jpg</image>
<image href="http://url.to.gallery/album3/subalbum1">test3.jpg</image>
</images>

So basically

http://url.to.gallery/album1/test1.jpg
http://url.to.gallery/album2/test2.jpg
http://url.to.gallery/album3/subalbum1/test3.jpg

are random URL's taken from my gallery.

Of course it would actually be sufficient to be able to retrieve the simple "random picture url" and process it with PHP to be put in above format.

I could archieve that by using the @readfile(external image block) thing and then use a lot of PHP to filter the URL - but maybe there is an easier way??

Cheers

Felix

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 7892
Posted: Tue, 2009-07-21 13:17
 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Tue, 2009-07-21 13:27

Thanks, I'll look into it

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Tue, 2009-07-21 14:23

Actually I solved it now the way I first thought - thanks anyway for your help, yours is probably the cleaner solution.

If anyone is interested, that's the code I use:

<?php
$code = file_get_contents('http://gallery.felixsalomon.net/main.php?g2_view=imageblock.External&g2_blocks=randomImage|randomImage|randomImage|randomImage&g2_show=none&g2_maxSize=60&
g2_itemFrame=none');
$regex = '=^(.*)(<img|<image)(.*)src\="?(\S+)"([^>]*)>(.*)$=msi';
$xml = '<images>'. "\r\n";
$i=0;
while (preg_match($regex, $code, $finds)) { 
  $xml .= '<image href="' . dirname( $finds[4] ) . '">' . basename( $finds[4] ) . '</image>' . "\r\n" ;
  $code = $finds[1];
}
$xml .= '</images>';

$file = fopen("file.xml", "w");
fwrite($file, $xml);
fclose($file);
?>

It gives me a file which contains a simple xml list:

<images>
<image href="http://gallery.felixsalomon.net/d/7530-2">273_IMG_4555.jpg</image>
<image href="http://gallery.felixsalomon.net/d/7443-2">238_IMG_4398.jpg</image>
<image href="http://gallery.felixsalomon.net/d/746-2">P7220744.JPG</image>
<image href="http://gallery.felixsalomon.net/d/9129-2">fraser_029.jpg</image>
</images>

Cheers

Felix