Login  |  Register
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome, Guest. Please login or register.
Did you miss your activation email?

February 05, 2023, 11:18:58 AM

Login with username, password and session length
Members
  • Total Members: 3856
  • Latest: Bixby
Stats
  • Total Posts: 193983
  • Total Topics: 21135
  • Online today: 45
  • Online ever: 3540
  • (September 02, 2022, 06:38:54 PM)
Users Online
Users: 5
Guests: 30
Total: 35

Author Topic: [Block] SMF Media Gallery Random Picture  (Read 28873 times)

0 Members and 1 Guest are viewing this topic.

Petee

  • Guest
[Block] SMF Media Gallery Random Picture
« on: December 14, 2008, 11:02:31 AM »
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:

Code: [Select]
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.

Code: [Select]
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>';
« Last Edit: March 06, 2009, 12:50:33 PM by Petee »

fl4pj4ck

  • Guest
Re: [Block] SMF Media Gallery Random Picture
« Reply #1 on: December 14, 2008, 12:23:59 PM »
excellent block, but is there any chance the thumbnails would be bigger?

Petee

  • Guest
Re: [Block] SMF Media Gallery Random Picture
« Reply #2 on: December 14, 2008, 04: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.

HellBent

  • Guest
Re: [Block] SMF Media Gallery Random Picture
« Reply #3 on: December 21, 2008, 08:14:36 AM »
Fabulous!  I love it.  Thankyou  :up:

Jakki

  • Guest
Re: [Block] SMF Media Gallery Random Picture
« Reply #4 on: December 31, 2008, 06:31:54 AM »
Perfect!!! worked great. thanks

wyckeddreamz

  • Guest
Re: [Block] SMF Media Gallery Random Picture
« Reply #5 on: January 01, 2009, 04:12:14 PM »
thank you for this, works a treat!!!

vulcan59

  • Guest
Re: [Block] SMF Media Gallery Random Picture
« Reply #6 on: January 04, 2009, 11:57:48 PM »
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?




Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: [Block] SMF Media Gallery Random Picture
« Reply #7 on: January 05, 2009, 08:26:40 AM »
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.

vulcan59

  • Guest
Re: [Block] SMF Media Gallery Random Picture
« Reply #8 on: January 05, 2009, 12:44:50 PM »
Thanks for the response IchBin.

Will look it up.

Offline IchBin

  • Friends
  • *
  • Posts: 16231
Re: [Block] SMF Media Gallery Random Picture
« Reply #9 on: January 05, 2009, 01:08:02 PM »
Sure, need any help with it feel free to post your code and we'll take a look.