]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
b703173bbd9c7484044ff276b4798ba1ccd59dd5
[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\System;
14
15 require_once "include/plugin.php";
16 require_once "include/socgraph.php";
17 require_once "mod/proxy.php";
18
19 function vier_init(App $a) {
20
21         $a->theme_events_in_profile = false;
22
23         set_template_engine($a, 'smarty3');
24
25         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] || $a->argv[0] === "network" && local_user()) {
26                 vier_community_info();
27
28                 $a->page['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
29         }
30
31         if ($a->is_mobile || $a->is_tablet) {
32                 $a->page['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
33                 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
34         }
35         /// @todo deactivated since it doesn't work with desktop browsers at the moment
36         //$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
37
38         $a->page['htmlhead'] .= <<< EOT
39 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
40 <script type="text/javascript">
41
42 function insertFormatting(BBcode, id) {
43         var tmpStr = $("#comment-edit-text-" + id).val();
44         if (tmpStr == "") {
45                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
46                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
47                 openMenu("comment-edit-submit-wrapper-" + id);
48         }
49
50         textarea = document.getElementById("comment-edit-text-" +id);
51         if (document.selection) {
52                 textarea.focus();
53                 selected = document.selection.createRange();
54                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
55         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
56                 var start = textarea.selectionStart;
57                 var end = textarea.selectionEnd;
58                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
59         }
60
61         return true;
62 }
63
64 function showThread(id) {
65         $("#collapsed-comments-" + id).show()
66         $("#collapsed-comments-" + id + " .collapsed-comments").show()
67 }
68 function hideThread(id) {
69         $("#collapsed-comments-" + id).hide()
70         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
71 }
72
73 function cmtBbOpen(id) {
74         $("#comment-edit-bb-" + id).show();
75 }
76 function cmtBbClose(id) {
77         $("#comment-edit-bb-" + id).hide();
78 }
79 </script>
80 EOT;
81
82         if ($a->is_mobile || $a->is_tablet){
83                 $a->page['htmlhead'] .= <<< EOT
84 <script>
85         $(document).ready(function() {
86                 $(".mobile-aside-toggle a").click(function(e){
87                         e.preventDefault();
88                         $("aside").toggleClass("show");
89                 });
90                 $(".tabs").click(function(e){
91                         $(this).toggleClass("show");
92                 });
93         });
94 </script>
95 EOT;
96         }
97
98         // Hide the left menu bar
99         /// @TODO maybe move this static array out where it should belong?
100         if (($a->page['aside'] == "") && in_array($a->argv[0], array("community", "events", "help", "manage", "notifications",
101                         "probe", "webfinger", "login", "invite", "credits"))) {
102                 $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
103         }
104 }
105
106 function get_vier_config($key, $default = false, $admin = false) {
107         if (local_user() && !$admin) {
108                 $result = get_pconfig(local_user(), "vier", $key);
109                 if ($result !== false) {
110                         return $result;
111                 }
112         }
113
114         $result = get_config("vier", $key);
115         if ($result !== false) {
116                 return $result;
117         }
118
119         return $default;
120 }
121
122 function vier_community_info() {
123         $a = get_app();
124
125         $show_pages      = get_vier_config("show_pages", 1);
126         $show_profiles   = get_vier_config("show_profiles", 1);
127         $show_helpers    = get_vier_config("show_helpers", 1);
128         $show_services   = get_vier_config("show_services", 1);
129         $show_friends    = get_vier_config("show_friends", 1);
130         $show_lastusers  = get_vier_config("show_lastusers", 1);
131
132         // get_baseurl
133         $url = System::baseUrl($ssl_state);
134         $aside['$url'] = $url;
135
136         // comunity_profiles
137         if ($show_profiles) {
138
139                 $r = suggestion_query(local_user(), 0, 9);
140
141                 $tpl = get_markup_template('ch_directory_item.tpl');
142                 if (dbm::is_result($r)) {
143
144                         $aside['$comunity_profiles_title'] = t('Community Profiles');
145                         $aside['$comunity_profiles_items'] = array();
146
147                         foreach ($r as $rr) {
148                                 $entry = replace_macros($tpl,array(
149                                         '$id' => $rr['id'],
150                                         //'$profile_link' => zrl($rr['url']),
151                                         '$profile_link' => 'follow/?url='.urlencode($rr['url']),
152                                         '$photo' => proxy_url($rr['photo'], false, PROXY_SIZE_MICRO),
153                                         '$alt_text' => $rr['name'],
154                                 ));
155                                 $aside['$comunity_profiles_items'][] = $entry;
156                         }
157                 }
158         }
159
160         // last 9 users
161         if ($show_lastusers) {
162                 $publish = (get_config('system', 'publish_all') ? '' : " AND `publish` = 1 ");
163                 $order = " ORDER BY `register_date` DESC ";
164
165                 $tpl = get_markup_template('ch_directory_item.tpl');
166
167                 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
168                                 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
169                                 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
170                                 0, 9);
171
172                 if (dbm::is_result($r)) {
173
174                         $aside['$lastusers_title'] = t('Last users');
175                         $aside['$lastusers_items'] = array();
176
177                         foreach ($r as $rr) {
178                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
179                                 $entry = replace_macros($tpl,array(
180                                         '$id' => $rr['id'],
181                                         '$profile_link' => $profile_link,
182                                         '$photo' => $a->remove_baseurl($rr['thumb']),
183                                         '$alt_text' => $rr['name']));
184                                 $aside['$lastusers_items'][] = $entry;
185                         }
186                 }
187         }
188
189         //right_aside FIND FRIENDS
190         if ($show_friends && local_user()) {
191                 $nv = array();
192                 $nv['title'] = array("", t('Find Friends'), "", "");
193                 $nv['directory'] = array('directory', t('Local Directory'), "", "");
194                 $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", "");
195                 $nv['match'] = array('match', t('Similar Interests'), "", "");
196                 $nv['suggest'] = array('suggest', t('Friend Suggestions'), "", "");
197                 $nv['invite'] = array('invite', t('Invite Friends'), "", "");
198
199                 $nv['search'] = '<form name="simple_bar" method="get" action="dirfind">
200                                                 <span class="sbox_l"></span>
201                                                 <span class="sbox">
202                                                 <input type="text" name="search" size="13" maxlength="50">
203                                                 </span>
204                                                 <span class="sbox_r" id="srch_clear"></span>';
205
206                 $aside['$nv'] = $nv;
207         }
208
209         //Community_Pages at right_aside
210         if ($show_pages && local_user()) {
211
212                 require_once 'include/ForumManager.php';
213
214                 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
215                         $cid = $_GET['cid'];
216                 }
217
218                 //sort by last updated item
219                 $lastitem = true;
220
221                 $contacts = ForumManager::get_list($a->user['uid'],true,$lastitem, true);
222                 $total = count($contacts);
223                 $visible_forums = 10;
224
225                 if (count($contacts)) {
226
227                         $id = 0;
228
229                         foreach ($contacts as $contact) {
230
231                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
232
233                                 $entry = array(
234                                         'url'          => 'network?f=&cid=' . $contact['id'],
235                                         'external_url' => 'redir/' . $contact['id'],
236                                         'name'         => $contact['name'],
237                                         'cid'          => $contact['id'],
238                                         'selected'     => $selected,
239                                         'micro'        => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
240                                         'id'           => ++$id,
241                                 );
242                                 $entries[] = $entry;
243                         }
244
245
246                         $tpl = get_markup_template('widget_forumlist_right.tpl');
247
248                         $page .= replace_macros($tpl, array(
249                                 '$title'          => t('Forums'),
250                                 '$forums'         => $entries,
251                                 '$link_desc'      => t('External link to forum'),
252                                 '$total'          => $total,
253                                 '$visible_forums' => $visible_forums,
254                                 '$showmore'       => t('show more'),
255                         ));
256
257                         $aside['$page'] = $page;
258                 }
259         }
260         // END Community Page
261
262         // helpers
263         if ($show_helpers) {
264                 $r = array();
265
266                 $helperlist = get_config("vier", "helperlist");
267
268                 $helpers = explode(",",$helperlist);
269
270                 if ($helpers) {
271                         $query = "";
272                         foreach ($helpers AS $index=>$helper) {
273                                 if ($query != "")
274                                         $query .= ",";
275
276                                 $query .= "'".dbesc(normalise_link(trim($helper)))."'";
277                         }
278
279                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
280                 }
281
282                 foreach ($r AS $index => $helper)
283                         $r[$index]["url"] = zrl($helper["url"]);
284
285                 $r[] = array("url" => "help/Quick-Start-guide", "name" => t("Quick Start"));
286
287                 $tpl = get_markup_template('ch_helpers.tpl');
288
289                 if ($r) {
290
291                         $helpers = array();
292                         $helpers['title'] = array("", t('Help'), "", "");
293
294                         $aside['$helpers_items'] = array();
295
296                         foreach ($r as $rr) {
297                                 $entry = replace_macros($tpl,array(
298                                         '$url' => $rr['url'],
299                                         '$title' => $rr['name'],
300                                 ));
301                                 $aside['$helpers_items'][] = $entry;
302                         }
303
304                         $aside['$helpers'] = $helpers;
305                 }
306         }
307         // end helpers
308
309         // connectable services
310         if ($show_services) {
311
312                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
313                 $r = array();
314
315                 if (plugin_enabled("appnet")) {
316                         $r[] = array("photo" => "images/appnet.png", "name" => "App.net");
317                 }
318
319                 if (plugin_enabled("buffer")) {
320                         $r[] = array("photo" => "images/buffer.png", "name" => "Buffer");
321                 }
322
323                 if (plugin_enabled("blogger")) {
324                         $r[] = array("photo" => "images/blogger.png", "name" => "Blogger");
325                 }
326
327                 if (plugin_enabled("dwpost")) {
328                         $r[] = array("photo" => "images/dreamwidth.png", "name" => "Dreamwidth");
329                 }
330
331                 if (plugin_enabled("fbpost")) {
332                         $r[] = array("photo" => "images/facebook.png", "name" => "Facebook");
333                 }
334
335                 if (plugin_enabled("ifttt")) {
336                         $r[] = array("photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT");
337                 }
338
339                 if (plugin_enabled("statusnet")) {
340                         $r[] = array("photo" => "images/gnusocial.png", "name" => "GNU Social");
341                 }
342
343                 if (plugin_enabled("gpluspost")) {
344                         $r[] = array("photo" => "images/googleplus.png", "name" => "Google+");
345                 }
346
347                 /// @TODO old-lost code (and below)?
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") && !get_config("system","imap_disabled") && !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 }