$val) $_POST[$key] = addslashes($val); foreach ($_GET as $key => $val) $_GET[$key] = addslashes($val); foreach ($_REQUEST as $key => $val) $_REQUEST[$key] = addslashes($val); foreach ($_COOKIE as $key => $val) $_COOKIE[$key] = addslashes($val); } $logged_in = 0; // check and perform login if ($action == 'Login') { $q = "SELECT * FROM lh_user WHERE username = '$_POST[username]'"; $r = mysql_query($q) or die(mysql_error()); $d = mysql_fetch_array($r); if (!($_POST['pass'] == $d['pass'] && strlen($_POST['pass']) > 0)) { $login_error = "Incorrect login."; } else { setcookie("username",$d['username']); setcookie("pass",$d['pass']); $user_id = $d['user_id']; $logged_in = 1; } } else if ($action == 'logout') { setcookie("username",''); setcookie("pass",''); } else if ($_COOKIE['username'] && $_COOKIE['pass']) { $q = "SELECT * FROM lh_user WHERE username = '$_COOKIE[username]' AND pass = '$_COOKIE[pass]'"; $r = mysql_query($q) or die(mysql_error()); $d = mysql_fetch_array($r); if ($d) { $user_id = $d['user_id']; $logged_in = 1; } } $cpanel = cpanel(); $cats = cats(); $newest = newest(); $featured = featured(); $tmp = read_template("index"); $tmp = preg_replace("/\%\%CONTROLPANEL\%\%/",$cpanel,$tmp); $tmp = preg_replace("/\%\%CATEGORIES\%\%/",$cats,$tmp); $tmp = preg_replace("/\%\%NEWEST\%\%/",$newest,$tmp); $tmp = preg_replace("/\%\%FEATURED\%\%/",$featured,$tmp); echo $tmp; function cpanel() { global $login_error, $logged_in, $user_id; $output = ""; if ($login_error) { $output .= "Login Error: $login_error

"; } if ($logged_in && ! isset($_GET['force_login'])) { $new_messages = ""; $q = "SELECT count(*) as cnt FROM lh_message m WHERE (m.new_until IS NULL OR m.new_until > NOW()) AND to_user_id = $user_id"; $r = mysql_query($q) or die(mysql_error()); $d = mysql_fetch_array($r); if ($d[cnt]) $new_messages = "($d[cnt])"; $new_exchanges = ""; $q = "SELECT count(*) as cnt FROM lh_exchange e JOIN lh_site s ON (e.to_site_id = s.site_id) WHERE (e.new_until IS NULL OR e.new_until > NOW()) AND user_id = $user_id"; $r = mysql_query($q) or die(mysql_error()); $d = mysql_fetch_array($r); if ($d[cnt]) $new_exchanges = "($d[cnt])"; $output .= ""; } else { $output .= '
Login Form
   
Username:
Password:
 
 
Forgot Password - Register Free
'; } return $output; } function cats() { $q = "SELECT count(site_id) as cnt, lh_tag.* FROM lh_tag LEFT JOIN lh_site_tag USING (tag_id) GROUP BY tag_id"; $r = mysql_query($q) or die(mysql_error()); /* $cats = array(); $q = "SELECT count(s.site_id) as cnt,c.* FROM lh_category c LEFT JOIN lh_site s USING (category_id) GROUP BY c.category_id ORDER BY category "; $r = mysql_query($q) or die(mysql_error()); while ($d = mysql_fetch_array($r)) { $cats []= array($d[category],$d[cnt],$d[category_id]); } */ $output = ''; while ($d = mysql_fetch_array($r)) { $output .= ""; $output .= ""; $output .= ""; $i++; } $output .= "
($d[cnt])$d[tag_name]$d[tag_description]
"; return $output; } function newest() { $q = "SELECT s.*,c.category FROM lh_site s LEFT JOIN lh_category c USING (category_id) ORDER BY date_added DESC LIMIT 10"; $r = mysql_query($q) or die(mysql_error()); while ($d = mysql_fetch_array($r)) { $tmp = parse_url($d[url]); $domain = preg_replace("/^[wW][wW][wW]\./","",$tmp['host']); $tags = ""; $q2 = "SELECT * FROM lh_site JOIN lh_site_tag USING (site_id) JOIN lh_tag USING (tag_id) WHERE lh_site.site_id = '$d[site_id]'"; $r2 = mysql_query($q2) or die(mysql_error()); while ($d2 = mysql_fetch_array($r2)) { $tags .= " "; } $output .= "

PR$d[pagerank]
$d[title]
($domain)
$d[description]
$tags
[request link exchange] [send private message]


"; } return $output; } function featured() { $q = "SELECT s.*,c.category FROM lh_site s LEFT JOIN lh_category c USING (category_id) WHERE s.featured = 1 ORDER BY date_added DESC LIMIT 10"; $r = mysql_query($q) or die(mysql_error()); if (!mysql_num_rows($r)) { $output = "There are no Websites in this category."; } else { while ($d = mysql_fetch_array($r)) { $tmp = parse_url($d[url]); $domain = preg_replace("/^[wW][wW][wW]\./","",$tmp['host']); if (!$d[notes]) $d[notes] = '(none)'; $tags = ""; $q2 = "SELECT * FROM lh_site JOIN lh_site_tag USING (site_id) JOIN lh_tag USING (tag_id) WHERE lh_site.site_id = '$d[site_id]'"; $r2 = mysql_query($q2) or die(mysql_error()); while ($d2 = mysql_fetch_array($r2)) { $tags .= " "; } $output .= "

PR$d[pagerank]
$d[title]
($domain)

Description: $d[description]

$tags
[request link exchange] [send private message]


"; } } return $output; } ?>