]> git.mxchange.org Git - friendica.git/blob - include/contact_widgets.php
Merge remote-tracking branch 'upstream/develop' into develop
[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 (!sizeof($networks))
70                 return "";
71
72         $network_filter = implode("','", $networks);
73
74         $network_filter = "AND `network` NOT IN ('$network_filter')";
75
76         return $network_filter;
77 }
78
79 function networks_widget($baseurl,$selected = '') {
80
81         $a = get_app();
82
83         if (!local_user()) {
84                 return '';
85         }
86
87         if (!feature_enabled(local_user(),'networks')) {
88                 return '';
89         }
90
91         $extra_sql = unavailable_networks();
92
93         $r = q("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = %d AND NOT `self` $extra_sql ORDER BY `network`",
94                 intval(local_user())
95         );
96
97         $nets = array();
98         if (dbm::is_result($r)) {
99                 require_once('include/contact_selectors.php');
100                 foreach($r as $rr) {
101                                 if($rr['network'])
102                                         $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
103                 }
104         }
105
106         if(count($nets) < 2)
107                 return '';
108
109         return replace_macros(get_markup_template('nets.tpl'),array(
110                 '$title' => t('Networks'),
111                 '$desc' => '',
112                 '$sel_all' => (($selected == '') ? 'selected' : ''),
113                 '$all' => t('All Networks'),
114                 '$nets' => $nets,
115                 '$base' => $baseurl,
116
117         ));
118 }
119
120 function fileas_widget($baseurl,$selected = '') {
121         if (! local_user()) {
122                 return '';
123         }
124
125         if (! feature_enabled(local_user(),'filing')) {
126                 return '';
127         }
128
129         $saved = get_pconfig(local_user(),'system','filetags');
130         if (! strlen($saved)) {
131                 return;
132         }
133
134         $matches = false;
135         $terms = array();
136     $cnt = preg_match_all('/\[(.*?)\]/',$saved,$matches,PREG_SET_ORDER);
137     if($cnt) {
138                 foreach($matches as $mtch) {
139                         $unescaped = xmlify(file_tag_decode($mtch[1]));
140                         $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
141                 }
142         }
143
144         return replace_macros(get_markup_template('fileas_widget.tpl'),array(
145                 '$title' => t('Saved Folders'),
146                 '$desc' => '',
147                 '$sel_all' => (($selected == '') ? 'selected' : ''),
148                 '$all' => t('Everything'),
149                 '$terms' => $terms,
150                 '$base' => $baseurl,
151
152         ));
153 }
154
155 function categories_widget($baseurl,$selected = '') {
156
157         $a = get_app();
158
159         if(! feature_enabled($a->profile['profile_uid'],'categories'))
160                 return '';
161
162         $saved = get_pconfig($a->profile['profile_uid'],'system','filetags');
163         if(! strlen($saved))
164                 return;
165
166         $matches = false;
167         $terms = array();
168         $cnt = preg_match_all('/<(.*?)>/',$saved,$matches,PREG_SET_ORDER);
169         if($cnt) {
170                 foreach($matches as $mtch) {
171                         $unescaped = xmlify(file_tag_decode($mtch[1]));
172                         $terms[] = array('name' => $unescaped,'selected' => (($selected == $unescaped) ? 'selected' : ''));
173                 }
174         }
175
176         return replace_macros(get_markup_template('categories_widget.tpl'),array(
177                 '$title' => t('Categories'),
178                 '$desc' => '',
179                 '$sel_all' => (($selected == '') ? 'selected' : ''),
180                 '$all' => t('Everything'),
181                 '$terms' => $terms,
182                 '$base' => $baseurl,
183
184         ));
185 }
186
187 function common_friends_visitor_widget($profile_uid) {
188
189         $a = get_app();
190
191         if(local_user() == $profile_uid)
192                 return;
193
194         $cid = $zcid = 0;
195
196         if(is_array($_SESSION['remote'])) {
197                 foreach($_SESSION['remote'] as $visitor) {
198                         if($visitor['uid'] == $profile_uid) {
199                                 $cid = $visitor['cid'];
200                                 break;
201                         }
202                 }
203         }
204
205         if(! $cid) {
206                 if(get_my_url()) {
207                         $r = q("select id from contact where nurl = '%s' and uid = %d limit 1",
208                                 dbesc(normalise_link(get_my_url())),
209                                 intval($profile_uid)
210                         );
211                         if (dbm::is_result($r))
212                                 $cid = $r[0]['id'];
213                         else {
214                                 $r = q("select id from gcontact where nurl = '%s' limit 1",
215                                         dbesc(normalise_link(get_my_url()))
216                                 );
217                                 if (dbm::is_result($r))
218                                         $zcid = $r[0]['id'];
219                         }
220                 }
221         }
222
223         if($cid == 0 && $zcid == 0)
224                 return;
225
226         require_once('include/socgraph.php');
227
228         if($cid)
229                 $t = count_common_friends($profile_uid,$cid);
230         else
231                 $t = count_common_friends_zcid($profile_uid,$zcid);
232         if(! $t)
233                 return;
234
235         if($cid)
236                 $r = common_friends($profile_uid,$cid,0,5,true);
237         else
238                 $r = common_friends_zcid($profile_uid,$zcid,0,5,true);
239
240         return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
241                 '$desc' =>  sprintf( tt("%d contact in common", "%d contacts in common", $t), $t),
242                 '$base' => App::get_baseurl(),
243                 '$uid' => $profile_uid,
244                 '$cid' => (($cid) ? $cid : '0'),
245                 '$linkmore' => (($t > 5) ? 'true' : ''),
246                 '$more' => t('show more'),
247                 '$items' => $r
248         ));
249
250 };