HowTo: Use "Photowidget" by RoyTanck with G2

dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Wed, 2009-08-05 13:02

Hey there,

just thought I might share some stuff I came up with recently.

Photowidget is a nice flash app to display images on your webpage. In combination with the external image block you can actually use it with your gallery. That's how I got it to work:

/* settings */
$g2_url = 'www.mygallery.com';              // url to main.php
$thumb_size = 60;                           // thumbnail size in pixel
$images = array ( 'randomImage'   => 12,    // number of types of images
                  'recentImage'   => 0,
                  'viewedImage'   => 0,
                  'randomAlbum'   => 0,
                  'recentAlbum'   => 0,
                  'viewedAlbum'   => 0,
                  'dailyImage'    => 0,
                  'weeklyImage'   => 0,
                  'monthlyImage'  => 0,
                  'dailyAlbum'    => 0,
                  'weeklyAlbum'   => 0,
                  'monthlyAlbum'  => 0,
                  'specificItem'  => 0 );


while( list ( $type, $count ) = each ( $images ) ) {
  for($i = 0; $i < $count; $i++) {
    $image_list .= $type . '|';
  }
}
$image_list = substr($image_list, 0, -1);   // get rid of trailing '|'

/* create source code */
$code = file_get_contents('http://' . $g2_url . '/main.php?g2_view=imageblock.External&g2_blocks=' . $image_list . '&g2_show=none&g2_maxSize='. $thumb_size .'&
g2_itemFrame=none');

/* regex rules */
$regex_image = '=^(.*)(<img|<image)(.*)src\="?(\S+)"([^>]*)>(.*)$=msi';
$regex_url = '=^(.*)(<a)(.*)href\="?(\S+)"([^>]*)>(.*)$=msi';

/* start creating xml content */
$xml = '<images>'. "\r\n";

while (preg_match($regex_url, $code, $finds_url) && preg_match($regex_image, $code, $finds_image)) { 
  $xml .= '<image href="' . $finds_url[4] . '">' . $finds_image[4] . '</image>' . "\r\n" ;
  $code = $finds_url[1];
}

$xml .= '</images>';

/* write xml file */
$file = fopen("photowidget.xml", "w");
fwrite($file, $xml);
fclose($file);

This piece of code only creates the required photowidget.xml, using pathnames from the external image block. You still have to embed the actual flash file acording to the instructions on the widgets homepage.

Maybe someone finds it useful.

Cheers,
Felix

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Wed, 2009-08-05 13:10
 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Wed, 2009-08-05 14:56

See it in action here.

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Wed, 2009-08-05 16:35

You could easily modify the xml generator found in my minislideshow to feed the PhotoWidget or even the feed generator in my SlideshowPro -> Gallery2 script.
It would lend the ability to display dynamic albums like tag albums or keyword albums as well as the usual types.

-s
FlashYourWeb and Your Gallery with The E2 XML Media Player for Gallery2

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Wed, 2009-08-05 16:43

That's what I forst wanted to do. I tried after you had mentioned your script a while ago - but somehow I didn't quite understand where to start :-(
Might have a closer look again at some point

Felix

 
nivekiam
nivekiam's picture

Joined: 2002-12-10
Posts: 16504
Posted: Wed, 2009-08-05 18:13

Thanks, added: http://codex.gallery2.org/Gallery2:User_Contributions#Mods.2FPatches
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here

 
lucasmarin
lucasmarin's picture

Joined: 2010-07-14
Posts: 37
Posted: Sun, 2010-07-25 02:14

Hi! Its very interesting. But how exactly do you get it to work?
I mean, is that the code that goes IN the .xml file? Or is that php code that goes somewhere else?
Can you be more specific?
Thank you!

http://www.lucasmarin.com

 
suprsidr
suprsidr's picture

Joined: 2005-04-17
Posts: 8339
Posted: Sun, 2010-07-25 04:19
 
lucasmarin
lucasmarin's picture

Joined: 2010-07-14
Posts: 37
Posted: Sun, 2010-07-25 04:25

Hey Suprsidr! Thanks for the reply. Yes i have. As a matter of fact, i am using the miniSlideshow in my main page, but i really liked the photowidget. Is a really good alternative to a tag cloud i think.
But no matter what, i coudlnt make it work. I am definitely doing something wrong.
Any ideas?

http://www.lucasmarin.com

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Mon, 2010-07-26 04:08

Hi lucasmarin,

this code has to go somewhere in your homepage's php code, e.g. in my Wordpress blog I put it in the sidebar. The XML file gets then created int he same directory as the script is located in (unles you change the path in the last lines).

I actually made a widget for it, too, in case you use wordpress.

 
lucasmarin
lucasmarin's picture

Joined: 2010-07-14
Posts: 37
Posted: Mon, 2010-07-26 05:18

Hey Dreamingof8a! Thanks for the reply.
I put the code, and its generating the photowidget.xml file, but its generating it empty, with just "<images></images>".
That is when i try it in localhost. When i tried online, it didnt generate a file at all.
In $g2_url i used localhost when i tried it here, and www.lucasmarin.com when i tried it online.
Any ideas what am i doing wrong?

http://www.lucasmarin.com

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Mon, 2010-07-26 05:42

Hmm, not sure. Does the image block get generated if you just call it the normal way? And if you replace the line in my script where the imageblock url is created, with the standard call, does it work then? I remember having trouble with the whole file creation but it somehow it ended work out. But the fact that the file is created and has content looks like it's a problem with the regex and/or imageblock creation itself.
Maybe my piece of code below helps you to identify an arror? As fro not working on your actual site, I think it might have to do with the paths. for fopen you need the system path rather than the url, see in my code.

Quote:
/* write xml file */
if ($file = fopen("/www/htdocs/was63ad7/_blog/wp-content/themes/currenttheme/photowidget.xml", "w")) {
fwrite($file, $xml);
fclose($file);

}
?>

<script type="text/javascript" src="http://blog.felixsalomon.net/wp-content/plugins/fs_wp-g2-photowidget/swfobject.js"></script><div id="wpg2photowidgetcontent">
<script type="text/javascript">var photowidget = new SWFObject("http://blog.felixsalomon.net/wp-content/plugins/fs_wp-g2-photowidget/photowidget.swf", "photowidget", "160", "160", "9", "#C4CBD2");
photowidget.addParam("allowScriptAccess", "always");
photowidget.addParam("wmode", "transparent");
photowidget.addVariable("feed", "http://blog.felixsalomon.net/wp-content/themes/currenttheme/photowidget.xml");
photowidget.write("wpg2photowidgetcontent");</script></div>

 
lucasmarin
lucasmarin's picture

Joined: 2010-07-14
Posts: 37
Posted: Tue, 2010-07-27 01:25

Hey dreamingof8a. I finally got it working, but in the strangest way. Maybe you can explain me why.
The .xml file is generated if i put it in a file like "test.php" which is outside the gallery folder and i call it with a line like "require_once('...\public_html\test.php');".
But if i put that code inside lets say Theme.inc or main.php, it does not work.
Does it have to do something with the way you are calling the imageblock?

http://www.lucasmarin.com

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Tue, 2010-07-27 06:06

I'm glad it works now ... no idea why though :-) The way I'm calling the image block should be the same as you would call it from anywhere ...
But I remember that I had similar problems, but the other way around - I wanted to use an external file but couldn't ...