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