X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;ds=sidebyside;f=wwwroot%2Fbackend%2Fmysql%2Fbackend.inc;h=d0861e1bd0166329903ca001a0a05389feb0499d;hb=92ac14b2de96259830a9a35cfd4f2f1485006334;hp=7efab4280258b680e9d21ceb91cb58b5fe50b9d9;hpb=229a00474645760cb16603d172f13d6270d9200d;p=mirrors%2FKyberia-bloodline.git diff --git a/wwwroot/backend/mysql/backend.inc b/wwwroot/backend/mysql/backend.inc index 7efab42..d0861e1 100644 --- a/wwwroot/backend/mysql/backend.inc +++ b/wwwroot/backend/mysql/backend.inc @@ -370,9 +370,9 @@ public static function getLast($params) { else $offset=addslashes($params['offset']); global $db,$node; - if ($node['node_id']==23) { + if ($node['node_id']==DEF_LAST_NODE) { $interval=" nodes.node_created>NOW()-INTERVAL 65 HOUR and"; - $params['vector']="00"; + $vector="00"; } else { $vector=$node['node_vector']; @@ -482,8 +482,226 @@ public static function getSynapseWeight($user_id,$node_id){ if (! ($synapse_weight) ) { $synapse_weight = 1;} return $synapse_weight; +} + +// getNodeUserlist + +// Get list of users currently viewing specified node. +// Secure. +// Returns list of (login, user_id) + +public static function getNodeUserlist($node_id) { + + global $db; + if (!is_numeric($node_id)) + { return -1; } + + + $set=$db->query("select login,user_id from users where user_action_id='$node_id'"); + while ($set->next()) { + $userlist[]=$set->getRecord(); + } + + return $userlist; +} + +// getNodeCommanders + +// Get logins of all node commanders (used in configure) +// Secure. +// Returns list of (node_permission, login) + +public static function getNodeCommanders($node_id) { + global $db; + + if (!is_numeric($node_id)) + { return -1; } + + $set=$db->query("select node_permission,users.login from node_access + left join users on node_access.user_id=users.user_id where + node_id='$node_id' and node_permission!='' order by node_permission"); + + while ($set->next()) { + $commanders[$set->getString('node_permission')].=$set->getString('login').";"; + } + + return $commanders; +} + +// logout + +// Log out user. +// Secure + +public static function logout() { + global $db; + $q="update users set user_action_id=null where user_id='".$_SESSION['user_id']."'"; + $db->query($q); +} + +// getNodesByType + +// XXX +// Secure +// returns xxx + +public static function getNodesByType($vector,$user_id,$type,$orderby,$offset,$listing_amount) { + global $db; + + if ((!is_numeric($user_id)) + or (!is_numeric($offset)) + or (!is_numeric($listing_amount)) + or ($vector && !is_numeric($vector)) + or (!is_numeric($type))) + { return -1; } + + $orderby=db_escape_string($orderby); + + + $q="select parent.node_name as parent_name,users.*,nodes.*,node_access.node_user_subchild_count from nodes + left join nodes as parent on parent.node_id=nodes.node_parent + left join node_access on node_access.node_id=nodes.node_id and node_access.user_id='$user_id' + left join users on users.user_id=nodes.node_creator where "; + if ($vector) $q.="nodes.node_vector like '$vector%' and"; + $q.=" nodes.template_id='$type' and nodes.node_system_access!='private'"; + if ($orderby) $q.=" order by $orderby "; + else $q.=" order by nodes.node_id desc "; + $q.= " LIMIT $offset,$listing_amount "; + $set=$db->query($q); + while ($set->next()) $result[]=$set->getRecord(); + + return $result; +} + +// getLinkedNodes + +// XXX +// Secure +// returns XXX + +public static function getLinkedNodes($node_id,$orderby,$offset,$listing_amount) { + global $db; + + if ((!is_numeric($node_id)) + or (!is_numeric($offset)) + or (!is_numeric($listing_amount))) + { return false; } // XXX check return value by caller? + $orderby=db_escape_string($orderby); + + $q="select neurons.synapse_created,node_content,author.login,linker.login as linker,nodes.* from neurons + left join nodes on neurons.src=nodes.node_id + left join users as linker on neurons.synapse_creator=linker.user_id + left join users as author on nodes.node_creator=author.user_id + where dst='$node_id' and link in ('hard','bookmark') + order by $orderby desc limit $offset , $listing_amount"; + + $result=$db->query($q); + while ($result->next()) { + $array=$result->getRecord(); + transport_process_node($array); // XXX + $array['node_status']="linked"; + $array['node_created']=$array['synapse_created']; + $get_linked_nodes[]=$array; + } + return (isset($get_linked_nodes) ? $get_linked_nodes : false); +} + +// 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; } + } ?>