Browse Source

Moving mod/feedtest to src/Module/Feedtest

pull/6923/head
Philipp Holzer 4 years ago committed by Hypolite Petovan
parent
commit
083820b107
  1. 50
      mod/feedtest.php
  2. 10
      src/Model/Contact.php
  3. 55
      src/Module/Feedtest.php

50
mod/feedtest.php

@ -1,50 +0,0 @@
<?php
/**
* @file_tag_list_to_file mod/feedtest.php
*/
use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\Model\Contact;
use Friendica\Protocol\Feed;
use Friendica\Util\Network;
function feedtest_content(App $a)
{
if (!local_user()) {
info(L10n::t('You must be logged in to use this module'));
return;
};
$result = [];
if (!empty($_REQUEST['url'])) {
$url = $_REQUEST['url'];
$importer = DBA::selectFirst('user', [], ['uid' => local_user()]);
$contact_id = Contact::getIdForURL($url, local_user(), true);
$contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
$xml = Network::fetchUrl($contact['poll']);
$dummy = null;
$import_result = Feed::import($xml, $importer, $contact, $dummy, true);
$result = [
'input' => $xml,
'output' => var_export($import_result, true),
];
}
$tpl = Renderer::getMarkupTemplate('feedtest.tpl');
$o = Renderer::replaceMacros($tpl, [
'$url' => ['url', L10n::t('Source URL'), defaults($_REQUEST, 'url', ''), ''],
'$result' => $result
]);
return $o;
}

10
src/Model/Contact.php

@ -109,6 +109,16 @@ class Contact extends BaseObject
* @}
*/
/**
* @param integer $id
* @return array|boolean Contact record if it exists, false otherwise
* @throws \Exception
*/
public static function getById($id)
{
return DBA::selectFirst('contact', [], ['id' => $id]);
}
/**
* @brief Tests if the given contact is a follower
*

55
src/Module/Feedtest.php

@ -0,0 +1,55 @@
<?php
namespace Friendica\Module;
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
*/
class Feedtest extends BaseModule
{
public static function init()
{
if (!local_user()) {
info(L10n::t('You must be logged in to use this module'));
self::getApp()->internalRedirect();
}
}
public static function content()
{
$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),
];
}
print_r($result);
$tpl = Renderer::getMarkupTemplate('feedtest.tpl');
return Renderer::replaceMacros($tpl, [
'$url' => ['url', L10n::t('Source URL'), defaults($_REQUEST, 'url', ''), ''],
'$result' => $result
]);
}
}
Loading…
Cancel
Save