From c5e7abf9c552689812f1388ebba5e87fe245ad41 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Thu, 2 May 2019 22:03:27 +0200 Subject: [PATCH] Move mod/allfriends to src/Module/AllFriends --- mod/allfriends.php | 106 -------------------------------------- src/App/Router.php | 78 ++++++++++++++-------------- src/Model/Contact.php | 22 ++++++++ src/Module/AllFriends.php | 104 +++++++++++++++++++++++++++++++++++++ src/Module/Feed.php | 1 - 5 files changed, 165 insertions(+), 146 deletions(-) delete mode 100644 mod/allfriends.php create mode 100644 src/Module/AllFriends.php diff --git a/mod/allfriends.php b/mod/allfriends.php deleted file mode 100644 index ce648cc25a..0000000000 --- a/mod/allfriends.php +++ /dev/null @@ -1,106 +0,0 @@ -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; -} diff --git a/src/App/Router.php b/src/App/Router.php index e2a6719f6c..a3d6af7581 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -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) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index beb91d11a0..6e7860c8aa 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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 index 0000000000..37710d4d9c --- /dev/null +++ b/src/Module/AllFriends.php @@ -0,0 +1,104 @@ +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), + ]); + } +} diff --git a/src/Module/Feed.php b/src/Module/Feed.php index ba1b085963..15b2026e2c 100644 --- a/src/Module/Feed.php +++ b/src/Module/Feed.php @@ -3,7 +3,6 @@ namespace Friendica\Module; use Friendica\BaseModule; -use Friendica\Core\System; use Friendica\Protocol\OStatus; /** -- 2.39.5