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

54 lines
1.2 KiB
PHP
Raw Normal View History

<?php
namespace Friendica\Module\Debug;
use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
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
{
2019-11-05 20:22:54 +00:00
public static function init($parameters)
{
if (!local_user()) {
info(L10n::t('You must be logged in to use this module'));
self::getApp()->internalRedirect();
}
}
2019-11-05 20:22:54 +00:00
public static function content($parameters)
{
$result = [];
if (!empty($_REQUEST['url'])) {
$url = $_REQUEST['url'];
$importer = Model\User::getById(local_user());
$contact_id = Model\Contact::getIdForURL($url, local_user(), true);
$contact = Model\Contact::getById($contact_id);
$xml = Network::fetchUrl($contact['poll']);
$dummy = null;
$import_result = Protocol\Feed::import($xml, $importer, $contact, $dummy, true);
$result = [
'input' => $xml,
'output' => var_export($import_result, true),
];
}
$tpl = Renderer::getMarkupTemplate('feedtest.tpl');
return Renderer::replaceMacros($tpl, [
'$url' => ['url', L10n::t('Source URL'), $_REQUEST['url'] ?? '', ''],
'$result' => $result
]);
}
}