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] 2 3 4 5 ... 9   Go Down

Author Topic: Random image include? (SSI.php)  (Read 195922 times)

0 Members and 2 Guests are viewing this topic.

Brian

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
    • http://taiwanpictures.com
Random image include? (SSI.php)
« on: October 17, 2003, 03:37:11 am »

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!
« Last Edit: March 07, 2005, 08:35:24 am by GauGau »
Logged

Zarsky

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 268
    • Zerr Family Website
Random image include?
« Reply #1 on: October 17, 2003, 04:19:57 am »

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.
Logged
Read the Online DOCs, FAQ, and SEARCH the board BEFORE posting questions for help.

Brian

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
    • http://taiwanpictures.com
Random image include?
« Reply #2 on: October 17, 2003, 05:49:23 am »

Will this work with the latest 1.2 rc?
Logged

jasendorf

  • VIP
  • Coppermine frequent poster
  • ***
  • Offline Offline
  • Posts: 350
    • http://www.338tharmyband.com
Random image include?
« Reply #3 on: October 17, 2003, 06:26:02 am »

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

Tarique Sani

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Gender: Male
  • Posts: 2712
    • http://tariquesani.net
Random image include?
« Reply #4 on: October 17, 2003, 06:33:47 am »

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

gtroll

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 618
    • CPG-Nuke
Random Images
« Reply #5 on: October 17, 2003, 08:06:23 am »

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...
Code: [Select]
<?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
Code: [Select]
<? include('pathname/filename');?>
« Last Edit: October 25, 2004, 02:22:57 pm by Casper »
Logged

duntuk

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Random image include?
« Reply #6 on: November 03, 2003, 07:55:02 am »

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...

Code: [Select]
// 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'....

 :?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Random image include?
« Reply #7 on: November 03, 2003, 08:03:29 am »

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
Logged

duntuk

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Random image include?
« Reply #8 on: November 03, 2003, 06:35:56 pm »

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:
Logged

NHBA

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Random Pics on non Coppermine page (CPG 1.2.0)
« Reply #9 on: November 11, 2003, 10:32:58 am »

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
Logged

2pac

  • Coppermine newbie
  • Offline Offline
  • Posts: 1
Random image include?
« Reply #10 on: December 07, 2003, 01:02:20 am »

Hi,

You're getting that TSTRING error cause on this line

Code: [Select]
$content .= "<br><a href=\"index.php">Go to gallery</a></center>";


is not closed on the "

so should be

Code: [Select]

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




Hope this helps,

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

duntuk

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
actually... this is how it works...
« Reply #11 on: December 21, 2003, 04:35:11 am »

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:

Code: [Select]


<?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...
Logged

duntuk

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Random image include?
« Reply #12 on: December 21, 2003, 04:45:09 am »

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')

Code: [Select]


<?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
?>


Logged

alirezaok

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 22
all pictures without one album
« Reply #13 on: December 21, 2003, 09:28:24 am »

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?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Random image include?
« Reply #14 on: December 21, 2003, 01:40:11 pm »

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

duntuk

  • Coppermine newbie
  • Offline Offline
  • Posts: 13
Random image include?
« Reply #15 on: December 22, 2003, 12:00:19 am »

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.:

Code: [Select]
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
Logged

ojohn

  • Coppermine novice
  • *
  • Offline Offline
  • Posts: 44
Quick Question?
« Reply #16 on: December 22, 2003, 09:04:56 pm »

In the ssi.php there is this line:

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

what do each one do?
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Random image include?
« Reply #17 on: December 22, 2003, 11:31:18 pm »

did you have a look at the readme and the example that comes with ssi.zip? It's all in there!
The syntax is
Code: [Select]
<?
$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
Code: [Select]
<? 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
Logged

chillypk

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Random image include?
« Reply #18 on: December 26, 2003, 10:03:24 am »

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!
Logged

chillypk

  • Coppermine newbie
  • Offline Offline
  • Posts: 7
Random image include?
« Reply #19 on: December 26, 2003, 10:45:29 am »

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 :)
Logged
Pages: [1] 2 3 4 5 ... 9   Go Up
 

Page created in 0.03 seconds with 20 queries.