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