]> git.mxchange.org Git - friendica.git/blob - mod/item.php
672084fe85e21a7464aef580c181ec7d3c2250f3
[friendica.git] / mod / item.php
1 <?php
2
3 function sanitise_intacl(&$item) {
4         $item = '<' . intval(notags(trim($item))) . '>';
5 }
6
7
8 function sanitise_acl(&$item) {
9         $item = '<' . notags(trim($item)) . '>';
10 }
11
12 function item_post(&$a) {
13
14         if((! local_user()) && (! remote_user()))
15                 return;
16
17         require_once('include/security.php');
18
19         $uid = $_SESSION['uid'];
20         $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
21         $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
22
23         if(! can_write_wall($a,$profile_uid)) {
24                 notice("Permission denied." . EOL) ;
25                 return;
26         }
27         
28         $str_group_allow = '';
29         $group_allow = $_POST['group_allow'];
30         if(is_array($group_allow)) {
31                 array_walk($group_allow,'sanitise_acl');
32                 $str_group_allow = implode('',$group_allow);
33         }
34
35         $str_contact_allow = '';
36         $contact_allow = $_POST['contact_allow'];
37         if(is_array($contact_allow)) {
38                 array_walk($contact_allow,'sanitise_intacl');
39                 $str_contact_allow = implode('',$contact_allow);
40         }
41
42         $str_group_deny = '';
43         $group_deny = $_POST['group_deny'];
44         if(is_array($group_deny)) {
45                 array_walk($group_deny,'sanitise_acl');
46                 $str_group_deny = implode('',$group_deny);
47         }
48
49         $str_contact_deny = '';
50         $contact_deny = $_POST['contact_deny'];
51         if(is_array($contact_deny)) {
52                 array_walk($contact_deny,'sanitise_intacl');
53                 $str_contact_deny = implode('',$contact_deny);
54         }
55
56
57         $body = escape_tags(trim($_POST['body']));
58
59         if(! strlen($body)) {
60                 notice("Empty post discarded." . EOL );
61                 goaway($a->get_baseurl() . "/profile/$profile_uid");
62         }
63
64         if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id'])))
65                 $contact_id = $_SESSION['visitor_id'];
66         else {
67                 $r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
68                         intval($_SESSION['uid']));
69                 if(count($r))
70                         $contact_id = $r[0]['id'];
71         }       
72
73         $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
74
75         if($_POST['type'] == 'jot') {
76
77                 do {
78                         $dups = false;
79                         $hash = random_string();
80                         $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
81                         dbesc($hash));
82                         if(count($r))
83                                 $dups = true;
84                 } while($dups == true);
85
86
87                 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`created`,`edited`,`hash`,`body`,
88                         `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
89                         VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
90                         intval($profile_uid),
91                         "jot",
92                         intval($contact_id),
93                         datetime_convert(),
94                         datetime_convert(),
95                         dbesc($hash),
96                         dbesc(escape_tags(trim($_POST['body']))),
97                         dbesc($str_contact_allow),
98                         dbesc($str_group_allow),
99                         dbesc($str_contact_deny),
100                         dbesc($str_group_deny)
101
102                 );
103                 $r = q("SELECT `id` FROM `item` WHERE `hash` = '%s' LIMIT 1",
104                         dbesc($hash));
105                 if(count($r)) {
106                         $post_id = $r[0]['id'];
107                         if($parent) {
108                                 $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent` = %d ",
109                                         intval($parent)
110                                 );
111                         }
112                         else {
113                                 $parent = $post_id;
114                         }
115
116                         $r = q("UPDATE `item` SET `parent` = %d, `last-child` = 1, `visible` = 1
117                                 WHERE `id` = %d LIMIT 1",
118                                 intval($parent),
119                                 intval($post_id));
120                 }
121
122                 $url = bin2hex($a->get_baseurl());
123
124                 proc_close(proc_open("php include/notifier.php $url $notify_type $post_id > notify.log &",
125                         array(),$foo));
126
127         }
128         goaway($a->get_baseurl() . "/profile/$profile_uid");
129
130
131
132
133
134
135
136 }