]> git.mxchange.org Git - friendica.git/blob - include/contact_widgets.php
Fix unused code in include
[friendica.git] / include / contact_widgets.php
1 <?php
2
3 /**
4  * @file include/contact_widgets.php
5  */
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
13 require_once 'include/contact_selectors.php';
14
15 function follow_widget($value = "")
16 {
17         return replace_macros(get_markup_template('follow.tpl'), array(
18                 '$connect' => t('Add New Contact'),
19                 '$desc' => t('Enter address or web location'),
20                 '$hint' => t('Example: bob@example.com, http://example.com/barbara'),
21                 '$value' => $value,
22                 '$follow' => t('Connect')
23         ));
24 }
25
26 function findpeople_widget()
27 {
28         $a = get_app();
29         $global_dir = Config::get('system', 'directory');
30
31         if (Config::get('system', 'invitation_only')) {
32                 $x = PConfig::get(local_user(), 'system', 'invites_remaining');
33                 if ($x || is_site_admin()) {
34                         $a->page['aside'] .= '<div class="side-link" id="side-invite-remain">'
35                                 . tt('%d invitation available', '%d invitations available', $x)
36                                 . '</div>' . $inv;
37                 }
38         }
39
40         return replace_macros(get_markup_template('peoplefind.tpl'), array(
41                 '$findpeople' => t('Find People'),
42                 '$desc' => t('Enter name or interest'),
43                 '$label' => t('Connect/Follow'),
44                 '$hint' => t('Examples: Robert Morgenstein, Fishing'),
45                 '$findthem' => t('Find'),
46                 '$suggest' => t('Friend Suggestions'),
47                 '$similar' => t('Similar Interests'),
48                 '$random' => t('Random Profile'),
49                 '$inv' => t('Invite Friends'),
50                 '$directory' => t('View Global Directory'),
51                 '$global_dir' => $global_dir
52         ));
53 }
54
55 function unavailable_networks()
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         if (!local_user()) {
105                 return '';
106         }
107
108         if (!Feature::isEnabled(local_user(), 'networks')) {
109                 return '';
110         }
111
112         $extra_sql = unavailable_networks();
113
114         $r = dba::p("SELECT DISTINCT(`network`) FROM `contact` WHERE `uid` = ? AND `network` != '' $extra_sql ORDER BY `network`",
115                 local_user()
116         );
117
118         $nets = array();
119         while ($rr = dba::fetch($r)) {
120                 /// @TODO If 'network' is not there, this triggers an E_NOTICE
121                 if ($rr['network']) {
122                         $nets[] = array('ref' => $rr['network'], 'name' => network_to_name($rr['network']), 'selected' => (($selected == $rr['network']) ? 'selected' : '' ));
123                 }
124         }
125         dba::close($r);
126
127         if (count($nets) < 2) {
128                 return '';
129         }
130
131         return replace_macros(get_markup_template('nets.tpl'), array(
132                 '$title' => t('Networks'),
133                 '$desc' => '',
134                 '$sel_all' => (($selected == '') ? 'selected' : ''),
135                 '$all' => t('All Networks'),
136                 '$nets' => $nets,
137                 '$base' => $baseurl,
138         ));
139 }
140
141 function fileas_widget($baseurl, $selected = '')
142 {
143         if (!local_user()) {
144                 return '';
145         }
146
147         if (!Feature::isEnabled(local_user(), 'filing')) {
148                 return '';
149         }
150
151         $saved = PConfig::get(local_user(), 'system', 'filetags');
152         if (!strlen($saved)) {
153                 return;
154         }
155
156         $matches = false;
157         $terms = array();
158         $cnt = preg_match_all('/\[(.*?)\]/', $saved, $matches, PREG_SET_ORDER);
159         if ($cnt) {
160                 foreach ($matches as $mtch) {
161                         $unescaped = xmlify(file_tag_decode($mtch[1]));
162                         $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
163                 }
164         }
165
166         return replace_macros(get_markup_template('fileas_widget.tpl'), array(
167                 '$title' => t('Saved Folders'),
168                 '$desc' => '',
169                 '$sel_all' => (($selected == '') ? 'selected' : ''),
170                 '$all' => t('Everything'),
171                 '$terms' => $terms,
172                 '$base' => $baseurl,
173         ));
174 }
175
176 function categories_widget($baseurl, $selected = '')
177 {
178         $a = get_app();
179
180         if (!Feature::isEnabled($a->profile['profile_uid'], 'categories')) {
181                 return '';
182         }
183
184         $saved = PConfig::get($a->profile['profile_uid'], 'system', 'filetags');
185         if (!strlen($saved)) {
186                 return;
187         }
188
189         $matches = false;
190         $terms = array();
191         $cnt = preg_match_all('/<(.*?)>/', $saved, $matches, PREG_SET_ORDER);
192
193         if ($cnt) {
194                 foreach ($matches as $mtch) {
195                         $unescaped = xmlify(file_tag_decode($mtch[1]));
196                         $terms[] = array('name' => $unescaped, 'selected' => (($selected == $unescaped) ? 'selected' : ''));
197                 }
198         }
199
200         return replace_macros(get_markup_template('categories_widget.tpl'), array(
201                 '$title' => t('Categories'),
202                 '$desc' => '',
203                 '$sel_all' => (($selected == '') ? 'selected' : ''),
204                 '$all' => t('Everything'),
205                 '$terms' => $terms,
206                 '$base' => $baseurl,
207         ));
208 }
209
210 function common_friends_visitor_widget($profile_uid)
211 {
212         if (local_user() == $profile_uid) {
213                 return;
214         }
215
216         $cid = $zcid = 0;
217
218         if (is_array($_SESSION['remote'])) {
219                 foreach ($_SESSION['remote'] as $visitor) {
220                         if ($visitor['uid'] == $profile_uid) {
221                                 $cid = $visitor['cid'];
222                                 break;
223                         }
224                 }
225         }
226
227         if (!$cid) {
228                 if (get_my_url()) {
229                         $r = dba::select('contact', array('id'),
230                                         array('nurl' => normalise_link(get_my_url()), 'uid' => $profile_uid), array('limit' => 1));
231                         if (DBM::is_result($r)) {
232                                 $cid = $r['id'];
233                         } else {
234                                 $r = dba::select('gcontact', array('id'), array('nurl' => normalise_link(get_my_url())), array('limit' => 1));
235                                 if (DBM::is_result($r)) {
236                                         $zcid = $r['id'];
237                                 }
238                         }
239                 }
240         }
241
242         if ($cid == 0 && $zcid == 0) {
243                 return;
244         }
245
246         if ($cid) {
247                 $t = GContact::countCommonFriends($profile_uid, $cid);
248         } else {
249                 $t = GContact::countCommonFriendsZcid($profile_uid, $zcid);
250         }
251
252         if (!$t) {
253                 return;
254         }
255
256         if ($cid) {
257                 $r = GContact::commonFriends($profile_uid, $cid, 0, 5, true);
258         } else {
259                 $r = GContact::commonFriendsZcid($profile_uid, $zcid, 0, 5, true);
260         }
261
262         return replace_macros(get_markup_template('remote_friends_common.tpl'), array(
263                 '$desc' => tt("%d contact in common", "%d contacts in common", $t),
264                 '$base' => System::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 }