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