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