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']));
23 $activity = ACTIVITY_LIKE;
27 $activity = ACTIVITY_DISLIKE;
35 $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
37 logger('like: verb ' . $verb . ' item ' . $item_id);
40 $r = q("SELECT * FROM `item` WHERE ( `id` = '%s' OR `uri` = '%s') AND `id` = `parent` LIMIT 1",
45 if(! $item_id || (! count($r))) {
46 logger('like: no item ' . $item_id);
52 $owner_uid = $item['uid'];
54 if(! can_write_wall($a,$owner_uid)) {
58 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
59 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
66 logger('like: no owner');
71 if((local_user()) && (local_user() == $owner_uid)) {
75 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
76 intval($_SESSION['visitor_id']),
86 $r = q("SELECT `id` FROM `item` WHERE `verb` = '%s' AND `deleted` = 0
87 AND `contact-id` = %d AND ( `parent` = '%s' OR `parent-uri` = '%s') LIMIT 1",
89 intval($contact['id']),
94 // Already voted, undo it
95 $r = q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
96 dbesc(datetime_convert()),
100 proc_run('php',"include/notifier.php","like","$post_id");
104 $uri = item_new_uri($a->get_hostname(),$owner_uid);
106 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
107 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
108 $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
109 $body = $item['body'];
114 <type>$objtype</type>
116 <id>{$item['uri']}</id>
119 <content>$body</content>
123 $bodyverb = t('%1$s likes %2$s\'s %3$s');
124 if($verb === 'dislike')
125 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
127 if(! isset($bodyverb))
133 $arr['uid'] = $owner_uid;
134 $arr['contact-id'] = $contact['id'];
135 $arr['type'] = 'activity';
137 $arr['gravity'] = GRAVITY_LIKE;
138 $arr['parent'] = $item['id'];
139 $arr['parent-uri'] = $item['uri'];
140 $arr['owner-name'] = $owner['name'];
141 $arr['owner-link'] = $owner['url'];
142 $arr['owner-avatar'] = $owner['thumb'];
143 $arr['author-name'] = $contact['name'];
144 $arr['author-link'] = $contact['url'];
145 $arr['author-avatar'] = $contact['thumb'];
147 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
148 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
149 $plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
150 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
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);
165 if(! $item['visible']) {
166 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
172 $arr['id'] = $post_id;
174 call_hooks('post_local_end', $arr);
176 proc_run('php',"include/notifier.php","like","$post_id");
178 return; // NOTREACHED