2021-04-27 07:54:42 +00: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 18:52:20 +00:00
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Model\Contact;
|
2021-08-08 17:10:04 +00:00
|
|
|
use Friendica\Model\User;
|
2021-04-27 07:54:42 +00:00
|
|
|
|
2021-04-27 18:52:20 +00:00
|
|
|
function opmlexport_install()
|
|
|
|
{
|
2021-04-27 19:21:58 +00:00
|
|
|
Hook::register('addon_settings', __FILE__, 'opmlexport_addon_settings');
|
|
|
|
Hook::register('addon_settings_post', __FILE__, 'opmlexport_addon_settings_post');
|
2021-10-21 06:04:27 +00:00
|
|
|
Logger::notice('installed opmlexport Addon');
|
2021-04-27 07:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-04-27 18:52:20 +00:00
|
|
|
function opmlexport(App $a)
|
|
|
|
{
|
2021-04-27 19:21:58 +00:00
|
|
|
$condition = [
|
2022-10-20 21:51:49 +00:00
|
|
|
'uid' => DI::userSession()->getLocalUserId(),
|
2021-04-27 19:21:58 +00:00
|
|
|
'self' => false,
|
|
|
|
'deleted' => false,
|
|
|
|
'archive' => false,
|
|
|
|
'blocked' => false,
|
|
|
|
'pending' => false,
|
|
|
|
'network' => Protocol::FEED
|
|
|
|
];
|
|
|
|
$data = Contact::selectToArray([], $condition, ['order' => ['name']]);
|
2022-10-20 21:51:49 +00:00
|
|
|
$user = User::getById(DI::userSession()->getLocalUserId());
|
2021-04-27 07:54:42 +00:00
|
|
|
|
2021-04-27 19:21:58 +00:00
|
|
|
$xml = new \DOMDocument( '1.0', 'utf-8' );
|
|
|
|
$opml = $xml->createElement('opml');
|
|
|
|
$head = $xml->createElement('head');
|
|
|
|
$body = $xml->createElement('body');
|
|
|
|
$outline = $xml->createElement('outline');
|
2021-08-08 17:10:04 +00:00
|
|
|
$outline->setAttribute('title', $user['username'] . '\'s RSS/Atom contacts');
|
|
|
|
$outline->setAttribute('text', $user['username'] . '\'s RSS/Atom contacts');
|
2021-04-27 07:54:42 +00:00
|
|
|
|
2021-04-27 19:21:58 +00:00
|
|
|
foreach($data as $c) {
|
|
|
|
$entry = $xml->createElement('outline');
|
|
|
|
$entry->setAttribute('title', $c['name']);
|
|
|
|
$entry->setAttribute('text', $c['name']);
|
|
|
|
$entry->setAttribute('xmlUrl', $c['url']);
|
|
|
|
$outline->appendChild($entry);
|
|
|
|
}
|
2021-04-27 07:54:42 +00:00
|
|
|
|
2021-04-27 19:21:58 +00:00
|
|
|
$body->appendChild($outline);
|
|
|
|
$opml->appendChild($head);
|
|
|
|
$opml->appendChild($body);
|
|
|
|
$xml->appendChild($opml);
|
|
|
|
header('Content-Type: text/x-opml');
|
|
|
|
header('Content-Disposition: attachment; filename=feeds.opml');
|
|
|
|
$xml->formatOutput = true;
|
|
|
|
echo $xml->saveXML();
|
|
|
|
die();
|
2021-04-27 07:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-11-20 09:56:55 +00:00
|
|
|
function opmlexport_addon_settings(App $a, array &$data)
|
2021-04-27 18:52:20 +00:00
|
|
|
{
|
2022-10-20 21:51:49 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId()) {
|
2021-04-27 19:21:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-04-27 07:54:42 +00:00
|
|
|
|
2021-11-20 09:56:55 +00:00
|
|
|
$data = [
|
|
|
|
'addon' => 'opmlexport',
|
|
|
|
'title' => DI::l10n()->t('OPML Export'),
|
|
|
|
'submit' => DI::l10n()->t('Export RSS/Atom contacts'),
|
|
|
|
];
|
2021-04-27 07:54:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-23 05:16:22 +00:00
|
|
|
function opmlexport_addon_settings_post(App $a, array &$b)
|
2021-04-27 07:54:42 +00:00
|
|
|
{
|
2022-10-20 21:51:49 +00:00
|
|
|
if (!DI::userSession()->getLocalUserId() || empty($_POST['opmlexport-submit'])) {
|
2021-04-27 19:21:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-23 05:16:22 +00:00
|
|
|
|
2021-04-27 19:21:58 +00:00
|
|
|
opmlexport($a);
|
2021-04-27 07:54:42 +00:00
|
|
|
}
|