// #######################################################################
//
// This code is provided free on the basis that you do not claim that
// it is your own, sell it or use it as the basis for other products that you
// sell. But by all means extend it, modify it, upgrade it, correct it,
// suggest improvements, call me an idiot, etc.
//
// (c) 2004/05
// Andrew Dearing
// European Industrial Research Management Association
// www.eirma.asso.fr
//
// v1.60b 22.04.2005
// see changes.txt for history
// v1.00, 1.3.2004
// #######################################################################
error_reporting(E_ALL & ~E_NOTICE);
define('THIS_SCRIPT', 'local_links');
define('ADMIN_SCRIPT', 'local_links_admin');
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
'local_links'
);
// pre-cache all templates used by this hack
$globaltemplates = array(
'links_addnewcat',
'links_addnewlink',
'links_addnewlink_catinput',
'links_addnewlink_catinput_one',
'links_addnewlink_catselect',
'links_addnewlink_catselect_one',
'links_catbit',
'links_catmod',
'links_footer',
'links_header',
'links_linkbit',
'links_linkbit_table',
'links_linkseparator',
'links_main',
'links_massedit',
'links_modbit',
'links_othercatsbit',
'links_ratebit',
'links_search',
'links_subcatbit',
'navbar',
'option'
);
// get special data templates from the datastore
$specialtemplates = array(
'smiliecache',
'bbcodecache'
);
// pre-cache templates used by specific actions
$actiontemplates = array();
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once("includes/local_links_include.php");
if (!isset($_REQUEST['action']) or $_REQUEST['action']=="") $_REQUEST['action'] = "links";
// #################### Links Home
if ($_REQUEST['action'] == "links") {
require_once('includes/functions_bbcodeparse.php');
$this_navigation_title = $vbphrase['ll_links_database'];
if (!$perpage) $perpage = $bbuserinfo['maxposts'];
$checkmax = explode(',', $vboptions['usermaxposts'] . ',' . $vboptions['maxposts']);
if ($perpage < 1 OR $perpage > max($checkmax)) $perpage = $vboptions['maxposts'];
$perpage = iif($links_defaults['links_per_page']!=0, $links_defaults['links_per_page'], $perpage);
build_forum_list();
// fetch the permissions for each forum
$limitfids = array(0);
if (!$links_permissions['can_see_protected_links_on_portal']) {
$forumperms = array();
foreach ($forumcache AS $forum) {
if (isset($forum['forumid'])) {
$forumperms["$forum[forumid]"] = fetch_permissions($forum['forumid']);
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids[] = $forum['forumid'];
}
}
}
}
if (!isset($_REQUEST['page']) or $_REQUEST['page']=="") $_REQUEST['page'] = '1';
$pagenumber = iif( is_numeric($_REQUEST['page']), $_REQUEST['page'], '1');
if (!isset($_REQUEST['catid']) or !is_numeric($_REQUEST['catid'])) $_REQUEST['catid'] = $BASE_CAT;
$viewcatid = $_REQUEST['catid'];
if (isset($linkscat[$viewcatid]) and in_array($linkscat[$viewcatid]["catforum"], $limitfids)) {
print_no_permission();
exit;
} else {
if (!$links_permissions["can_moderate_links"] and !$links_permissions["can_moderate_forums"]
and ($viewcatid==$HIDE_CAT or $viewcatid==$AVL_CAT or $viewcatid==$BRKN_CAT or $viewcatid==$INVD_CAT)) {
print_no_permission();
exit;
}
}
if (!isset($_REQUEST['sort'])) $_REQUEST['sort']=="";
$catlistbit = "";
$linklistbit = "";
// nav bar and title
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $this_navigation_title;
if ($viewcatid>0) {
if (!isset($linkscat["$viewcatid"]['catid'])) {
eval(print_standard_error($vbphrase['ll_error_category'].' '.$vbphrase['ll_return'].'',0));
exit;
}
$viewcatname = parse_bbcode2($linkscat["$viewcatid"]["catname"], $links_defaults['allow_html'], $links_defaults['allow_images'], $links_defaults['allow_smilies'], $links_defaults['allow_bbcode']);
$viewcatdesc = parse_bbcode2($linkscat["$viewcatid"]["catdesc"], $links_defaults['allow_html'], $links_defaults['allow_images'], $links_defaults['allow_smilies'], $links_defaults['allow_bbcode']);
$viewcattext = parse_bbcode2($linkscat["$viewcatid"]["cattext"], $links_defaults['allow_html'], $links_defaults['allow_images'], $links_defaults['allow_smilies'], $links_defaults['allow_bbcode']);
$parentlist = $linkscat["$viewcatid"]["parentlist"];
$parentlist = array_reverse(explode(',', $parentlist));
foreach ($parentlist AS $linkID) {
if ($linkID > 0) {
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$linkID"] = htmlspecialchars(kill_bbcodes($linkscat["$linkID"]["catname"]));
}
}
$navbits[""] = htmlspecialchars(kill_bbcodes($linkscat["$viewcatid"]["catname"]));
$this_navigation_title = $this_navigation_title . ' - ' . $viewcatname;
} else {
$viewcatdesc = $viewcattext = "";
switch ($viewcatid) {
case $FAVS_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showfav'];
break;
case $HIDE_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showhid'];
break;
case $AVL_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showavl'];
break;
case $BRKN_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showbrk'];
break;
case $INVD_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showinv'];
break;
case $HOT_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showhot'];
break;
case $NEW_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_shownew'];
break;
case $RND_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showrnd'];
break;
case $MY_CAT:
$viewcatname = $navbits[""] = $vbphrase['ll_menu_showmyl'];
break;
case $BASE_CAT:
$viewcatname = $vbphrase['ll_links_database'];
$count = $DB_site->query_first("
SELECT COUNT(link.linkid) AS newlinks
FROM (".THIS_TABLE."linkslink AS link
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
ON link.linkid = ltoc.linkid)
WHERE
link.linkstatus>0
AND link.linkforum NOT IN (".implode(',', $limitfids).")
AND linkdate > ".$bbuserinfo['lastvisit']."
");
$viewcattext = ''.$count['newlinks'] .' '. $vbphrase['ll_newentries'] .' '. $vbphrase['ll_sincelastvisit'];
break;
default:
$viewcatname = "";
break;
}
}
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// Get links in selected category
$query = "
SELECT DISTINCT link.linkid AS linkid, link.linkname AS linkname, link.linkuserid AS linkuserid,
link.linkusername AS linkusername, link.linkurl AS linkurl, link.linkimg AS linkimg, link.linkdesc AS linkdesc,
link.linkhits AS linkhits, link.linkstatus AS linkstatus, link.linkdate AS linkdate,
link.linkmoderate AS linkmoderate,
ltoc.catid AS linkcatid, ltoc.displayorder AS linkdorder, ltoc2.catid AS linkcatid2
FROM (".THIS_TABLE."linkslink AS link
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
ON link.linkid = ltoc.linkid)
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc2
ON link.linkid = ltoc2.linkid
";
// Which records to pull
switch ($viewcatid) {
case $FAVS_CAT:
$query .= "
LEFT JOIN ".THIS_TABLE."linksfavs AS lfav
ON link.linkid = lfav.linkid
WHERE
lfav.userid = '".$bbuserinfo['userid']."'
AND ltoc.catid <= ltoc2.catid
AND link.linkforum NOT IN (".implode(',', $limitfids).")
";
break;
case $HIDE_CAT:
$query .= "WHERE
link.linkstatus='".$LINK_HIDDEN."'
AND ltoc.catid <= ltoc2.catid
AND link.linkforum NOT IN (".implode(',', $limitfids).")
";
break;
case $AVL_CAT:
$query .= "WHERE
link.linkstatus>0
AND ltoc.catid <= ltoc2.catid
AND link.linkforum NOT IN (".implode(',', $limitfids).")
";
break;
case $BRKN_CAT:
$query .= "WHERE
link.linkstatus='".$LINK_BROKEN."'
AND ltoc.catid <= ltoc2.catid
AND link.linkforum NOT IN (".implode(',', $limitfids).")
";
break;
case $INVD_CAT:
$query .= "WHERE
link.linkstatus='".$LINK_NO_ACCESS."'
AND ltoc.catid <= ltoc2.catid
AND link.linkforum NOT IN (".implode(',', $limitfids).")
";
break;
case $NEW_CAT:
if (isset($_REQUEST['limit'])) {
$when = TIMENOW - intval($_REQUEST['limit'])*24*60*60;
$viewcatdesc = $viewcattext = $vbphrase['ll_newentries'].' ('.$_REQUEST['limit'].' '.$vbphrase['ll_days'].')';
} elseif (isset($_REQUEST['lastvisit']) or $links_defaults["days_seen_on_portal"]==0) {
$when = $bbuserinfo['lastvisit'];
$viewcatdesc = $viewcattext = $vbphrase['ll_newentries'].' '.$vbphrase['ll_sincelastvisit'];
} else {
$when = TIMENOW - intval($links_defaults["days_seen_on_portal"])*24*60*60;
$viewcatdesc = $viewcattext = $vbphrase['ll_newentries'].' ('.$links_defaults["days_seen_on_portal"].' '.$vbphrase['ll_days'].')';
}
$query .= "WHERE
link.linkstatus>0
AND ltoc.catid <= ltoc2.catid
AND link.linkforum NOT IN (".implode(',', $limitfids).")
AND linkdate > $when
";
break;
case $RND_CAT:
case $HOT_CAT:
if (isset($_REQUEST['limit'])) {
$limit = "
LIMIT ".intval($_REQUEST['limit'])."
";
} else {
$limit = "
LIMIT ".intval($links_defaults["links_seen_on_portal"])."
";
}
switch ($viewcatid) {
case $HOT_CAT: $sorder = "linkhits DESC"; break;
case $RND_CAT: $sorder = "RAND()"; break;
}
// Pull linkids to use as selection criteria in a second search
$asb = $DB_site->query("
SELECT linkid
FROM ".THIS_TABLE."linkslink AS link
WHERE
link.linkstatus>0
AND link.linkforum NOT IN (".implode(',', $limitfids).")
ORDER BY $sorder $limit
");
$ids = array(-1);
while ($myrow=$DB_site->fetch_array($asb)) {
$ids[] = $myrow['linkid'];
}
$query .= "WHERE
link.linkid IN (".implode(',', $ids).")
AND ltoc.catid <= ltoc2.catid
";
break;
case $MY_CAT:
$query .= "WHERE
link.linkuserid=".$bbuserinfo['userid']."
AND ltoc.catid <= ltoc2.catid
AND link.linkforum NOT IN (".implode(',', $limitfids).")
";
break;
default:
$query .= "WHERE
ltoc.catid = '".$viewcatid."'
AND link.linkforum NOT IN (".implode(',', $limitfids).")
";
break;
}
// Now sort out the sorting...
switch ($viewcatid) {
case $HIDE_CAT:
case $AVL_CAT:
case $BRKN_CAT:
case $INVD_CAT:
case $RND_CAT:
$sorder = "linkname ASC";
$searchnav = "";
break;
case $HOT_CAT:
$sorder = "linkhits DESC";
$searchnav = "";
break;
case $FAVS_CAT:
case $NEW_CAT:
case $MY_CAT:
default:
$sort = $_REQUEST['sort'];
if ($sort == "") {
$sort = iif(isset($links_defaults['default_sort_order']), $links_defaults['default_sort_order'], 'N');
}
switch ($sort) {
case 'd': $sorder = "linkdorder ASC, linkdate DESC, linkcatid ASC"; break;
case 'D': $sorder = "linkdorder ASC, linkdate ASC, linkcatid ASC"; break;
case 'h': $sorder = "linkdorder ASC, linkhits DESC, linkcatid ASC"; break;
case 'H': $sorder = "linkdorder ASC, linkhits ASC, linkcatid ASC"; break;
case 'n': $sorder = "linkdorder ASC, linkname DESC, linkcatid ASC"; break;
case 'N':
default: $sorder = "linkdorder ASC, linkname ASC, linkcatid ASC"; break;
}
$searchnav = "1";
break;
}
// Filter out unmoderated links if not the owner/moderator
if (!$links_permissions["can_moderate_links"] and !$links_permissions["can_moderate_forums"]) {
$query .= "
AND (link.linkmoderate = $LINK_ACCEPTED OR (link.linkmoderate = $LINK_TO_MODERATE AND link.linkuserid = ".$bbuserinfo['userid']."))
";
}
$query .= "
ORDER BY $sorder
";
get_linksfav();
get_linksratings();
list ($linklistbit, $nhits) = get_linklistbit($query, "", $pagenumber, $perpage, 0);
$pcatid = $linkscat[$viewcatid]["parentid"];
$catstyle = 1;
// Get categories at this level
unset ($thisorder);
$cattree = cat_walk($viewcatid, $links_defaults['cat_depth_display']);
foreach ($cattree AS $thisid=>$thischildren) {
$catlistbit .= get_catlistbit($thisid, $thischildren, 0);
}
$pagenav = construct_page_nav($nhits, THIS_SCRIPT.".php?action=links&catid=$viewcatid&sort=$sort", "&pp=$perpage");
$catclosed = $linkscat[$viewcatid]["catclosed"];
if ($catclosed != 0) {
$links_permissions["can_add_link"] = 0;
if (!$links_permissions["can_admin_links"]) $links_permissions["can_edit_link"] = 0;
$links_permissions["can_add_category"] = 0;
if (!$links_permissions["can_admin_links"]) $links_permissions["can_edit_category"] = 0;
}
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_main')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Set up a Search
if ($_REQUEST['action'] == "search") {
$this_navigation_title = $vbphrase['ll_links_database'];
build_forum_list();
// Make Links Nav Bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// this code controls which menu items are visible in the header template
$viewcatid = -2;
$links_permissions["can_add_link"] = 0;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_search')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Show Links, i.e. Execute a Search
if ($_REQUEST['action'] == "show") {
require_once('includes/functions_bbcodeparse.php');
$this_navigation_title = $vbphrase['ll_links_database'];
$sstring = $_REQUEST['search'];
$sforum = intval($_REQUEST['forum']);
$suser = $_REQUEST['user'];
build_forum_list();
// fetch the permissions for each forum
$limitfids = array(-999999);
$forumperms = array();
foreach ($forumcache AS $forum) {
if (isset($forum['forumid'])) {
$forumperms["$forum[forumid]"] = fetch_permissions($forum['forumid']);
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids[] = $forum['forumid'];
}
}
}
unset($forum);
$subtitle = $vbphrase['ll_entries'];
$squery = "
WHERE
link.linkforum NOT IN (".implode(',', $limitfids).")
AND (link.linkmoderate = $LINK_ACCEPTED
OR (link.linkmoderate = $LINK_TO_MODERATE AND link.linkuserid = ".$bbuserinfo['userid']."))
";
$sorder = "
ORDER BY linkdorder ASC, linkname ASC, linkcatid ASC
";
if ($sstring <> "") {
$squery .= "
AND MATCH (link.linkname, link.linkdesc) AGAINST ('".addslashes($sstring)."'
";
if (defined('CANDO_BOOLEAN')) $squery .= " IN BOOLEAN MODE";
$squery .= ")";
}
if ($suser <> "") {
$squery .= "
AND link.linkuserid = '".addslashes($suser)."'
";
}
if ($sforum <> "") {
if (preg_match ( "/^\s*-*\d+\s*$/", $sforum)) {
$squery .= "
AND link.linkforum IN ($sforum)
";
} else {
eval(print_standard_error($vbphrase['ll_error_forum'].' '.$vbphrase['ll_return'].'',0));
exit;
}
}
$query = "
SELECT link.linkid AS linkid, link.linkname AS linkname, link.linkuserid AS linkuserid,
link.linkusername AS linkusername, link.linkurl AS linkurl, link.linkimg AS linkimg, link.linkdesc AS linkdesc,
link.linkhits AS linkhits, link.linkstatus AS linkstatus, link.linkdate AS linkdate,
link.linkmoderate AS linkmoderate,
ltoc.catid AS linkcatid, ltoc.displayorder AS linkdorder
FROM ".THIS_TABLE."linkslink AS link
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
ON link.linkid = ltoc.linkid
$squery
$sorder
";
$viewcatid = $BASE_CAT;
$catlistbit = "";
// draw nav bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
get_linksfav();
get_linksratings();
// Get links that match the search query
list ($linklistbit, $nhits) = get_linklistbit($query, $sstring);
$pcatid = $linkscat[$viewcatid]["parentid"];
$viewcatname = $vbphrase['ll_searchresults'];
$message = iif ($nhits,$nhits,0).' '.$subtitle;
if ($sstring <> "") $message .= ' '.$vbphrase['ll_matching'].' '.$sstring;
if ($sforum <> "") $message .= ' '.$vbphrase['ll_asso_forum'].' '.$forumcache[$sforum][title];
if ($suser <> "") {
$userinfo = fetch_userinfo($suser);
$message .= ' '.$vbphrase['ll_submitby'].' '.$userinfo['username'];
}
$viewcatdesc = $message;
$viewcattext = $message;
// control which menu items are visible in the header template
$viewcatid = -2;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
$action = "";
if ($sstring <> "") $action = "&search=$sstring";
if ($sforum <> "") $action .= "&forum=$sforum";
$pagenav = "";
$searchnav = "";
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_main')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Moderate
if ($_REQUEST['action'] == "mod") {
require_once('includes/functions_bbcodeparse.php');
if (!$links_permissions["can_moderate_links"] and !$links_permissions["can_moderate_forums"]) {
print_no_permission();
exit;
}
$this_navigation_title = $vbphrase['ll_links_moderation'];
build_forum_list();
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $vbphrase['ll_links_database'];
$navbits[""] = $vbphrase['ll_links_moderation'];
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// fetch the permissions for each forum
$limitfids = array(0);
$forumperms = array();
foreach ($forumcache AS $forum) {
if (isset($forum['forumid'])) {
$forumperms["$forum[forumid]"] = fetch_permissions($forum['forumid']);
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids[] = $forum['forumid'];
}
}
}
unset($forum);
$query = $DB_site->query("
SELECT forumid, title
FROM ". TABLE_PREFIX . "forum
");
while ($row=$DB_site->fetch_array($query)) {
$forum[$row['forumid']] = $row['title'];
}
$query = $DB_site->query("
SELECT link.linkid AS linkid, ltoc.catid AS linkcatid, link.linkmoderate AS linkmoderate
FROM ". THIS_TABLE . "linkslink AS link
LEFT JOIN ". THIS_TABLE . "linksltoc AS ltoc
ON link.linkid = ltoc.linkid
WHERE
link.linkforum NOT IN (".implode(',', $limitfids).")
AND (
link.linkmoderate = $LINK_TO_MODERATE
OR
(link.linkreviewfreq>0 AND (link.linkmoddate+link.linkreviewfreq*24*60*60)<".TIMENOW.")
)
");
foreach ($linkscat AS $thiscat) {
$tomod[$thiscat['catid']] = 0;
}
while ($row=$DB_site->fetch_array($query)) {
$tomod[$row['linkcatid']] += 1;
}
$catlistbit = '';
$linklistbit = '';
$links_permissions["can_edit_category"] = 0;
foreach ($linkscat AS $thiscat) {
if (!in_array($thiscat["catforum"], $limitfids) and
($tomod[$thiscat['catid']] > 0 or $thiscat['catmoderate'] == $LINK_TO_MODERATE)) {
$catlistbit .= get_catlistbit ($thiscat['catid'], array(), 1);
}
}
if ($catlistbit == '') $catlistbit = '
'.$vbphrase['ll_error_nolinkmod'].' |
';
$pagenav = "";
$searchnav = "";
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_main')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
if ($_REQUEST['action'] == "domod") {
require_once('includes/functions_bbcodeparse.php');
if (!$links_permissions["can_moderate_links"] and !$links_permissions["can_moderate_forums"]) {
print_no_permission();
exit;
}
$this_navigation_title = $vbphrase['ll_links_moderation'];
build_forum_list();
unset($linkid);
unset($viewcatid);
if (isset($_REQUEST['id'])) {
$linkid = $_REQUEST['id'];
} elseif (isset($_REQUEST['catid'])) {
$viewcatid = intval($_REQUEST['catid']);
} else {
eval(print_standard_error($vbphrase['ll_error_catlinknull'].' '.$vbphrase['ll_return'].'',0));
exit;
}
// fetch the permissions for each forum
$limitfids = array(0);
$forumperms = array();
foreach ($forumcache AS $forum) {
if (isset($forum['forumid'])) {
$forumperms["$forum[forumid]"] = fetch_permissions($forum['forumid']);
if (!($forumperms["$forum[forumid]"] & CANVIEW) || !($forumperms["$forum[forumid]"] & CANVIEWOTHERS)) {
$limitfids[] = $forum['forumid'];
}
}
}
unset($forum);
// find unmoderated links
$query = "
SELECT link.linkid AS linkid, link.linkname AS linkname, link.linkuserid AS linkuserid,
link.linkusername AS linkusername, link.linkurl AS linkurl, link.linkimg AS linkimg, link.linkdesc AS linkdesc,
link.linkhits AS linkhits, link.linkstatus AS linkstatus, link.linkdate AS linkdate,
link.linkmoderate AS linkmoderate,
ltoc.catid AS linkcatid, ltoc.displayorder AS linkdorder
FROM ".THIS_TABLE."linkslink AS link
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
ON link.linkid = ltoc.linkid
WHERE
".iif(isset($linkid),"link.linkid = '$linkid'",
"ltoc.catid = '$viewcatid'
AND link.linkforum NOT IN (".implode(',', $limitfids).")
AND (
link.linkmoderate = $LINK_TO_MODERATE
OR
(link.linkreviewfreq>0 AND (link.linkmoddate+link.linkreviewfreq*24*60*60)<".TIMENOW.")
)
")."
ORDER BY linkcatid, linkname
";
$catlistbit = "";
list ($linklistbit, $nhits) = get_linklistbit($query, "", 1, 999999, 1);
// build nav bar
$navbits = array();
if ($viewcatid>0 and isset($linkscat["$viewcatid"])) {
$parentlist = $linkscat["$viewcatid"]["parentlist"];
$parentlist = array_reverse(explode(',', $parentlist));
foreach ($parentlist AS $pid) {
if ($pid > 0) {
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$pid"] = kill_bbcodes($linkscat["$pid"]["catname"]);
}
}
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$viewcatid"] = kill_bbcodes($linkscat["$viewcatid"]["catname"]);
}
$navbits[""] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
$pcatid = $linkscat[$viewcatid]["parentid"];
$viewcatname = $linkscat[$viewcatid]["catname"];
$message = iif($nhits, $nhits, 0) . ' ' . $vbphrase['ll_entries_to_moderate'];
$viewcatdesc = $message;
$viewcattext = $message;
// this code controls which menu items are visible in the header template
$viewcatid = -2;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
$pagenav = "";
$searchnav = "";
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_main')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Add Entry
if ($_REQUEST['action'] == "addlink") {
require_once('includes/functions_bbcodeparse.php');
if (!isset($links_permissions["can_add_link"]) or !$links_permissions["can_add_link"]) {
print_no_permission();
exit;
}
$linkurl = "http://";
if (isset($_REQUEST['url'])) {
$linkurl = preg_replace("/(['\"]*)(.*)\\1/", "\\2", $_REQUEST['url']);
}
$linkname = "";
if (isset($_REQUEST['name'])) {
$linkname = preg_replace("/(['\"]*)(.*)\\1/", "\\2", $_REQUEST['name']);
}
$linkdesc = "";
if (isset($_REQUEST['description'])) {
$linkdesc = preg_replace("/(['\"]*)(.*)\\1/", "\\2", $_REQUEST['description']);
}
$linkimg = "";
if (!isset($_REQUEST['catid']) or $_REQUEST['catid']=="") {
$_REQUEST['catid'] = $BASE_CAT;
}
$viewcatid = intval($_REQUEST['catid']);
$viewcatname = "";
if (isset($linkscat[$viewcatid]["catname"])) $viewcatname = $linkscat[$viewcatid]["catname"];
$viewlinkid = -1;
$linkmod = 0;
if ($linkscat[$viewcatid]["catclosed"] != 0) {
eval(print_standard_error($vbphrase['ll_error_catclosed'].' '.$vbphrase['ll_return'].'',0));
exit;
}
if (!isset($links_defaults["default_forumid"]) or
!forumid_is_valid($links_defaults["default_forumid"])
) {
eval(print_standard_error($vbphrase['ll_error_noforum'].' '.$vbphrase['ll_return'].'',0));
exit;
}
$curforumid = $links_defaults["default_forumid"];
$this_navigation_title = $vbphrase['ll_menu_addlink'];
build_forum_list();
$curforumtitle = iif($curforumid<=0,$vbphrase['ll_none'],$forumcache[$curforumid][title]);
// draw nav bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $vbphrase['ll_links_database'];
if ($viewcatid>0 and isset($linkscat["$viewcatid"])) {
$parentlist = $linkscat["$viewcatid"]["parentlist"];
$parentlist = array_reverse(explode(',', $parentlist));
foreach ($parentlist AS $linkID) {
if ($linkID > 0) {
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$linkID"] = kill_bbcodes($linkscat["$linkID"]["catname"]);
}
}
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$viewcatid"] = kill_bbcodes($linkscat["$viewcatid"]["catname"]);
}
$navbits[""] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// Build the category list
$pcatid = array($viewcatid);
$optbit = construct_category_list ($pcatid, SELECT_MULTI_CAT, 0, "pcatid[]");
$link_pcatbit = construct_parent_list ($pcatid);
$action = "doaddlink";
$display_order = $links_defaults["default_link_dseq"];
$instructions = parse_bbcode2($linkscat[$viewcatid]["catinstructions"], $links_defaults['allow_html'], $links_defaults['allow_images'], $links_defaults['allow_smilies'], $links_defaults['allow_bbcode']);
// this code controls which menu items are visible in the header template
$links_permissions["can_add_link"] = 0;
$links_permissions["can_delete_link"] = 0;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
$pcatid = $viewcatid;
$linkreviewfreq = 0;
unset($linkstatus);
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_addnewlink')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Edit Entry
if ($_REQUEST['action'] == "editlink") {
require_once('includes/functions_bbcodeparse.php');
$viewlinkid = intval($_REQUEST['linkid']);
$viewcatid = intval($_REQUEST['catid']);
$viewcatname = "";
if (isset($linkscat[$viewcatid]["catname"])) $viewcatname = $linkscat[$viewcatid]["catname"];
if (!isset($_REQUEST['page']) or $_REQUEST['page']=="") $_REQUEST['page'] = '1';
$pagenumber = iif( is_numeric($_REQUEST['page']), $_REQUEST['page'], '1');
$linkmod = intval($_REQUEST['mod']);
if ($linkmod != 1) $linkmod = 0;
$asb = $DB_site->query("
SELECT *
FROM ".THIS_TABLE."linkslink
WHERE linkid=$viewlinkid
LIMIT 1
");
if ($DB_site->num_rows($asb)) {
while ($myrow=$DB_site->fetch_array($asb)) {
$linkname = $myrow["linkname"];
$linkurl = $myrow["linkurl"];
$linkimg = $myrow["linkimg"];
$linkdesc = $myrow["linkdesc"];
$linkforum = $myrow["linkforum"];
$linkuserid = $myrow["linkuserid"];
$linkusername = $myrow["linkusername"];
$linkreviewfreq = $myrow["linkreviewfreq"];
$linkstatus = $myrow["linkstatus"];
}
} else {
eval(print_standard_error($vbphrase['ll_error_linkid'].' '.$viewlinkid.' '.$vbphrase['ll_return'].'',0));
exit;
}
// always allow creator to edit, otherwise check permissions
if ($bbuserinfo[userid]<>$linkuserid and (!isset($links_permissions["can_edit_link"]) or !$links_permissions["can_edit_link"])) {
print_no_permission();
exit;
}
$this_navigation_title = $vbphrase['ll_editlink'];
// draw nav bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $vbphrase['ll_links_database'];
if ($viewcatid>0 and isset($linkscat["$viewcatid"])) {
$parentlist = $linkscat["$viewcatid"]["parentlist"];
$parentlist = array_reverse(explode(',', $parentlist));
foreach ($parentlist AS $linkID) {
if ($linkID > 0) {
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$linkID"] = kill_bbcodes($linkscat["$linkID"]["catname"]);
}
}
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$viewcatid"] = kill_bbcodes($linkscat["$viewcatid"]["catname"]);
}
$navbits[""] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
$curforumid = $linkforum;
build_forum_list();
$curforumtitle = iif($curforumid<=0,$vbphrase['ll_none'],$forumcache[$curforumid][title]);
// Build the category list
$pcatid = array();
$asb = $DB_site->query("
SELECT catid FROM ".THIS_TABLE."linksltoc
WHERE linkid=$viewlinkid
");
while ($myrow=$DB_site->fetch_array($asb)) {
$pcatid[] = $myrow["catid"];
}
$optbit = construct_category_list ($pcatid, SELECT_MULTI_CAT, 0, "pcatid[]");
$link_pcatbit = construct_parent_list ($pcatid);
$action = "doeditlink";
$asb = $DB_site->query("
SELECT *
FROM ".THIS_TABLE."linksltoc
WHERE linkid=$viewlinkid AND catid=$viewcatid
LIMIT 1
");
if ($DB_site->num_rows($asb)) {
while ($myrow=$DB_site->fetch_array($asb)) {
$display_order = $myrow["displayorder"];
}
} else {
$display_order = $links_defaults["default_link_dseq"];
}
$instructions = parse_bbcode2($linkscat[$viewcatid]["catinstructions"], $links_defaults['allow_html'], $links_defaults['allow_images'], $links_defaults['allow_smilies'], $links_defaults['allow_bbcode']);
// control which menu items are visible in the header template
$links_permissions["can_add_link"] = 0;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
$pcatid = $viewcatid;
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_addnewlink')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Do (Add) Entry
if ($_REQUEST['action'] == "doaddlink") {
$pcatid = $_REQUEST['pcatid']; // an array ...
$viewcatid = intval($_REQUEST['viewcatid']);
$pforum = intval($_REQUEST['pforum']);
$linkname = $_REQUEST['linkname'];
$linkurl = $_REQUEST['linkurl'];
$linkimg = $_REQUEST['linkimg'];
$linkdesc = $_REQUEST['linkdesc'];
$linkdups = intval($_REQUEST['linkdups']);
$display_order = intval($_REQUEST['display_order']);
$change_display_order = intval($_REQUEST['change_display_order']);
$linkreviewfreq = intval($_REQUEST['linkreviewfreq']);
$linkuser = $_REQUEST['linkuser'];
$url = THIS_SCRIPT.".php?action=links&catid=$viewcatid";
if (!isset($_REQUEST['submit'])) {
eval(print_standard_redirect($vbphrase['ll_abandoned'],0));
exit;
}
if ($pforum<=0) { $pforum = $DEFAULT_FORUMID; };
if ($bbuserinfo['usergroupid'] <= 1) {
if (!is_valid_email($linkuser)) {
$err = $vbphrase['ll_error_email'].' '.$linkuser.'. '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
} else {
$linkuser = $bbuserinfo['username'];
}
if (!forumid_is_valid($pforum)) {
$err = $vbphrase['ll_error_forum'].' '.$pforum.' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if (!is_array($pcatid)) {
$err = $vbphrase['ll_error_catnull'].' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($linkname == '') {
$err = $vbphrase['ll_error_linknull'].' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($linkurl == '' and !$links_defaults["allow_null_links"]) {
$err = $vbphrase['ll_error_urlnull'].' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
} elseif ($linkurl == '') {
$statuscheck = $LINK_OK;
} else {
$statuscheck = check_url($linkurl);
}
if ($statuscheck == $LINK_NO_ACCESS) {
$err = $vbphrase['ll_error_protocol'].' '.$linkurl.'. '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
$statustime = TIMENOW;
if ($links_permissions["can_moderate_links"]) {
$moderate = $LINK_ACCEPTED;
} else {
$moderate = iif($links_defaults["moderate_links"] != '0', $LINK_TO_MODERATE, $LINK_ACCEPTED);
}
list ($insert_status, $linkid) = insert_link ($linkuser, $bbuserinfo['userid'], $linkname, $linkurl, $linkimg, $linkdesc, $pcatid, $pforum, $statuscheck, $moderate, $linkreviewfreq, $linkdups);
if ($insert_status<0) {
$eurl = THIS_SCRIPT.".php?action=editlink&linkid=$linkid&catid=$viewcatid";
$message = $vbphrase['ll_error_linkduplicate'];
if ($is_admin) {
$message .= "
".$vbphrase['ll_edit_original'].'';
}
eval(print_standard_error($message,0));
exit;
}
switch ($change_display_order) {
case 1:
$DB_site->query("
UPDATE ".THIS_TABLE."linksltoc SET
displayorder='".$display_order."'
WHERE linkid='$linkid' AND catid='$viewcatid'
");
break;
case 2:
$DB_site->query("
UPDATE ".THIS_TABLE."linksltoc SET
displayorder='".$display_order."'
WHERE linkid='$linkid'
");
break;
default:
break;
}
if ($moderate != $LINK_TO_MODERATE) {
if ($statuscheck) {
eval(print_standard_redirect($vbphrase['ll_accepted'],0));
} else {
$eurl = THIS_SCRIPT.".php?action=editlink&linkid=$linkid&catid=$viewcatid";
$message = $vbphrase['ll_error_linkcheckfailed']." $linkurl
".
"".$vbphrase['ll_accept']." ".$vbphrase['ll_modify'].''
;
eval(print_standard_error($message,0));
}
} else {
if ($statuscheck) {
eval(print_standard_redirect($vbphrase['ll_submit_moderation'],0));
} else {
$eurl = THIS_SCRIPT.".php?action=editlink&linkid=$linkid&catid=$viewcatid";
$message = $vbphrase['ll_error_linkcheckfailed']." $linkurl
".
"".$vbphrase['ll_accept']." ".$vbphrase['ll_modify'].''
;
eval(print_standard_error($message,0));
}
}
exit;
}
// #################### Do (Edit) Entry
if ($_REQUEST['action'] == "doeditlink") {
$pcatid = $_REQUEST['pcatid']; // an array ...
$viewcatid = intval($_REQUEST['viewcatid']);
$viewlinkid = intval($_REQUEST['viewlinkid']);
$pforum = intval($_REQUEST['pforum']);
$linkname = $_REQUEST['linkname'];
$linkurl = $_REQUEST['linkurl'];
$linkimg = $_REQUEST['linkimg'];
$linkdesc = $_REQUEST['linkdesc'];
$linkmod = intval($_REQUEST['mod']);
if (!isset($_REQUEST['page']) or $_REQUEST['page']=="") $_REQUEST['page'] = '1';
$pagenumber = iif( is_numeric($_REQUEST['page']), $_REQUEST['page'], '1');
$display_order = intval($_REQUEST['display_order']);
$change_display_order = intval($_REQUEST['change_display_order']);
$linkreviewfreq = intval($_REQUEST['linkreviewfreq']);
$linkuser = $_REQUEST['linkuser'];
if ($linkmod == 1) {
$url = THIS_SCRIPT.".php?action=mod";
} else {
$url = THIS_SCRIPT.".php?action=links&catid=$viewcatid&page=$pagenumber";
}
if (isset($_REQUEST['submit'])) {
$submit = "submit";
} elseif (isset($_REQUEST['accept'])) {
$submit = "accept";
} elseif (isset($_REQUEST['delete'])) {
$submit = "delete";
} elseif (isset($_REQUEST['unhide'])) {
$submit = "unhide";
} elseif (isset($_REQUEST['hide'])) {
$submit = "hide";
} else {
eval(print_standard_redirect($vbphrase['ll_abandoned'],0));
exit;
}
if ($viewlinkid == '') {
$err = $vbphrase['ll_error_linkid'].' '.$linkid.' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($bbuserinfo['usergroupid'] <= 1) {
if (!is_valid_email($linkuser)) {
$err = $vbphrase['ll_error_email'].' '.$linkuser.'. '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
} else {
$linkuser = $bbuserinfo['username'];
}
// if ($pforum<=0) { $pforum = $links_defaults["default_forumid"]; };
if ($pforum<=0) { $pforum = $DEFAULT_FORUMID; };
if (!forumid_is_valid($pforum)) {
$err = $vbphrase['ll_error_forum'].' '.$pforum.' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($submit == 'submit' and !is_array($pcatid)) {
$err = $vbphrase['ll_error_catnull'].' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($submit == 'submit' and $linkname == '') {
$err = $vbphrase['ll_error_linknull'].' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($submit == 'submit') {
if ($linkurl == '' and !$links_defaults["allow_null_links"]) {
$err = $vbphrase['ll_error_urlnull'].' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
} elseif ($linkurl == '') {
$statuscheck = $LINK_OK;
} else {
$statuscheck = check_url($linkurl);
}
}
$asb = $DB_site->query("
SELECT * FROM ".THIS_TABLE."linkslink
WHERE linkid=$viewlinkid LIMIT 1
");
if ($DB_site->num_rows($asb)<=0) {
$err = $vbphrase['ll_error_linkid'].' '.$viewlinkid.'. '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
$myrow=$DB_site->fetch_array($asb);
$oldurl = $myrow['linkurl'];
$oldstatus = $myrow['linkstatus'];
$linkdate = $myrow['linkdate'];
$statustime = TIMENOW;
if ($submit == 'submit') {
if ($statuscheck == $LINK_NO_ACCESS) {
$err = $vbphrase['ll_error_protocol'].' '.$linkurl.' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($linkurl <> $oldurl or $linkstatus <> $oldstatus) {
$linkdate = $statustime;
}
$query = "
UPDATE ".THIS_TABLE."linkslink SET
linkname='".addslashes($linkname)."',
linkurl='".addslashes(str_replace('"', '"', $linkurl))."',
linkimg='".addslashes(str_replace('"', '"', $linkimg))."',
linkdesc='".addslashes($linkdesc)."',
linkforum='$pforum',
linkcheck='$statustime',
linkstatus='$statuscheck',
linkdate='$linkdate',
linkreviewfreq='$linkreviewfreq'
WHERE linkid='$viewlinkid'
";
write_debug($query);
$DB_site->query($query);
$DB_site->query("
DELETE FROM ".THIS_TABLE."linksltoc
WHERE linkid='$viewlinkid'
");
foreach ($pcatid as $p) {
$DB_site->query("
INSERT INTO ".THIS_TABLE."linksltoc (linkid, catid)
VALUES ('$viewlinkid', '$p')
");
}
switch ($change_display_order) {
case 1:
$DB_site->query("
UPDATE ".THIS_TABLE."linksltoc SET
displayorder='".$display_order."'
WHERE linkid='$viewlinkid' AND catid='$viewcatid'
");
break;
case 2:
$DB_site->query("
UPDATE ".THIS_TABLE."linksltoc SET
displayorder='".$display_order."'
WHERE linkid='$viewlinkid'
");
break;
default:
break;
}
fix_cat_count();
if ($statuscheck) {
$message = $vbphrase['ll_edited'];
eval(print_standard_redirect($message,0));
} else {
$eurl = THIS_SCRIPT.".php?action=editlink&linkid=$viewlinkid&catid=$viewcatid&page=$pagenumber";
$message = $vbphrase['ll_error_linkcheckfailed']." $linkurl
".
"".$vbphrase['ll_accept']." ".$vbphrase['ll_modify'].''
;
eval(print_standard_error($message,0));
}
}
if ($submit == 'accept') {
$DB_site->query("
UPDATE ".THIS_TABLE."linkslink SET
linkmoderate=$LINK_ACCEPTED,
linkmoddate='$statustime'
WHERE linkid='$viewlinkid'
");
eval(print_standard_redirect($vbphrase['ll_accepted'],0));
}
if ($submit == 'hide') {
$DB_site->query("
UPDATE ".THIS_TABLE."linkslink SET
linkmoderate=$LINK_TO_MODERATE,
linkstatus=$LINK_HIDDEN,
linkmoddate='$statustime'
WHERE linkid='$viewlinkid'
");
eval(print_standard_redirect($vbphrase['ll_hidden'],0));
}
if ($submit == 'unhide') {
$DB_site->query("
UPDATE ".THIS_TABLE."linkslink SET
linkmoderate=$LINK_ACCEPTED,
linkstatus=$LINK_OK,
linkmoddate='$statustime'
WHERE linkid='$viewlinkid'
");
eval(print_standard_redirect($vbphrase['ll_unhidden'],0));
}
if ($submit == 'delete') {
$DB_site->query("
DELETE FROM ".THIS_TABLE."linkslink
WHERE linkid='$viewlinkid'
");
$DB_site->query("
DELETE FROM ".THIS_TABLE."linksltoc
WHERE linkid='$viewlinkid'
");
$DB_site->query("
DELETE FROM ".THIS_TABLE."linksfavs
WHERE linkid='$viewlinkid'
");
fix_cat_count();
eval(print_standard_redirect($vbphrase['ll_deleted'],0));
}
exit;
}
// #################### Do (Rate) Entry
if ($_REQUEST['action'] == "doratelink") {
$viewcatid = intval($_REQUEST['catid']);
$linkid = intval($_REQUEST['id']);
$linkvote = intval($_REQUEST['vote']);
if (!isset($_REQUEST['page']) or $_REQUEST['page']=="") $_REQUEST['page'] = '1';
$pagenumber = iif( is_numeric($_REQUEST['page']), $_REQUEST['page'], '1');
$url = THIS_SCRIPT.".php?action=links&catid=$viewcatid&page=$pagenumber";
if ($linkvote < 0) {
if (isset($links_permissions["can_admin_links"])) {
$DB_site->query("
DELETE FROM ".THIS_TABLE."linksrate
WHERE linkid='$linkid'
");
eval(print_standard_redirect($vbphrase['ll_rating_cleared'],0));
} else {
print_no_permission();
}
exit;
}
if (!isset($links_permissions["can_rate_link"]) or !$links_permissions["can_rate_link"]) {
print_no_permission();
exit;
}
if ($linkvote<$MIN_VOTE or $linkvote>$MAX_VOTE) {
eval(print_standard_redirect('Invalid rating.',0));
exit;
}
$DB_site->query("
DELETE FROM ".THIS_TABLE."linksrate
WHERE linkid='$linkid' AND linkuserid='$bbuserinfo[userid]'
");
$DB_site->query("
INSERT INTO ".THIS_TABLE."linksrate (linkid, linkuserid, linkvote)
VALUES (
'$linkid',
$bbuserinfo[userid],
'$linkvote'
)
");
eval(print_standard_redirect($vbphrase['ll_rating_recorded'],0));
exit;
}
// #################### Do Add/Remove Favourite
if ($_REQUEST['action'] == "dofavlink") {
$viewcatid = intval($_REQUEST['catid']);
$linkid = intval($_REQUEST['id']);
$linkset = intval($_REQUEST['set']);
if (!isset($_REQUEST['page']) or $_REQUEST['page']=="") $_REQUEST['page'] = '1';
$pagenumber = iif( is_numeric($_REQUEST['page']), $_REQUEST['page'], '1');
$url = THIS_SCRIPT.".php?action=links&catid=$viewcatid&page=$pagenumber";
if ($linkset < 0) {
$DB_site->query("
DELETE FROM ".THIS_TABLE."linksfavs
WHERE linkid='".$linkid."' AND userid='".$bbuserinfo['userid']."'
");
eval(print_standard_redirect($vbphrase['ll_myfav_deleted'],0));
exit;
}
if (!isset($links_permissions["can_mark_link"]) or !$links_permissions["can_mark_link"]) {
print_no_permission();
exit;
}
$DB_site->query("
DELETE FROM ".THIS_TABLE."linksfavs
WHERE linkid='".$linkid."' AND userid='".$bbuserinfo[userid]."'
");
$DB_site->query("
INSERT INTO ".THIS_TABLE."linksfavs (linkid, userid)
VALUES (
'".$linkid."',
'".$bbuserinfo[userid]."'
)
");
eval(print_standard_redirect($vbphrase['ll_myfav_added'],0));
exit;
}
// #################### Add Category
if ($_REQUEST['action'] == "addcat") {
$catmod = 0;
if (!isset($links_permissions["can_add_category"]) or !$links_permissions["can_add_category"]) {
print_no_permission();
exit;
}
if (!isset($_REQUEST['catid']) or $_REQUEST['catid']=="") {
$_REQUEST['catid'] = $BASE_CAT;
}
if (!isset($links_defaults["default_forumid"]) or
!forumid_is_valid($links_defaults["default_forumid"])
) {
eval(print_standard_error($vbphrase['ll_error_noforum'].' '.$vbphrase['ll_return'].'',0));
exit;
}
$forum = $curforumid = $links_defaults["default_forumid"];
$this_navigation_title = $vbphrase['ll_addcat'];
build_forum_list();
$curforumtitle = iif($curforumid<=0,$vbphrase['ll_none'],$forumcache[$curforumid][title]);
$pcatid = array();
$pcatid[0] = intval($_REQUEST['catid']);
$optbit = construct_category_list($pcatid, SELECT_ONE_CAT, 1, "pcatid");
$display_order = $links_defaults["default_cat_dseq"];
// draw nav bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $vbphrase['ll_links_database'];
if ($pcatid[0]>0 and isset($linkscat[$pcatid[0]])) {
$parentlist = $linkscat[$pcatid[0]]["parentlist"];
$parentlist = array_reverse(explode(',', $parentlist));
foreach ($parentlist AS $linkID) {
if ($linkID > 0) {
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$linkID"] = kill_bbcodes($linkscat["$linkID"]["catname"]);
}
}
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=".$pcatid[0]] = kill_bbcodes($linkscat[$pcatid[0]]["catname"]);
}
$navbits[""] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
$action = "doaddcat";
$viewcatid = $BASE_CAT;
$catname = "";
$catdesc = "";
$cattext = "";
$catinstructions = "";
$catforumlink = 0;
$forumname = $catname;
// this code controls which menu items are visible in the header template
$links_permissions["can_add_link"] = 0;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
$links_permissions["can_delete_category"] = 0;
$pcatid = $pcatid[0];
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_addnewcat')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Edit Category
if ($_REQUEST['action'] == "editcat") {
$catmod = $_REQUEST['mod']; // may be moderating
if ($catmod != 1) $catmod = 0;
$viewcatid = intval($_REQUEST['catid']);
$pcatid = array();
if (!isset($linkscat[$viewcatid])) {
eval(print_standard_error($vbphrase['ll_error_category'].' '.$viewcatid.' '.$vbphrase['ll_return'].'',0));
exit;
}
$catname = $linkscat[$viewcatid]["catname"];
$catdesc = $linkscat[$viewcatid]["catdesc"];
$cattext = $linkscat[$viewcatid]["cattext"];
$pcatid[0] = $linkscat[$viewcatid]["parentid"];
$forum = $linkscat[$viewcatid]["catforum"];
$catuserid = $linkscat[$viewcatid]["userid"];
$catusername = $linkscat[$viewcatid]["username"];
$catinstructions = $linkscat[$viewcatid]["catinstructions"];
$catforumlink = $linkscat[$viewcatid]["catforumlink"];
$forumname = $catname;
// always allow the category creator to edit, otherwise check usergroup permissions
if ($bbuserinfo[userid]<>$catuserid and (!isset($links_permissions["can_edit_category"]) or !$links_permissions["can_edit_category"])) {
print_no_permission();
exit;
}
$this_navigation_title = $vbphrase['ll_editcat'];
$display_order = $linkscat[$viewcatid]["displayorder"];
// draw nav bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $vbphrase['ll_links_database'];
if ($viewcatid>0 and isset($linkscat["$viewcatid"])) {
$parentlist = $linkscat["$viewcatid"]["parentlist"];
$parentlist = array_reverse(explode(',', $parentlist));
foreach ($parentlist AS $linkID) {
if ($linkID > 0) {
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$linkID"] = kill_bbcodes($linkscat["$linkID"]["catname"]);
}
}
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$viewcatid"] = kill_bbcodes($linkscat["$viewcatid"]["catname"]);
}
$navbits[""] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
$curforumid = $forum;
build_forum_list();
$curforumtitle = iif($curforumid<=0,$vbphrase['ll_none'],$forumcache[$curforumid][title]);
$optbit = construct_category_list($pcatid, SELECT_ONE_CAT, 1, "pcatid");
$action = "doeditcat";
// this code controls which menu items are visible in the header template
$links_permissions["can_add_link"] = 0;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
$pcatid = $pcatid[0];
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_addnewcat')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Mass Edit Category
if ($_REQUEST['action'] == "massedit") {
if (!$links_permissions["can_admin_links"]) {
print_no_permission();
exit;
}
$url = ADMIN_SCRIPT.".php?action=admin&set=categories";
if (isset($_REQUEST['catid']) and $_REQUEST['catid']!="") {
$catid = intval($_REQUEST['catid']);
if (!isset($linkscat[$catid]['catid'])) {
eval(print_standard_redirect($vbphrase['ll_error_category'].' '.$catid,0));
exit;
}
$forumid = $curforumid = $linkscat[$catid]['catforum'];
$selectby = 0;
} elseif (isset($_REQUEST['forumid']) and $_REQUEST['forumid']!="") {
$catid = $BASE_CAT;
$forumid = $curforumid = intval($_REQUEST['forumid']);
$selectby = 1;
} else {
eval(print_standard_redirect($vbphrase['ll_error_catnull'],0));
exit;
}
$this_navigation_title = $vbphrase['ll_admin_masseditcat'];
build_forum_list();
$curforumtitle = iif($curforumid<=0,$vbphrase['ll_none'],iif(forumid_is_valid($curforumid),$forumcache[$curforumid]['title'],$curforumid));
$catname = iif (isset($_REQUEST['catid']), $vbphrase['ll_cat'].' '.$linkscat[$catid]['catname'],
$vbphrase['ll_admin_masseditforum'] . ' ' . iif($forumid>0,$forumcache[$curforumid]['title'],$vbphrase['ll_forumdefault']));
$optbit = construct_category_list(array($catid), SELECT_ONE_CAT, 0, "pcatid");
// draw nav bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $vbphrase['ll_links_database'];
$parentlist = $linkscat[$catid["parentlist"]];
$parentlist = array_reverse(explode(',', $parentlist));
foreach ($parentlist AS $linkID) {
if ($linkID > 0) {
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=$linkID"] = kill_bbcodes($linkscat["$linkID"]["catname"]);
}
}
$navbits[THIS_SCRIPT.".php?$session[sessionurl]catid=".$catid] = kill_bbcodes($linkscat[$catid]["catname"]);
$navbits[""] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// this code controls which menu items are visible in the header template
$links_permissions["can_add_link"] = 0;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
$links_permissions["can_delete_category"] = 0;
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_massedit')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// #################### Do (Add) Category
if ($_REQUEST['action'] == "doaddcat") {
$pcatid = intval($_REQUEST['pcatid']); // NB - single value
$catname = $_REQUEST['catname'];
$catdesc = $_REQUEST['catdesc'];
$cattext = $_REQUEST['cattext'];
$catinstructions = $_REQUEST['catinstructions'];
$display_order = intval($_REQUEST['display_order']);
$pforum = intval($_REQUEST['pforum']);
$auto_forumlink = iif(isset($_REQUEST['auto_forumlink']), intval($_REQUEST['auto_forumlink']), 0);
$forumname = iif(isset($_REQUEST['forumname']), $_REQUEST['forumname'], $catname);
$url = THIS_SCRIPT.".php?action=links&catid=$pcatid";
if (!isset($_REQUEST['submit'])) {
eval(print_standard_redirect($vbphrase['ll_abandoned'],0));
exit;
}
if ($pcatid > 0) {
if (isset($linkscat[$pcatid]['catid'])) {
$pcatlist = "$pcatid,".$linkscat[$pcatid]["parentlist"];
} else {
$url = THIS_SCRIPT.".php?action=links";
eval(print_standard_error($vbphrase['ll_error_category'].' '.$pcatid.' '.$vbphrase['ll_return'].'',0));
}
} elseif ($pcatid == $BASE_CAT) {
$pcatlist = $pcatid;
} else {
$url = THIS_SCRIPT.".php?action=links";
eval(print_standard_error($vbphrase['ll_error_pcatnull'].' '.$vbphrase['ll_return'].'',0));
}
if ($catname == ''){
eval(print_standard_error($vbphrase['ll_error_catnull'].' '.$vbphrase['ll_return'].'',0));
exit;
}
// if ($pforum<=0) { $pforum = $links_defaults["default_forumid"]; };
if ($pforum<=0) { $pforum = $DEFAULT_FORUMID; };
if (!forumid_is_valid($pforum)) {
eval(print_standard_error($vbphrase['ll_error_forum'].' '.$pforum.' '.$vbphrase['ll_return'].'',0));
exit;
}
if ($pforum<-0 and $auto_forumlink==1) {
eval(print_standard_error($vbphrase['ll_error_forumlink'].' '.$vbphrase['ll_return'].'',0));
exit;
}
if ($cattext == '') {
$cattext = $catdesc;
}
if ($links_permissions["can_moderate_links"]) {
$moderate = $LINK_ACCEPTED;
} else {
$moderate = iif($links_defaults["moderate_links"] != '0', $LINK_TO_MODERATE, $LINK_ACCEPTED);
}
$DB_site->query("
INSERT INTO ".THIS_TABLE."linkscat (catname, catdesc, cattext, parentid, parentlist, catforum, catusername, catuserid, catentry, catdate, catmoderate, catinstructions, displayorder)
VALUES (
'".addslashes($catname)."',
'".addslashes($catdesc)."',
'".addslashes($cattext)."',
'$pcatid',
'$pcatlist',
'$pforum',
'".addslashes(htmlspecialchars($bbuserinfo[username]))."',
$bbuserinfo[userid],
0,
0,
$moderate,
'".addslashes($catinstructions)."',
$display_order
)
");
$catid = $DB_site->insert_id();
fix_cat_count();
insert_category_in_forum($catid, $pforum, $auto_forumlink, $forumname);
$url = THIS_SCRIPT.".php?action=links&catid=$catid";
eval(print_standard_redirect($vbphrase['ll_accepted'],0));
exit;
}
// #################### Do (Edit) Category
if ($_REQUEST['action'] == "doeditcat") {
$pcatid = intval($_REQUEST['pcatid']);
$catid = intval($_REQUEST['catid']);
$catname = $_REQUEST['catname'];
$catdesc = $_REQUEST['catdesc'];
$cattext = $_REQUEST['cattext'];
$catinstructions = $_REQUEST['catinstructions'];
$display_order = intval($_REQUEST['display_order']);
$auto_forumlink = iif(isset($_REQUEST['auto_forumlink']), intval($_REQUEST['auto_forumlink']), 0);
$forumname = iif(isset($_REQUEST['forumname']), $_REQUEST['forumname'], $catname);
$pforum = intval($_REQUEST['pforum']);
$submit = $_REQUEST['submit'];
$catmod = intval($_REQUEST['mod']);
$force_permissions = iif(($links_permissions[can_set_permissions] and isset($_REQUEST['force_permissions'])),
intval($_REQUEST['force_permissions']),0);
if ($catmod == 1) {
$url = THIS_SCRIPT.".php?action=mod";
} else {
$url = THIS_SCRIPT.".php?action=links&catid=$pcatid";
}
if (isset($_REQUEST['submit'])) {
$submit = "submit";
} elseif (isset($_REQUEST['accept'])) {
$submit = "accept";
} elseif (isset($_REQUEST['delete'])) {
$submit = "delete";
} elseif (isset($_REQUEST['open']) and $_REQUEST['open']==0) {
$submit = "close";
} elseif (isset($_REQUEST['open']) and $_REQUEST['open']==1) {
$submit = "open";
} else {
eval(print_standard_redirect($vbphrase['ll_abandoned'],0));
exit;
}
if ($catid == '' or !isset($linkscat[$catid])) {
eval(print_standard_error($vbphrase['ll_error_category'].' '.$catid.' '.$vbphrase['ll_return'].'',0));
exit;
}
if ($submit == 'submit') {
// if ($pforum<=0) { $pforum = $links_defaults["default_forumid"]; };
if ($pforum<=0) { $pforum = $DEFAULT_FORUMID; };
if (!forumid_is_valid($pforum)) {
$err = $vbphrase['ll_error_forum'].' '.$pforum.' '.$vbphrase['ll_return'].'';
eval(print_standard_error($err,0));
exit;
}
if ($catname == ''){
eval(print_standard_error($vbphrase['ll_error_catnull'].' '.$vbphrase['ll_return'].'',0));
exit;
}
if ($cattext == '') $cattext = $catdesc;
if ($pcatid > 0) {
if (isset($linkscat[$pcatid])) {
if ($catid == $pcatid or in_array($catid, explode(",", $linkscat[$pcatid]["parentlist"]))) {
eval(print_standard_error($vbphrase['ll_error_catrecurse'].' '.$vbphrase['ll_return'].'',0));
exit;
}
$pcatlist = "$pcatid,".$linkscat[$pcatid]["parentlist"];
} else {
$url = THIS_SCRIPT.".php?action=links";
eval(print_standard_error($vbphrase['ll_error_category'].' '.$pcatid.' '.$vbphrase['ll_return'].'',0));
}
} elseif ($pcatid == $BASE_CAT) {
$pcatlist = $pcatid;
} else {
$url = THIS_SCRIPT.".php?action=links";
eval(print_standard_error($vbphrase['ll_error_pcatnull'].' '.$vbphrase['ll_return'].'',0));
}
if ($pforum<=0 and $auto_forumlink==1) {
eval(print_standard_error($vbphrase['ll_error_forumlink'].' '.$vbphrase['ll_return'].'',0));
exit;
}
insert_category_in_forum($catid, $pforum, $auto_forumlink, $forumname);
$DB_site->query("
UPDATE ".THIS_TABLE."linkscat SET
catid='$catid',
catname='".addslashes($catname)."',
catdesc='".addslashes($catdesc)."',
cattext='".addslashes($cattext)."',
parentid='$pcatid',
parentlist='$pcatlist',
catforum='$pforum',
catinstructions='".addslashes($catinstructions)."',
displayorder='$display_order'
WHERE catid='$catid'
");
fix_cat_parentlist();
fix_cat_count();
if ($force_permissions == 1) {
$asb = $DB_site->query("
SELECT DISTINCT link.linkid AS linkid
FROM ".THIS_TABLE."linkslink AS link
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
ON link.linkid = ltoc.linkid
WHERE ltoc.catid='$catid'
");
if ($DB_site->num_rows($asb)>0) {
$linkidlist = array();
while ($myrow=$DB_site->fetch_array($asb)) {
$linkidlist[] = $myrow["linkid"];
}
$linkidlist = implode(',', $linkidlist);
$query = "
UPDATE ".THIS_TABLE."linkslink SET
linkforum='$pforum'
WHERE linkid IN($linkidlist)
";
$DB_site->query($query);
}
}
if ($catmod != 1) $url = THIS_SCRIPT.".php?action=links&catid=$catid";
eval(print_standard_redirect($vbphrase['ll_edited'],0));
}
if ($submit == 'accept') {
$DB_site->query("
UPDATE ".THIS_TABLE."linkscat SET
catmoderate=$LINK_ACCEPTED
WHERE catid='$catid'
");
eval(print_standard_redirect('Entry accepted.',0));
}
if ($submit == 'open') {
if (!isset($links_permissions["can_admin_links"]) or !$links_permissions["can_admin_links"]) {
print_no_permission();
exit;
}
$DB_site->query("
UPDATE ".THIS_TABLE."linkscat SET
catclosed=0
WHERE catid='$catid'
");
$url = ADMIN_SCRIPT.".php?action=admin&set=categories";
eval(print_standard_redirect($vbphrase['ll_catopen'],0));
}
if ($submit == 'close') {
if (!isset($links_permissions["can_admin_links"]) or !$links_permissions["can_admin_links"]) {
print_no_permission();
exit;
}
$DB_site->query("
UPDATE ".THIS_TABLE."linkscat SET
catclosed=1
WHERE catid='$catid'
");
$url = ADMIN_SCRIPT.".php?action=admin&set=categories";
eval(print_standard_redirect($vbphrase['ll_catclosed'],0));
}
if ($submit == 'delete') {
$hasentries = 0;
foreach ($linkscat as $thiscat) {
if ($thiscat["parentid"] == $catid) {
$hasentries = 1;
break;
}
}
if (!$hasentries) {
$asb = $DB_site->query("
SELECT * FROM ".THIS_TABLE."linksltoc
WHERE catid='$catid'
");
$hasentries = $DB_site->num_rows($asb);
}
if ($hasentries) {
eval(print_standard_error('Invalid delete - category '.$catid.' still contains links/subcategories. '.$vbphrase['ll_return'].'',0));
} else {
insert_category_in_forum($catid, $linkscat[$catid]['catforumlink'], -1);
$DB_site->query("
DELETE FROM ".THIS_TABLE."linkscat
WHERE catid='$catid'
");
eval(print_standard_redirect($vbphrase['ll_deleted'],0));
}
}
exit;
}
// #################### Do (Mass Edit) Links
if ($_REQUEST['action'] == "domassedit") {
if (!$links_permissions["can_admin_links"]) {
print_no_permission();
exit;
}
$url = ADMIN_SCRIPT.".php?action=admin&set=categories";
if (!isset($_REQUEST['submit'])) {
eval(print_standard_redirect($vbphrase['ll_abandoned'],0));
exit;
}
if (!isset($_REQUEST['select']) or $_REQUEST['select']<0 or $_REQUEST['select']>1) {
eval(print_standard_redirect($vbphrase['ll_abandoned'],0));
exit;
}
$selectby = intval($_REQUEST['select']); // 0=mass edit by catid; 1=mass edit by forumid
$forumid = intval($_REQUEST['forumid']);
if ($selectby==0 and (!isset($_REQUEST['catid']) or !isset($linkscat[$_REQUEST['catid']]['catid']))) {
eval(print_standard_error($vbphrase['ll_error_category'].' '.$_REQUEST['catid'].
' '.$vbphrase['ll_return'].'',0));
exit;
}
$catid = intval($_REQUEST['catid']);
if (isset($_REQUEST['force_cat']) and intval($_REQUEST['force_cat'])!=0) {
$pcatid = intval($_REQUEST['pcatid']);
if (!$_REQUEST['pcatid'] or !isset($linkscat[$pcatid])) {
eval(print_standard_error($vbphrase['ll_error_category'].' '.$pcatid.
' '.$vbphrase['ll_return'].'',0));
}
if ($selectby == 0) { // By category
if ($catid!=$pcatid) {
$query = "
UPDATE ".THIS_TABLE."linksltoc SET
catid='".$pcatid."'
WHERE catid='".$catid."'
";
$DB_site->query($query);
}
} else { // By forum
$query = "
UPDATE ".THIS_TABLE."linkslink AS link,
".THIS_TABLE."linksltoc AS ltoc
SET
ltoc.catid='".$pcatid."'
WHERE
link.linkid=ltoc.linkid AND link.linkforum='".$forumid."'
";
$DB_site->query($query);
}
fix_cat_count();
}
if (isset($_REQUEST['force_forum']) and intval($_REQUEST['force_forum'])!=0) {
$pforum = intval($_REQUEST['pforum']);
if (!isset($_REQUEST['pforum']) or !forumid_is_valid($pforum)) {
eval(print_standard_error($vbphrase['ll_error_forum'].' '.$pforum.
' '.$vbphrase['ll_return'].'',0));
exit;
}
if ($selectby == 0) { // By category
$query = "
UPDATE ".THIS_TABLE."linkslink AS link,
".THIS_TABLE."linksltoc AS ltoc
SET
link.linkforum='".$pforum."'
WHERE
link.linkid=ltoc.linkid AND ltoc.catid='".$catid."'
";
$DB_site->query($query);
} else { // By forum
$query = "
UPDATE ".THIS_TABLE."linkslink
SET
linkforum='".$pforum."'
WHERE
linkforum='".$forumid."'
";
$DB_site->query($query);
}
}
if (isset($_REQUEST['force_hide']) and (intval($_REQUEST['force_hide'])==$LINK_HIDDEN or intval($_REQUEST['force_hide'])==$LINK_OK)) {
$hide = intval($_REQUEST['force_hide']);
$mod = iif($hide==$LINK_HIDDEN,$LINK_TO_MODERATE,$LINK_ACCEPTED);
$statustime = TIMENOW;
if ($selectby == 0) { // By category
$query = "
UPDATE ".THIS_TABLE."linkslink AS link,
".THIS_TABLE."linksltoc AS ltoc
SET
link.linkmoderate='".$mod."',
link.linkstatus='".$hide."',
link.linkmoddate='".$statustime."'
WHERE
link.linkid=ltoc.linkid AND ltoc.catid='".$catid."'
";
$DB_site->query($query);
} else { // By forum
$query = "
UPDATE ".THIS_TABLE."linkslink
SET
linkmoderate='".$mod."',
linkstatus='".$hide."',
linkmoddate='".$statustime."'
WHERE
linkforum='".$forumid."'
";
$DB_site->query($query);
}
}
eval(print_standard_redirect($vbphrase['ll_accepted'],0));
exit;
}
// #################### Play link in an embedded media player
if ($_REQUEST['action'] == "play") {
if (!$links_permissions["can_play_musicbox"]) {
print_no_permission();
exit;
}
if (isset($_REQUEST['id'])) {
$linkid = intval($_REQUEST['id']);
$jumplink = $DB_site->query("
SELECT linkurl, linkforum, linkstatus FROM ".THIS_TABLE."linkslink
WHERE linkid='$linkid'
LIMIT 1
");
unset($url);
while ($jump=$DB_site->fetch_array($jumplink)) {
$url = $jump['linkurl'];
$linkforum = $jump['linkforum'];
$linkstatus = $jump['linkstatus'];
}
if (!isset($url)) {
eval(print_standard_error($vbphrase['ll_error_linkid'].' '.$id,0));
exit;
}
} else {
eval(print_standard_error($vbphrase['ll_error_nolinkid'],0));
exit;
}
if (!forumid_is_valid($linkforum)) {
$DB_site->query("
UPDATE ".THIS_TABLE."linkslink
SET linkstatus=$LINK_NO_ACCESS, linkcheck=$time
WHERE linkid='$linkid'
LIMIT 1
");
eval(print_standard_error($vbphrase['ll_error_unknownaccess']." $linkid, $linkforum" ,0));
exit;
} elseif ($linkforum > 0) {
// fetch the permissions for this forum
$forumperms = fetch_permissions($linkforum);
if (!($forumperms & CANVIEW) || !($forumperms & CANVIEWOTHERS)) {
print_no_permission();
exit;
}
}
$this_navigation_title = $vbphrase['ll_links_jukebox'];
eval("\$output .= \"".fetch_template('links_play')."\";");
print_output($output);
exit;
}
// #################### Send email to friend
if ($_REQUEST['action'] == "sendtofriend") {
if (!$links_permissions["can_send_tofriend"]) {
eval(print_standard_error($vbphrase['ll_error_nosend'],0));
exit;
}
if (isset($_REQUEST['id'])) {
$id = intval($_REQUEST['id']);
$jumplink = $DB_site->query("
SELECT linkforum, linkname, linkdesc FROM ".THIS_TABLE."linkslink
WHERE linkid='$id'
LIMIT 1
");
unset($linkname);
while ($jump=$DB_site->fetch_array($jumplink)) {
$linkforum = $jump['linkforum'];
$linkname = $jump['linkname'];
$linkdesc = $jump['linkdesc'];
}
if (!isset($linkname)) {
eval(print_standard_error($vbphrase['ll_error_linkid'].' '.$id,0));
exit;
}
} else {
eval(print_standard_error($vbphrase['ll_error_nolinkid'],0));
exit;
}
if (!forumid_is_valid($linkforum)) {
$DB_site->query("
UPDATE ".THIS_TABLE."linkslink
SET linkstatus=$LINK_NO_ACCESS, linkcheck=$time
WHERE linkid='$id'
LIMIT 1
");
eval(print_standard_error($vbphrase['ll_error_unknownaccess']." $id, $linkforum",0));
exit;
} elseif ($linkforum > 0) {
// fetch the permissions for this forum
$forumperms = fetch_permissions($linkforum);
if (!($forumperms & CANVIEW) || !($forumperms & CANVIEWOTHERS)) {
print_no_permission();
exit;
}
}
$this_navigation_title = $vbphrase['ll_links_database'];
build_forum_list();
$title = $linkname;
$message = $vbphrase['ll_seethis']."\r\n\r\n"
. $vboptions[bburl].'/'.THIS_SCRIPT.'.php?action=jump&id='.$id
. "\r\n\r\n" .$linkdesc;
// Make Links Nav Bar
$navbits = array();
$navbits[THIS_SCRIPT.".php?$session[sessionurl]"] = $this_navigation_title;
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
// this code controls which menu items are visible in the header template
$viewcatid = -2;
$links_permissions["can_add_link"] = 0;
$links_permissions["can_add_category"] = 0;
$links_permissions["can_edit_category"] = 0;
eval("\$output = \"".fetch_template('links_header')."\";");
eval("\$output .= \"".fetch_template('links_sendemail')."\";");
eval("\$output .= \"".fetch_template('links_footer')."\";");
print_output($output);
exit;
}
// ############################### start do send to friend ###############################
if ($_REQUEST['action'] == 'dosendtofriend')
{
globalize($_REQUEST , array('sendtoname', 'sendtoemail', 'emailsubject', 'emailmessage'));
if (empty($sendtoname) OR !is_valid_email($sendtoemail) OR empty($emailsubject) OR empty($emailmessage))
{
eval(print_standard_error('error_requiredfields'));
}
$postusername = $bbuserinfo['username'];
eval(fetch_email_phrases('sendtofriend'));
vbmail($sendtoemail, $emailsubject, $message);
$DB_site->query("UPDATE " . TABLE_PREFIX . "user SET emailstamp = " . TIMENOW . " WHERE userid=$bbuserinfo[userid]");
$sendtoname = htmlspecialchars_uni($sendtoname);
eval("\$output .= \"".fetch_template('links_emailsent')."\";");
print_output($output);
exit;
}
// #################### Jump to link - open/download
function record_hit($id, $url, $status) {
global $DB_site, $bbuserinfo, $links_permissions;
if ($links_permissions["can_bypass_hit_recording"]) return;
$userip = iif (isset($_SERVER[REMOTE_ADDR]), $_SERVER[REMOTE_ADDR], 'unknown');
$userbrowser = iif (isset($_SERVER[HTTP_USER_AGENT]), $_SERVER[HTTP_USER_AGENT], 'unknown');
$username = $bbuserinfo[username];
$userid = $bbuserinfo[userid];
// Avoid double hits
$time = TIMENOW;
if ($links_defaults["timeout_hit_recording"]>0) {
$timeout = $time - $links_defaults["timeout_hit_recording"];
$jumplink = $DB_site->query("
SELECT * FROM ".THIS_TABLE."linksdownloads
WHERE linkid='$id' AND userid='$userid' AND usertime>'$timeout'
LIMIT 1
");
if ($DB_site->num_rows($jumplink)>0) return(-1);
}
$DB_site->query("
UPDATE ".THIS_TABLE."linkslink
SET linkhits=linkhits+1, linkstatus=$status
WHERE linkid='$id'
LIMIT 1
");
$DB_site->query("
INSERT INTO ".THIS_TABLE."linksdownloads (linkid, linkurl, username, userid, userip, userbrowser, usertime)
VALUES (
'".intval($id)."',
'".addslashes($url)."',
'".addslashes(htmlspecialchars($username))."',
'".$userid."',
'".$userip."',
'".addslashes(htmlspecialchars($userbrowser))."',
$time
)
");
return(0);
}
if ($_REQUEST['action'] == "stream") {
if (!$links_permissions["can_play_musicbox"]) {
print_no_permission();
exit;
}
}
if ($_REQUEST['action'] == "jump" or $_REQUEST['action'] == "stream") {
$time = TIMENOW;
unset($url);
// Prevent multiple hits within specified timeout
if ($links_defaults["timeout_hit_allow"]>0) {
$timeout = $time - $links_defaults["timeout_hit_allow"];
$jumplink = $DB_site->query("
SELECT userid, usertime FROM ".THIS_TABLE."linksdownloads
WHERE userid='".$bbuserinfo[userid]."'
ORDER BY usertime DESC
LIMIT 1
");
while ($jump=$DB_site->fetch_array($jumplink)) {
if ($jump['usertime'] > $timeout) {
eval(print_standard_error($vbphrase['ll_wait'].' '.$links_defaults["timeout_hit_allow"],0));
exit;
}
}
}
if (isset($_REQUEST['link'])) {
$link = preg_replace("/(['\"]*)(.*)\\1/", "\\2", $_REQUEST['link']);
if (preg_match("/(.*)\/(.*)/", $link, $match)) {
$lname = addslashes($match[2]);
$cname = addslashes($match[1]);
} else {
$lname = addslashes($link);
$cname = "%";
}
$jumplink = $DB_site->query("
SELECT link.linkid AS linkid, link.linkname AS linkname,
link.linkurl AS linkurl, link.linkforum AS linkforum, link.linkstatus AS linkstatus,
cat.catname AS catname
FROM ".THIS_TABLE."linkslink AS link
LEFT JOIN ".THIS_TABLE."linksltoc AS ltoc
ON link.linkid = ltoc.linkid
LEFT JOIN ".THIS_TABLE."linkscat AS cat
ON ltoc.catid = cat.catid
WHERE link.linkname LIKE '$lname' AND cat.catname LIKE '$cname'
LIMIT 1
");
while ($jump=$DB_site->fetch_array($jumplink)) {
$url = $jump['linkurl'];
$linkid = $jump['linkid'];
$linkforum = $jump['linkforum'];
$linkstatus = $jump['linkstatus'];
}
if (!isset($url)) {
eval(print_standard_error($vbphrase['ll_error_linkid'].' '.$lname.'/'.$cname,0));
exit;
}
} elseif (isset($_REQUEST['id'])) {
$id = intval($_REQUEST['id']);
$jumplink = $DB_site->query("
SELECT linkurl, linkforum, linkstatus FROM ".THIS_TABLE."linkslink
WHERE linkid='$id'
LIMIT 1
");
while ($jump=$DB_site->fetch_array($jumplink)) {
$url = $jump['linkurl'];
$linkforum = $jump['linkforum'];
$linkstatus = $jump['linkstatus'];
}
if (!isset($url)) {
eval(print_standard_error($vbphrase['ll_error_linkid'].' '.$id,0));
exit;
}
} else {
eval(print_standard_error($vbphrase['ll_error_nolinkid'],0));
exit;
}
if (!forumid_is_valid($linkforum)) {
$DB_site->query("
UPDATE ".THIS_TABLE."linkslink
SET linkstatus=$LINK_NO_ACCESS, linkcheck=$time
WHERE linkid='$id'
LIMIT 1
");
eval(print_standard_error($vbphrase['ll_error_unknownaccess']." $id, $linkforum",0));
exit;
} elseif ($linkforum > 0) {
// fetch the permissions for this forum
$forumperms = fetch_permissions($linkforum);
if (!($forumperms & CANVIEW) || !($forumperms & CANVIEWOTHERS)) {
print_no_permission();
exit;
}
}
$urlInfo = parse_url($url);
if ($urlInfo['scheme'] != "" and !in_array($urlInfo['scheme'], $schemes)) {
$hit = record_hit($id, $url, $LINK_BROKEN);
eval(print_standard_error($vbphrase['ll_error_protocol'].' '.$urlInfo['scheme'],0));
exit;
}
$dfname = basename($urlInfo['path']);
$type = substr(strrchr($dfname, "."), 1);
$mimetype = get_mimetype($type);
if ($links_defaults["force_redirect"]==1 or !is_array($mimetype) or $urlInfo['query'] != "") {
// force redirect mode or not a known mimetype or a qualified mimetype (a la Sourceforge)
// access as a regular link
write_debug("jump($url) begin redirect");
$hit = record_hit($id, $url, $LINK_OK);
eval(print_standard_redirect($vbphrase['ll_redirect'],0));
} else {
// mimetype found so assume this is a file to be downloaded
// guard against allow_url_fopen being turned off
if (!ini_get('allow_url_fopen')) {
eval(print_standard_error($vbphrase['ll_error_dldisable'],0));
exit;
}
$file = cleanto_fopen($url);
$conn = @fopen($file, "rb");
if (!$conn) {
write_debug("jump($url) open $file fails");
$hit = record_hit($id, $url, $LINK_BROKEN);
eval(print_standard_error($vbphrase['ll_error_linknotavail'],0));
exit;
} else {
write_debug("jump($url) begin transfer");
ini_set('zlib.output_compression', 'Off');
if ($_REQUEST['action'] == "jump") {
exec_nocache_headers();
if (HEADER_BEHAVIOUR == "inline") {
header("Content-disposition: inline; filename=\"$dfname\"");
} else {
header("Content-type: application/x-download");
header("Content-disposition: attachment; filename=\"$dfname\"");
}
if ($type != 'txt') {
header('Content-transfer-encoding: binary');
}
if ($linkstatus > 1) {
header("Accept-Ranges: bytes");
header("Content-Length: $linkstatus");
}
foreach ($mimetype AS $index => $header) {
header($header);
}
}
$bytes = 0;
while ($contents = fread ($conn, $READ_BUFFER_SIZE)) {
echo $contents;
$bytes += strlen($contents);
}
flush();
fclose($conn);
if ($bytes==0) $bytes=$LINK_OK;
$hit = record_hit($id, $url, $bytes);
write_debug("jump($url) open $file ok, $bytes read");
}
}
exit;
}
// Default fall through
$url = THIS_SCRIPT.".php?action=links";
eval(print_standard_redirect('Unknown action requested',0));
exit;
?>