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']));
22 $activity = ACTIVITY_LIKE;
25 $activity = ACTIVITY_DISLIKE;
28 $activity = ACTIVITY_LIKE;
31 $activity = ACTIVITY_DISLIKE;
39 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
41 logger('like: verb ' . $verb . ' item ' . $item_id);
44 $r = q("SELECT * FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s') AND `id` = `parent` LIMIT 1",
49 if(! $item_id || (! count($r))) {
50 logger('like: no item ' . $item_id);
56 $owner_uid = $item['uid'];
58 if(! can_write_wall($a,$owner_uid)) {
62 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
63 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
70 logger('like: no owner');
75 if((local_user()) && (local_user() == $owner_uid)) {
79 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
80 intval($_SESSION['visitor_id']),
90 $r = q("SELECT `id` FROM `item` WHERE `verb` = '%s' AND `deleted` = 0
91 AND `contact-id` = %d AND ( `parent` = '%s' OR `parent-uri` = '%s') LIMIT 1",
93 intval($contact['id']),
98 // Already voted, undo it
99 $r = q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
100 dbesc(datetime_convert()),
104 proc_run('php',"include/notifier.php","like","$post_id");
108 $uri = item_new_uri($a->get_hostname(),$owner_uid);
110 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
111 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
112 $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
113 $body = $item['body'];
118 <type>$objtype</type>
120 <id>{$item['uri']}</id>
123 <content>$body</content>
127 $bodyverb = t('%1$s likes %2$s\'s %3$s');
128 if($verb === 'dislike')
129 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
131 if(! isset($bodyverb))
137 $arr['uid'] = $owner_uid;
138 $arr['contact-id'] = $contact['id'];
139 $arr['type'] = 'activity';
141 $arr['gravity'] = GRAVITY_LIKE;
142 $arr['parent'] = $item['id'];
143 $arr['parent-uri'] = $item['uri'];
144 $arr['owner-name'] = $owner['name'];
145 $arr['owner-link'] = $owner['url'];
146 $arr['owner-avatar'] = $owner['thumb'];
147 $arr['author-name'] = $contact['name'];
148 $arr['author-link'] = $contact['url'];
149 $arr['author-avatar'] = $contact['thumb'];
151 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
152 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
153 $plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
154 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
156 $arr['verb'] = $activity;
157 $arr['object-type'] = $objtype;
158 $arr['object'] = $obj;
159 $arr['allow_cid'] = $item['allow_cid'];
160 $arr['allow_gid'] = $item['allow_gid'];
161 $arr['deny_cid'] = $item['deny_cid'];
162 $arr['deny_gid'] = $item['deny_gid'];
165 $arr['last-child'] = 0;
167 $post_id = item_store($arr);
169 if(! $item['visible']) {
170 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
176 $arr['id'] = $post_id;
178 call_hooks('post_local_end', $arr);
180 proc_run('php',"include/notifier.php","like","$post_id");
182 return; // NOTREACHED