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: Help needed with blocks  (Read 5472 times)

0 Members and 1 Guest are viewing this topic.

keiju

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Help needed with blocks
« on: October 22, 2003, 11:20:03 pm »

I checked the other posts in this forum but couldnt find what im searching for.

żHow to make a php-nuke block that shows random image from 1 album and no one else?

I found a topic about making a block exclude other albums but i want to restrict (not exclude, that would make me change the block whenever i put a new album) AND it didn´t work anyways for me :(

THX in advance :)
Logged

DJMaze

  • VIP
  • Coppermine addict
  • ***
  • Offline Offline
  • Posts: 831
    • Dragonfly CMS
Help needed with blocks
« Reply #1 on: October 23, 2003, 01:53:54 am »

Code: [Select]
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
   $nbEnr = mysql_fetch_array($result);
   $count = $nbEnr[0];

while ($stop<$numberpic)
{
   srand(time()+$stop);
   $random_number = rand(0, $count-1);
   $result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
  $picture = mysql_fetch_array($result2);

Ofcourse set $albumnumber to the labum you wanna view
Logged
There are 2 kinds of users in this world: satisfied and complainers.
Why do we never hear something from the satisfied users?
http://coppermine-gallery.net/forum/index.php?topic=24315.0

keiju

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Help needed with blocks
« Reply #2 on: October 23, 2003, 12:21:45 pm »

Quote from: "DJMaze"
Code: [Select]
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
   $nbEnr = mysql_fetch_array($result);
   $count = $nbEnr[0];

while ($stop<$numberpic)
{
   srand(time()+$stop);
   $random_number = rand(0, $count-1);
   $result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
  $picture = mysql_fetch_array($result2);

Ofcourse set $albumnumber to the labum you wanna view


sorry, must i save that code in a block-name.php way?

and to set the album i have to put a "$albumnumber = 10" first or what?

(im really stupid, i know)
Logged

sigi

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 68
    • http://www.allygally.de
Help needed with blocks
« Reply #3 on: October 24, 2003, 08:41:03 am »

in the coppermine.1.1.d.zip there are plenty of blocks ....

grab block-Random_pictures.php ans save it as block-oneRandom_Picture.php

then open it in an editor

change the line that reads

Code: [Select]
$numberpic=5; // you can change the number of pictures here

to the number of pics you want to see - 1 I think :-)

add a line
Code: [Select]
$albumnumber=4;
direct after that. Change the number to suit your needs...

change the line that reads
Code: [Select]
$result = sql_query("SELECT count(*) from cpg_pictures", $dbi);  
to

Code: [Select]
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);

change the line that reads


Code: [Select]
$result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES' LIMIT $random_number,1", $dbi);  

to
Code: [Select]
$result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);


save it
use it
Logged
Siegfried Schlosser

Berlin, Germany

had a big Coppermine gallery with more than 250.000 pics  at
www.allygally.de, but due to juristical problems that is closed now ....
Now trying Coppermine 1.4.x at http://walexis.pytalhost.de/

keiju

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
Help needed with blocks
« Reply #4 on: October 24, 2003, 11:49:53 am »

