Moving mod/feedtest to src/Module/Feedtest
This commit is contained in:
parent
ec2c84a4e9
commit
083820b107
3 changed files with 65 additions and 50 deletions
|
@ -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;
|
||||
}
|
|
@ -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
Normal file
55
src/Module/Feedtest.php
Normal file
|
@ -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…
Reference in a new issue