Image processing consumes a lot of resources and CPU time, since
I'm using a free web host, sometimes when the images are too large
thumbnail generation would fail. So I decided to create a version of
the Photo Gallery that uses RSS feeds from Picasa.
All you need is an RSS feed link from picasa, pass it to the picasa.php
file and it will fetch all the albums, selecting an album displays all the
image from that album.
The gallery uses Lightbox, Prototype and Scriptaculous. The previous
Paginator class I created is also used here to provide item pagination.
Picasa Gallery Demo
picasa.php
<?php
/**
* Picasa RSS Gallery
*
* Generates a gallery based on a Picasa RSS feed
*
*
* @author Herbert Balagtas
* @todo cache RSS
*/
error_reporting(0);
include('../cache_start.php');
include_once ('config.php');
include_once ('myfunctions.php');
include_once ('../myfunctions.php');
include_once ('paginator.php');
$time_start = microtime_float ();
if (! isset ( $_GET ['album_rss'] )) {
$rss = "http://picasaweb.google.com/data/feed/base/user/hbalagtas?alt=rss&kind=album&hl=en_US";
$picasa_cache = '../rss/picasa.rss';
$rssdata = fetchRSS ( $rss, $picasa_cache );
if ($rssdata) {
$picasa_xml = new SimpleXMLElement ( $rssdata );
#$picasa_xml = simplexml_load_file($picasa_cache);
foreach ( $picasa_xml->channel->item as $item ) {
$ns_dc = $item->children ( 'http://search.yahoo.com/mrss/' );
$album_thumbnail = $ns_dc->group->thumbnail->attributes ()->url;
$album_title = $ns_dc->group->title;
$album_guid = $item->guid;
$album_date = $item->pubDate;
$albums [] = array ('title' => $album_title, 'thumbnail' => $album_thumbnail, 'rss' => $album_guid, 'date' => $album_date );
}
} else {
echo 'Could not fetch RSS feed';
}
}
/** fetch album rss
*
*/
if (isset ( $_GET ['album_rss'] )) {
$url = urldecode ( $_GET ['album_rss'] ) . '&kind=photo';
$album_cache = '../rss/'. md5 ( $url ) . '.rss';
#$album_rss = curlFetch ( $url );
$album_rss = fetchRSS ( $url, $album_cache );
if ($album_rss) {
$album_xml = new SimpleXMLElement ( $album_rss );
$album_title = $album_xml->channel->title;
foreach ( $album_xml->channel->item as $item ) {
$title = $item->title;
$image = $item->enclosure ['url'];
$ns_dc = $item->children ( 'http://search.yahoo.com/mrss/' );
$thumb = $ns_dc->group->thumbnail [1]->attributes ()->url;
$album_items [] = array ('title' => $title, 'image' => $image, 'thumbnail' => $thumb );
}
} else {
echo 'Could not fetch album rss';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Picasa Gallery - Online Portfolio</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="gallery.css" />
<!-- <script type='text/javascript' src='js/prototype.js'></script>
<script type='text/javascript' src='js/scriptaculous/scriptaculous.js'></script>
<script type='text/javascript' src='js/scriptaculous/effects.js'></script>-->
<script type='text/javascript'
src='http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js'></script>
<script type='text/javascript'
src='http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js'></script>
<script type='text/javascript'
src='http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/effects.js'></script>
<script type='text/javascript' src='lightview/js/lightview.js'></script>
<link rel="stylesheet" type="text/css"
href="lightview/css/lightview.css" />
<style type="text/css">
.album {
width: 200px;
height: 200px;
float: left;
}
</style>
</head>
<body>
<h1><?php
echo ALBUM_TITLE;
?></h1>
<a href="../">Home</a>
<?php
if (! isset ( $_GET ['album_rss'] )) {
$albums = new Paginator ( $albums );
$albums->setIPP ( IMAGE_PER_PAGE );
if (! empty ( $_GET ['pg'] )) {
$albums->CurrentPage ( $_GET ['pg'] );
} else {
$albums->CurrentPage ( 1 );
}
$gallery = '';
$gallery .= '<div id="gallery">' . "\r\n";
foreach ( $albums->getItems () as $album ) {
$gallery .= '<div class="album">' . "\r\n";
$url = urlencode ( preg_replace ( '/\/entry\//', '/feed/', $album ['rss'] ) );
$gallery .= '<a href="?album_rss=' . $url . '">' . "\r\n";
$gallery .= '<img src="' . $album ['thumbnail'] . '" class="album_preview" border="0" alt="' . $album ['title'] . '"/>' . "\r\n";
#$gallery .= '<img src="file.png" class="album_preview" border="0"/><br />' . "\r\n";
$gallery .= '</a>';
$gallery .= '<br /><span>' . $album ['title'] . '</span>' . "\r\n";
$gallery .= '</div>' . "\r\n";
}
$gallery .= '</div>' . "\r\n";
$params = array_merge ( $_GET, $_POST );
echo $albums->paginationControl ( $params, 'control1' );
echo $gallery;
echo '<br clear="all"/>';
echo $albums->paginationControl ( $params, 'control2' );
}
if (isset ( $_GET ['album_rss'] ) && ! empty ( $album_items )) {
echo '<h2>';
$home = basename ( __FILE__ );
echo '<a href="' . $home . '">Albums</a> :: ';
echo $album_title;
echo '</h2>';
$album_items = new Paginator ( $album_items );
$album_items->setIPP ( 12 );
if (! empty ( $_GET ['pg'] )) {
$album_items->CurrentPage ( $_GET ['pg'] );
} else {
$album_items->CurrentPage ( 1 );
}
$gallery = '';
$gallery .= '<div id="gallery">' . "\r\n";
foreach ( $album_items->getItems () as $item ) {
$gallery .= '<div class="album">' . "\r\n";
$gallery .= '<a href="' . $item ['image'] . '" class="lightview" rel="gallery[myset400]">' . "\r\n";
$gallery .= '<img src="' . $item ['thumbnail'] . '" class="album_preview" border="0" alt="' . $item ['title'] . '" />' . "\r\n";
#$gallery .= '<img src="file.png" class="album_preview" border="0"/><br />' . "\r\n";
$gallery .= '</a>';
$gallery .= '<br /><span>' . $item ['title'] . '</span>' . "\r\n";
$gallery .= '</div>' . "\r\n";
}
$gallery .= '</div>' . "\r\n";
$params = array_merge ( $_GET, $_POST );
if ($album_items->getTotalPage () > 1) {
echo $album_items->paginationControl ( $params, 'control1' );
echo '<br /><br clear="all"/><br />';
}
echo $gallery;
if ($album_items->getTotalPage () > 1) {
echo '<br /><br clear="all"/><br />';
echo $album_items->paginationControl ( $params, 'control2' );
}
}
?>
<?php
$time_end = microtime_float ();
$time = $time_end - $time_start;
echo '<br clear="all" />';
echo '<hr />';
echo "Script Execution time $time seconds\n";
?>
</body>
</html>
<?php include('../cache_end.php'); ?>