Random image include? (SSI.php) Random image include? (SSI.php)
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Random image include? (SSI.php)

Started by Brian, October 17, 2003, 03:37:11 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Brian

Is there a file I can include within my main (non-coppermine) page to display a random image from the coppermine db?

As in a random image "block"

Thanks!

Zarsky

check out the ssi.php (show CPG-thumb) mod in the download/mod section of this site.

http://coppermine.sourceforge.net/download.php#mods

I also have an old hacked up little script...I will dig it up and post it soon.
Read the Online DOCs, FAQ, and SEARCH the board BEFORE posting questions for help.

Brian

Will this work with the latest 1.2 rc?

jasendorf

Don't see why not.  give it a try and get back to us!  ;)
Read the Online DOCs,FAQ, and SEARCH the board BEFORE posting questions for help.

Tarique Sani

To repeat Gaugau - that ssi does not respect permissions so be careful
SANIsoft PHP applications for E Biz

gtroll

#5
Here is something I took out of the nuke port and modified to work for the standalone, now I didn't test this but it should work let me know we can post it under hacks...

<?php 
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.2.0                                            //
// ------------------------------------------------------------------------- //
// Copyright (C) 2002,2003 Gregory DEMAR <gdemar@wanadoo.fr>                 //
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// Updated by the Coppermine Dev Team                                        //
// (http://coppermine.sf.net/team/)                                          //
// see /docs/credits.html for details                                        //
// ------------------------------------------------------------------------- //
// 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.                                       //
// ------------------------------------------------------------------------- // 
// hack from the nuke port for the standalone  version                  //
// by gtroll                                                                                //
// modify aid!=4 AND aid!=6 AND aid!=7                                         //
// to fit the album(s) you want not to show                                        //
// ------------------------------------------------------------------------- // 

