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