4 * Description: Export user's RSS/Atom contacts as OPML
6 * Author: Fabio Comuni <https://social.gl-como.it/profile/fabrixxm>
7 * License: 3-clause BSD license
12 use Friendica\Core\Hook;
13 use Friendica\Core\Logger;
14 use Friendica\Network\HTTPException;
15 use Friendica\Database\DBA;
16 use Friendica\Core\Renderer;
17 use Friendica\Core\Protocol;
18 use Friendica\Model\Contact;
19 use Friendica\Model\User;
21 function opmlexport_install()
23 Hook::register('addon_settings', __FILE__, 'opmlexport_addon_settings');
24 Hook::register('addon_settings_post', __FILE__, 'opmlexport_addon_settings_post');
25 Logger::notice('installed opmlexport Addon');
32 'uid' => DI::userSession()->getLocalUserId(),
38 'network' => Protocol::FEED
40 $data = Contact::selectToArray([], $condition, ['order' => ['name']]);
41 $user = User::getById(DI::userSession()->getLocalUserId());
43 $xml = new \DOMDocument( '1.0', 'utf-8' );
44 $opml = $xml->createElement('opml');
45 $head = $xml->createElement('head');
46 $body = $xml->createElement('body');
47 $outline = $xml->createElement('outline');
48 $outline->setAttribute('title', $user['username'] . '\'s RSS/Atom contacts');
49 $outline->setAttribute('text', $user['username'] . '\'s RSS/Atom contacts');
51 foreach($data as $c) {
52 $entry = $xml->createElement('outline');
53 $entry->setAttribute('title', $c['name']);
54 $entry->setAttribute('text', $c['name']);
55 $entry->setAttribute('xmlUrl', $c['url']);
56 $outline->appendChild($entry);
59 $body->appendChild($outline);
60 $opml->appendChild($head);
61 $opml->appendChild($body);
62 $xml->appendChild($opml);
63 header('Content-Type: text/x-opml');
64 header('Content-Disposition: attachment; filename=feeds.opml');
65 $xml->formatOutput = true;
71 function opmlexport_addon_settings(array &$data)
73 if (!DI::userSession()->getLocalUserId()) {
78 'addon' => 'opmlexport',
79 'title' => DI::l10n()->t('OPML Export'),
80 'submit' => DI::l10n()->t('Export RSS/Atom contacts'),
85 function opmlexport_addon_settings_post(array &$b)
87 if (!DI::userSession()->getLocalUserId() || empty($_POST['opmlexport-submit'])) {