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