Merge branch 'develop' into rewrites/coding-convention-split2
[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         /// @TODO maybe move this static array out where it should belong?
105         if (($a->page['aside'] == "") AND in_array($a->argv[0], array("community", "events", "help", "manage", "notifications",
106                         "probe", "webfinger", "login", "invite", "credits"))) {
107                 $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
108         }
109 }
110
111 function get_vier_config($key, $default = false, $admin = false) {
112         if (local_user() AND !$admin) {
113                 $result = get_pconfig(local_user(), "vier", $key);
114                 if ($result !== false) {
115                         return $result;
116                 }
117         }
118
119         $result = get_config("vier", $key);
120         if ($result !== false) {
121                 return $result;
122         }
123
124         return $default;
125 }
126
127 function vier_community_info() {
128         $a = get_app();
129
130         $show_pages      = get_vier_config("show_pages", 1);
131         $show_profiles   = get_vier_config("show_profiles", 1);
132         $show_helpers    = get_vier_config("show_helpers", 1);
133         $show_services   = get_vier_config("show_services", 1);
134         $show_friends    = get_vier_config("show_friends", 1);
135         $show_lastusers  = get_vier_config("show_lastusers", 1);
136
137         // get_baseurl
138         $url = App::get_baseurl($ssl_state);
139         $aside['$url'] = $url;
140
141         // comunity_profiles
142         if ($show_profiles) {
143
144                 $r = suggestion_query(local_user(), 0, 9);
145
146                 $tpl = get_markup_template('ch_directory_item.tpl');
147                 if (dbm::is_result($r)) {
148
149                         $aside['$comunity_profiles_title'] = t('Community Profiles');
150                         $aside['$comunity_profiles_items'] = array();
151
152                         foreach ($r as $rr) {
153                                 $entry = replace_macros($tpl,array(
154                                         '$id' => $rr['id'],
155                                         //'$profile_link' => zrl($rr['url']),
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 = (get_config('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, 9);
176
177                 if (dbm::is_result($r)) {
178
179                         $aside['$lastusers_title'] = t('Last users');
180                         $aside['$lastusers_items'] = array();
181
182                         foreach ($r as $rr) {
183                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
184                                 $entry = replace_macros($tpl,array(
185                                         '$id' => $rr['id'],
186                                         '$profile_link' => $profile_link,
187                                         '$photo' => $a->remove_baseurl($rr['thumb']),
188                                         '$alt_text' => $rr['name']));
189                                 $aside['$lastusers_items'][] = $entry;
190                         }
191                 }
192         }
193
194         //right_aside FIND FRIENDS
195         if ($show_friends AND local_user()) {
196                 $nv = array();
197                 $nv['title'] = array("", t('Find Friends'), "", "");
198                 $nv['directory'] = array('directory', t('Local Directory'), "", "");
199                 $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", "");
200                 $nv['match'] = array('match', t('Similar Interests'), "", "");
201                 $nv['suggest'] = array('suggest', t('Friend Suggestions'), "", "");
202                 $nv['invite'] = array('invite', t('Invite Friends'), "", "");
203
204                 $nv['search'] = '<form name="simple_bar" method="get" action="dirfind">
205                                                 <span class="sbox_l"></span>
206                                                 <span class="sbox">
207                                                 <input type="text" name="search" size="13" maxlength="50">
208                                                 </span>
209                                                 <span class="sbox_r" id="srch_clear"></span>';
210
211                 $aside['$nv'] = $nv;
212         }
213
214         //Community_Pages at right_aside
215         if ($show_pages AND local_user()) {
216
217                 require_once 'include/ForumManager.php';
218
219                 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
220                         $cid = $_GET['cid'];
221                 }
222
223                 //sort by last updated item
224                 $lastitem = true;
225
226                 $contacts = ForumManager::get_list($a->user['uid'],true,$lastitem, true);
227                 $total = count($contacts);
228                 $visible_forums = 10;
229
230                 if (count($contacts)) {
231
232                         $id = 0;
233
234                         foreach ($contacts as $contact) {
235
236                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
237
238                                 $entry = array(
239                                         'url'          => 'network?f=&cid=' . $contact['id'],
240                                         'external_url' => 'redir/' . $contact['id'],
241                                         'name'         => $contact['name'],
242                                         'cid'          => $contact['id'],
243                                         'selected'     => $selected,
244                                         'micro'        => App::remove_baseurl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
245                                         'id'           => ++$id,
246                                 );
247                                 $entries[] = $entry;
248                         }
249
250
251                         $tpl = get_markup_template('widget_forumlist_right.tpl');
252
253                         $page .= replace_macros($tpl, array(
254                                 '$title'          => t('Forums'),
255                                 '$forums'         => $entries,
256                                 '$link_desc'      => t('External link to forum'),
257                                 '$total'          => $total,
258                                 '$visible_forums' => $visible_forums,
259                                 '$showmore'       => t('show more'),
260                         ));
261
262                         $aside['$page'] = $page;
263                 }
264         }
265         // END Community Page
266
267         // helpers
268         if ($show_helpers) {
269                 $r = array();
270
271                 $helperlist = get_config("vier", "helperlist");
272
273                 $helpers = explode(",",$helperlist);
274
275                 if ($helpers) {
276                         $query = "";
277                         foreach ($helpers AS $index=>$helper) {
278                                 if ($query != "")
279                                         $query .= ",";
280
281                                 $query .= "'".dbesc(normalise_link(trim($helper)))."'";
282                         }
283
284                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
285                 }
286
287                 foreach ($r AS $index => $helper)
288                         $r[$index]["url"] = zrl($helper["url"]);
289
290                 $r[] = array("url" => "help/Quick-Start-guide", "name" => t("Quick Start"));
291
292                 $tpl = get_markup_template('ch_helpers.tpl');
293
294                 if ($r) {
295
296                         $helpers = array();
297                         $helpers['title'] = array("", t('Help'), "", "");
298
299                         $aside['$helpers_items'] = array();
300
301                         foreach ($r as $rr) {
302                                 $entry = replace_macros($tpl,array(
303                                         '$url' => $rr['url'],
304                                         '$title' => $rr['name'],
305                                 ));
306                                 $aside['$helpers_items'][] = $entry;
307                         }
308
309                         $aside['$helpers'] = $helpers;
310                 }
311         }
312         // end helpers
313
314         // connectable services
315         if ($show_services) {
316
317                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
318                 $r = array();
319
320                 if (plugin_enabled("appnet")) {
321                         $r[] = array("photo" => "images/appnet.png", "name" => "App.net");
322                 }
323
324                 if (plugin_enabled("buffer")) {
325                         $r[] = array("photo" => "images/buffer.png", "name" => "Buffer");
326                 }
327
328                 if (plugin_enabled("blogger")) {
329                         $r[] = array("photo" => "images/blogger.png", "name" => "Blogger");
330                 }
331
332                 if (plugin_enabled("dwpost")) {
333                         $r[] = array("photo" => "images/dreamwidth.png", "name" => "Dreamwidth");
334                 }
335
336                 if (plugin_enabled("fbpost")) {
337                         $r[] = array("photo" => "images/facebook.png", "name" => "Facebook");
338                 }
339
340                 if (plugin_enabled("ifttt")) {
341                         $r[] = array("photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT");
342                 }
343
344                 if (plugin_enabled("statusnet")) {
345                         $r[] = array("photo" => "images/gnusocial.png", "name" => "GNU Social");
346                 }
347
348                 if (plugin_enabled("gpluspost")) {
349                         $r[] = array("photo" => "images/googleplus.png", "name" => "Google+");
350                 }
351
352                 /// @TODO old-lost code (and below)?
353                 //if (plugin_enabled("ijpost")) {
354                 //      $r[] = array("photo" => "images/", "name" => "");
355                 //}
356
357                 if (plugin_enabled("libertree")) {
358                         $r[] = array("photo" => "images/libertree.png", "name" => "Libertree");
359                 }
360
361                 //if (plugin_enabled("ljpost")) {
362                 //      $r[] = array("photo" => "images/", "name" => "");
363                 //}
364
365                 if (plugin_enabled("pumpio")) {
366                         $r[] = array("photo" => "images/pumpio.png", "name" => "pump.io");
367                 }
368
369                 if (plugin_enabled("tumblr")) {
370                         $r[] = array("photo" => "images/tumblr.png", "name" => "Tumblr");
371                 }
372
373                 if (plugin_enabled("twitter")) {
374                         $r[] = array("photo" => "images/twitter.png", "name" => "Twitter");
375                 }
376
377                 if (plugin_enabled("wppost")) {
378                         $r[] = array("photo" => "images/wordpress.png", "name" => "Wordpress");
379                 }
380
381                 if (function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only")) {
382                         $r[] = array("photo" => "images/mail.png", "name" => "E-Mail");
383                 }
384
385                 $tpl = get_markup_template('ch_connectors.tpl');
386
387                 if (dbm::is_result($r)) {
388
389                         $con_services = array();
390                         $con_services['title'] = array("", t('Connect Services'), "", "");
391                         $aside['$con_services'] = $con_services;
392
393                         foreach ($r as $rr) {
394                                 $entry = replace_macros($tpl,array(
395                                         '$url' => $url,
396                                         '$photo' => $rr['photo'],
397                                         '$alt_text' => $rr['name'],
398                                 ));
399                                 $aside['$connector_items'][] = $entry;
400                         }
401                 }
402
403         }
404         //end connectable services
405
406         //print right_aside
407         $tpl = get_markup_template('communityhome.tpl');
408         $a->page['right_aside'] = replace_macros($tpl, $aside);
409 }