3 require_once('include/security.php');
4 require_once('include/bbcode.php');
5 require_once('include/items.php');
8 function like_content(&$a) {
10 if(! local_user() && ! remote_user()) {
14 $verb = notags(trim($_GET['verb']));
21 $activity = ACTIVITY_LIKE;
24 $activity = ACTIVITY_DISLIKE;
27 $activity = ACTIVITY_LIKE;
30 $activity = ACTIVITY_DISLIKE;
38 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
40 $r = q("SELECT * FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s') AND `id` = `parent` LIMIT 1",
45 if(! $item_id || (! count($r))) {
51 $owner_uid = $item['uid'];
53 if(! can_write_wall($a,$owner_uid)) {
57 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
58 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
69 if((local_user()) && (get_uid() == $owner_uid)) {
73 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
74 intval($_SESSION['visitor_id']),
84 $r = q("SELECT `id` FROM `item` WHERE `verb` = '%s' AND `deleted` = 0
85 AND `contact-id` = %d AND ( `parent` = '%s' OR `parent-uri` = '%s') LIMIT 1",
87 intval($contact['id']),
92 // Already voted, undo it
93 $r = q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
94 dbesc(datetime_convert()),
98 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
99 $proc_debug = get_config('system','proc_debug');
101 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" $proc_debug &",
106 $uri = item_new_uri($a->get_hostname(),$owner_uid);
108 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
109 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
110 $link = $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'];
111 $body = $item['body'];
116 <type>$objtype</type>
118 <id>{$item['uri']}</id>
121 <content>$body</content>
125 $bodyverb = t('likes');
126 if($verb == 'dislike')
127 $bodyverb = t('doesn\'t like');
129 if(! isset($bodyverb))
135 $arr['uid'] = $owner_uid;
136 $arr['contact-id'] = $contact['id'];
137 $arr['type'] = 'activity';
139 $arr['gravity'] = GRAVITY_LIKE;
140 $arr['parent'] = $item['id'];
141 $arr['parent-uri'] = $item['uri'];
142 $arr['owner-name'] = $owner['name'];
143 $arr['owner-link'] = $owner['url'];
144 $arr['owner-avatar'] = $owner['thumb'];
145 $arr['author-name'] = $contact['name'];
146 $arr['author-link'] = $contact['url'];
147 $arr['author-avatar'] = $contact['thumb'];
148 $arr['body'] = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . ' ' . t('likes') . ' '
149 . '[url=' . $owner['url'] . ']' . $owner['name'] . t('\'s') . '[/url]' . ' '
150 . '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]' ;
152 $arr['verb'] = $activity;
153 $arr['object-type'] = $objtype;
154 $arr['object'] = $obj;
155 $arr['allow_cid'] = $item['allow_cid'];
156 $arr['allow_gid'] = $item['allow_gid'];
157 $arr['deny_cid'] = $item['deny_cid'];
158 $arr['deny_gid'] = $item['deny_gid'];
161 $arr['last-child'] = 0;
163 $post_id = item_store($arr);
166 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
167 $proc_debug = get_config('system','proc_debug');
169 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" $proc_debug &",
172 return; // NOTREACHED