Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

97 lines
2.5 KiB

  1. <?php
  2. /**
  3. * @file mod/ostatus_subscribe.php
  4. */
  5. use Friendica\App;
  6. use Friendica\Core\L10n;
  7. use Friendica\Core\Protocol;
  8. use Friendica\DI;
  9. use Friendica\Model\Contact;
  10. use Friendica\Network\Probe;
  11. use Friendica\Util\Network;
  12. function ostatus_subscribe_content(App $a)
  13. {
  14. if (!local_user()) {
  15. notice(L10n::t('Permission denied.') . EOL);
  16. DI::baseUrl()->redirect('ostatus_subscribe');
  17. // NOTREACHED
  18. }
  19. $o = '<h2>' . L10n::t('Subscribing to OStatus contacts') . '</h2>';
  20. $uid = local_user();
  21. $counter = intval($_REQUEST['counter']);
  22. if (DI::pConfig()->get($uid, 'ostatus', 'legacy_friends') == '') {
  23. if ($_REQUEST['url'] == '') {
  24. DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
  25. return $o . L10n::t('No contact provided.');
  26. }
  27. $contact = Probe::uri($_REQUEST['url']);
  28. if (!$contact) {
  29. DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
  30. return $o . L10n::t('Couldn\'t fetch information for contact.');
  31. }
  32. $api = $contact['baseurl'] . '/api/';
  33. // Fetching friends
  34. $curlResult = Network::curl($api . 'statuses/friends.json?screen_name=' . $contact['nick']);
  35. if (!$curlResult->isSuccess()) {
  36. DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
  37. return $o . L10n::t('Couldn\'t fetch friends for contact.');
  38. }
  39. DI::pConfig()->set($uid, 'ostatus', 'legacy_friends', $curlResult->getBody());
  40. }
  41. $friends = json_decode(DI::pConfig()->get($uid, 'ostatus', 'legacy_friends'));
  42. if (empty($friends)) {
  43. $friends = [];
  44. }
  45. $total = sizeof($friends);
  46. if ($counter >= $total) {
  47. DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . DI::baseUrl() . '/settings/connectors">';
  48. DI::pConfig()->delete($uid, 'ostatus', 'legacy_friends');
  49. DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
  50. $o .= L10n::t('Done');
  51. return $o;
  52. }
  53. $friend = $friends[$counter++];
  54. $url = $friend->statusnet_profile_url;
  55. $o .= '<p>' . $counter . '/' . $total . ': ' . $url;
  56. $probed = Probe::uri($url);
  57. if ($probed['network'] == Protocol::OSTATUS) {
  58. $result = Contact::createFromProbe($uid, $url, true, Protocol::OSTATUS);
  59. if ($result['success']) {
  60. $o .= ' - ' . L10n::t('success');
  61. } else {
  62. $o .= ' - ' . L10n::t('failed');
  63. }
  64. } else {
  65. $o .= ' - ' . L10n::t('ignored');
  66. }
  67. $o .= '</p>';
  68. $o .= '<p>' . L10n::t('Keep this window open until done.') . '</p>';
  69. DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="0; URL=' . DI::baseUrl() . '/ostatus_subscribe?counter=' . $counter . '">';
  70. return $o;
  71. }