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