define('IN_COPPERMINE'true);
require(
'include/init.inc.php');
$numberpic=5// you can change the number of pictures here 
global $prefix$dbi
function 
truncate_string444($str

   
$maxlength 20// maximum lenght of name in block 
    
   
if (strlen($str) > $maxlength
      return 
substr($str0$maxlength)." ..."
   else 
      return 
$str


$content="<center>"
$result db_query("SELECT count(*) from cpg_pictures WHERE aid!=4 AND aid!=6 AND aid!=7"$dbi); 
   
$nbEnr mysql_fetch_array($result); 
   
$count $nbEnr[0]; 
while (
$stop<$numberpic

    
   
srand(time()+$stop); 
   
$random_number rand(0$count-1); 
   
$result2 db_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE aid!=4 AND aid!=6 AND aid!=7  AND approved='YES' LIMIT $random_number,1"$dbi); // aid numbers can be changed as need to respect permissions
  
$picture mysql_fetch_array($result2); 
  
   
$img "<img src=\"{$picture['filepath']}thumb_{$picture['filename']}\"  border=\"0\">"
   
$content .= "<a href=\"displayimage.php&album=random&cat=&pos=-{$picture['pid']}\">$img<br>" truncate_string444($picture['filename']) . "</a><br><br>"
$stop++; 

$content .= "<br><a href=\"index.php">Go to gallery</a></center>"; 
print 
$content;
?>

include this where you want the images to show or save as a file and include in your main page like
<? include('pathname/filename');?>

duntuk

gtroll...

well... that didn't work for me... seems like somewhere the file paths are being lost when calling the 'include'... because it keeps giving errors about all lines that are not given the absolute path in init.inc.php...

hence... when it gets to this part... it states that "include/config.inc.php" can't be found...

// Include config and functions files
require 'include/config.inc.php';
require 'include/functions.inc.php';


but if you actually change the above to give an absolute path, then it works, but continues to give errors for everything else down the line using a 'require'....

 :?

Joachim Müller

well if you don't care about security that much or you simply don't have private albums, but only public ones you could give ssi.php a try. Like Tarique said: we do not recommend it any more, but it'll give you a little more control and is reported to work on many sites.
Download here: http://prdownloads.sourceforge.net/coppermine/cpg1.1mod_ssi.zip?download (instructions included).

GauGau

duntuk

thanks gaugau... will give it a go... (since i won't be using CPG for private galleries...... 4images will be used for that, since that supports multiple forum group permissions...)
 :wink:

NHBA

Not haveing much luck with this I did have it working with SSI on the last version 1.1.1 but since upgrading ( or something else happened at the same time) it no longer works I just get errors "failed to create stream : No Such File or dir " as the path in line 6 of example.php doesn't seem to point to my SSI.PHP file which makes more errors " undefined function calls" I also tried GTROLL'S hacked scripted but also had no luck as it give me a "T String error" on line 53 (displaying the gallery index.php file) no pics at all.
 I though the random picture was in the new version but now find it was just in the wish list of the SSI doc file any chance of adding it to a future version as its a nice touch for a logon/main page.

Keep up the great work regards Damon

2pac

Hi,

You're getting that TSTRING error cause on this line

$content .= "<br><a href=\"index.php">Go to gallery</a></center>";


is not closed on the "

so should be


$content .= "<br><a href=\"index.php\">Go to gallery</a></center>";




Hope this helps,

2pac
2pac is not alive but it is his music!

duntuk

The initial instructions by gtroll would ONLY work if you had the page, you wanted to display the random photo on, in the SAME directory as coopermine....

if you put it anywhere else... the paths would break....

however... there's a simple solution...

1. create a file called, for example, ssi_include.php in your root coopermine directory, and copy/paste gtroll's code, and save the file...

2. let's say you wanted to include this on your home page, then edit index.htm in your root public-html directory...

and insert the following code where ever you'd like:



<?php include_once &#40;'http&#58;//www.sitename.com/cooperminedir/ssi_include.php'&#41;; ?>



and pa-dow... and that should do it....

although, i should note, it's comming up with broken images, as of this writing... but atleast the code fully executes now... heh...

duntuk

ok... that was easy....

just had to add the path to coopermine:

here's the corrected code (we'll assume our coopermine directory is called 'gallery')



<?php 
// ------------------------------------------------------------------------- // 
// Coppermine Photo Gallery 1.2.0                                            // 
// ------------------------------------------------------------------------- // 
// Copyright &#40;C&#41; 2002,2003 Gregory DEMAR <gdemar@wanadoo.fr>                 // 
// http&#58;//www.chezgreg.net/coppermine/                                       // 
// ------------------------------------------------------------------------- // 
// Updated by the Coppermine Dev Team                                        // 
// &#40;http&#58;//coppermine.sf.net/team/&#41;                                          // 
// see /docs/credits.html for details                                        // 
// ------------------------------------------------------------------------- // 
// 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         // 
// &#40;at your option&#41; any later version.                                       // 
// ------------------------------------------------------------------------- // 
// hack from the nuke port for the standalone  version                  // 
// by gtroll                                                                                // 
// modify aid!=4 AND aid!=6 AND aid!=7                                         // 
// to fit the album&#40;s&#41; you want not to show                                        // 
// ------------------------------------------------------------------------- // 

define&#40;'IN_COPPERMINE', true&#41;; 
require&#40;'include/init.inc.php'&#41;; 
$numberpic=5// you can change the number of pictures here 
global $prefix$dbi
function 
truncate_string444&#40;$str&#41; 
&#123; 
   
$maxlength 20// maximum lenght of name in block 
    
   
if &#40;strlen&#40;$str&#41; > $maxlength&#41; 
      
return substr&#40;$str, 0, $maxlength&#41;." ..."; 
   
else 
      return 
$str
&
#125; 

$content="<center>"
$result db_query&#40;"SELECT count&#40;*&#41; from cpg_pictures WHERE aid!=4 AND aid!=6 AND aid!=7", $dbi&#41;; 
   
$nbEnr mysql_fetch_array&#40;$result&#41;; 
   
$count $nbEnr[0&#93;; 
while &#40;$stop<$numberpic&#41; 
&#123; 
    
   
srand&#40;time&#40;&#41;+$stop&#41;; 
   
$random_number rand&#40;0, $count-1&#41;; 
   
$result2 db_query&#40;"SELECT pid, aid, filepath, filename  from cpg_pictures WHERE aid!=4 AND aid!=6 AND aid!=7  AND approved='YES' LIMIT $random_number,1", $dbi&#41;; // aid numbers can be changed as need to respect permissions 
  
$picture mysql_fetch_array&#40;$result2&#41;; 
  
   
$img "<img src=\"gallery/&#123;$picture['filepath'&#93;&#125;thumb_&#123;$picture['filename'&#93;&#125;\"  border=\"0\">"
   
$content .= "<a href=\"gallery/displayimage.php&album=random&cat=&pos=-&#123;$picture['pid'&#93;&#125;\">$img<br>" truncate_string444&#40;$picture['filename'&#93;&#41; . "</a><br><br>"; 
$stop++; 
&
#125; 
$content .= "<br><a href=\"gallery/index.php\">Go to gallery</a></center>"
print 
$content
?>



alirezaok

if i want display all random pictueres of all albums without one specail album in front page site with use ssi hack what do i do?

Joachim Müller

using ssi.php, this will show a random pic of your gallery (any album):<?php
print cpg_thumb(0,0,1,"",1);
?>
GauGau

duntuk

yeah.. i'd definitely recommend gaugau's ssi.php over gtroll's way...

i'm 90% sure that gtroll's hack doesn't work like it's suppose to...  hence it only shows the same photo, with no 'random' aspect...

i only tested this with 1 album (since that's all i have setup), but with 1 album it definitely isn't random at all... but static, showing the same 1 photo...

and there also seems to be unnessary code, e.g.:

srand(time()+$stop);

which i can't see has any purpose...

unless, i'm wrong... this hack should NOT be recommended at all...

even the the author claims that he didn't check to see if his *own* code worked......  that's pretty bad... posting a mod that you didn't even check to see if it works or not.... tisk tisk...

btw... gaugau, you should edit one of your posts recommending this as one of the hacks... cause it's that post that brought me back here for a second try, which showed, that the code actually was garbage...

 :D

ojohn

In the ssi.php there is this line:

<? print cpg_thumb(0,0,4,0,0); ?>

what do each one do?

Joachim Müller

did you have a look at the readme and the example that comes with ssi.zip? It's all in there!
The syntax is<?
$cpg_include_link=1; // thumbnails are links? 0=no, 1=yes
$cpg_link_singlepic=0; // link points to album or single pic? 0=album, 1=single pic
$cpg_how_many=8; // how many thumbs do you need?
$cgp_limit_album=""; // specify certain album, ""=all
$cpg_random=0; //get random pic 0=no, 1=yes
print cpg_thumb($cpg_include_link,$cpg_link_singlepic,$cpg_how_many,$cgp_limit_album,$cpg_random);
?>
or shortened<? print cpg_thumb($cpg_include_link,$cpg_link_singlepic,$cpg_how_many,$cgp_limit_album,$cpg_random,"_blank"); ?>
In your case, this means: show a thumbnail with
0 = no link pointing to the large pic
0 = no link to a single pic
4 = display a row of four thumbnails
0 = do not restrict to a special album (in other words: from any album)
0 = don't show a random pic (switching random off means showing the last uploaded)

I'd really appreciate if you did some reading before asking questions.

GauGau

chillypk

Great script!
I got it working right away.
One quick question?

It seems to be defaulting to a thumbnail dimension thats no longer the way its configured to the main gallery. I think the default was height dependent 100 pixels.

I changed it to width dependent 100 px on config - so it fits in a column im using for "last picture uploaded".

Shows up in the main gallery OK - albeit ugly.  But when using the example script it shows up as the old default 100pixels height dependent. I cleared cookies and it still seems to be showing the same thing.

Am I missing something?
It would be great if that was configurable :)

I think height dependent looks a lot better in album view but for my random picture in a column it would have to be width dependent obviously for layout purposes.

THanks!

chillypk

Hmm - well I found a way to fix it - although its not pretty - I deleted all the albums and reuploaded them using the new parameters - so now the thumbanails are at the new default size.

So problem fixed goin forward.

I also noticed in the ssi.php code some code about showing the title and other fields text?

Is that being used - documented somewhere?
It would be great to show the title and other info underneath the photo :)