TinyPortal

Development => Block Codes => Topic started by: Petee on December 14, 2008, 06:02:31 PM

Title: [Block] SMF Media Gallery Random Picture
Post by: Petee on December 14, 2008, 06:02:31 PM
Quote from: Smoothbrain on December 09, 2008, 07:22:42 PM
Hi all, I have a site that I run SMF Gallery Lite and I love this block snippet and I have another site where I am trying out SMF Media Gallery as it has a few more features I like and I was wondering if anyone has or knows how to modify this block code so that it will work for SMG.  Thanks heaps in advance.  You guys rule!

I tweaked the code I found on the SMF forums for a different portal block and came up with the code below to work with my site using SMF Media Gallery.

PHPBOX:


global $sourcedir, $user_info, $ID_MEMBER, $context, $txt, $galurl, $galurl2, $scripturl, $settings, $db_prefix;

   require_once($sourcedir . '/Subs-MGallery.php');
   loadMGal_Settings();

   if(loadlanguage('MGallery') == false)
      loadLanguage('MGallery', 'english');

   $request = db_query("
      SELECT m.id_media, m.id_member, IFNULL(mem.realName, m.member_name) AS member_name,  m.id_thumb, m.title, m.description, m.views, m.rating, m.voters,
      a.id_album, a.name, IFNULL(lm.time, 0) <  m.log_last_access_time AS is_new, m.time_added, m.type
      FROM {$db_prefix}mgallery_media AS m
         INNER JOIN {$db_prefix}mgallery_albums AS a ON (a.id_album = m.album_id)
         LEFT JOIN {$db_prefix}members AS mem ON (mem.ID_MEMBER = m.id_member)
         LEFT JOIN {$db_prefix}mgallery_log_media AS lm ON (lm.id_member = $ID_MEMBER AND lm.id_media = m.id_media)
      WHERE $user_info[mgallery_query_see_album]
      AND m.approved = 1
      ORDER BY RAND()
      LIMIT 1", __FILE__, __LINE__);
   while ($row = mysql_fetch_assoc($request)) {
      $item = array(
         'id' => $row['id_media'],
         'id_album' => $row['id_album'],
         'album_name' => $row['name'],
         'item_title' => $row['title'],
         'member_name' => $row['member_name'],
         'member_id' => $row['id_member'],
         'rating' => $row['voters'] != 0 ? ($row['rating']/$row['voters']) : 0,
         'voters' => $row['voters'],
         'id_thumb' => $row['type'] == 'embed' ? 2 : $row['id_thumb'],
         'desc' => $row['description'],
         'time_added' => $row['time_added'],
         'is_new' => !empty($row['is_new']) && !$user_info['is_guest'],
         'views' => $row['views']
      );
   }
   mysql_free_result($request);

   echo '
<div class="smalltext" style="text-align: center; line-height: 1.4em; padding: 5px;">
   <a href="',$galurl,'sa=item;id=',$item['id'],'">',$item['item_title'],'</a><br /><br />
   <a href="',$galurl,'sa=item;id=',$item['id'],'"><img src="',$galurl,'sa=media;id=',$item['id'],';thumb" alt="" /></a><br /><br />
   ',$txt['mgallery_posted_by'],': <a href="',$scripturl,'?action=profile;u=',$item['member_id'],'">',$item['member_name'],'</a><br />
   ',$txt['mgallery_in_album'],': <a href="',$galurl,'sa=album;id=',$item['id_album'],'">',$item['album_name'],'</a>
   ',$item['is_new'] ? '<br />' : '','
</div>';





Below is another version that gives a similar output that I found at the smf-media site. 

2, 'rand()');  this part of the code says to pull 2 random pictures. Change it to suit your needs.

global $sourcedir, $context, $txt, $galurl, $scripturl, $settings;

require_once($sourcedir . '/Subs-MGallery.php');
loadMGal_Settings();

if (loadlanguage('MGallery') == false)
  loadLanguage('MGallery', 'english');

$items = getMediaItems(0, 2, 'rand()');

echo '
<center><table border="0">
  <tr>';

foreach ($items as $item)
  echo '
    <td>
      <div class="smalltext" style="text-align: center; line-height: 1.4em; border: 1px #000000 solid; padding: 5px;">
      <a href="',$galurl,'sa=item;id=',$item['id'],'">',$item['title'],'</a><br />
      <a href="',$galurl,'sa=item;id=',$item['id'],'"><img alt="" src="',$galurl,'sa=media;id=',$item['id'],';thumb" alt="" /></a><br />
      ',$txt['mgallery_views'],': ',$item['views'],'<br />
      ',$txt['mgallery_posted_by'],': <a href="',$scripturl,'?action=profile;u=',$item['poster_id'],'">',$item['poster_name'],'</a><br />
      ',$txt['mgallery_in_album'],': <a href="',$galurl,'sa=album;id=',$item['id_album'],'">',$item['album_name'],'</a>
      ',$item['is_new'] ? '<br /><img alt="" src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" border="0" />' : '','
      </div>
    </td>';
