]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
26066ccb048c9d8ccd06b99536682d946437d5bb
[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\Content\ForumManager;
14 use Friendica\Core\Config;
15 use Friendica\Core\PConfig;
16 use Friendica\Core\System;
17 use Friendica\Database\DBM;
18 use Friendica\Model\GContact;
19 use Friendica\Model\Profile;
20
21 require_once "include/plugin.php";
22 require_once "mod/proxy.php";
23
24 function vier_init(App $a) {
25
26         $a->theme_events_in_profile = false;
27
28         $a->set_template_engine('smarty3');
29
30         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] || $a->argv[0] === "network" && local_user()) {
31                 vier_community_info();
32
33                 $a->page['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
34         }
35
36         if ($a->is_mobile || $a->is_tablet) {
37                 $a->page['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
38                 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
39         }
40         /// @todo deactivated since it doesn't work with desktop browsers at the moment
41         //$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
42
43         $a->page['htmlhead'] .= <<< EOT
44 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
45 <script type="text/javascript">
46
47 function insertFormatting(BBcode, id) {
48         var tmpStr = $("#comment-edit-text-" + id).val();
49         if (tmpStr == "") {
50                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
51                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
52                 openMenu("comment-edit-submit-wrapper-" + id);
53         }
54
55         textarea = document.getElementById("comment-edit-text-" +id);
56         if (document.selection) {
57                 textarea.focus();
58                 selected = document.selection.createRange();
59                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
60         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
61                 var start = textarea.selectionStart;
62                 var end = textarea.selectionEnd;
63                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
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'] == "") && 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() && !$admin) {
113                 $result = PConfig::get(local_user(), "vier", $key);
114                 if (!is_null($result)) {
115                         return $result;
116                 }
117         }
118
119         $result = Config::get("vier", $key);
120         if (!is_null($result)) {
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 = System::baseUrl($ssl_state);
139         $aside['$url'] = $url;
140
141         // comunity_profiles
142         if ($show_profiles) {
143                 $r = GContact::suggestionQuery(local_user(), 0, 9);
144
145                 $tpl = get_markup_template('ch_directory_item.tpl');
146                 if (DBM::is_result($r)) {
147
148                         $aside['$comunity_profiles_title'] = t('Community Profiles');
149                         $aside['$comunity_profiles_items'] = array();
150
151                         foreach ($r as $rr) {
152                                 $entry = replace_macros($tpl,array(
153                                         '$id' => $rr['id'],
154                                         //'$profile_link' => Profile::zrl($rr['url']),
155                                         '$profile_link' => 'follow/?url='.urlencode($rr['url']),
156                                         '$photo' => proxy_url($rr['photo'], false, PROXY_SIZE_MICRO),
157                                         '$alt_text' => $rr['name'],
158                                 ));
159                                 $aside['$comunity_profiles_items'][] = $entry;
160                         }
161                 }
162         }
163
164         // last 9 users
165         if ($show_lastusers) {
166                 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ");
167                 $order = " ORDER BY `register_date` DESC ";
168
169                 $tpl = get_markup_template('ch_directory_item.tpl');
170
171                 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
172                                 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
173                                 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
174                                 0, 9);
175
176                 if (DBM::is_result($r)) {
177
178                         $aside['$lastusers_title'] = t('Last users');
179                         $aside['$lastusers_items'] = array();
180
181                         foreach ($r as $rr) {
182                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
183                                 $entry = replace_macros($tpl,array(
184                                         '$id' => $rr['id'],
185                                         '$profile_link' => $profile_link,
186                                         '$photo' => $a->remove_baseurl($rr['thumb']),
187                                         '$alt_text' => $rr['name']));
188                                 $aside['$lastusers_items'][] = $entry;
189                         }
190                 }
191         }
192
193         //right_aside FIND FRIENDS
194         if ($show_friends && local_user()) {
195                 $nv = array();
196                 $nv['title'] = array("", t('Find Friends'), "", "");
197                 $nv['directory'] = array('directory', t('Local Directory'), "", "");
198                 $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", "");
199                 $nv['match'] = array('match', t('Similar Interests'), "", "");
200                 $nv['suggest'] = array('suggest', t('Friend Suggestions'), "", "");
201                 $nv['invite'] = array('invite', t('Invite Friends'), "", "");
202
203                 $nv['search'] = '<form name="simple_bar" method="get" action="dirfind">
204                                                 <span class="sbox_l"></span>
205                                                 <span class="sbox">
206                                                 <input type="text" name="search" size="13" maxlength="50">
207                                                 </span>
208                                                 <span class="sbox_r" id="srch_clear"></span>';
209
210                 $aside['$nv'] = $nv;
211         }
212
213         //Community_Pages at right_aside
214         if ($show_pages && local_user()) {
215                 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
216                         $cid = $_GET['cid'];
217                 }
218
219                 //sort by last updated item
220                 $lastitem = true;
221
222                 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
223                 $total = count($contacts);
224                 $visible_forums = 10;
225
226                 if (count($contacts)) {
227                         $id = 0;
228
229                         foreach ($contacts as $contact) {
230                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
231
232                                 $entry = array(
233                                         'url'          => 'network?f=&cid=' . $contact['id'],
234                                         'external_url' => 'redir/' . $contact['id'],
235                                         'name'         => $contact['name'],
236                                         'cid'          => $contact['id'],
237                                         'selected'     => $selected,
238                                         'micro'        => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
239                                         'id'           => ++$id,
240                                 );
241                                 $entries[] = $entry;
242                         }
243
244
245                         $tpl = get_markup_template('widget_forumlist_right.tpl');
246
247                         $page .= replace_macros(
248                                 $tpl,
249                                 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 = Config::get("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"] = Profile::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                 /// @TODO old-lost code (and below)?
349                 //if (plugin_enabled("ijpost")) {
350                 //      $r[] = array("photo" => "images/", "name" => "");
351                 //}
352
353                 if (plugin_enabled("libertree")) {
354                         $r[] = array("photo" => "images/libertree.png", "name" => "Libertree");
355                 }
356
357                 //if (plugin_enabled("ljpost")) {
358                 //      $r[] = array("photo" => "images/", "name" => "");
359                 //}
360
361                 if (plugin_enabled("pumpio")) {
362                         $r[] = array("photo" => "images/pumpio.png", "name" => "pump.io");
363                 }
364
365                 if (plugin_enabled("tumblr")) {
366                         $r[] = array("photo" => "images/tumblr.png", "name" => "Tumblr");
367                 }
368
369                 if (plugin_enabled("twitter")) {
370                         $r[] = array("photo" => "images/twitter.png", "name" => "Twitter");
371                 }
372
373                 if (plugin_enabled("wppost")) {
374                         $r[] = array("photo" => "images/wordpress.png", "name" => "Wordpress");
375                 }
376
377                 if (function_exists("imap_open") && !Config::get("system","imap_disabled") && !Config::get("system","dfrn_only")) {
378                         $r[] = array("photo" => "images/mail.png", "name" => "E-Mail");
379                 }
380
381                 $tpl = get_markup_template('ch_connectors.tpl');
382
383                 if (DBM::is_result($r)) {
384
385                         $con_services = array();
386                         $con_services['title'] = array("", t('Connect Services'), "", "");
387                         $aside['$con_services'] = $con_services;
388
389                         foreach ($r as $rr) {
390                                 $entry = replace_macros($tpl,array(
391                                         '$url' => $url,
392                                         '$photo' => $rr['photo'],
393                                         '$alt_text' => $rr['name'],
394                                 ));
395                                 $aside['$connector_items'][] = $entry;
396                         }
397                 }
398
399         }
400         //end connectable services
401
402         //print right_aside
403         $tpl = get_markup_template('communityhome.tpl');
404         $a->page['right_aside'] = replace_macros($tpl, $aside);
405 }