function diaspora_load() { register_hook('notifier_hub', 'addon/diaspora/diaspora.php', 'diaspora_process_outbound'); register_hook('notifier_process', 'addon/diaspora/diaspora.php', 'diaspora_notifier_process'); register_hook('permissions_create', 'addon/diaspora/diaspora.php', 'diaspora_permissions_create'); register_hook('permissions_update', 'addon/diaspora/diaspora.php', 'diaspora_permissions_update'); register_hook('module_loaded', 'addon/diaspora/diaspora.php', 'diaspora_load_module'); register_hook('follow_allow', 'addon/diaspora/diaspora.php', 'diaspora_follow_allow'); register_hook('feature_settings_post', 'addon/diaspora/diaspora.php', 'diaspora_feature_settings_post'); register_hook('feature_settings', 'addon/diaspora/diaspora.php', 'diaspora_feature_settings'); register_hook('post_local', 'addon/diaspora/diaspora.php', 'diaspora_post_local'); register_hook('well_known', 'addon/diaspora/diaspora.php', 'diaspora_well_known'); if (!get_config('diaspora', 'relay_handle')) { $x = import_author_diaspora(array('address' => '*****@*****.**')); if ($x) { set_config('diaspora', 'relay_handle', $x); // Now register $url = "http://the-federation.info/register/" . App::get_hostname(); $ret = z_fetch_url($url); } } }
function import_author_xchan($x) { $arr = array('xchan' => $x, 'xchan_hash' => ''); call_hooks('import_author_xchan', $arr); if ($arr['xchan_hash']) { return $arr['xchan_hash']; } if (!array_key_exists('network', $x) || $x['network'] === 'zot') { $y = import_author_zot($x); } if (!$y) { $y = import_author_diaspora($x); } if ($x['network'] === 'rss') { $y = import_author_rss($x); } if ($x['network'] === 'unknown') { $y = import_author_unknown($x); } return $y ? $y : false; }
/** * poco_load * * xchan is your connection * We will load their friend list, and store in xlink_xchan your connection hash and xlink_link the hash for each connection * If xchan isn't provided we will load the list of people from url who have indicated they are willing to be friends with * new folks and add them to xlink with no xlink_xchan. * * Old behaviour: (documentation only): * Given a contact-id (minimum), load the PortableContacts friend list for that contact, * and add the entries to the gcontact (Global Contact) table, or update existing entries * if anything (name or photo) has changed. * We use normalised urls for comparison which ignore http vs https and www.domain vs domain * * Once the global contact is stored add (if necessary) the contact linkage which associates * the given uid, cid to the global contact entry. There can be many uid/cid combinations * pointing to the same global contact id. * * @param string $xchan * @param string $url */ function poco_load($xchan = '', $url = null) { if ($xchan && !$url) { $r = q("select xchan_connurl from xchan where xchan_hash = '%s' limit 1", dbesc($xchan)); if ($r) { $url = $r[0]['xchan_connurl']; } } if (!$url) { logger('poco_load: no url'); return; } $url = $url . '?f=&fields=displayName,hash,urls,photos'; logger('poco_load: ' . $url, LOGGER_DEBUG); $s = z_fetch_url($url); if (!$s['success']) { if ($s['return_code'] == 401) { logger('poco_load: protected'); } elseif ($s['return_code'] == 404) { logger('poco_load: nothing found'); } else { logger('poco_load: returns ' . print_r($s, true)); } return; } $j = json_decode($s['body'], true); if (!$j) { logger('poco_load: unable to json_decode returned data.'); return; } logger('poco_load: ' . print_r($j, true), LOGGER_DATA); if ($xchan) { if (array_key_exists('chatrooms', $j) && is_array($j['chatrooms'])) { foreach ($j['chatrooms'] as $room) { if (!$room['url'] || !$room['desc']) { continue; } $r = q("select * from xchat where xchat_url = '%s' and xchat_xchan = '%s' limit 1", dbesc($room['url']), dbesc($xchan)); if ($r) { q("update xchat set xchat_edited = '%s' where xchat_id = %d", dbesc(datetime_convert()), intval($r[0]['xchat_id'])); } else { $x = q("insert into xchat ( xchat_url, xchat_desc, xchat_xchan, xchat_edited )\n\t\t\t\t\t\tvalues ( '%s', '%s', '%s', '%s' ) ", dbesc(escape_tags($room['url'])), dbesc(escape_tags($room['desc'])), dbesc($xchan), dbesc(datetime_convert())); } } } q("delete from xchat where xchat_edited < %s - INTERVAL %s and xchat_xchan = '%s' ", db_utcnow(), db_quoteinterval('7 DAY'), dbesc($xchan)); } if (!(x($j, 'entry') && is_array($j['entry']))) { logger('poco_load: no entries'); return; } $total = 0; foreach ($j['entry'] as $entry) { $profile_url = ''; $profile_photo = ''; $address = ''; $name = ''; $hash = ''; $rating = 0; $name = $entry['displayName']; $hash = $entry['hash']; if (x($entry, 'urls') && is_array($entry['urls'])) { foreach ($entry['urls'] as $url) { if ($url['type'] == 'profile') { $profile_url = $url['value']; continue; } if ($url['type'] == 'zot' || $url['type'] == 'diaspora' || $url['type'] == 'friendica') { $network = $url['type']; $address = str_replace('acct:', '', $url['value']); continue; } } } if (x($entry, 'photos') && is_array($entry['photos'])) { foreach ($entry['photos'] as $photo) { if ($photo['type'] == 'profile') { $profile_photo = $photo['value']; continue; } } } if (!$name || !$profile_url || !$profile_photo || !$hash || !$address) { logger('poco_load: missing data'); continue; } $x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", dbesc($hash)); // We've never seen this person before. Import them. if ($x !== false && !count($x)) { if ($address) { if ($network === 'zot') { $j = Zotlabs\Zot\Finger::run($address, null); if ($j['success']) { import_xchan($j); } $x = q("select xchan_hash from xchan where xchan_hash = '%s' limit 1", dbesc($hash)); if (!$x) { continue; } } else { $x = import_author_diaspora(array('address' => $address)); if (!$x) { continue; } } } else { continue; } } $total++; $r = q("select * from xlink where xlink_xchan = '%s' and xlink_link = '%s' and xlink_static = 0 limit 1", dbesc($xchan), dbesc($hash)); if (!$r) { q("insert into xlink ( xlink_xchan, xlink_link, xlink_updated, xlink_static ) values ( '%s', '%s', '%s', 0 ) ", dbesc($xchan), dbesc($hash), dbesc(datetime_convert())); } else { q("update xlink set xlink_updated = '%s' where xlink_id = %d", dbesc(datetime_convert()), intval($r[0]['xlink_id'])); } } logger("poco_load: loaded {$total} entries", LOGGER_DEBUG); q("delete from xlink where xlink_xchan = '%s' and xlink_updated < %s - INTERVAL %s and xlink_static = 0", dbesc($xchan), db_utcnow(), db_quoteinterval('2 DAY')); }