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