Mass-subscribing to OStatus contacts is enabled again

This commit is contained in:
Michael Vogel 2015-09-05 10:32:10 +02:00
parent 3cccb5ecb1
commit cecbc58729
2 changed files with 84 additions and 6 deletions

78
mod/ostatus_subscribe.php Normal file
View file

@ -0,0 +1,78 @@
<?php
require_once('include/Scrape.php');
require_once('include/follow.php');
function ostatus_subscribe_content(&$a) {
if(! local_user()) {
notice( t('Permission denied.') . EOL);
goaway($_SESSION['return_url']);
// NOTREACHED
}
$o = "<h2>".t("Subsribing to OStatus contacts")."</h2>";
$uid = local_user();
$a = get_app();
$counter = intval($_REQUEST['counter']);
if (get_pconfig($uid, "ostatus", "legacy_friends") == "") {
if ($_REQUEST["url"] == "")
return $o.t("No contact provided.");
$contact = probe_url($_REQUEST["url"]);
if (!$contact)
return $o.t("Couldn't fetch information for contact.");
$api = $contact["baseurl"]."/api/";
// Fetching friends
$data = z_fetch_url($api."statuses/friends.json?screen_name=".$contact["nick"]);
if (!$data["success"])
return $o.t("Couldn't fetch friends for contact.");
set_pconfig($uid, "ostatus", "legacy_friends", $data["body"]);
}
$friends = json_decode(get_pconfig($uid, "ostatus", "legacy_friends"));
$total = sizeof($friends);
if ($counter >= $total) {
$a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/settings/connectors">';
del_pconfig($uid, "ostatus", "legacy_friends");
del_pconfig($uid, "ostatus", "legacy_contact");
$o .= t("Done");
return $o;
}
$friend = $friends[$counter++];
$url = $friend->statusnet_profile_url;
$o .= "<p>".$counter."/".$total.": ".$url;
$data = probe_url($url);
if ($data["network"] == NETWORK_OSTATUS) {
$result = new_contact($uid,$url,true);
if ($result["success"])
$o .= " - ".t("success");
else
$o .= " - ".t("failed");
} else
$o .= " - ".t("ignored");
$o .= "</p>";
$o .= "<p>".t("Keep this window open until done.")."</p>";
$a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/ostatus_subscribe?counter='.$counter.'">';
return $o;
}

View file

@ -189,7 +189,7 @@ function settings_post(&$a) {
if(x($_POST, 'general-submit')) { if(x($_POST, 'general-submit')) {
set_pconfig(local_user(), 'system', 'no_intelligent_shortening', intval($_POST['no_intelligent_shortening'])); 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_autofriend', intval($_POST['snautofollow']));
//set_pconfig(local_user(), 'system', 'ostatus_legacy_contact', $_POST['legacy_contact']); set_pconfig(local_user(), 'ostatus', 'legacy_contact', $_POST['legacy_contact']);
} elseif(x($_POST, 'imap-submit')) { } elseif(x($_POST, 'imap-submit')) {
$mail_server = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : ''); $mail_server = ((x($_POST,'mail_server')) ? $_POST['mail_server'] : '');
@ -770,18 +770,18 @@ 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 .= '<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>'; $settings_connectors .= '</div>';
$settings_connectors .= '<p><a href="'.$a->get_baseurl().'/repair_ostatus">'.t("Repair OStatus subscriptions").'</a></p>'; $legacy_contact = get_pconfig(local_user(), 'ostatus', 'legacy_contact');
/* if ($legacy_contact != "")
// Deactivated by now - it doesn't seem to work reliable $a->page['htmlhead'] = '<meta http-equiv="refresh" content="0; URL='.$a->get_baseurl().'/ostatus_subscribe?url='.urlencode($legacy_contact).'">';
$legacy_contact = get_pconfig(local_user(), 'system', 'ostatus_legacy_contact');
$settings_connectors .= '<div id="legacy-contact-wrapper" class="field input">'; $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 .= '<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 .= '<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 .= '<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>';
*/
$settings_connectors .= '<p><a href="'.$a->get_baseurl().'/repair_ostatus">'.t("Repair OStatus subscriptions").'</a></p>';
$settings_connectors .= '<div class="settings-submit-wrapper" ><input type="submit" name="general-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>'; $settings_connectors .= '<div class="settings-submit-wrapper" ><input type="submit" name="general-submit" class="settings-submit" value="' . t('Save Settings') . '" /></div>';