TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

Members
Stats
  • Total Posts: 195,994
  • Total Topics: 21,325
  • Online today: 97
  • Online ever: 8,223 (February 19, 2025, 04:35:35 AM)
Users Online
  • Users: 1
  • Guests: 84
  • Total: 85
  • @rjen

[Block] Code to display image RSS feeds from Flickr, Picasa and Photobucket

Started by PeterLawrence, November 23, 2008, 10:19:12 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

PeterLawrence

Here is some code I've been using to display image feeds from Flickr, Picasa and Photobucket.
It works by scanning the RSS feed for the description fields and displaying the data (images and text) in a table.
I've included an example RSS feed for each photo gallery type in the $feedurls array, see top of code.
To obtain your own feed URL go to your gallery system, select your required photos and then click on the RSS symbol. This should give you an URL which then can be used in the $feedurls array in this PHP code.
Note this code only works with PHP version 5.
Example output provided in attached jpeg (see bottom of post).

// list your Picasa, Flickr and Photobucket RSS feeds here
$feedurls=array(
'http://api.flickr.com/services/feeds/photos_public.gne?id=31558111@N08&lang=en-us&format=rss_200', // flickr example
'http://feed123.photobucket.com/albums/o282/rszczepanski/Tryweryn280707/feed.rss', // photobucket example
'http://picasaweb.google.com/data/feed/base/user/junk.Jonandteresa?alt=rss&kind=album&hl=en_US&access=public', // Picasa example
);

foreach ($feedurls as $feedurl)
{
$photofeed = new PhotoRSSFeed($feedurl);
$photofeed -> outputTable(3); // the parameter specifies the number of columns to display
}
/*
Photo RSS Feed Class PHP 5
*/
class PhotoRSSFeed{
protected $photos=array();

public function PhotoRSSFeed($url)
    {
        $doc   = new DOMDocument();
        $doc->load($url);
        $xpath = new DOMXPath($doc);
$QueryRst=$xpath->query("/rss/channel/title/text()");
if ($QueryRst) {
$album = $QueryRst->item(0)->nodeValue;
}
else {
    $album='Unknown';
}

// scan for JPG image discription fields
        $photos_list = $xpath->query("/rss/channel/item");
        for($i=0;$i<$photos_list->length;$i++) {
    $QueryRst=$xpath->query("media:thumbnail/@url",$photos_list->item($i));
if ($QueryRst->length>0) {
$type = $QueryRst->item(0)->nodeValue;
}
if (empty($type)) {
$QueryRst=$xpath->query("media:content/media:thumbnail/@url",$photos_list->item($i));
if ($QueryRst->length>0) {
$type = $QueryRst->item(0)->nodeValue;
}
}
if (empty($type)) {
$type="jpg"; // if can't find a type just set it to jpg
}
            $type = substr($type,strlen($type)-3,strlen($type));
if (strtolower($type)=="jpg") {
$this->photos[$album][$i]["id"]    = "$i";
$QueryRst=$xpath->query("description/text()",$photos_list->item($i));
if ($QueryRst->length>0) {
$this->photos[$album][$i]["description"] = $QueryRst->item(0)->nodeValue;
}
}
        }
    }

// output the table of images
public function outputTable($Cols)
    {
$TableBackgroundCol = '#F2F5F7';
if (count($this->photos) == 0) {
echo '<div align="center"><br /><b>No Photos Found</b></br \></div>';
}
else {
foreach($this->photos as $albums_key => $albums_value)
{
    echo '<div align="center">';
echo $albums_key,'<br />';
echo '<table align="center" width="100%" cellspacing="1" style="clear: both; table-layout: fixed;">
<tr>';
$colcount=0;
// iterate through all photos of the album
foreach ($albums_value as $photos)
{
$colcount++;
if ($colcount>$Cols)
{
$colcount=1;
echo ' </tr>';
echo '  <tr>';
}
echo '<td valign="center" bgcolor="',$TableBackgroundCol,'" class="windowbg windowbg_hover" valign="middle" align="center">';
if (isset($photos["description"]))
echo $photos["description"],'<br />';
echo '</td>';
}

// add empty cells
for ($colcount=$colcount;$colcount<$Cols;$colcount++)
{
echo '
<td bgcolor="',$TableBackgroundCol,'" >
</td>';
}
echo '
</tr>
</table>';
}
echo '</div>';
}
}
}

