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