friendica-github/src/Module/Debug/Feed.php

51 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model;
use Friendica\Protocol;
use Friendica\Util\Network;
/**
* Tests a given feed of a contact
*/
2019-05-18 19:05:13 +00:00
class Feed extends BaseModule
{
public static function init(array $parameters = [])
{
if (!local_user()) {
info(DI::l10n()->t('You must be logged in to use this module'));
DI::baseUrl()->redirect();
}
}
public static function content(array $parameters = [])
{
$result = [];
if (!empty($_REQUEST['url'])) {
$url = $_REQUEST['url'];
$contact_id = Model\Contact::getIdForURL($url, local_user(), true);
$contact = Model\Contact::getById($contact_id);
$xml = Network::fetchUrl($contact['poll']);
$import_result = Protocol\Feed::import($xml);
$result = [
'input' => $xml,
'output' => var_export($import_result, true),
];
}
$tpl = Renderer::getMarkupTemplate('feedtest.tpl');
return Renderer::replaceMacros($tpl, [
'$url' => ['url', DI::l10n()->t('Source URL'), $_REQUEST['url'] ?? '', ''],
'$result' => $result
]);
}
}