× Didn't find what you were looking for? Ask a question
Top Posters
Since Sunday
a
5
k
5
c
5
B
5
l
5
C
4
s
4
a
4
t
4
i
4
r
4
r
4
New Topic  
bio_man bio_man
wrote...
Administrator
Educator
Posts: 33241
6 years ago
Retired as of 7/31/17

Code:
function CanViewMature()
{
if (isset($_SESSION['mature_ok']))
return true;
else
return false;
}

global $scripturl, $db_prefix, $modSettings, $boardurl, $ID_MEMBER, $user_info, $context, $settings;

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

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype = 0;

// 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 = 0;

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

// put pictures in how many columns?  (1 for left/right block, more for centerblock / article if you wish)
$gal_columns = 1;

// information display flags (0 = No, 1 = Yes)
// display picture title?
$gal_dispTitle = 0;

// display membername who posted pic?
$gal_dispMember = 0;

// display posted date?
$gal_dispDate = 1;

// display category the picture is in?
$gal_dispCategory = 0;

// display number of views?
$gal_dispViews = 1;

// display dimensions?
$gal_dispDimensions = 0;

// display filesize?
$gal_dispSize = 0;

// display picture description?
$gal_dispDescription = 0;

//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = "4,2,7" - don't show categories 2, 4, or 7
$gal_disallowCats = '';

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

if (empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}

// 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']) ? $ID_MEMBER : $_GET['u'];
}

// 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, mature, description, views, filesize, height, width, totalratings, rating, 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 ($gal_buddylist)")) : "AND ID_MEMBER = $gal_member" ).'
'.(empty($gal_disallowCats) ? '' : " AND ID_CAT NOT IN ($gal_disallowCats)").'
'.(empty($gal_allowCats) ? '' : " AND ID_CAT IN ($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 = mysql_query($gal_query);

if (!$gal_result)
{
// error retrieving information from database
if (mysql_errno() == 1146)
{
echo '<div>Error, no database found.</div>';
}
else
{
echo '<div>MySQL error: '.mysql_error().'</div>';
}
}

else
{
echo '
<table id="galleryblock">';

$gal_colcnt = 1;
echo '
<tr>';

while ($row = mysql_fetch_assoc($gal_result))
{
if ($gal_colcnt > $gal_columns)
{
// close out the row and start a new row
echo '
</tr>
<tr>
<td colspan="'.$gal_columns.'" style="padding: 0;">
<hr/>
</td>
</tr>
<tr>';

// reset count to column 1
$gal_colcnt = 1;
}

echo '<td>';

if(strlen($row['description'])>128)
$row['description'] = substr($row['description'],0,128).' ...';

// display the picture thumbnail and link it to gallery full picture
echo '
<table>';

// display title if enabled, make edit link if viewing user is picture poster
if (!empty($gal_dispTitle))
echo '
<tr>
<td colspan="2" class="galleryblocktitle">
',$ID_MEMBER == $row['ID_MEMBER'] ? '<a href="'.$scripturl.'?action=gallery;sa=edit;id='.$row['ID_PICTURE'].'">'.$row['title'].'</a>' : $row['title'],'
</td>
</tr>';

// display description if enabled
if (!empty($gal_dispDescription))
echo '
<tr>
<td colspan="2" class="galleryblocktitle">
'.$row['description'].'
</td>
</tr>';

echo'
<tr>
<td>
<a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'" ', empty($row['description']) ? 'onmouseover="Tip(\''.$row['title'].'\')" onmouseout="UnTip()"' : 'onmouseover="Tip(\''.$row['description'].'\')" onmouseout="UnTip()"','>';

if ($row['mature'] == 1)
{
if (CanViewMature() == false)
$row['thumbfilename'] = 'mature.png';
}

echo'
<img src="'.$modSettings['gallery_url'].$row['thumbfilename'].'" alt="" />
</a>
</td>
<td>';

// Display the views
if(!empty($gal_dispViews))
echo'
<div title="Views">
<i class="fa fa-eye" aria-hidden="true"></i> <span>',$row['views'],'</span>
</div>';

// Display the rating (this will be displayed all the time)

if($row['totalratings'] != 0)
$rating = $row['rating'] / $row['totalratings'];
else
$rating = '0';

echo'
<div title="Rating">
<i class="fa fa-star-half-o" aria-hidden="true"></i> <span>',floor($rating),'</span>
</div>';

// Display the poster
if (!empty($gal_dispMember))
{
// display the membername who posted pic?  need to get name based on ID_MEMBER
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT memberName FROM ".$db_prefix."members WHERE ID_MEMBER = ".$row['ID_MEMBER']));

echo '
<div title="Author">
<i class="fa fa-user" aria-hidden="true"></i> <span><a href="'.$scripturl.'?action=profile;u='.$row['ID_MEMBER'].'">'.$gal_tmp['memberName'].'</a></span>
</div>';
}

// Display the Date
if (!empty($gal_dispDate))
{
// display the date it was posted
echo '
<div title="Date">
<i class="fa fa-calendar-o" aria-hidden="true"></i> <span>',date('m/d/y', $row['date']),'</span>
</div>';
}

// display category if enabled
if (!empty($gal_dispCategory))
{
// get category name based on category id
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE ID_CAT = ".$row['ID_CAT']));
echo '
<div title="Category">
<i class="fa fa-bars" aria-hidden="true"></i> <span><a href="'.$scripturl.'?action=gallery;cat='.$row['ID_CAT'].'">'.$gal_tmp['title'].'</a></span>
</div>';
}

// display dimensions if enabled
if (!empty($gal_dispDimensions))
{
echo '
<div title="Dimension">
<i class="fa fa-expand" aria-hidden="true"></i> <span>'.$row['width'].' × '.$row['height'].'</span>
</div>';
}

// display filesize if enabled
if (!empty($gal_dispSize))
{
echo '
<div title="File Size">
<i class="fa fa-file-image-o" aria-hidden="true"></i> <span>'.$row['filesize'].'</span>
</div>';
}
echo'
</td>
</tr>
</table>
</td>';

$gal_colcnt++;
}

mysql_free_result($gal_result);
echo '
</tr>
</table>';

if (!empty($gal_member) && empty($_GET['gal_viewall']))
echo '
<div>
<a href="'.$boardurl.'/index.php?action=profile;u='.$gal_member.';gal_viewall=1">View all pictures from this member</a>
</div>';

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 '
<div>
<a href="'.$boardurl.'/index.php?'.$gal_querystring.'">View all pictures of friends</a>
</div>';
}
}
}
else
{
echo 'Sorry, you do not have permission to view pictures...';
}

