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