Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: Displaying random image from coppermine gallery on website  (Read 2881 times)

0 Members and 1 Guest are viewing this topic.

apassio

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 35
    • Christine & Son's website
Displaying random image from coppermine gallery on website
« on: January 08, 2006, 03:20:01 pm »

Some time ago, with an earlier coppermine version, I used the code below to display random images of my gallery on my website:
http://www.dophan.com

Code: [Select]
// this was found in coppermine forum at http://coppermine.sourceforge.net/board/index.php?topic=1196.msg6902#msg6902
//***Enter Path information here***
//***absolute path to main coppermine directory***

$copperminepath = 'path';  //***YOU MUST CHANGE THIS***

//This connects to the mysql DB
//***change username and password below***

$MZrandompic = @mysql_connect('XXXX', 'XXXX', 'XXXX'); //***YOU MUST CHANGE THIS***

if (!$MZrandompic) { 
echo( '<p>Unable to connect to the ' . 
'database server at this time.</p>' ); 
exit(); 


//select photo DB
//***YOU MUST CHANGE THIS***

if (! @mysql_select_db('XXXX') ) {
die( '<p>Unable to locate the picture ' . 
'database at this time.</p>' ); 


//This gets a random picture record from the database and
//the picture's location and displays it

$MZresult = @mysql_query("SELECT * FROM cpg11d_pictures ORDER BY RAND() LIMIT 0,4"); 
if (!$MZresult) { 
die('<p>Error performing query: ' . mysql_error() . 
'</p>'); 


while ( $MZrow = mysql_fetch_array($MZresult) ) { 

// $albumid = $MZrow['aid'];  //This gets the picture's associated album name
$pos = $MZrow['pid'];      //This finds the picture's coppermine location

// echo('<P ALIGN=center>'); 

//old: target opens in new window
//echo('<a target = "_new" href="' . $copperminepath . '/displayimage.php?album=' . $albumid . 
//'&pos=-' . $pos . '">'); //make thumbnail clickable

//new: target opens in same window
echo('<a href="' . $copperminepath . '/displayimage.php?album=' . $albumid . 
'&pos=-' . $pos . '">'); //make thumbnail clickable

echo('<IMG SRC="' . $copperminepath . '/albums/');           //append base dir structure
echo($MZrow['filepath'].thumb_.$MZrow['filename'] .
     '" alt=' . $MZrow['filename'] . ' '. 'border=0 height=100>' . '</a> &nbsp;&nbsp;'); //outputs path from /userspics


//This displays the picture's album name and
//links it to the coppermine album

$MZalbumresult = @mysql_query("SELECT * FROM cpg11d_albums WHERE aid = '$albumid'"); 
if (!$MZalbumresult) { 
die('<p>Error performing query: ' . mysql_error() . 
'</p>'); 


while ( $MZalbumname = mysql_fetch_array($MZalbumresult) ) { 
echo('<FONT SIZE=1>');
echo('<P ALIGN=center>'); 

echo('<a href="' . $copperminepath . 
'/thumbnails.php?album=' . $albumid . '">' . 
$MZalbumname['title'] . '</a>' . '</p>'); 


if (! @mysql_select_db('XXXX') ) { 
die( '<p>Unable to reload the main website ' . 
'database at this time.</p>' ); 


?>


It's been working every until now. But after upgrading to CPG 4.1.3 I have the following question/issues:

1) Will the code above show pictures from albums which are password protected (new feature in CPG 4.1.3).
If yes, how can I prevent this?

2) How could I force image displayed to be only from my own albums (not from user gallery albums)

3) How can I choose only particular albums to be used in the random function?

Thanks
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Logged
Pages: [1]   Go Up
 

Page created in 0.018 seconds with 19 queries.