Page 1 of 1

Random Picture from Coppermine Gallery Block

Posted: 8. August 2008 21:11
by Fliggerty
Hello,

This is a simple block I put together so I could have a "pic of the moment" thing on my portal. It randomly pulls an image from my Coppermine gallery and displays it in the block.

I came across the Coppermine part of the code on the forum there.

First, make a file called get_photo.php in /root/coppermine (or wherever you gallery is installed.)

Code: Select all

<?php 
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery - RSS Feed                                      //
// ------------------------------------------------------------------------- //
// Copyright (C) Dr. Tarique Sani                                           //
// http://tariquesani.net/                                                  //
// Adapted by djib to display a random photo - http://djib.biz              //
// This program is free software; you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License, or        //
// (at your option) any later version.                                      //
// ------------------------------------------------------------------------- //
// Just put into the same directory as your coppermine installation         //
// ------------------------------------------------------------------------ //

define('IN_COPPERMINE', true);
define('INDEX_PHP', true);
require('include/init.inc.php');

//How many items you want to show in your get_photo script
if(isset($_GET['nb'])) {
     $thumb_per_page=$_GET['nb'];
} else {
     $thumb_per_page = 1;
}
$thumb_count = 1;
$lower_limit = 0;

if(isset($_GET['album'])){
    $album = $_GET['album'];
}

//If it is a numeric album get the name and set variables
if ((is_numeric($album))){
     $album_name_keyword = get_album_name($album);
     $CURRENT_CAT_NAME = $album_name_keyword['title'];
     $ALBUM_SET = "AND aid IN (".(int)$_GET['album'].")".$ALBUM_SET;
     //Set the album to last uploaded
     $album = 'random';
}

//If the album is not set set it to lastup - this is the default
if(!isset($album)){
     $album = 'random';
}


//Changes these to point to your site if the following is not giving correct results.
$link_url = $CONFIG['ecards_more_pic_target']."displayimage.php?pos=-";
$image_url = $CONFIG['ecards_more_pic_target']."albums/";


$data = get_pic_data($album, $thumb_count, $album_name, $lower_limit, $thumb_per_page);


foreach($data AS $picture) {
    $thumb_url = "$image_url$picture[filepath]$CONFIG[thumb_pfx]$picture[filename]";
    $description = '<a href="' . $link_url . $picture['pid'] . '" target="_blank"><img src="' . $thumb_url . '"  border="0"/></a>';
    echo $description;

}
?
Then I made a new block template called random_shot.html:

Code: Select all

<div class="forabg2">
   <div class="inner">
      <span class="corners-top"><span></span></span>
      	<ul class="topiclist">
			<h3>Screenshot</h3>
		</ul>
		<ul class="topiclist forums">
         	<iframe src="http://www.fliggerty.com/coppermine/get_photo.php" align="center" border="0" width="120" height="120" frameborder="0"></iframe>		
		</ul>
      <span class="corners-bottom"><span></span></span>
   </div>
</div>
<br style="clear:both" />
You might want to change forabg2 to a class that really exists in your css.

Next, edit portal_body.html and add this where you want the block to show up:

Code: Select all

		<!-- INCLUDE portal/block/random_shot.html -->
And that's it.

I hope someone else can find this to be a useful thing!

--Fligg

Re: Random Picture from Coppermine Gallery Block

Posted: 9. August 2008 00:14
by thomas.d
Hi Fligg,

thanks for sharing!