Merge remote-tracking branch 'upstream/develop' into rewrites/app_get_baseurl_static
[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(&$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                 // deactivated since it doesn't work with desktop browsers at the moment (To-Do)
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(comment,BBcode,id) {
40
41                 var tmpStr = $("#comment-edit-text-" + id).val();
42                 if(tmpStr == comment) {
43                         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                         $("#comment-edit-text-" + id).val(tmpStr);
48                 }
49
50         textarea = document.getElementById("comment-edit-text-" +id);
51         if (document.selection) {
52                 textarea.focus();
53                 selected = document.selection.createRange();
54                 if (BBcode == "url"){
55                         selected.text = "["+BBcode+"]" + "http://" +  selected.text + "[/"+BBcode+"]";
56                         } else
57                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
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         return true;
67 }
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
80 function cmtBbOpen(id) {
81         $("#comment-edit-bb-" + id).show();
82 }
83 function cmtBbClose(id) {
84         $("#comment-edit-bb-" + id).hide();
85 }
86
87
88
89 </script>
90 EOT;
91
92
93 if ($a->is_mobile || $a->is_tablet){
94         $a->page['htmlhead'] .= <<< EOT
95 <script>
96         $(document).ready(function() {
97                 $(".mobile-aside-toggle a").click(function(e){
98                         e.preventDefault();
99                         $("aside").toggleClass("show");
100                 });
101                 $(".tabs").click(function(e){
102                         $(this).toggleClass("show");
103                 });
104         });
105 </script>
106 EOT;
107 }
108
109
110         // Hide the left menu bar
111         if (($a->page['aside'] == "") AND in_array($a->argv[0], array("community", "events", "help", "manage", "notifications",
112                                                                         "probe", "webfinger", "login", "invite", "credits")))
113                 $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
114 }
115
116 function get_vier_config($key, $default = false, $admin = false) {
117         if (local_user() AND !$admin) {
118                 $result = get_pconfig(local_user(), "vier", $key);
119                 if ($result !== false)
120                         return $result;
121         }
122
123         $result = get_config("vier", $key);
124         if ($result !== false)
125                 return $result;
126
127         return $default;
128 }
129
130 function vier_community_info() {
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 = App::get_baseurl($ssl_state);
142         $aside['$url'] = $url;
143
144         // comunity_profiles
145         if($show_profiles) {
146
147                 $r = suggestion_query(local_user(), 0, 9);
148
149                 $tpl = get_markup_template('ch_directory_item.tpl');
150                 if (dbm::is_result($r)) {
151
152                         $aside['$comunity_profiles_title'] = t('Community Profiles');
153                         $aside['$comunity_profiles_items'] = array();
154
155                         foreach ($r as $rr) {
156                                 $entry = replace_macros($tpl,array(
157                                         '$id' => $rr['id'],
158                                         //'$profile_link' => zrl($rr['url']),
159                                         '$profile_link' => 'follow/?url='.urlencode($rr['url']),
160                                         '$photo' => proxy_url($rr['photo'], false, PROXY_SIZE_MICRO),
161                                         '$alt_text' => $rr['name'],
162                                 ));
163                                 $aside['$comunity_profiles_items'][] = $entry;
164                         }
165                 }
166         }
167
168         // last 9 users
169         if($show_lastusers) {
170                 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 ");
171                 $order = " ORDER BY `register_date` DESC ";
172
173                 $tpl = get_markup_template('ch_directory_item.tpl');
174
175                 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
176                                 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
177                                 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
178                                 0, 9);
179
180                 if (dbm::is_result($r)) {
181
182                         $aside['$lastusers_title'] = t('Last users');
183                         $aside['$lastusers_items'] = array();
184
185                         foreach ($r as $rr) {
186                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
187                                 $entry = replace_macros($tpl,array(
188                                         '$id' => $rr['id'],
189                                         '$profile_link' => $profile_link,
190                                         '$photo' => $a->remove_baseurl($rr['thumb']),
191                                         '$alt_text' => $rr['name']));
192                                 $aside['$lastusers_items'][] = $entry;
193                         }
194                 }
195         }
196
197         //right_aside FIND FRIENDS
198         if ($show_friends AND local_user()) {
199                 $nv = array();
200                 $nv['title'] = Array("", t('Find Friends'), "", "");
201                 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
202                 $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", "");
203                 $nv['match'] = Array('match', t('Similar Interests'), "", "");
204                 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
205                 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
206
207                 $nv['search'] = '<form name="simple_bar" method="get" action="dirfind">
208                                                 <span class="sbox_l"></span>
209                                                 <span class="sbox">
210                                                 <input type="text" name="search" size="13" maxlength="50">
211                                                 </span>
212                                                 <span class="sbox_r" id="srch_clear"></span>';
213
214                 $aside['$nv'] = $nv;
215         }
216
217         //Community_Pages at right_aside
218         if($show_pages AND local_user()) {
219
220                 require_once('include/ForumManager.php');
221
222                 if(x($_GET['cid']) && intval($_GET['cid']) != 0)
223                         $cid = $_GET['cid'];
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                 //if (plugin_enabled("ijpost")) {
355                 //      $r[] = array("photo" => "images/", "name" => "");
356                 //}
357
358                 if (plugin_enabled("libertree")) {
359                         $r[] = array("photo" => "images/libertree.png", "name" => "Libertree");
360                 }
361
362                 //if (plugin_enabled("ljpost")) {
363                 //      $r[] = array("photo" => "images/", "name" => "");
364                 //}
365
366                 if (plugin_enabled("pumpio")) {
367                         $r[] = array("photo" => "images/pumpio.png", "name" => "pump.io");
368                 }
369
370                 if (plugin_enabled("tumblr")) {
371                         $r[] = array("photo" => "images/tumblr.png", "name" => "Tumblr");
372                 }
373
374                 if (plugin_enabled("twitter")) {
375                         $r[] = array("photo" => "images/twitter.png", "name" => "Twitter");
376                 }
377
378                 if (plugin_enabled("wppost")) {
379                         $r[] = array("photo" => "images/wordpress.png", "name" => "Wordpress");
380                 }
381
382                 if (function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only")) {
383                         $r[] = array("photo" => "images/mail.png", "name" => "E-Mail");
384                 }
385
386                 $tpl = get_markup_template('ch_connectors.tpl');
387
388                 if (dbm::is_result($r)) {
389
390                         $con_services = array();
391                         $con_services['title'] = Array("", t('Connect Services'), "", "");
392                         $aside['$con_services'] = $con_services;
393
394                         foreach ($r as $rr) {
395                                 $entry = replace_macros($tpl,array(
396                                         '$url' => $url,
397                                         '$photo' => $rr['photo'],
398                                         '$alt_text' => $rr['name'],
399                                 ));
400                                 $aside['$connector_items'][] = $entry;
401                         }
402                 }
403
404         }
405         //end connectable services
406
407         //print right_aside
408         $tpl = get_markup_template('communityhome.tpl');
409         $a->page['right_aside'] = replace_macros($tpl, $aside);
410 }