BIG Thanks... but... it doesnt work  :roll:  :cry:  :roll:  :(  :oops:

Ur explanation was very clear but i cant see any image in the block :/

Here´s what comes in my edited file żok?:

Code: [Select]
<?php 

/************************************************************************/ 
/* PHP-NUKE&#58; Web Portal System                                          */ 
/* ===========================                                          */ 
/*                                                                      */ 
/* Copyright &#40;c&#41; 2002 by Francisco Burzi                                */ 
/* http&#58;//phpnuke.org                                                   */ 
/*                                                                      */ 
/* 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.       */ 
/************************************************************************/ 

/* Block to fit perfectly in the center of the site, remember that not all 
   blocks looks good on Center, just try and see yourself what fits your needs */ 

if &#40;eregi&#40;"block-Random_pictures.php", $PHP_SELF&#41;&#41; &#123; 
    
Header&#40;"Location&#58; index.php"&#41;; 
    
die&#40;&#41;; 
&#125; 

$numberpic=1// you can change the number of pictures here 
$albumnumber=10;

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 sql_query&#40;"SELECT count&#40;*&#41; from cpg_pictures WHERE aid='".$albumnumber."'", $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 sql_query&#40;"SELECT pid, aid, filepath, filename from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi&#41;;

  
$picture mysql_fetch_array&#40;$result2&#41;; 
  
   
$img "<img src=\"&#123;$picture['filepath'&#93;&#125;thumb_&#123;$picture['filename'&#93;&#125;\"  border=\"0\">"
   
$content .= "<a href=\"modules.php?name=coppermine&file=displayimage&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=\"modules.php?name=coppermine\">Go to gallery</a></center>"
?>


żAny Failures? żAny Idea?
Logged

kegobeer

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 4637
  • Beer - it does a body good!
    • The Kazebeer Family Website
Help needed with blocks
« Reply #5 on: October 24, 2003, 01:32:37 pm »

Right idea, but a small error:
Code: [Select]
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
should be
Code: [Select]
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid=$albumnumber", $dbi);
and
Code: [Select]
$result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
should be
Code: [Select]
$result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES', aid=$albumnumber LIMIT $random_number,1", $dbi);
Logged
Do not send me a private message unless I ask for one.  Make your post public so everyone can benefit.

There are no stupid questions
But there are a LOT of inquisitive idiots

sigi

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 68
    • http://www.allygally.de
Help needed with blocks
« Reply #6 on: October 24, 2003, 01:34:34 pm »

change the comma to "and" ind the query

... approved='YES' and aid= .-.-.

see it in all its glory at www.ally.sigi-2.de :-)
Logged
Siegfried Schlosser

Berlin, Germany

had a big Coppermine gallery with more than 250.000 pics  at
www.allygally.de, but due to juristical problems that is closed now ....
Now trying Coppermine 1.4.x at http://walexis.pytalhost.de/

keiju

  • Coppermine newbie
  • Offline Offline
  • Posts: 4
NOW IT WORKS !!! :)
« Reply #7 on: October 24, 2003, 03:26:56 pm »

Well M8´s Big Thanks !!!

Now it works !

I´ll put here the code for anyone in future that needs this żok? :)

Code: [Select]
<?php 

/************************************************************************/ 
/* PHP-NUKE&#58; Web Portal System                                          */ 
/* ===========================                                          */ 
/*                                                                      */ 
/* Copyright &#40;c&#41; 2002 by Francisco Burzi                                */ 
/* http&#58;//phpnuke.org                                                   */ 
/*                                                                      */ 
/* 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.       */ 
/************************************************************************/ 

/* Block to fit perfectly in the center of the site, remember that not all 
   blocks looks good on Center, just try and see yourself what fits your needs */ 

if &#40;eregi&#40;"block-Random_pictures.php", $PHP_SELF&#41;&#41; &#123; 
    
Header&#40;"Location&#58; index.php"&#41;; 
    
die&#40;&#41;; 
&#125; 

$numberpic=1// you can change the number of pictures here 
$albumnumber=10;

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 sql_query&#40;"SELECT count&#40;*&#41; from cpg_pictures WHERE aid=$albumnumber", $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 sql_query&#40;"SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES'AND aid=$albumnumber LIMIT $random_number,1", $dbi&#41;;
  
$picture mysql_fetch_array&#40;$result2&#41;; 
  
   
$img "<img src=\"&#123;$picture['filepath'&#93;&#125;thumb_&#123;$picture['filename'&#93;&#125;\"  border=\"0\">"
   
$content .= "<a href=\"modules.php?name=coppermine&file=displayimage&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=\"modules.php?name=coppermine\">Go to gallery</a></center>"
?>
Logged
Pages: [1]   Go Up
 

Page created in 0.091 seconds with 14 queries.