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