- logger('like: verb ' . $verb . ' item ' . $item_id);
-
-
- $r = q("SELECT * FROM `item` WHERE `id` = '%s' OR `uri` = '%s' LIMIT 1",
- dbesc($item_id),
- dbesc($item_id)
- );
-
- if(! $item_id || (! count($r))) {
- logger('like: no item ' . $item_id);
- return;
- }
-
- $item = $r[0];
-
- $owner_uid = $item['uid'];
-
- if(! can_write_wall($a,$owner_uid)) {
- return;
- }
-
- $remote_owner = null;
-
- if(! $item['wall']) {
- // The top level post may have been written by somebody on another system
- $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];
- }
-
- // this represents the post owner on this system.
-
- $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];
-
- if(! $owner) {
- logger('like: no owner');
- return;
- }
-
- if(! $remote_owner)
- $remote_owner = $owner;
-
-
- // This represents the person posting
-
- 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;
- }
-
-
- $r = q("SELECT * FROM `item` WHERE `verb` = '%s' AND `deleted` = 0
- AND `contact-id` = %d AND ( `parent` = '%s' OR `parent-uri` = '%s') LIMIT 1",
- dbesc($activity),
- intval($contact['id']),
- dbesc($item_id),
- dbesc($item_id)
- );
- if(count($r)) {
- $like_item = $r[0];
-
- // Already voted, undo it
- $r = q("UPDATE `item` SET `deleted` = 1, `changed` = '%s' WHERE `id` = %d LIMIT 1",
- dbesc(datetime_convert()),
- intval($like_item['id'])
- );
-
-
- // Clean up the Diaspora signatures for this like
- // Go ahead and do it even if Diaspora support is disabled. We still want to clean up
- // if it had been enabled in the past
- $r = q("DELETE FROM `sign` WHERE `iid` = %d",
- intval($like_item['id'])
- );
-
- // Save the author information for the unlike in case we need to relay to Diaspora
- store_diaspora_like_retract_sig($activity, $item, $like_item, $contact);
-
-
-// proc_run('php',"include/notifier.php","like","$post_id"); // $post_id isn't defined here!
- $like_item_id = $like_item['id'];
- proc_run('php',"include/notifier.php","like","$like_item_id");
- return;
- }