]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
da2c08335dae02cb42c3e8579b8d7e33ac1b4cb3
[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
14 require_once "include/plugin.php";
15 require_once "include/socgraph.php";
16 require_once "mod/proxy.php";
17
18 function vier_init(App $a) {
19
20         $a->theme_events_in_profile = false;
21
22         set_template_engine($a, 'smarty3');
23
24         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()) {
25                 vier_community_info();
26
27                 $a->page['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
28         }
29
30         if ($a->is_mobile || $a->is_tablet) {
31                 $a->page['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
32                 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
33         }
34         /// @todo deactivated since it doesn't work with desktop browsers at the moment
35         //$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
36
37         $a->page['htmlhead'] .= <<< EOT
38 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
39 <script type="text/javascript">
40
41 function insertFormatting(BBcode, id) {
42         var tmpStr = $("#comment-edit-text-" + id).val();
43         if (tmpStr == "") {
44                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
45                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
46                 openMenu("comment-edit-submit-wrapper-" + id);
47         }
48
49         textarea = document.getElementById("comment-edit-text-" +id);
50         if (document.selection) {
51                 textarea.focus();
52                 selected = document.selection.createRange();
53                 if (BBcode == "url") {
54                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
55                 } else {
56                         selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
57                 }
58         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
59                 var start = textarea.selectionStart;
60                 var end = textarea.selectionEnd;
61                 if (BBcode == "url") {
62                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
63                 } else {
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
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 (($a->page['aside'] == "") AND in_array($a->argv[0], array("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         if (local_user() AND !$admin) {
115                 $result = get_pconfig(local_user(), "vier", $key);
116                 if ($result !== false) {
117                         return $result;
118                 }
119         }
120
121         $result = get_config("vier", $key);
122         if ($result !== false) {
123                 return $result;
124         }
125
126         return $default;
127 }
128
129 function vier_community_info() {
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 = App::get_baseurl($ssl_state);
141         $aside['$url'] = $url;
142
143         // comunity_profiles
144         if ($show_profiles) {
145
146                 $r = suggestion_query(local_user(), 0, 9);
147
148                 $tpl = get_markup_template('ch_directory_item.tpl');
149                 if (dbm::is_result($r)) {
150
151                         $aside['$comunity_profiles_title'] = t('Community Profiles');
152                         $aside['$comunity_profiles_items'] = array();
153
154                         foreach ($r as $rr) {
155                                 $entry = replace_macros($tpl,array(
156                                         '$id' => $rr['id'],
157                                         //'$profile_link' => zrl($rr['url']),
158                                         '$profile_link' => 'follow/?url='.urlencode($rr['url']),
159                                         '$photo' => proxy_url($rr['photo'], false, PROXY_SIZE_MICRO),
160                                         '$alt_text' => $rr['name'],
161                                 ));
162                                 $aside['$comunity_profiles_items'][] = $entry;
163                         }
164                 }
165         }
166
167         // last 9 users
168         if ($show_lastusers) {
169                 $publish = (get_config('system', 'publish_all') ? '' : " AND `publish` = 1 ");
170                 $order = " ORDER BY `register_date` DESC ";
171
172                 $tpl = get_markup_template('ch_directory_item.tpl');
173
174                 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
175                                 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
176                                 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
177                                 0, 9);
178
179                 if (dbm::is_result($r)) {
180
181                         $aside['$lastusers_title'] = t('Last users');
182                         $aside['$lastusers_items'] = array();
183
184                         foreach ($r as $rr) {
185                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
186                                 $entry = replace_macros($tpl,array(
187                                         '$id' => $rr['id'],
188                                         '$profile_link' => $profile_link,
189                                         '$photo' => $a->remove_baseurl($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 AND local_user()) {
198                 $nv = array();
199                 $nv['title'] = array("", t('Find Friends'), "", "");
200                 $nv['directory'] = array('directory', t('Local Directory'), "", "");
201                 $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", "");
202                 $nv['match'] = array('match', t('Similar Interests'), "", "");
203                 $nv['suggest'] = array('suggest', t('Friend Suggestions'), "", "");
204                 $nv['invite'] = array('invite', t('Invite Friends'), "", "");
205
206                 $nv['search'] = '<form name="simple_bar" method="get" action="dirfind">
207                                                 <span class="sbox_l"></span>
208                                                 <span class="sbox">
209                                                 <input type="text" name="search" size="13" maxlength="50">
210                                                 </span>
211                                                 <span class="sbox_r" id="srch_clear"></span>';
212
213                 $aside['$nv'] = $nv;
214         }
215
216         //Community_Pages at right_aside
217         if ($show_pages AND local_user()) {
218
219                 require_once 'include/ForumManager.php';
220
221                 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
222                         $cid = $_GET['cid'];
223                 }
224
225                 //sort by last updated item
226                 $lastitem = true;
227
228                 $contacts = ForumManager::get_list($a->user['uid'],true,$lastitem, true);
229                 $total = count($contacts);
230                 $visible_forums = 10;
231
232                 if (count($contacts)) {
233
234                         $id = 0;
235
236                         foreach ($contacts as $contact) {
237
238                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
239
240                                 $entry = array(
241                                         'url'          => 'network?f=&cid=' . $contact['id'],
242                                         'external_url' => 'redir/' . $contact['id'],
243                                         'name'         => $contact['name'],
244                                         'cid'          => $contact['id'],
245                                         'selected'     => $selected,
246                                         'micro'        => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
247                                         'id'           => ++$id,
248                                 );
249                                 $entries[] = $entry;
250                         }
251
252
253                         $tpl = get_markup_template('widget_forumlist_right.tpl');
254
255                         $page .= replace_macros($tpl, array(
256                                 '$title'          => t('Forums'),
257                                 '$forums'         => $entries,
258                                 '$link_desc'      => t('External link to forum'),
259                                 '$total'          => $total,
260                                 '$visible_forums' => $visible_forums,
261                                 '$showmore'       => t('show more'),
262                         ));
263
264                         $aside['$page'] = $page;
265                 }
266         }
267         // END Community Page
268
269         // helpers
270         if ($show_helpers) {
271                 $r = array();
272
273                 $helperlist = get_config("vier", "helperlist");
274
275                 $helpers = explode(",",$helperlist);
276
277                 if ($helpers) {
278                         $query = "";
279                         foreach ($helpers AS $index=>$helper) {
280                                 if ($query != "")
281                                         $query .= ",";
282
283                                 $query .= "'".dbesc(normalise_link(trim($helper)))."'";
284                         }
285
286                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
287                 }
288
289                 foreach ($r AS $index => $helper)
290                         $r[$index]["url"] = zrl($helper["url"]);
291
292                 $r[] = array("url" => "help/Quick-Start-guide", "name" => t("Quick Start"));
293
294                 $tpl = get_markup_template('ch_helpers.tpl');
295
296                 if ($r) {
297
298                         $helpers = array();
299                         $helpers['title'] = array("", t('Help'), "", "");
300
301                         $aside['$helpers_items'] = array();
302
303                         foreach ($r as $rr) {
304                                 $entry = replace_macros($tpl,array(
305                                         '$url' => $rr['url'],
306                                         '$title' => $rr['name'],
307                                 ));
308                                 $aside['$helpers_items'][] = $entry;
309                         }
310
311                         $aside['$helpers'] = $helpers;
312                 }
313         }
314         // end helpers
315
316         // connectable services
317         if ($show_services) {
318
319                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
320                 $r = array();
321
322                 if (plugin_enabled("appnet")) {
323                         $r[] = array("photo" => "images/appnet.png", "name" => "App.net");
324                 }
325
326                 if (plugin_enabled("buffer")) {
327                         $r[] = array("photo" => "images/buffer.png", "name" => "Buffer");
328                 }
329
330                 if (plugin_enabled("blogger")) {
331                         $r[] = array("photo" => "images/blogger.png", "name" => "Blogger");
332                 }
333
334                 if (plugin_enabled("dwpost")) {
335                         $r[] = array("photo" => "images/dreamwidth.png", "name" => "Dreamwidth");
336                 }
337
338                 if (plugin_enabled("fbpost")) {
339                         $r[] = array("photo" => "images/facebook.png", "name" => "Facebook");
340                 }
341
342                 if (plugin_enabled("ifttt")) {
343                         $r[] = array("photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT");
344                 }
345
346                 if (plugin_enabled("statusnet")) {
347                         $r[] = array("photo" => "images/gnusocial.png", "name" => "GNU Social");
348                 }
349
350                 if (plugin_enabled("gpluspost")) {
351                         $r[] = array("photo" => "images/googleplus.png", "name" => "Google+");
352                 }
353
354                 /// @TODO old-lost code (and below)?
355                 //if (plugin_enabled("ijpost")) {
356                 //      $r[] = array("photo" => "images/", "name" => "");
357                 //}
358
359                 if (plugin_enabled("libertree")) {
360                         $r[] = array("photo" => "images/libertree.png", "name" => "Libertree");
361                 }
362
363                 //if (plugin_enabled("ljpost")) {
364                 //      $r[] = array("photo" => "images/", "name" => "");
365                 //}
366
367                 if (plugin_enabled("pumpio")) {
368                         $r[] = array("photo" => "images/pumpio.png", "name" => "pump.io");
369                 }
370
371                 if (plugin_enabled("tumblr")) {
372                         $r[] = array("photo" => "images/tumblr.png", "name" => "Tumblr");
373                 }
374
375                 if (plugin_enabled("twitter")) {
376                         $r[] = array("photo" => "images/twitter.png", "name" => "Twitter");
377                 }
378
379                 if (plugin_enabled("wppost")) {
380                         $r[] = array("photo" => "images/wordpress.png", "name" => "Wordpress");
381                 }
382
383                 if (function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only")) {
384                         $r[] = array("photo" => "images/mail.png", "name" => "E-Mail");
385                 }
386
387                 $tpl = get_markup_template('ch_connectors.tpl');
388
389                 if (dbm::is_result($r)) {
390
391                         $con_services = array();
392                         $con_services['title'] = array("", t('Connect Services'), "", "");
393                         $aside['$con_services'] = $con_services;
394
395                         foreach ($r as $rr) {
396                                 $entry = replace_macros($tpl,array(
397                                         '$url' => $url,
398                                         '$photo' => $rr['photo'],
399                                         '$alt_text' => $rr['name'],
400                                 ));
401                                 $aside['$connector_items'][] = $entry;
402                         }
403                 }
404
405         }
406         //end connectable services
407
408         //print right_aside
409         $tpl = get_markup_template('communityhome.tpl');
410         $a->page['right_aside'] = replace_macros($tpl, $aside);
411 }