I've updated the above php code. The revised version fixes a bug relating to newline characters being outputted in some strings.
Also it now outputs the album description in the subtitle field.
Note that this php file, cpgjson.php, should be placed in your Coppermine directory.
<?php
// Coppermine JSON Generator (1.01)
// Based on Picasa JSON feed format see http://code.google.com/apis/gdata/json.html
// Peter J Lawrence (December 2008)
// Based on code from Coppermine RSS 2.0 Generator (1.0) by Mohammad Hafiz bin Ismail
$upperlimit = 6; //default = 6
define('INC_COMMENT_TIMES', false);
define('FILEDUMP', false);
define('GZ_COMPRESS', false);
// [0.0 <= priority <= 1.0]
define('P_DISPLAYIMAGE', 0.5);
define('P_ALBUM', 0.5);
define('P_CATEGORY', 0.5);
// [changefreq = always || hourly || daily || weekly || monthly || yearly || never]
define('CF_DISPLAYIMAGE', 'unspecified');
define('CF_ALBUM', 'unspecified');
define('CF_CATEGORY', 'unspecified');
define('IN_COPPERMINE', true);
require('include/init.inc.php');
// This should work as it is, but hardcode if necessary.
define('CPG14', version_compare(COPPERMINE_VERSION, "1.4.0", ">="));
define('PHP5', version_compare(phpversion(), "5", ">="));
$base = rtrim($CONFIG['ecards_more_pic_target'], '/');
$albumpath = "$base/" . $CONFIG['fullpath'];
function FormatOutput($aString)
{
// removes returns and replaces them with html br
// also add slashes
return (preg_replace("/\\r\\n|\\n\\r|\\n|\\r/", "<br />",addslashes($aString)));
}
function lmdate($timestamp)
{
if (PHP5){
return date('c', $timestamp);
} else {
return date('D, d M Y H:i:s +0800', $timestamp - date('Z'));
}
}
ob_flush();
if (isset($_GET['callback']))
{
print ($_GET['callback'])."(";
}
header('Content-type: application/x-json');
print "{\n";
print " \"version\":\"1.0\",\n";
print " \"encoding\":\"UTF-8\",\n";
print " \"feed\":{\n";
//cpg_db_connect(); // uncomment this line if you're having problems connecting to the database
$TheAlbum=null;
if (isset($_GET['album']))
{
$TheAlbum = (int) $_GET['album'];
$result = mysql_query("SELECT aid, title, description FROM {$CONFIG['TABLE_ALBUMS']} WHERE aid=$TheAlbum");
}
else
{
// find the album last uploaded to
$result = mysql_query("SELECT aid, title, description FROM {$CONFIG['TABLE_ALBUMS']} ORDER BY title ASC LIMIT
0,1");
}
while (list($aaid, $atitle, $adescription) = mysql_fetch_row($result))
{
if (isset($TheAlbum))
{
$result2 = mysql_query("SELECT pid, aid, caption, ctime, title, keywords, filepath, filename, owner_name, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} WHERE aid=$aaid ORDER BY ctime ASC, pid ASC");
}
else
{
// set atitle and adescription
$atitle="Recent uploads";
$adescription="Recently uploaded images";
// find the last $upperlimit uploaded images
$result2 = mysql_query("SELECT pid, aid, caption, ctime, title, keywords, filepath, filename, owner_name, pwidth, pheight FROM {$CONFIG['TABLE_PICTURES']} ORDER BY ctime DESC, pid DESC LIMIT
0,$upperlimit");
}
$result_count=mysql_num_rows($result2);
print ' "id":{'."\n ".'"$t":"'.$base."\"},\n";
print ' "updated":{'."\n ".'"$t":"'.lmdate(time())."\"},\n";
print ' "title":{'."\n";
print ' "type":"text",'."\n";
print ' "$t":"'.FormatOutput($atitle).'"},'."\n";
print ' "subtitle":{'."\n";
print ' "type":"text",'."\n";
print ' "$t":"'.FormatOutput($adescription).'"},'."\n";
print ' "link":'."\n";
print ' ['."\n";
print ' { "rel":"'.$base.'",'."\n";
print ' "type":"text/html",'."\n";
print ' "href":"'.$base.'"}'."\n";
if (isset($TheAlbum))
{
print ' ,{ "rel":"alternate",'."\n";
print ' "type":"text/html",'."\n";
print ' "href":"'.$base.'/thumbnails.php?album='.$TheAlbum.'"}'."\n";
}
print ' ],'."\n";
print ' "author":'."\n";
print ' ['."\n";
print ' {'."\n";
print ' "name":{'."\n";
print ' "$t":"Unkown"},'."\n";
print ' "uri":{'."\n";
print ' "$t":"'.$base.'"}'."\n";
print ' }'."\n";
print ' ],'."\n";
print ' "generator":{'."\n";
print ' "version":"1.00",'."\n";
print ' "uri":"'.$base.'",'."\n";
print ' "$t":"Coppermine JSON Generator (1.01)"},'."\n";
print ' "openSearch$totalResults":{'."\n";
print ' "$t":"'.$result_count.'"},'."\n";
print ' "openSearch$startIndex":{'."\n";
print ' "$t":"1"},'."\n";
print ' "openSearch$itemsPerPage":{'."\n";
print ' "$t":"1000"},'."\n";
print ' "georss$where":{'."\n";
print ' "gml$Point":{'."\n";
print ' "gml$pos":{'."\n";
print ' "$t":"51.50199 -0.118955"}'."\n";
print ' }'."\n";
print ' },'."\n";
print ' "entry":'."\n";
print ' ['."\n";
$count-0;
while (list($pid, $aid,$desc, $ctime, $title, $keywords,$filepath,$filename, $owner, $width, $height) = mysql_fetch_row($result2))
{
$count++;
print ' {'."\n"; // start of entry
print ' "id":{'."\n";
print ' "$t":"'."$base/displayimage.php?pos=-$pid".'"},'."\n";
print ' "published":{'."\n";
print ' "$t":"'. lmdate($ctime) .'"},'."\n";
print ' "updated":{'."\n";
print ' "$t":"'. lmdate($ctime) .'"},'."\n";
print ' "title":{'."\n";
print ' "type":"text",'."\n";
print ' "$t":"'.FormatOutput($title).'"},'."\n";
print ' "summary":{'."\n";
print ' "type":"html",'."\n";
print ' "$t":"';
//echo nl2br(addslashes($desc));
echo FormatOutput($desc);
print '"},'."\n";
print ' "content":{'."\n";
print ' "type":"image/jpeg",'."\n";
print ' "src":"'.$albumpath.$filepath.$filename.'"},'."\n";
print ' "link":'."\n";
print ' ['."\n";
print ' {'."\n";
print ' "rel":"'."$base/displayimage.php?pos=-$pid".'",'."\n";
print ' "type":"text/html",'."\n";
print ' "href":"'."$base/displayimage.php?pos=-$pid".'"'."\n";
print ' }'."\n";
print ' ],'."\n";
print ' "media$group":{'."\n";
print ' "media$title":{'."\n";
print ' "type":"plain",'."\n";
print ' "$t":"'.$filename.'"},'."\n";
print ' "media$description":{'."\n";
print ' "type":"plain",'."\n";
print ' "$t":"'.FormatOutput($desc).'"},'."\n";
print ' "media$keywords":{'."\n";
print ' "$t":"';
echo FormatOutput("$keywords");
print '"},'."\n";
print ' "media$content":'."\n";
print ' ['."\n";
print ' {'."\n";
print ' "url":"'."$albumpath$filepath$filename".'",'."\n";
print ' "height":"'.$height.'",'."\n";
print ' "width":"'.$width.'",'."\n";
print ' "type":"image/jpeg",'."\n";
print ' "medium":"image"}'."\n";
print ' ],'."\n";
print ' "media$thumbnail":'."\n";
print ' ['."\n";
print ' {'."\n";
print ' "url":"'."$albumpath$filepath"."thumb_$filename".'",'."\n";
print ' "height":"80",'."\n";
print ' "width":"100"}'."\n";
print ' ],'."\n";
print ' "media$credit":'."\n";
print ' ['."\n";
print ' {'."\n";
print ' "$t":"'.$owner.'"}'."\n";
print ' ]'."\n";
print ' }'."\n";
if ($count==$result_count)
{
print ' }'."\n"; // end of entry last one
}
else
{
print ' },'."\n"; // end of entry more to come
}
}
print ' ]'."\n"; // entry
}
print " }\n"; // end feed
if (isset($_GET['callback']))
{
print "});\n"; // end opening function
}
else
{
print "}\n"; // end opening {
}
?>
In addition I've attached another Javascript file which uses the EnlargeIt script to embed an album in an html page.
This Javascript should work OK if placed in the root folder. Note you'll need to login to see the attachment.
If there is a problem you should check the directory paths specified in test.html and
enlargeit_source.js.