TinyPortal

Development => Block Codes => Topic started by: deniz on October 27, 2006, 02:41:30 PM

Title: Random Image for SMF Gallery Mod
Post by: deniz on October 27, 2006, 02:41:30 PM
add fallowing code before "?>" in ssi.php

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

;}


and add a php block:

ssi_galleryrandom();
echo '<center>
<br>
<a href="http://www.yoursite.com/forum/index.php?action=gallery">Show Gallery</a>
<br>
<a href="http://www.yoursite.com/forum/index.php?action=gallery;sa=add;cat=1">Add Picture</a>
</center>';



change "yoursite.com/forum" depends on your site..

demo : http://www.sifirforum.com/forum/index.php  (right panel)

quote from: http://www.smfhacks.com/index.php/topic,125.60.html
Title: Re: Random Image for SMF Gallery Mod
Post by: akulion on October 27, 2006, 03:19:22 PM
Thanks :D

I'll try it out :up:
Title: Re: Random Image for SMF Gallery Mod
Post by: jacortina on October 27, 2006, 03:21:44 PM
Quote from: deniz on October 27, 2006, 02:41:30 PM
ssi_galleryrandom();
echo '<center>
<br>
<a href="http://www.yoursite.com/forum/index.php?action=gallery">Show Gallery</a>
<br>
<a href="http://www.yoursite.com/forum/index.php?action=gallery;sa=add;cat=1">Add Picture</a>
</center>';



change "yoursite.com/forum" depends on your site..

global $scripturl;
ssi_galleryrandom();
echo '<center>
<br>
<a href="',$scripturl,'?action=gallery">Show Gallery</a>
<br>
<a href="',$scripturl,'?action=gallery;sa=add;cat=1">Add Picture</a>
</center>';


Or let the php do it for you.  ;)

Note that if this is the only place you're going to display a random image, you can skip modifying the SSI.php and just replace the ssi_galleryrandom() call in the block with the code from the function itself (no FTP'ing, no problems with redo-ing the change at the next upgrade).
Title: Re: Random Image for SMF Gallery Mod
Post by: akulion on October 27, 2006, 03:23:28 PM
Thanks :D

I'll try it out :up:
Title: Re: Random Image for SMF Gallery Mod
Post by: akulion on October 27, 2006, 04:16:15 PM
hey could one of u guys add a "condition check" for the links for gallery and add a pic links?

So that they only appear to members instead of everyone?

that would make the code complete in my view :D
Title: Re: Random Image for SMF Gallery Mod
Post by: jacortina on October 27, 2006, 04:37:43 PM
global $scripturl, $user_info;
ssi_galleryrandom();
if (!$user_info['is_guest']) {
echo '<center>
<br>
<a href="',$scripturl,'?action=gallery">Show Gallery</a>
<br>
<a href="',$scripturl,'?action=gallery;sa=add;cat=1">Add Picture</a>
</center>';
}


Don't know what you mean by "add a pic links". As I read the code, the thumbnail is a link to the full picture Gallery display.
Title: Re: Random Image for SMF Gallery Mod
Post by: akulion on October 27, 2006, 04:49:00 PM
oh no i meant that :

if (!$user_info['is_guest']) {
echo '<center>Please register so you can add your pics to the gallery';
}
else
{
echo '<center>
<br>
<a href="',$scripturl,'?action=gallery">Show Gallery</a>
<br>
<a href="',$scripturl,'?action=gallery;sa=add;cat=1">Add Picture</a>
</center>';
}


is that correct?
Title: Re: Random Image for SMF Gallery Mod
Post by: jacortina on October 27, 2006, 05:00:24 PM
Nope. But it's exactly 100% opposite of what you want. ;)

Change:
if (!$user_info['is_guest'])

To:
if ($user_info['is_guest'])
Title: Re: Random Image for SMF Gallery Mod
Post by: akulion on October 27, 2006, 05:03:02 PM
aaaahhh i see my non-eagle-programmer eyes failed to catch the !

lol thanks :D
Title: Re: Random Image for SMF Gallery Mod
Post by: kran1um on October 28, 2006, 03:37:18 PM
Great! I will try, so whats the final code with no errors?
Title: Re: Random Image for SMF Gallery Mod
Post by: jacortina on October 28, 2006, 06:04:53 PM
Quote from: kran1um on October 28, 2006, 03:37:18 PM
Great! I will try, so whats the final code with no errors?

That depends (sorry, but it's true).

Do you want to put the random image function in your SSI (do you plan on multiple occurrences of calling it or calling it from you site, but outside the TP/Forum structure)?

Do you want to display the extra links to guests or not?

If modifying SSI, look at first post in this thread for what you have to do to accomplish that.

Then create a phpblock with this code:
global $scripturl, $user_info;

ssi_galleryrandom();

if ($user_info['is_guest']) {
echo 'Please register so you can add your pics to the gallery';
}
else
{
echo '<center>
<br>
<a href="',$scripturl,'?action=gallery">Show Gallery</a>
<br>
<a href="',$scripturl,'?action=gallery;sa=add;cat=1">Add Picture</a>
</center>';
}


If you don't want to modify SSI.php, replace the single line:
ssi_galleryrandom();
in the above with the actual contents of the function:

global $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>';
Title: Re: Random Image for SMF Gallery Mod
Post by: kran1um on October 28, 2006, 09:27:19 PM
Thanks! It worked!