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