]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
cleanup namespace usages for L10n
[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\Renderer;
17 use Friendica\Core\Search;
18 use Friendica\Database\DBA;
19 use Friendica\DI;
20 use Friendica\Model\Contact;
21 use Friendica\Model\GContact;
22 use Friendica\Util\Proxy as ProxyUtils;
23 use Friendica\Util\Strings;
24
25 function vier_init(App $a)
26 {
27         $a->theme_events_in_profile = false;
28
29         Renderer::setActiveTemplateEngine('smarty3');
30
31         if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . $a->user['nickname']) || $a->argv[0] === 'network' && local_user()) {
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($a->argv[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 = 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         $a = DI::app();
109
110         $show_pages      = get_vier_config("show_pages", 1);
111         $show_profiles   = get_vier_config("show_profiles", 1);
112         $show_helpers    = get_vier_config("show_helpers", 1);
113         $show_services   = get_vier_config("show_services", 1);
114         $show_friends    = get_vier_config("show_friends", 1);
115         $show_lastusers  = get_vier_config("show_lastusers", 1);
116
117         // get_baseurl
118         $url = DI::baseUrl();
119         $aside['$url'] = $url;
120
121         // comunity_profiles
122         if ($show_profiles) {
123                 $r = GContact::suggestionQuery(local_user(), 0, 9);
124
125                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
126                 if (DBA::isResult($r)) {
127                         $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
128                         $aside['$comunity_profiles_items'] = [];
129
130                         foreach ($r as $rr) {
131                                 $entry = Renderer::replaceMacros($tpl, [
132                                         '$id' => $rr['id'],
133                                         '$profile_link' => 'follow/?url='.urlencode($rr['url']),
134                                         '$photo' => ProxyUtils::proxifyUrl($rr['photo'], false, ProxyUtils::SIZE_MICRO),
135                                         '$alt_text' => $rr['name'],
136                                 ]);
137                                 $aside['$comunity_profiles_items'][] = $entry;
138                         }
139                 }
140         }
141
142         // last 9 users
143         if ($show_lastusers) {
144                 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ");
145                 $order = " ORDER BY `register_date` DESC ";
146
147                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
148
149                 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
150                                 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
151                                 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
152                         0,
153                         9
154                 );
155
156                 if (DBA::isResult($r)) {
157                         $aside['$lastusers_title'] = DI::l10n()->t('Last users');
158                         $aside['$lastusers_items'] = [];
159
160                         foreach ($r as $rr) {
161                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
162                                 $entry = Renderer::replaceMacros($tpl, [
163                                         '$id' => $rr['id'],
164                                         '$profile_link' => $profile_link,
165                                         '$photo' => DI::baseUrl()->remove($rr['thumb']),
166                                         '$alt_text' => $rr['name']]);
167                                 $aside['$lastusers_items'][] = $entry;
168                         }
169                 }
170         }
171
172         //right_aside FIND FRIENDS
173         if ($show_friends && local_user()) {
174                 $nv = [];
175                 $nv['findpeople'] = DI::l10n()->t('Find People');
176                 $nv['desc'] = DI::l10n()->t('Enter name or interest');
177                 $nv['label'] = DI::l10n()->t('Connect/Follow');
178                 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
179                 $nv['findthem'] = DI::l10n()->t('Find');
180                 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
181                 $nv['similar'] = DI::l10n()->t('Similar Interests');
182                 $nv['random'] = DI::l10n()->t('Random Profile');
183                 $nv['inv'] = DI::l10n()->t('Invite Friends');
184                 $nv['directory'] = DI::l10n()->t('Global Directory');
185                 $nv['global_dir'] = Search::getGlobalDirectory();
186                 $nv['local_directory'] = DI::l10n()->t('Local Directory');
187
188                 $aside['$nv'] = $nv;
189         }
190
191         //Community_Pages at right_aside
192         if ($show_pages && local_user()) {
193                 $cid = $_GET['cid'] ?? null;
194
195                 //sort by last updated item
196                 $lastitem = true;
197
198                 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
199                 $total = count($contacts);
200                 $visible_forums = 10;
201
202                 if (count($contacts)) {
203                         $id = 0;
204
205                         foreach ($contacts as $contact) {
206                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
207
208                                 $entry = [
209                                         'url'          => 'network?cid=' . $contact['id'],
210                                         'external_url' => Contact::magicLink($contact['url']),
211                                         'name'         => $contact['name'],
212                                         'cid'          => $contact['id'],
213                                         'selected'     => $selected,
214                                         'micro'        => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
215                                         'id'           => ++$id,
216                                 ];
217                                 $entries[] = $entry;
218                         }
219
220
221                         $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
222
223                         $page = Renderer::replaceMacros(
224                                 $tpl,
225                                 [
226                                         '$title'          => DI::l10n()->t('Forums'),
227                                         '$forums'         => $entries,
228                                         '$link_desc'      => DI::l10n()->t('External link to forum'),
229                                         '$total'          => $total,
230                                         '$visible_forums' => $visible_forums,
231                                         '$showmore'       => DI::l10n()->t('show more')]
232                         );
233
234                         $aside['$page'] = $page;
235                 }
236         }
237         // END Community Page
238
239         // helpers
240         if ($show_helpers) {
241                 $r = [];
242
243                 $helperlist = Config::get("vier", "helperlist");
244
245                 $helpers = explode(",", $helperlist);
246
247                 if ($helpers) {
248                         $query = "";
249                         foreach ($helpers as $index => $helper) {
250                                 if ($query != "") {
251                                         $query .= ",";
252                                 }
253
254                                 $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
255                         }
256
257                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
258                 }
259
260                 foreach ($r as $index => $helper) {
261                         $r[$index]["url"] = Contact::magicLink($helper["url"]);
262                 }
263
264                 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
265
266                 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
267
268                 if ($r) {
269                         $helpers = [];
270                         $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
271
272                         $aside['$helpers_items'] = [];
273
274                         foreach ($r as $rr) {
275                                 $entry = Renderer::replaceMacros($tpl, [
276                                         '$url' => $rr['url'],
277                                         '$title' => $rr['name'],
278                                 ]);
279                                 $aside['$helpers_items'][] = $entry;
280                         }
281
282                         $aside['$helpers'] = $helpers;
283                 }
284         }
285         // end helpers
286
287         // connectable services
288         if ($show_services) {
289                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
290                 $r = [];
291
292                 if (Addon::isEnabled("buffer")) {
293                         $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
294                 }
295
296                 if (Addon::isEnabled("blogger")) {
297                         $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
298                 }
299
300                 if (Addon::isEnabled("dwpost")) {
301                         $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
302                 }
303
304                 if (Addon::isEnabled("ifttt")) {
305                         $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
306                 }
307
308                 if (Addon::isEnabled("statusnet")) {
309                         $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
310                 }
311
312                 /// @TODO old-lost code (and below)?
313                 //if (Addon::isEnabled("ijpost")) {
314                 //      $r[] = array("photo" => "images/", "name" => "");
315                 //}
316
317                 if (Addon::isEnabled("libertree")) {
318                         $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
319                 }
320
321                 //if (Addon::isEnabled("ljpost")) {
322                 //      $r[] = array("photo" => "images/", "name" => "");
323                 //}
324
325                 if (Addon::isEnabled("pumpio")) {
326                         $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
327                 }
328
329                 if (Addon::isEnabled("tumblr")) {
330                         $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
331                 }
332
333                 if (Addon::isEnabled("twitter")) {
334                         $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
335                 }
336
337                 if (Addon::isEnabled("wppost")) {
338                         $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
339                 }
340
341                 if (function_exists("imap_open") && !Config::get("system", "imap_disabled") && !Config::get("system", "dfrn_only")) {
342                         $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
343                 }
344
345                 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
346
347                 if (DBA::isResult($r)) {
348                         $con_services = [];
349                         $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
350                         $aside['$con_services'] = $con_services;
351
352                         foreach ($r as $rr) {
353                                 $entry = Renderer::replaceMacros($tpl, [
354                                         '$url' => $url,
355                                         '$photo' => $rr['photo'],
356                                         '$alt_text' => $rr['name'],
357                                 ]);
358                                 $aside['$connector_items'][] = $entry;
359                         }
360                 }
361         }
362         //end connectable services
363
364         //print right_aside
365         $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
366         DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
367 }