TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

February 26, 2024, 03:31:28 PM

Login with username, password and session length
Members
  • Total Members: 3,881
  • Latest: fords8
Stats
  • Total Posts: 195,080
  • Total Topics: 21,209
  • Online today: 104
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 1
  • Guests: 68
  • Total: 69
  • @rjen

[Block] SMF Media Gallery Random Picture

Started by Petee, December 14, 2008, 06:02:31 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

Petee

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

fl4pj4ck

excellent block, but is there any chance the thumbnails would be bigger?

Petee

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


Jakki


wyckeddreamz


vulcan59

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?




IchBin

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

Thanks for the response IchBin.

Will look it up.

IchBin

Sure, need any help with it feel free to post your code and we'll take a look.