]> git.mxchange.org Git - friendica.git/blob - include/contact_widgets.php
cc25c88ed52bfccf2b3d74efba259e688f710a05
[friendica.git] / include / contact_widgets.php
1 <?php
2 /**
3  * @file include/contact_widgets.php
4  */
5 use Friendica\Content\ContactSelector;
6 use Friendica\Content\Feature;
7 use Friendica\Core\System;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10 use Friendica\Database\DBM;
11 use Friendica\Model\GContact;
12
13 function follow_widget($value = "")
14 {
15         return replace_macros(get_markup_template('follow.tpl'), array(
16                 '$connect' => t('Add New Contact'),
17                 '$desc' => t('Enter address or web location'),
18                 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
19                 '$value' => $value,
20                 '$follow' => t('Connect')
21         ));
22 }
23
24 function findpeople_widget()
25 {
26         $a = get_app();
27         $global_dir = Config::get('system', 'directory');
28
29         if (Config::get('system', 'invitation_only')) {
30                 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
31                 if ($x || is_site_admin()) {
32                         $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
33                                 . tt('%d invitation available', '%d invitations available', $x)
34                                 . '</div>' . $inv;
35                 }
36         }
37
38         return replace_macros(get_markup_template('peoplefind.tpl'), array(
39                 '$findpeople' => t('Find People'),
40                 '$desc' => t('Enter name or interest'),
41                 '$label' => t('Connect/Follow'),
42                 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
43                 '$findthem' => t('Find'),
44                 '$suggest' => t('Friend Suggestions'),
45                 '$similar' => t('Similar Interests'),
46                 '$random' => t('Random Profile'),
47                 '$inv' => t('Invite Friends'),
48                 '$directory' => t('View Global Directory'),
49                 '$global_dir' => $global_dir
50         ));
51 }
52
53 function unavailable_networks()
54 {
55         $networks = array();
56
57         if (!plugin_enabled("appnet")) {
58                 $networks[] = NETWORK_APPNET;
59         }
60
61         if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
62                 $networks[] = NETWORK_FACEBOOK;
63         }
64
65         if (!plugin_enabled("statusnet")) {
66                 $networks[] = NETWORK_STATUSNET;
67         }
68
69         if (!plugin_enabled("pumpio")) {
70                 $networks[] = NETWORK_PUMPIO;
71         }
72
73         if (!plugin_enabled("twitter")) {
74                 $networks[] = NETWORK_TWITTER;
75         }
76
77         if (Config::get("system", "ostatus_disabled")) {
78                 $networks[] = NETWORK_OSTATUS;
79         }
80
81         if (!Config::get("system", "diaspora_enabled")) {
82                 $networks[] = NETWORK_DIASPORA;
83         }
84
85         if (!plugin_enabled("pnut")) {
86                 $networks[] = NETWORK_PNUT;
87         }
88
89         if (!sizeof($networks)) {
90                 return "";
91         }
92
93         $network_filter = implode("','", $networks);
94
95         $network_filter = "AND `network` NOT IN ('$network_filter')";
96
97         return $network_filter;
98 }
99
100 function networks_widget($baseurl, $selected = '')
101 {
102         if (!local_user()) {
103                 return '';
104         }
105
106         if (!Feature::isEnabled(local_user(), 'networks')) {
107                 return '';
108         }
109
110         $extra_sql = unavailable_networks();
111
112         $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
113                 local_user()
114         );
115
116         $nets = array();
117         while ($rr = dba::fetch($r)) {
118                 /// @TODO If 'network' is not there, this triggers an E_NOTICE
119                 if ($rr['network']) {
120                         $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
121                 }
122         }
123         dba::close($r);
124
125         if (count($nets) < 2) {
126                 return '';
127         }
128
129         return replace_macros(get_markup_template('nets.tpl'), array(
130                 '$title' => t('Networks'),
131                 '$desc' => '',
132                 '$sel_all' => (($selected == '') ? 'selected' : ''),
133                 '$all' => t('All Networks'),
134                 '$nets' => $nets,
135                 '$base' => $baseurl,
136         ));
137 }
138
139 function fileas_widget($baseurl, $selected = '')
140 {
141         if (!local_user()) {
142                 return '';
143         }
144
145         if (!Feature::isEnabled(local_user(), 'filing')) {
146                 return '';
147         }
148
149         $saved = PConfig::get(local_user(), 'system', 'filetags');
150         if (!strlen($saved)) {
151                 return;
152         }
153
154         $matches = false;
155         $terms = array();
156         $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
157         if ($cnt) {
158                 foreach ($matches as $mtch) {
159                         $unescaped = xmlify(file_tag_decode($mtch[1]));
160                         $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
161                 }
162         }
163
164         return replace_macros(get_markup_template('fileas_widget.tpl'), array(
165                 '$title' => t('Saved Folders'),
166                 '$desc' => '',
167                 '$sel_all' => (($selected == '') ? 'selected' : ''),
168                 '$all' => t('Everything'),
169                 '$terms' => $terms,
170                 '$base' => $baseurl,
171         ));
172 }
173
174 function categories_widget($baseurl, $selected = '')
175 {
176         $a = get_app();
177
178         if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
179                 return '';
180         }
181
182         $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
183         if (!strlen($saved)) {
184                 return;
185         }
186
187         $matches = false;
188         $terms = array();
189         $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
190
191         if ($cnt) {
192                 foreach ($matches as $mtch) {
193                         $unescaped = xmlify(file_tag_decode($mtch[1]));
194                         $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
195                 }
196         }
197
198         return replace_macros(get_markup_template('categories_widget.tpl'), array(
199                 '$title' => t('Categories'),
200                 '$desc' => '',
201                 '$sel_all' => (($selected == '') ? 'selected' : ''),
202                 '$all' => t('Everything'),
203                 '$terms' => $terms,
204                 '$base' => $baseurl,
205         ));
206 }
207
208 function common_friends_visitor_widget($profile_uid)
209 {
210         if (local_user() == $profile_uid) {
211                 return;
212         }
213
214         $cid = $zcid = 0;
215
216         if (is_array($_SESSION['remote'])) {
217                 foreach ($_SESSION['remote'] as $visitor) {
218                         if ($visitor['uid'] == $profile_uid) {
219                                 $cid = $visitor['cid'];
220                                 break;
221                         }
222                 }
223         }
224
225         if (!$cid) {
226                 if (get_my_url()) {
227                         $r = dba::selectFirst('contact', ['id'],
228                                         ['nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid]);
229                         if (DBM::is_result($r)) {
230                                 $cid = $r['id'];
231                         } else {
232                                 $r = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(get_my_url())]);
233                                 if (DBM::is_result($r)) {
234                                         $zcid = $r['id'];
235                                 }
236                         }
237                 }
238         }
239
240         if ($cid == 0 && $zcid == 0) {
241                 return;
242         }
243
244         if ($cid) {
245                 $t = GContact::countCommonFriends($profile_uid, $cid);
246         } else {
247                 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
248         }
249
250         if (!$t) {
251                 return;
252         }
253
254         if ($cid) {
255                 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
256         } else {
257                 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
258         }
259
260         return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
261                 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
262                 '$base' => System::baseUrl(),
263                 '$uid' => $profile_uid,
264                 '$cid' => (($cid) ? $cid : '0'),
265                 '$linkmore' => (($t > 5) ? 'true' : ''),
266                 '$more' => t('show more'),
267                 '$items' => $r)
268         );
269 }