]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
Some more avatar function replacements
[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                 $r = GContact::suggestionQuery(local_user(), 0, 9);
122
123                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
124                 if (DBA::isResult($r)) {
125                         $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
126                         $aside['$comunity_profiles_items'] = [];
127
128                         foreach ($r as $rr) {
129                                 $contact = Contact::getByURL($rr['url']);
130                                 $entry = Renderer::replaceMacros($tpl, [
131                                         '$id' => $rr['id'],
132                                         '$profile_link' => 'follow/?url='.urlencode($rr['url']),
133                                         '$photo' => Contact::getMicro($contact, $rr['photo']),
134                                         '$alt_text' => $contact['name'] ?? $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'        => Contact::getMicro($contact),
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 }