Location: PHPKode > scripts > PHP Link Directory Script > linkdirectory/www/browse.php
<?php
/* PHP Link Directory Copyright 2011 Robert Rook */
if(!isset($db)) { require('dblogon.php'); }

/* Clean URL function */
function make_url_safe($txt) {
	$txt = str_replace(array('&amp;', '&#039;', '&quot;','&lt;', '&gt;'),"",$txt);
	$txt = preg_replace('/[^a-z0-9\-]/',"-",strtolower($txt));
	return preg_replace('/[\-]{2,}/',"-",$txt);
}

/* Attempt to fetch a category to view */
if(isset($_GET['curl'])) {
	$_GET['curl'] = urldecode($_GET['curl']);
	if(!get_magic_quotes_gpc()) { $_GET['curl'] = addslashes($_GET['curl']); }
	//echo $_GET['curl']; die();
	$res = mysql_query("SELECT * FROM {$prefix}cat WHERE curl='{$_GET['curl']}'", $db);
	if(mysql_num_rows($res)) { $c = mysql_fetch_array($res); }
}
if(isset($_GET['c']) && is_numeric($_GET['c']) && $_GET['c']>0) {
	$res = mysql_query("SELECT * FROM {$prefix}cat WHERE catid='{$_GET['c']}'", $db);
	if(mysql_num_rows($res)) { $c = mysql_fetch_array($res); }
}
if(!isset($c)) {
	$c = array("ctitle"=>"Home", "cpath"=>"", "catid"=>0, "cdesc"=>"The home category", "acceptlinks"=>0, "curl"=>"", "ckeywords"=>"");
}

$breadcrumbs = "";
$tmp = explode("&&", $c['cpath']);
$turl = "";
foreach($tmp as $value) {
	if(strlen($value)<3) { continue; }
	$value = explode("&:", $value);
	if(strlen($breadcrumbs)) {
		$breadcrumbs.= " :: ";
	}
	if($value[0]>0) { $turl.= make_url_safe($value[1]); }
	if(strlen($turl)) { $turl.= "/"; }
	$breadcrumbs.= "<a href=\"".($ldir_usestatic?"{$site_url}/{$ldir_folderroot}/{$turl}":"{$site_url}/browse.php?c={$value[0]}");
	$breadcrumbs.= "\">{$value[1]}</a>";
}

$page_title = $c['ctitle'];
$page_description = $c['cdesc'];
if(strlen($c['ckeywords'])) { $page_keywords = $c['ckeywords']; }
require('page_l.php');

if(strlen($breadcrumbs)) { $breadcrumbs = "<span class=\"breadcrumbs\">{$breadcrumbs}</span>"; }

echo <<<ENDHTML
	<form method="get" action="{$site_url}/search.php">
	<div class="dirsearch">
	<table border="0" cellpadding="2px" cellspacing="0">
	<tr><td>Search </td>
		<td><input type="text" class="searchbox" name="s"></td>
		<td align="right"><input type="submit" value="Search" class="stdbutton" id="id_search_submit"></td></tr>
	</table>
	</div>
	</form>
	
	<table border="0" cellpadding="2px" cellspacing="0" class="dirinfo" width="100%">
	<tr><td>
		<h1>{$c['ctitle']}</h1>
		{$breadcrumbs}
		<p>{$c['cdesc']}</p>
ENDHTML;

if($ldir_acceptlinks && $c['acceptlinks']) {
	echo "<a href=\"{$site_url}/addlink.php?c={$c['catid']}\" class=\"submitlink\">Submit link</a>\n";
}

echo <<<ENDHTML
		</td></tr>
	</table>
ENDHTML;

