]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
Issue-#3873
[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\Core\Config;
14 use Friendica\Core\PConfig;
15 use Friendica\Core\System;
16
17 require_once "include/plugin.php";
18 require_once "include/socgraph.php";
19 require_once "mod/proxy.php";
20
21 function vier_init(App $a) {
22
23         $a->theme_events_in_profile = false;
24
25         set_template_engine($a, 'smarty3');
26
27         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] || $a->argv[0] === "network" && local_user()) {
28                 vier_community_info();
29
30                 $a->page['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
31         }
32
33         if ($a->is_mobile || $a->is_tablet) {
34                 $a->page['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
35                 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
36         }
37         /// @todo deactivated since it doesn't work with desktop browsers at the moment
38         //$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
39
40         $a->page['htmlhead'] .= <<< EOT
41 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
42 <script type="text/javascript">
43
44 function insertFormatting(BBcode, id) {
45         var tmpStr = $("#comment-edit-text-" + id).val();
46         if (tmpStr == "") {
47                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
48                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
49                 openMenu("comment-edit-submit-wrapper-" + id);
50         }
51
52         textarea = document.getElementById("comment-edit-text-" +id);
53         if (document.selection) {
54                 textarea.focus();
55                 selected = document.selection.createRange();
56                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
57         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
58                 var start = textarea.selectionStart;
59                 var end = textarea.selectionEnd;
60                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
61         }
62
63         return true;
64 }
65
66 function showThread(id) {
67         $("#collapsed-comments-" + id).show()
68         $("#collapsed-comments-" + id + " .collapsed-comments").show()
69 }
70 function hideThread(id) {
71         $("#collapsed-comments-" + id).hide()
72         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
73 }
74
75 function cmtBbOpen(id) {
76         $("#comment-edit-bb-" + id).show();
77 }
78 function cmtBbClose(id) {
79         $("#comment-edit-bb-" + id).hide();
80 }
81 </script>
82 EOT;
83
84         if ($a->is_mobile || $a->is_tablet){
85                 $a->page['htmlhead'] .= <<< EOT
86 <script>
87         $(document).ready(function() {
88                 $(".mobile-aside-toggle a").click(function(e){
89                         e.preventDefault();
90                         $("aside").toggleClass("show");
91                 });
92                 $(".tabs").click(function(e){
93                         $(this).toggleClass("show");
94                 });
95         });
96 </script>
97 EOT;
98         }
99
100         // Hide the left menu bar
101         /// @TODO maybe move this static array out where it should belong?
102         if (($a->page['aside'] == "") && in_array($a->argv[0], array("community", "events", "help", "manage", "notifications",
103                         "probe", "webfinger", "login", "invite", "credits"))) {
104                 $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
105         }
106 }
107
108 function get_vier_config($key, $default = false, $admin = false) {
109         if (local_user() && !$admin) {
110                 $result = PConfig::get(local_user(), "vier", $key);
111                 if ($result !== false) {
112                         return $result;
113                 }
114         }
115
116         $result = Config::get("vier", $key);
117         if ($result !== false) {
118                 return $result;
119         }
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 = System::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 = (Config::get('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 && 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 && 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
220                 //sort by last updated item
221                 $lastitem = true;
222
223                 $contacts = ForumManager::get_list($a->user['uid'],true,$lastitem, true);
224                 $total = count($contacts);
225                 $visible_forums = 10;
226
227                 if (count($contacts)) {
228
229                         $id = 0;
230
231                         foreach ($contacts as $contact) {
232
233                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
234
235                                 $entry = array(
236                                         'url'          => 'network?f=&cid=' . $contact['id'],
237                                         'external_url' => 'redir/' . $contact['id'],
238                                         'name'         => $contact['name'],
239                                         'cid'          => $contact['id'],
240                                         'selected'     => $selected,
241                                         'micro'        => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
242                                         'id'           => ++$id,
243                                 );
244                                 $entries[] = $entry;
245                         }
246
247
248                         $tpl = get_markup_template('widget_forumlist_right.tpl');
249
250                         $page .= replace_macros($tpl, array(
251                                 '$title'          => t('Forums'),
252                                 '$forums'         => $entries,
253                                 '$link_desc'      => t('External link to forum'),
254                                 '$total'          => $total,
255                                 '$visible_forums' => $visible_forums,
256                                 '$showmore'       => t('show more'),
257                         ));
258
259                         $aside['$page'] = $page;
260                 }
261         }
262         // END Community Page
263
264         // helpers
265         if ($show_helpers) {
266                 $r = array();
267
268                 $helperlist = Config::get("vier", "helperlist");
269
270                 $helpers = explode(",",$helperlist);
271
272                 if ($helpers) {
273                         $query = "";
274                         foreach ($helpers AS $index=>$helper) {
275                                 if ($query != "")
276                                         $query .= ",";
277
278                                 $query .= "'".dbesc(normalise_link(trim($helper)))."'";
279                         }
280
281                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
282                 }
283
284                 foreach ($r AS $index => $helper)
285                         $r[$index]["url"] = zrl($helper["url"]);
286
287                 $r[] = array("url" => "help/Quick-Start-guide", "name" => t("Quick Start"));
288
289                 $tpl = get_markup_template('ch_helpers.tpl');
290
291                 if ($r) {
292
293                         $helpers = array();
294                         $helpers['title'] = array("", t('Help'), "", "");
295
296                         $aside['$helpers_items'] = array();
297
298                         foreach ($r as $rr) {
299                                 $entry = replace_macros($tpl,array(
300                                         '$url' => $rr['url'],
301                                         '$title' => $rr['name'],
302                                 ));
303                                 $aside['$helpers_items'][] = $entry;
304                         }
305
306                         $aside['$helpers'] = $helpers;
307                 }
308         }
309         // end helpers
310
311         // connectable services
312         if ($show_services) {
313
314                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
315                 $r = array();
316
317                 if (plugin_enabled("appnet")) {
318                         $r[] = array("photo" => "images/appnet.png", "name" => "App.net");
319                 }
320
321                 if (plugin_enabled("buffer")) {
322                         $r[] = array("photo" => "images/buffer.png", "name" => "Buffer");
323                 }
324
325                 if (plugin_enabled("blogger")) {
326                         $r[] = array("photo" => "images/blogger.png", "name" => "Blogger");
327                 }
328
329                 if (plugin_enabled("dwpost")) {
330                         $r[] = array("photo" => "images/dreamwidth.png", "name" => "Dreamwidth");
331                 }
332
333                 if (plugin_enabled("fbpost")) {
334                         $r[] = array("photo" => "images/facebook.png", "name" => "Facebook");
335                 }
336
337                 if (plugin_enabled("ifttt")) {
338                         $r[] = array("photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT");
339                 }
340
341                 if (plugin_enabled("statusnet")) {
342                         $r[] = array("photo" => "images/gnusocial.png", "name" => "GNU Social");
343                 }
344
345                 if (plugin_enabled("gpluspost")) {
346                         $r[] = array("photo" => "images/googleplus.png", "name" => "Google+");
347                 }
348
349                 /// @TODO old-lost code (and below)?
350                 //if (plugin_enabled("ijpost")) {
351                 //      $r[] = array("photo" => "images/", "name" => "");
352                 //}
353
354                 if (plugin_enabled("libertree")) {
355                         $r[] = array("photo" => "images/libertree.png", "name" => "Libertree");
356                 }
357
358                 //if (plugin_enabled("ljpost")) {
359                 //      $r[] = array("photo" => "images/", "name" => "");
360                 //}
361
362                 if (plugin_enabled("pumpio")) {
363                         $r[] = array("photo" => "images/pumpio.png", "name" => "pump.io");
364                 }
365
366                 if (plugin_enabled("tumblr")) {
367                         $r[] = array("photo" => "images/tumblr.png", "name" => "Tumblr");
368                 }
369
370                 if (plugin_enabled("twitter")) {
371                         $r[] = array("photo" => "images/twitter.png", "name" => "Twitter");
372                 }
373
374                 if (plugin_enabled("wppost")) {
375                         $r[] = array("photo" => "images/wordpress.png", "name" => "Wordpress");
376                 }
377
378                 if (function_exists("imap_open") && !Config::get("system","imap_disabled") && !Config::get("system","dfrn_only")) {
379                         $r[] = array("photo" => "images/mail.png", "name" => "E-Mail");
380                 }
381
382                 $tpl = get_markup_template('ch_connectors.tpl');
383
384                 if (dbm::is_result($r)) {
385
386                         $con_services = array();
387                         $con_services['title'] = array("", t('Connect Services'), "", "");
388                         $aside['$con_services'] = $con_services;
389
390                         foreach ($r as $rr) {
391                                 $entry = replace_macros($tpl,array(
392                                         '$url' => $url,
393                                         '$photo' => $rr['photo'],
394                                         '$alt_text' => $rr['name'],
395                                 ));
396                                 $aside['$connector_items'][] = $entry;
397                         }
398                 }
399
400         }
401         //end connectable services
402
403         //print right_aside
404         $tpl = get_markup_template('communityhome.tpl');
405         $a->page['right_aside'] = replace_macros($tpl, $aside);
406 }