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