From: <lra...@us...> - 2003-01-13 19:59:09
|
Update of /cvsroot/tikiwiki/tiki/lib/directory In directory sc8-pr-cvs1:/tmp/cvs-serv2280/lib/directory Modified Files: dirlib.php Log Message: Internal commit for consistency Index: dirlib.php =================================================================== RCS file: /cvsroot/tikiwiki/tiki/lib/directory/dirlib.php,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- dirlib.php 13 Jan 2003 15:04:03 -0000 1.1 +++ dirlib.php 13 Jan 2003 19:59:05 -0000 1.2 @@ -1,16 +1,16 @@ -<?php - -class DirLib extends TikiLib { - - function DirLib($db) - { - if(!$db) { - die("Invalid db object passed to UsersLib constructor"); - } - $this->db = $db; - } - - // Path functions +<?php + +class DirLib extends TikiLib { + + function DirLib($db) + { + if(!$db) { + die("Invalid db object passed to UsersLib constructor"); + } + $this->db = $db; + } + + // Path functions function dir_get_category_path_admin($categId) { @@ -21,17 +21,17 @@ $path = '<a class="link" href="tiki-directory_admin_categories.php?parent='.$info["categId"].'">'.$info["name"].'</a>'.'>'.$path; } return $path; - } - - function dir_get_path_text($categId) - { + } + + function dir_get_path_text($categId) + { $info = $this->dir_get_category($categId); $path = $info["name"]; while($info["parent"]!=0) { $info = $this->dir_get_category($info["parent"]); $path = $info["name"].'>>'.$path; } - return $path; + return $path; } function dir_get_category_path_browse($categId) @@ -44,24 +44,24 @@ $path = $path = '<a class="link" href=tiki-directory_browse_category.php?parent="'.$info["categId"].'">'.$info["name"].'</a>'.'>'.$path; } return $path; - } - - // Stats functions - // get stats (valid sites, invalid sites, categories, searches) - function dir_stats() - { - $aux=Array(); - $aux["valid"] = $this->db->getOne("select count(*) from tiki_directory_sites where isValid='y'"); - $aux["invalid"] = $this->db->getOne("select count(*) from tiki_directory_sites where isValid='n'"); - $aux["categs"] = $this->db->getOne("select count(*) from tiki_directory_categories"); - $aux["searches"] = $this->db->getOne("select sum(hits) from tiki_directory_search"); - $aux["visits"] = $this->db->getOne("select sum(hits) from tiki_directory_sites"); - return $aux; - } - - // Functions to manage categories - - // List + } + + // Stats functions + // get stats (valid sites, invalid sites, categories, searches) + function dir_stats() + { + $aux=Array(); + $aux["valid"] = $this->db->getOne("select count(*) from tiki_directory_sites where isValid='y'"); + $aux["invalid"] = $this->db->getOne("select count(*) from tiki_directory_sites where isValid='n'"); + $aux["categs"] = $this->db->getOne("select count(*) from tiki_directory_categories"); + $aux["searches"] = $this->db->getOne("select sum(hits) from tiki_directory_search"); + $aux["visits"] = $this->db->getOne("select sum(hits) from tiki_directory_sites"); + return $aux; + } + + // Functions to manage categories + + // List function dir_list_categories($parent,$offset,$maxRecords,$sort_mode,$find) { $sort_mode = str_replace("_"," ",$sort_mode); @@ -72,172 +72,406 @@ } $query = "select * from tiki_directory_categories where parent=$parent $mid order by $sort_mode limit $offset,$maxRecords"; $query_cant = "select count(*) from tiki_directory_categories where parent=$parent $mid"; - $result = $this->query($query); + $result = $this->query($query); $cant = $this->getOne($query_cant); $ret = Array(); while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { - $res["sites"]=$this->db->getOne("select count(*) from tiki_category_sites where categId=".$res["categId"]); - //$res["path"]=$this->dir_get_path_text($res["categId"]); + $res["sites"]=$this->db->getOne("select count(*) from tiki_category_sites where categId=".$res["categId"]); + //$res["path"]=$this->dir_get_path_text($res["categId"]); $ret[] = $res; } $retval = Array(); $retval["data"] = $ret; $retval["cant"] = $cant; return $retval; - } - - function dir_get_all_categories($offset,$maxRecords,$sort_mode,$find) + } + + function dir_list_sites($parent,$offset,$maxRecords,$sort_mode,$find,$isValid) { $sort_mode = str_replace("_"," ",$sort_mode); if($find) { - $mid=" and (title like '%".$find."%' or data like '%".$find."%')"; + $mid=" and (name like '%".$find."%' or description like '%".$find."%')"; + } else { + $mid=""; + } + if($isValid) { + $mid.= " and isValid='$isValid' "; + } + $query = "select * from tiki_directory_sites tds, tiki_category_sites tcs where tds.siteId=tcs.siteId and tcs.categId=$parent $mid order by $sort_mode limit $offset,$maxRecords"; + $query_cant = "select count(*) from tiki_directory_sites tds, tiki_category_sites tcs where tds.siteId=tcs.siteId and tcs.categId=$parent $mid"; + $result = $this->query($query); + $cant = $this->getOne($query_cant); + $ret = Array(); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $res["cats"]=$this->dir_get_site_categories($res["siteId"]); + $ret[] = $res; + } + $retval = Array(); + $retval["data"] = $ret; + $retval["cant"] = $cant; + return $retval; + } + + function dir_list_invalid_sites($offset,$maxRecords,$sort_mode,$find) + { + $sort_mode = str_replace("_"," ",$sort_mode); + if($find) { + $mid=" and (name like '%".$find."%' or description like '%".$find."%')"; + } else { + $mid=""; + } + + $query = "select * from tiki_directory_sites where isValid='n' $mid order by $sort_mode limit $offset,$maxRecords"; + $query_cant = "select count(*) from tiki_directory_sites where isValid='n' $mid"; + $result = $this->query($query); + $cant = $this->getOne($query_cant); + $ret = Array(); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $res["cats"]=$this->dir_get_site_categories($res["siteId"]); + $ret[] = $res; + } + $retval = Array(); + $retval["data"] = $ret; + $retval["cant"] = $cant; + return $retval; + } + + function dir_get_site_categories($siteId) + { + $query = "select tdc.name,tcs.categId from tiki_category_sites tcs,tiki_directory_categories tdc where tcs.siteId=$siteId and tcs.categId=tdc.categId"; + $result = $this->query($query); + $ret=Array(); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $res["path"]=$this->dir_get_path_text($res["categId"]); + $ret[]=$res; + } + return $ret; + } + + function dir_list_all_sites($offset,$maxRecords,$sort_mode,$find) + { + $sort_mode = str_replace("_"," ",$sort_mode); + if($find) { + $mid=" and (name like '%".$find."%' or description like '%".$find."%')"; + } else { + $mid=""; + } + + $query = "select * from tiki_directory_sites $mid order by $sort_mode limit $offset,$maxRecords"; + $query_cant = "select count(*) from tiki_directory_sites $mid"; + $result = $this->query($query); + $cant = $this->getOne($query_cant); + $ret = Array(); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $res["cats"]=$this->dir_get_site_categories($res["siteId"]); + $ret[] = $res; + } + $retval = Array(); + $retval["data"] = $ret; + $retval["cant"] = $cant; + return $retval; + } + + + function dir_get_all_categories($offset,$maxRecords,$sort_mode,$find,$siteId=0) + { + $sort_mode = str_replace("_"," ",$sort_mode); + if($find) { + $mid=" where (title like '%".$find."%' or data like '%".$find."%')"; } else { $mid=""; } $query = "select * from tiki_directory_categories $mid order by $sort_mode limit $offset,$maxRecords"; $query_cant = "select count(*) from tiki_directory_categories $mid"; - $result = $this->query($query); + $result = $this->query($query); $cant = $this->getOne($query_cant); $ret = Array(); while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { - $res["sites"]=$this->db->getOne("select count(*) from tiki_category_sites where categId=".$res["categId"]); - $res["path"]=$this->dir_get_path_text($res["categId"]); + $res["path"]=$this->dir_get_path_text($res["categId"]); + $res["belongs"]='n'; + if($siteId) { + $belongs = $this->db->getOne("select count(*) from tiki_category_sites where siteId=$siteId and categId=".$res["categId"]); + if($belongs) { + $res["belongs"]='y'; + } + } + $ret[] = $res; + } + usort($ret,'compare_paths'); + return $ret; + } + + function dir_get_all_categories_np($offset,$maxRecords,$sort_mode,$find,$parent) + { + $sort_mode = str_replace("_"," ",$sort_mode); + if($find) { + $mid=" and (title like '%".$find."%' or data like '%".$find."%')"; + } else { + $mid=""; + } + $query = "select * from tiki_directory_categories where categId<>$parent $mid order by $sort_mode limit $offset,$maxRecords"; + $query_cant = "select count(*) from tiki_directory_categories where categId<>$parent $mid"; + $result = $this->query($query); + $cant = $this->getOne($query_cant); + $ret = Array(); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $res["path"]=$this->dir_get_path_text($res["categId"]); + $ret[] = $res; + } + usort($ret,'compare_paths'); + return $ret; + } + + function dir_get_all_categories_accept_sites($offset,$maxRecords,$sort_mode,$find,$siteId=0) + { + $sort_mode = str_replace("_"," ",$sort_mode); + if($find) { + $mid=" and (title like '%".$find."%' or data like '%".$find."%')"; + } else { + $mid=""; + } + $query = "select * from tiki_directory_categories where allowSites='y' $mid order by $sort_mode limit $offset,$maxRecords"; + $query_cant = "select count(*) from tiki_directory_categories $mid"; + $result = $this->query($query); + $cant = $this->getOne($query_cant); + $ret = Array(); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $res["sites"]=$this->db->getOne("select count(*) from tiki_category_sites where categId=".$res["categId"]); + $res["path"]=$this->dir_get_path_text($res["categId"]); + $res["belongs"]='n'; + if($siteId) { + $belongs = $this->db->getOne("select count(*) from tiki_category_sites where siteId=$siteId and categId=".$res["categId"]); + if($belongs) { + $res["belongs"]='y'; + } + } $ret[] = $res; } usort($ret,'compare_paths'); return $ret; - } - - - - // Replace - function dir_replace_category($parent, $categId, $name, $description, $childrenType, $viewableChildren, $allowSites, $showCount, $editorGroup) - { - $name = addslashes($name); - $descripton = addslashes($description); - - if($categId) { - $query = "update tiki_directory_categories set - name = '$name', - parent = $parent, - description = '$description', - childrenType = '$childrenType', - viewableChildren = $viewableChildren, - allowSites = '$allowSites', - showCount = '$showCount', - editorGroup = '$editorGroup' - where categId=$categId"; - $this->query($query); - } else { - $query = "insert into tiki_directory_categories(parent,hits,name,description,childrenType,viewableChildren,allowSites,showCount,editorGroup) - values($parent,0,'$name','$description','$childrenType',$viewableChildren,'$allowSites','$showCount','$editorGroup')"; - $this->query($query); - } - } - - // Get - function dir_get_category($categId) - { + } + + function dir_validate_site($siteId) + { + $query = "update tiki_directory_sites set isValid='y' where siteId=$siteId"; + $this->query($query); + } + + + function dir_replace_site($siteId,$name,$description,$url,$country,$isValid) + { + $name = addslashes($name); + $description = addslashes($description); + $now=date("U"); + if($siteId) { + $query ="update tiki_directory_sites set + name='$name', + description='$description', + url='$url', + country='$country', + isValid='$isValid', + lastModif=$now + where siteId=$siteId"; + $this->query($query); + return $siteId; + } else { + $query = "insert into tiki_directory_sites(name,description,url,country,isValid,hits,created,lastModif) + values('$name','$description','$url','$country','$isValid',0,$now,$now)"; + $this->query($query); + $siteId=$this->db->getOne("select max(siteId) from tiki_directory_sites where created=$now and name='$name'"); + return $siteId; + } + + } + + + + + // Replace + function dir_replace_category($parent, $categId, $name, $description, $childrenType, $viewableChildren, $allowSites, $showCount, $editorGroup) + { + $name = addslashes($name); + $descripton = addslashes($description); + + if($categId) { + $query = "update tiki_directory_categories set + name = '$name', + parent = $parent, + description = '$description', + childrenType = '$childrenType', + viewableChildren = $viewableChildren, + allowSites = '$allowSites', + showCount = '$showCount', + editorGroup = '$editorGroup' + where categId=$categId"; + $this->query($query); + } else { + $query = "insert into tiki_directory_categories(parent,hits,name,description,childrenType,viewableChildren,allowSites,showCount,editorGroup,sites) + values($parent,0,'$name','$description','$childrenType',$viewableChildren,'$allowSites','$showCount','$editorGroup',0)"; + $this->query($query); + } + } + + // Get + function dir_get_site($siteId) + { + $query = "select * from tiki_directory_sites where siteId=$siteId"; + $result = $this->query($query); + if(!$result->numRows()) return false; + $res = $result->fetchRow(DB_FETCHMODE_ASSOC); + return $res; + } + + function dir_get_category($categId) + { $query = "select * from tiki_directory_categories where categId=$categId"; $result = $this->query($query); if(!$result->numRows()) return false; $res = $result->fetchRow(DB_FETCHMODE_ASSOC); return $res; - } - - // Remove - function dir_remove_category($categId) - { - $query = "select * from tiki_directory_categories where parent=$categId"; - $result = $this->query($query); - // Get each children category - while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { - $categId=$res["categId"]; - $this->dir_remove_category($res["categId"]); - } - // Remove sites from this category - $query = "select * from tiki_category_sites where categId=$categId"; - $result = $this->query($query); - while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { - $siteId=$res["siteId"]; - $query2 = "delete from tiki_category_sites where categId=$categId and siteId=$siteId"; - $result2 = $this->query($query2); - $cant= $this->db->getOne("select count(*) from tiki_category_sites where siteId=$siteId"); - if(!$cant) { - $this->dir_remove_site($siteId); - } - } - // Remove relationshipts involving this category - $query = "delete from tiki_related_categories where categId=$categId or relatedTo=$categId"; - $result = $this->query($query); - // Remove the category - $query = "delete from tiki_directory_categories where categId=$categId"; - $result = $this->query($query); - } - - // Functions to manage sites - - // List - // param: valid (y,n,all) - // param: category id (can be 0=all) - - // Replace - - // Get - - // Remove - function dir_remove_site($siteId) - { - $query = "delete from tiki_directory_sites where siteId=$siteId"; - $result = $this->query($query); - // No need to cascade - } - - // Functions to manage relationship between categories - - // Update relationship - - // Remove relationship - - // Add relationship - - // Functions to manage relationshipts between sites and categories - - // Add relation - - // Remove - - // Functions to validate sites - - // Validate - - // Functions to add hits - - // Site hit - - // Category hit - - // Functions for search stats - - // List searched - - // Add search - -} - -$dirlib= new DirLib($dbTiki); - - -function compare_paths($p1,$p2) { - if($p1["path"]<$p2["path"]) { - return +1; - } elseif($p1["path"]>$p2["path"]) { - return -1; - } else { - return 0; - } - -} - + } + + function dir_remove_site($siteId) + { + $query = "delete from tiki_directory_sites where siteId=$siteId"; + $this->query($query); + $query = "delete from tiki_category_sites where siteId=$siteId"; + $this->query($query); + } + + function dir_add_site_to_category($siteId,$categId) + { + $query = "replace into tiki_category_sites(siteId,categId) values($siteId,$categId)"; + $this->query($query); + } + + function remove_site_from_categories($siteId) + { + $query = "delete from tiki_category_sites where siteId=$siteId"; + $this->query($query); + } + + function remove_site_from_category($siteId,$categId) + { + $query = "delete from tiki_category_sites where siteId=$siteId and categId=$categId"; + $this->query($query); + } + + // Remove + function dir_remove_category($categId) + { + $query = "select * from tiki_directory_categories where parent=$categId"; + $result = $this->query($query); + // Get each children category + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $categId=$res["categId"]; + $this->dir_remove_category($res["categId"]); + } + // Remove sites from this category + $query = "select * from tiki_category_sites where categId=$categId"; + $result = $this->query($query); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + $siteId=$res["siteId"]; + $query2 = "delete from tiki_category_sites where categId=$categId and siteId=$siteId"; + $result2 = $this->query($query2); + $cant= $this->db->getOne("select count(*) from tiki_category_sites where siteId=$siteId"); + if(!$cant) { + $this->dir_remove_site($siteId); + } + } + // Remove relationshipts involving this category + $query = "delete from tiki_related_categories where categId=$categId or relatedTo=$categId"; + $result = $this->query($query); + // Remove the category + $query = "delete from tiki_directory_categories where categId=$categId"; + $result = $this->query($query); + $query = "delete from tiki_category_sites where categId=$categId"; + $result = $this->query($query); + } + + function dir_remove_related($parent,$related) + { + $query = "delete from tiki_related_categories where categId=$parent and relatedTo=$related"; + $this->query($query); + } + + // Functions to manage sites + + // List + // param: valid (y,n,all) + // param: category id (can be 0=all) + + // Replace + + // Get + + // Remove + function dir_remove_site($siteId) + { + $query = "delete from tiki_directory_sites where siteId=$siteId"; + $result = $this->query($query); + // No need to cascade + } + + // Functions to manage relationship between categories + function dir_list_related_categories($parent,$offset,$maxRecords,$sort_mode,$find) + { + $sort_mode = str_replace("_"," ",$sort_mode); + + // Armar query con info de las categories + $query = "select * from tiki_related_categories where categId=$parent limit $offset,$maxRecords"; + $query_cant = "select count(*) from tiki_related_categories where categId=$parent"; + $result = $this->query($query); + $cant = $this->getOne($query_cant); + $ret = Array(); + while($res = $result->fetchRow(DB_FETCHMODE_ASSOC)) { + //$res["path"]=$this->dir_get_path_text($res["relatedTo"]); + $ret[] = $res; + } + $retval = Array(); + $retval["data"] = $ret; + $retval["cant"] = $cant; + return $retval; + } + + function dir_add_categ_rel($parent,$categ) + { + $query = "replace into tiki_related_categories(categId,relatedTo) values('$parent','$categ')"; + $this->query($query); + } + + + // Functions to validate sites + + // Validate + + // Functions to add hits + + // Site hit + + // Category hit + + // Functions for search stats + + // List searched + + // Add search + +} + +$dirlib= new DirLib($dbTiki); + + +function compare_paths($p1,$p2) { + if($p1["path"]<$p2["path"]) { + return +1; + } elseif($p1["path"]>$p2["path"]) { + return -1; + } else { + return 0; + } + +} + ?> |