]> git.mxchange.org Git - friendica.git/blob - mod/allfriends.php
Remove unreliable ANY_VALUE from message list query
[friendica.git] / mod / allfriends.php
1 <?php
2 /**
3  * @file mod/allfriends.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Pager;
9 use Friendica\Core\L10n;
10 use Friendica\Core\Renderer;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Model;
14 use Friendica\Module;
15 use Friendica\Util\Proxy as ProxyUtils;
16
17
18 require_once 'include/dba.php';
19
20 function allfriends_content(App $a)
21 {
22         $o = '';
23         if (!local_user()) {
24                 notice(L10n::t('Permission denied.') . EOL);
25                 return;
26         }
27
28         $cid = 0;
29         if ($a->argc > 1) {
30                 $cid = intval($a->argv[1]);
31         }
32
33         if (!$cid) {
34                 return;
35         }
36
37         $uid = $a->user['uid'];
38
39         $contact = DBA::selectFirst('contact', ['name', 'url', 'photo', 'uid', 'id'], ['id' => $cid, 'uid' => local_user()]);
40
41         if (!DBA::isResult($contact)) {
42                 return;
43         }
44
45         $a->page['aside'] = "";
46         Model\Profile::load($a, "", 0, Model\Contact::getDetailsByURL($contact["url"]));
47
48         $total = Model\GContact::countAllFriends(local_user(), $cid);
49
50         $pager = new Pager($a->query_string);
51
52         $r = Model\GContact::allFriends(local_user(), $cid, $pager->getStart(), $pager->getItemsPerPage());
53         if (!DBA::isResult($r)) {
54                 $o .= L10n::t('No friends to display.');
55                 return $o;
56         }
57
58         $id = 0;
59
60         $entries = [];
61         foreach ($r as $rr) {
62                 //get further details of the contact
63                 $contact_details = Model\Contact::getDetailsByURL($rr['url'], $uid, $rr);
64
65                 $photo_menu = '';
66
67                 $connlnk = '';
68                 // $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
69                 // If the contact is not common to the user, Connect/Follow' will be added to the photo menu
70                 if ($rr['cid']) {
71                         $rr['id'] = $rr['cid'];
72                         $photo_menu = Model\Contact::photoMenu($rr);
73                 } else {
74                         $connlnk = System::baseUrl() . '/follow/?url=' . $rr['url'];
75                         $photo_menu = [
76                                 'profile' => [L10n::t("View Profile"), Model\Contact::magicLink($rr['url'])],
77                                 'follow' => [L10n::t("Connect/Follow"), $connlnk]
78                         ];
79                 }
80
81                 $entry = [
82                         'url'          => $rr['url'],
83                         'itemurl'      => defaults($contact_details, 'addr', $rr['url']),
84                         'name'         => htmlentities($contact_details['name']),
85                         'thumb'        => ProxyUtils::proxifyUrl($contact_details['thumb'], false, ProxyUtils::SIZE_THUMB),
86                         'img_hover'    => htmlentities($contact_details['name']),
87                         'details'      => $contact_details['location'],
88                         'tags'         => $contact_details['keywords'],
89                         'about'        => $contact_details['about'],
90                         'account_type' => Model\Contact::getAccountType($contact_details),
91                         'network'      => ContactSelector::networkToName($contact_details['network'], $contact_details['url']),
92                         'photo_menu'   => $photo_menu,
93                         'conntxt'      => L10n::t('Connect'),
94                         'connlnk'      => $connlnk,
95                         'id'           => ++$id,
96                 ];
97                 $entries[] = $entry;
98         }
99
100         $tab_str = Module\Contact::getTabsHTML($a, $contact, 4);
101
102         $tpl = Renderer::getMarkupTemplate('viewcontact_template.tpl');
103
104         $o .= Renderer::replaceMacros($tpl, [
105                 //'$title' => L10n::t('Friends of %s', htmlentities($c[0]['name'])),
106                 '$tab_str' => $tab_str,
107                 '$contacts' => $entries,
108                 '$paginate' => $pager->renderFull($total),
109         ]);
110
111         return $o;
112 }