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