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