<?php
/* -----------------8/9/2006 6:20am -----------------
Add Gallery Images to your Forum Index v1.8
Tested on:
* vBulletin 3.6
* PhotoPost vBGallery v2.0
Zachariah -
Ground Zero Headquarters
------------------------------------------------------*/
//Latest Images In ForumHome BEGIN
require_once('./includes/functions_gallery.php');
require_once('./includes/class_bbcode.php');
$categorycache = unserialize($vbulletin->gallery_c_cache);
$galleryoptions = unserialize($vbulletin->adv_gallery_opt);
$gallery_permissions = unserialize($vbulletin->gallery_ugroups);
if (!empty($vba_options))
{
$vba_options = array_merge($vba_options, $galleryoptions);
}
else
{
$vba_options = $galleryoptions;
}
if (!$vba_options['gallery_active'])
{
if (($permissions['adminpermissions'] & CANCONTROLPANEL) OR ($permissions['adminpermissions'] AND ISMODERATOR))
{
$warning = $vbphrase['alert_gallery_turned_off'];
$header = $warning . $header;
$footer .= $warning;
}
}
if ($vba_options['gallery_active'] AND $vbulletin->options['vbgactive']) // If Gallery and Hack is not active disable
{
// Create a list of fields to be shown in the imagebit
$showfield = explode(',', $vba_options['gallery_imagebitdisplay']);
if (!empty($showfield))
{
$showfields = array();
foreach ($showfield AS $field)
{
$showfields["$field"] = 1;
}
}
if ($vbulletin->options['vbgbit_category'] == 1)
{
$show['category'] = true;
}
$showfields['title'] = $vbulletin->options['vbgbit_title'];
$showfields['description'] = $vbulletin->options['vbgbit_description'];
$showfields['rating'] = $vbulletin->options['vbgbit_rating'];
$showfields['user'] = $vbulletin->options['vbgbit_user'];
$showfields['dateline'] = $vbulletin->options['vbgbit_dateline'];
$showfields['views'] = $vbulletin->options['vbgbit_views'];
$showfields['dimensions'] = $vbulletin->options['vbgbit_dimensions'];
$showfields['filesize'] = $vbulletin->options['vbgbit_filesize'];
$showfields['posts'] = $vbulletin->options['vbgbit_posts'];
$showfields['lastpost'] = $vbulletin->options['vbgbit_lastpost'];
// ########################### Show Variables #################################
if ($vbulletin->options['vbgnavbar'] == '1') // Disable Nav Bar
{
if ($galleryperms['cansearchimages'])
{
$show['search'] = true;
}
if ($galleryperms['cansendimagetofriend'])
{
$show['sendtofriend'] = true;
}
if ($vba_options['gallery_showmodcolumn'])
{
$show['modcolumn'] = true;
}
if ($vba_options['gallery_allowsubscribe'] AND $vbulletin->userinfo['userid'])
{
$show['subscribe'] = true;
}
if ($vba_options['gallery_allowfav'] AND $vbulletin->userinfo['userid'])
{
$show['favorites'] = true;
}
if ($galleryperms['cancreatecategories'])
{
$show['catmanager'] = true;
}
$gallery_modcache = unserialize($vbulletin->gal_mod_cache);
if ($permissions['adminpermissions'] & CANCONTROLPANEL)
{
$show['modoptions'] = true;
}
else if (!empty($gallery_modcache))
{
foreach ($gallery_modcache AS $moderator)
{
if ($moderator['userid'] == $vbulletin->userinfo['userid'])
{
$show['modoptions'] = true;
}
}
}
// ######################### Navbar Width ##########################
$lnavrows = 3;
if ($show['favorites'] OR $show['subscribe'] OR $show['catmanager'])
{
$lnavrows++;
}
if ($vba_options['gallery_newimagelimit'])
{
$lnavrows++;
}
if ($vba_options['gallery_popimagelimit'])
{
$lnavrows++;
}
if ($show['uploadlink'])
{
$lnavrows++;
}
if ($show['modoptions'])
{
$lnavrows++;
}
$navbarwidth = intval(100 / $lnavrows) . '%';
if ($vba_options['gallery_newimagelimit'])
{
foreach (explode(',', $vba_options['gallery_newimagelimit']) AS $ndatecut)
{
$show['newimagenav'] = true;
$dayphrase = construct_phrase($vbphrase['last_x_days'], $ndatecut);
eval('$newimagenavbits .= "' . fetch_template('forumhome_vbgallery_newestbits') . '";');
$show['newimagenav'] = false;
eval('$newpostnavbits .= "' . fetch_template('forumhome_vbgallery_newestbits') . '";');
}
}
eval('$gallerynav = "' . fetch_template('forumhome_vbgallery_nav') . '";');
}
// ########################## end NAV #################################
$bbuserino['usergrouparray'] = fetch_membergroupids_array($bbuserinfo);
if (empty($galleryperms))
{
$bbuserino['usergrouparray'] = fetch_membergroupids_array($bbuserinfo);
if (empty($bbuserinfo['usergrouparray']))
{
$bbuserinfo['usergrouparray'] = array(1);
}
foreach ($bbuserino['usergrouparray'] AS $usergroupid)
{
if (empty($gallery_permissions["$usergroupid"]))
{
$usergroupid = 1;
}
foreach ($gallerypermissionsbit AS $option => $value)
{
if (!$galleryperms["$option"] OR in_array($option, array('moderateimages', 'moderateposts')))
{
$galleryperms["$option"] = 0;
if ($gallery_permissions["$usergroupid"]['gallery_perms'] & $value)
{
$galleryperms["$option"] = 1;
}
}
}
}
}
if ($privatecatids = fetch_private_categories())
{
$privatecatids = explode(',', $privatecatids);
}
if ($vba_options['gallery_homeexcats'])
{
$vba_options['gallery_homeexcats'] = explode(',', $vba_options['gallery_homeexcats']);
if (PHP_VERSION > '5.0.0') {
$privatecatids = iif(empty($privatecatids), $vba_options['gallery_homeexcats'], array_merge((array)$privatecatids, (array)$vba_options['gallery_homeexcats']));
}else{
$privatecatids = iif(empty($privatecatids), $vba_options['gallery_homeexcats'], array_merge($privatecatids, $vba_options['gallery_homeexcats']));
}
}
if (!empty($privatecatids))
{
$privcatids = 'images.catid NOT IN(' . implode(',', $privatecatids) . ') AND ';
}
$galleryorderby = $vbulletin->options['vbgorderby'];
$catlimit = $vbulletin->options['vbginclude'];
$notcat = $vbulletin->options['vbgexclude'];
$vba_options['gallery_columns'] = $vbulletin->options['vbgcolumn'];
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$query = fetch_image_fields();
$cellwidth = round(100 / $vba_options['gallery_columns']) . '%';
switch ($galleryorderby)
{
case 2:
$galleryorderby = 'views DESC';
break;
case 3:
$galleryorderby = 'posts DESC';
break;
case 4:
$votequery = 'IF(votenum >= ' . $vbulletin->options['showvotes'] . ', votenum, 0) AS votenum, IF(votenum >= ' . $vbulletin->options['showvotes'] . ' AND votenum> 0, votetotal / votenum, 0) AS voteavg,';
$galleryorderby = 'voteavg DESC, votenum DESC';
break;
case 5:
$galleryorderby = 'RAND()';
break;
default:
$galleryorderby = 'dateline DESC';
}
$counter = 0;
$getrand = $db->query_read("
SELECT imageid, images.title, images.description, filename, thumbname, originalname, extension, images.catid $query[fields]
FROM " . TABLE_PREFIX . "adv_gallery_images AS images
$query[tables]
WHERE valid = 1 $ignquery
" . iif(!empty($catlimit), "AND images.catid IN ($catlimit)") . "
" . iif(!empty($notcat), "AND images.catid NOT IN ($notcat)") . "
ORDER BY $galleryorderby
LIMIT ".$vbulletin->options['vbglimit']."
");
while ($images = $vbulletin->db->fetch_array($getrand))
{
$counter++;
$adv_sorturl = '&catid=' . $images['catid'];
$gal_imagebits .= construct_imagebits($images);
}
$gal_imagebits .= construct_empty_cellbits($vba_options['gallery_columns']);
$db->free_result($getrand);
unset($images);
// ### Update the template to have the path qualified ###
$gal_imagebits = str_replace(array('"showimage.php', '"browseimages.php'), array('"' . $vba_options['gallery_url'] . '/showimage.php', '"' . $vba_options['gallery_url'] . '/browseimages.php'), $gal_imagebits);
//Latest Images In ForumHome END
$placement = $vbulletin->options['vbgplace'];
if ($placement != 7)
{ // auto placement by choice
switch ($placement)
{
case 2:
$placement = '<body>';
break;
case 3:
$placement = '$header';
break;
case 4:
$placement = '<!-- what\'s going on box -->';
break;
case 5:
$placement = '<!-- end what\'s going on box -->';
break;
case 6:
$placement = '<!-- end logged-in users -->';
break;
default:
$placement = '$navbar';
}
if ($placement != '<!-- end logged-in users -->')
{
$search_text = $placement;
$vbulletin->templatecache['FORUMHOME'] = str_replace($search_text,
$search_text.fetch_template('forumhome_vbgallery') ,$vbulletin->templatecache['FORUMHOME']);
}else{
$search_text = $placement;
$vbulletin->templatecache['FORUMHOME'] = str_replace($search_text,
$search_text.fetch_template('forumhome_vbgallery_w ho'),$vbulletin->templatecache['FORUMHOME']);
}
}else{
// Place $vbgallery in FORUMHOME template for custom location
eval('$vbgallery = "' . fetch_template('forumhome_vbgallery') . '";');
}
}
//Latest Images In ForumHome END
?>