Please click here to install CNCat.
Do not forget to create files config.php, _top.php and _bottom.php after installation.
Documentation: English, Russian.
Please create the file "_top.php".
Documentation: English, Russian.
Please create the file "_bottom.php".
Documentation: English, Russian.
Please click here to install CNCat.
Do not forget to create files config.php, _top.php and _bottom.php after installation.
Documentation: English, Russian.
Documentation: English, Russian.5) $defaultorder=0;
if (($o<0 && $o>5) || !isset($o)) $o=$defaultorder;
$ostr=getOrderStr($o);
/* Rendering page */
// Get info for current and parent categories
$parentLinks="";
$url="";
$title="";
getCategoryInfo($c, $title, $url, $parentLinks);
// Page title
if (!empty($title))
$title .= " / ".$CATNAME;
else
$title = $CATNAME;
include "./_top.php";
// Initialization warnings
displayWarnings();
// Block from template "Menu" (Directory index | Submit a site | Administration)
displayMenu();
// JavaScript for broken links ("brokenscript" template);
displayBrokenScript();
// Block from template "Search form"
displaySearchForm();
// Directory title and path to the current category
displayCategoryPath($c, $parentLinks);
// List of child categories
displayCategories($c);
// New links
displayNewLinks($c);
// Sort order
displaySortOrderCat($c, $o, $url);
// Links in the current category
$total = displayCategoryLinks($c, $o, $start);
// Page navigation
displayPages($c, $o, $url, $total, $start);
// Block from template "Menu" (Directory index | Submit a site | Administration)
displayMenu();
// Page bottom
include "./_bottom.php";
/***********************************************
* Service functions
***********************************************/
function getCategoryInfo($c, &$title, &$url, &$parentLinks)
{
GLOBAL $TMPL, $LANG, $cat, $db;
$cid=$c;
do
{
$r=mysql_query("SELECT c.parent,c.name,c.cid,l.url FROM ".$db["prefix"]."cat c,".$db["prefix"]."cat_linear l WHERE c.cid='$cid' AND c.cid=l.cid;") or die(mysql_error());
if (mysql_num_rows($r)==1)
{
$ct = mysql_fetch_assoc($r);
if ($cid==$c)
{
$title = $ct["name"];
$url = $ct["url"];
$parentLinks = $ct["name"];
}
else
$parentLinks="".$ct["name"]." » ".$parentLinks;
$cid=$ct["parent"];
}
else $cid=0;
} while ($cid!=0);
};
/***********************************************
* Display functions
***********************************************/
function displayWarnings()
{
GLOBAL $warning;
if (!empty($warning))
{
print "";
print "Warning: ".$warning;
print "
";
}
}
function displayCategoryPath($c, $parents)
{
GLOBAL $TMPL, $LANG, $cat, $db;
if ($cat["showpathonmain"]==1 || $c!=0)
{
$template=$TMPL["catname"];
$template=str_replace("%MAINTEXT",$cat["catname"],$template);
$template=str_replace("%OTHERTEXT",$parents,$template);
if (isAdmin() && $c>0)
$edit = " ".
"";
else
$edit="";
$template=str_replace("%ADMINIFACE",$edit,$template);
print $template;
}
}
function displayCategories($cid)
{
GLOBAL $cat,$TMPL,$db;
$showsubcats = $cat["showsubcats"]==2 || $cat["showsubcats"]==1 && $cid==0;
$catOrder = $cat["catsort"]==0 ? "c.name" : "c.sortorder, c.name";
$query = "SELECT c.name,c.cid,c.count,l.url FROM ".$db["prefix"]."cat c,".$db["prefix"]."cat_linear l WHERE c.parent='$cid' AND c.cid=l.cid ORDER BY ".$catOrder;
$r=mysql_query($query) or die(mysql_error());
$num=0;
$cnt=mysql_num_rows($r);
if ($cnt==0) return;
$cats = array();
$catIds = array();
while ($c = mysql_fetch_array($r))
{
$cats1[$c[1]] = count ($cats);
$cats[] = $c;
$catIds[] = $c[1];
}
if ($showsubcats)
{
$query = "SELECT c.name,c.cid,c.count,l.url,c.parent FROM ".$db["prefix"]."cat c,".$db["prefix"]."cat_linear l WHERE c.parent in (".join (",",$catIds).") AND c.cid=l.cid ORDER BY ".$catOrder;
$r1 = mysql_query($query) or die(mysql_error());
while ($c1 = mysql_fetch_array($r1))
$cats[$cats1[$c1[4]]]["subcats"][] = $c1;
};
print $TMPL["partstop"];
$rows = $cat["rows"];
// Auto row count - priority to columns
if ($rows==0) $rows = intval (ceil(sqrt($cnt)));
// Auto row count - priority to rows
//if ($rows==0) $rows = intval (floor(sqrt($cnt)));
$width = intval (100/ceil($cnt/$rows));
for ($i=0;$i<$cnt;$i++)
{
$num++;
if ($num==1) print str_replace("%WIDTH",$width."%",$TMPL["partsdelimtop"]);
$template=$TMPL["partsbit"];
$template=str_replace("%CTITLE",$cats[$i][0],$template);
$catUrl = getCatUrl($cats[$i][1], $cats[$i][3]);
$template=str_replace("%URL",$catUrl,$template);
$template=str_replace("%CID",$cats[$i][1],$template);
$template=str_replace("%CCOUNT",$cats[$i][2],$template);
// Sub-categories
$subcats = "";
$subCnt = count ($cats[$i]["subcats"]);
if ($showsubcats && $subCnt>0)
{
$subMore = 0;
$subcats .= $TMPL["subpartstop"];
if ($subCnt>$cat["showsubcatcount"])
{
$subCnt=$cat["showsubcatcount"];
$subMore=1;
}
for ($j=0; $j<$subCnt; $j++)
{
$template1 = $TMPL["subpartsbit"];
$catUrl = getCatUrl($cats[$i]["subcats"][$j][1], $cats[$i]["subcats"][$j][3]);
$template1=str_replace("%URL",$catUrl,$template1);
$template1=str_replace("%CTITLE",$cats[$i]["subcats"][$j][0],$template1);
$template1=str_replace("%CCOUNT",$cats[$i]["subcats"][$j][2],$template1);
if ($j>0) $subcats .= $TMPL["subpartsdelim"];
$subcats .= $template1;
};
if ($subMore)
$subcats .= $TMPL["subpartsmore"];
$subcats .= $TMPL["subpartsbottom"];
};
$template=str_replace("%SUBPARTS",$subcats,$template);
print $template;
if ($num==$rows)
{
print $TMPL["partsdelimbottom"];
$num=0;
}
}
print $TMPL["partsbottom"];
}
function displayNewLinks($c)
{
GLOBAL $TMPL, $LANG, $cat, $db;
if (intval($c)==0 && $cat["shownew"]==1)
{
$newlinkstop=$TMPL["newlinkstop"];
$newlinkstop=str_replace("%NEWLINKSTEXT",$LANG["newlinks"],$newlinkstop);
print $newlinkstop;
$r=mysql_query("SELECT lid,title,description,resfield1,resfield2,resfield3 FROM ".$db["prefix"]."main WHERE type=1 ORDER by insert_date DESC LIMIT ".$cat["shownewcount"].";");
while ($ar=mysql_fetch_array($r))
{
if (substr($ar["description"], 0, 6)!="[html]" && strlen($ar["description"])>75)
$ar["description75"]=substr($ar["description"],0,75)."...";
else
$ar["description75"]=$ar["description"];
$template=$TMPL["newlinkstbit"];
$template=str_replace("%ID",$ar["lid"],$template);
$template=str_replace("%EXTENDEDINFOURL",getExtendedInfoUrl($ar["lid"]),$template);
$template=str_replace("%TITLE",$ar["title"],$template);
$template=str_replace("%GIN",$ar["gin"],$template);
$template=str_replace("%GOUT",$ar["gout"],$template);
$template=str_replace("%MODERVOTE",$ar["moder_vote"],$template);
$template=str_replace("%DESC75",rehtml($ar["description75"]),$template);
$template=str_replace("%DESC",rehtml($ar["description"]),$template);
$template=str_replace("%URL",$ar["url"],$template);
$template=str_replace("%RESFIELD1",$ar["resfield1"],$template);
$template=str_replace("%RESFIELD2",$ar["resfield2"],$template);
$template=str_replace("%RESFIELD3",$ar["resfield3"],$template);
print $template;
}
print $TMPL["newlinkstbottom"];
}
}
function displaySortOrderCat($c, $o, $url)
{
GLOBAL $TMPL, $LANG, $cat, $db;
if ($cat["linksatmain"]==1 || $c!=0)
{
if ($o==0) $sortbypop="".$LANG["popuarity"].""; else $sortbypop="".$LANG["popuarity"]."";
if ($o==1) $sortbytitle="".$LANG["title"].""; else $sortbytitle="".$LANG["title"]."";
if ($o==2) $sortbymoder="".$LANG["modervote"].""; else $sortbymoder="".$LANG["modervote"]."";
if ($o==3) $sortbyin="".$LANG["sortbyin"].""; else $sortbyin="".$LANG["sortbyin"]."";
if ($o==4) $sortbypr="".$LANG["sortbypr"].""; else $sortbypr="".$LANG["sortbypr"]."";
if ($o==5) $sortbycy="".$LANG["sortbycy"].""; else $sortbycy="".$LANG["sortbycy"]."";
$template=$TMPL["sortby"];
$template=str_replace("%SORTBYPOP",$sortbypop,$template);
$template=str_replace("%SORTBYTITLE",$sortbytitle,$template);
$template=str_replace("%SORTBYMODER",$sortbymoder,$template);
$template=str_replace("%SORTBYIN",$sortbyin,$template);
$template=str_replace("%SORTBYPR",$sortbypr,$template);
$template=str_replace("%SORTBYCY",$sortbycy,$template);
$template=str_replace("%SORTBYTEXT",$LANG["sortby"],$template);
print $template;
}
}
function displayCategoryLinks($c, $o, $start)
{
GLOBAL $TMPL, $LANG, $cat, $db;
$pp=$cat["linksperpage"];
if ($cat["linksatmain"]==1 || $c!=0)
{
print $TMPL["linkstop"];
dislpayCategoryLinksByRank($c,$o, $start, 1);
print str_replace("%NUM",($start*$pp)+1,$TMPL["linksmiddle"]);
$total = dislpayCategoryLinksByRank ($c, $o, $start, 0);
print $TMPL["linksbottom"];
if ($total>0)
print "".$LANG["linkcount"].": $total
";
}
return $total;
}
function dislpayCategoryLinksByRank($cid, $o, $start, $best=0)
{
GLOBAL $TMPL, $LANG, $cat, $db;
$pp=$cat["linksperpage"];
if ($best==1) $bestsql="AND moder_vote=10"; else $bestsql="AND moder_vote!=10";
if ($o==0) $order="ORDER BY gin DESC,gout DESC";
if ($o==1) $order="ORDER BY title";
if ($o==2) $order="ORDER BY moder_vote DESC, gout DESC";
if ($o==3) $order="ORDER BY insert_date DESC";
if ($o==4) $order="ORDER BY pr DESC";
if ($o==5) $order="ORDER BY cy DESC";
if ($cid!=0)
$Q="SELECT m.lid,url,title,description,fulldesc,keywords,gin,gout,moder_vote,pr,cy,resfield1,resfield2,resfield3 FROM ".$db["prefix"]."lincat lc left join ".$db["prefix"]."main m on lc.lid=m.lid WHERE type=1 $bestsql AND lc.cid=$cid $order LIMIT ".($start*$pp).",$pp;";
else
$Q="SELECT lid,url,title,description,fulldesc,keywords,gin,gout,moder_vote,pr,cy,resfield1,resfield2,resfield3 FROM ".$db["prefix"]."main WHERE type=1 $bestsql $order LIMIT ".($start*$pp).",$pp;";
$r=mysql_query($Q) or die(mysql_error());
if ($best!=1)
{
$cnt=mysql_num_rows($r);
if ($cnt==0) print $LANG["linksnotfound"];
}
displayLinks ($r);
if ($best!=1)
{
if ($cid!=0)
$Q="SELECT count(*) FROM ".$db["prefix"]."lincat lc left join ".$db["prefix"]."main m on lc.lid=m.lid WHERE type=1 $bestsql AND lc.cid=$cid;";
else
$Q="SELECT count(*) FROM ".$db["prefix"]."main WHERE type=1 $bestsql;";
return(mysql_result(mysql_query($Q),0,0));
}
}
function displayPages($c, $o, $url, $total, $start)
{
GLOBAL $TMPL, $LANG, $cat, $db;
$pp=$cat["linksperpage"];
if ($pp>0)
{
if ($cat["sefriendly"]==1 && !empty ($url) && substr($url, -1)!="/")
print "".uniLeftRight(ceil($total/$pp),$start,getCatUrl($c, $url, $o),1,".html")."";
else
print "".uniLeftRight(ceil($total/$pp),$start,getCatUrl($c, $url, $o)."&start=",1)."";
}
}
?>