]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
Remove deprecated App::removeBaseURL - process methods to DI::baseUrl()->remove()
[friendica.git] / view / theme / vier / theme.php
1 <?php
2 /**
3  * Name: Vier
4  * Version: 1.2
5  * Author: Fabio <http://kirgroup.com/profile/fabrixxm>
6  * Author: Ike <http://pirati.ca/profile/heluecht>
7  * Author: Beanow <https://fc.oscp.info/profile/beanow>
8  * Maintainer: Ike <http://pirati.ca/profile/heluecht>
9  * Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
10  */
11
12 use Friendica\App;
13 use Friendica\Content\ForumManager;
14 use Friendica\Core\Addon;
15 use Friendica\Core\Config;
16 use Friendica\Core\L10n;
17 use Friendica\Core\PConfig;
18 use Friendica\Core\Renderer;
19 use Friendica\Core\System;
20 use Friendica\Database\DBA;
21 use Friendica\DI;
22 use Friendica\Model\Contact;
23 use Friendica\Model\GContact;
24 use Friendica\Util\Proxy as ProxyUtils;
25 use Friendica\Util\Strings;
26
27 function vier_init(App $a)
28 {
29         $a->theme_events_in_profile = false;
30
31         Renderer::setActiveTemplateEngine('smarty3');
32
33         if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . $a->user['nickname']) || $a->argv[0] === 'network' && local_user()) {
34                 vier_community_info();
35
36                 $a->page['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
37         }
38
39         if ($a->is_mobile || $a->is_tablet) {
40                 $a->page['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
41                 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
42         }
43         /// @todo deactivated since it doesn't work with desktop browsers at the moment
44         //$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
45
46         $a->page['htmlhead'] .= <<< EOT
47 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
48 <script type="text/javascript">
49 function showThread(id) {
50         $("#collapsed-comments-" + id).show()
51         $("#collapsed-comments-" + id + " .collapsed-comments").show()
52 }
53 function hideThread(id) {
54         $("#collapsed-comments-" + id).hide()
55         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
56 }
57
58 function cmtBbOpen(id) {
59         $("#comment-edit-bb-" + id).show();
60 }
61 function cmtBbClose(id) {
62         $("#comment-edit-bb-" + id).hide();
63 }
64 </script>
65 EOT;
66
67         if ($a->is_mobile || $a->is_tablet) {
68                 $a->page['htmlhead'] .= <<< EOT
69 <script>
70         $(document).ready(function() {
71                 $(".mobile-aside-toggle a").click(function(e){
72                         e.preventDefault();
73                         $("aside").toggleClass("show");
74                 });
75                 $(".tabs").click(function(e){
76                         $(this).toggleClass("show");
77                 });
78         });
79 </script>
80 EOT;
81         }
82
83         // Hide the left menu bar
84         /// @TODO maybe move this static array out where it should belong?
85         if (empty($a->page['aside']) && in_array($a->argv[0], ["community", "events", "help", "delegation", "notifications",
86                         "probe", "webfinger", "login", "invite", "credits"])) {
87                 $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
88         }
89 }
90
91 function get_vier_config($key, $default = false, $admin = false)
92 {
93         if (local_user() && !$admin) {
94                 $result = PConfig::get(local_user(), "vier", $key);
95                 if (!is_null($result)) {
96                         return $result;
97                 }
98         }
99
100         $result = Config::get("vier", $key);
101         if (!is_null($result)) {
102                 return $result;
103         }
104
105         return $default;
106 }
107
108 function vier_community_info()
109 {
110         $a = \get_app();
111
112         $show_pages      = get_vier_config("show_pages", 1);
113         $show_profiles   = get_vier_config("show_profiles", 1);
114         $show_helpers    = get_vier_config("show_helpers", 1);
115         $show_services   = get_vier_config("show_services", 1);
116         $show_friends    = get_vier_config("show_friends", 1);
117         $show_lastusers  = get_vier_config("show_lastusers", 1);
118
119         // get_baseurl
120         $url = System::baseUrl();
121         $aside['$url'] = $url;
122
123         // comunity_profiles
124         if ($show_profiles) {
125                 $r = GContact::suggestionQuery(local_user(), 0, 9);
126
127                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
128                 if (DBA::isResult($r)) {
129                         $aside['$comunity_profiles_title'] = L10n::t('Community Profiles');
130                         $aside['$comunity_profiles_items'] = [];
131
132                         foreach ($r as $rr) {
133                                 $entry = Renderer::replaceMacros($tpl, [
134                                         '$id' => $rr['id'],
135                                         '$profile_link' => 'follow/?url='.urlencode($rr['url']),
136                                         '$photo' => ProxyUtils::proxifyUrl($rr['photo'], false, ProxyUtils::SIZE_MICRO),
137                                         '$alt_text' => $rr['name'],
138                                 ]);
139                                 $aside['$comunity_profiles_items'][] = $entry;
140                         }
141                 }
142         }
143
144         // last 9 users
145         if ($show_lastusers) {
146                 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ");
147                 $order = " ORDER BY `register_date` DESC ";
148
149                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
150
151                 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
152                                 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
153                                 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
154                         0,
155                         9
156                 );
157
158                 if (DBA::isResult($r)) {
159                         $aside['$lastusers_title'] = L10n::t('Last users');
160                         $aside['$lastusers_items'] = [];
161
162                         foreach ($r as $rr) {
163                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
164                                 $entry = Renderer::replaceMacros($tpl, [
165                                         '$id' => $rr['id'],
166                                         '$profile_link' => $profile_link,
167                                         '$photo' => DI::baseUrl()->remove($rr['thumb']),
168                                         '$alt_text' => $rr['name']]);
169                                 $aside['$lastusers_items'][] = $entry;
170                         }
171                 }
172         }
173
174         //right_aside FIND FRIENDS
175         if ($show_friends && local_user()) {
176                 $nv = [];
177                 $nv['findpeople'] = L10n::t('Find People');
178                 $nv['desc'] = L10n::t('Enter name or interest');
179                 $nv['label'] = L10n::t('Connect/Follow');
180                 $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
181                 $nv['findthem'] = L10n::t('Find');
182                 $nv['suggest'] = L10n::t('Friend Suggestions');
183                 $nv['similar'] = L10n::t('Similar Interests');
184                 $nv['random'] = L10n::t('Random Profile');
185                 $nv['inv'] = L10n::t('Invite Friends');
186                 $nv['directory'] = L10n::t('Global Directory');
187                 $nv['global_dir'] = get_server();
188                 $nv['local_directory'] = L10n::t('Local Directory');
189
190                 $aside['$nv'] = $nv;
191         }
192
193         //Community_Pages at right_aside
194         if ($show_pages && local_user()) {
195                 $cid = $_GET['cid'] ?? null;
196
197                 //sort by last updated item
198                 $lastitem = true;
199
200                 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
201                 $total = count($contacts);
202                 $visible_forums = 10;
203
204                 if (count($contacts)) {
205                         $id = 0;
206
207                         foreach ($contacts as $contact) {
208                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
209
210                                 $entry = [
211                                         'url'          => 'network?cid=' . $contact['id'],
212                                         'external_url' => Contact::magicLink($contact['url']),
213                                         'name'         => $contact['name'],
214                                         'cid'          => $contact['id'],
215                                         'selected'     => $selected,
216                                         'micro'        => System::removedBaseUrl(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
217                                         'id'           => ++$id,
218                                 ];
219                                 $entries[] = $entry;
220                         }
221
222
223                         $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
224
225                         $page = Renderer::replaceMacros(
226                                 $tpl,
227                                 [
228                                         '$title'          => L10n::t('Forums'),
229                                         '$forums'         => $entries,
230                                         '$link_desc'      => L10n::t('External link to forum'),
231                                         '$total'          => $total,
232                                         '$visible_forums' => $visible_forums,
233                                         '$showmore'       => L10n::t('show more')]
234                         );
235
236                         $aside['$page'] = $page;
237                 }
238         }
239         // END Community Page
240
241         // helpers
242         if ($show_helpers) {
243                 $r = [];
244
245                 $helperlist = Config::get("vier", "helperlist");
246
247                 $helpers = explode(",", $helperlist);
248
249                 if ($helpers) {
250                         $query = "";
251                         foreach ($helpers as $index => $helper) {
252                                 if ($query != "") {
253                                         $query .= ",";
254                                 }
255
256                                 $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
257                         }
258
259                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
260                 }
261
262                 foreach ($r as $index => $helper) {
263                         $r[$index]["url"] = Contact::magicLink($helper["url"]);
264                 }
265
266                 $r[] = ["url" => "help/Quick-Start-guide", "name" => L10n::t("Quick Start")];
267
268                 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
269
270                 if ($r) {
271                         $helpers = [];
272                         $helpers['title'] = ["", L10n::t('Help'), "", ""];
273
274                         $aside['$helpers_items'] = [];
275
276                         foreach ($r as $rr) {
277                                 $entry = Renderer::replaceMacros($tpl, [
278                                         '$url' => $rr['url'],
279                                         '$title' => $rr['name'],
280                                 ]);
281                                 $aside['$helpers_items'][] = $entry;
282                         }
283
284                         $aside['$helpers'] = $helpers;
285                 }
286         }
287         // end helpers
288
289         // connectable services
290         if ($show_services) {
291                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
292                 $r = [];
293
294                 if (Addon::isEnabled("buffer")) {
295                         $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
296                 }
297
298                 if (Addon::isEnabled("blogger")) {
299                         $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
300                 }
301
302                 if (Addon::isEnabled("dwpost")) {
303                         $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
304                 }
305
306                 if (Addon::isEnabled("ifttt")) {
307                         $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
308                 }
309
310                 if (Addon::isEnabled("statusnet")) {
311                         $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
312                 }
313
314                 /// @TODO old-lost code (and below)?
315                 //if (Addon::isEnabled("ijpost")) {
316                 //      $r[] = array("photo" => "images/", "name" => "");
317                 //}
318
319                 if (Addon::isEnabled("libertree")) {
320                         $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
321                 }
322
323                 //if (Addon::isEnabled("ljpost")) {
324                 //      $r[] = array("photo" => "images/", "name" => "");
325                 //}
326
327                 if (Addon::isEnabled("pumpio")) {
328                         $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
329                 }
330
331                 if (Addon::isEnabled("tumblr")) {
332                         $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
333                 }
334
335                 if (Addon::isEnabled("twitter")) {
336                         $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
337                 }
338
339                 if (Addon::isEnabled("wppost")) {
340                         $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
341                 }
342
343                 if (function_exists("imap_open") && !Config::get("system", "imap_disabled") && !Config::get("system", "dfrn_only")) {
344                         $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
345                 }
346
347                 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
348
349                 if (DBA::isResult($r)) {
350                         $con_services = [];
351                         $con_services['title'] = ["", L10n::t('Connect Services'), "", ""];
352                         $aside['$con_services'] = $con_services;
353
354                         foreach ($r as $rr) {
355                                 $entry = Renderer::replaceMacros($tpl, [
356                                         '$url' => $url,
357                                         '$photo' => $rr['photo'],
358                                         '$alt_text' => $rr['name'],
359                                 ]);
360                                 $aside['$connector_items'][] = $entry;
361                         }
362                 }
363         }
364         //end connectable services
365
366         //print right_aside
367         $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
368         $a->page['right_aside'] = Renderer::replaceMacros($tpl, $aside);
369 }