SMFHacks.com

SMF Gallery Lite => SMF Gallery Lite => Topic started by: jklapp on September 22, 2006, 06:40:03 pm

Title: Random Image in Block?
Post by: jklapp on September 22, 2006, 06:40:03 pm
Can a random image be put in a block with SMF Gallery ?
Title: Re: Random Image in Block?
Post by: SMFHacks on September 22, 2006, 06:48:38 pm
You mean like a random image block for like tiny portal?
Just a box with a random image?
Title: Re: Random Image in Block?
Post by: jklapp on September 22, 2006, 09:23:44 pm
Yes :)
Title: Re: Random Image in Block?
Post by: SMFHacks on September 22, 2006, 09:30:06 pm
Yeah that wouldn't hard to do I could supply some TP codes later on.
Title: Re: Random Image in Block?
Post by: jklapp on September 22, 2006, 10:06:32 pm
Thank would be great!!!  Thank you :)
Title: Re: Random Image in Block?
Post by: BrocLee on September 29, 2006, 11:09:28 am
Yeah, that would be a cool addition :)
Title: Re: Random Image in Block?
Post by: usermike3969 on October 03, 2006, 03:21:29 am
i have a code that i use iin ssi.php that will show random imgs from what ever cat u wont  ;D

is it ok to put it here for everyone or is it something that u r doing for pro ver. only ???
Title: Re: Random Image in Block?
Post by: usermike3969 on October 03, 2006, 03:52:17 am
heres a live demo www.mib4life.com:8080 (http://www.mib4life.com:8080) on the left side 2nd block also with it being a ssi function u can use it even if your not using tportal
Title: Re: Random Image in Block?
Post by: SMFHacks on October 03, 2006, 06:35:49 pm
Ah, I see it now the sig spotlight
Title: Re: Random Image in Block?
Post by: usermike3969 on October 03, 2006, 06:44:14 pm
......so can i post the code here ?
Title: Re: Random Image in Block?
Post by: SMFHacks on October 03, 2006, 07:17:55 pm
I don't mind.
Title: Re: Random Image in Block?
Post by: usermike3969 on October 03, 2006, 07:33:17 pm
ok thanks....here it is

in ssi.php

Find :
Code: [Select]
?>
Place before :
Code: [Select]
function ssi_grandom ($cat)
{
mysql_select_db($db_name);
$query  = "SELECT `thumbfilename`,`ID_CAT`,`ID_PICTURE` FROM `smf_gallery_pic` WHERE `ID_CAT`='$cat' GROUP BY `thumbfilename` ORDER BY RAND() LIMIT 1";
$request = mysql_query($query);
while($row = mysql_fetch_array($request, MYSQL_ASSOC))
echo' <a href="' . $scripturl . '?action=gallery;sa=view;id=' . $row['ID_PICTURE'] . '"><img src="/gallery/'. $row['thumbfilename']  . '" />';}

then put in a php block   ssi_grandom(2);   where the 2 = cat number
Title: Re: Random Image in Block?
Post by: SMFHacks on October 03, 2006, 07:55:34 pm
Nice work,

I updated it a little
Code: [Select]
function ssi_grandom ($cat)
{
global $scripturl,$db_prefix;
$cat = (int) $cat;

$request = db_query("SELECT thumbfilename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = $cat GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);
echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="/gallery/', $row['thumbfilename'] ,'" />'

;}
Title: Re: Random Image in Block?
Post by: usermike3969 on October 03, 2006, 08:54:57 pm
cool thanks

i am not very good with php i didnt even know any php like 6 mo. ago and that was the first little code that i did on my own

again thanks for fixing it
Title: Re: Random Image in Block?
Post by: usermike3969 on October 04, 2006, 07:07:05 am
How about this ? It puts the linking codes below the thumb
Code: [Select]
function ssi_grandom ($cat)
{
    global $scripturl,$db_prefix;
    $cat = (int) $cat;

    $request = db_query("SELECT thumbfilename, filename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = $cat GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="/gallery/', $row['thumbfilename'] ,'" /></a>';
 ?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=350,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#000000"><center><font color="#FFFFFF">');
  tmp.write('HTML THUMB</br>&lt;img src="http://mib4life.com:8080/gallery/thumb_<?echo $row['filename'];?>"&gt; ');
  tmp.write('</br></br>HTML</br>&lt;img src="http://mib4life.com:8080/gallery/<?echo $row['filename']; ?>"&gt;');
  tmp.write('</br></br>BBC THUMB</br>[img]http://mib4life.com:8080/gallery/thumb_<?echo $row['filename'];?>[/img]');
  tmp.write('</br></br>BBC</br>[img]http://mib4life.com:8080/gallery/<?echo $row['filename']; ?>[/img]');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
<?
}


Title: Re: Random Image in Block?
Post by: usermike3969 on October 04, 2006, 07:13:27 am
is there a way to make it universal because i couldnt figger it out so that code only works for my site but if any one wont to use it just change all the www.mib4life.com:8080 to your site address
Title: Re: Random Image in Block?
Post by: usermike3969 on October 04, 2006, 07:43:02 am
nevermind i figgered it out i just forgot the a global lol heres the universal code
Code: [Select]
function ssi_grandom ($cat)
{
    global $scripturl,$modSettings,$db_prefix;
    $cat = (int) $cat;

    $request = db_query("SELECT thumbfilename, filename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = $cat GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="/gallery/', $row['thumbfilename'] ,'" /></a>';
 ?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=350,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#000000"><center><font color="#FFFFFF">');
  tmp.write('HTML THUMB</br>&lt;img src="<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>"&gt; ');
  tmp.write('</br></br>HTML</br>&lt;img src="<?echo $modSettings['gallery_url'].$row['filename']; ?>"&gt;');
  tmp.write('</br></br>BBC THUMB</br>[img]<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>[/img]');
  tmp.write('</br></br>BBC</br>[img]<?echo $modSettings['gallery_url'].$row['filename']; ?>[/img]');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
Title: Re: Random Image in Block?
Post by: jklapp on October 09, 2006, 11:17:30 pm
in ssi.php

Find :
Code: [Select]
?>

I'm confused... Could you explain this in more detail? ... Thank you :)
Title: Re: Random Image in Block?
Post by: usermike3969 on October 10, 2006, 08:24:11 am
in ssi.php

Find :
Code: [Select]
?>

I'm confused... Could you explain this in more detail? ... Thank you :)

if u look in your forums dir and find ssi.php and open it in a editor or notepad at the very bottem u will find ?> then place the code i gave right befor it
Title: Re: Random Image in Block?
Post by: jklapp on October 10, 2006, 10:41:08 am
For some reason it's not working... I'm not getting a picture in the block (only an empty space where the image should be) But if I click-on the empty space, it does take me to the image that should be showing.
Title: Re: Random Image in Block?
Post by: SMFHacks on October 10, 2006, 10:50:31 am
Yeah that is not the full random image. I have a good one in the paid section.
This one is missing the path to the images if you never set it.
Title: Re: Random Image in Block?
Post by: usermike3969 on October 10, 2006, 11:17:42 am
try this
Code: [Select]
function ssi_grandom ($cat)
{
    global $scripturl,$modSettings,$db_prefix;
    $cat = (int) $cat;

    $request = db_query("SELECT thumbfilename, filename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = $cat GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="',$modSettings['gallery_url'], $row['thumbfilename'] ,'" /></a>';
Title: Re: Random Image in Block?
Post by: jklapp on October 10, 2006, 12:13:02 pm
No.. That gives this error  :'(

Quote
Parse error: parse error in D:\Inetpub\akronsanctuary\smf\SSI.php on line 1642
Title: Re: Random Image in Block?
Post by: jklapp on October 10, 2006, 12:15:57 pm
What I need to do is talk to the Church people and get someone to donate this mod for the Church site :)
Title: Re: Random Image in Block?
Post by: usermike3969 on October 10, 2006, 12:17:48 pm
sorry i fixed it i forgot the } at the end of the code
Code: [Select]
function ssi_grandom ($cat)
{
    global $scripturl,$modSettings,$db_prefix;
    $cat = (int) $cat;

    $request = db_query("SELECT thumbfilename, filename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = $cat GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="',$modSettings['gallery_url'], $row['thumbfilename'] ,'" /></a>';
}
Title: Re: Random Image in Block?
Post by: usermike3969 on October 10, 2006, 12:29:07 pm
whats the url to your site if u dont mind me asking
Title: Re: Random Image in Block?
Post by: jklapp on October 10, 2006, 12:38:32 pm
Wow... Thank you :) That really works nice :)

I'm thinking about changing our Church site from Enigma 2.0 to Tiny Portal, so I've been testing mods.

Right now I'm using Gallery 2, but I'm starting to like this Gallery. :)

Our website is www.akronsanctuary.com (http://www.akronsanctuary.com) This is Enigma 2.0. The test site is not accessable from the net right now.
Title: Re: Random Image in Block?
Post by: Maya on October 10, 2006, 04:15:55 pm
I am trying to get this to go, without much luck.  ::)
2 questions, if I may...

I got the code in the ssi.php okay... I would like to run this in a front page block  ( using tp.95 and rc3) ,

1. Do I create a 'script block', and paste the code in there, ( in an ssi block there is no option for the code snippet ) ?
In other words... what type of block should I create?

2. If I wanted to change from just 1 image to say a block in the center showing 3 or 4...is this as simple as instead of 'Limit_1' in the code to say 'Limit_3' ?

tia


Title: Re: Random Image in Block?
Post by: SMFHacks on October 10, 2006, 04:42:05 pm
1. it would be a php block.

2. Very close that is part of it but you need to add a loop as well.
Title: Re: Random Image in Block?
Post by: xface on October 12, 2006, 03:42:46 am
so cool! those linking codes I could not get to work, but hell of an idea!!! thanks for this code, its helped alot!!!
Title: Re: Random Image in Block?
Post by: usermike3969 on October 12, 2006, 04:24:45 am
what happen when u tried the linking codes ???
Title: Re: Random Image in Block?
Post by: xface on October 12, 2006, 12:05:35 pm
fatal error, but I think I might have screwed something up there. I will try it again today now that I have a few hours of sleep under my belt. ;D

I will let you know how it turns out...
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 01:33:24 pm
I, understand code, but don't know how to write code, yet  ;) , so I am just content to get this working for now with 1 image...figure the rest out later

lol... not havin fun here...no biggie, just  trying this on a test site till I see something work.. ;D

heres what I have done..

added the code to the ssi.php

created a php block (thnx btw)

and heres what I get...

Quote
Fatal error: Cannot redeclare ssi_grandom() (previously declared in /home/talk/public_html/test/SSI.php:1595) in /home/talk/public_html/test/Sources/Load.php(1708) : eval()'d code(35) : eval()'d code on line 1

Title: Re: Random Image in Block?
Post by: SMFHacks on October 12, 2006, 01:41:33 pm
What are you putting in the php block?
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 02:14:36 pm
 ::)...k..( sorry Im workin on about 10 different thing right now...)

I pasted the wrong code in...
(its ok btw, I have just finished a slew of nasty words dericted to self....lol)

now I have put the correct call in the php box

ssi_grandom(2);



I removed the 2 to just make it ();

(if no cat is defined will it just call from all categories ?)

but get a red x...

it is trying to call the image from http://mysite/gallery and I need it to call them from mysite/test/gallery...
Is that back in the ssi.php code I put in...?




Title: Re: Random Image in Block?
Post by: usermike3969 on October 12, 2006, 03:04:40 pm
r u using the last code i gave here ??
Title: Re: Random Image in Block?
Post by: SMFHacks on October 12, 2006, 03:17:02 pm
This is correct code you all should use
Code: [Select]
function ssi_galleryrandom()
{
global $scripturl,$db_prefix,$modSettings,$boardurl;

if(empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}

$request = db_query("SELECT thumbfilename,ID_PICTURE FROM {$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);
echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] . $row['thumbfilename'] ,'" /></a>'

;}
Title: Re: Random Image in Block?
Post by: xface on October 12, 2006, 03:30:32 pm
yeah that is the correct code it works awesome.

What I liked about the other code was the linking codes. This would allow members of mine to host the photo at another forum, and in turn drag other visitor's to my site.....

I have not tryed the linking codes version posted earlier yet today, been to busy sleeping...LOL
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 03:48:57 pm
actually the code i had posted was
Code: [Select]
function ssi_grandom ($cat)
{
    global $scripturl,$modSettings,$db_prefix;
    $cat = (int) $cat;

    $request = db_query("SELECT thumbfilename, filename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = $cat GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
    $row = mysql_fetch_assoc($request);
    mysql_free_result($request);
    echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="',$modSettings['gallery_url'], $row['thumbfilename'] ,'" /></a>';
}

(this code got the pics well the red x showing..

I just replaced it with the code u posted and i am back to

Quote
Fatal error: Call to undefined function: ssi_grandom() in /home/talk/public_html/test/Sources/Load.php(1708) : eval()'d code(35) : eval()'d code on line 1

phpbox with "ssi_grandom(); "

 ???
Title: Re: Random Image in Block?
Post by: SMFHacks on October 12, 2006, 03:50:26 pm
If you use my code then you would put ssi_galleryrandom(); in the php box
Title: Re: Random Image in Block?
Post by: usermike3969 on October 12, 2006, 04:00:17 pm
Maya is what u wont to do is like what i have on my main page in the center at the bottem ??
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 04:07:26 pm
Perfect... ;) thank you...it works very well

Yes that is exactly what I want to do...a few adjustment for my site( and maybe without the info on bottom, but yes...

*btw thanks for the test for me... ;)
Title: Re: Random Image in Block?
Post by: usermike3969 on October 12, 2006, 04:10:38 pm
Code: [Select]
function ssi_g3random ()
{global $db_prefix, $scripturl, $txt, $context,$ID_MEMBER,$modSettings, $boarddir,$boardurl;
          echo'<table cellspacing="0" cellpadding="5" border="0" align="center" width="90%"><tr>';

         $request10 = db_query("SELECT z.ID_PICTURE, z.commenttotal, z.filesize, z.views, z.thumbfilename, z.title, z.ID_MEMBER, x.memberName, x.realName, z.date, z.description FROM {$db_prefix}gallery_pic as z, {$db_prefix}members AS x WHERE approved = 1 GROUP BY date ORDER BY RAND() DESC LIMIT 3", __FILE__, __LINE__);
          while ($row10 = mysql_fetch_assoc($request10))
          {
          echo'<td align="center" colspan="3"></br><a href="' . $scripturl . '?action=gallery;sa=view;id=' . $row10['ID_PICTURE'] . '"><img src="' . $modSettings['gallery_url'] . $row10['thumbfilename']  . '" /></a></br>';
         }
          mysql_free_result($request10);
          echo'</td></tr>';
          echo'</table></br>';
}

this is the code i used but mite not b the best way
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 05:46:58 pm
no dice...

back to parse error on fp

Parse error: syntax error, unexpected $end in /home/talk/public_html/test/Sources/Load.php(1708) : eval()'d code(35) : eval()'d code on line 1


when I changed this in the ssi,
I changed what i put in the php box to match

ssi_g3random ()
 
then back... hmmm
Title: Re: Random Image in Block?
Post by: Jpg on October 12, 2006, 06:58:15 pm
I'll help everyone out. I modified SMF Hack's code and made it center when it a block.. No biggy.



USE THIS ONE
Code: [Select]
function ssi_galleryrandom()
{
global $scripturl,$db_prefix,$modSettings,$boardurl;

if(empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}

$request = db_query("SELECT thumbfilename,ID_PICTURE FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);
echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;}

Put this in a PHP block.

Code: [Select]
ssi_galleryrandom();
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 07:10:18 pm
The code looks similar to an earlier post, but np

Thanks..I popped it in and ...

and it works, I just wanted to  uh.. 'enhance ' it now

show 3 or 4 images in a center block at once

do you know how? ;D
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 07:30:11 pm
rofl.. u should here what my son just asked
Title: Re: Random Image in Block?
Post by: Jpg on October 12, 2006, 07:31:33 pm
Let me take a look into it. I'll see what I can do. If I remember correctly I can make an infinite amount...
Title: Re: Random Image in Block?
Post by: usermike3969 on October 12, 2006, 08:33:43 pm
try like this

Code: [Select]
function ssi_galleryrandom()

 {
  global $scripturl,$db_prefix,$modSettings,$boardurl;
  echo'<table cellspacing="0" cellpadding="5" border="0" align="center" width="90%"><tr>';
  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
  $request = db_query("SELECT thumbfilename,ID_PICTURE FROM {$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 3", __FILE__,__LINE__);
  while ($row = mysql_fetch_assoc($request))
  echo' <center><td align="center" colspan="3"><a href="', $scripturl, '?action=gallery;sa=view;id=',
  $row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

  $row['thumbfilename'] ,'" /></a></center>';
  echo'</td></tr>';
  echo'</table></br>';
  mysql_free_result($request);
}
Title: Re: Random Image in Block?
Post by: Jpg on October 12, 2006, 08:43:35 pm
Nice.

I like it.
How about for 5...

Code: [Select]
function ssi_galleryrandom()
{
  global $scripturl,$db_prefix,$modSettings,$boardurl;
  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }

  $request = db_query("SELECT thumbfilename,ID_PICTURE
                                FROM {$db_prefix}gallery_pic
                                ORDER BY RAND() LIMIT 5", __FILE__, __LINE__);

  while ($row = mysql_fetch_assoc($request))
  {
    echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] . $row['thumbfilename'] ,'" /></a></center>';
  }
  mysql_free_result($request);
}

I got some help from a pal of mine. :)

Shows 5. Just add this to the bottom of your SSi.php.
Then you can use the SSI function
Code: [Select]
ssi_galleryrandom();
Title: Re: Random Image in Block?
Post by: usermike3969 on October 12, 2006, 08:57:17 pm
nice but it puts them under each other and i think she wonted them beside each other thats y i made the tables in the code i edited
Title: Re: Random Image in Block?
Post by: Jpg on October 12, 2006, 09:06:59 pm
I love your idea much more better. :D
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 09:07:30 pm
hehe... ur right usermike...5 random go vertical..

I definitely want them to go horrorzontally... :P

autothumbnailing too... sure looks like it from the pics I put in for test..*thmbs up 2u

very cool...



Title: Re: Random Image in Block?
Post by: usermike3969 on October 12, 2006, 09:12:09 pm
so does that mean it worked ??? ?
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 09:22:26 pm
 :D lol...sorry...( im trying to cook some grub too...)

yes it worked..I even experimented....

changed the colspan from 3 to 5
and the limit 3 to limit 5...

voila...perfect ( almost: auto- height resizes but not width)

sorry for takin so long...


and thanks all for your patience...  :D
Title: Re: Random Image in Block?
Post by: Jpg on October 12, 2006, 10:57:18 pm
I had some fun with the template with this code.
I'll post up some codes later, some for editing it like adding a logo and 5 most recent images, and 5 random images with little pictures as headers...blah blah blah.
Title: Re: Random Image in Block?
Post by: Maya on October 12, 2006, 11:15:57 pm
cool Jpg

5 most recent for a tp side block... :)

what about having them able to randomise from certain cats only....

ie: have one center block for a cat of artwork and one for musicians run in another block right below...

uh oh...I feel a few more ideas comin on...lol

btw-same Maya  ;)

