<?

/*======================================================================*\
|| #################################################################### ||
|| # vBoard 1.0 Release Candidate 1 Updated Feb 13, 2005              # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright @2005 PHPHOST Enterprises Ltd. All Rights Reserved.    # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # http://www.phphost.cn                                            # ||
|| #################################################################### ||
\*======================================================================*/

// ######################## USER-EDITABLE VAR ############################
// If you want to use the standard VBulletin database table prefix, comment out
// the following line and uncomment the line after it
define('THIS_TABLE', 'local_');
// define ('THIS_TABLE', TABLE_PREFIX); 
//
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once('./includes/functions_misc.php');

global $DB_site, $vboptions, $forumcache;

$limit = "3"; // default number of HotLinks to display in case not set in database

$links_permissions = array();
$links_defaults = array();

$asb = $DB_site->query("SELECT * FROM ".THIS_TABLE."linksadmin");
while ($admin_settings = $DB_site->fetch_array($asb)) {
if (substr($admin_settings["settingname"],0,3) == "can") {
$array = preg_split("/[\s,]+/", $admin_settings["setting"]);
$links_permissions[$admin_settings["settingname"]] = iif(in_array($bbuserinfo[usergroupid], $array), 1, 0);
} else {
$links_defaults[$admin_settings["settingname"]] = $admin_settings["setting"];
}
}

if (isset($links_permissions[can_see_protected_links_on_portal])) {
$cansee = $links_permissions[can_see_protected_links_on_portal];
} else {
$cansee = 0;
}

$thismonth = vbdate("n")-1;
$thisyear = vbdate("Y");
$lastmonth = vbmktime("6","0","0",$thismonth,"1",$thisyear);

$filter = "WHERE link.linkmoderate = 0 AND ldown.usertime > $lastmonth ";

if (!$cansee) {
$limitfids = array(0);
$forumperms = array();
foreach ($forumcache AS $forum) {
$forumperms["$forum[forumid]"] = fetch_permissions($forum['forumid']);
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids[] = $forum['forumid'];
}
}
$filter .= 'AND link.linkforum NOT IN ('.implode(',', $limitfids).') ';
}

if (isset($links_defaults[categories_seen_on_portal])) {
$catsee = $links_defaults[categories_seen_on_portal];
} else {
$catsee = '';
}
if ($catsee != '') $filter .= 'AND ltoc.catid IN ('.$catsee.')';

if (isset($links_defaults[links_seen_on_portal])) {
$linksee = $links_defaults[links_seen_on_portal];
} else {
$linksee = $limit;
}

$hotquery = "
SELECT DISTINCT link.linkid AS linkid, link.linkname AS linkname, link.linkdesc AS linkdesc, 
COUNT(ldown.usertime) AS linkhits, link.linkstatus AS linkstatus, 
ltoc.catid AS linkcatid, link.linkhits AS olinkhits 
FROM ".THIS_TABLE."linkslink AS link
LEFT JOIN ".THIS_TABLE."linksdownloads AS ldown
ON link.linkid = ldown.linkid
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
ON link.linkid = ltoc.linkid
$filter
GROUP BY olinkhits ORDER BY linkhits DESC
LIMIT $linksee
";

$hotties = $DB_site->query($hotquery);

while ($myrow=$DB_site->fetch_array($hotties)) {
$linkid = $myrow["linkid"];
$linkname = parse_bbcode2($myrow["linkname"], 1, 1, 1, 1);
$linkdesc = parse_bbcode2($myrow["linkdesc"], 1, 1, 1, 1);
$linkhits = $myrow["olinkhits"];
$monthhits = $myrow["linkhits"];
$linkstatus = $myrow["linkstatus"];
if ($linkstatus > 1) { // filesize, convert to KB
$linkstatus = intval (round($linkstatus / 1024));
}
eval('$hotlinksbits .= "' . fetch_template('adv_portal_hotlinksbits') . '";');
$nhits++;
}
eval('$home[$mods[\'modid\']][\'content\'] = "' . fetch_template('adv_portal_hotlinks') . '";');
?>
