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