Date: Sun, 6 Mar 2016 14:09:04 +0100
Subject: [PATCH 09/15] Settings for only importing threads from our ostatus
contacts
---
mod/admin.php | 3 +++
view/templates/admin_site.tpl | 1 +
2 files changed, 4 insertions(+)
diff --git a/mod/admin.php b/mod/admin.php
index a98f464f8..f6958098b 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -598,6 +598,7 @@ function admin_page_site_post(&$a) {
$dfrn_only = ((x($_POST,'dfrn_only')) ? True : False);
$ostatus_disabled = !((x($_POST,'ostatus_disabled')) ? True : False);
$ostatus_poll_interval = ((x($_POST,'ostatus_poll_interval')) ? intval(trim($_POST['ostatus_poll_interval'])) : 0);
+ $ostatus_full_threads = ((x($_POST,'ostatus_full_threads')) ? True : False);
$diaspora_enabled = ((x($_POST,'diaspora_enabled')) ? True : False);
$ssl_policy = ((x($_POST,'ssl_policy')) ? intval($_POST['ssl_policy']) : 0);
$force_ssl = ((x($_POST,'force_ssl')) ? True : False);
@@ -746,6 +747,7 @@ function admin_page_site_post(&$a) {
set_config('system','dfrn_only', $dfrn_only);
set_config('system','ostatus_disabled', $ostatus_disabled);
set_config('system','ostatus_poll_interval', $ostatus_poll_interval);
+ set_config('system','ostatus_full_threads', $ostatus_full_threads);
set_config('system','diaspora_enabled', $diaspora_enabled);
set_config('config','private_addons', $private_addons);
@@ -947,6 +949,7 @@ function admin_page_site(&$a) {
'$max_author_posts_community_page' => array('max_author_posts_community_page', t("Posts per user on community page"), get_config('system','max_author_posts_community_page'), t("The maximum number of posts per user on the community page. (Not valid for 'Global Community')")),
'$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disabled'), t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")),
'$ostatus_poll_interval' => array('ostatus_poll_interval', t("OStatus conversation completion interval"), (string) intval(get_config('system','ostatus_poll_interval')), t("How often shall the poller check for new entries in OStatus conversations? This can be a very ressource task."), $ostatus_poll_choices),
+ '$ostatus_full_threads' => array('ostatus_disabled', t("Only import OStatus threads from our contacts"), get_config('system','ostatus_full_threads'), t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")),
'$ostatus_not_able' => t("OStatus support can only be enabled if threading is enabled."),
'$diaspora_able' => $diaspora_able,
'$diaspora_not_able' => t("Diaspora support can't be enabled because Friendica was installed into a sub directory."),
diff --git a/view/templates/admin_site.tpl b/view/templates/admin_site.tpl
index b08e5f935..91957d016 100644
--- a/view/templates/admin_site.tpl
+++ b/view/templates/admin_site.tpl
@@ -87,6 +87,7 @@
{{if $thread_allow.2}}
{{include file="field_checkbox.tpl" field=$ostatus_disabled}}
{{include file="field_select.tpl" field=$ostatus_poll_interval}}
+ {{include file="field_checkbox.tpl" field=$ostatus_full_threads}}
{{else}}
From 4bd1061a095a0fd80c69e2151b3fcf0a232a0169 Mon Sep 17 00:00:00 2001
From: Michael Vogel
Date: Sun, 6 Mar 2016 14:53:30 +0100
Subject: [PATCH 10/15] Only import OStatus threads if we follow the thread
starter
---
boot.php | 3 +++
include/ostatus.php | 7 +++++++
mod/admin.php | 2 +-
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/boot.php b/boot.php
index 0a2f5c50c..5cc349931 100644
--- a/boot.php
+++ b/boot.php
@@ -1509,6 +1509,9 @@ function killme() {
* @brief Redirect to another URL and terminate this process.
*/
function goaway($s) {
+ if (!strstr(normalise_link($s), normalise_link(App::get_baseurl())))
+ $s = App::get_baseurl()."/".$s;
+
header("Location: $s");
killme();
}
diff --git a/include/ostatus.php b/include/ostatus.php
index 5c5016d0f..40df688ea 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -809,6 +809,13 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// 2. This first post is a post inside our thread
// 3. This first post is a post inside another thread
if (($first_id != $parent["uri"]) AND ($parent["uri"] != "")) {
+
+ // Do we only want to import threads that were started by our contacts?
+ if (get_config('system','ostatus_full_threads')) {
+ logger("Don't import uri ".$first_id." because we don't follow this person.", LOGGER_DEBUG);
+ continue;
+ }
+
$new_parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN
(SELECT `parent` FROM `item`
WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1",
diff --git a/mod/admin.php b/mod/admin.php
index f6958098b..e7c4f51b6 100644
--- a/mod/admin.php
+++ b/mod/admin.php
@@ -949,7 +949,7 @@ function admin_page_site(&$a) {
'$max_author_posts_community_page' => array('max_author_posts_community_page', t("Posts per user on community page"), get_config('system','max_author_posts_community_page'), t("The maximum number of posts per user on the community page. (Not valid for 'Global Community')")),
'$ostatus_disabled' => array('ostatus_disabled', t("Enable OStatus support"), !get_config('system','ostatus_disabled'), t("Provide built-in OStatus \x28StatusNet, GNU Social etc.\x29 compatibility. All communications in OStatus are public, so privacy warnings will be occasionally displayed.")),
'$ostatus_poll_interval' => array('ostatus_poll_interval', t("OStatus conversation completion interval"), (string) intval(get_config('system','ostatus_poll_interval')), t("How often shall the poller check for new entries in OStatus conversations? This can be a very ressource task."), $ostatus_poll_choices),
- '$ostatus_full_threads' => array('ostatus_disabled', t("Only import OStatus threads from our contacts"), get_config('system','ostatus_full_threads'), t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")),
+ '$ostatus_full_threads' => array('ostatus_full_threads', t("Only import OStatus threads from our contacts"), get_config('system','ostatus_full_threads'), t("Normally we import every content from our OStatus contacts. With this option we only store threads that are started by a contact that is known on our system.")),
'$ostatus_not_able' => t("OStatus support can only be enabled if threading is enabled."),
'$diaspora_able' => $diaspora_able,
'$diaspora_not_able' => t("Diaspora support can't be enabled because Friendica was installed into a sub directory."),
From 7f48df63a3b278e1ff44d71b8cfdd8966fce2341 Mon Sep 17 00:00:00 2001
From: Michael Vogel
Date: Sun, 6 Mar 2016 15:11:04 +0100
Subject: [PATCH 11/15] Relocated the check.
---
include/ostatus.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/ostatus.php b/include/ostatus.php
index 40df688ea..8749d3ab2 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -810,12 +810,6 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// 3. This first post is a post inside another thread
if (($first_id != $parent["uri"]) AND ($parent["uri"] != "")) {
- // Do we only want to import threads that were started by our contacts?
- if (get_config('system','ostatus_full_threads')) {
- logger("Don't import uri ".$first_id." because we don't follow this person.", LOGGER_DEBUG);
- continue;
- }
-
$new_parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN
(SELECT `parent` FROM `item`
WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1",
@@ -925,6 +919,12 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
} else {
logger("No contact found for url ".$actor, LOGGER_DEBUG);
+ // Do we only want to import threads that were started by our contacts?
+ if (get_config('system','ostatus_full_threads')) {
+ logger("Don't import uri ".$first_id." because we don't follow this person.", LOGGER_DEBUG);
+ continue;
+ }
+
// Adding a global contact
/// @TODO Use this data for the post
$global_contact_id = get_contact($actor, 0);
From 279a0453f9d338bae467db4c0aee938798e7c8f3 Mon Sep 17 00:00:00 2001
From: Michael Vogel
Date: Sun, 6 Mar 2016 15:13:19 +0100
Subject: [PATCH 12/15] Or back ...
---
include/ostatus.php | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/ostatus.php b/include/ostatus.php
index 8749d3ab2..40df688ea 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -810,6 +810,12 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// 3. This first post is a post inside another thread
if (($first_id != $parent["uri"]) AND ($parent["uri"] != "")) {
+ // Do we only want to import threads that were started by our contacts?
+ if (get_config('system','ostatus_full_threads')) {
+ logger("Don't import uri ".$first_id." because we don't follow this person.", LOGGER_DEBUG);
+ continue;
+ }
+
$new_parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN
(SELECT `parent` FROM `item`
WHERE `uid` = %d AND `uri` = '%s' AND `network` IN ('%s','%s')) LIMIT 1",
@@ -919,12 +925,6 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
} else {
logger("No contact found for url ".$actor, LOGGER_DEBUG);
- // Do we only want to import threads that were started by our contacts?
- if (get_config('system','ostatus_full_threads')) {
- logger("Don't import uri ".$first_id." because we don't follow this person.", LOGGER_DEBUG);
- continue;
- }
-
// Adding a global contact
/// @TODO Use this data for the post
$global_contact_id = get_contact($actor, 0);
From 9579725d4deafdbf123fd2c882be0cff93af4b5b Mon Sep 17 00:00:00 2001
From: Michael Vogel
Date: Sun, 6 Mar 2016 19:27:34 +0100
Subject: [PATCH 13/15] This should work better ...
---
include/ostatus.php | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/include/ostatus.php b/include/ostatus.php
index 40df688ea..44431967e 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -686,7 +686,8 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
$conversation_url = ostatus_convert_href($conversation_url);
// If the thread shouldn't be completed then store the item and go away
- if ((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) {
+ // Don't do a completion on liked content
+ if (((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) OR ($item["verb"] == ACTIVITY_LIKE)) {
//$arr["app"] .= " (OStatus-NoCompletion)";
$item_stored = item_store($item, true);
return($item_stored);
@@ -725,7 +726,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
$pageno = 1;
$items = array();
- logger('fetching conversation url '.$conv.' for user '.$uid);
+ logger('fetching conversation url '.$conv.' ('.$conversation_url.') for user '.$uid);
do {
$conv_arr = z_fetch_url($conv."?page=".$pageno);
@@ -778,6 +779,8 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
$r = q("SELECT `nurl` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid));
$importer = $r[0];
+ $new_parent = true;
+
foreach ($items as $single_conv) {
// Update the gcontact table
@@ -810,11 +813,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
// 3. This first post is a post inside another thread
if (($first_id != $parent["uri"]) AND ($parent["uri"] != "")) {
- // Do we only want to import threads that were started by our contacts?
- if (get_config('system','ostatus_full_threads')) {
- logger("Don't import uri ".$first_id." because we don't follow this person.", LOGGER_DEBUG);
- continue;
- }
+ $new_parent = true;
$new_parents = q("SELECT `id`, `parent`, `uri`, `contact-id`, `type`, `verb`, `visible` FROM `item` WHERE `id` IN
(SELECT `parent` FROM `item`
@@ -916,12 +915,14 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
if (isset($single_conv->actor->url))
$actor = $single_conv->actor->url;
- $contact = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
+ $contact = q("SELECT `id`, `rel` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` != '%s'",
$uid, normalise_link($actor), NETWORK_STATUSNET);
if (count($contact)) {
logger("Found contact for url ".$actor, LOGGER_DEBUG);
$contact_id = $contact[0]["id"];
+
+ $not_following = !in_array($contact[0]["rel"], array(CONTACT_IS_SHARING, CONTACT_IS_FRIEND));
} else {
logger("No contact found for url ".$actor, LOGGER_DEBUG);
@@ -932,6 +933,14 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
logger("Global contact ".$global_contact_id." found for url ".$actor, LOGGER_DEBUG);
$contact_id = $parent["contact-id"];
+
+ $not_following = true;
+ }
+
+ // Do we only want to import threads that were started by our contacts?
+ if ($not_following AND $new_parent AND get_config('system','ostatus_full_threads')) {
+ logger("Don't import uri ".$first_id." because we don't follow the person ".$actor, LOGGER_DEBUG);
+ continue;
}
$arr = array();
From ef2bc47cc6d8f6be3fda65aec366ad237396a52c Mon Sep 17 00:00:00 2001
From: Michael Vogel
Date: Sun, 6 Mar 2016 20:36:28 +0100
Subject: [PATCH 14/15] New way of fetching the conversation id for thread
completion
---
include/ostatus.php | 41 ++++++++++++++++++++++++++++++++++++-----
1 file changed, 36 insertions(+), 5 deletions(-)
diff --git a/include/ostatus.php b/include/ostatus.php
index 44431967e..138f51090 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -537,7 +537,7 @@ function ostatus_import($xml,$importer,&$contact, &$hub) {
} else
$item["parent-uri"] = $item["uri"];
- $item_id = ostatus_completion($conversation, $importer["uid"], $item);
+ $item_id = ostatus_completion($conversation, $importer["uid"], $item, $self);
if (!$item_id) {
logger("Error storing item", LOGGER_DEBUG);
@@ -676,18 +676,49 @@ function ostatus_conv_fetch_actor($actor) {
update_gcontact($contact);
}
+function ostatus_fetch_conversation($self, $conversation_url = "") {
-function ostatus_completion($conversation_url, $uid, $item = array()) {
+ if ($conversation_url != "") {
+ $elements = explode(":", $conversation_url);
+
+ if ((count($elements) <= 2) OR ($elements[0] != "tag"))
+ return $conversation_url;
+ }
+
+ if ($self == "")
+ return "";
+
+ $json = str_replace(".atom", ".json", $self);
+
+ $raw = fetch_url($json);
+ if ($raw == "")
+ return "";
+
+ $data = json_decode($raw);
+ if (!is_object($data))
+ return "";
+
+ $conversation_id = $data->statusnet_conversation_id;
+
+ $pos = strpos($self, "/api/statuses/show/");
+ $base_url = substr($self, 0, $pos);
+
+ return $base_url."/conversation/".$conversation_id;
+}
+
+function ostatus_completion($conversation_url, $uid, $item = array(), $self = "") {
$a = get_app();
$item_stored = -1;
- $conversation_url = ostatus_convert_href($conversation_url);
+ //$conversation_url = ostatus_convert_href($conversation_url);
+ $conversation_url = ostatus_fetch_conversation($self, $conversation_url);
// If the thread shouldn't be completed then store the item and go away
// Don't do a completion on liked content
- if (((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) OR ($item["verb"] == ACTIVITY_LIKE)) {
+ if (((intval(get_config('system','ostatus_poll_interval')) == -2) AND (count($item) > 0)) OR
+ ($item["verb"] == ACTIVITY_LIKE) OR ($conversation_url == "")) {
//$arr["app"] .= " (OStatus-NoCompletion)";
$item_stored = item_store($item, true);
return($item_stored);
@@ -726,7 +757,7 @@ function ostatus_completion($conversation_url, $uid, $item = array()) {
$pageno = 1;
$items = array();
- logger('fetching conversation url '.$conv.' ('.$conversation_url.') for user '.$uid);
+ logger('fetching conversation url '.$conv.' (Self: '.$self.') for user '.$uid);
do {
$conv_arr = z_fetch_url($conv."?page=".$pageno);
From 4ef44c67b84a9f8d66b91a61123b10fe2be75784 Mon Sep 17 00:00:00 2001
From: Michael Vogel
Date: Sun, 6 Mar 2016 21:06:52 +0100
Subject: [PATCH 15/15] Added documentation
---
include/ostatus.php | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/include/ostatus.php b/include/ostatus.php
index 138f51090..54b70e6d6 100644
--- a/include/ostatus.php
+++ b/include/ostatus.php
@@ -676,13 +676,21 @@ function ostatus_conv_fetch_actor($actor) {
update_gcontact($contact);
}
-function ostatus_fetch_conversation($self, $conversation_url = "") {
+/**
+ * @brief Fetches the conversation url for a given item link or conversation id
+ *
+ * @param string $self The link to the posting
+ * @param string $conversation_id The conversation id
+ *
+ * @return string The conversation url
+ */
+function ostatus_fetch_conversation($self, $conversation_id = "") {
- if ($conversation_url != "") {
- $elements = explode(":", $conversation_url);
+ if ($conversation_id != "") {
+ $elements = explode(":", $conversation_id);
if ((count($elements) <= 2) OR ($elements[0] != "tag"))
- return $conversation_url;
+ return $conversation_id;
}
if ($self == "")