smf gallery latest images from album php block

Started by Goten22, July 30, 2017, 05:42:56 PM

Previous topic - Next topic

Goten22

I'm looking for a way to display recent images from specific album with specific start item and creator name and image title in smf gallery.

Here is some code that works but I need to place it into my divs but I don't know how. Plus it doesn't support "start from X item" and selectable album.

////////////////////////////////////////////////////
// SMF Gallery Random Picture - ver. 1.8          //
////////////////////////////////////////////////////
//
// Developed by Thurnok
// Thurnok -AT- tinyportal .DOT. net
// November 30, 2006
//
// Updated 9/26/2008
// 1.8
//      - added display # of comments option
//
// Updated 10 April 2010 by Freddy888 to work with SMF2
// Updated 12 July 2011 by Freddy888 to work with TP1
// Used in a TinyPortal phpblock or Article.
// This block displays random/most/least/newest/oldest picture(s) from
// the SMF Gallery mod along with other information
//
//////////////////////////////////////////////

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

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

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

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype = 1;
// 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 = 7;

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

//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = array(4,2,7) - don't show categories 2, 4, or 7
$gal_disallowCats = array(3,4,13,15,16,17,155,172,175);
// 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']) ? $context['user']['id'] : $_GET['u'];
}
else
$gal_member = '';

// 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 ({array_int:gal_buddylist})")) : "AND id_member = {int:gal_member}" ).'
'.(empty($gal_disallowCats) ? "" : "   AND id_cat NOT IN ({array_int:gal_disallowCats})").'
'.(empty($gal_allowCats) ? "" : "   AND id_cat IN ({array_int: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 = $smcFunc['db_query']('', $gal_query ,
array(
'gal_buddylist' => $gal_buddylist,
'gal_member' => $gal_member,
'gal_disallowCats' => $gal_disallowCats,
'gal_allowCats' => $gal_allowCats,
)
);


if (!$gal_result)
{
$db_error = @$smcFunc['db_error']($db_connection);
echo '<p />MySQL error:'.$db_error.'<p />';
}
else
{
echo "\n".'
<table cellspacing="0" cellpadding="2" border="0" align="center" width="100%">'."\n";

$gal_colcnt = 1;
echo "
<tr>\n";

while ($row = $smcFunc['db_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 "         ".($context['user']['id'] == $row['id_member'] ? ('<a href="'.$scripturl.'?action=gallery;sa=edit;pic='.$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 'Owner:';
if (!empty($gal_dispMember))
{

// display the member name who posted pic?  need to get name based on id_member
$get_name_result = $smcFunc['db_query']('' , '
SELECT member_name
FROM {db_prefix}members
WHERE id_member = {int:id_member}
LIMIT 1',
array (
'id_member' => $row['id_member'],
)
);

//$get_name_result = tp_query("SELECT member_name FROM ".$db_prefix."members WHERE id_member = ".$row['id_member'], __FILE__, __LINE__);
$gal_tmp = $smcFunc['db_fetch_assoc']($get_name_result);
echo '  <a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'">'.$gal_tmp['member_name'].'</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
$get_category_result = $smcFunc['db_query']('' , '
SELECT title
FROM {db_prefix}gallery_cat
WHERE id_cat = {int:id_cat}
LIMIT 1',
array (
'id_cat' => $row['id_cat'],
)
);

//$get_category_result = tp_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE id_cat = ".$row['id_cat'], __FILE__, __LINE__);
$gal_tmp = $smcFunc['db_fetch_assoc']($get_category_result);

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

// display # of comments if enabled
if (!empty($gal_dispNumComments))
echo '<br /><i><a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['id_picture'].'">'.$row['commenttotal']."</a> comment(s)</i><br />\n";

echo   "      </td>\n";
$gal_colcnt++;
}

$smcFunc['db_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!';
}


I can achieve it by using Aeva Media php block but this gallery is no longer supported. Here is code with my divs. It's based on foreach and is very easy to modify.


require_once($sourcedir . '/Aeva-Subs.php');   
$aeva_start = 1;                   // where item number to start at
$aeva_limit = 3;                  // maximum number of items to display
$aeva_sort = 'm.time_added DESC';  // sort see Aeva-Subs.php for values I use 'RAND()' or 'm.time_added DESC' DESC or ASC for sorting order
$aeva_all_albums = true;           // all albums .. true or false 
$aeva_albums = array(1);            // for a single album put eg: array(10) for an array of albums eg: array(3,5,7) for all albums eg:array()

$items = aeva_getMediaItems($aeva_start,$aeva_limit,$aeva_sort,$aeva_all_albums,$aeva_albums);


echo'<div style="width:20%; height:300px; text-align:center; float:left; overflow:hidden;">';

foreach ($items as $item) {
echo'
<a href="', $galurl, 'sa=item;id=', $item['id'], '#itembox">
<div id="wyr" style="margin: 0 0 2px; padding:10px; display: inline-block; text-align:center; background-image:url(', $galurl, 'sa=media;id=', $item['id'], '); background-repeat:no-repeat; background-color: #000; background-position: center; background-size: cover; width:100%; height:100px;">
<br>
', $item['title'], '
<br>
<i class="fa fa-eye"></i>: ', $item['views'], '<br />
<i class="fa fa-user"></i>: ', $item['desc'], '<br><br>

</div>
</a>';
};
echo'</div>';


Is there any way to simplify smf gallery code, to foreach maybe? Or whatever so I could put it into my divs?

vbgamer45

The $gal_allowCats = ""; in the SMF Gallery block allows you choose which categories to show the pictures from.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Goten22

Oh, I see, thanks. ;) One problem solved. But I still wonder how to put it into my own div.

vbgamer45

Around the whole table?
You can find the code that  has

echo "\n".'
<table cellspacing="0" cellpadding="2" border="0" align="center" width="100%">'."\n";

Then add a div around that and </table>
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Goten22

It's not enough. I need something like in aeva block:

', $galurl, 'sa=media;id=', $item['id'], '
', $item['title'], '

and so on. I need to separate almost every parameter.

vbgamer45

What are you trying to do. What do you want it to show?
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Goten22

#6
I want to display:

  • last 3 images
  • from specific album
  • starting from specific item (first or second)
  • image link
  • image title
  • author/uploader

Thanks for your interest. ;)

patkoch

////////////////////////////////////////////////////
// SMF Gallery Random Picture - ver. 1.8          //
////////////////////////////////////////////////////
//
// Developed by Thurnok
// Thurnok -AT- tinyportal .DOT. net
// November 30, 2006
//
// Updated 9/26/2008
// 1.8
//      - added display # of comments option
//
// Updated 10 April 2010 by Freddy888 to work with SMF2
// Updated 12 July 2011 by Freddy888 to work with TP1
// Used in a TinyPortal phpblock or Article.
// This block displays random/most/least/newest/oldest picture(s) from
// the SMF Gallery mod along with other information
//
//////////////////////////////////////////////

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

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

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

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype = 1;
// 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 = 7;

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

//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = array(4,2,7) - don't show categories 2, 4, or 7
$gal_disallowCats = array(3,4,13,15,16,17,155,172,175);
// 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']) ? $context['user']['id'] : $_GET['u'];
}
else
   $gal_member = '';

