Heh. Wondered when someone was going to ask.
The Latest Images and Subalbums are easy. The Most Popular and Highest Rated involve minor database changes, relating to hit counts and star rating systems, both of which have forum posts here. Still interested? The only reason I ask is that some people don't want to modify their DB. I'll have to package them up for you too, because it involves a few files, and then some DB changes, and then some CSS tweaking, and etc....
Here's the counting functions:
`/* SQL Counting Functions */
function show_subalbum_count() {
$sql = "SELECT COUNT(id) FROM ". prefix("albums") ." WHERE parentid <> \"NULL\"";
$result = query($sql);
$count = mysql_result($result, 0);
echo $count;
}
function getIDforAlbum() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
return $_zp_current_album->getAlbumID();
}
function show_sub_count_index() {
$id = getIDforAlbum();
$sql = "SELECT COUNT(*) FROM ". prefix("albums") ." WHERE parentid = $id";
$result = query($sql);
$count = mysql_result($result, 0);
echo $count;
}`
Now mind, the latest albums/subalbums and the latest images were not developed by me but by this nice gentleman here, and I tweaked them a bit. But these are the functions. Don't forget the Most Popular and Highest Rated require additional work, so don't call them unless you have the changes in place mentioned above, but basically they are just versions of the latest images.
`/* Show Latest Albums */
/* http://anton.gektoras.lt/zenphoto/zenphoto-latest-albums */
function show_latest_album($number) {
$sql = "SELECT * FROM ". prefix("albums") ." ORDER BY id DESC LIMIT $number";
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
if ($r['thumb']==NULL) {
$image = get_album_image($r['id']);
} else {
$image = $r['thumb'];
}
echo '[*]';
if (zp_conf('mod_rewrite') == false) {
echo '.']';
echo '[img]'.WEBPATH.'/zen/i.php?a='.$r['folder'].'&i='.$image.'&s=thumb[/img]';
// echo '.']'.$r['title'].'';
} else {
echo '.']';
echo '[img]'.WEBPATH.'/'.$r['folder'].'/image/thumb/'.$image.'[/img]';
// echo '.']'.$r['title'].'';
}
echo '';
}
}
function get_album_image($id) {
$sql = "SELECT * FROM ". prefix("images") ." WHERE albumid = $id";
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
return $r['filename'];
}
}`
`/* Show Latest Images */
/* http://anton.gektoras.lt/zenphoto/zenphoto-latest-images */
function show_latest_images($number) {
$images = query_full_array("SELECT images.albumid, images.filename AS filename, images.title AS title, albums.folder AS folder FROM ".prefix('images')." AS images, ".prefix('albums')." AS albums WHERE images.albumid = albums.id AND images.show = 1 ORDER BY images.id DESC LIMIT $number");
$size = '_'.zp_conf('thumb_size').'_cw'.zp_conf('thumb_crop_width').'_ch'.zp_conf('thumb_crop_height');
foreach ($images as $image) {
$filename = $image['filename'];
$album = $image['folder'];
$desc = $image['title'];
echo '[*]';
if (zp_conf('mod_rewrite') == false) {
echo '';
} else {
echo '<a href="'.WEBPATH.'/'.$album.'/'.$filename.'" title="'.$desc.'">';
}
/* echo '[img]'.WEBPATH.'/cache/'.$album.'/'.$filename.$size.'.jpg[/img]'; */
echo '[img]'.WEBPATH.'/zen/i.php?a='.$album.'&i='.$filename.'&s=thumb[/img]</a>';
echo '';
}
}
/* Show Most Popular Images */
/* Modified from show_latest_images from http://anton.gektoras.lt/zenphoto/zenphoto-latest-images */
function show_most_popular($number) {
$images = query_full_array("SELECT images.albumid, images.filename AS filename, images.title AS title, images.hit AS hit, albums.folder AS folder FROM ".prefix('images')." AS images, ".prefix('albums')." AS albums WHERE images.albumid = albums.id AND images.show = 1 ORDER BY images.hit DESC LIMIT $number");
$size = '_'.zp_conf('thumb_size').'_cw'.zp_conf('thumb_crop_width').'_ch'.zp_conf('thumb_crop_height');
foreach ($images as $image) {
$filename = $image['filename'];
$album = $image['folder'];
$desc = $image['title'];
$hit = $image['hit'];
echo '[*]';
if (zp_conf('mod_rewrite') == false) {
echo '';
} else {
echo '<a href="'.WEBPATH.'/'.$album.'/'.$filename.'" title="'.$desc.' with '.$hit.' hit(s)">';
}
echo '[img]'.WEBPATH.'/zen/i.php?a='.$album.'&i='.$filename.'&s=thumb[/img]';
echo '';
}
}
/* Show Highest Rated Images */
/* Modified from show_latest_images from http://anton.gektoras.lt/zenphoto/zenphoto-latest-images */
function show_highest_rated($number) {
$images = query_full_array("SELECT images.albumid, images.filename AS filename, images.title AS title, images.total_value AS totalvalue, images.total_votes as votes, albums.folder AS folder FROM ".prefix('images')." AS images, ".prefix('albums')." AS albums WHERE images.albumid = albums.id AND images.show = 1 ORDER BY (images.total_value/images.total_votes) DESC LIMIT $number");
$size = '_'.zp_conf('thumb_size').'_cw'.zp_conf('thumb_crop_width').'_ch'.zp_conf('thumb_crop_height');
foreach ($images as $image) {
$filename = $image['filename'];
$album = $image['folder'];
$desc = $image['title'];
$totalvalue = @number_format($image['totalvalue']/$image['votes'],2);
echo '[*]';
if (zp_conf('mod_rewrite') == false) {
echo '';
} else {
echo '<a href="'.WEBPATH.'/'.$album.'/'.$filename.'" title="'.$desc.' with a rating of '.$totalvalue.'">';
}
echo '[img]'.WEBPATH.'/zen/i.php?a='.$album.'&i='.$filename.'&s=thumb[/img]';
echo '';
}
}`