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( t('Permission denied.') . EOL) ;
38 $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
45 $str_group_allow = perms2str($_POST['group_allow']);
46 $str_contact_allow = perms2str($_POST['contact_allow']);
47 $str_group_deny = perms2str($_POST['group_deny']);
48 $str_contact_deny = perms2str($_POST['contact_deny']);
50 $title = notags(trim($_POST['title']));
51 $body = escape_tags(trim($_POST['body']));
52 $location = notags(trim($_POST['location']));
55 notice( t('Empty post discarded.') . EOL );
56 goaway($a->get_baseurl() . "/" . $_POST['return'] );
60 // get contact info for poster
64 if(($_SESSION['uid']) && ($_SESSION['uid'] == $profile_uid)) {
65 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
66 intval($_SESSION['uid'])
70 if((x($_SESSION,'visitor_id')) && (intval($_SESSION['visitor_id']))) {
71 $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
72 intval($_SESSION['visitor_id'])
79 $contact_id = $author['id'];
82 // get contact info for owner
84 if($profile_uid == $_SESSION['uid']) {
85 $contact_record = $author;
88 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
92 $contact_record = $r[0];
95 $post_type = notags(trim($_POST['type']));
97 if($post_type == 'net-comment') {
98 if($parent_item !== null) {
99 if($parent_item['type'] == 'remote')
100 $post_type = 'remote-comment';
102 $post_type = 'wall-comment';
106 $notify_type = (($parent) ? 'comment-new' : 'wall-new' );
108 $uri = item_new_uri($a->get_hostname(),$profile_uid);
110 $r = q("INSERT INTO `item` (`uid`,`type`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`,
111 `author-name`, `author-link`, `author-avatar`, `created`,
112 `edited`, `changed`, `uri`, `title`, `body`, `location`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`)
113 VALUES( %d, '%s', %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' )",
114 intval($profile_uid),
117 dbesc($contact_record['name']),
118 dbesc($contact_record['url']),
119 dbesc($contact_record['thumb']),
120 dbesc($author['name']),
121 dbesc($author['url']),
122 dbesc($author['thumb']),
123 dbesc(datetime_convert()),
124 dbesc(datetime_convert()),
125 dbesc(datetime_convert()),
130 dbesc($str_contact_allow),
131 dbesc($str_group_allow),
132 dbesc($str_contact_deny),
133 dbesc($str_group_deny)
135 $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1",
138 $post_id = $r[0]['id'];
142 // This item is the last leaf and gets the comment box, clear any ancestors
143 $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ",
144 dbesc(datetime_convert()),
148 // Inherit ACL's from the parent item.
149 // TODO merge with subsequent UPDATE operation and save a db write
151 $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'
152 WHERE `id` = %d LIMIT 1",
153 dbesc($parent_item['allow_cid']),
154 dbesc($parent_item['allow_gid']),
155 dbesc($parent_item['deny_cid']),
156 dbesc($parent_item['deny_gid']),
160 if(($user['notify-flags'] & NOTIFY_COMMENT) && ($contact_record != $author)) {
161 require_once('bbcode.php');
162 $from = $author['name'];
163 $tpl = file_get_contents('view/cmnt_received_eml.tpl');
164 $email_tpl = replace_macros($tpl, array(
165 '$sitename' => $a->config['sitename'],
166 '$siteurl' => $a->get_baseurl(),
167 '$username' => $user['username'],
168 '$email' => $user['email'],
170 '$body' => strip_tags(bbcode($body))
173 $res = mail($user['email'], $from . t(" commented on your item at ") . $a->config['sitename'],
174 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
180 if(($user['notify-flags'] & NOTIFY_WALL) && ($contact_record != $author)) {
181 require_once('bbcode.php');
182 $from = $author['name'];
183 $tpl = file_get_contents('view/wall_received_eml.tpl');
184 $email_tpl = replace_macros($tpl, array(
185 '$sitename' => $a->config['sitename'],
186 '$siteurl' => $a->get_baseurl(),
187 '$username' => $user['username'],
188 '$email' => $user['email'],
190 '$body' => strip_tags(bbcode($body))
193 $res = mail($user['email'], $from . t(" posted on your profile wall at ") . $a->config['sitename'],
194 $email_tpl,t("From: Administrator@") . $a->get_hostname() );
198 $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1
199 WHERE `id` = %d LIMIT 1",
201 dbesc(($parent == $post_id) ? $uri : $parent_item['uri']),
202 dbesc(datetime_convert()),
205 // photo comments turn the corresponding item visible to the profile wall
206 if(! $parent_item['visible']) {
207 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1",
208 intval($parent_item['id'])
213 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
215 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$notify_type\" \"$post_id\" > notify.out &",
218 goaway($a->get_baseurl() . "/" . $_POST['return'] );
219 return; // NOTREACHED
222 function item_content(&$a) {
224 if((! local_user()) && (! remote_user()))
227 require_once('include/security.php');
229 $uid = $_SESSION['uid'];
231 if(($a->argc == 3) && ($a->argv[1] == 'drop') && intval($a->argv[2])) {
233 // locate item to be deleted
235 $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1",
240 notice( t('Item not found.') . EOL);
241 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
245 // check if logged in user is either the author or owner of this item
247 if(($_SESSION['visitor_id'] == $item['contact-id']) || ($_SESSION['uid'] == $item['uid'])) {
251 $r = q("UPDATE `item` SET `deleted` = 1, `body` = '', `edited` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1",
252 dbesc(datetime_convert()),
253 dbesc(datetime_convert()),
257 // If item is a link to a photo resource, nuke all the associated photos
258 // (visitors will not have photo resources)
259 // This only applies to photos uploaded from the photos page. Photos inserted into a post do not
260 // generate a resource-id and therefore aren't intimately linked to the item.
262 if(strlen($item['resource-id'])) {
263 $q("DELETE FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d ",
264 dbesc($item['resource-id']),
270 // If it's the parent of a comment thread, kill all the kids
272 if($item['uri'] == $item['parent-uri']) {
273 $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s', `body` = ''
274 WHERE `parent-uri` = '%s' AND `uid` = %d ",
275 dbesc(datetime_convert()),
276 dbesc(datetime_convert()),
277 dbesc($item['parent-uri']),
283 // ensure that last-child is set in case the comment that had it just got wiped.
284 q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ",
285 dbesc(datetime_convert()),
286 dbesc($item['parent-uri']),
289 // who is the last child now?
290 $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 ORDER BY `edited` DESC LIMIT 1",
291 dbesc($item['parent-uri'])
294 q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1",
299 $drop_id = intval($item['id']);
300 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
302 // send the notification upstream/downstream as the case may be
304 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" > drop.out &",
307 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
311 notice( t('Permission denied.') . EOL);
312 goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);