Title: Re: Random Image in Block?
Post by: xface on October 12, 2006, 11:29:37 pm
what happen when u tried the linking codes ???

This:

Parse error: syntax error, unexpected '=' in /full/directory/path/www/site/SSI.php on line 1572

I have tryed just about every combination to get it included, but then again my knowledge is not all that great, LOL!!
Title: Re: Random Image in Block?
Post by: usermike3969 on October 13, 2006, 01:13:46 am
try this

Code: [Select]
function ssi_galleryrandom()
{
  global $scripturl,$db_prefix,$modSettings,$boardurl;

  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
 
  $request = db_query("SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
  $row = mysql_fetch_assoc($request);
  mysql_free_result($request);
  echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;
?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=350,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#000000"><center><font color="#FFFFFF">');
  tmp.write('HTML THUMB</br>&lt;img src="<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>"&gt; ');
  tmp.write('</br></br>HTML</br>&lt;img src="<?echo $modSettings['gallery_url'].$row['filename']; ?>"&gt;');
  tmp.write('</br></br>BBC THUMB</br>[img]<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>[/img]');
  tmp.write('</br></br>BBC</br>[img]<?echo $modSettings['gallery_url'].$row['filename']; ?>[/img]');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
<?
}
place this before
Code: [Select]
?>
Title: Re: Random Image in Block?
Post by: xface on October 13, 2006, 09:41:07 am
yup that works perfect!! is there an easy way to combine the thumbnail with the direct link to the gallery full image page? I think this little code is priceless!!!

your the king!
Title: Re: Random Image in Block?
Post by: xface on October 13, 2006, 10:13:11 am
I changed up your output codes to this:
Code: [Select]
function ssi_galleryrandom()
{
  global $scripturl,$db_prefix,$modSettings,$boardurl;

  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
 
  $request = db_query("SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
  $row = mysql_fetch_assoc($request);
  mysql_free_result($request);
  echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;
?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=250,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#FFFFFF"><center><font color="#000000" size="1" face="verdana">');
  tmp.write('HTML For Websites:</br><form><textarea rows="2" cols="90">&lt;a href="<?echo $modSettings['gallery_url'].$row['filename']; ?>"&gt;&lt;img src="<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>"&gt;&lt;/a&gt;</textarea></form> ');
  tmp.write('</br></br>BBC For Forums</br><form><textarea rows="2" cols="90">[url=<?echo $modSettings['gallery_url'].$row['filename']; ?>][img]<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>[/img][/url]</textarea></form>');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
<?
}
and it works awesome as well.....
This way the code is easily selected and copied.
Title: Re: Random Image in Block?
Post by: Jump1979man on October 13, 2006, 11:07:34 am
I'll help everyone out. I modified SMF Hack's code and made it center when it a block.. No biggy.



USE THIS ONE
Code: [Select]
function ssi_galleryrandom()
{
global $scripturl,$db_prefix,$modSettings,$boardurl;

if(empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}

$request = db_query("SELECT thumbfilename,ID_PICTURE FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);
echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;}

Put this in a PHP block.

Code: [Select]
ssi_galleryrandom();



Code works great!  Thanks.
Title: Re: Random Image in Block?
Post by: Jump1979man on October 13, 2006, 11:08:11 am
Anyway to have like the first 2 or three comments to show up as well???
Title: Re: Random Image in Block?
Post by: Warbird on October 30, 2006, 10:35:25 am
I did what you guys did but still got a error in this box.

Quote
Parse error: parse error, unexpected $ in /var/www/vhosts/placenholder/subdomains/forums/httpdocs/Sources/Load.php(1718) : eval()'d code(35) : eval()'d code on line 1

What can it be ?

Title: Re: Random Image in Block?
Post by: Warbird on October 30, 2006, 10:40:55 am
Hmm, ok, got it working now, donīt know why it didnīt worked before, but ok. One more question, is it possible to make a bigger thumbnail size ?

Its 104 x 78, but I would prefer the thumb more around 150 or 160 width, is that possible ?

WarBirD
Title: Re: Random Image in Block?
Post by: SMFHacks on October 30, 2006, 10:48:09 am
Well you could use html to enlarge the size of the image or if you really want a larger image you would need to change the thumbnail size in Gallery.php
Title: Re: Random Image in Block?
Post by: Warbird on October 30, 2006, 11:00:18 am
Where in the text I put in SSI.PHP would be the place where to make it with HTML. Sry, i am not sure in code and all that.
Title: Re: Random Image in Block?
Post by: Warbird on October 30, 2006, 11:10:13 am
Ok, since I donīt know where in the SSI.PHP Lines i added, i tried the GALLERY.PHP. There is quite sometimes the values 104 and 78 which I assume is the width and height. Changed them all, but still shows the same size as before. Anything else ?

WarbiRd
Title: Re: Random Image in Block?
Post by: Warbird on October 30, 2006, 11:15:49 am
Ok, my Browserīs cache played badly on me. But here is the problem if I do it with the changes in GALLERY.PHP, it only creates Thumbs from now on with that Size. All the Images I had before in there are in the old Size. So I would like to have some help where to do the HTML resize values with width="" and height="" in the code I added to the SSI.PHP.

P.S: How to get rid of the LINKING CODES button ?
Title: Re: Random Image in Block?
Post by: Hack on November 11, 2006, 11:02:19 am
thought I would add my little bit of code to this block section too. All I have basically added is the Images name below each of the pictures thats shown in the block (also added a 'alt' tag for the image)

Code: [Select]
function ssi_galleryrandom()
{
  global $scripturl,$db_prefix,$modSettings,$boardurl;
  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }

  $request = db_query("SELECT thumbfilename, ID_PICTURE, title, description
                                FROM {$db_prefix}gallery_pic
                                WHERE ID_CAT NOT LIKE '%7%'
                                ORDER BY RAND() LIMIT 3", __FILE__, __LINE__);

  while ($row = mysql_fetch_assoc($request))
  {
    echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] . $row['thumbfilename'] ,'" style="padding-bottom:3px; padding-top:6px" alt="Random Gallery Mini Image" /><br />' . $row['title'] . '<br /></a></center>';
  }
  mysql_free_result($request);
}

Got a feeling I have probably got the 'style' part of the image src thing incorrect, but I am only a beginner with this sort of thing. If you only want certain catagorys showing you will need to exclude them by changing the 'ID_CAT not like' part to exclude the catagory you dont want to be included (in my case it stops the news post images being included as part of the random image display).

Thanks for the block though, makes th site look snazzy. All I want to really add to this now is the ability to make it 'scroll' like you see with the phpnuke blocks.. does anyone know how to do this? (will save me some time if they do..)
Title: Re: Random Image in Block?
Post by: Protocultura on November 20, 2006, 09:30:59 am
Hi, I'm receiving the same error reported a few lines ago.
Code: [Select]
Fatal error: Call to undefined function: ssi_galleryrandom() in /home/c4dbra/public_html/Sources/Load.php(1708) : eval()'d code on line 427
Somebody knows why?
Thanks.
Title: Re: Random Image in Block?
Post by: SMFHacks on November 20, 2006, 09:45:10 am
Do you have the ssi_galleryrandom() in SSI.php and are you using an SSI block?
Title: Re: Random Image in Block?
Post by: Protocultura on November 20, 2006, 10:02:33 am
Yep.
SSI.php
Code: [Select]
function ssi_galleryrandom()
{
  global $scripturl,$db_prefix,$modSettings,$boardurl;

  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
 
  $request = db_query("SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
  $row = mysql_fetch_assoc($request);
  mysql_free_result($request);
  echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;
?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=250,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#FFFFFF"><center><font color="#000000" size="1" face="verdana">');
  tmp.write('HTML For Websites:</br><form><textarea rows="2" cols="90">&lt;a href="<?echo $modSettings['gallery_url'].$row['filename']; ?>"&gt;&lt;img src="<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>"&gt;&lt;/a&gt;</textarea></form> ');
  tmp.write('</br></br>BBC For Forums</br><form><textarea rows="2" cols="90">[url=<?echo $modSettings['gallery_url'].$row['filename']; ?>][img]<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>[/img][/url]</textarea></form>');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
<?
}
?>

index.template.php
Code: [Select]
<table width="860" border="0" cellpadding="0" cellspacing="0">

<tr>
<td>';
ssi_galleryrandom();
echo '</td>
</tr>

<tr>...
Any idea?
Thanks
Title: Re: Random Image in Block?
Post by: SMFHacks on November 20, 2006, 10:12:09 am
oh that code won't work since SSI requires that it be loaded before all php


You would need to replace ssi_galleryrandom(); in your index.template.ph with something like
Code: [Select]
global $scripturl,$db_prefix,$modSettings,$boardurl;

  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
 
  $request = db_query("SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
  $row = mysql_fetch_assoc($request);
  mysql_free_result($request);
  echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;
?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=250,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#FFFFFF"><center><font color="#000000" size="1" face="verdana">');
  tmp.write('HTML For Websites:</br><form><textarea rows="2" cols="90">&lt;a href="<?echo $modSettings['gallery_url'].$row['filename']; ?>"&gt;&lt;img src="<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>"&gt;&lt;/a&gt;</textarea></form> ');
  tmp.write('</br></br>BBC For Forums</br><form><textarea rows="2" cols="90">[url=<?echo $modSettings['gallery_url'].$row['filename']; ?>][img]<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>[/img][/url]</textarea></form>');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
<?
Title: Re: Random Image in Block?
Post by: Protocultura on November 20, 2006, 10:59:16 am
thanks, works like a charm!
You can see the mod in my site www.c4dbrasil.com
Thanks SMFHacks a priceless piece of code!!!
Title: Re: Random Image in Block?
Post by: Protocultura on November 20, 2006, 04:35:46 pm
One last thing, this mod shows not aproved images, there is a way to block not admited images?
Cheers.
Title: Re: Random Image in Block?
Post by: SMFHacks on November 20, 2006, 04:45:44 pm
Change
Code: [Select]
SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1"
To
Code: [Select]
SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic Where approved = 1 GROUP BY thumbfilename ORDER BY RAND() LIMIT 1"
Title: Re: Random Image in Block?
Post by: craftervillage on March 18, 2007, 10:04:50 pm
thanks, works like a charm!
You can see the mod in my site www.c4dbrasil.com
Thanks SMFHacks a priceless piece of code!!!

Your site is very nice. I tried and tried to get the code to work on my board. No dice. I like the way your thumbnails are all the same size. Looks very professional. I don't understand a word on your site but the design is excellent!! Maybe soon I will figure out how to get the block code to work on mine. I wish it was in the mod package to make it easy. I think it is too hard for me to understand. I only know the html old school.  :( I am an php idiot. I bought the pro version in high hopes of a block code pre installed on it.  :'(
I have just started the board and have not any members yet and at this rate maybe I will give up. I have a design that I like called christmas2006_11. It's just right for my forum but the button would not show on it so I had to reinstall the whole thing over and I did not install the template a second time. 
Title: Re: Random Image in Block?
Post by: SMFHacks on March 19, 2007, 06:50:28 am
If you need help adding a button for the menu on a custom theme I can do that for you. Just attach your index.template.php of your custom theme.
Title: Re: Random Image in Block?
Post by: craftervillage on March 19, 2007, 08:48:36 am
I think that's the right file. Let me know if it's not. Thank you for doing that. I can't wait to start up my board. I really like the gallery. The old gals will like it too. Thanks again for the help.
craftervillage.com/board/
Title: Re: Random Image in Block?
Post by: ~Alex on March 19, 2007, 08:07:55 pm
Well, I've got the SMF Gallery Lite v1.7 or so and have tried to do as everyone's indicated, but I keep getting an SSI error, after copying the code, pasting it, then creating the php block.

Can someone be a bit more specific about which one is the correct code to use?

I'm on SMF 1.1.2 and TP 0.9.8.

Which code goes into SSI.php? Which command goes into the PHP we are suppose to create? And lastly, what I'm trying to do is create a random image block, am I even reading the correct thread?  ;D
Title: Re: Random Image in Block?
Post by: SMFHacks on March 19, 2007, 09:25:32 pm
I think that's the right file. Let me know if it's not. Thank you for doing that. I can't wait to start up my board. I really like the gallery. The old gals will like it too. Thanks again for the help.
craftervillage.com/board/


File attached with gallery menu
Title: Re: Random Image in Block?
Post by: ~Alex on March 19, 2007, 11:48:28 pm
SMFHacks...Taking that index template and replacing it with the one I have, changes my entire board to something unrecognizable...
Title: Re: Random Image in Block?
Post by: ~Alex on March 19, 2007, 11:49:46 pm
Unless that response was not meant for me?
Title: Re: Random Image in Block?
Post by: SMFHacks on March 20, 2007, 06:56:55 am
That was not meant for you.
Title: Re: Random Image in Block?
Post by: ~Alex on March 20, 2007, 07:53:59 pm
That was not meant for you.

LoL. Well, can someone advise?
Title: Re: Random Image in Block?
Post by: ~Alex on March 21, 2007, 01:18:16 am
any help is appreciated.

i'm on 1.1.2 w/ TP .98.
Title: Re: Random Image in Block?
Post by: craftervillage on March 21, 2007, 09:51:39 am
I managed to get some code to work on my site for a random images.

   
global $scripturl,$db_prefix,$modSettings,$boardurl;

echo'<table cellspacing="0" cellpadding="1" border="0" align="center" width="90%"><tr>';
if(empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}
$request = db_query("SELECT thumbfilename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = '1' GROUP BY thumbfilename ORDER BY RAND() LIMIT 10", __FILE__, __LINE__);
   
$row = mysql_fetch_assoc($request);
while ($row = mysql_fetch_assoc($request))
echo' <center><td align="center" colspan="3"><a href="', $scripturl, '?action=gallery;sa=view;id=',
$row['ID_PICTURE'], '"><img src="', $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>';
echo'</td></tr>';
echo'</table></br>';
mysql_free_result($request);

I have it on my boardindex.template just below the set of tabs. The only thing I don't like about the code is my picturres repeat themselves. Really I don't know how they look in someone elses browser and I don't know any php at all. I just played around until something worked. Well I think it worked. I would like to have the pictures in a matching table but I lack the skills to make one. I hope someone will visit my site and tell me if it is ok in their browser. I didn't use any ssi. ssi to me is something disabled people get?.! No clue. ;)
http://www.craftervillage.com/board/
Title: Re: Random Image in Block?
Post by: craftervillage on March 21, 2007, 02:41:52 pm
I think that's the right file. Let me know if it's not. Thank you for doing that. I can't wait to start up my board. I really like the gallery. The old gals will like it too. Thanks again for the help.
craftervillage.com/board/


File attached with gallery menu

The code didn't work. I cannot see the button/link for the gallery. I really like it. I know it's installed because it works with the default template. Did I not do something right? I uploaded the file twice just to make sure it was the file you fixed. I even copied and pasted it to the index.template and it still did not work. I can link to it but I cannot find the link to it....http://craftervillage.com/board/index.php?action=gallery
Title: Re: Random Image in Block?
Post by: SMFHacks on March 21, 2007, 07:16:31 pm
Hmm reattached the file.
Title: Re: Random Image in Block?
Post by: ~Alex on March 21, 2007, 07:25:01 pm
I managed to get some code to work on my site for a random images.

   
global $scripturl,$db_prefix,$modSettings,$boardurl;

echo'<table cellspacing="0" cellpadding="1" border="0" align="center" width="90%"><tr>';
if(empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}
$request = db_query("SELECT thumbfilename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = '1' GROUP BY thumbfilename ORDER BY RAND() LIMIT 10", __FILE__, __LINE__);
   
$row = mysql_fetch_assoc($request);
while ($row = mysql_fetch_assoc($request))
echo' <center><td align="center" colspan="3"><a href="', $scripturl, '?action=gallery;sa=view;id=',
$row['ID_PICTURE'], '"><img src="', $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>';
echo'</td></tr>';
echo'</table></br>';
mysql_free_result($request);

I have it on my boardindex.template just below the set of tabs. The only thing I don't like about the code is my picturres repeat themselves. Really I don't know how they look in someone elses browser and I don't know any php at all. I just played around until something worked. Well I think it worked. I would like to have the pictures in a matching table but I lack the skills to make one. I hope someone will visit my site and tell me if it is ok in their browser. I didn't use any ssi. ssi to me is something disabled people get?.! No clue. ;)
http://www.craftervillage.com/board/

I like the way that code sets the images across the top, in a row, but how can I do this in a column? And does it work on TP .98 w/ SMF 1.1.2?
Title: Re: Random Image in Block?
Post by: craftervillage on March 21, 2007, 08:48:38 pm
Quote from: ~Alex

I like the way that code sets the images across the top, in a row, but how can I do this in a column? And does it work on TP .98 w/ SMF 1.1.2?

I don't even know what tp is. Maybe someone else can help you. As for a column....I don't have a clue. I am new to all this and am just learning as I go. I am still tring to figure out why my gallery buttons don't work. The template file I downloaded didn't work. If it was in html I could write the code myslef. This php stuff is just too hard. I hope you find your answer for your forum and share your forum link. I would like to see it.
Title: Re: Random Image in Block?
Post by: ~Alex on March 24, 2007, 06:04:27 pm
that's ok. :D

hey, i found what i needed and i'd like to share it, but i'm not sure if i'm allowed to post links to other forums that offer support for SMF and TP...but um...it's from TP. (http://www.tinyportal.net/index.php?topic=4873.0)

Hi

Nothing much to it...

1. Create a directory on your server anywhere you want

2. Download this file (rightclick and save as) (http://path-to-peace.net/misc/rotate.zip)

3. Unzip and Upload the file you downloaded to your directory

4. Upload the images to the same directory - dosent matter what their names or format or size or dimensions are...as long as its a png, gif or jpg file

5. add this code to a SCRIPT / HTML block

Code: [Select]

<img src="http://www.mysite.com/myfolder/rotate.php" alt="A Random Image" />


Be sure to change www.mysite.com/myfolder to your website addy and folder path!

Each time your page loads it will display a random image from your folder :)
And thats all - enjoy :)

Details of how this thing works and its homepage can be found HERE (http://automaticlabs.com/products/rotator)

it works just as i needed. :D
Title: Re: Random Image in Block?
Post by: CRONUS on May 24, 2007, 03:40:03 am
ok.. i had to code myself (i'm not good realy on that) cause i didn't find exactly what i needed so looked at all your codes and thats the result :)

Code: [Select]
function ssi_gallerylast($limit, $appr, $orient)
{
  global $scripturl,$db_prefix,$modSettings,$boardurl;
  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }

  $request = db_query("SELECT thumbfilename,ID_PICTURE,approved
                                FROM {$db_prefix}gallery_pic WHERE approved = {$appr}
                                ORDER BY ID_PICTURE DESC LIMIT {$limit}", __FILE__, __LINE__);

  $result = db_query("SELECT COUNT(*)
FROM {$db_prefix}gallery_pic
    WHERE approved = {$appr}
    LIMIT {$limit}", __FILE__, __LINE__);
  list ($len) = mysql_fetch_row($result);
mysql_free_result($result);

  if ( $len > 0 ) {
  echo '<table>';
  if ($orient == 0) {
    if ($appr == 0) {
      echo '<tr><td style="font-size: 8px; text-align: center; letter-spacing: 3px;" colspan="'. $limit .'">UNAPPROVED</td></tr>';
    }
    echo '<tr>';
  }
  elseif ($orient == 1 && $appr == 0) {
    echo '<tr><td style="font-size: 8px; text-align: center; letter-spacing: 3px;">UNAPPROVED</td></tr>';
  }
  while ($row = mysql_fetch_assoc($request))
  {
    if ($orient == 1) echo '<tr>';
    echo '<td style="text-align: center; width: '. 100/$len .'%;"><a href="'. $scripturl .'?action=gallery;sa=view;id='. $row['ID_PICTURE'] .'"><img src="'.  $modSettings['gallery_url'] . $row['thumbfilename'] .'" /></a></td>';
    if ($orient == 1) echo '</tr>';
  }
  if ($orient == 0) echo '</tr>';
  echo '</table>';
  }

  mysql_free_result($request);
}

then put
Code: [Select]
ssi_gallerylast(5,1,1);where you want pictures to be shown.

the numbers are: limit, not/approved, orientation

limit explains itself
not/approved - if you want to show approved images put 1, if unapproved - 0
orientation - if you want to show images in a row, then put 0, if in a column - 1

it shows last approved or not images.
If you want random then replace
Code: [Select]
  $request = db_query("SELECT thumbfilename,ID_PICTURE,approved
                                FROM {$db_prefix}gallery_pic WHERE approved = {$appr}
                                ORDER BY ID_PICTURE DESC LIMIT {$limit}", __FILE__, __LINE__);
to
Code: [Select]
  $request = db_query("SELECT thumbfilename,ID_PICTURE,approved
                                FROM {$db_prefix}gallery_pic WHERE approved = {$appr}
                                ORDER BY RAND() LIMIT {$limit}", __FILE__, __LINE__);

example:

ssi_gallerylast(3,0,0) would return:
Code: [Select]
<table><tr>
<td colspan="3">UNAPPROVED</td>
</tr><tr>
<td>unapproved image</td>
<td>unapproved image</td>
<td>unapproved image</td>
</tr></table>

or ssi_gallerylast(3,1,1) would return:
Code: [Select]
<table>
<tr><td>approved image</td></tr>
<tr><td>approved image</td></tr>
<tr><td>approved image</td></tr>
</table>

Hope someone will get use of it ;)
Title: Re: Random Image in Block?
Post by: stormlrd on May 24, 2007, 01:34:49 pm
Nice job
Title: Re: Random Image in Block?
Post by: CRONUS on May 25, 2007, 04:53:32 am
updated SSI code so that if no pictures it doesn't show anything and now table cells have same width ;)
Title: Re: Random Image in Block?
Post by: RWL on May 25, 2007, 06:21:05 am
Use this snippet from Thurnock over at TP - works great for me!

Code: [Select]
////////////////////////////////////////////////////
// SMF Gallery Random Picture - ver. 1.7.1        //
////////////////////////////////////////////////////
//
// Developed by Thurnok
// Thurnok -AT- tinyportal .DOT. net
// November 30, 2006
//
// Updated 5/9/2007
// 1.7.1
// - quick fix to parsing the url
//
// Updated 5/9/2007
// 1.7
// - added option to view pics that members on your buddy list posted
//
// For list of all previous updates history, see the UPDATES.TXT attached file
// in the post where you got this code, or the .ZIP file if you downloaded it
//
// Used in a TinyPortal phpblock or Article.
// This block displays random picture(s) from
// the SMF Gallery mod along with other information
//
//////////////////////////////////////////////

global $scripturl, $db_prefix, $modSettings, $boardurl, $ID_MEMBER, $user_info, $context;

/*
****************************************
****************************************
***    !! Admin Config Section !!    ***
****************************************
****************************************
*/

//   *****   LAYOUT OPTIONS   *****
// how many pictures do you want to show?  0 = all!
$gal_numpics = 1;

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype = 0;
// sort :: 0 = Descending, 1 = Ascending
$gal_sort = 0;

// enable profile pics display?
// 0 = disable, 1 = enable --- if enabled, and you are viewing a member profile, show pics from that member only
// other options still apply (showtype, sort order, etc)
$gal_profile = 1;

// only show pics from buddies?
// 0 = disable, 1 = enable --- if enabled, will only show pics posted by members in your buddy list
$gal_buddies = 0;

// use Normal Size Text, or Small Size Text? (0 = Normal Size, 1 = Small Size)
$gal_smalltext = 1;

// put pictures in how many columns?  (1 for left/right block, more for centerblock / article if you wish)
$gal_columns = 1;

// information display flags (0 = No, 1 = Yes)
// display picture title?
$gal_dispTitle = 1;
// display membername who posted pic?
$gal_dispMember = 1;
// display posted date?
$gal_dispDate = 1;
// display category the picture is in?
$gal_dispCategory = 1;
// display number of views?
$gal_dispViews = 1;
// display dimensions?
$gal_dispDimensions = 1;
// display filesize?
$gal_dispSize = 1;
// display picture description?
$gal_dispDescription = 0;


//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = "4,2,7" - don't show categories 2, 4, or 7
$gal_disallowCats = "";
// select only from the following cats - leave empty for all - NOTE:($gal_disallowCats overrides)
// example: $gal_allowCats = "1,3,4" - show only categories 1, 3, and 4
$gal_allowCats = "";
// Require the user has allowedTo('smfgallery_view') permission to view random pics thumbnails in block?
$gal_viewPermission = 1;

/*
****************************************
****************************************
***  !! END Admin Config Section !!  ***
****************************************
****************************************
*/

//###############################################
//###############################################
//   You shouldn't change anything below here
//###############################################
//###############################################

if (empty($modSettings['gallery_url'])){
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}

$gal_textclass = empty($gal_smalltext) ? "normaltext" : "smalltext";

// get this user's buddy list
$gal_buddylist = implode(",", $user_info['buddies']);

// prep for our switch routine
if (empty($gal_showtype))
$gal_showtype = 0;

// sort text
if (empty($gal_sort)){
$gal_sort_text = 'DESC';
} else {
$gal_sort_text = '';
}

// are we viewing a member profile and $gal_profile is enabled?
if (!empty($gal_profile) && strtolower($context['current_action']) == "profile"){
$gal_member = empty($_GET['u']) ? $ID_MEMBER : $_GET['u'];
}
// allow member to view random pic based on security settings
if (empty($gal_viewPermission) || allowedTo('smfgallery_view')){
$gal_query = '
SELECT
thumbfilename,
ID_PICTURE,
ID_MEMBER,
date,
title,
description,
views,
filesize,
height,
width,
commenttotal,
ID_CAT
FROM '.$db_prefix.'gallery_pic
WHERE approved = 1
'.(empty($gal_member) ? (empty($gal_buddies) ? "" : (empty($gal_buddylist) ? "AND ID_MEMBER = NULL " : "AND ID_MEMBER in ($gal_buddylist)")) : "AND ID_MEMBER = $gal_member" ).'
'.(empty($gal_disallowCats) ? "" : " AND ID_CAT NOT IN ($gal_disallowCats)").'
'.(empty($gal_allowCats) ? "" : " AND ID_CAT IN ($gal_allowCats)").'
GROUP BY thumbfilename ';

switch ($gal_showtype){
// most/least recent
case 1:
$gal_query .= '
ORDER BY date '.$gal_sort_text;
break;

// most/least viewed
case 2:
$gal_query .= '
ORDER BY views '.$gal_sort_text;
break;

// most/least commented
case 3:
$gal_query .= '
ORDER BY commenttotal '.$gal_sort_text;
break;

default:
$gal_query .= '
ORDER BY rand() '.$gal_sort_text;
break;
}
$gal_query .= (empty($_GET['gal_viewall']) && !empty($gal_numpics)) ? ' LIMIT '.$gal_numpics : '';
$gal_result = mysql_query($gal_query);
if (!$gal_result){
// error retrieving information from database
if (mysql_errno() == 1146){
echo '<p />Error, no database found!<p />';
} else {
echo '<p />MySQL error:'.mysql_error().'<p />';
}
} else {
echo "\n".'<table cellspacing="0" cellpadding="5" border="0" align="center" width="90%">'."\n";

$gal_colcnt = 1;
echo " <tr>\n";
while ($row = mysql_fetch_assoc($gal_result)){
if ($gal_colcnt > $gal_columns){
// close out the row and start a new row
echo " </tr>\n <tr>\n".' <td colspan="'.$gal_columns.'"><hr /></td>'."\n </tr>\n <tr>\n";
// reset count to column 1
$gal_colcnt = 1;
}
echo ' <td class="'.$gal_textclass.'" align="center">'."\n";
// display title if enabled, make edit link if viewing user is picture poster
if (!empty($gal_dispTitle)){
echo " ".($ID_MEMBER == $row['ID_MEMBER'] ? ('<a href="'.$scripturl.'?action=gallery;sa=edit;id='.$row['ID_PICTURE'].'">'.$row['title'].'</a>') : $row['title'])."<br />\n";
}
// display the picture thumbnail and link it to gallery full picture
echo ' <a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'"><img src="'.$modSettings['gallery_url'].$row['thumbfilename'].'" /></a><br />'."\n";
// display poster's name and posted date if enabled
if (!empty($gal_dispMember) || !empty($gal_dispDate)){
echo 'Posted';
if (!empty($gal_dispMember)){
// display the membername who posted pic?  need to get name based on ID_MEMBER
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT memberName FROM ".$db_prefix."members WHERE ID_MEMBER = ".$row['ID_MEMBER']));
echo ' by <a href="'.$scripturl.'?action=profile;u='.$row['ID_MEMBER'].'">'.$gal_tmp['memberName'].'</a>';
}
if (!empty($gal_dispDate)){
// display the date it was posted
echo ' on '.date("d M Y", $row['date']);
}
echo "<br />\n";
}
// display category if enabled
if (!empty($gal_dispCategory)){
// get category name based on category id
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE ID_CAT = ".$row['ID_CAT']));
echo '<br />in<br /><a href="'.$scripturl.'?action=gallery;cat='.$row['ID_CAT'].'">'.$gal_tmp['title']."</a><br /><br />\n";
}
// display number of views if enabled
if (!empty($gal_dispViews)){
echo "Viewed ".$row['views']." times<br />\n";
}
// display dimensions if enabled
if (!empty($gal_dispDimensions)){
echo $row['width']."w X ".$row['height']."h<br />\n";
}
// display filesize if enabled
if (!empty($gal_dispSize)){
echo $row['filesize']." bytes<br />\n";
}
// display description if enabled
if (!empty($gal_dispDescription)){
echo "<br />".$row['description']."<br />\n";
}
echo " </td>\n";
$gal_colcnt++;
}
mysql_free_result($gal_result);
echo " </tr>\n</table>\n";
if (!empty($gal_member) && empty($_GET['gal_viewall']))
echo '<br /><a href="'.$boardurl.'/index.php?action=profile;u='.$gal_member.';gal_viewall=1">View all pics from this member</a>';
if (!empty($gal_buddies) && empty($_GET['gal_viewall'])){
// build the link
$gal_querystring = $context['TPortal']['querystring'];
$gal_querystring .= empty($gal_querystring) ? 'gal_viewall=1' : ';gal_viewall=1';
echo '<br /><a href="'.$boardurl.'/index.php?'.$gal_querystring.'">View all pics of buddies</a>';
}
}
} else {
echo 'Sorry, you do not have permission to view pictures!';
}
Title: Re: Random Image in Block?
Post by: craftervillage on June 29, 2007, 11:00:13 am
Does anyone know what I can add here to make the members name appear below thier picture.

I managed to get some code to work on my site for a random images.

   
global $scripturl,$db_prefix,$modSettings,$boardurl;

echo'<table cellspacing="0" cellpadding="1" border="0" align="center" width="90%"><tr>';
if(empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}
$request = db_query("SELECT thumbfilename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = '1' GROUP BY thumbfilename ORDER BY RAND() LIMIT 10", __FILE__, __LINE__);
   
$row = mysql_fetch_assoc($request);
while ($row = mysql_fetch_assoc($request))
echo' <center><td align="center" colspan="3"><a href="', $scripturl, '?action=gallery;sa=view;id=',
$row['ID_PICTURE'], '"><img src="', $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>';
echo'</td></tr>';
echo'</table></br>';
mysql_free_result($request);

Title: Re: Random Image in Block?
Post by: SMFHacks on June 29, 2007, 08:45:56 pm
Code: [Select]
You would need to do another join

Find
[code]
db_query("SELECT thumbfilename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = '1' GROUP BY thumbfilename ORDER BY RAND() LIMIT 10", __FILE__, __LINE__);
Change to
db_query("SELECT m.ID_MEMBER, m.realName, p.thumbfilename, p.ID_CAT, p.ID_PICTURE FROM {$db_prefix}gallery_pic as p, {$db_prefix}_members as m  WHERE p.ID_MEMBER = m.ID_MEMBER AND p.ID_CAT = '1' GROUP BY thumbfilename ORDER BY RAND() LIMIT 10", __FILE__, __LINE__);
[/code]

so you can then use the realName returned by the query in the display part
Title: Re: Random Image in Block?
Post by: deezin on October 12, 2007, 07:21:36 pm
Any idea how to implement the same thing in drupal ... i.e. creating a recent SMF Gallery Pro images block for Drupal.

Thank you for your help.
Rachel
Title: Re: Random Image in Block?
Post by: Raji on November 23, 2007, 04:33:43 am
oh that code won't work since SSI requires that it be loaded before all php


You would need to replace ssi_galleryrandom(); in your index.template.ph with something like
Code: [Select]
global $scripturl,$db_prefix,$modSettings,$boardurl;

  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
 
  $request = db_query("SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
  $row = mysql_fetch_assoc($request);
  mysql_free_result($request);
  echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;
?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=250,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#FFFFFF"><center><font color="#000000" size="1" face="verdana">');
  tmp.write('HTML For Websites:</br><form><textarea rows="2" cols="90">&lt;a href="<?echo $modSettings['gallery_url'].$row['filename']; ?>"&gt;&lt;img src="<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>"&gt;&lt;/a&gt;</textarea></form> ');
  tmp.write('</br></br>BBC For Forums</br><form><textarea rows="2" cols="90">[url=<?echo $modSettings['gallery_url'].$row['filename']; ?>][img]<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>[/img][/url]</textarea></form>');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
<?


I have added this mod before
function template_main_below()

but its showing fetal errror :( I need your help to fix this problem.

Thanks in advance for your support.

Regards
Raji

Title: Re: Random Image in Block?
Post by: SMFHacks on November 23, 2007, 03:34:01 pm
That code won't work in that case since its a mix of php/html code and was meant for a block not to be stuck inside a template.
Title: Re: Random Image in Block?
Post by: Kesk on November 27, 2007, 07:51:31 am
I am wanting to add a random image to my welcome menu in the header. I am using the default theme. I would like to place it next to the small ad that you can see here:

http://www.deathknight.info

I have tried both the SSI codes and the other codes thatSMFHACKS posted. I cant seem to get the code placed right and still work (it will only work in certain places of the index.template   file. anyone have a clue?
Title: Re: Random Image in Block?
Post by: smartmouse on December 19, 2007, 07:53:14 pm
Nice work,

I updated it a little
Code: [Select]
function ssi_grandom ($cat)
{
global $scripturl,$db_prefix;
$cat = (int) $cat;

$request = db_query("SELECT thumbfilename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = $cat GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__, __LINE__);
$row = mysql_fetch_assoc($request);
mysql_free_result($request);
echo' <a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="/gallery/', $row['thumbfilename'] ,'" />'

;}


Hello i'm new here. How to set more than 1 cat?
Is it possible?

Thank you.
Title: Re: Random Image in Block?
Post by: SMFHacks on December 19, 2007, 09:29:09 pm
Change
WHERE ID_CAT = $cat
To
WHERE ID_CAT = $cat OR ID_CAT = anothercategorynumber
Title: Re: Random Image in Block?
Post by: smartmouse on December 20, 2007, 05:52:26 pm
Change
WHERE ID_CAT = $cat
To
WHERE ID_CAT = $cat OR ID_CAT = anothercategorynumber


I have a lot of categories! How to set that the it has to get any category number?
Title: Re: Random Image in Block?
Post by: SMFHacks on December 21, 2007, 11:30:25 pm
If you want all the categories just remove the
WHERE ID_CAT = $cat
Title: Re: Random Image in Block?
Post by: smartmouse on December 22, 2007, 07:42:24 pm
If you want all the categories just remove the
WHERE ID_CAT = $cat

It worked! Thank you so much!
Title: Re: Random Image in Block?
Post by: tatore on January 22, 2008, 06:52:17 am
That's a way to show the thumbs in a superbe look, I always loved the Protocultura's website, really.


oh that code won't work since SSI requires that it be loaded before all php


You would need to replace ssi_galleryrandom(); in your index.template.ph with something like
Code: [Select]
global $scripturl,$db_prefix,$modSettings,$boardurl;

  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
 
  $request = db_query("SELECT thumbfilename,ID_PICTURE,filename FROM

{$db_prefix}gallery_pic GROUP BY thumbfilename ORDER BY RAND() LIMIT 1", __FILE__,

__LINE__);
  $row = mysql_fetch_assoc($request);
  mysql_free_result($request);
  echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=',

$row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a></center>'

;
?><script language="javascript" type="text/javascript">
<!--
function linkingcodes() {
  newwindow2=window.open('','name','height=250,width=800,scrollbars=yes');
  var tmp = newwindow2.document;
  tmp.write('<html><head><title>Linking codes</title>');
  tmp.write('');
  tmp.write('</head><body bgcolor="#FFFFFF"><center><font color="#000000" size="1" face="verdana">');
  tmp.write('HTML For Websites:</br><form><textarea rows="2" cols="90">&lt;a href="<?echo $modSettings['gallery_url'].$row['filename']; ?>"&gt;&lt;img src="<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>"&gt;&lt;/a&gt;</textarea></form> ');
  tmp.write('</br></br>BBC For Forums</br><form><textarea rows="2" cols="90">[url=<?echo $modSettings['gallery_url'].$row['filename']; ?>][img]<?echo $modSettings['gallery_url'].$row['thumbfilename'];?>[/img][/url]</textarea></form>');
  tmp.write('</font></center></body></html>');
  tmp.close();
}
// -->
</script><center><form>
</br><input type="button" onClick="return linkingcodes()" value="Linking codes!">
</form></center>
<?

Unfortunately I didn't find any way to put the code into index.template and then see itwork properly.
SmfHack, when you have a chance..
I'm using DilberMc.
I'd coded the boardindex.template file to show the pics into the infocenter side, but for the tons of queries generated I've gave up.
However, in a test site I'd like to see the effect they have if I will be able to show them under the main user bar.
Title: Re: Random Image in Block?
Post by: smartmouse on March 13, 2008, 04:34:03 pm
Where to paste this code?
Can i see a demo?
Title: Re: Random Image in Block?
Post by: dark4sorrow on March 17, 2008, 03:51:38 pm
I just used this code with SMF 1.1.4 and TinyPortal v0.9.8 and it worked perfectly.
Just thought I'd add in my 2 cents here. :)

-sorrow


Use this snippet from Thurnock over at TP - works great for me!

Code: [Select]
////////////////////////////////////////////////////
// SMF Gallery Random Picture - ver. 1.7.1        //
////////////////////////////////////////////////////
//
// Developed by Thurnok
// Thurnok -AT- tinyportal .DOT. net
// November 30, 2006
//
// Updated 5/9/2007
// 1.7.1
// - quick fix to parsing the url
//
// Updated 5/9/2007
// 1.7
// - added option to view pics that members on your buddy list posted
//
// For list of all previous updates history, see the UPDATES.TXT attached file
// in the post where you got this code, or the .ZIP file if you downloaded it
//
// Used in a TinyPortal phpblock or Article.
// This block displays random picture(s) from
// the SMF Gallery mod along with other information
//
//////////////////////////////////////////////

global $scripturl, $db_prefix, $modSettings, $boardurl, $ID_MEMBER, $user_info, $context;

/*
****************************************
****************************************
***    !! Admin Config Section !!    ***
****************************************
****************************************
*/

//   *****   LAYOUT OPTIONS   *****
// how many pictures do you want to show?  0 = all!
$gal_numpics = 1;

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype = 0;
// sort :: 0 = Descending, 1 = Ascending
$gal_sort = 0;

// enable profile pics display?
// 0 = disable, 1 = enable --- if enabled, and you are viewing a member profile, show pics from that member only
// other options still apply (showtype, sort order, etc)
$gal_profile = 1;

// only show pics from buddies?
// 0 = disable, 1 = enable --- if enabled, will only show pics posted by members in your buddy list
$gal_buddies = 0;

// use Normal Size Text, or Small Size Text? (0 = Normal Size, 1 = Small Size)
$gal_smalltext = 1;

// put pictures in how many columns?  (1 for left/right block, more for centerblock / article if you wish)
$gal_columns = 1;

// information display flags (0 = No, 1 = Yes)
// display picture title?
$gal_dispTitle = 1;
// display membername who posted pic?
$gal_dispMember = 1;
// display posted date?
$gal_dispDate = 1;
// display category the picture is in?
$gal_dispCategory = 1;
// display number of views?
$gal_dispViews = 1;
// display dimensions?
$gal_dispDimensions = 1;
// display filesize?
$gal_dispSize = 1;
// display picture description?
$gal_dispDescription = 0;


//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = "4,2,7" - don't show categories 2, 4, or 7
$gal_disallowCats = "";
// select only from the following cats - leave empty for all - NOTE:($gal_disallowCats overrides)
// example: $gal_allowCats = "1,3,4" - show only categories 1, 3, and 4
$gal_allowCats = "";
// Require the user has allowedTo('smfgallery_view') permission to view random pics thumbnails in block?
$gal_viewPermission = 1;

/*
****************************************
****************************************
***  !! END Admin Config Section !!  ***
****************************************
****************************************
*/

//###############################################
//###############################################
//   You shouldn't change anything below here
//###############################################
//###############################################

if (empty($modSettings['gallery_url'])){
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}

$gal_textclass = empty($gal_smalltext) ? "normaltext" : "smalltext";

// get this user's buddy list
$gal_buddylist = implode(",", $user_info['buddies']);

// prep for our switch routine
if (empty($gal_showtype))
$gal_showtype = 0;

// sort text
if (empty($gal_sort)){
$gal_sort_text = 'DESC';
} else {
$gal_sort_text = '';
}

// are we viewing a member profile and $gal_profile is enabled?
if (!empty($gal_profile) && strtolower($context['current_action']) == "profile"){
$gal_member = empty($_GET['u']) ? $ID_MEMBER : $_GET['u'];
}
// allow member to view random pic based on security settings
if (empty($gal_viewPermission) || allowedTo('smfgallery_view')){
$gal_query = '
SELECT
thumbfilename,
ID_PICTURE,
ID_MEMBER,
date,
title,
description,
views,
filesize,
height,
width,
commenttotal,
ID_CAT
FROM '.$db_prefix.'gallery_pic
WHERE approved = 1
'.(empty($gal_member) ? (empty($gal_buddies) ? "" : (empty($gal_buddylist) ? "AND ID_MEMBER = NULL " : "AND ID_MEMBER in ($gal_buddylist)")) : "AND ID_MEMBER = $gal_member" ).'
'.(empty($gal_disallowCats) ? "" : " AND ID_CAT NOT IN ($gal_disallowCats)").'
'.(empty($gal_allowCats) ? "" : " AND ID_CAT IN ($gal_allowCats)").'
GROUP BY thumbfilename ';

switch ($gal_showtype){
// most/least recent
case 1:
$gal_query .= '
ORDER BY date '.$gal_sort_text;
break;

// most/least viewed
case 2:
$gal_query .= '
ORDER BY views '.$gal_sort_text;
break;

// most/least commented
case 3:
$gal_query .= '
ORDER BY commenttotal '.$gal_sort_text;
break;

default:
$gal_query .= '
ORDER BY rand() '.$gal_sort_text;
break;
}
$gal_query .= (empty($_GET['gal_viewall']) && !empty($gal_numpics)) ? ' LIMIT '.$gal_numpics : '';
$gal_result = mysql_query($gal_query);
if (!$gal_result){
// error retrieving information from database
if (mysql_errno() == 1146){
echo '<p />Error, no database found!<p />';
} else {
echo '<p />MySQL error:'.mysql_error().'<p />';
}
} else {
echo "\n".'<table cellspacing="0" cellpadding="5" border="0" align="center" width="90%">'."\n";

$gal_colcnt = 1;
echo " <tr>\n";
while ($row = mysql_fetch_assoc($gal_result)){
if ($gal_colcnt > $gal_columns){
// close out the row and start a new row
echo " </tr>\n <tr>\n".' <td colspan="'.$gal_columns.'"><hr /></td>'."\n </tr>\n <tr>\n";
// reset count to column 1
$gal_colcnt = 1;
}
echo ' <td class="'.$gal_textclass.'" align="center">'."\n";
// display title if enabled, make edit link if viewing user is picture poster
if (!empty($gal_dispTitle)){
echo " ".($ID_MEMBER == $row['ID_MEMBER'] ? ('<a href="'.$scripturl.'?action=gallery;sa=edit;id='.$row['ID_PICTURE'].'">'.$row['title'].'</a>') : $row['title'])."<br />\n";
}
// display the picture thumbnail and link it to gallery full picture
echo ' <a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'"><img src="'.$modSettings['gallery_url'].$row['thumbfilename'].'" /></a><br />'."\n";
// display poster's name and posted date if enabled
if (!empty($gal_dispMember) || !empty($gal_dispDate)){
echo 'Posted';
if (!empty($gal_dispMember)){
// display the membername who posted pic?  need to get name based on ID_MEMBER
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT memberName FROM ".$db_prefix."members WHERE ID_MEMBER = ".$row['ID_MEMBER']));
echo ' by <a href="'.$scripturl.'?action=profile;u='.$row['ID_MEMBER'].'">'.$gal_tmp['memberName'].'</a>';
}
if (!empty($gal_dispDate)){
// display the date it was posted
echo ' on '.date("d M Y", $row['date']);
}
echo "<br />\n";
}
// display category if enabled
if (!empty($gal_dispCategory)){
// get category name based on category id
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE ID_CAT = ".$row['ID_CAT']));
echo '<br />in<br /><a href="'.$scripturl.'?action=gallery;cat='.$row['ID_CAT'].'">'.$gal_tmp['title']."</a><br /><br />\n";
}
// display number of views if enabled
if (!empty($gal_dispViews)){
echo "Viewed ".$row['views']." times<br />\n";
}
// display dimensions if enabled
if (!empty($gal_dispDimensions)){
echo $row['width']."w X ".$row['height']."h<br />\n";
}
// display filesize if enabled
if (!empty($gal_dispSize)){
echo $row['filesize']." bytes<br />\n";
}
// display description if enabled
if (!empty($gal_dispDescription)){
echo "<br />".$row['description']."<br />\n";
}
echo " </td>\n";
$gal_colcnt++;
}
mysql_free_result($gal_result);
echo " </tr>\n</table>\n";
if (!empty($gal_member) && empty($_GET['gal_viewall']))
echo '<br /><a href="'.$boardurl.'/index.php?action=profile;u='.$gal_member.';gal_viewall=1">View all pics from this member</a>';
if (!empty($gal_buddies) && empty($_GET['gal_viewall'])){
// build the link
$gal_querystring = $context['TPortal']['querystring'];
$gal_querystring .= empty($gal_querystring) ? 'gal_viewall=1' : ';gal_viewall=1';
echo '<br /><a href="'.$boardurl.'/index.php?'.$gal_querystring.'">View all pics of buddies</a>';
}
}
} else {
echo 'Sorry, you do not have permission to view pictures!';
}
Title: Re: Random Image in Block?
Post by: Raji on March 08, 2009, 11:16:22 am
Plz advice how can i display 5  random images in horizontal order instead of vertical order?
I am using following code in php block of AD management and its working okay.

global $scripturl,$db_prefix,$modSettings,$boardurl;
  if(empty($modSettings['gallery_url']))
  {
    $modSettings['gallery_url'] = $boardurl . '/gallery/';
  }
   
  $request = db_query("SELECT thumbfilename,ID_PICTURE
                                FROM {$db_prefix}gallery_pic
                                ORDER BY RAND() LIMIT 5", __FILE__, __LINE__);

  while ($row = mysql_fetch_assoc($request))
  {
    echo' <center><a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '"><img src="',  $modSettings['gallery_url'] . $row['thumbfilename'] ,'" /></a></center>';
  }
  mysql_free_result($request);
Title: Re: Random Image in Block?
Post by: Raji on March 08, 2009, 11:52:44 am
This code worked for me :)

Quote
global $scripturl,$db_prefix,$modSettings,$boardurl;

echo'<table cellspacing="0" cellpadding="0" border="0"  width="90%"><tr>';
if(empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}
$request = db_query("SELECT thumbfilename, ID_CAT, ID_PICTURE FROM {$db_prefix}gallery_pic WHERE ID_CAT = '1' GROUP BY thumbfilename ORDER BY RAND() LIMIT 7", __FILE__, __LINE__);
   
$row = mysql_fetch_assoc($request);
while ($row = mysql_fetch_assoc($request))
echo' <td align="center" colspan="3"><a href="', $scripturl, '?action=gallery;sa=view;id=',
$row['ID_PICTURE'], '"><img src="', $modSettings['gallery_url'] .

$row['thumbfilename'] ,'" /></a>';
echo'</td></tr>';
echo'</table></br>';
mysql_free_result($request);

www.baask.com/diwwan