From 2e022733f67acb2fe027075429ed2078429c55ea Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 21 Dec 2017 22:54:58 +0000 Subject: [PATCH 1/5] Standards --- include/like.php | 8 ++++---- mod/like.php | 29 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/include/like.php b/include/like.php index 9a8b9b957b..6b8c138b95 100644 --- a/include/like.php +++ b/include/like.php @@ -24,7 +24,7 @@ use Friendica\Protocol\Diaspora; function do_like($item_id, $verb) { $a = get_app(); - if (! local_user() && ! remote_user()) { + if (!local_user() && !remote_user()) { return false; } @@ -73,21 +73,21 @@ function do_like($item_id, $verb) { dbesc($item_id) ); - if (! $item_id || ! DBM::is_result($items)) { + if (!$item_id || !DBM::is_result($items)) { logger('like: unknown item ' . $item_id); return false; } $item = $items[0]; - if (! can_write_wall($a, $item['uid'])) { + if (!can_write_wall($a, $item['uid'])) { logger('like: unable to write on wall ' . $item['uid']); return false; } // Retrieves the local post owner $owners = q("SELECT `contact`.* FROM `contact` - WHERE `contact`.`self` = 1 + WHERE `contact`.`self` AND `contact`.`uid` = %d", intval($item['uid']) ); diff --git a/mod/like.php b/mod/like.php index 6918bd5521..3c7e70cea6 100644 --- a/mod/like.php +++ b/mod/like.php @@ -3,33 +3,35 @@ use Friendica\App; use Friendica\Core\System; -require_once('include/security.php'); -require_once('include/bbcode.php'); -require_once('include/items.php'); -require_once('include/like.php'); +require_once 'include/security.php'; +require_once 'include/bbcode.php'; +require_once 'include/items.php'; +require_once 'include/like.php'; function like_content(App $a) { - if(! local_user() && ! remote_user()) { + if (!local_user() && !remote_user()) { return false; } $verb = notags(trim($_GET['verb'])); - if(! $verb) + if (!$verb) { $verb = 'like'; + } $item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0); $r = do_like($item_id, $verb); - if (!$r) return; + if (!$r) { + return; + } // See if we've been passed a return path to redirect to $return_path = ((x($_REQUEST,'return')) ? $_REQUEST['return'] : ''); like_content_return(System::baseUrl(), $return_path); killme(); // NOTREACHED -// return; // NOTREACHED } @@ -37,15 +39,16 @@ function like_content(App $a) { // then redirect back to the calling page. If not, just quietly end function like_content_return($baseurl, $return_path) { - - if($return_path) { + if ($return_path) { $rand = '_=' . time(); - if(strpos($return_path, '?')) $rand = "&$rand"; - else $rand = "?$rand"; + if (strpos($return_path, '?')) { + $rand = "&$rand"; + } else { + $rand = "?$rand"; + } goaway($baseurl . "/" . $return_path . $rand); } killme(); } - From fc0031f4ba37117c25b2a613731951a82eb41a6c Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 24 Dec 2017 11:36:30 +0000 Subject: [PATCH 2/5] First steps to support public likes --- include/like.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/include/like.php b/include/like.php index 6b8c138b95..05bb758c2a 100644 --- a/include/like.php +++ b/include/like.php @@ -80,22 +80,26 @@ function do_like($item_id, $verb) { $item = $items[0]; - if (!can_write_wall($a, $item['uid'])) { + if (!can_write_wall($a, $item['uid']) && ($item['uid'] != 0)) { logger('like: unable to write on wall ' . $item['uid']); return false; } // Retrieves the local post owner - $owners = q("SELECT `contact`.* FROM `contact` - WHERE `contact`.`self` - AND `contact`.`uid` = %d", - intval($item['uid']) - ); - if (DBM::is_result($owners)) { - $owner_self_contact = $owners[0]; + if ($item['uid'] != 0) { + $owners = q("SELECT `contact`.* FROM `contact` + WHERE `contact`.`self` + AND `contact`.`uid` = %d", + intval($item['uid']) + ); + if (DBM::is_result($owners)) { + $owner_self_contact = $owners[0]; + } else { + logger('like: unknown owner ' . $item['uid']); + return false; + } } else { - logger('like: unknown owner ' . $item['uid']); - return false; + $owner_self_contact = ['uid' => 0, 'nick' => 'feed-item']; } // Retrieve the current logged in user's public contact From 1c72a71933901979b02818198ae8970aa4d7a3d3 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 27 Dec 2017 21:44:22 +0000 Subject: [PATCH 3/5] Use another uid for likes --- include/like.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/include/like.php b/include/like.php index 05bb758c2a..32a2cabcfd 100644 --- a/include/like.php +++ b/include/like.php @@ -79,26 +79,28 @@ function do_like($item_id, $verb) { } $item = $items[0]; + $uid = $item['uid']; - if (!can_write_wall($a, $item['uid']) && ($item['uid'] != 0)) { - logger('like: unable to write on wall ' . $item['uid']); + if (!can_write_wall($a, $uid) && (($uid != 0) || !local_user())) { + logger('like: unable to write on wall ' . $uid); return false; } // Retrieves the local post owner - if ($item['uid'] != 0) { + if ($uid != 0) { $owners = q("SELECT `contact`.* FROM `contact` WHERE `contact`.`self` AND `contact`.`uid` = %d", - intval($item['uid']) + intval($uid) ); if (DBM::is_result($owners)) { $owner_self_contact = $owners[0]; } else { - logger('like: unknown owner ' . $item['uid']); + logger('like: unknown owner ' . $uid); return false; } } else { + $uid = local_user(); $owner_self_contact = ['uid' => 0, 'nick' => 'feed-item']; } @@ -116,11 +118,11 @@ function do_like($item_id, $verb) { } // Contact-id is the uid-dependant author contact - if (local_user() == $item['uid']) { + if (local_user() == $uid) { $item_contact_id = $owner_self_contact['id']; $item_contact = $owner_self_contact; } else { - $item_contact_id = Contact::getIdForURL($author_contact['url'], $item['uid']); + $item_contact_id = Contact::getIdForURL($author_contact['url'], $uid); $contacts = q("SELECT * FROM `contact` WHERE `id` = %d", intval($item_contact_id) @@ -150,7 +152,7 @@ function do_like($item_id, $verb) { AND (`parent` = '%s' OR `parent-uri` = '%s' OR `thr-parent` = '%s') LIMIT 1", intval($author_contact['id']), - intval($item['uid']), + intval($uid), dbesc($item_id), dbesc($item_id), dbesc($item['uri']) ); @@ -209,8 +211,8 @@ EOT; $new_item = array( 'guid' => get_guid(32), - 'uri' => item_new_uri($a->get_hostname(), $item['uid']), - 'uid' => $item['uid'], + 'uri' => item_new_uri($a->get_hostname(), $uid), + 'uid' => $uid, 'contact-id' => $item_contact_id, 'type' => 'activity', 'wall' => $item['wall'], @@ -244,9 +246,8 @@ EOT; // @todo: Explain this block if (! $item['visible']) { - q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d AND `uid` = %d", - intval($item['id']), - intval($item['uid']) + q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d", + intval($item['id']) ); } From 9acc2ffc24b3df0465a6970502c63d690aa16a4f Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 27 Dec 2017 21:51:16 +0000 Subject: [PATCH 4/5] Make it easier --- include/like.php | 29 ++++++++++++++--------------- src/Worker/Notifier.php | 9 ++++++++- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/include/like.php b/include/like.php index 32a2cabcfd..31698658a2 100644 --- a/include/like.php +++ b/include/like.php @@ -81,27 +81,26 @@ function do_like($item_id, $verb) { $item = $items[0]; $uid = $item['uid']; - if (!can_write_wall($a, $uid) && (($uid != 0) || !local_user())) { + if (($uid == 0) && local_user()) { + $uid = local_user(); + } + + if (!can_write_wall($a, $uid)) { logger('like: unable to write on wall ' . $uid); return false; } // Retrieves the local post owner - if ($uid != 0) { - $owners = q("SELECT `contact`.* FROM `contact` - WHERE `contact`.`self` - AND `contact`.`uid` = %d", - intval($uid) - ); - if (DBM::is_result($owners)) { - $owner_self_contact = $owners[0]; - } else { - logger('like: unknown owner ' . $uid); - return false; - } + $owners = q("SELECT `contact`.* FROM `contact` + WHERE `contact`.`self` + AND `contact`.`uid` = %d", + intval($uid) + ); + if (DBM::is_result($owners)) { + $owner_self_contact = $owners[0]; } else { - $uid = local_user(); - $owner_self_contact = ['uid' => 0, 'nick' => 'feed-item']; + logger('like: unknown owner ' . $uid); + return false; } // Retrieve the current logged in user's public contact diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index e8dc25c5ee..78daae2752 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -154,10 +154,12 @@ class Notifier { FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible AND NOT moderated ORDER BY `id` ASC", intval($parent_id) ); +logger('Blubb: a-'.$item_id); if (!count($items)) { return; } +logger('Blubb: b-'.$item_id); // avoid race condition with deleting entries if ($items[0]['deleted']) { @@ -171,11 +173,13 @@ class Notifier { $top_level = true; } } +logger('Blubb: 0-'.$item_id.' - '.$uid); $owner = User::getOwnerDataById($uid); if (!$owner) { return; } +logger('Blubb: 1-'.$item_id); $walltowall = ($top_level && ($owner['id'] != $items[0]['contact-id']) ? true : false); @@ -193,12 +197,14 @@ class Notifier { // fill this in with a single salmon slap if applicable $slap = ''; +logger('Blubb: 2-'.$item_id); if (! ($mail || $fsuggest || $relocate)) { $slap = OStatus::salmon($target_item, $owner); $parent = $items[0]; +logger('Blubb: 3-'.$item_id); $thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d", dbesc($target_item["thr-parent"]), intval($target_item["uid"])); @@ -280,7 +286,6 @@ class Notifier { } } if ($relay_to_owner) { - logger('notifier: followup '.$target_item["guid"], LOGGER_DEBUG); // local followup to remote post $followup = true; $public_message = false; // not public @@ -288,6 +293,8 @@ class Notifier { $recipients = array($parent['contact-id']); $recipients_followup = array($parent['contact-id']); + logger('notifier: followup '.$target_item["guid"].' to '.$conversant_str, LOGGER_DEBUG); + //if (!$target_item['private'] && $target_item['wall'] && if (!$target_item['private'] && (strlen($target_item['allow_cid'].$target_item['allow_gid']. From 0bcbe6034ecca48c26196ff68bc08950efbb46af Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 27 Dec 2017 22:21:40 +0000 Subject: [PATCH 5/5] Like on uid=0 does work now --- include/like.php | 6 +++--- src/Worker/Notifier.php | 6 ------ 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/include/like.php b/include/like.php index 31698658a2..8b8759c2f6 100644 --- a/include/like.php +++ b/include/like.php @@ -151,7 +151,7 @@ function do_like($item_id, $verb) { AND (`parent` = '%s' OR `parent-uri` = '%s' OR `thr-parent` = '%s') LIMIT 1", intval($author_contact['id']), - intval($uid), + intval($item['uid']), dbesc($item_id), dbesc($item_id), dbesc($item['uri']) ); @@ -210,8 +210,8 @@ EOT; $new_item = array( 'guid' => get_guid(32), - 'uri' => item_new_uri($a->get_hostname(), $uid), - 'uid' => $uid, + 'uri' => item_new_uri($a->get_hostname(), $item['uid']), + 'uid' => $item['uid'], 'contact-id' => $item_contact_id, 'type' => 'activity', 'wall' => $item['wall'], diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php index 78daae2752..5c86a95efe 100644 --- a/src/Worker/Notifier.php +++ b/src/Worker/Notifier.php @@ -154,12 +154,10 @@ class Notifier { FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible AND NOT moderated ORDER BY `id` ASC", intval($parent_id) ); -logger('Blubb: a-'.$item_id); if (!count($items)) { return; } -logger('Blubb: b-'.$item_id); // avoid race condition with deleting entries if ($items[0]['deleted']) { @@ -173,13 +171,11 @@ logger('Blubb: b-'.$item_id); $top_level = true; } } -logger('Blubb: 0-'.$item_id.' - '.$uid); $owner = User::getOwnerDataById($uid); if (!$owner) { return; } -logger('Blubb: 1-'.$item_id); $walltowall = ($top_level && ($owner['id'] != $items[0]['contact-id']) ? true : false); @@ -197,14 +193,12 @@ logger('Blubb: 1-'.$item_id); // fill this in with a single salmon slap if applicable $slap = ''; -logger('Blubb: 2-'.$item_id); if (! ($mail || $fsuggest || $relocate)) { $slap = OStatus::salmon($target_item, $owner); $parent = $items[0]; -logger('Blubb: 3-'.$item_id); $thr_parent = q("SELECT `network`, `author-link`, `owner-link` FROM `item` WHERE `uri` = '%s' AND `uid` = %d", dbesc($target_item["thr-parent"]), intval($target_item["uid"]));