// 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 ({array_int:gal_buddylist})")) : "AND id_member = {int:gal_member}" ).'
      '.(empty($gal_disallowCats) ? "" : "   AND id_cat NOT IN ({array_int:gal_disallowCats})").'
      '.(empty($gal_allowCats) ? "" : "   AND id_cat IN ({array_int: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 = $smcFunc['db_query']('', $gal_query ,
      array(
         'gal_buddylist' => $gal_buddylist,
         'gal_member' => $gal_member,
         'gal_disallowCats' => $gal_disallowCats,
         'gal_allowCats' => $gal_allowCats,
      )
   );
   

   if (!$gal_result)
   {
      $db_error = @$smcFunc['db_error']($db_connection);
      echo '<p />MySQL error:'.$db_error.'<p />';
   }
   else
   {
      echo "\n".'
   <table cellspacing="0" cellpadding="2" border="0" align="center" width="100%">'."\n";

      $gal_colcnt = 1;
      echo "
      <tr>\n";

      while ($row = $smcFunc['db_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 "         ".($context['user']['id'] == $row['id_member'] ? ('<a href="'.$scripturl.'?action=gallery;sa=edit;pic='.$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 'Owner:';
            if (!empty($gal_dispMember))
            {
         
               // display the member name who posted pic?  need to get name based on id_member
               $get_name_result = $smcFunc['db_query']('' , '
                  SELECT member_name
                  FROM {db_prefix}members
                  WHERE id_member = {int:id_member}
                  LIMIT 1',
                  array (
                     'id_member' => $row['id_member'],
                  )
               );
            
               //$get_name_result = tp_query("SELECT member_name FROM ".$db_prefix."members WHERE id_member = ".$row['id_member'], __FILE__, __LINE__);
               $gal_tmp = $smcFunc['db_fetch_assoc']($get_name_result);
               echo '  <a href="'.$scripturl.'?action=profile;u='.$row['id_member'].'">'.$gal_tmp['member_name'].'</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
            $get_category_result = $smcFunc['db_query']('' , '
               SELECT title
               FROM {db_prefix}gallery_cat
               WHERE id_cat = {int:id_cat}
               LIMIT 1',
               array (
                  'id_cat' => $row['id_cat'],
               )
            );
         
            //$get_category_result = tp_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE id_cat = ".$row['id_cat'], __FILE__, __LINE__);
            $gal_tmp = $smcFunc['db_fetch_assoc']($get_category_result);

            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";
      
         // display # of comments if enabled
         if (!empty($gal_dispNumComments))
            echo '<br /><i><a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['id_picture'].'">'.$row['commenttotal']."</a> comment(s)</i><br />\n";

         echo   "      </td>\n";
         $gal_colcnt++;
      }

      $smcFunc['db_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!';
}

Advertisement: