3 function item_post(&$a) {
5 if((! local_user()) && (! remote_user()))
8 require_once('include/security.php');
10 $uid = $_SESSION['uid'];
13 $parent = ((x($_POST,'parent')) ? intval($_POST['parent']) : 0);
18 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
22 notice( t('Unable to locate original post.') . EOL);
23 goaway($a->get_baseurl() . "/" . $_POST['return'] );
28 $profile_uid = ((x($_POST,'profile_uid')) ? intval($_POST['profile_uid']) : 0);
31 if(! can_write_wall($a,$profile_uid)) {
32 notice("Permission denied." . EOL) ;
38 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
45 $str_group_allow = '';
46 $group_allow = $_POST['group_allow'];
47 if(is_array($group_allow)) {
48 array_walk($group_allow,'sanitise_acl');
49 $str_group_allow = implode('',$group_allow);
52 $str_contact_allow = '';
53 $contact_allow = $_POST['contact_allow'];
54 if(is_array($contact_allow)) {
55 array_walk($contact_allow,'sanitise_acl');
56 $str_contact_allow = implode('',$contact_allow);
60 $group_deny = $_POST['group_deny'];
61 if(is_array($group_deny)) {
62 array_walk($group_deny,'sanitise_acl');
63 $str_group_deny = implode('',$group_deny);
66 $str_contact_deny = '';
67 $contact_deny = $_POST['contact_deny'];
68 if(is_array($contact_deny)) {
69 array_walk($contact_deny,'sanitise_acl');
70 $str_contact_deny = implode('',$contact_deny);
73 $title = notags(trim($_POST['title']));
74 $body = escape_tags(trim($_POST['body']));
77 notice( t('Empty post discarded.') . EOL );
78 goaway($a->get_baseurl() . "/" . $_POST['return'] );
82 // get contact info for poster
86 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
87 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
88 intval($_SESSION['uid'])
92 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
93 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
94 intval($_SESSION['visitor_id'])
101 $contact_id = $author['id'];
104 // get contact info for owner
106 if($profile_uid == $_SESSION['uid']) {
107 $contact_record = $author;
110 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
114 $contact_record = $r[0];
117 $post_type = notags(trim($_POST['type']));
119 if($post_type == 'net-comment') {
120 if($parent_item !== null) {
121 if($parent_item['type'] == 'remote')
122 $post_type = 'remote-comment';
124 $post_type = 'wall-comment';
128 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
132 $hash = random_string();
134 $uri = "urn:X-dfrn:" . $a->get_hostname() . ':' . $profile_uid . ':' . $hash;
136 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
140 } while($dups == true);
143 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
144 `author-name`, `author-link`, `author-avatar`, `created`,
145 `edited`, `uri`, `title`, `body`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
146 VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
147 intval($profile_uid),
150 dbesc($contact_record['name']),
151 dbesc($contact_record['url']),
152 dbesc($contact_record['thumb']),
153 dbesc($author['name']),
154 dbesc($author['url']),
155 dbesc($author['thumb']),
161 dbesc($str_contact_allow),
162 dbesc($str_group_allow),
163 dbesc($str_contact_deny),
164 dbesc($str_group_deny)
166 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
169 $post_id = $r[0]['id'];
173 // This item is the last leaf and gets the comment box, clear any ancestors
174 $r = q("UPDATE `item` SET `last-child` = 0 WHERE `parent` = %d ",
178 // Inherit ACL's from the parent item.
179 // TODO merge with subsequent UPDATE operation and save a db write
181 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
182 WHERE `id` = %d LIMIT 1",
183 dbesc($parent_item['allow_cid']),
184 dbesc($parent_item['allow_gid']),
185 dbesc($parent_item['deny_cid']),
186 dbesc($parent_item['deny_gid']),
190 if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
191 require_once('bbcode.php');
192 $from = $author['name'];
193 $tpl = file_get_contents('view/cmnt_received_eml.tpl');
194 $email_tpl = replace_macros($tpl, array(
195 '$sitename' => $a->config['sitename'],
196 '$siteurl' => $a->get_baseurl(),
197 '$username' => $user['username'],
198 '$email' => $user['email'],
200 '$body' => strip_tags(bbcode($body))
203 $res = mail($user['email'], $from . t(" commented on your item at ") . $a->config['sitename'],
204 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
210 if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
211 require_once('bbcode.php');
212 $from = $author['name'];
213 $tpl = file_get_contents('view/wall_received_eml.tpl');
214 $email_tpl = replace_macros($tpl, array(
215 '$sitename' => $a->config['sitename'],
216 '$siteurl' => $a->get_baseurl(),
217 '$username' => $user['username'],
218 '$email' => $user['email'],
220 '$body' => strip_tags(bbcode($body))
223 $res = mail($user['email'], $from . t(" posted on your profile wall at ") . $a->config['sitename'],
224 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
228 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `last-child` = 1, `visible` = 1
229 WHERE `id` = %d LIMIT 1",
231 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
234 // photo comments turn the corresponding item visible to the profile wall
235 if(! $parent_item['visible']) {
236 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
237 intval($parent_item['id'])
241 $url = $a->get_baseurl();
242 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
244 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"$notify_type\" \"$post_id\" &",
247 goaway($a->get_baseurl() . "/" . $_POST['return'] );
248 return; // NOTREACHED
251 function item_content(&$a) {
253 if((! local_user()) && (! remote_user()))
256 require_once('include/security.php');
258 $uid = $_SESSION['uid'];
260 if(($a->argc == 3) && ($a->argv[1] == 'drop') && intval($a->argv[2])) {
262 // locate item to be deleted
264 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
269 notice( t('Item not found.') . EOL);
270 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
274 // check if logged in user is either the author or owner of this item
276 if(($_SESSION['visitor_id'] == $item['contact-id']) || ($_SESSION['uid'] == $item['uid'])) {
280 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s' WHERE `id` = %d LIMIT 1",
281 dbesc(datetime_convert()),
285 // If item is a link to a photo resource, nuke all the associated photos
286 // (visitors will not have photo resources)
287 // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
288 // generate a resource-id and therefore aren't intimately linked to the item.
290 if(strlen($item['resource-id'])) {
291 $q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
292 dbesc($item['resource-id']),
298 // If it's the parent of a comment thread, kill all the kids
300 if($item['uri'] == $item['parent-uri']) {
301 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s'
302 WHERE `parent-uri` = '%s' AND `uid` = %d ",
303 dbesc(datetime_convert()),
304 dbesc($item['parent-uri']),
310 $url = $a->get_baseurl();
311 $drop_id = intval($item['id']);
312 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
314 // send the notification upstream/downstream as the case may be
316 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$url\" \"drop\" \"$drop_id\" &",
319 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
323 notice( t('Permission denied.') . EOL);
324 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);