51ff3226 |
1 | <?php |
2 | //funkcie na pridanie Re: alebo Re[x]: do nazvu (by Maniax) |
bd9d442f |
3 | function title_reply_callback($_matches) { |
4 | return ($_matches[1].($_matches[2] + 1).$_matches[3]); |
5 | } |
6 | |
51ff3226 |
7 | function title_reply($_in) { |
bd9d442f |
8 | if (preg_match('/^Re[:\[]/', $_in)) { |
9 | if (preg_match('/^Re\[/', $_in)) |
10 | return (preg_replace_callback('/^(Re\[)(\d*)(\].*)$/', 'title_reply_callback', $_in)); |
11 | else return (preg_replace('/^(Re)(:.*)$/', '\1[2]\2', $_in)); |
12 | } else return ('Re: '.$_in); |
51ff3226 |
13 | } |
14 | |
15 | //Pridanie prispevku |
16 | function add() { |
17 | |
18 | global $db,$error,$node,$permissions,$types; |
19 | |
20 | $node_content=$_POST['node_content']; |
21 | $node_parent=$_POST['node_parent']; |
22 | $template_id=$_POST['template_id']; |
23 | if (empty($template_id)) $template_id=4; |
24 | $node_type=$template_id; |
25 | |
26 | if (strlen($node_name)<1){ |
27 | // $error="node_name too short. please write some title"; |
28 | // return false; |
29 | } |
30 | |
31 | $node_name=addslashes(strip_tags($_POST['node_name'])); |
32 | $external_link=addslashes(strip_tags($_POST['external_link'])); |
33 | |
34 | if (!empty($_POST['node_chosen'])) { |
35 | $node_chosen=$_POST['node_chosen']; |
36 | if (count($node_chosen)>1) { |
37 | $error="please select only one node."; |
38 | return false; |
39 | }else { |
40 | $node_parent=addslashes($node_chosen['0']); |
41 | $q="select * from nodes where node_id='".$node_parent."'"; |
42 | $p_set = $db->query($q); |
43 | if($p_set->next()){ |
44 | $node_parent_name = $p_set->getString('node_name'); |
45 | $node_parent_template = $p_set->getString('template_id'); |
46 | } |
47 | } |
48 | }else{ |
49 | $node_parent_name = $node['node_name']; |
50 | $node_parent_template = $node['template_id']; |
51 | } |
52 | |
53 | |
54 | if (empty($node_name)) { |
55 | if (empty($node_parent_name)){ |
56 | $node_name=date("d.m.Y-G:i:s"); |
57 | }elseif ($node_parent_template == "4"){ |
58 | $node_name = title_reply($node_parent_name); |
59 | }else{ |
60 | $node_name=date("d.m.Y-G:i:s"); |
61 | } |
62 | } |
63 | |
64 | if (empty($node_name)) { |
65 | $node_name=date("d.m.Y-G:i:s"); |
66 | } |
67 | $parent_name=$node['node_name']; |
68 | $node_creator=$_SESSION['user_id']; |
69 | |
70 | $node_system_access=$node['node_system_access']; |
71 | |
72 | |
73 | if (empty($node_system_access)) { |
74 | $node_system_access='public'; |
75 | } |
76 | |
77 | $node_external_access=$_POST['node_external_access']; |
78 | if (empty($node_external_access)) { |
79 | $node_external_access='yes'; |
80 | } |
81 | |
82 | |
83 | if (empty($node_content)) { |
84 | $error=$error_messages['ADD_NO_CONTENT']; |
85 | return false; |
86 | } |
87 | |
88 | // prida mood na koniec contentu |
89 | if (is_numeric($_SESSION['mood_id']) && $node['external_link'] != 'db://user' && $node['external_link'] != 'session://user') { |
90 | $node_content .= "\n\n<small>".$_SESSION['mood_content']."</small>"; |
91 | } |
92 | |
93 | $node_content=nodes::processContent($node_content); |
94 | |
95 | if ($node_system_access=='crypto') { |
96 | |
e909f81b |
97 | require(INCLUDE_DIR.'crypto.inc'); |
51ff3226 |
98 | |
99 | if ($_SESSION['crypto'][$node_parent]) { |
100 | $key=$_SESSION['crypto'][$node_parent]; |
101 | } |
102 | else { |
103 | $key = substr(md5(uniqid(rand(), true)),0,8); |
104 | } |
105 | |
106 | $node_content=crypto::crypto($node_content,$key); |
107 | |
108 | |
51ff3226 |
109 | |
110 | } |
111 | |
112 | $params['node_name']=$node_name; |
113 | $params['template_id']=$template_id; |
114 | $params['node_parent']=$node_parent; |
115 | $params['node_system_access']=$node_system_access; |
116 | $params['node_creator']=$_SESSION['user_id']; |
78f1a5f4 |
117 | $params['node_content']=db_escape_string($node_content); |
51ff3226 |
118 | $params['external_link']=$external_link; |
119 | nodes::addNode($params); |
120 | return true; |
bd9d442f |
121 | } |
122 | |
123 | ?> |