]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
b99433f81b3de12d1ed0f94ee86eb0397a581705
[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\Addon;
15 use Friendica\Core\L10n;
16 use Friendica\Core\Config;
17 use Friendica\Core\PConfig;
18 use Friendica\Core\System;
19 use Friendica\Database\DBM;
20 use Friendica\Model\Contact;
21 use Friendica\Model\GContact;
22 use Friendica\Model\Profile;
23
24 require_once "mod/proxy.php";
25
26 function vier_init(App $a)
27 {
28         $a->theme_events_in_profile = false;
29
30         $a->set_template_engine('smarty3');
31
32         if (!empty($a->argv[0]) && !empty($a->argv[1])) {
33                 if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] || $a->argv[0] === "network" && local_user()) {
34                         vier_community_info();
35
36                         $a->page['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
37                 }
38         }
39
40         if ($a->is_mobile || $a->is_tablet) {
41                 $a->page['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
42                 $a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
43         }
44         /// @todo deactivated since it doesn't work with desktop browsers at the moment
45         //$a->page['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
46
47         $a->page['htmlhead'] .= <<< EOT
48 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
49 <script type="text/javascript">
50
51 function insertFormatting(BBcode, id) {
52         var tmpStr = $("#comment-edit-text-" + id).val();
53         if (tmpStr == "") {
54                 $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
55                 $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
56                 openMenu("comment-edit-submit-wrapper-" + id);
57         }
58
59         textarea = document.getElementById("comment-edit-text-" +id);
60         if (document.selection) {
61                 textarea.focus();
62                 selected = document.selection.createRange();
63                 selected.text = "["+BBcode+"]" + selected.text + "[/"+BBcode+"]";
64         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
65                 var start = textarea.selectionStart;
66                 var end = textarea.selectionEnd;
67                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
68         }
69
70         return true;
71 }
72
73 function showThread(id) {
74         $("#collapsed-comments-" + id).show()
75         $("#collapsed-comments-" + id + " .collapsed-comments").show()
76 }
77 function hideThread(id) {
78         $("#collapsed-comments-" + id).hide()
79         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
80 }
81
82 function cmtBbOpen(id) {
83         $("#comment-edit-bb-" + id).show();
84 }
85 function cmtBbClose(id) {
86         $("#comment-edit-bb-" + id).hide();
87 }
88 </script>
89 EOT;
90
91         if ($a->is_mobile || $a->is_tablet) {
92                 $a->page['htmlhead'] .= <<< EOT
93 <script>
94         $(document).ready(function() {
95                 $(".mobile-aside-toggle a").click(function(e){
96                         e.preventDefault();
97                         $("aside").toggleClass("show");
98                 });
99                 $(".tabs").click(function(e){
100                         $(this).toggleClass("show");
101                 });
102         });
103 </script>
104 EOT;
105         }
106
107         // Hide the left menu bar
108         /// @TODO maybe move this static array out where it should belong?
109         if (empty($a->page['aside']) && in_array($a->argv[0], ["community", "events", "help", "manage", "notifications",
110                         "probe", "webfinger", "login", "invite", "credits"])) {
111                 $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
112         }
113 }
114
115 function get_vier_config($key, $default = false, $admin = false)
116 {
117         if (local_user() && !$admin) {
118                 $result = PConfig::get(local_user(), "vier", $key);
119                 if (!is_null($result)) {
120                         return $result;
121                 }
122         }
123
124         $result = Config::get("vier", $key);
125         if (!is_null($result)) {
126                 return $result;
127         }
128
129         return $default;
130 }
131
132 function vier_community_info()
133 {
134         $a = get_app();
135
136         $show_pages      = get_vier_config("show_pages", 1);
137         $show_profiles   = get_vier_config("show_profiles", 1);
138         $show_helpers    = get_vier_config("show_helpers", 1);
139         $show_services   = get_vier_config("show_services", 1);
140         $show_friends    = get_vier_config("show_friends", 1);
141         $show_lastusers  = get_vier_config("show_lastusers", 1);
142
143         // get_baseurl
144         $url = System::baseUrl();
145         $aside['$url'] = $url;
146
147         // comunity_profiles
148         if ($show_profiles) {
149                 $r = GContact::suggestionQuery(local_user(), 0, 9);
150
151                 $tpl = get_markup_template('ch_directory_item.tpl');
152                 if (DBM::is_result($r)) {
153                         $aside['$comunity_profiles_title'] = L10n::t('Community Profiles');
154                         $aside['$comunity_profiles_items'] = [];
155
156                         foreach ($r as $rr) {
157                                 $entry = replace_macros($tpl, [
158                                         '$id' => $rr['id'],
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 = (Config::get('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,
179                         9
180                 );
181
182                 if (DBM::is_result($r)) {
183                         $aside['$lastusers_title'] = L10n::t('Last users');
184                         $aside['$lastusers_items'] = [];
185
186                         foreach ($r as $rr) {
187                                 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
188                                 $entry = replace_macros($tpl, [
189                                         '$id' => $rr['id'],
190                                         '$profile_link' => $profile_link,
191                                         '$photo' => $a->remove_baseurl($rr['thumb']),
192                                         '$alt_text' => $rr['name']]);
193                                 $aside['$lastusers_items'][] = $entry;
194                         }
195                 }
196         }
197
198         //right_aside FIND FRIENDS
199         if ($show_friends && local_user()) {
200                 $nv = [];
201                 $nv['findpeople'] = L10n::t('Find People');
202                 $nv['desc'] = L10n::t('Enter name or interest');
203                 $nv['label'] = L10n::t('Connect/Follow');
204                 $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
205                 $nv['findthem'] = L10n::t('Find');
206                 $nv['suggest'] = L10n::t('Friend Suggestions');
207                 $nv['similar'] = L10n::t('Similar Interests');
208                 $nv['random'] = L10n::t('Random Profile');
209                 $nv['inv'] = L10n::t('Invite Friends');
210                 $nv['directory'] = L10n::t('Global Directory');
211                 $nv['global_dir'] = get_server();
212                 $nv['local_directory'] = L10n::t('Local Directory');
213
214                 $aside['$nv'] = $nv;
215         }
216
217         //Community_Pages at right_aside
218         if ($show_pages && local_user()) {
219                 $cid = null;
220                 if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
221                         $cid = $_GET['cid'];
222                 }
223
224                 //sort by last updated item
225                 $lastitem = true;
226
227                 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
228                 $total = count($contacts);
229                 $visible_forums = 10;
230
231                 if (count($contacts)) {
232                         $id = 0;
233
234                         foreach ($contacts as $contact) {
235                                 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
236
237                                 $entry = [
238                                         'url'          => 'network?f=&cid=' . $contact['id'],
239                                         'external_url' => Contact::magicLink($contact['url']),
240                                         'name'         => $contact['name'],
241                                         'cid'          => $contact['id'],
242                                         'selected'     => $selected,
243                                         'micro'        => System::removedBaseUrl(proxy_url($contact['micro'], false, PROXY_SIZE_MICRO)),
244                                         'id'           => ++$id,
245                                 ];
246                                 $entries[] = $entry;
247                         }
248
249
250                         $tpl = get_markup_template('widget_forumlist_right.tpl');
251
252                         $page = replace_macros(
253                                 $tpl,
254                                 [
255                                         '$title'          => L10n::t('Forums'),
256                                         '$forums'         => $entries,
257                                         '$link_desc'      => L10n::t('External link to forum'),
258                                         '$total'          => $total,
259                                         '$visible_forums' => $visible_forums,
260                                         '$showmore'       => L10n::t('show more')]
261                         );
262
263                         $aside['$page'] = $page;
264                 }
265         }
266         // END Community Page
267
268         // helpers
269         if ($show_helpers) {
270                 $r = [];
271
272                 $helperlist = Config::get("vier", "helperlist");
273
274                 $helpers = explode(",", $helperlist);
275
276                 if ($helpers) {
277                         $query = "";
278                         foreach ($helpers as $index => $helper) {
279                                 if ($query != "") {
280                                         $query .= ",";
281                                 }
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"] = Contact::magicLink($helper["url"]);
291                 }
292
293                 $r[] = ["url" => "help/Quick-Start-guide", "name" => L10n::t("Quick Start")];
294
295                 $tpl = get_markup_template('ch_helpers.tpl');
296
297                 if ($r) {
298                         $helpers = [];
299                         $helpers['title'] = ["", L10n::t('Help'), "", ""];
300
301                         $aside['$helpers_items'] = [];
302
303                         foreach ($r as $rr) {
304                                 $entry = replace_macros($tpl, [
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                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
319                 $r = [];
320
321                 if (Addon::isEnabled("appnet")) {
322                         $r[] = ["photo" => "images/appnet.png", "name" => "App.net"];
323                 }
324
325                 if (Addon::isEnabled("buffer")) {
326                         $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
327                 }
328
329                 if (Addon::isEnabled("blogger")) {
330                         $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
331                 }
332
333                 if (Addon::isEnabled("dwpost")) {
334                         $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
335                 }
336
337                 if (Addon::isEnabled("fbpost")) {
338                         $r[] = ["photo" => "images/facebook.png", "name" => "Facebook"];
339                 }
340
341                 if (Addon::isEnabled("ifttt")) {
342                         $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
343                 }
344
345                 if (Addon::isEnabled("statusnet")) {
346                         $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
347                 }
348
349                 if (Addon::isEnabled("gpluspost")) {
350                         $r[] = ["photo" => "images/googleplus.png", "name" => "Google+"];
351                 }
352
353                 /// @TODO old-lost code (and below)?
354                 //if (Addon::isEnabled("ijpost")) {
355                 //      $r[] = array("photo" => "images/", "name" => "");
356                 //}
357
358                 if (Addon::isEnabled("libertree")) {
359                         $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
360                 }
361
362                 //if (Addon::isEnabled("ljpost")) {
363                 //      $r[] = array("photo" => "images/", "name" => "");
364                 //}
365
366                 if (Addon::isEnabled("pumpio")) {
367                         $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
368                 }
369
370                 if (Addon::isEnabled("tumblr")) {
371                         $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
372                 }
373
374                 if (Addon::isEnabled("twitter")) {
375                         $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
376                 }
377
378                 if (Addon::isEnabled("wppost")) {
379                         $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
380                 }
381
382                 if (function_exists("imap_open") && !Config::get("system", "imap_disabled") && !Config::get("system", "dfrn_only")) {
383                         $r[] = ["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                         $con_services = [];
390                         $con_services['title'] = ["", L10n::t('Connect Services'), "", ""];
391                         $aside['$con_services'] = $con_services;
392
393                         foreach ($r as $rr) {
394                                 $entry = replace_macros($tpl, [
395                                         '$url' => $url,
396                                         '$photo' => $rr['photo'],
397                                         '$alt_text' => $rr['name'],
398                                 ]);
399                                 $aside['$connector_items'][] = $entry;
400                         }
401                 }
402         }
403         //end connectable services
404
405         //print right_aside
406         $tpl = get_markup_template('communityhome.tpl');
407         $a->page['right_aside'] = replace_macros($tpl, $aside);
408 }