echo '
  </tr>
</table></center>';
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: fl4pj4ck on December 14, 2008, 07:23:59 PM
excellent block, but is there any chance the thumbnails would be bigger?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Petee on December 14, 2008, 11:12:09 PM
When a user uploads an image, a thumbnail is created based on the max width and/or max height you defined in the Admin Panel for SMG.   The default is 120, I believe. The block just pulls up that pre-existing thumbnail.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: HellBent on December 21, 2008, 03:14:36 PM
Fabulous!  I love it.  Thankyou  :up:
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Jakki on December 31, 2008, 01:31:54 PM
Perfect!!! worked great. thanks
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: wyckeddreamz on January 01, 2009, 11:12:14 PM
thank you for this, works a treat!!!
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: vulcan59 on January 05, 2009, 06:57:48 AM
Thanks for this excellent code. I put it in the front block and it worked!!    :up:

One question I have though is, are the images suppose to scroll?



Title: Re: [Block] SMF Media Gallery Random Picture
Post by: IchBin on January 05, 2009, 03:26:40 PM
No, the code does not have any scrolling option in it. If you want scrolling you need to add the marquee tag to it. Google is your friend if you want to know more about the marquee tag.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: vulcan59 on January 05, 2009, 07:44:50 PM
Thanks for the response IchBin.

Will look it up.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: IchBin on January 05, 2009, 08:08:02 PM
Sure, need any help with it feel free to post your code and we'll take a look.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: vulcan59 on January 05, 2009, 09:45:50 PM
Hi IchBin,

Perhaps Marquee tag was not the right choice of words. More like a slide show with a time delay.

I found the code here (http://www.php.net/manual/de/function.harupage-setslideshow.php) but how do I put it in the code above to make it work?

bool HaruPage::setSlideShow  ( int $type  , float $disp_time  , float $trans_time  )

Thanks.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: IchBin on January 06, 2009, 02:27:03 AM
There is a ton more code than that for a slideshow. I do believe that Dragoon was working on a slideshow code for it not to long ago. You should probably check with him on his site to see if he has anything he can share.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: vulcan59 on January 06, 2009, 02:39:10 AM
Thanks IchBin. Dragooon does have a Add on SlideShow but I have to pay for that addon. I might just purchase it.

Thanks once again.

Regards.

Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Lorazz on January 22, 2009, 11:00:07 AM
thank you very much for this. this is exactly what i've been looking for, awesome work :)
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: MinasC on January 25, 2009, 03:41:39 PM
great block, congrats.
could some stuff be added so that it doesn't look so poor? i mean it could also show the date and time of the item's posting, the number of views and comments, dimensions and description etc.there could be a choice of whether all these things will appear or not. wouldn't that be a good idea?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: G6Cad on January 25, 2009, 03:49:52 PM
Offcourse :)  Just go ahead and add in what you think would be great for this snippet to suit your needs  ;)
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: MinasC on January 25, 2009, 07:55:58 PM
lol i wish i could. that was just a thought, didn't mean anything bad or offensive (if that's what it came out like).
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Dark-Wolf on March 03, 2009, 01:15:36 AM
Thank is perfect!  :)
Only a small error with a double alt attribute:
From:
<img alt="" src="',$galurl,'sa=media;id=',$item['id'],';thumb" alt="" />
To:
<img src="',$galurl,'sa=media;id=',$item['id'],';thumb" alt="" /> ;)
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 05, 2009, 05:19:35 PM
What can I do with this message?

I put the code on a PHP block and selected the upper block for it and this is what I got.


Fatal error: require_once() [function.require]: Failed opening required '/home7/armyride/public_html/mmp/Sources/Subs-MGallery.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home7/armyride/public_html/mmp/Sources/Load.php(1745) : eval()'d code(48) : eval()'d code on line 3
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: IchBin on March 05, 2009, 10:41:54 PM
Do you have the media gallery installed?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 03:27:08 AM
Yes, I have media gallery lite installed
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: IchBin on March 06, 2009, 04:21:03 AM
Does the file that is in your error, exist in your Sources Directory?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 06:38:53 AM
public_html/mmp/Sources/Subs-MGallery.php'

I am missing that file no it is not in the directory.

The load.php is in there but the Subs-Mgallery.php isn't.

