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 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
105 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" &",
110 $uri = item_new_uri($a->get_hostname(),$owner_uid);
112 $post_type = (($item['resource-id']) ? t('photo') : t('status'));
113 $objtype = (($item['resource-id']) ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
114 $link = xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . '" />' . "\n") ;
115 $body = $item['body'];
120 <type>$objtype</type>
122 <id>{$item['uri']}</id>
125 <content>$body</content>
129 $bodyverb = t('likes');
130 if($verb === 'dislike')
131 $bodyverb = t('doesn\'t like');
133 if(! isset($bodyverb))
139 $arr['uid'] = $owner_uid;
140 $arr['contact-id'] = $contact['id'];
141 $arr['type'] = 'activity';
143 $arr['gravity'] = GRAVITY_LIKE;
144 $arr['parent'] = $item['id'];
145 $arr['parent-uri'] = $item['uri'];
146 $arr['owner-name'] = $owner['name'];
147 $arr['owner-link'] = $owner['url'];
148 $arr['owner-avatar'] = $owner['thumb'];
149 $arr['author-name'] = $contact['name'];
150 $arr['author-link'] = $contact['url'];
151 $arr['author-avatar'] = $contact['thumb'];
152 $arr['body'] = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]' . ' ' . t('likes') . ' '
153 . '[url=' . $owner['url'] . ']' . $owner['name'] . t('\'s') . '[/url]' . ' '
154 . '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]' ;
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",
177 $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
179 proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" &",
182 return; // NOTREACHED