]> git.mxchange.org Git - friendica.git/blob - mod/common.php
Change called method names
[friendica.git] / mod / common.php
1 <?php
2 /**
3  * @file include/common.php
4  */
5 use Friendica\App;
6 use Friendica\Database\DBM;
7 use Friendica\Model\GlobalContact;
8 use Friendica\Object\Contact;
9
10 require_once 'include/Contact.php';
11 require_once 'include/contact_selectors.php';
12 require_once 'mod/contacts.php';
13
14 function common_content(App $a) {
15
16         $o = '';
17
18         $cmd = $a->argv[1];
19         $uid = intval($a->argv[2]);
20         $cid = intval($a->argv[3]);
21         $zcid = 0;
22
23         if (! local_user()) {
24                 notice( t('Permission denied.') . EOL);
25                 return;
26         }
27
28         if ($cmd !== 'loc' && $cmd != 'rem') {
29                 return;
30         }
31
32         if (! $uid) {
33                 return;
34         }
35
36         if ($cmd === 'loc' && $cid) {
37                 $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
38                         intval($cid),
39                         intval($uid)
40                 );
41                 /// @TODO Handle $c with DBM::is_result()
42                 $a->page['aside'] = "";
43                 profile_load($a, "", 0, Contact::getDetailsByURL($c[0]["url"]));
44         } else {
45                 $c = q("SELECT `name`, `url`, `photo` FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
46                         intval($uid)
47                 );
48                 /// @TODO Handle $c with DBM::is_result()
49
50                 $vcard_widget .= replace_macros(get_markup_template("vcard-widget.tpl"),array(
51                         '$name' => htmlentities($c[0]['name']),
52                         '$photo' => $c[0]['photo'],
53                         'url' => 'contacts/' . $cid
54                 ));
55
56                 if (! x($a->page,'aside')) {
57                         $a->page['aside'] = '';
58                 }
59                 $a->page['aside'] .= $vcard_widget;
60         }
61
62         if (! DBM::is_result($c)) {
63                 return;
64         }
65
66         if(! $cid) {
67                 if(get_my_url()) {
68                         $r = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d LIMIT 1",
69                                 dbesc(normalise_link(get_my_url())),
70                                 intval($profile_uid)
71                         );
72                         if (DBM::is_result($r))
73                                 $cid = $r[0]['id'];
74                         else {
75                                 $r = q("SELECT `id` FROM `gcontact` WHERE `nurl` = '%s' LIMIT 1",
76                                         dbesc(normalise_link(get_my_url()))
77                                 );
78                                 if (DBM::is_result($r))
79                                         $zcid = $r[0]['id'];
80                         }
81                 }
82         }
83
84         if ($cid == 0 && $zcid == 0) {
85                 return;
86         }
87
88         if ($cid) {
89                 $t = GlobalContact::countCommonFriends($uid, $cid);
90         } else {
91                 $t = GlobalContact::countCommonFriendsZcid($uid, $zcid);
92         }
93
94         if (count($t)) {
95                 $a->set_pager_total($t);
96         } else {
97                 notice(t('No contacts in common.') . EOL);
98                 return $o;
99         }
100
101
102         if ($cid) {
103                 $r = GlobalContact::commonFriends($uid, $cid, $a->pager['start'], $a->pager['itemspage']);
104         } else {
105                 $r = GlobalContact::commonFriendsZcid($uid, $zcid, $a->pager['start'], $a->pager['itemspage']);
106         }
107
108
109         if (! DBM::is_result($r)) {
110                 return $o;
111         }
112
113         $id = 0;
114
115         foreach ($r as $rr) {
116
117                 //get further details of the contact
118                 $contact_details = Contact::getDetailsByURL($rr['url'], $uid);
119
120                 // $rr['id'] is needed to use contact_photo_menu()
121                 /// @TODO Adding '/" here avoids E_NOTICE on missing constants
122                 $rr['id'] = $rr['cid'];
123
124                 $photo_menu = '';
125                 $photo_menu = Contact::photoMenu($rr);
126
127                 $entry = array(
128                         'url'          => $rr['url'],
129                         'itemurl'      => (($contact_details['addr'] != "") ? $contact_details['addr'] : $rr['url']),
130                         'name'         => $contact_details['name'],
131                         'thumb'        => proxy_url($contact_details['thumb'], false, PROXY_SIZE_THUMB),
132                         'img_hover'    => htmlentities($contact_details['name']),
133                         'details'      => $contact_details['location'],
134                         'tags'         => $contact_details['keywords'],
135                         'about'        => $contact_details['about'],
136                         'account_type' => Contact::getAccountType($contact_details),
137                         'network'      => network_to_name($contact_details['network'], $contact_details['url']),
138                         'photo_menu'   => $photo_menu,
139                         'id'           => ++$id,
140                 );
141                 $entries[] = $entry;
142         }
143
144         if ($cmd === 'loc' && $cid && $uid == local_user()) {
145                 $tab_str = contacts_tab($a, $cid, 4);
146         } else {
147                 $title = t('Common Friends');
148         }
149
150         $tpl = get_markup_template('viewcontact_template.tpl');
151
152         $o .= replace_macros($tpl,array(
153                 '$title'    => $title,
154                 '$tab_str'  => $tab_str,
155                 '$contacts' => $entries,
156                 '$paginate' => paginate($a),
157         ));
158
159         return $o;
160 }