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

Recent

Welcome to TinyPortal. Please login or sign up.

May 18, 2024, 03:57:05 PM

Login with username, password and session length
Members
  • Total Members: 3,886
  • Latest: Grendor
Stats
  • Total Posts: 195,189
  • Total Topics: 21,220
  • Online today: 112
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 67
  • Total: 67

Random photos from coppermine

Started by carver, September 22, 2005, 01:32:19 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

carver

Thought some of you might find a use for this script. It will pull a random photo from the coppermine photo gallery.
The code in red can be edited to suit your needs
<?php

include_once( '/home/bowfishi/public_html/gallery/include/config.inc.php');

db_connect() || die(mysql_error());

function db_connect()
{
         global $CONFIG;
         $result = @mysql_connect($CONFIG['dbserver'],
$CONFIG['dbuser'], $CONFIG['dbpass']);
         if (!$result)
                 return false;
         if (!mysql_select_db($CONFIG['dbname']))
                 return false;
         return $result;
}

$result = mysql_query("SELECT filename,filepath from cpg132_pictures WHERE
approved='YES' AND aid <> 111 and owner_name='Carver' ORDER BY RAND() DESC LIMIT 1");
$row = mysql_fetch_array($result);

$filename = 'thumb_' . $row['filename'];
$filepath = $row['filepath'];

Header('Location:http://www.mysite.com/gallery/albums/' . $filepath .
$filename);
exit;
?>


You can put this in an HTML block and call this script as an image.
<BODY>
<IMG src="http://www.mysite.com/random_pic.php">
</BODY>

domp

Looks okay but be a bit more specific ?  :)

where do we put the first part ? in a block ? use the block as php ?                 

Tia

carver

#2
Sorry,

Once you have the php code tweaked to do what you want it to do, You can edit the WHERE statement to be more or less restrictive in what the query returns, make sure to set everything to your site's path and then  just save it to your server as a php file, for instance as random.php  and then call that file as you would any image. <IMG src="http://www.mysite.com/random.php">

If you are going to use it as a block then place it in a HTML Block and use the <body> tags.
You can even call this php script to the forum as your avatar which is what I used it for was a random image avatar from one of my galleries....
Let me know if you need more info


IchBin

Im sure there will be quite a few people looking for something like this. Good job !!!

YahMan

I've been trying to get this to work, but no luck so far.
AND aid <> 111 and owner_name='Carver'

I think it's got something to do with this, but what does it do?

carver

Quote from: YahMan on October 05, 2005, 01:56:48 AM
I've been trying to get this to work, but no luck so far.
AND aid <> 111 and owner_name='Carver'

I think it's got something to do with this, but what does it do?

That is just part of the WHERE Clause of the SQL Query.
It pretty much just says not to take Album 111 and only show pictures where the owner is equal to Carver.
So you can leave that part out of the query, unless you want only those pictures to show that belong to you then replace CARVER with your username...


In simple terms this: $result = mysql_query("SELECT filename,filepath from cpg132_pictures WHERE
approved='YES' AND aid <> 111 and owner_name='Carver' ORDER BY RAND() DESC LIMIT 1");


IS simply saying select the file name and file path from the table cpg132_pictures WHERE approved is equal to yes and the aid ( album ) is not equal to 111 and where the owner is equal to Carver, then return one picture in a random order...

make sure that your table name is not different then cpg132_pictures, it could be cpg135_pictures now or something different if you did not go with the default install when creating the database.

snork13

#6
Here is what i do to get coppermine gallery images into the portal, thought i would share.


Downloaded and install Coppermine Fetch (CPMFetch) , and using a php block, add

//gallery block added

echo '<table class="tborder" border="0" width="158" cellspacing="0" cellpadding="4">
<tr><td width="100%" class="titlebg">'.$txt['portal_27'].'</td>
<tr><td class="windowbg2" width="100%" align="center">';
include "coppermine.php";
$objCpm = new cpm("/gallery");
echo ' <div align="left">';
$objCpm->cpm_formatStats("There are %f photos in the gallery <br><ul><li> %a members have albums <br><li> The gallery has beenÂÃ,  viewed %v times <br><li>%n members have commented on photos </ul>");
echo '</div>';


ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, 
ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ,  ÂÃ, 
$objCpm->cpm_viewRandomMedia(1,1);



//$objCpm->cpm_close();

echo'</td></tr></table><br />';


thanks for sharing the portal bloc, it rocks and looks super!

-snork13

live demo for a limited time

www.phantasyposters.com/forum

test/cpmfetch

IchBin


crip

Quote from: snork13 on November 05, 2005, 10:59:20 PM
Here is what i do to get coppermine gallery images into the portal, thought i would share.
Downloaded and install Coppermine Fetch (CPMFetch) , and using a php block, add
//gallery block added
echo '<table class="tborder" border="0" width="158" cellspacing="0" cellpadding="4">
<tr><td width="100%" class="titlebg">'.$txt['portal_27'].'</td>
<tr><td class="windowbg2" width="100%" align="center">';
include "coppermine.php";
$objCpm = new cpm("/gallery");
echo ' <div align="left">';
$objCpm->cpm_formatStats("There are %f photos in the gallery <br><ul><li> %a members have albums <br><li> The gallery has beenÂÃ,  viewed %v times <br><li>%n members have commented on photos </ul>");
echo '</div>';
$objCpm->cpm_viewRandomMedia(1,1);
//$objCpm->cpm_close();
echo'</td></tr></table><br />';

thanks for sharing the portal bloc, it rocks and looks super!
-snork13
live demo for a limited time
www.phantasyposters.com/forum
test/cpmfetch

Using the CMG-Fetch - the php code above gives me this !error:!


Fatal error: Cannot instantiate non-existent class: cpm in /home/cripsite/public_html/forum/Sources/Load.php(1598) : eval()'d code(32) : eval()'d code on line 5


Is there another way of doing this? - I ran the test/cpmfetch.php and every thing passed and it showed 8 thumbnail files thats located in my Gallery.

Thanks,
crip~

domp

set up your coppermine.php and put this in a block:

print "A random selection:<CENTER>";
include "../gallery/cpmfetch/coppermine.php";
$objCpm = new cpm("/gallery");
$objCpm->cpm_viewRandomMedia(1,1);
$objCpm->cpm_close();
print "</center>";


Sure works 4us  :-)