Related Gallery Pics

Code:
global $scripturl, $db_prefix, $modSettings, $sourcedir, $boardurl, $txt, $ID_MEMBER, $settings, $user_info, $context;

if($context['current_action'] != 'post')
{

if(isset($_GET['topic']))
{
// how many pictures do you want to show?
$gal_numpics = 3;

  // Load the language files
  if (loadlanguage('Gallery') == false)
  loadLanguage('Gallery','english');

if(empty($modSettings['gallery_url']))
$modSettings['gallery_url'] = $boardurl . '/gallery/';

include_once($sourcedir . "/Gallery.php");
$relatedPics = Gallery_FindRelated(addslashes($context['page_title']), true);

if (!empty($relatedPics) && count($relatedPics) > 2)
{

$context['page_title'] = preg_replace("/&#?[a-z0-9]+;/i","",$context['page_title']);
shuffle($relatedPics);

$relatedPics = array_slice($relatedPics, 0, 10);
  $picsSQL = '';
  $counter = 0;
 
foreach ($relatedPics as $id)
  {
$counter++;

  if ($picsSQL != "")
  $picsSQL .= ',';

  $picsSQL .= $id[0];

 if ($counter >= $gal_numpics)
break;
  }
 
$pictures = Gallery_ReturnRelatedPictures(0,$picsSQL);

if(count($relatedPics) > $gal_numpics)
{
echo'
<script>
$(document).ready(function ShowRelated()
{
$("#button").click(function(){
$("#ajax_in_progress").fadeIn("slow");
$("#ReloadThis").load(encodeURI("https://biology-forums.com/Sources/related_images_ajax.php?t='.$context['page_title'].'"));
});
});
$(document).ajaxComplete(function ShowRelated()
{
$("#ajax_in_progress").fadeOut("slow");
});
</script>';
}
echo '
<div class="tp_block_design">
<div class="tp_header_0">
Related Images ', count($relatedPics) > $gal_numpics ? '<i id="button" class="fa fa-refresh fa-spin fa-fw" style="float: right; cursor: pointer;" title="More"></i>':'','
</div>

<div class="tp_header_0_body" id="ReloadThis">
<table id="galleryblock">';

foreach($pictures as $row)
{
  echo '
  <tr>';

  if ($row['mature'] == 1)
  {
if (isset($_SESSION['mature_ok']))
continue;
else
$row['thumbfilename'] = 'mature.png';
  }

echo '
<td>
<table>
<tr>
<td>
<a href="', $scripturl, '?action=gallery;sa=view;id=', $row['ID_PICTURE'], '" ',!empty($modSettings['gallery_set_t_title']) ? 'onmouseover="Tip(\''.htmlentities(addslashes($row['title']), ENT_QUOTES).'\')" onmouseout="UnTip()"' : '','>
<img src="'.$modSettings['gallery_url'].$row['thumbfilename'].'" alt="" />
</a>
</td>
<td>
<div title="Views">
<i class="fa fa-eye" aria-hidden="true"></i> <span>',$row['views'],'</span>
</div>';

// Display the rating (this will be displayed all the time)

if($row['totalratings'] != 0)
$rating = $row['rating'] / $row['totalratings'];
else
$rating = '0';

echo'
<div title="Rating">
<i class="fa fa-star-half-o" aria-hidden="true"></i> <span>',floor($rating),'</span>
</div>';

// display the date it was posted
echo '
<div title="Date">
<i class="fa fa-calendar-o" aria-hidden="true"></i> <span>',date('m/d/y', $row['date']),'</span>
</div>
</td>
</tr>
</table>
</td>
</tr>';

// If you want to add this in the future, the code is below...
/*
// Unread
if (empty($row['unread'])) // && $gallerySettings['gallery_set_show_newicon'] == true)
echo '<img src="' . $settings['images_url'] . '/' . $context['user']['language'] . '/new.gif" alt="" /><br />';

echo '
<div class="smalltext">';

if (!empty($modSettings['gallery_set_t_views']))
echo $txt['gallery_text_views'] . $row['views'] . '<br />';
if (!empty($modSettings['gallery_set_t_filesize']))
echo $txt['gallery_text_filesize'] . gallery_format_size($row['filesize'], 2) . '<br />';
if (!empty($modSettings['gallery_set_t_comment']))
echo $txt['gallery_text_comments'] . ' (<a href="' . $scripturl . '?action=gallery;sa=view;id=' . $row['ID_PICTURE'] . '">' . $row['commenttotal'] . '</a>)<br />';
if (!empty($modSettings['gallery_set_t_username']))
{
if ($row['realName'] != '')
echo $txt['gallery_text_by'] . ' <a href="' . $scripturl . '?action=profile;u=' . $row['ID_MEMBER'] . '">'  . $row['realName'] . '</a><br />';
else
echo $txt['gallery_text_by'] . ' ' . $txt['gallery_guest'] . '<br />';
}

echo'</div>';
*/

if ($row != end($pictures))
echo'
<tr>
<td style="padding: 0;">
<hr/>
</td>
</tr>';
else
echo'
<tr>
<td style="padding: 0;"></td>
</tr>';

}

echo '
</table>
</div>
</div>';
} // END of related images
}

if ((isset($_GET['topic']) && count($relatedPics) < 3) || !isset($_GET['topic']))
{
//   *****   LAYOUT OPTIONS   *****
// how many pictures do you want to show?  0 = all!
$gal_numpics = 4;

// use random, or most recent pics?
// 0 = random, 1 = most recent, 2 = most viewed, 3 = most commented
$gal_showtype = 0;

// 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 = 0;

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

// put pictures in how many columns?  (1 for left/right block, more for centerblock / article if you wish)
$gal_columns = 1;

// information display flags (0 = No, 1 = Yes)
// display picture title?
$gal_dispTitle = 0;

// display membername who posted pic?
$gal_dispMember = 0;

// display posted date?
$gal_dispDate = 1;

// display category the picture is in?
$gal_dispCategory = 0;

// display number of views?
$gal_dispViews = 1;

// display dimensions?
$gal_dispDimensions = 0;

// display filesize?
$gal_dispSize = 0;

// display picture description?
$gal_dispDescription = 0;

//   *****   SECURITY CONFIGURATION   *****
// do not allow the following category numbers to be displayed
// example: $gal_disallowCats = "4,2,7" - don't show categories 2, 4, or 7
$gal_disallowCats = '';

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

if (empty($modSettings['gallery_url']))
{
$modSettings['gallery_url'] = $boardurl . '/gallery/';
}

// 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']) ? $ID_MEMBER : $_GET['u'];
}

// 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, mature, description, views, filesize, height, width, totalratings, rating, 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 ($gal_buddylist)")) : "AND ID_MEMBER = $gal_member" ).'
'.(empty($gal_disallowCats) ? '' : " AND ID_CAT NOT IN ($gal_disallowCats)").'
'.(empty($gal_allowCats) ? '' : " AND ID_CAT IN ($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 = mysql_query($gal_query);

if (!$gal_result)
{
// error retrieving information from database
if (mysql_errno() == 1146)
{
echo '<div>Error, no database found.</div>';
}
else
{
echo '<div>MySQL error: '.mysql_error().'</div>';
}
}

else
{
echo '
<div class="tp_block_design">
<div class="tp_header_0">
Gallery
</div>
<div class="tp_header_0_body">
<table id="galleryblock">';

$gal_colcnt = 1;
echo '
<tr>';

while ($row = mysql_fetch_assoc($gal_result))
{
if ($gal_colcnt > $gal_columns)
{
// close out the row and start a new row
echo '
</tr>
<tr>
<td colspan="'.$gal_columns.'" style="padding: 0;">
<hr/>
</td>
</tr>
<tr>';

// reset count to column 1
$gal_colcnt = 1;
}

echo '<td>';

if(strlen($row['description'])>128)
$row['description'] = substr($row['description'],0,128).' ...';

// display the picture thumbnail and link it to gallery full picture
echo '
<table>';

// display title if enabled, make edit link if viewing user is picture poster
if (!empty($gal_dispTitle))
echo '
<tr>
<td colspan="2" class="galleryblocktitle">
',$ID_MEMBER == $row['ID_MEMBER'] ? '<a href="'.$scripturl.'?action=gallery;sa=edit;id='.$row['ID_PICTURE'].'">'.$row['title'].'</a>' : $row['title'],'
</td>
</tr>';

// display description if enabled
if (!empty($gal_dispDescription))
echo '
<tr>
<td colspan="2" class="galleryblocktitle">
'.$row['description'].'
</td>
</tr>';

echo'
<tr>
<td>
<a href="'.$scripturl.'?action=gallery;sa=view;id='.$row['ID_PICTURE'].'" ', empty($row['description']) ? 'onmouseover="Tip(\''.$row['title'].'\')" onmouseout="UnTip()"' : 'onmouseover="Tip(\''.$row['description'].'\')" onmouseout="UnTip()"','>';

if ($row['mature'] == 1)
{
if (CanViewMature() == false)
$row['thumbfilename'] = 'mature.png';
}

echo'
<img src="'.$modSettings['gallery_url'].$row['thumbfilename'].'" alt="" />
</a>
</td>
<td>';

// Display the views
if(!empty($gal_dispViews))
echo'
<div title="Views">
<i class="fa fa-eye" aria-hidden="true"></i> <span>',$row['views'],'</span>
</div>';

// Display the rating (this will be displayed all the time)

if($row['totalratings'] != 0)
$rating = $row['rating'] / $row['totalratings'];
else
$rating = '0';

echo'
<div title="Rating">
<i class="fa fa-star-half-o" aria-hidden="true"></i> <span>',floor($rating),'</span>
</div>';

// Display the poster
if (!empty($gal_dispMember))
{
// display the membername who posted pic?  need to get name based on ID_MEMBER
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT memberName FROM ".$db_prefix."members WHERE ID_MEMBER = ".$row['ID_MEMBER']));

echo '
<div title="Author">
<i class="fa fa-user" aria-hidden="true"></i> <span><a href="'.$scripturl.'?action=profile;u='.$row['ID_MEMBER'].'">'.$gal_tmp['memberName'].'</a></span>
</div>';
}

// Display the Date
if (!empty($gal_dispDate))
{
// display the date it was posted
echo '
<div title="Date">
<i class="fa fa-calendar-o" aria-hidden="true"></i> <span>',date('m/d/y', $row['date']),'</span>
</div>';
}

// display category if enabled
if (!empty($gal_dispCategory))
{
// get category name based on category id
$gal_tmp = mysql_fetch_assoc(mysql_query("SELECT title FROM ".$db_prefix."gallery_cat WHERE ID_CAT = ".$row['ID_CAT']));
echo '
<div title="Category">
<i class="fa fa-bars" aria-hidden="true"></i> <span><a href="'.$scripturl.'?action=gallery;cat='.$row['ID_CAT'].'">'.$gal_tmp['title'].'</a></span>
</div>';
}

// display dimensions if enabled
if (!empty($gal_dispDimensions))
{
echo '
<div title="Dimension">
<i class="fa fa-expand" aria-hidden="true"></i> <span>'.$row['width'].' × '.$row['height'].'</span>
</div>';
}

// display filesize if enabled
if (!empty($gal_dispSize))
{
echo '
<div title="File Size">
<i class="fa fa-file-image-o" aria-hidden="true"></i> <span>'.$row['filesize'].'</span>
</div>';
}
echo'
</td>
</tr>
</table>
</td>';

$gal_colcnt++;
}

mysql_free_result($gal_result);
echo '
</tr>
</table>
</div>
</div>';

if (!empty($gal_member) && empty($_GET['gal_viewall']))
echo '
<div>
<a href="'.$boardurl.'/index.php?action=profile;u='.$gal_member.';gal_viewall=1">View all pictures from this member</a>
</div>';

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 '
<div>
<a href="'.$boardurl.'/index.php?'.$gal_querystring.'">View all pictures of friends</a>
</div>';
}
}
}
else
{
echo 'Sorry, you do not have permission to view pictures...';
}
} //last close
}
Read 1276 times

Related Topics

New Topic      
Explore
Post your homework questions and get free online help from our incredible volunteers
  1333 People Browsing
 123 Signed Up Today
Related Images
  
 318
  
 385
  
 315
Your Opinion
Where do you get your textbooks?
Votes: 372