What should I check for?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: G6Cad on March 06, 2009, 08:25:29 AM
Have you installed the package ?  That file is included in the package. it's not a part of TP
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 09:34:40 AM
Should I uninstall the gallery and re-install it again?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: G6Cad on March 06, 2009, 11:42:36 AM
This block is for Dragoons MEDIA gallery, not for SMF gallery, you need to have the MEDIA gallery installed for this to work,
What gallery do you have installed ?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Bec on March 06, 2009, 02:20:39 PM
Hi Everyone,

Just wondering what I would need to edit in this code to have more than one image showing? And also what to remove if I just want the pictures to show no data..?

Have tried a few things but it ended up removing the picture as well lol

Thank you!
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 02:24:47 PM
Quote from: G6 on March 06, 2009, 11:42:36 AM
This block is for Dragoons MEDIA gallery, not for SMF gallery, you need to have the MEDIA gallery installed for this to work,
What gallery do you have installed ?

Yes I came to figure that out myself. I already installed the dragoon version and got rid of the smf lite.

I will be trying it out shortly. Lets see.

Hey also got a question for you but I think it will be more appropiate to ask via PM
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 02:36:10 PM
It worked.

Thanks for the support. I appreciate it very much. Being a newbie sucks. :2funny:
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: G6Cad on March 06, 2009, 04:02:28 PM
We are all newbies at a lot of things in our life, glad you got it sorted  :up:  :)
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 04:07:31 PM
Now going back to that PM?................. should I send it?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 05:43:18 PM
Also as Bec mentioned, is it possible to get the code to post three pics instead of one? If not it is ok with me I am very pleased with just being able to see one.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Petee on March 06, 2009, 07:00:40 PM
Here is a block they posted over at the smf-media site. 

2, 'rand()');  this part of the code says to pull 2 random pictures. Change it to suit your needs.

global $sourcedir, $context, $txt, $galurl, $scripturl, $settings;

require_once($sourcedir . '/Subs-MGallery.php');
loadMGal_Settings();

if (loadlanguage('MGallery') == false)
  loadLanguage('MGallery', 'english');

$items = getMediaItems(0, 2, 'rand()');

echo '
<center><table border="0">
  <tr>';

foreach ($items as $item)
  echo '
    <td>
      <div class="smalltext" style="text-align: center; line-height: 1.4em; border: 1px #000000 solid; padding: 5px;">
      <a href="',$galurl,'sa=item;id=',$item['id'],'">',$item['title'],'</a><br />
      <a href="',$galurl,'sa=item;id=',$item['id'],'"><img alt="" src="',$galurl,'sa=media;id=',$item['id'],';thumb" alt="" /></a><br />
      ',$txt['mgallery_views'],': ',$item['views'],'<br />
      ',$txt['mgallery_posted_by'],': <a href="',$scripturl,'?action=profile;u=',$item['poster_id'],'">',$item['poster_name'],'</a><br />
      ',$txt['mgallery_in_album'],': <a href="',$galurl,'sa=album;id=',$item['id_album'],'">',$item['album_name'],'</a>
      ',$item['is_new'] ? '<br /><img alt="" src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" border="0" />' : '','
      </div>
    </td>';
echo '
  </tr>
</table></center>';
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: juanporro on March 06, 2009, 07:46:50 PM
Ok one more thing.

Do you guys know how to take away the outline from the thumbnail?

The first code had a clean picture and the one with multiple pictures puts a rather ugly outline to the thumbnail.

Thanks
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: IchBin on March 06, 2009, 08:07:05 PM
Remove border: 1px #000000 solid;
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: NenaGb on April 21, 2009, 05:54:38 AM
do you have any idea how to display a gallery slideshow in a block code? i know you have to purchase the slideshow code for smf media gallery which I have done, but I was under the impression the slideshow when purchased gave you this effect only to find out i was mistaken and it does not do that at all. I would love it if there was a way to actually display the slideshow in a block.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Lesmond on April 21, 2009, 07:03:19 AM
You would be best asking that over at http://smf-media.com

Quote from: NenaGb on April 21, 2009, 05:54:38 AM
do you have any idea how to display a gallery slideshow in a block code? i know you have to purchase the slideshow code for smf media gallery which I have done, but I was under the impression the slideshow when purchased gave you this effect only to find out i was mistaken and it does not do that at all. I would love it if there was a way to actually display the slideshow in a block.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: NenaGb on April 21, 2009, 08:12:39 AM
Quote from: Lesmondâ„¢ on April 21, 2009, 07:03:19 AM
You would be best asking that over at http://smf-media.com

Quote from: NenaGb on April 21, 2009, 05:54:38 AM
do you have any idea how to display a gallery slideshow in a block code? i know you have to purchase the slideshow code for smf media gallery which I have done, but I was under the impression the slideshow when purchased gave you this effect only to find out i was mistaken and it does not do that at all. I would love it if there was a way to actually display the slideshow in a block.

already did and was told he was not interested in looking into it any further at this time. i was a bit disappointed because naturally with a slideshow you would want to be able to feature it on a page or post or w/in a block but that is not an option they offer to work on at time time. :)
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: ehsizzup on May 09, 2009, 03:28:38 AM
nice job.  ive been looking for this for a while.

can this block be changed to show pictures from one album only?


Title: Re: [Block] SMF Media Gallery Random Picture
Post by: WillyP on May 24, 2009, 03:18:07 PM
To do that I would try changing the url in the script to the url of the album you want...  ;) just a guess, I haven't tried that.

Nice block, just installed and it works great! See it here if you want a demo. (http://planetdescent.net) (no, not the picture of the day block, scroll down... :coolsmiley: )
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Dark-Wolf on May 27, 2009, 10:18:33 AM
SMF-Media block code is more clean :)
Instead to use <center> (deprecated and old tag) i've used:
<table style="margin: 0 auto; border: 0;">  ;)
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: G6Cad on May 27, 2009, 10:20:39 AM
Yes you can exclude everything if you like.
Look in the top of the code, you have the diffrent settings right there.
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Dark-Wolf on May 27, 2009, 10:27:30 AM
Quote from: G6 on May 27, 2009, 10:20:39 AM
Yes you can exclude everything if you like.
Look in the top of the code, you have the diffrent settings right there.
My final code is this (only one random image without table):
global $sourcedir, $context, $txt, $galurl, $scripturl, $settings;

require_once($sourcedir . '/Subs-MGallery.php');
loadMGal_Settings();

if (loadlanguage('MGallery') == false)
  loadLanguage('MGallery', 'english');

$items = getMediaItems(0, 1, 'RAND()');

foreach ($items as $item)
  echo '
      <div class="smalltext" style="text-align: center; line-height: 1.4em; border: 0; padding: 5px;">
      <a href="',$galurl,'sa=item;id=',$item['id'],'">',$item['title'],'</a><br />
      <a href="',$galurl,'sa=item;id=',$item['id'],'"><img alt="" src="',$galurl,'sa=media;id=',$item['id'],';thumb" /></a><br />
      ',$txt['mgallery_views'],': ',$item['views'],'<br />
      ',$txt['mgallery_posted_by'],': <a href="',$scripturl,'?action=profile;u=',$item['poster_id'],'">',$item['poster_name'],'</a><br />
      ',$txt['mgallery_in_album'],': <a href="',$galurl,'sa=album;id=',$item['id_album'],'">',$item['album_name'],'</a>
      ',$item['is_new'] ? '<br /><img alt="" src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" border="0" />' : '','
      </div>';
:)

---
One new question: "Can i exclude a specific gallery(ID) to the block"?
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: jpacs29 on September 05, 2009, 06:10:12 AM
// Hi Guys, try this code it will show 5 images without border and thumbnail info on your TP block.... hope you like it :D
______________________________________________________________________


global $sourcedir, $context, $txt, $galurl, $scripturl, $settings;

require_once($sourcedir . '/Subs-MGallery.php');
loadMGal_Settings();

if (loadlanguage('MGallery') == false)
  loadLanguage('MGallery', 'english');

$items = getMediaItems(0, 5, 'rand()');

echo '
<center><table border="0">
  <tr>';

foreach ($items as $item)
  echo '
    <td>
   <div class="smalltext" style="text-align: center; line-height: 1.4em; border: 0px #000000 solid; padding: 5px;">
      <a href="',$galurl,'sa=item;id=',$item['id'],'"></a><br />
      <a href="',$galurl,'sa=item;id=',$item['id'],'"><img alt="" src="',$galurl,'sa=media;id=',$item['id'],';thumb" alt="" /></a><br />

      ',$item['is_new'] ? '<br /><img alt="" src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" border="0" />' : '','
      </div>
    </td>';
echo '
  </tr>
</table></center>';

_________________________________________________________________
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: Freddy on September 05, 2009, 01:42:44 PM
Cool :)   I Didn't know about the getMediaItems function, thanks jpacs.

I'll have to take a better look at mgallery I think...
Title: Re: [Block] SMF Media Gallery Random Picture
Post by: jpacs29 on September 05, 2009, 02:28:54 PM
Quote from: freddy888 on September 05, 2009, 01:42:44 PM
Cool :)   I Didn't know about the getMediaItems function, thanks jpacs.

I'll have to take a better look at mgallery I think...

Welcome freddy...  i was just lucky that when i tweak that codes, i have no problem during the testing but then i had to do trial and error method too :D