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