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