2010-09-17 10:10:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once('include/security.php');
|
|
|
|
require_once('include/bbcode.php');
|
|
|
|
require_once('include/items.php');
|
|
|
|
|
|
|
|
|
|
|
|
function like_content(&$a) {
|
|
|
|
|
|
|
|
if(! local_user() && ! remote_user()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
$observer = $a->get_observer();
|
|
|
|
|
|
|
|
|
2010-09-17 10:10:19 +00:00
|
|
|
$verb = notags(trim($_GET['verb']));
|
|
|
|
|
|
|
|
if(! $verb)
|
|
|
|
$verb = 'like';
|
|
|
|
|
2010-11-04 10:57:49 +00:00
|
|
|
|
2010-09-17 10:10:19 +00:00
|
|
|
switch($verb) {
|
|
|
|
case 'like':
|
|
|
|
case 'unlike':
|
|
|
|
$activity = ACTIVITY_LIKE;
|
|
|
|
break;
|
2011-08-18 03:52:18 +00:00
|
|
|
case 'dislike':
|
2010-09-17 10:10:19 +00:00
|
|
|
case 'undislike':
|
|
|
|
$activity = ACTIVITY_DISLIKE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
|
|
|
|
|
2010-11-04 10:57:49 +00:00
|
|
|
logger('like: verb ' . $verb . ' item ' . $item_id);
|
|
|
|
|
|
|
|
|
2012-06-23 12:46:15 +00:00
|
|
|
$r = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
|
2010-09-17 10:10:19 +00:00
|
|
|
dbesc($item_id),
|
|
|
|
dbesc($item_id)
|
|
|
|
);
|
|
|
|
|
|
|
|
if(! $item_id || (! count($r))) {
|
2010-11-04 10:57:49 +00:00
|
|
|
logger('like: no item ' . $item_id);
|
2010-09-17 10:10:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$item = $r[0];
|
|
|
|
|
|
|
|
$owner_uid = $item['uid'];
|
|
|
|
|
|
|
|
if(! can_write_wall($a,$owner_uid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-23 10:12:31 +00:00
|
|
|
$remote_owner = null;
|
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
// fixme
|
|
|
|
// if(! $item['wall']) {
|
2011-09-23 10:12:31 +00:00
|
|
|
// The top level post may have been written by somebody on another system
|
2012-11-06 04:42:12 +00:00
|
|
|
|
|
|
|
// $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
|
|
|
// intval($item['contact-id']),
|
|
|
|
// intval($item['uid'])
|
|
|
|
// );
|
|
|
|
// if(! count($r))
|
|
|
|
// return;
|
|
|
|
// if(! $r[0]['self'])
|
|
|
|
// $remote_owner = $r[0];
|
|
|
|
// }
|
2011-09-23 10:12:31 +00:00
|
|
|
|
|
|
|
// this represents the post owner on this system.
|
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
// $r = q("SELECT `contact`.*, `user`.`nickname` FROM `contact` LEFT JOIN `user` ON `contact`.`uid` = `user`.`uid`
|
|
|
|
// WHERE `contact`.`self` = 1 AND `contact`.`uid` = %d LIMIT 1",
|
|
|
|
// intval($owner_uid)
|
|
|
|
// );
|
|
|
|
// if(count($r))
|
|
|
|
// $owner = $r[0];
|
2010-09-17 10:10:19 +00:00
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
// if(! $owner) {
|
|
|
|
// logger('like: no owner');
|
|
|
|
// return;
|
|
|
|
// }
|
2010-09-17 10:10:19 +00:00
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
// if(! $remote_owner)
|
|
|
|
// $remote_owner = $owner;
|
2011-09-23 10:12:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
// This represents the person posting
|
2010-09-17 10:10:19 +00:00
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
// if((local_user()) && (local_user() == $owner_uid)) {
|
|
|
|
// $contact = $owner;
|
|
|
|
// }
|
|
|
|
// else {
|
|
|
|
// $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
|
|
|
// intval($_SESSION['visitor_id']),
|
|
|
|
// intval($owner_uid)
|
|
|
|
// );
|
|
|
|
// if(count($r))
|
|
|
|
// $contact = $r[0];
|
|
|
|
// }
|
|
|
|
// if(! $contact) {
|
|
|
|
// return;
|
|
|
|
// }
|
2010-09-17 10:10:19 +00:00
|
|
|
|
2012-06-03 05:56:42 +00:00
|
|
|
|
2012-06-03 20:32:17 +00:00
|
|
|
$r = q("SELECT * FROM `item` WHERE `verb` = '%s' AND `deleted` = 0
|
2012-10-02 01:02:11 +00:00
|
|
|
AND `contact-id` = %d AND ( `parent` = '%s' OR `parent_uri` = '%s' OR `thr_parent` = '%s') LIMIT 1",
|
2010-09-17 10:10:19 +00:00
|
|
|
dbesc($activity),
|
|
|
|
intval($contact['id']),
|
|
|
|
dbesc($item_id),
|
2012-07-13 14:09:29 +00:00
|
|
|
dbesc($item_id),
|
|
|
|
dbesc($item['uri'])
|
2010-09-17 10:10:19 +00:00
|
|
|
);
|
|
|
|
if(count($r)) {
|
2012-06-03 20:32:17 +00:00
|
|
|
$like_item = $r[0];
|
|
|
|
|
2010-09-17 10:10:19 +00:00
|
|
|
// Already voted, undo it
|
2012-07-15 03:39:46 +00:00
|
|
|
$r = q("UPDATE `item` SET `deleted` = 1, `unseen` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
|
2010-09-17 10:10:19 +00:00
|
|
|
dbesc(datetime_convert()),
|
2012-06-03 20:32:17 +00:00
|
|
|
intval($like_item['id'])
|
2010-09-17 10:10:19 +00:00
|
|
|
);
|
|
|
|
|
2012-06-03 20:32:17 +00:00
|
|
|
$like_item_id = $like_item['id'];
|
|
|
|
proc_run('php',"include/notifier.php","like","$like_item_id");
|
2010-09-17 10:10:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
|
|
|
|
|
2012-10-04 05:28:19 +00:00
|
|
|
$uri = item_message_id();
|
2010-09-17 10:10:19 +00:00
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
$post_type = (($item['resource_id'] === 'photo') ? $t('photo') : t('status'));
|
|
|
|
|
|
|
|
$links = array(array('rel' => 'alternate','type' => 'text/html',
|
|
|
|
'href' => z_root() . '/display/' . $item['uri']));
|
|
|
|
$objtype = (($item['resource_id'] === 'photo') ? ACTIVITY_OBJ_PHOTO : ACTIVITY_OBJ_NOTE );
|
|
|
|
|
2010-09-17 10:10:19 +00:00
|
|
|
$body = $item['body'];
|
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
$obj = json_encode(array(
|
|
|
|
'type' => $objtype,
|
|
|
|
'id' => $item['uri'],
|
|
|
|
'link' => $links,
|
|
|
|
'title' => $item['title'],
|
|
|
|
'content' => $item['body']
|
|
|
|
));
|
|
|
|
|
2010-09-27 00:24:20 +00:00
|
|
|
if($verb === 'like')
|
2011-03-18 10:02:42 +00:00
|
|
|
$bodyverb = t('%1$s likes %2$s\'s %3$s');
|
2010-09-27 00:24:20 +00:00
|
|
|
if($verb === 'dislike')
|
2011-03-18 10:02:42 +00:00
|
|
|
$bodyverb = t('%1$s doesn\'t like %2$s\'s %3$s');
|
2010-09-17 10:10:19 +00:00
|
|
|
|
|
|
|
if(! isset($bodyverb))
|
|
|
|
return;
|
|
|
|
|
|
|
|
$arr = array();
|
|
|
|
|
|
|
|
$arr['uri'] = $uri;
|
|
|
|
$arr['uid'] = $owner_uid;
|
2012-11-06 04:42:12 +00:00
|
|
|
// $arr['contact-id'] = $contact['id'];
|
2010-09-17 10:10:19 +00:00
|
|
|
$arr['type'] = 'activity';
|
2012-11-06 04:42:12 +00:00
|
|
|
// $arr['wall'] = $item['wall'];
|
|
|
|
// $arr['origin'] = 1;
|
|
|
|
// $arr['gravity'] = GRAVITY_LIKE;
|
2010-09-17 10:10:19 +00:00
|
|
|
$arr['parent'] = $item['id'];
|
2012-08-16 05:33:37 +00:00
|
|
|
$arr['parent_uri'] = $item['uri'];
|
2012-10-02 01:02:11 +00:00
|
|
|
$arr['thr_parent'] = $item['uri'];
|
2012-11-06 04:42:12 +00:00
|
|
|
$arr['owner_xchan'] = $remote_owner['xchan_hash'];
|
|
|
|
$arr['author_xchan'] = $observer['xchan_hash'];
|
|
|
|
|
2011-03-18 10:02:42 +00:00
|
|
|
|
|
|
|
$ulink = '[url=' . $contact['url'] . ']' . $contact['name'] . '[/url]';
|
|
|
|
$alink = '[url=' . $item['author-link'] . ']' . $item['author-name'] . '[/url]';
|
|
|
|
$plink = '[url=' . $a->get_baseurl() . '/display/' . $owner['nickname'] . '/' . $item['id'] . ']' . $post_type . '[/url]';
|
|
|
|
$arr['body'] = sprintf( $bodyverb, $ulink, $alink, $plink );
|
2010-09-17 10:10:19 +00:00
|
|
|
|
|
|
|
$arr['verb'] = $activity;
|
2012-08-16 05:33:37 +00:00
|
|
|
$arr['obj_type'] = $objtype;
|
2010-09-17 10:10:19 +00:00
|
|
|
$arr['object'] = $obj;
|
2012-11-06 04:42:12 +00:00
|
|
|
|
2010-09-17 10:10:19 +00:00
|
|
|
$arr['allow_cid'] = $item['allow_cid'];
|
|
|
|
$arr['allow_gid'] = $item['allow_gid'];
|
|
|
|
$arr['deny_cid'] = $item['deny_cid'];
|
|
|
|
$arr['deny_gid'] = $item['deny_gid'];
|
2012-11-06 04:42:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
// $arr['visible'] = 1;
|
|
|
|
// $arr['unseen'] = 1;
|
2010-09-17 10:10:19 +00:00
|
|
|
|
|
|
|
$post_id = item_store($arr);
|
|
|
|
|
2012-11-06 04:42:12 +00:00
|
|
|
// if(! $item['visible']) {
|
|
|
|
// $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d LIMIT 1",
|
|
|
|
// intval($item['id']),
|
|
|
|
// intval($owner_uid)
|
|
|
|
// );
|
|
|
|
// }
|
2010-11-04 10:57:49 +00:00
|
|
|
|
2012-06-03 05:56:42 +00:00
|
|
|
|
2012-06-10 00:39:21 +00:00
|
|
|
$arr['id'] = $post_id;
|
|
|
|
|
|
|
|
call_hooks('post_local_end', $arr);
|
|
|
|
|
|
|
|
proc_run('php',"include/notifier.php","like","$post_id");
|
|
|
|
|
|
|
|
killme();
|
|
|
|
}
|
|
|
|
|
|
|
|
|