/*=========================================================================
:: phpWebLog -- web news management with tits.
:: Copyright (C) 2000-2001 Jason Hines
:: see http://phpweblog.org for more
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
=*=======================================================================*/
# Original links code written by Twyst (http://anime-central.net)
# Modified for use with phpWebLog by Jason Hines
# Thanks Twyst!
include("./include/common.inc.php");
include("./include/header.inc.php");
function do_main($node="",$start=0) {
$A["Heading"] = ucwords(_LINKS);
$A["Content"] = F_nodewalk($node,0);
# $A["Content"] .= F_showalphanodes($node);
$A["Content"] .= F_shownodes($node);
$A["Content"] .= "
\n";
$A["Content"] .= F_showitems($node,$start);
$A["Content"] .= F_suggest($node);
F_drawMain($A);
if(F_isAdmin()) {
do_admin();
}
}
function F_nodewalk($startnode="",$linklast=0) {
global $PHP_SELF,$db;
$currnode = $startnode;
while(!empty($currnode)) {
$sql = "SELECT * from T_LinkCats ";
$sql .= "WHERE Rid='$currnode' ";
$sql .= "AND Verified='1'";
$result=mysql_query($sql,$db);
list($id,$name,$currnode) = mysql_fetch_row($result);
if (!empty($name)) {
if($id != $startnode) {
$temp = " > $name" . $output;
$output = $temp;
} else {
if($linklast == 1) {
$temp = " > $name" . $output;
$output = $temp;
} else {
$temp = " > $name " . $output;
$output = $temp;
}
}
}
}
$temp = "Top" . $output;
return $temp;
}
function F_shownodes($node="") {
global $db,$PHP_SELF;
if ((empty($node)) || ($node=="null")) {
$search = "ParentRid='NULL'";
} else {
$search = "ParentRid='$node'";
}
$output = "
";
$sql = "SELECT Rid,Name FROM T_LinkCats ";
$sql .= "WHERE $search and Verified='1' ";
$sql .= "AND length(Name) > 1 ORDER BY Name";
$result = mysql_query($sql,$db);
$numrows = mysql_num_rows($result);
$half = $numrows / 2;
$count = 0;
$output .="| \n";
while($count < $half) {
list($id,$name) = mysql_fetch_row($result);
$cnt = F_count("T_Links","CatRid",$id,"Verified","1");
$output .="$name ($cnt)" .
F_admin("T_LinkCats",$id,"links.php?node=$node") . "\n";
$count++;
}
$output .=" | \n";
while(list($id,$name) = mysql_fetch_row($result)) {
$cnt = F_count("T_Links","CatRid",$id,"Verified","1");
$output .="$name ($cnt)" .
F_admin("T_LinkCats",$id,"links.php?node=$node") . "\n";
}
$output .=" |
";
return $output;
}
function F_showalphanodes($node="") {
global $db,$PHP_SELF;
$sql = "SELECT Rid,Name FROM T_LinkCats ";
if ((empty($node)) || ($node=="null")) {
$sql .= "WHERE ParentRid = 'NULL'";
} else {
$sql .= "WHERE ParentRid = '$node'";
}
$sql .= " AND Verified='1' AND length(Name) = 1 ";
$sql .= "ORDER BY Name";
echo $sql;
$result = mysql_query($sql,$db);
if (mysql_num_rows($result) > 0) {
$s = "\n";
$s .= "| | ";
while(list($id,$name) = mysql_fetch_row($result)) {
$s .= " $name |\n";
}
$output .= " |
\n";
}
return $s;
}
function F_showitems($node="",$start="") {
global $db,$PHP_SELF,$G_URL;
if ((empty($node)) || ($node=="null")) {
$search = "CatRid = 'NULL'";
} else {
$search = "CatRid = '$node'";
}
$output = "";
$sql = "SELECT Rid from T_Links ";
$sql .= "WHERE $search and Verified='1'";
$temp = mysql_query($sql,$db);
$total = mysql_num_rows($temp);
if ($total > 0) {
if ($start > 0) {
$pr = $start - 26;
if ($pr < 0) { $pr = 0; }
$prevlink = "[<< " . _PREV . "]";
}
if (empty($start)) { $start = 0; }
$end = $start + 25;
if ($end > $total) { $end = $total; }
if ($end < $total) {
$nx = $end + 1;
$nextlink = "[" . _NEXT . " >>]";
}
$tmp = $start+1;
$display = _SHOWING . " $tmp - $end of $total";
$sql = "SELECT Rid,Url,Name,Description,Hits ";
$sql .= "FROM T_Links ";
$sql .= "WHERE $search and Verified='1' ";
$sql .= "ORDER BY Name limit $start,25";
$result = mysql_query($sql,$db);
$ck = 0;
while (list($id,$url,$name,$desc,$hits) = mysql_fetch_row($result)) {
$ck++;
if(($ck % 2) < 1) {
$output .= "| ";
} else {
$output .=" |
";
}
$tmp = urlencode($url);
$output .= "$name ($hits) - $url\n";
if (!empty($desc)) {
$output .= " $desc";
}
# $output .= " |
";
if(F_isAdmin()) {
$output .= "  |
";
}
$output .="\n";
}
$output .= "
$prevlink $display $nextlink";
} else {
$output = _NOLINKS;
}
return $output;
}
function F_suggest($node="") {
global $PHP_SELF,$CONF;
if ($node == "") { $node = "null"; }
$output = "";
return $output;
}
function F_suggestnode($node="") {
global $db,$PHP_SELF;
$output = F_nodewalk($node,1);
$output .= "";
return $output;
}
function editlink($node="") {
global $db,$PHP_SELF;
$sql = "SELECT * from T_Links ";
$sql .= "WHERE Rid='$node'";
$result = mysql_query($sql,$db);
if (mysql_num_rows($result) < 1) {
$output = "No such ID";
} else {
list($linkid,$catid,$url,$linkname,$desc,$approved,$sname,$semail,$sdate) = mysql_fetch_row($result);
$output = F_nodewalk($catid,1);
$output .= "";
}
return $output;
}
function F_suggestlink($node="") {
global $db,$PHP_SELF,$C_USER,$HTTP_COOKIE_VARS;
$tmp = $HTTP_COOKIE_VARS["$C_USER"];
$USER = explode("|",rot13($tmp));
$output = F_nodewalk($node,1);
$output .= "";
return $output;
}
function do_search($keywords="",$start) {
global $db,$PHP_SELF,$G_URL;
$kw = urlencode($keywords);
$sql = "SELECT distinct Rid from T_Links ";
$sql .= "WHERE (Name like '%$keywords%' ";
$sql .= "or Description like '%$keywords%') ";
$sql .= "AND Verified='1'";
$temp = mysql_query($sql,$db);
$total = mysql_num_rows($temp);
if ($total > 0) {
if($total > 1) { $rs = "s"; }
$header = "$total result$rs found";
$output = "";
if ($start > 0) {
$pr = $start - 26;
if ($pr < 0) { $pr = 0; }
$prevlink = "[<< " . _PREV . "]";
}
if (empty($start)) { $start = 0; }
$end = $start + 25;
if ($end > $total) { $end = $total; }
if ($end < $total) {
$nx = $end + 1;
$nextlink = "[" . _NEXT . " >>]";
}
$display = _SHOWING . " $start - $end";
$sql = "SELECT distinct CatRid,Rid,Url,Name,Description ";
$sql .= "FROM T_Links ";
$sql .= "WHERE (Name like \"%$keywords%\" or ";
$sql .= "Description like \"%$keywords%\") ";
$sql .= "AND Verified='1' ";
$sql .= "ORDER BY Name limit $start,25";
$result = mysql_query($sql,$db);
$ck = 0;
while (list($cat,$id,$url,$name,$desc) = mysql_fetch_row($result)) {
$ck++;
$node = F_nodewalk($cat,1);
if(($ck % 2) < 1) {
$output .= "| ";
} else {
$output .=" |
";
}
$tmp = urlencode($url);
$output .= "$name ($hits) - $url\n";
if (!empty($desc)) {
$output .= " $desc";
}
$output .= " [" . $node . "]";
if(F_isAdmin()) { $output .= " |
 |
"; }
}
$output .= "
$prevlink $display $nextlink";
} else {
$header = _SEARCHRESULTS;
$output = _NOMATCHES;
}
$A["Heading"]=$header;
$A["Content"]=$output;
F_drawMain($A);
$suggest = F_suggest("");
$A["Heading"]="Search";
$A["Content"]=$suggest;
F_DrawMain($A);
}
function do_admin() {
global $db,$PHP_SELF,$G_URL;
$sql = "SELECT * from T_LinkCats ";
$sql .= "WHERE Verified='0' ";
$sql .= "ORDER BY Name";
$result = mysql_query($sql,$db);
if(mysql_num_rows($result) > 0) {
$A["Heading"]="Submitted Nodes";
$A["Content"]="\n";
while(list($CatID,$CatName,$CatParent) = mysql_fetch_row($result)) {
$A["Content"] .= "$CatName - (in " . F_nodewalk($CatParent,1) .") \n";
$A["Content"] .= " |  ";
}
$A["Content"] .= " |
";
F_drawMain($A);
}
$sql = "SELECT * from T_Links ";
$sql .= "WHERE Verified='0' ";
$sql .= "ORDER BY Name";
$result = mysql_query($sql,$db);
if(mysql_num_rows($result) > 0) {
$A["Heading"]="Submitted Links";
$A["Content"]="\n";
while(list($id,$cat,$url,$name,$desc,$app,$sname,$semail,$sdate) = mysql_fetch_row($result)) {
$A["Content"] .= "$name - (in " . F_nodewalk($cat,1) .") \n";
$A["Content"] .= "Description: $desc URL: $url Submitted by $sname - $sdate ";
$A["Content"] .= " |  ";
}
$A["Content"] .= " |
";
F_drawMain($A);
}
}
if ($editlink) {
$edit = editlink($editlink);
$A["Heading"]="Editing Link";
$A["Content"] = $edit;
F_drawMain($A);
} else if ($updatelink) {
$sql = "UPDATE T_Links set ";
$sql .= "Name='$linkname',";
$sql .= "Url='$url',";
$sql .= "CatRid='$category',";
$sql .= "Description='$description',";
$sql .= "SubmitName='$subname',";
$sql .= "SubmitEmail='$subemail' ";
$sql .= "WHERE Rid='$linkid'";
$result = mysql_query($sql,$db);
F_notice("Link successfully changed.");
do_main();
} else if ($unapprove) {
$sql = "UPDATE T_Links set Verified='0' ";
$sql .= "WHERE Rid='$unapprove'";
$result = mysql_query($sql,$db);
F_notice("Link successfully unapproved.");
do_main();
} else if ($approvenode) {
$sql = "UPDATE T_LinkCats SET Verified='1' ";
$sql .= "WHERE Rid='$approvenode'";
$result=mysql_query($sql,$db);
F_notice("Node successfully approved.");
do_main();
} else if ($approvelink) {
$sql = "UPDATE T_Links SET Verified='1' ";
$sql .= "WHERE Rid='$approvelink'";
$result=mysql_query($sql,$db);
F_notice("Link successfully approved.");
do_main();
} else if ($delnode) {
$sql = "DELETE FROM T_LinkCats ";
$sql .= "WHERE Verified='0' ";
$sql .= "AND Rid='$delnode'";
$result=mysql_query($sql,$db);
F_notice("Node successfully deleted.");
do_main();
} else if ($dellink) {
$sql = "DELETE FROM T_Links ";
$sql .= "WHERE Verified='0' ";
$sql .= "AND Rid='$dellink'";
$result=mysql_query($sql,$db);
F_notice("Link successfully deleted.");
do_main();
} else if ($sugnode) {
$A["Heading"] = _ADDSUG;
$A["Content"] = F_suggestnode($sugnode);
F_drawMain($A);
} else if ($suglink) {
$A["Heading"] = _ADDSUG;
$A["Content"] = F_suggestlink($suglink);
F_drawMain($A);
} else if ($addnode) {
if(F_isAdmin()) { $appr = 1; } else { $appr = 0; }
$sql = "INSERT into T_LinkCats ";
$sql .= "(Rid,Name,ParentRid,Verified) values ";
$sql .= "('" . F_getRid() . "','$newnode','$parent','$appr')";
$result = mysql_query($sql,$db);
F_notice(_SUGTHANK);
do_main($parent);
} else if ($addlink) {
if(F_isAdmin()) { $appr = 1; } else { $appr = 0; }
$sql = "INSERT into T_Links ";
$sql .= "(Rid,CatRid,Url,Name,Description,Verified,Hits,";
$sql .= "SubmitName,SubmitEmail,SubmitDate) values ";
$sql .= "('" . F_getRid() . "','$parent','$url','$linkname','$description',";
$sql .= "'$appr',0,'$subname','$subemail',now())";
$result = mysql_query($sql,$db);
F_notice(_SUGTHANK);
do_main($parent);
} else if ($search) {
do_search($search,$start);
} else {
do_main($node,$start);
}
include("./include/footer.inc.php");
?>