]> git.mxchange.org Git - friendica.git/blob - include/contact_widgets.php
use
[friendica.git] / include / contact_widgets.php
1 <?php
2 /**
3  * @file include/contact_widgets.php
4  */
5 use Friendica\Content\ContactSelector;
6 use Friendica\Content\Feature;
7 use Friendica\Core\System;
8 use Friendica\Core\Config;
9 use Friendica\Core\PConfig;
10 use Friendica\Database\DBM;
11 use Friendica\Model\GContact;
12 use Friendica\Model\Profile;
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 function findpeople_widget()
26 {
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                                 . tt('%d invitation available', '%d invitations available', $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 function unavailable_networks()
55 {
56         $networks = array();
57
58         if (!plugin_enabled("appnet")) {
59                 $networks[] = NETWORK_APPNET;
60         }
61
62         if (!plugin_enabled("fbpost") && !plugin_enabled("facebook")) {
63                 $networks[] = NETWORK_FACEBOOK;
64         }
65
66         if (!plugin_enabled("statusnet")) {
67                 $networks[] = NETWORK_STATUSNET;
68         }
69
70         if (!plugin_enabled("pumpio")) {
71                 $networks[] = NETWORK_PUMPIO;
72         }
73
74         if (!plugin_enabled("twitter")) {
75                 $networks[] = NETWORK_TWITTER;
76         }
77
78         if (Config::get("system", "ostatus_disabled")) {
79                 $networks[] = NETWORK_OSTATUS;
80         }
81
82         if (!Config::get("system", "diaspora_enabled")) {
83                 $networks[] = NETWORK_DIASPORA;
84         }
85
86         if (!plugin_enabled("pnut")) {
87                 $networks[] = NETWORK_PNUT;
88         }
89
90         if (!sizeof($networks)) {
91                 return "";
92         }
93
94         $network_filter = implode("','", $networks);
95
96         $network_filter = "AND `network` NOT IN ('$network_filter')";
97
98         return $network_filter;
99 }
100
101 function networks_widget($baseurl, $selected = '')
102 {
103         if (!local_user()) {
104                 return '';
105         }
106
107         if (!Feature::isEnabled(local_user(), 'networks')) {
108                 return '';
109         }
110
111         $extra_sql = unavailable_networks();
112
113         $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
114                 local_user()
115         );
116
117         $nets = array();
118         while ($rr = dba::fetch($r)) {
119                 /// @TODO If 'network' is not there, this triggers an E_NOTICE
120                 if ($rr['network']) {
121                         $nets[] = array('ref' => $rr['network'], 'name' => ContactSelector::networkToName($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
122                 }
123         }
124         dba::close($r);
125
126         if (count($nets) < 2) {
127                 return '';
128         }
129
130         return replace_macros(get_markup_template('nets.tpl'), array(
131                 '$title' => t('Networks'),
132                 '$desc' => '',
133                 '$sel_all' => (($selected == '') ? 'selected' : ''),
134                 '$all' => t('All Networks'),
135                 '$nets' => $nets,
136                 '$base' => $baseurl,
137         ));
138 }
139
140 function fileas_widget($baseurl, $selected = '')
141 {
142         if (!local_user()) {
143                 return '';
144         }
145
146         if (!Feature::isEnabled(local_user(), 'filing')) {
147                 return '';
148         }
149
150         $saved = PConfig::get(local_user(), 'system', 'filetags');
151         if (!strlen($saved)) {
152                 return;
153         }
154
155         $matches = false;
156         $terms = array();
157         $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
158         if ($cnt) {
159                 foreach ($matches as $mtch) {
160                         $unescaped = xmlify(file_tag_decode($mtch[1]));
161                         $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
162                 }
163         }
164
165         return replace_macros(get_markup_template('fileas_widget.tpl'), array(
166                 '$title' => t('Saved Folders'),
167                 '$desc' => '',
168                 '$sel_all' => (($selected == '') ? 'selected' : ''),
169                 '$all' => t('Everything'),
170                 '$terms' => $terms,
171                 '$base' => $baseurl,
172         ));
173 }
174
175 function categories_widget($baseurl, $selected = '')
176 {
177         $a = get_app();
178
179         if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
180                 return '';
181         }
182
183         $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
184         if (!strlen($saved)) {
185                 return;
186         }
187
188         $matches = false;
189         $terms = array();
190         $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
191
192         if ($cnt) {
193                 foreach ($matches as $mtch) {
194                         $unescaped = xmlify(file_tag_decode($mtch[1]));
195                         $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
196                 }
197         }
198
199         return replace_macros(get_markup_template('categories_widget.tpl'), array(
200                 '$title' => t('Categories'),
201                 '$desc' => '',
202                 '$sel_all' => (($selected == '') ? 'selected' : ''),
203                 '$all' => t('Everything'),
204                 '$terms' => $terms,
205                 '$base' => $baseurl,
206         ));
207 }
208
209 function common_friends_visitor_widget($profile_uid)
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 (Profile::getMyURL()) {
228                         $contact = dba::selectFirst('contact', ['id'],
229                                         ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]);
230                         if (DBM::is_result($contact)) {
231                                 $cid = $contact['id'];
232                         } else {
233                                 $gcontact = dba::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]);
234                                 if (DBM::is_result($gcontact)) {
235                                         $zcid = $gcontact['id'];
236                                 }
237                         }
238                 }
239         }
240
241         if ($cid == 0 && $zcid == 0) {
242                 return;
243         }
244
245         if ($cid) {
246                 $t = GContact::countCommonFriends($profile_uid, $cid);
247         } else {
248                 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
249         }
250
251         if (!$t) {
252                 return;
253         }
254
255         if ($cid) {
256                 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
257         } else {
258                 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
259         }
260
261         return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
262                 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
263                 '$base' => System::baseUrl(),
264                 '$uid' => $profile_uid,
265                 '$cid' => (($cid) ? $cid : '0'),
266                 '$linkmore' => (($t > 5) ? 'true' : ''),
267                 '$more' => t('show more'),
268                 '$items' => $r)
269         );
270 }