/* Show any sub categories for this category */
$res = mysql_query("SELECT ctitle, catid, cdesc, csafe, curl FROM {$prefix}cat WHERE cparent='{$c['catid']}' ORDER BY ctitle ASC", $db);
if(mysql_num_rows($res)) {
	echo "<table border=\"0\" cellpadding=\"2px\" cellspacing=\"0\" class=\"dirsublist\" width=\"100%\">\n";
	echo "<tr><td>\n";
	
	while($row = mysql_fetch_array($res)) {
		echo "<span class=\"subdir\"><a href=\"{$site_url}/";
		echo ($ldir_usestatic?"{$ldir_folderroot}/{$row['curl']}/":"browse.php?c={$row['catid']}");
		echo "\">{$row['ctitle']}</a><br>\n";
		echo "<p>".substr($row['cdesc'],0,200)."...</p></span>\n";
	}
	
	echo "</td></tr>\n";
	echo "</table>\n";
}

/* Show links for this category */
$view = 0;
$show = 20;
$res = mysql_query("SELECT COUNT(*) FROM {$prefix}link WHERE bactive=1 AND catid='{$c['catid']}'", $db);
$count = mysql_result($res,0);
if(isset($_GET['view']) && is_numeric($_GET['view']) && $_GET['view']>0 && $_GET['view']<$count) {
	$view = round($_GET['view']);
}

if($count>$show) {
	$pagelist = "<div class=\"pagelist\">\n";
	$ahtm = "<a href=\"{$site_url}/";
	$ahtm.= ($ldir_usestatic?"{$ldir_folderroot}/{$c['curl']}/?":"browse.php?c={$c['catid']}&");
	$ahtm.= "view=";
	if($view>0) {
		$pagelist.= $ahtm.(($view-$show)<0?0:($view-$show))."\">Back</a> ";
	}
	for($i=0;$i<floor($count/$show);$i++) {
		if(($i*$show)==$view) { $pagelist.= "<b>".($i+1)."</b> "; }
		else {
			$pagelist.= $ahtm.($i*$show)."\">".($i+1)."</a> ";
		}
	}
	if(($view+$show)<$count) {
		$pagelist.= $ahtm.($view+$show)."\">Next</a>";
	}
	$pagelist.= "</div>\n";
	echo $pagelist;
}

if($count) {
	$res = mysql_query("SELECT ltitle, lurl, ldesc, linkid, ctime, allowrating, lhits, rate1, rate2, rate3, rate4, rate5, lsafe, curl FROM {$prefix}link WHERE bactive=1 AND catid='{$c['catid']}' ORDER BY lrank DESC, ctime DESC LIMIT {$view},{$show}", $db);
	while($row = mysql_fetch_array($res)) {
		$row['nhits'] = number_format($row['lhits']);
		$row['nratings'] = number_format($row['rate1']+$row['rate2']+$row['rate3']+$row['rate4']+$row['rate5']);
		if(!$row['nratings']) { $row['nscore'] = "(not yet rated)"; }
		else {
			$row['nscore'] = round(($row['rate1']+($row['rate2']*2)+($row['rate3']*3)+($row['rate4']*4)+($row['rate5']*5))/$row['nratings']);
		}
		
		echo "<div class=\"dirlink\">";
		if($row['allowrating'] && $ldir_allowrating && $row['nratings']) {
			echo "<span class=\"linkrating\">";
			for($i=1;$i<=5;$i++) {
				if($i<=$row['nscore']) {
					echo "<img src=\"{$site_url}/imgs/ico_star_full.gif\" alt=\"{$i}\" border=\"0\" width=\"20px\" height=\"20px\">";
				} else {
					echo "<img src=\"{$site_url}/imgs/ico_star_empty.gif\" alt=\"{$i}\" border=\"0\" width=\"20px\" height=\"20px\">";
				}
			}
			echo "</span>\n";
		}
		echo "<a href=\"{$site_url}/";
		echo ($ldir_usestatic?"{$ldir_folderroot}/{$row['curl']}/{$row['lsafe']}.html":"viewlink.php?l={$row['linkid']}");
		echo "\">{$row['ltitle']}</a><br>\n";
		echo "<i>Added ".date('jS F, Y', $row['ctime'])."</i>\n";
		echo "<span class=\"linkhits\">{$row['nhits']} Visits</span>\n";
		echo "<p>".substr($row['ldesc'],0,200)."...";
		echo "</p></div>\n";
	}
}

if($count>$show) { echo $pagelist; }

require('page_r.php');
?>
Return current item: PHP Link Directory Script