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