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