From 083820b1077a260c53d8701c8d0b6e78a57667fc Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Fri, 1 Mar 2019 10:50:31 +0100 Subject: [PATCH] Moving mod/feedtest to src/Module/Feedtest --- mod/feedtest.php | 50 ------------------------------------- src/Model/Contact.php | 10 ++++++++ src/Module/Feedtest.php | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 50 deletions(-) delete mode 100644 mod/feedtest.php create mode 100644 src/Module/Feedtest.php diff --git a/mod/feedtest.php b/mod/feedtest.php deleted file mode 100644 index cffc1f3451..0000000000 --- a/mod/feedtest.php +++ /dev/null @@ -1,50 +0,0 @@ - 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; -} diff --git a/src/Model/Contact.php b/src/Model/Contact.php index d938ad29c2..fe373ae94a 100644 --- a/src/Model/Contact.php +++ b/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 * diff --git a/src/Module/Feedtest.php b/src/Module/Feedtest.php new file mode 100644 index 0000000000..ff4c960c1b --- /dev/null +++ b/src/Module/Feedtest.php @@ -0,0 +1,55 @@ +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 + ]); + } +} -- 2.39.5