]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
Update the last query at a single place
[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\Strings;
22
23 function vier_init(App $a)
24 {
25         $a->theme_events_in_profile = false;
26
27         Renderer::setActiveTemplateEngine('smarty3');
28
29         if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . ($a->user['nickname'] ?? '')) || $a->argv[0] === 'network' && local_user()) {
30                 vier_community_info();
31
32                 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
33         }
34
35         if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
36                 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
37                 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
38         }
39         /// @todo deactivated since it doesn't work with desktop browsers at the moment
40         //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
41
42         DI::page()['htmlhead'] .= <<< EOT
43 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
44 <script type="text/javascript">
45 function showThread(id) {
46         $("#collapsed-comments-" + id).show()
47         $("#collapsed-comments-" + id + " .collapsed-comments").show()
48 }
49 function hideThread(id) {
50         $("#collapsed-comments-" + id).hide()
51         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
52 }
53
54 function cmtBbOpen(id) {
55         $("#comment-edit-bb-" + id).show();
56 }
57 function cmtBbClose(id) {
58         $("#comment-edit-bb-" + id).hide();
59 }
60 </script>
61 EOT;
62
63         if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
64                 DI::page()['htmlhead'] .= <<< EOT
65 <script>
66         $(document).ready(function() {
67                 $(".mobile-aside-toggle a").click(function(e){
68                         e.preventDefault();
69                         $("aside").toggleClass("show");
70                 });
71                 $(".tabs").click(function(e){
72                         $(this).toggleClass("show");
73                 });
74         });
75 </script>
76 EOT;
77         }
78
79         // Hide the left menu bar
80         /// @TODO maybe move this static array out where it should belong?
81         if (empty(DI::page()['aside']) && in_array($a->argv[0], ["community", "events", "help", "delegation", "notifications",
82                         "probe", "webfinger", "login", "invite", "credits"])) {
83                 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
84         }
85 }
86
87 function get_vier_config($key, $default = false, $admin = false)
88 {
89         if (local_user() && !$admin) {
90                 $result = DI::pConfig()->get(local_user(), "vier", $key);
91                 if (!is_null($result)) {
92                         return $result;
93                 }
94         }
95
96         $result = DI::config()->get("vier", $key);
97         if (!is_null($result)) {
98                 return $result;
99         }
100
101         return $default;
102 }
103
104 function vier_community_info()
105 {
106         $a = DI::app();
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::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                 $cid = $_GET['cid'] ?? null;
189
190                 //sort by last updated item
191                 $lastitem = true;
192
193                 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
194                 $total = count($contacts);
195                 $visible_forums = 10;
196
197                 if (count($contacts)) {
198                         $id = 0;
199
200                         foreach ($contacts as $contact) {
201                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
202
203                                 $entry = [
204                                         'url'          => 'network?contactid=' . $contact['id'],
205                                         'external_url' => Contact::magicLink($contact['url']),
206                                         'name'         => $contact['name'],
207                                         'cid'          => $contact['id'],
208                                         'selected'     => $selected,
209                                         'micro'        => Contact::getMicro($contact),
210                                         'id'           => ++$id,
211                                 ];
212                                 $entries[] = $entry;
213                         }
214
215
216                         $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
217
218                         $page = Renderer::replaceMacros(
219                                 $tpl,
220                                 [
221                                         '$title'          => DI::l10n()->t('Forums'),
222                                         '$forums'         => $entries,
223                                         '$link_desc'      => DI::l10n()->t('External link to forum'),
224                                         '$total'          => $total,
225                                         '$visible_forums' => $visible_forums,
226                                         '$showmore'       => DI::l10n()->t('show more')]
227                         );
228
229                         $aside['$page'] = $page;
230                 }
231         }
232         // END Community Page
233
234         // helpers
235         if ($show_helpers) {
236                 $r = [];
237
238                 $helperlist = DI::config()->get("vier", "helperlist");
239
240                 $helpers = explode(",", $helperlist);
241
242                 if ($helpers) {
243                         $query = "";
244                         foreach ($helpers as $index => $helper) {
245                                 if ($query != "") {
246                                         $query .= ",";
247                                 }
248
249                                 $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
250                         }
251
252                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
253                 }
254
255                 foreach ($r as $index => $helper) {
256                         $r[$index]["url"] = Contact::magicLink($helper["url"]);
257                 }
258
259                 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
260
261                 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
262
263                 if ($r) {
264                         $helpers = [];
265                         $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
266
267                         $aside['$helpers_items'] = [];
268
269                         foreach ($r as $rr) {
270                                 $entry = Renderer::replaceMacros($tpl, [
271                                         '$url' => $rr['url'],
272                                         '$title' => $rr['name'],
273                                 ]);
274                                 $aside['$helpers_items'][] = $entry;
275                         }
276
277                         $aside['$helpers'] = $helpers;
278                 }
279         }
280         // end helpers
281
282         // connectable services
283         if ($show_services) {
284                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
285                 $r = [];
286
287                 if (Addon::isEnabled("buffer")) {
288                         $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
289                 }
290
291                 if (Addon::isEnabled("blogger")) {
292                         $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
293                 }
294
295                 if (Addon::isEnabled("dwpost")) {
296                         $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
297                 }
298
299                 if (Addon::isEnabled("ifttt")) {
300                         $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
301                 }
302
303                 if (Addon::isEnabled("statusnet")) {
304                         $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
305                 }
306
307                 /// @TODO old-lost code (and below)?
308                 //if (Addon::isEnabled("ijpost")) {
309                 //      $r[] = array("photo" => "images/", "name" => "");
310                 //}
311
312                 if (Addon::isEnabled("libertree")) {
313                         $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
314                 }
315
316                 //if (Addon::isEnabled("ljpost")) {
317                 //      $r[] = array("photo" => "images/", "name" => "");
318                 //}
319
320                 if (Addon::isEnabled("pumpio")) {
321                         $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
322                 }
323
324                 if (Addon::isEnabled("tumblr")) {
325                         $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
326                 }
327
328                 if (Addon::isEnabled("twitter")) {
329                         $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
330                 }
331
332                 if (Addon::isEnabled("wppost")) {
333                         $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
334                 }
335
336                 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled") && !DI::config()->get("system", "dfrn_only")) {
337                         $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
338                 }
339
340                 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
341
342                 if (DBA::isResult($r)) {
343                         $con_services = [];
344                         $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
345                         $aside['$con_services'] = $con_services;
346
347                         foreach ($r as $rr) {
348                                 $entry = Renderer::replaceMacros($tpl, [
349                                         '$url' => $url,
350                                         '$photo' => $rr['photo'],
351                                         '$alt_text' => $rr['name'],
352                                 ]);
353                                 $aside['$connector_items'][] = $entry;
354                         }
355                 }
356         }
357         //end connectable services
358
359         //print right_aside
360         $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
361         DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
362 }
363
364 /**
365  * @param int|null $uid
366  * @return null
367  * @see \Friendica\Core\Theme::getBackgroundColor()
368  * @TODO Implement this function
369  */
370 function vier_get_background_color(int $uid = null)
371 {
372         return null;
373 }
374
375 /**
376  * @param int|null $uid
377  * @return null
378  * @see \Friendica\Core\Theme::getThemeColor()
379  * @TODO Implement this function
380  */
381 function vier_get_theme_color(int $uid = null)
382 {
383         return null;
384 }