2021-04-27 03:54:42 -04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Name: OPML Export
|
|
|
|
* Description: Export user's RSS/Atom contacts as OPML
|
|
|
|
* Version: 1.0
|
|
|
|
* Author: Fabio Comuni <https://social.gl-como.it/profile/fabrixxm>
|
|
|
|
* License: 3-clause BSD license
|
|
|
|
*/
|
|
|
|
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\App;
|
|
|
|
use Friendica\Core\Hook;
|
|
|
|
use Friendica\Core\Logger;
|
|
|
|
use Friendica\Network\HTTPException;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\Core\Renderer;
|
2021-04-27 14:52:20 -04:00
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Model\Contact;
|
2021-04-27 03:54:42 -04:00
|
|
|
|
2021-04-27 14:52:20 -04:00
|
|
|
function opmlexport_install()
|
|
|
|
{
|
|
|
|
Hook::register('addon_settings', __FILE__, 'opmlexport_addon_settings');
|
|
|
|
Hook::register('addon_settings_post', __FILE__, 'opmlexport_addon_settings_post');
|
|
|
|
Logger::log('installed opmlexport Addon');
|
2021-04-27 03:54:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-27 14:52:20 -04:00
|
|
|
function opmlexport(App $a)
|
|
|
|
{
|
2021-04-27 15:08:42 -04:00
|
|
|
$condition = [
|
|
|
|
'uid' => local_user(),
|
|
|
|
'self' => false,
|
|
|
|
'deleted' => false,
|
|
|
|
'archive' => false,
|
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
|
|
|
'network' => Protocol::FEED
|
|
|
|
];
|
|
|
|
$data = Contact::selectToArray([], $condition, ['order' => ['name']]);
|
2021-04-27 03:54:42 -04:00
|
|
|
|
2021-04-27 14:52:20 -04:00
|
|
|
$xml = new \DOMDocument( '1.0', 'utf-8' );
|
|
|
|
$opml = $xml->createElement('opml');
|
|
|
|
$head = $xml->createElement('head');
|
|
|
|
$body = $xml->createElement('body');
|
|
|
|
$outline = $xml->createElement('outline');
|
|
|
|
$outline->setAttribute('title', $a->user['username'] . '\'s RSS/Atom contacts');
|
|
|
|
$outline->setAttribute('text', $a->user['username'] . '\'s RSS/Atom contacts');
|
2021-04-27 03:54:42 -04:00
|
|
|
|
2021-04-27 15:08:42 -04:00
|
|
|
foreach($data as $c) {
|
2021-04-27 14:52:20 -04:00
|
|
|
$entry = $xml->createElement('outline');
|
|
|
|
$entry->setAttribute('title', $c['name']);
|
|
|
|
$entry->setAttribute('text', $c['name']);
|
|
|
|
$entry->setAttribute('xmlUrl', $c['url']);
|
2021-04-27 03:54:42 -04:00
|
|
|
$outline->appendChild($entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
$body->appendChild($outline);
|
|
|
|
$opml->appendChild($head);
|
|
|
|
$opml->appendChild($body);
|
|
|
|
$xml->appendChild($opml);
|
2021-04-27 14:52:20 -04:00
|
|
|
header('Content-Type: text/x-opml');
|
|
|
|
header('Content-Disposition: attachment; filename=feeds.opml');
|
2021-04-27 03:54:42 -04:00
|
|
|
$xml->formatOutput = true;
|
|
|
|
echo $xml->saveXML();
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-27 14:52:20 -04:00
|
|
|
function opmlexport_addon_settings(App $a, &$s)
|
|
|
|
{
|
|
|
|
if (!local_user()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-27 03:54:42 -04:00
|
|
|
|
2021-04-27 14:52:20 -04:00
|
|
|
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/opmlexport/');
|
|
|
|
$s .= Renderer::replaceMacros($t, [
|
|
|
|
'$title' => DI::l10n()->t('OPML Export'),
|
|
|
|
'$submit' => DI::l10n()->t('Export RSS/Atom contacts'),
|
|
|
|
]);
|
2021-04-27 03:54:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function opmlexport_addon_settings_post(App $a, &$b)
|
|
|
|
{
|
2021-04-27 14:52:20 -04:00
|
|
|
if (!local_user() || empty($_POST['opmlexport-submit'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
opmlexport($a);
|
2021-04-27 03:54:42 -04:00
|
|
|
}
|