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)) {
61 // The top level post may have been written by somebody on another system
62 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
63 intval($item['contact-id']),
69 $remote_owner = $r[0];
72 // this represents the post owner on this system.
74 $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
75 WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
82 logger('like: no owner');
87 $remote_owner = $owner;
90 // This represents the person posting
92 if((local_user()) && (local_user() == $owner_uid)) {
96 $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
97 intval($_SESSION['visitor_id']),
107 $r = q("SELECT `id` FROM `item` WHERE `verb` = '%s' AND `deleted` = 0
108 AND `contact-id` = %d AND ( `parent` = '%s' OR `parent-uri` = '%s') LIMIT 1",
110 intval($contact['id']),
115 // Already voted, undo it
116 $r = q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
117 dbesc(datetime_convert()),
121 proc_run('php',"include/notifier.php","like","$post_id");
125 $uri = item_new_uri($a->get_hostname(),$owner_uid);
127 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
128 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
129 $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
130 $body = $item['body'];
135 <type>$objtype</type>
137 <id>{$item['uri']}</id>
140 <content>$body</content>
144 $bodyverb = t('%1$s likes %2$s\'s %3$s');
145 if($verb === 'dislike')
146 $bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
148 if(! isset($bodyverb))
154 $arr['uid'] = $owner_uid;
155 $arr['contact-id'] = $contact['id'];
156 $arr['type'] = 'activity';
157 $arr['wall'] = $item['wall'];
159 $arr['gravity'] = GRAVITY_LIKE;
160 $arr['parent'] = $item['id'];
161 $arr['parent-uri'] = $item['uri'];
162 $arr['owner-name'] = $remote_owner['name'];
163 $arr['owner-link'] = $remote_owner['url'];
164 $arr['owner-avatar'] = $remote_owner['thumb'];
165 $arr['author-name'] = $contact['name'];
166 $arr['author-link'] = $contact['url'];
167 $arr['author-avatar'] = $contact['thumb'];
169 $ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
170 $alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
171 $plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
172 $arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
174 $arr['verb'] = $activity;
175 $arr['object-type'] = $objtype;
176 $arr['object'] = $obj;
177 $arr['allow_cid'] = $item['allow_cid'];
178 $arr['allow_gid'] = $item['allow_gid'];
179 $arr['deny_cid'] = $item['deny_cid'];
180 $arr['deny_gid'] = $item['deny_gid'];
183 $arr['last-child'] = 0;
185 $post_id = item_store($arr);
187 if(! $item['visible']) {
188 $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
194 $arr['id'] = $post_id;
196 call_hooks('post_local_end', $arr);
198 proc_run('php',"include/notifier.php","like","$post_id");
201 // return; // NOTREACHED