P.S. You need to log into this forum to see the attached image.

futuro

hi, how can use this without tinyportal? the code give me the error

Fatal error: Class 'PhotoRSSFeed' not found in...

thanks

IchBin

You running php5? How are you using the code? Please give us some details.

futuro

php 5.2.6 and php 5.2.8

iÃ,´m try to put the code into a php-block for tiny portal and into a php single page...

the only change i make is remove the photobucket and picassa examples and change the rss flickr.

errors:
into php-block -> Fatal error: Call to undefined method domdocument::load() in...
into php-single page -> Fatal error: Class 'PhotoRSSFeed' not found in...

PeterLawrence

I've tested the above script under PHP 5.2.3 and it seems to work fine.
The script should run standalone.
Simply save the code in  a separate php file with <?php  inserted at the top and  ?> at the bottom of the file.

The error Fatal error: Call to undefined method domdocument::load() looks like an error that you would get if you were to try and run this script under PHP 4. However, if you were using PHP4 you would also get a warning about domdocument() expects at least 1 parameter.

Is it possible for you to post your modified script or the section of code that you've changed to this forum so I can take a look?

futuro

thanks... the web is not online yet, but this is the code:

<?php

function template_main()
{

global $context$settings$options$txt;

// list your Picasa, Flickr and Photobucket RSS feeds here
 
$feedurls=array(
'http://api.flickr.com/services/feeds/groups_pool.gne?id=986935@N20&lang=es-us&format=rss_200'
);

foreach (
$feedurls as $feedurl)
{
$photofeed = new PhotoRSSFeed($feedurl);
$photofeed -> outputTable(3); // the parameter specifies the number of columns to display
}
/*
Photo RSS Feed Class PHP 5
*/ 
class PhotoRSSFeed{
protected $photos=array();

public function PhotoRSSFeed($url)
    {
        
$doc   = new DOMDocument();
        
$doc->load($url);
        
$xpath = new DOMXPath($doc);
$QueryRst=$xpath->query("/rss/channel/title/text()");
if ($QueryRst) {
$album $QueryRst->item(0)->nodeValue;
}
else {
    $album='Unknown';
}

// scan for JPG image discription fields
        
$photos_list $xpath->query("/rss/channel/item");
        for(
$i=0;$i<$photos_list->length;$i++) {
    $QueryRst=$xpath->query("media:thumbnail/@url",$photos_list->item($i));
if ($QueryRst->length>0) {
$type $QueryRst->item(0)->nodeValue;
}
if (empty($type)) {
$QueryRst=$xpath->query("media:content/media:thumbnail/@url",$photos_list->item($i));
if ($QueryRst->length>0) {
$type $QueryRst->item(0)->nodeValue;
}
}
if (empty($type)) {
$type="jpg"// if can't find a type just set it to jpg
}
            
$type substr($type,strlen($type)-3,strlen($type));
if (strtolower($type)=="jpg") {
$this->photos[$album][$i]["id"]    = "$i";
$QueryRst=$xpath->query("description/text()",$photos_list->item($i));
if ($QueryRst->length>0) {
$this->photos[$album][$i]["description"] = $QueryRst->item(0)->nodeValue;
}
}
        }
    }

// output the table of images
public function outputTable($Cols)
    {
$TableBackgroundCol '#F2F5F7';
if (count($this->photos) == 0) {
echo '<div align="center"><br /><b>No Photos Found</b></br \></div>';
}
else {
foreach($this->photos as $albums_key => $albums_value)
{
    echo '<div align="center">'
echo $albums_key,'<br />';
echo '<table align="center" width="100%" cellspacing="1" style="clear: both; table-layout: fixed;">
<tr>'
;
$colcount=0;
// iterate through all photos of the album
foreach ($albums_value as $photos)
{
$colcount++;
if ($colcount>$Cols)
{
$colcount=1;
echo ' </tr>';
echo '  <tr>';
}
echo '<td valign="center" bgcolor="',$TableBackgroundCol,'" class="windowbg windowbg_hover" valign="middle" align="center">';
if (isset($photos["description"]))
echo $photos["description"],'<br />';
echo '</td>';
}

// add empty cells
for ($colcount=$colcount;$colcount<$Cols;$colcount++)
{
echo '
<td bgcolor="'
,$TableBackgroundCol,'" >
</td>'
;
}
echo '
</tr>
</table>'
;
}
echo '</div>'
}
}
}



}

