diff --git a/include/ostatus.php b/include/ostatus.php index 369659f2d5..a086177a7a 100644 --- a/include/ostatus.php +++ b/include/ostatus.php @@ -7,11 +7,62 @@ require_once("mod/share.php"); require_once("include/enotify.php"); require_once("include/socgraph.php"); require_once("include/Photo.php"); +require_once("include/Scrape.php"); +require_once("include/follow.php"); define('OSTATUS_DEFAULT_POLL_INTERVAL', 30); // given in minutes define('OSTATUS_DEFAULT_POLL_TIMEFRAME', 1440); // given in minutes define('OSTATUS_DEFAULT_POLL_TIMEFRAME_MENTIONS', 14400); // given in minutes +function ostatus_check_follow_friends() { + $r = q("SELECT `uid`,`v` FROM `pconfig` WHERE `cat`='system' AND `k`='ostatus_legacy_contact' AND `v` != ''"); + + if (!$r) + return; + + foreach ($r AS $contact) { + ostatus_follow_friends($contact["uid"], $contact["v"]); + set_pconfig($contact["uid"], "system", "ostatus_legacy_contact", ""); + } +} + +function ostatus_follow_friends($uid, $url) { + $contact = probe_url($url); + + if (!$contact) + return; + + $api = $contact["baseurl"]."/api/"; + + // Fetching friends + $data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]); + + if (!$data["success"]) + return; + + $friends = json_decode($data["body"]); + + foreach ($friends AS $friend) { + $url = $friend->statusnet_profile_url; + $r = q("SELECT `url` FROM `contact` WHERE `uid` = %d AND + (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND + `network` != '%s' LIMIT 1", + intval($uid), dbesc(normalise_link($url)), + dbesc(normalise_link($url)), dbesc($url), dbesc(NETWORK_STATUSNET)); + if (!$r) { + $data = probe_url($friend->statusnet_profile_url); + if ($data["network"] == NETWORK_OSTATUS) { + $result = new_contact($uid,$friend->statusnet_profile_url); + if ($result["success"]) + logger($friend->name." ".$url." - success", LOGGER_DEBUG); + else + logger($friend->name." ".$url." - failed", LOGGER_DEBUG); + } else + logger($friend->name." ".$url." - not OStatus", LOGGER_DEBUG); + } + } +} + function ostatus_fetchauthor($xpath, $context, $importer, &$contact, $onlyfetch) { $author = array(); diff --git a/include/poller.php b/include/poller.php index b72a4a823f..28dc0c0cde 100644 --- a/include/poller.php +++ b/include/poller.php @@ -118,6 +118,9 @@ function poller_run(&$argv, &$argc){ // Check every conversation check_conversations(false); + // Follow your friends from your legacy OStatus account + ostatus_check_follow_friends(); + // update nodeinfo data nodeinfo_cron(); diff --git a/mod/settings.php b/mod/settings.php index ca0829f021..cddabcb8b2 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -189,6 +189,7 @@ function settings_post(&$a) { if(x($_POST, 'general-submit')) { set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening'])); set_pconfig(local_user(), 'system', 'ostatus_autofriend', intval($_POST['snautofollow'])); + set_pconfig(local_user(), 'system', 'ostatus_legacy_contact', $_POST['legacy_contact']); } elseif(x($_POST, 'imap-submit')) { $mail_server = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : ''); @@ -769,6 +770,14 @@ function settings_content(&$a) { $settings_connectors .= ''.t('If you receive a message from an unknown OStatus user, this option decides what to do. If it is checked, a new contact will be created for every unknown user.').''; $settings_connectors .= ''; + $legacy_contact = get_pconfig(local_user(), 'system', 'ostatus_legacy_contact'); + + $settings_connectors .= '
'; + $settings_connectors .= ''; + $settings_connectors .= ''; + $settings_connectors .= ''.t('If you enter your old GNU Social/Statusnet account name here (in the format user@domain.tld), your contacts will be added automatically. The field will be emptied when done.').''; + $settings_connectors .= '
'; + $settings_connectors .= '
'; $settings_connectors .= '
';