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 $stmt = DBA::p("SELECT *
33 AND NOT `archive` AND NOT `blocked` AND NOT `pending`
36 [local_user(), "feed"]
39 function opmlexport(App $a)
42 $xml = new \DOMDocument( '1.0', 'utf-8' );
43 $opml = $xml->createElement('opml');
44 $head = $xml->createElement('head');
45 $body = $xml->createElement('body');
46 $outline = $xml->createElement('outline');
47 $outline->setAttribute('title', $a->user['username'] . '\'s RSS/Atom contacts');
48 $outline->setAttribute('text', $a->user['username'] . '\'s RSS/Atom contacts');
50 while ($c = DBA::fetch($stmt)) {
51 $entry = $xml->createElement('outline');
52 $entry->setAttribute('title', $c['name']);
53 $entry->setAttribute('text', $c['name']);
54 $entry->setAttribute('xmlUrl', $c['url']);
55 $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(App $a, &$s)
77 $t = Renderer::getMarkupTemplate('settings.tpl', 'addon/opmlexport/');
78 $s .= Renderer::replaceMacros($t, [
79 '$title' => DI::l10n()->t('OPML Export'),
80 '$submit' => DI::l10n()->t('Export RSS/Atom contacts'),
85 function opmlexport_addon_settings_post(App $a, &$b)
87 if (!local_user() || empty($_POST['opmlexport-submit'])) {