sforkowany z mirror/friendica
Merge pull request #1845 from annando/1508-follow-ostatus-friends
Auto adding friends of legacy OStatus accounts as new contacts2022.09-rc
commit
59bc08ce31
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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>';
|
||||
|
|
Ładowanie…
Reference in New Issue