?>


thanks

PeterLawrence

This is a simple one to fix. You need to move the class outside the function template_main.
try..

<?php
template_main
();

function 
template_main()
{

global $context$settings$options$txt;

// list your Picasa, Flickr and Photobucket RSS feeds here
    
$feedurls=array(
        
'http://api.flickr.com/services/feeds/groups_pool.gne?id=986935@N20&lang=es-us&format=rss_200'
        );
        
    foreach (
$feedurls as $feedurl)
    {
        
$photofeed = new PhotoRSSFeed($feedurl);
        
$photofeed -> outputTable(3); // the parameter specifies the number of columns to display
    
}
}
/*
Photo RSS Feed Class PHP 5
*/ 
class PhotoRSSFeed{
protected $photos=array();

public function PhotoRSSFeed($url)
    {
        
$doc   = new DOMDocument();
        
$doc->load($url);
        
$xpath = new DOMXPath($doc);
$QueryRst=$xpath->query("/rss/channel/title/text()");
if ($QueryRst) {
$album $QueryRst->item(0)->nodeValue;
}
else {
    $album='Unknown';
}

// scan for JPG image discription fields
        
$photos_list $xpath->query("/rss/channel/item");
        for(
$i=0;$i<$photos_list->length;$i++) {
    $QueryRst=$xpath->query("media:thumbnail/@url",$photos_list->item($i));
if ($QueryRst->length>0) {
$type $QueryRst->item(0)->nodeValue;
}
if (empty($type)) {
$QueryRst=$xpath->query("media:content/media:thumbnail/@url",$photos_list->item($i));
if ($QueryRst->length>0) {
$type $QueryRst->item(0)->nodeValue;
}
}
if (empty($type)) {
$type="jpg"// if can't find a type just set it to jpg
}
            
$type substr($type,strlen($type)-3,strlen($type));
if (strtolower($type)=="jpg") {
$this->photos[$album][$i]["id"]    = "$i";
$QueryRst=$xpath->query("description/text()",$photos_list->item($i));
if ($QueryRst->length>0) {
$this->photos[$album][$i]["description"] = $QueryRst->item(0)->nodeValue;
}
}
        }
    }

// output the table of images
public function outputTable($Cols)
    {
$TableBackgroundCol '#F2F5F7';
if (count($this->photos) == 0) {
echo '<div align="center"><br /><b>No Photos Found</b></br \></div>';
}
else {
foreach($this->photos as $albums_key => $albums_value)
{
    echo '<div align="center">'
echo $albums_key,'<br />';
echo '<table align="center" width="100%" cellspacing="1" style="clear: both; table-layout: fixed;">
<tr>'
;
$colcount=0;
// iterate through all photos of the album
foreach ($albums_value as $photos)
{
$colcount++;
if ($colcount>$Cols)
{
$colcount=1;
echo ' </tr>';
echo '  <tr>';
}
echo '<td valign="center" bgcolor="',$TableBackgroundCol,'" class="windowbg windowbg_hover" valign="middle" align="center">';
if (isset($photos["description"]))
echo $photos["description"],'<br />';
echo '</td>';
}

// add empty cells
for ($colcount=$colcount;$colcount<$Cols;$colcount++)
{
echo '
<td bgcolor="'
,$TableBackgroundCol,'" >
</td>'
;
}
echo '
</tr>
</table>'
;
}
echo '</div>'
}
}
}
?>



On another point I notice you're using Flickr. So you may be interested in one of my SMF mods
Flickr Gallery Browser

futuro

yes... im the same man... i canÃ,´t use your flickr gallry browser for a group :(

for this i wanto to try with this one...

futuro

now, the code give me a new error:

Fatal error: Call to undefined method domdocument::load() in ...\Sources\Load.php(1741) : eval()'d code on line 27

Sorry for this.

PeterLawrence

This problem could be related to how PHP5 is install on your system.
If you search the web for Call to undefined method domdocument::load php5 there are quite a number of articles.
Are you using PHP5 in safe mode?
I also read that with PHP 5 ona  windows system you may need to comment out the line php_domxml.dll in your php.ini file.


Also see http://uk.php.net/manual/en/dom.setup.php
and http://uk.php.net/manual/en/domdocument.load.php

This website is proudly hosted on Crocweb Cloud Website Hosting.