Kyberia v2.3 - 1st revision from SVN (Without patches of kyberia.sk team)
[mirrors/Kyberia-bloodline.git] / inc / nodes.inc
CommitLineData
e586807d 1<?php
b42b2bf9
H
2 if (!function_exists('str_split')){
3 function str_split($string, $split_length=1){
4
5 if ($split_length < 1){
6 return false;
7 }
8
9 for ($pos=0, $chunks = array(); $pos < strlen($string); $pos+=$split_length){
10 $chunks[] = substr($string, $pos, $split_length);
11 }
12 return $chunks;
13 }
14 }
e586807d
H
15
16class nodes {
17
b42b2bf9 18
e586807d
H
19
20function addNode($params) {
b42b2bf9
H
21 global $db,$node,$error,$error_messages;
22 $parent_id=$params['node_parent'];
23
24 if (!is_numeric($parent_id)) {
25 $parent_id=$node['node_id'];
26 }
27
28 $parent_permissions=permissions::checkPermissions($parent_id);
29 if (!$parent_permissions['w']) {
30 $error=$error_messages['WRITE_PERMISSION_ERROR'];
31 log::log('add','error','WRITE_PERMISSION_ERROR');
32 return false;
33 }
34
e586807d
H
35
36 $kset=$db->query("select user_k from users where user_id='$params[node_creator]'");
37 $kset->next();
38 $user_k=$kset->getString('user_k');
39
b42b2bf9
H
40 if ($params['flag']=='registration') $params['node_creator']=UBIK_ID;
41
42 if (!$user_k && $params['node_creator']!=UBIK_ID) {
43 $error=$error_messages['K_SPENT'];
44 return false;
45 }
e586807d
H
46
47
48
b42b2bf9
H
49 $set=$db->query("select node_vector,node_children_count from nodes where node_id='$parent_id'");
50 $set->next();
51 $parent_vector=$set->getString('node_vector');
e586807d 52
b42b2bf9
H
53 if ($set->getInt('node_children_count')>MAX_CHILDREN) {
54 $error=$error_messages['MAX_CHILDREN'];
55 return false;
56 }
e586807d 57
b42b2bf9
H
58 //working with external links
59 $external_link=$params['external_link'];
e586807d 60
b42b2bf9
H
61 $template_id=$params['template_id'];
62 if (!is_numeric($template_id)) $template_id=DEFAULT_TEMPLATE_ID;
63
64 $q="insert into nodes set
65node_name='".$params['node_name']."',
e586807d
H
66node_external_access='".$node['node_external_access']."',
67node_system_access='".$node['node_system_access']."',
68node_creator='".$params['node_creator']."',
69template_id='".$template_id."',
70external_link='".$external_link."',
b42b2bf9 71node_parent='".$parent_id."',
e586807d 72node_views=0,node_created=NOW(),
b42b2bf9 73node_content='".$params['node_content']."',
e586807d 74node_vector='".$params['node_vector']."'";
b42b2bf9 75 $db->query("start transaction");
e586807d
H
76 $db->query($q);
77 $id=$db->getLastInsertId();
b42b2bf9
H
78
79//node_content MyIsam only for FULLTEXT !!!
80// $db->query("insert into node_content set node_id='$id',node_content='".$params['node_content']."'");
81
e586807d 82 $new_id=str_pad($id,VECTOR_CHARS,"0",STR_PAD_LEFT);
b42b2bf9
H
83 $new_vector=trim($parent_vector,"z").$new_id;
84
85 if ($params['flag']=='registration') $db->query("update nodes set node_system_access='public',node_external_access='yes',node_creator=$id where node_id=$id");
e586807d 86
b42b2bf9
H
87 $db->query("update nodes set node_vector='$new_vector' where node_id='$id'");
88 $db->query("update nodes set node_children_count=node_children_count+1 where node_id='$parent_id'");
e586807d
H
89
90 $node_vector=trim(chunk_split($new_vector,VECTOR_CHARS,';'),';');
b42b2bf9
H
91
92 $ancestors=explode(";",$node_vector);
93 foreach($ancestors as $key => $ancestor_id) {
94 if ($key) {
95 $ancestor_id=ltrim($ancestor_id,'0');
96 $db->query("update nodes set node_descendant_count=node_descendant_count+1,lastdescendant_created=NOW() where node_id='$ancestor_id'");
97 }
98 }
99 $db->query("update node_access set node_user_subchild_count=node_user_subchild_count+1 where node_id='$parent_id'");
100 --$user_k;
e586807d 101 $db->query("update users set user_k='$user_k' where user_id='$params[node_creator]'");
b42b2bf9 102 $db->query("commit");
e586807d
H
103 log::log('add','ok',$id);
104
b42b2bf9
H
105 if ($_POST['code']) {
106 $params['node_creator']=UBIK_ID;
107 $params['node_parent']=WARNING_ZONE;
108 $params['node_name']="node $id added with code_parameter";
109 $params['node_content']="node <a href='/id/$id'>$id</a> added with code_parameter";
110 unset($_POST['code']);
111 nodes::addNode($params);
112 }
113
114 return $id;
e586807d
H
115}
116
117
118function processContent($node_content) {
b42b2bf9 119 global $node;
e586807d
H
120 include_once(SYSTEM_ROOT.'/inc/htmlparse.inc');
121
b42b2bf9
H
122 if ($node['template_id']==$node['node_id'] && $_POST['event']=='configure_content') {
123
124 }
e586807d 125
b42b2bf9
H
126 elseif ($_POST['no_html']) {
127 $node_content=htmlspecialchars($node_content);
128 }
e586807d 129
b42b2bf9
H
130 elseif ($_POST['wiki']) {
131 // load the class file
132 require_once 'Text/Wiki.php';
e586807d 133
b42b2bf9
H
134 // instantiate a Text_Wiki object with the default rule set
135 $wiki =& new Text_Wiki();
e586807d 136
b42b2bf9
H
137 $node_content = $wiki->transform($node_content, 'Xhtml');
138 }
e586807d 139
b42b2bf9 140 elseif ($_POST['code']) {}
e586807d 141
b42b2bf9
H
142 else {
143 global $db,$htmlparse,$error;
144
145 if (!htmlparse::htmlparse($node_content)) {
146 $error=$htmlparse;
147 return false;
148 }
149
150 $node_content = eregi_Replace("((( )|(\n)|(^))+)(http://|ftp://|https://)([[:alnum:]][^,[:space:]]*)","\\2<a target='_blank' href=\"\\6\\7\">\\6\\7</a>",$node_content);
151 $node_content = mysql_real_escape_string($node_content);
152 }
153
154 return $node_content;
e586807d
H
155}
156
157
b42b2bf9
H
158 function getUserByLogin($login) {
159 global $error, $error_messages;
160 $q2="select user_id from users where login='".$login."'";
e586807d
H
161 $userset=$db->query($q2);
162 $userset->next();
163 $id=$userset->getString('user_id');
b42b2bf9
H
164 if (is_numeric($id)) return $id;
165 else {
166 $error = $error_messages['USER_NOT_FOUND'];
167 return false;
168 }
169 }
170
171
172 function getNodeIdByName($name,$external_link=false) {
173 global $db;
174 $q="select node_id from nodes where node_name='$name'";
175 if ($external_link) $q.=" and external_link='$external_link'";
176 $set=$db->query($q);
177 $set->next();
178 return $set->getString('node_id');
179 }
180
181 function getNodeById($node_handle,$user_id, $table_name="nodes") {
182 global $db, $error;
183 $q="select length(concat($table_name.node_vector)) as
184vector_depth,$table_name.*,$table_name.node_creator as
185node_owner_id,creator.node_name as owner,node_access.*,$table_name.node_id as
186node_id,node_parent.node_name as node_parent_name
187from $table_name left join $table_name as creator on creator.node_id=$table_name.node_creator
188left join $table_name as node_parent on $table_name.node_parent=node_parent.node_id
189left join node_access on (node_access.node_id='$node_handle' and node_access.user_id='$user_id')
190where $table_name.node_id='$node_handle'";
191
192 $result=$db->query($q);
193 if (!$result->next()) {
194 return false;
195 }
196 else {
197 $node=$result->getRecord();
198 $node['node_vector']=trim($node['node_vector'],"z");
199 $ancestors=str_split($node['node_vector'],VECTOR_CHARS);
200 foreach ($ancestors as $ancestor) {
201 $node['ancestors'][]=array("name"=>"","link"=>ltrim($ancestor,"0"));
202 }
203 }
204 return $node;
205
206 }
207
208
209 function redirByName($node_handle) {
210 global $db, $error;
211 $user_id=$_SESSION['user_id'];
212 $set=$db->query("select node_id from nodes where node_name='$node_handle' and node_creator='$user_id'");
213 if ($set->next()) {
214 $node_id=$set->getString('node_id');
215 if (!empty($node_id)) {
216 return nodes::getNodeById($node_id,$_SESSION['user_id']);
217 }
218
219 }
220 $set=$db->query("select node_id from nodes where node_name='$node_handle' ");
221 $set->next();
222 $node_id=$set->getString('node_id');
223 if (!empty($node_id)) {
224 return nodes::getNodeById($node_id,$_SESSION['user_id']);
225 }
226
227 }
228
229 function getNodesByName($node_handle) {
230 global $db, $error;
231 $q="select nodes.* from nodes where node_name='$node_handle%'";
232
233 $result=$db->query($q);
234
235 while ($result->next()){
236 $record[]=$result->getRecord();
237 }
238 return $record;
239
240 }
241
242
243
244 function getChildrenNodes($orderby="desc",$offset=0,$limit=DEFAULT_LISTING_AMOUNT) {
245 global $db, $error, $node;
246 $node_handle=$node['node_id'];
247
248 $q="select users.*,nodes.* from nodes
e586807d
H
249left join users on users.user_id=nodes.node_creator where
250node_parent='$node_handle' order by node_created $orderby LIMIT $offset,$limit";
b42b2bf9
H
251 echo $q;
252 $result=$db->query($q);
e586807d 253
b42b2bf9
H
254 while ($result->next()) {
255 $array[]=$result->getRecord();
256 }
e586807d 257
b42b2bf9 258 return $array;
e586807d 259
b42b2bf9 260 }
e586807d
H
261
262
b42b2bf9
H
263 function getThreadedChildrenNodes($orderby="desc",$offset=0,$limit=DEFAULT_LISTING_AMOUNT) {
264 global $db, $error, $node;
265 $node_handle=$node['node_id'];
e586807d 266
b42b2bf9 267 $q="select length(node_vector) as depth,users.login,nodes.* from nodes left join users on users.user_id=nodes.node_creator where node_vector like '".$node['node_vector'].";".$node['node_id']."%' and node_type=3 order by concat(node_vector,';',nodes.node_id,';z') desc,depth LIMIT $offset,$limit";
e586807d 268
b42b2bf9 269 $result=$db->query($q);
e586807d 270
b42b2bf9
H
271 while ($result->next()) {
272 $children_array[]=$result->getRecord();
273 }
e586807d 274
b42b2bf9 275 return $children_array;
e586807d 276
b42b2bf9 277 }
e586807d
H
278
279
280
b42b2bf9
H
281 function getNodeAccessData() {
282 global $node,$db;
283 $q="select users.login,node_access.* from node_access left join users on users.user_id=node_access.user_id where node_id='".$node['node_id']."' and node_permission!=''";
284 $result=$db->query($q);
e586807d
H
285
286 while ($result->next()) {
287 $access_data[]=$result->getRecord();
288 }
289
290 return $access_data;
291
b42b2bf9 292 }
e586807d
H
293}
294
295?>
This page took 0.682391 seconds and 4 git commands to generate.