]> git.mxchange.org Git - friendica.git/commitdiff
Move mod/allfriends to src/Module/AllFriends
authorPhilipp Holzer <admin@philipp.info>
Thu, 2 May 2019 20:03:27 +0000 (22:03 +0200)
committerPhilipp Holzer <admin@philipp.info>
Thu, 2 May 2019 20:03:27 +0000 (22:03 +0200)
mod/allfriends.php [deleted file]
src/App/Router.php
src/Model/Contact.php
src/Module/AllFriends.php [new file with mode: 0644]
src/Module/Feed.php

diff --git a/mod/allfriends.php b/mod/allfriends.php
deleted file mode 100644 (file)
index ce648cc..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-/**
- * @file mod/allfriends.php
- */
-
-use Friendica\App;
-use Friendica\Content\ContactSelector;
-use Friendica\Content\Pager;
-use Friendica\Core\L10n;
-use Friendica\Core\Renderer;
-use Friendica\Core\System;
-use Friendica\Database\DBA;
-use Friendica\Model;
-use Friendica\Module;
-use Friendica\Util\Proxy as ProxyUtils;
-
-
-function allfriends_content(App $a)
-{
-       $o = '';
-       if (!local_user()) {
-               notice(L10n::t('Permission denied.') . EOL);
-               return;
-       }
-
-       $cid = 0;
-       if ($a->argc > 1) {
-               $cid = intval($a->argv[1]);
-       }
-
-       if (!$cid) {
-               return;
-       }
-
-       $uid = $a->user['uid'];
-
-       $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => local_user()]);
-
-       if (!DBA::isResult($contact)) {
-               return;
-       }
-
-       $a->page['aside'] = "";
-       Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
-
-       $total = Model\GContact::countAllFriends(local_user(), $cid);
-
-       $pager = new Pager($a->query_string);
-
-       $r = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
-       if (!DBA::isResult($r)) {
-               $o .= L10n::t('No friends to display.');
-               return $o;
-       }
-
-       $id = 0;
-
-       $entries = [];
-       foreach ($r as $rr) {
-               //get further details of the contact
-               $contact_details = Model\Contact::getDetailsByURL($rr['url'], $uid, $rr);
-
-               $connlnk = '';
-               // $rr[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photo_menu
-               // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
-               if ($rr['cid']) {
-                       $rr['id'] = $rr['cid'];
-                       $photo_menu = Model\Contact::photoMenu($rr);
-               } else {
-                       $connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
-                       $photo_menu = [
-                               'profile' => [L10n::t("View Profile"), Model\Contact::magicLink($rr['url'])],
-                               'follow' => [L10n::t("Connect/Follow"), $connlnk]
-                       ];
-               }
-
-               $entry = [
-                       'url'          => Model\Contact::magicLink($rr['url']),
-                       'itemurl'      => defaults($contact_details, 'addr', $rr['url']),
-                       'name'         => $contact_details['name'],
-                       'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
-                       'img_hover'    => $contact_details['name'],
-                       'details'      => $contact_details['location'],
-                       'tags'         => $contact_details['keywords'],
-                       'about'        => $contact_details['about'],
-                       'account_type' => Model\Contact::getAccountType($contact_details),
-                       'network'      => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
-                       'photo_menu'   => $photo_menu,
-                       'conntxt'      => L10n::t('Connect'),
-                       'connlnk'      => $connlnk,
-                       'id'           => ++$id,
-               ];
-               $entries[] = $entry;
-       }
-
-       $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
-
-       $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
-       $o .= Renderer::replaceMacros($tpl, [
-               '$tab_str' => $tab_str,
-               '$contacts' => $entries,
-               '$paginate' => $pager->renderFull($total),
-       ]);
-
-       return $o;
-}
index e2a6719f6c941caf6aa54bae96ef4f2248a21835..a3d6af75814d3a8f9e4f3a7cb3c1ba1a2f3ccb8d 100644 (file)
@@ -40,15 +40,51 @@ class Router
         */
        public function collectRoutes()
        {
-               $this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Itemsource::class);
-               $this->routeCollector->addRoute(['GET'],         '/amcd',                Module\AccountManagementControlDocument::class);
                $this->routeCollector->addGroup('/.well-known', function (RouteCollector $collector) {
                        $collector->addRoute(['GET'], '/host-meta'       , Module\WellKnown\HostMeta::class);
                        $collector->addRoute(['GET'], '/nodeinfo[/1.0]'  , Module\NodeInfo::class);
                        $collector->addRoute(['GET'], '/webfinger'       , Module\Xrd::class);
                        $collector->addRoute(['GET'], '/x-social-relay'  , Module\WellKnown\XSocialRelay::class);
                });
