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