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