]> git.mxchange.org Git - friendica.git/commitdiff
Moving mod/feedtest to src/Module/Feedtest
authorPhilipp Holzer <admin@philipp.info>
Fri, 1 Mar 2019 09:50:31 +0000 (10:50 +0100)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sat, 23 Mar 2019 02:55:49 +0000 (22:55 -0400)
mod/feedtest.php [deleted file]
src/Model/Contact.php
src/Module/Feedtest.php [new file with mode: 0644]

diff --git a/mod/feedtest.php b/mod/feedtest.php
deleted file mode 100644 (file)
index cffc1f3..0000000
+++ /dev/null
@@ -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;
-}
index d938ad29c284dcb3fd21335c05ff2220e7d78c0e..fe373ae94a737923b3bc21be033e99a231b4ceaf 100644 (file)
@@ -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 (file)
index 0000000..ff4c960
--- /dev/null
@@ -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
+               ]);
+       }
+}