+               $this->routeCollector->addGroup('/admin', function (RouteCollector $collector) {
+                       $collector->addRoute(['GET']        , '[/]'                     , Module\Admin\Summary::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/addons'                 , Module\Admin\Addons\Index::class);
+                       $collector->addRoute(['GET', 'POST'], '/addons/{addon}'         , Module\Admin\Addons\Details::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/blocklist/contact'      , Module\Admin\Blocklist\Contact::class);
+                       $collector->addRoute(['GET', 'POST'], '/blocklist/server'       , Module\Admin\Blocklist\Server::class);
+
+                       $collector->addRoute(['GET']        , '/dbsync[/check]'         , Module\Admin\DBSync::class);
+                       $collector->addRoute(['GET']        , '/dbsync/{update:\d+}'    , Module\Admin\DBSync::class);
+                       $collector->addRoute(['GET']        , '/dbsync/mark/{update:\d+}', Module\Admin\DBSync::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/features'               , Module\Admin\Features::class);
+                       $collector->addRoute(['GET']        , '/federation'             , Module\Admin\Federation::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/item/delete'            , Module\Admin\Item\Delete::class);
+                       $collector->addRoute(['GET', 'POST'], '/item/source[/{guid}]'   , Module\Admin\Item\Source::class);
+
+                       $collector->addRoute(['GET']        , '/logs/view'              , Module\Admin\Logs\View::class);
+                       $collector->addRoute(['GET', 'POST'], '/logs'                   , Module\Admin\Logs\Settings::class);
+
+                       $collector->addRoute(['GET']        , '/phpinfo'                , Module\Admin\PhpInfo::class);
+
+                       $collector->addRoute(['GET']        , '/queue[/deferred]'       , Module\Admin\Queue::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/site'                   , Module\Admin\Site::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/themes'                 , Module\Admin\Themes\Index::class);
+                       $collector->addRoute(['GET', 'POST'], '/themes/{theme}'         , Module\Admin\Themes\Details::class);
+                       $collector->addRoute(['GET', 'POST'], '/themes/{theme}/embed'   , Module\Admin\Themes\Embed::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/tos'                    , Module\Admin\Tos::class);
+
+                       $collector->addRoute(['GET', 'POST'], '/users[/{action}/{uid}]' , Module\Admin\Users::class);
+               });
+               $this->routeCollector->addRoute(['GET'],         '/amcd',                Module\AccountManagementControlDocument::class);
                $this->routeCollector->addRoute(['GET'],         '/acctlink',            Module\Acctlink::class);
+               $this->routeCollector->addRoute(['GET'],         '/allfriends/{id:\d+}', Module\AllFriends::class);
                $this->routeCollector->addRoute(['GET'],         '/apps',                Module\Apps::class);
                $this->routeCollector->addRoute(['GET'],         '/attach/{item:\d+}',   Module\Attach::class);
                $this->routeCollector->addRoute(['GET'],         '/babel',               Module\Babel::class);
@@ -85,6 +121,7 @@ class Router
                        $collector->addRoute(['GET', 'POST'], '[/]',                         Module\Install::class);
                        $collector->addRoute(['GET'],         '/testrewrite',                Module\Install::class);
                });
+               $this->routeCollector->addRoute(['GET', 'POST'], '/itemsource[/{guid}]', Module\Itemsource::class);
                $this->routeCollector->addRoute(['GET', 'POST'], '/localtime',           Module\Localtime::class);
                $this->routeCollector->addRoute(['GET', 'POST'], '/login',               Module\Login::class);
                $this->routeCollector->addRoute(['GET'],         '/magic',               Module\Magic::class);
@@ -117,43 +154,6 @@ class Router
                $this->routeCollector->addRoute(['GET'],         '/tos',                 Module\Tos::class);
                $this->routeCollector->addRoute(['GET'],         '/webfinger',           Module\WebFinger::class);
                $this->routeCollector->addRoute(['GET'],         '/xrd',                 Module\Xrd::class);
-
-               $this->routeCollector->addGroup('/admin', function (RouteCollector $collector) {
-                       $collector->addRoute(['GET']        , '[/]'                     , Module\Admin\Summary::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/addons'                 , Module\Admin\Addons\Index::class);
-                       $collector->addRoute(['GET', 'POST'], '/addons/{addon}'         , Module\Admin\Addons\Details::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/blocklist/contact'      , Module\Admin\Blocklist\Contact::class);
-                       $collector->addRoute(['GET', 'POST'], '/blocklist/server'       , Module\Admin\Blocklist\Server::class);
-
-                       $collector->addRoute(['GET']        , '/dbsync[/check]'         , Module\Admin\DBSync::class);
-                       $collector->addRoute(['GET']        , '/dbsync/{update:\d+}'    , Module\Admin\DBSync::class);
-                       $collector->addRoute(['GET']        , '/dbsync/mark/{update:\d+}', Module\Admin\DBSync::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/features'               , Module\Admin\Features::class);
-                       $collector->addRoute(['GET']        , '/federation'             , Module\Admin\Federation::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/item/delete'            , Module\Admin\Item\Delete::class);
-                       $collector->addRoute(['GET', 'POST'], '/item/source[/{guid}]'   , Module\Admin\Item\Source::class);
-
-                       $collector->addRoute(['GET']        , '/logs/view'              , Module\Admin\Logs\View::class);
-                       $collector->addRoute(['GET', 'POST'], '/logs'                   , Module\Admin\Logs\Settings::class);
-
-                       $collector->addRoute(['GET']        , '/phpinfo'                , Module\Admin\PhpInfo::class);
-
-                       $collector->addRoute(['GET']        , '/queue[/deferred]'       , Module\Admin\Queue::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/site'                   , Module\Admin\Site::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/themes'                 , Module\Admin\Themes\Index::class);
-                       $collector->addRoute(['GET', 'POST'], '/themes/{theme}'         , Module\Admin\Themes\Details::class);
-                       $collector->addRoute(['GET', 'POST'], '/themes/{theme}/embed'   , Module\Admin\Themes\Embed::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/tos'                    , Module\Admin\Tos::class);
-
-                       $collector->addRoute(['GET', 'POST'], '/users[/{action}/{uid}]' , Module\Admin\Users::class);
-               });
        }
 
        public function __construct(RouteCollector $routeCollector = null)
index beb91d11a0b1f3a74e21383c97a2413eaaa4d435..6e7860c8aae96d58541d59cbfc40e763cb9866cb 100644 (file)
@@ -237,6 +237,28 @@ class Contact extends BaseObject
                return ['public' => $pcid, 'user' => $ucid];
        }
 
+       /**
+        * Returns contact details for a given contact id in combination with a user id
+        *
+        * @param int $cid A contact ID
+        * @param int $uid The User ID
+        * @param array $fields The selected fields for the contact
+        *
+        * @return array The contact details
+        *
+        * @throws \Exception
+        */
+       public static function getContactForUser($cid, $uid, array $fields = [])
+       {
+               $contact = DBA::selectFirst('contact', $fields, ['id' => $cid, 'uid' => $uid]);
+
+               if (!DBA::isResult($contact)) {
+                       return [];
+               } else {
+                       return $contact;
+               }
+       }
+
        /**
         * @brief Block contact id for user id
         *
diff --git a/src/Module/AllFriends.php b/src/Module/AllFriends.php
new file mode 100644 (file)
index 0000000..37710d4
--- /dev/null
@@ -0,0 +1,104 @@
+<?php
+
+namespace Friendica\Module;
+
+use Friendica\BaseModule;
+use Friendica\Content\ContactSelector;
+use Friendica\Content\Pager;
+use Friendica\Core\L10n;
+use Friendica\Core\Renderer;
+use Friendica\Model;
+use Friendica\Network\HTTPException;
+use Friendica\Util\Proxy as ProxyUtils;
+
+class AllFriends extends BaseModule
+{
+       public static function content()
+       {
+               $app = self::getApp();
+
+               if (!local_user()) {
+                       throw new HTTPException\ForbiddenException();
+               }
+
+               $cid = 0;
+
+               // @TODO: Replace with parameter from router
+               if ($app->argc > 1) {
+                       $cid = intval($app->argv[1]);
+               }
+
+               if (!$cid) {
+                       throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
+               }
+
+               $uid = $app->user['uid'];
+
+               $contact = Model\Contact::getContactForUser($cid, local_user(), ['name', 'url', 'photo', 'uid', 'id']);
+
+               if (empty($contact)) {
+                       throw new HTTPException\BadRequestException(L10n::t('Invalid contact.'));
+               }
+
+               $app->page['aside'] = "";
+               Model\Profile::load($app, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
+
+               $total = Model\GContact::countAllFriends(local_user(), $cid);
+
+               $pager = new Pager($app->query_string);
+
+               $friends = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
+               if (empty($friends)) {
+                       return L10n::t('No friends to display.');
+               }
+
+               $id = 0;
+
+               $entries = [];
+               foreach ($friends as $friend) {
+                       //get further details of the contact
+                       $contactDetails = Model\Contact::getDetailsByURL($friend['url'], $uid, $friend);
+
+                       $connlnk = '';
+                       // $friend[cid] is only available for common contacts. So if the contact is a common one, use contact_photo_menu to generate the photoMenu
+                       // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
+                       if ($friend['cid']) {
+                               $friend['id'] = $friend['cid'];
+                               $photoMenu = Model\Contact::photoMenu($friend);
+                       } else {
+                               $connlnk = $app->getBaseURL() . '/follow/?url=' . $friend['url'];
+                               $photoMenu = [
+                                       'profile' => [L10n::t("View Profile"), Model\Contact::magicLink($friend['url'])],
+                                       'follow'  => [L10n::t("Connect/Follow"), $connlnk]
+                               ];
+                       }
+
+                       $entry = [
+                               'url'          => Model\Contact::magicLink($friend['url']),
+                               'itemurl'      => defaults($contactDetails, 'addr', $friend['url']),
+                               'name'         => $contactDetails['name'],
+                               'thumb'        => ProxyUtils::proxifyUrl($contactDetails['thumb'], false, ProxyUtils::SIZE_THUMB),
+                               'img_hover'    => $contactDetails['name'],
+                               'details'      => $contactDetails['location'],
+                               'tags'         => $contactDetails['keywords'],
+                               'about'        => $contactDetails['about'],
+                               'account_type' => Model\Contact::getAccountType($contactDetails),
+                               'network'      => ContactSelector::networkToName($contactDetails['network'], $contactDetails['url']),
+                               'photoMenu'    => $photoMenu,
+                               'conntxt'      => L10n::t('Connect'),
+                               'connlnk'      => $connlnk,
+                               'id'           => ++$id,
+                       ];
+                       $entries[] = $entry;
+               }
+
+               $tab_str = Contact::getTabsHTML($app, $contact, 4);
+
+               $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
+               return Renderer::replaceMacros($tpl, [
+                       '$tab_str'  => $tab_str,
+                       '$contacts' => $entries,
+                       '$paginate' => $pager->renderFull($total),
+               ]);
+       }
+}
index ba1b085963d9d2afb99d37506d5e7aca39530ea8..15b2026e2c246559668a4e30df495e8a811280d0 100644 (file)
@@ -3,7 +3,6 @@
 namespace Friendica\Module;
 
 use Friendica\BaseModule;
-use Friendica\Core\System;
 use Friendica\Protocol\OStatus;
 
 /**