From 637e2914f5777984c69b5df67f012de9059dbb11 Mon Sep 17 00:00:00 2001 From: niekt0 Date: Thu, 29 Sep 2011 23:58:47 +0200 Subject: [PATCH] get_threaded_children moved to backend --- wwwroot/backend/mysql/backend.inc | 95 ++++++++++++++++++ wwwroot/inc/senate.inc | 2 + .../function.get_threaded_children.php | 98 +++++-------------- 3 files changed, 124 insertions(+), 71 deletions(-) diff --git a/wwwroot/backend/mysql/backend.inc b/wwwroot/backend/mysql/backend.inc index bd765af..563caf6 100644 --- a/wwwroot/backend/mysql/backend.inc +++ b/wwwroot/backend/mysql/backend.inc @@ -607,6 +607,101 @@ public static function getLinkedNodes($node_id,$orderby,$offset,$listing_amount) return $get_linked_nodes; } +// getThreadedChildren +// XXX +// XXX FUCKING MESS, argh +// returns XXX + +// if ($limit > DEF_MAX_GET_THREADED_CHILDREN) +// $limit = DEF_MAX_GET_THREADED_CHILDREN; +// +// // XXX this should go to separate function +// +// if (!empty($params['search'])) { +// if ($params['search_type']=='content') $sql_type.=" and node_content like '%".addslashes($params['search'])."%' "; +// else { +// $q2="select user_id from users where login='".$params['search']."'"; +// $userset=$db->query($q2); +// $userset->next(); +// $id=$userset->getString('user_id'); +// $sql_type=" and nodes.node_creator='$id'"; +// } +// +// } + + +public static function getThreadedChildren($offset,$limit,$orderby,$time,$synapse_time,$security,$link,$search,$search_param) { + global $db; + + $sql_synapse=""; + $sql_type=""; + if ($synapse_time) { $sql_synapse.=" and node_created >'".db_escape_string($synapse_time)."'"; } + + if ($orderby=='' OR $orderby=='desc') { + $orderby="concat(node_vector,'z') desc,depth"; + } else { + $orderby="node_vector asc"; + } + + if ($time) { + $sql_time="node_created > '".db_escape_string($time)."' and"; + } + + // WTF? + if ($security) { $security=" and node_system_access!='private'"; } + else { $security = ""; } + + + if ($search=='content') { + $sql_type.=" and node_content like '%".db_escape_string($search_param)."%' "; + } + if ($search=='user') { + if (!is_numeric($search_param)) { return false; } + $sql_type=" and nodes.node_creator='$search_param'"; + } + + + + if ($link=='yes') $q.="("; + $q.="select nodes.node_id,node_name,node_external_access,external_link,node_parent, + node_system_access,node_children_count,node_creator,node_created,lastchild_created, + k,node_views,node_descendant_count,lastdescendant_created,template_id,node_updated, + length(node_vector) as depth,users.login,node_vector, node_content,'' as synapse_creator + from nodes + left join users on users.user_id=nodes.node_creator + where $sql_time node_vector like '".$node['node_vector']."%' $sql_type + and node_id != '".$node['node_id']."' $security + order by $orderby LIMIT $offset,$limit"; + + if ($link=='yes') { + $q.=" ) UNION (select nodes.node_id,node_name,node_external_access,external_link, + node_parent,node_system_access,node_children_count,node_creator,node_created, + lastchild_created,k,node_views,node_descendant_count,lastdescendant_created, + template_id,node_updated,length(dst_vector) as depth, + users.login,dst_vector as node_vector,node_content,synapse_creator + from neurons + left join nodes on neurons.src=nodes.node_id + left join users on users.user_id=nodes.node_creator + where $sql_time dst_vector like '".$node['node_vector']."%' $sql_synapse $sql_type + and node_id != '".$node['node_id']."' order by $orderby LIMIT $offset,$limit)"; + } + + if ($link=='yes') $q.=" order by $orderby LIMIT $limit"; + + $result=$db->query($q); + + while ($result->next()) { + $child = $result->getRecord(); + transport_process_node($child); + if($child['synapse_creator']!='') $child['node_status']='linked'; + + $get_children_array[]=$child; + } + + return $get_children_array; } + +} + ?> diff --git a/wwwroot/inc/senate.inc b/wwwroot/inc/senate.inc index 95761c5..c7f104d 100644 --- a/wwwroot/inc/senate.inc +++ b/wwwroot/inc/senate.inc @@ -14,7 +14,9 @@ define('DEF_DATA_TEMPLATE',12); define('DEF_GALLERY_TEMPLATE',1041658); define('DEF_LAST_NODE',23); +define('DEF_LISTING_AMMOUNT',42); define('DEF_MAX_LISTING_AMMOUNT',333); +define('DEF_MAX_GET_THREADED_CHILDREN',100); // 1961061 citizens? // 1061495 citizens? diff --git a/wwwroot/inc/smarty/node_methodz/function.get_threaded_children.php b/wwwroot/inc/smarty/node_methodz/function.get_threaded_children.php index b1bb752..5c04c4e 100644 --- a/wwwroot/inc/smarty/node_methodz/function.get_threaded_children.php +++ b/wwwroot/inc/smarty/node_methodz/function.get_threaded_children.php @@ -1,80 +1,36 @@ 100) - $limit = 100; - - if (!empty($params['search'])) { - if ($params['search_type']=='content') $sql_type.=" and node_content like '%".addslashes($params['search'])."%' "; - else { - $q2="select user_id from users where login='".$params['search']."'"; - $userset=$db->query($q2); - $userset->next(); - $id=$userset->getString('user_id'); - $sql_type=" and nodes.node_creator='$id'"; - } - - } - if (!empty($_POST['synapse_time'])) $sql_synapse.=" and node_created >'".$_POST['synapse_time']."'"; - if (empty($params['orderby']) OR $params['orderby']=='desc') { - //$orderby="node_vector desc"; - $orderby="concat(node_vector,'z') desc,depth"; - } - else { - $orderby="node_vector asc"; - } - -if ($params['time']) { -$time=addslashes($params['time']); -$sql_time="node_created > '$time' and"; -} -if ($node['node_system_access']=='public') $security=" and node_system_access!='private'"; -else $security = ""; - - // by br & maniac - - if ($node['node_vector']=='') { - $node['node_vector']='blabla'; // XXX - // system("echo \"node: $node[node_id]\" >> /tmp/blabla.log") ; +function smarty_function_get_threaded_children($params,&$smarty) { + global $error, $node; + + $offset=isset($params['offset']) ? $params['offset'] : ""; + $limit=isset($params['listing_amount']) ? $params['listing_amount'] : DEF_LISTING_AMMOUNT; + $limit=($limit > DEF_MAX_LISTING_AMMOUNT) ? DEF_MAX_LISTING_AMMOUNT : $limit; + $synapse_time= isset($_POST['synapse_time'])? $_POST['synapse_time'] : ""; + $orderby=isset($params['orderby']) ? $params['orderby'] : "desc"; + $time=isset($params['time']) ? $params['time'] : ""; + $link=(isset($params['link']) && $params['link']=='yes') ? "yes" : ""; + + // XXX WTF + if ($node['node_system_access']=='public') { $security="yes"; } + else { $security = ""; } + + if (!empty($params['search'])) { + if ($params['search_type']=='content') { + $search='content'; + $search_param=$params['search']; + } else { + $id=nodes::getUserByLogin($params['search']); + $search='user'; + $search_param=$id; } - - if ($params['link']=='yes') $q.="("; - $q.="select nodes.node_id,node_name,node_external_access,external_link,node_parent,node_system_access,node_children_count,node_creator,node_created,lastchild_created,k,node_views,node_descendant_count,lastdescendant_created,template_id,node_updated,length(node_vector) as depth,users.login,node_vector, node_content,'' as synapse_creator from nodes left join users on users.user_id=nodes.node_creator where $sql_time node_vector like '".$node['node_vector']."%' $sql_type and node_id != '".$node['node_id']."' $security order by $orderby LIMIT $offset,$limit"; - - if ($params['link']=='yes') { - $q.=" ) UNION (select nodes.node_id,node_name,node_external_access,external_link,node_parent,node_system_access,node_children_count,node_creator,node_created,lastchild_created,k,node_views,node_descendant_count,lastdescendant_created,template_id,node_updated,length(dst_vector) as depth, - users.login,dst_vector as node_vector,node_content,synapse_creator from neurons left join nodes on neurons.src=nodes.node_id left join users on users.user_id=nodes.node_creator where $sql_time dst_vector like '".$node['node_vector']."%' $sql_synapse $sql_type and node_id != '".$node['node_id']."' order by $orderby LIMIT $offset,$limit)"; - } - - if ($params['link']=='yes') $q.=" order by $orderby LIMIT $limit"; - - $result=$db->query($q); - - while ($result->next()) { - $child = $result->getRecord(); - transport_process_node($child); - if($child['synapse_creator']!='') $child['node_status']='linked'; - - $get_children_array[]=$child; + } else { + $search=""; + $search_param=""; } - global $time_1, $time_2; - $time_2=$result->getString('node_created'); - $time_1=$get_children_array[0]['node_created']; + nodes::getThreadedChildren($offset,$limit,$orderby,$time,$synapse_time,$security,$link,$search,$search_param); $smarty->assign('get_threaded_children',$get_children_array); - } ?> - -- 2.30.2