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;
20 function opmlexport_install()
22 Hook::register('addon_settings', __FILE__, 'opmlexport_addon_settings');
23 Hook::register('addon_settings_post', __FILE__, 'opmlexport_addon_settings_post');
24 Logger::log('installed opmlexport Addon');
28 function opmlexport(App $a)
31 'uid' => local_user(),
37 'network' => Protocol::FEED
39 $data = Contact::selectToArray([], $condition, ['order' => ['name']]);
41 $xml = new \DOMDocument( '1.0', 'utf-8' );
42 $opml = $xml->createElement('opml');
43 $head = $xml->createElement('head');
44 $body = $xml->createElement('body');
45 $outline = $xml->createElement('outline');
46 $outline->setAttribute('title', $a->user['username'] . '\'s RSS/Atom contacts');
47 $outline->setAttribute('text', $a->user['username'] . '\'s RSS/Atom contacts');
49 foreach($data as $c) {
50 $entry = $xml->createElement('outline');
51 $entry->setAttribute('title', $c['name']);
52 $entry->setAttribute('text', $c['name']);
53 $entry->setAttribute('xmlUrl', $c['url']);
54 $outline->appendChild($entry);
57 $body->appendChild($outline);
58 $opml->appendChild($head);
59 $opml->appendChild($body);
60 $xml->appendChild($opml);
61 header('Content-Type: text/x-opml');
62 header('Content-Disposition: attachment; filename=feeds.opml');
63 $xml->formatOutput = true;
69 function opmlexport_addon_settings(App $a, &$s)
75 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/opmlexport/');
76 $s .= Renderer::replaceMacros($t, [
77 '$title' => DI::l10n()->t('OPML Export'),
78 '$submit' => DI::l10n()->t('Export RSS/Atom contacts'),
83 function opmlexport_addon_settings_post(App $a, &$b)
85 if (!local_user() || empty($_POST['opmlexport-submit'])) {