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