]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
old boot.php functions replaced in various places
[friendica.git] / view / theme / vier / theme.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  * Name: Vier
21  * Version: 1.2
22  * Author: Fabio <http://kirgroup.com/profile/fabrixxm>
23  * Author: Ike <http://pirati.ca/profile/heluecht>
24  * Author: Beanow <https://fc.oscp.info/profile/beanow>
25  * Maintainer: Ike <http://pirati.ca/profile/heluecht>
26  * Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
27  */
28
29 use Friendica\App;
30 use Friendica\Content\ForumManager;
31 use Friendica\Core\Addon;
32 use Friendica\Core\Renderer;
33 use Friendica\Core\Search;
34 use Friendica\Core\Session;
35 use Friendica\Database\DBA;
36 use Friendica\DI;
37 use Friendica\Model\Contact;
38 use Friendica\Util\Strings;
39
40 /*
41  * This script can be included even when the app is in maintenance mode which requires us to avoid any config call
42  */
43
44 function vier_init(App $a)
45 {
46         $a->setThemeInfoValue('events_in_profile', false);
47
48         Renderer::setActiveTemplateEngine('smarty3');
49
50         $args = DI::args();
51
52         if (
53                 DI::mode()->has(App\Mode::MAINTENANCEDISABLED)
54                 && (
55                         $args->get(0) === 'profile' && $args->get(1) === ($a->getLoggedInUserNickname() ?? '')
56                         || $args->get(0) === 'network' && Session::getLocalUser()
57                 )
58         ) {
59                 vier_community_info();
60
61                 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
62         }
63
64         if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
65                 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
66                 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
67         }
68         /// @todo deactivated since it doesn't work with desktop browsers at the moment
69         //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
70
71         DI::page()['htmlhead'] .= <<< EOT
72 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
73 <script type="text/javascript">
74 function showThread(id) {
75         $("#collapsed-comments-" + id).show()
76         $("#collapsed-comments-" + id + " .collapsed-comments").show()
77 }
78 function hideThread(id) {
79         $("#collapsed-comments-" + id).hide()
80         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
81 }
82
83 function cmtBbOpen(id) {
84         $("#comment-edit-bb-" + id).show();
85 }
86 function cmtBbClose(id) {
87         $("#comment-edit-bb-" + id).hide();
88 }
89 </script>
90 EOT;
91
92         if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
93                 DI::page()['htmlhead'] .= <<< EOT
94 <script>
95         $(document).ready(function() {
96                 $(".mobile-aside-toggle a").click(function(e){
97                         e.preventDefault();
98                         $("aside").toggleClass("show");
99                 });
100                 $(".tabs").click(function(e){
101                         $(this).toggleClass("show");
102                 });
103         });
104 </script>
105 EOT;
106         }
107
108         // Hide the left menu bar
109         /// @TODO maybe move this static array out where it should belong?
110         if (empty(DI::page()['aside']) && in_array($args->get(0), ["community", "events", "help", "delegation", "notifications",
111                         "probe", "webfinger", "login", "invite", "credits"])) {
112                 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
113         }
114 }
115
116 function get_vier_config($key, $default = false, $admin = false)
117 {
118         if (Session::getLocalUser() && !$admin) {
119                 $result = DI::pConfig()->get(Session::getLocalUser(), "vier", $key);
120                 if (!is_null($result)) {
121                         return $result;
122                 }
123         }
124
125         $result = DI::config()->get("vier", $key);
126         if (!is_null($result)) {
127                 return $result;
128         }
129
130         return $default;
131 }
132
133 function vier_community_info()
134 {
135         $show_pages      = get_vier_config("show_pages", 1);
136         $show_profiles   = get_vier_config("show_profiles", 1);
137         $show_helpers    = get_vier_config("show_helpers", 1);
138         $show_services   = get_vier_config("show_services", 1);
139         $show_friends    = get_vier_config("show_friends", 1);
140         $show_lastusers  = get_vier_config("show_lastusers", 1);
141
142         // get_baseurl
143         $url = DI::baseUrl();
144         $aside['$url'] = $url;
145
146         // comunity_profiles
147         if ($show_profiles) {
148                 $contacts = Contact\Relation::getSuggestions(Session::getLocalUser(), 0, 9);
149
150                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
151                 if (DBA::isResult($contacts)) {
152                         $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
153                         $aside['$comunity_profiles_items'] = [];
154
155                         foreach ($contacts as $contact) {
156                                 $entry = Renderer::replaceMacros($tpl, [
157                                         '$id' => $contact['id'],
158                                         '$profile_link' => 'follow/?url='.urlencode($contact['url']),
159                                         '$photo' => Contact::getMicro($contact),
160                                         '$alt_text' => $contact['name'],
161                                 ]);
162                                 $aside['$comunity_profiles_items'][] = $entry;
163                         }
164                 }
165         }
166
167         // last 9 users
168         if ($show_lastusers) {
169                 $condition = ['blocked' => false];
170                 if (!DI::config()->get('system', 'publish_all')) {
171                         $condition['publish'] = true;
172                 }
173
174                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
175
176                 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
177
178                 if (DBA::isResult($profiles)) {
179                         $aside['$lastusers_title'] = DI::l10n()->t('Last users');
180                         $aside['$lastusers_items'] = [];
181
182                         foreach ($profiles as $profile) {
183                                 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
184                                 $entry = Renderer::replaceMacros($tpl, [
185                                         '$id' => $profile['id'],
186                                         '$profile_link' => $profile_link,
187                                         '$photo' => DI::baseUrl()->remove($profile['thumb']),
188                                         '$alt_text' => $profile['name']]);
189                                 $aside['$lastusers_items'][] = $entry;
190                         }
191                 }
192         }
193
194         //right_aside FIND FRIENDS
195         if ($show_friends && Session::getLocalUser()) {
196                 $nv = [];
197                 $nv['findpeople'] = DI::l10n()->t('Find People');
198                 $nv['desc'] = DI::l10n()->t('Enter name or interest');
199                 $nv['label'] = DI::l10n()->t('Connect/Follow');
200                 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
201                 $nv['findthem'] = DI::l10n()->t('Find');
202                 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
203                 $nv['similar'] = DI::l10n()->t('Similar Interests');
204                 $nv['random'] = DI::l10n()->t('Random Profile');
205                 $nv['inv'] = DI::l10n()->t('Invite Friends');
206                 $nv['directory'] = DI::l10n()->t('Global Directory');
207                 $nv['global_dir'] = Search::getGlobalDirectory();
208                 $nv['local_directory'] = DI::l10n()->t('Local Directory');
209
210                 $aside['$nv'] = $nv;
211         }
212
213         //Community_Pages at right_aside
214         if ($show_pages && Session::getLocalUser()) {
215                 $aside['$page'] = ForumManager::widget('network/forum', Session::getLocalUser());;
216         }
217         // END Community Page
218
219         // helpers
220         if ($show_helpers) {
221                 $r = [];
222
223                 $helperlist = DI::config()->get("vier", "helperlist");
224
225                 $helpers = explode(",", $helperlist);
226
227                 if ($helpers) {
228                         foreach ($helpers as $helper) {
229                                 $urls[] = Strings::normaliseLink(trim($helper));
230                         }
231                         $r = DBA::selectToArray('contact', ['url', 'name'], ['uid' => 0, 'nurl' => $urls]);
232                 }
233
234                 foreach ($r as $index => $helper) {
235                         $r[$index]["url"] = Contact::magicLink($helper["url"]);
236                 }
237
238                 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
239
240                 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
241
242                 if ($r) {
243                         $helpers = [];
244                         $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
245
246                         $aside['$helpers_items'] = [];
247
248                         foreach ($r as $rr) {
249                                 $entry = Renderer::replaceMacros($tpl, [
250                                         '$url' => $rr['url'],
251                                         '$title' => $rr['name'],
252                                 ]);
253                                 $aside['$helpers_items'][] = $entry;
254                         }
255
256                         $aside['$helpers'] = $helpers;
257                 }
258         }
259         // end helpers
260
261         // connectable services
262         if ($show_services) {
263                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
264                 $r = [];
265
266                 if (Addon::isEnabled("buffer")) {
267                         $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
268                 }
269
270                 if (Addon::isEnabled("blogger")) {
271                         $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
272                 }
273
274                 if (Addon::isEnabled("dwpost")) {
275                         $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
276                 }
277
278                 if (Addon::isEnabled("ifttt")) {
279                         $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
280                 }
281
282                 if (Addon::isEnabled("statusnet")) {
283                         $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
284                 }
285
286                 /// @TODO old-lost code (and below)?
287                 //if (Addon::isEnabled("ijpost")) {
288                 //      $r[] = array("photo" => "images/", "name" => "");
289                 //}
290
291                 if (Addon::isEnabled("libertree")) {
292                         $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
293                 }
294
295                 //if (Addon::isEnabled("ljpost")) {
296                 //      $r[] = array("photo" => "images/", "name" => "");
297                 //}
298
299                 if (Addon::isEnabled("pumpio")) {
300                         $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
301                 }
302
303                 if (Addon::isEnabled("tumblr")) {
304                         $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
305                 }
306
307                 if (Addon::isEnabled("twitter")) {
308                         $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
309                 }
310
311                 if (Addon::isEnabled("wppost")) {
312                         $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
313                 }
314
315                 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled")) {
316                         $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
317                 }
318
319                 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
320
321                 if (DBA::isResult($r)) {
322                         $con_services = [];
323                         $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
324                         $aside['$con_services'] = $con_services;
325
326                         foreach ($r as $rr) {
327                                 $entry = Renderer::replaceMacros($tpl, [
328                                         '$url' => $url,
329                                         '$photo' => $rr['photo'],
330                                         '$alt_text' => $rr['name'],
331                                 ]);
332                                 $aside['$connector_items'][] = $entry;
333                         }
334                 }
335         }
336         //end connectable services
337
338         //print right_aside
339         $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
340         DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
341 }
342
343 /**
344  * @param int|null $uid
345  * @return null
346  * @see \Friendica\Core\Theme::getBackgroundColor()
347  * @TODO Implement this function
348  */
349 function vier_get_background_color(int $uid = null)
350 {
351         return null;
352 }
353
354 /**
355  * @param int|null $uid
356  * @return null
357  * @see \Friendica\Core\Theme::getThemeColor()
358  * @TODO Implement this function
359  */
360 function vier_get_theme_color(int $uid = null)
361 {
362         return null;
363 }