]> git.mxchange.org Git - friendica.git/commitdiff
By entering a GNU Social account name, the friends of this contact will be added...
authorMichael Vogel <icarus@dabo.de>
Sun, 23 Aug 2015 20:21:15 +0000 (22:21 +0200)
committerMichael Vogel <icarus@dabo.de>
Sun, 23 Aug 2015 20:21:15 +0000 (22:21 +0200)
include/ostatus.php
include/poller.php
mod/settings.php

index 369659f2d579fd4d3a913a494833fa02a757f9ba..a086177a7a0258578b578613cf7f5a36bfc9f0a2 100644 (file)
@@ -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();
index b72a4a823fcfbbba123abded104603dcc10f2fd0..28dc0c0cde03748f926822923b6855d9b70aba4e 100644 (file)
@@ -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();
 
index ca0829f021c225eeea63c4415eb73cf958ff99be..cddabcb8b2b1b230f120e9b2f335cb55973ce628 100644 (file)
@@ -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 .= '<span class="field_help">'.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.').'</span>';
                $settings_connectors .= '</div>';
 
+               $legacy_contact = get_pconfig(local_user(), 'system', 'ostatus_legacy_contact');
+
+               $settings_connectors .= '<div id="legacy-contact-wrapper" class="field input">';
+               $settings_connectors .= '<label id="legacy-contact-label" for="snautofollow-checkbox">'. t('Your legacy GNU Social account'). '</label>';
+               $settings_connectors .= '<input id="legacy-contact-checkbox" name="legacy_contact" value="'.$legacy_contact.'"/>';
+               $settings_connectors .= '<span class="field_help">'.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.').'</span>';
+               $settings_connectors .= '</div>';
+
                $settings_connectors .= '<div class="settings-submit-wrapper" ><input type="submit" name="general-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';
 
                $settings_connectors .= '</div><div class="clear"></div>';