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