]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
Bugfix: The contact names had to be escaped
[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 require_once("mod/nodeinfo.php");
13 require_once("mod/proxy.php");
14 require_once("include/socgraph.php");
15
16 function vier_init(&$a) {
17
18         $a->theme_events_in_profile = false;
19
20         set_template_engine($a, 'smarty3');
21
22         $baseurl = $a->get_baseurl();
23
24         $a->theme_info = array();
25
26         if ($a->argv[0].$a->argv[1] === "profile".$a->user['nickname'] or $a->argv[0] === "network" && local_user()) {
27                 vier_community_info();
28
29                 $a->page['htmlhead'] .= "<link rel='stylesheet' media='screen and (min-width: 1300px)' href='view/theme/vier/wide.css' />";
30         }
31
32 $a->page['htmlhead'] .= <<< EOT
33 <link rel='stylesheet' media='screen and (max-width: 1100px)' href='view/theme/vier/narrow.css' />
34 <script type="text/javascript">
35
36 function insertFormatting(comment,BBcode,id) {
37
38                 var tmpStr = $("#comment-edit-text-" + id).val();
39                 if(tmpStr == comment) {
40                         tmpStr = "";
41                         $("#comment-edit-text-" + id).addClass("comment-edit-text-full");
42                         $("#comment-edit-text-" + id).removeClass("comment-edit-text-empty");
43                         openMenu("comment-edit-submit-wrapper-" + id);
44                         $("#comment-edit-text-" + id).val(tmpStr);
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         } else if (textarea.selectionStart || textarea.selectionStart == "0") {
56                 var start = textarea.selectionStart;
57                 var end = textarea.selectionEnd;
58                 if (BBcode == "url"){
59                         textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + "http://" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
60                         } else
61                 textarea.value = textarea.value.substring(0, start) + "["+BBcode+"]" + textarea.value.substring(start, end) + "[/"+BBcode+"]" + textarea.value.substring(end, textarea.value.length);
62         }
63         return true;
64 }
65
66
67 function showThread(id) {
68         $("#collapsed-comments-" + id).show()
69         $("#collapsed-comments-" + id + " .collapsed-comments").show()
70 }
71 function hideThread(id) {
72         $("#collapsed-comments-" + id).hide()
73         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
74 }
75
76
77 function cmtBbOpen(id) {
78         $("#comment-edit-bb-" + id).show();
79 }
80 function cmtBbClose(id) {
81         $("#comment-edit-bb-" + id).hide();
82 }
83 </script>
84 EOT;
85
86         // Hide the left menu bar
87         if (($a->page['aside'] == "") AND in_array($a->argv[0], array("community", "events", "help", "manage", "notifications",
88                                                                         "probe", "webfinger", "login", "invite")))
89                 $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
90 }
91
92 function get_vier_config($key, $default = false, $admin = false) {
93         if (local_user() AND !$admin) {
94                 $result = get_pconfig(local_user(), "vier", $key);
95                 if ($result !== false)
96                         return $result;
97         }
98
99         $result = get_config("vier", $key);
100         if ($result !== false)
101                 return $result;
102
103         return $default;
104 }
105
106 function vier_community_info() {
107         $a = get_app();
108
109         $show_pages      = get_vier_config("show_pages", 1);
110         $show_profiles   = get_vier_config("show_profiles", 1);
111         $show_helpers    = get_vier_config("show_helpers", 1);
112         $show_services   = get_vier_config("show_services", 1);
113         $show_friends    = get_vier_config("show_friends", 1);
114         $show_lastusers  = get_vier_config("show_lastusers", 1);
115
116         //get_baseurl
117         $url = $a->get_baseurl($ssl_state);
118         $aside['$url'] = $url;
119
120         // comunity_profiles
121         if($show_profiles) {
122
123                 $r = suggestion_query(local_user(), 0, 9);
124
125                 $tpl = get_markup_template('ch_directory_item.tpl');
126                 if(count($r)) {
127
128                         $aside['$comunity_profiles_title'] = t('Community Profiles');
129                         $aside['$comunity_profiles_items'] = array();
130
131                         foreach($r as $rr) {
132                                 $entry = replace_macros($tpl,array(
133                                         '$id' => $rr['id'],
134                                         //'$profile_link' => zrl($rr['url']),
135                                         '$profile_link' => $a->get_baseurl().'/follow/?url='.urlencode($rr['url']),
136                                         '$photo' => proxy_url($rr['photo'], false, PROXY_SIZE_MICRO),
137                                         '$alt_text' => $rr['name'],
138                                 ));
139                                 $aside['$comunity_profiles_items'][] = $entry;
140                         }
141                 }
142         }
143
144         // last 9 users
145         if($show_lastusers) {
146                 $publish = (get_config('system','publish_all') ? '' : " AND `publish` = 1 ");
147                 $order = " ORDER BY `register_date` DESC ";
148
149                 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
150                                 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
151                                 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
152                                 0, 9);
153
154                 $tpl = get_markup_template('ch_directory_item.tpl');
155                 if(count($r)) {
156
157                         $aside['$lastusers_title'] = t('Last users');
158                         $aside['$lastusers_items'] = array();
159
160                         foreach($r as $rr) {
161                                 $profile_link = $a->get_baseurl() . '/profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
162                                 $entry = replace_macros($tpl,array(
163                                         '$id' => $rr['id'],
164                                         '$profile_link' => $profile_link,
165                                         '$photo' => $a->get_cached_avatar_image($rr['thumb']),
166                                         '$alt_text' => $rr['name']));
167                                 $aside['$lastusers_items'][] = $entry;
168                         }
169                 }
170         }
171
172         //right_aside FIND FRIENDS
173         if ($show_friends AND local_user()) {
174                 $nv = array();
175                 $nv['title'] = Array("", t('Find Friends'), "", "");
176                 $nv['directory'] = Array('directory', t('Local Directory'), "", "");
177                 $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", "");
178                 $nv['match'] = Array('match', t('Similar Interests'), "", "");
179                 $nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", "");
180                 $nv['invite'] = Array('invite', t('Invite Friends'), "", "");
181
182                 $nv['search'] = '<form name="simple_bar" method="get" action="'.$a->get_baseurl().'/dirfind">
183                                                 <span class="sbox_l"></span>
184                                                 <span class="sbox">
185                                                 <input type="text" name="search" size="13" maxlength="50">
186                                                 </span>
187                                                 <span class="sbox_r" id="srch_clear"></span>';
188
189                 $aside['$nv'] = $nv;
190         }
191
192         //Community_Pages at right_aside
193         if($show_pages AND local_user()) {
194
195                 $pagelist = array();
196
197                 $contacts = q("SELECT `id`, `url`, `name`, `micro` FROM `contact`
198                                 WHERE `network`= '%s' AND `forum` AND `uid` = %d AND
199                                         NOT `hidden` AND NOT `blocked` AND
200                                         NOT `archive` AND NOT `pending` AND
201                                         `success_update` > `failure_update`
202                                 ORDER BY `name` ASC",
203                                 dbesc(NETWORK_DFRN), intval($a->user['uid']));
204
205                 $pageD = array();
206
207                 // Look if the profile is a community page
208                 foreach($contacts as $contact) {
209                         $pageD[] = array("url"=>$contact["url"], "name"=>$contact["name"], "id"=>$contact["id"], "micro"=>$contact['micro']);
210                 };
211
212                 $contacts = $pageD;
213
214                 if ($contacts) {
215                         $page = '
216                                 <h3>'.t("Community Pages").'</h3>
217                                 <div id="forum-list-right">';
218
219                         foreach($contacts as $contact) {
220                                 $page .= '<div role="menuitem"><a href="' . $a->get_baseurl() . '/redir/' . $contact["id"] . '" title="'.t('External link to forum').'" class="label sparkle" target="_blank"><img class="forumlist-img" height="20" width="20" src="' . $contact['micro'] .'" alt="'.t('External link to forum').'" /></a> <a href="' . $a->get_baseurl() . '/network?f=&cid=' . $contact['id'] . '" >' . $contact["name"]."</a></div>";
221                         }
222
223                         $page .= '</div>';
224                         $aside['$page'] = $page;
225                 }
226         }
227         //END Community Page
228
229         //helpers
230         if($show_helpers) {
231                 $r = array();
232
233                 $helperlist = get_config("vier", "helperlist");
234
235                 $helpers = explode(",",$helperlist);
236
237                 if ($helpers) {
238                         $query = "";
239                         foreach ($helpers AS $index=>$helper) {
240                                 if ($query != "")
241                                         $query .= ",";
242
243                                 $query .= "'".dbesc(normalise_link(trim($helper)))."'";
244                         }
245
246                         $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
247                 }
248
249                 foreach ($r AS $index => $helper)
250                         $r[$index]["url"] = zrl($helper["url"]);
251
252                 $r[] = Array("url" => "help/Quick-Start-guide", "name" => t("Quick Start"));
253
254                 $tpl = get_markup_template('ch_helpers.tpl');
255
256                 if ($r) {
257
258                         $helpers = array();
259                         $helpers['title'] = Array("", t('Help'), "", "");
260
261                         $aside['$helpers_items'] = array();
262
263                         foreach($r as $rr) {
264                                 $entry = replace_macros($tpl,array(
265                                         '$url' => $rr['url'],
266                                         '$title' => $rr['name'],
267                                 ));
268                                 $aside['$helpers_items'][] = $entry;
269                         }
270
271                         $aside['$helpers'] = $helpers;
272                 }
273         }
274         //end helpers
275
276         //connectable services
277         if ($show_services) {
278
279                 $r = array();
280
281                 if (nodeinfo_plugin_enabled("appnet"))
282                         $r[] = array("photo" => "images/appnet.png", "name" => "App.net");
283
284                 if (nodeinfo_plugin_enabled("buffer"))
285                         $r[] = array("photo" => "images/buffer.png", "name" => "Buffer");
286
287                 if (nodeinfo_plugin_enabled("blogger"))
288                         $r[] = array("photo" => "images/blogger.png", "name" => "Blogger");
289
290                 if (nodeinfo_plugin_enabled("dwpost"))
291                         $r[] = array("photo" => "images/dreamwidth.png", "name" => "Dreamwidth");
292
293                 if (nodeinfo_plugin_enabled("fbpost"))
294                         $r[] = array("photo" => "images/facebook.png", "name" => "Facebook");
295
296                 if (nodeinfo_plugin_enabled("statusnet"))
297                         $r[] = array("photo" => "images/gnusocial.png", "name" => "GNU Social");
298
299                 if (nodeinfo_plugin_enabled("gpluspost"))
300                         $r[] = array("photo" => "images/googleplus.png", "name" => "Google+");
301
302                 //if (nodeinfo_plugin_enabled("ijpost"))
303                 //      $r[] = array("photo" => "images/", "name" => "");
304
305                 if (nodeinfo_plugin_enabled("libertree"))
306                         $r[] = array("photo" => "images/libertree.png", "name" => "Libertree");
307
308                 //if (nodeinfo_plugin_enabled("ljpost"))
309                 //      $r[] = array("photo" => "images/", "name" => "");
310
311                 if (nodeinfo_plugin_enabled("pumpio"))
312                         $r[] = array("photo" => "images/pumpio.png", "name" => "pump.io");
313
314                 if (nodeinfo_plugin_enabled("tumblr"))
315                         $r[] = array("photo" => "images/tumblr.png", "name" => "Tumblr");
316
317                 if (nodeinfo_plugin_enabled("twitter"))
318                         $r[] = array("photo" => "images/twitter.png", "name" => "Twitter");
319
320                 if (nodeinfo_plugin_enabled("wppost"))
321                         $r[] = array("photo" => "images/wordpress", "name" => "Wordpress");
322
323                 if(function_exists("imap_open") AND !get_config("system","imap_disabled") AND !get_config("system","dfrn_only"))
324                         $r[] = array("photo" => "images/mail", "name" => "E-Mail");
325
326                 $tpl = get_markup_template('ch_connectors.tpl');
327
328                 if(count($r)) {
329
330                         $con_services = array();
331                         $con_services['title'] = Array("", t('Connect Services'), "", "");
332                         $aside['$con_services'] = $con_services;
333
334                         foreach($r as $rr) {
335                                 $entry = replace_macros($tpl,array(
336                                         '$url' => $url,
337                                         '$photo' => $rr['photo'],
338                                         '$alt_text' => $rr['name'],
339                                 ));
340                                 $aside['$connector_items'][] = $entry;
341                         }
342                 }
343
344         }
345         //end connectable services
346
347         //print right_aside
348         $tpl = get_markup_template('communityhome.tpl');
349         $a->page['right_aside'] = replace_macros($tpl, $aside);
350 }