News:

CPG Release 1.6.29
During HTML5 upload, keep pseudo blank code 200 messages from triggering error condition
added Russian language
correct failure to use theme menu icons in album manager
minor vulnerabilities mitigation

Main Menu

Help needed with blocks

Started by keiju, October 22, 2003, 11:20:03 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

keiju

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

DJMaze

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

Quote from: "DJMaze"$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)

sigi

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

$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
$albumnumber=4;
direct after that. Change the number to suit your needs...

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

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

change the line that reads


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

to
$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
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

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

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

kegobeer

Right idea, but a small error:
$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid='".$albumnumber."'", $dbi);
should be$result = sql_query("SELECT count(*) from cpg_pictures WHERE aid=$albumnumber", $dbi);
and$result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES', aid='".$albumnumber."' LIMIT $random_number,1", $dbi);
should be$result2 = sql_query("SELECT pid, aid, filepath, filename  from cpg_pictures WHERE approved='YES', aid=$albumnumber LIMIT $random_number,1", $dbi);
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

change the comma to "and" ind the query

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

see it in all its glory at www.ally.sigi-2.de :-)
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

Well M8´s Big Thanks !!!

Now it works !

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

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