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