]> git.mxchange.org Git - friendica.git/blob - view/theme/vier/theme.php
Merge pull request #9540 from MrPetovan/bug/9538-security-blind-attack-username
[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\Renderer;
16 use Friendica\Core\Search;
17 use Friendica\Database\DBA;
18 use Friendica\DI;
19 use Friendica\Model\Contact;
20 use Friendica\Util\Strings;
21
22 function vier_init(App $a)
23 {
24         $a->theme_events_in_profile = false;
25
26         Renderer::setActiveTemplateEngine('smarty3');
27
28         if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . ($a->user['nickname'] ?? '')) || $a->argv[0] === 'network' && local_user()) {
29                 vier_community_info();
30
31                 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
32         }
33
34         if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
35                 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
36                 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
37         }
38         /// @todo deactivated since it doesn't work with desktop browsers at the moment
39         //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
40
41         DI::page()['htmlhead'] .= <<< EOT
42 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
43 <script type="text/javascript">
44 function showThread(id) {
45         $("#collapsed-comments-" + id).show()
46         $("#collapsed-comments-" + id + " .collapsed-comments").show()
47 }
48 function hideThread(id) {
49         $("#collapsed-comments-" + id).hide()
50         $("#collapsed-comments-" + id + " .collapsed-comments").hide()
51 }
52
53 function cmtBbOpen(id) {
54         $("#comment-edit-bb-" + id).show();
55 }
56 function cmtBbClose(id) {
57         $("#comment-edit-bb-" + id).hide();
58 }
59 </script>
60 EOT;
61
62         if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
63                 DI::page()['htmlhead'] .= <<< EOT
64 <script>
65         $(document).ready(function() {
66                 $(".mobile-aside-toggle a").click(function(e){
67                         e.preventDefault();
68                         $("aside").toggleClass("show");
69                 });
70                 $(".tabs").click(function(e){
71                         $(this).toggleClass("show");
72                 });
73         });
74 </script>
75 EOT;
76         }
77
78         // Hide the left menu bar
79         /// @TODO maybe move this static array out where it should belong?
80         if (empty(DI::page()['aside']) && in_array($a->argv[0], ["community", "events", "help", "delegation", "notifications",
81                         "probe", "webfinger", "login", "invite", "credits"])) {
82                 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
83         }
84 }
85
86 function get_vier_config($key, $default = false, $admin = false)
87 {
88         if (local_user() && !$admin) {
89                 $result = DI::pConfig()->get(local_user(), "vier", $key);
90                 if (!is_null($result)) {
91                         return $result;
92                 }
93         }
94
95         $result = DI::config()->get("vier", $key);
96         if (!is_null($result)) {
97                 return $result;
98         }
99
100         return $default;
101 }
102
103 function vier_community_info()
104 {
105         $show_pages      = get_vier_config("show_pages", 1);
106         $show_profiles   = get_vier_config("show_profiles", 1);
107         $show_helpers    = get_vier_config("show_helpers", 1);
108         $show_services   = get_vier_config("show_services", 1);
109         $show_friends    = get_vier_config("show_friends", 1);
110         $show_lastusers  = get_vier_config("show_lastusers", 1);
111
112         // get_baseurl
113         $url = DI::baseUrl();
114         $aside['$url'] = $url;
115
116         // comunity_profiles
117         if ($show_profiles) {
118                 $contacts = Contact\Relation::getSuggestions(local_user(), 0, 9);
119
120                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
121                 if (DBA::isResult($contacts)) {
122                         $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
123                         $aside['$comunity_profiles_items'] = [];
124
125                         foreach ($contacts as $contact) {
126                                 $entry = Renderer::replaceMacros($tpl, [
127                                         '$id' => $contact['id'],
128                                         '$profile_link' => 'follow/?url='.urlencode($contact['url']),
129                                         '$photo' => Contact::getMicro($contact),
130                                         '$alt_text' => $contact['name'],
131                                 ]);
132                                 $aside['$comunity_profiles_items'][] = $entry;
133                         }
134                 }
135         }
136
137         // last 9 users
138         if ($show_lastusers) {
139                 $condition = ['blocked' => false];
140                 if (!DI::config()->get('system', 'publish_all')) {
141                         $condition['publish'] = true;
142                 }
143
144                 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
145
146                 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
147
148                 if (DBA::isResult($profiles)) {
149                         $aside['$lastusers_title'] = DI::l10n()->t('Last users');
150                         $aside['$lastusers_items'] = [];
151
152                         foreach ($profiles as $profile) {
153                                 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
154                                 $entry = Renderer::replaceMacros($tpl, [
155                                         '$id' => $profile['id'],
156                                         '$profile_link' => $profile_link,
157                                         '$photo' => DI::baseUrl()->remove($profile['thumb']),
158                                         '$alt_text' => $profile['name']]);
159                                 $aside['$lastusers_items'][] = $entry;
160                         }
161                 }
162         }
163
164         //right_aside FIND FRIENDS
165         if ($show_friends && local_user()) {
166                 $nv = [];
167                 $nv['findpeople'] = DI::l10n()->t('Find People');
168                 $nv['desc'] = DI::l10n()->t('Enter name or interest');
169                 $nv['label'] = DI::l10n()->t('Connect/Follow');
170                 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
171                 $nv['findthem'] = DI::l10n()->t('Find');
172                 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
173                 $nv['similar'] = DI::l10n()->t('Similar Interests');
174                 $nv['random'] = DI::l10n()->t('Random Profile');
175                 $nv['inv'] = DI::l10n()->t('Invite Friends');
176                 $nv['directory'] = DI::l10n()->t('Global Directory');
177                 $nv['global_dir'] = Search::getGlobalDirectory();
178                 $nv['local_directory'] = DI::l10n()->t('Local Directory');
179
180                 $aside['$nv'] = $nv;
181         }
182
183         //Community_Pages at right_aside
184         if ($show_pages && local_user()) {
185                 $aside['$page'] = ForumManager::widget('network/forum', local_user());;
186         }
187         // END Community Page
188
189         // helpers
190         if ($show_helpers) {
191                 $r = [];
192
193                 $helperlist = DI::config()->get("vier", "helperlist");
194
195                 $helpers = explode(",", $helperlist);
196
197                 if ($helpers) {
198                         foreach ($helpers as $helper) {
199                                 $urls[] = Strings::normaliseLink(trim($helper));
200                         }
201                         $r = DBA::selectToArray('contact', ['url', 'name'], ['uid' => 0, 'nurl' => $urls]);
202                 }
203
204                 foreach ($r as $index => $helper) {
205                         $r[$index]["url"] = Contact::magicLink($helper["url"]);
206                 }
207
208                 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
209
210                 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
211
212                 if ($r) {
213                         $helpers = [];
214                         $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
215
216                         $aside['$helpers_items'] = [];
217
218                         foreach ($r as $rr) {
219                                 $entry = Renderer::replaceMacros($tpl, [
220                                         '$url' => $rr['url'],
221                                         '$title' => $rr['name'],
222                                 ]);
223                                 $aside['$helpers_items'][] = $entry;
224                         }
225
226                         $aside['$helpers'] = $helpers;
227                 }
228         }
229         // end helpers
230
231         // connectable services
232         if ($show_services) {
233                 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
234                 $r = [];
235
236                 if (Addon::isEnabled("buffer")) {
237                         $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
238                 }
239
240                 if (Addon::isEnabled("blogger")) {
241                         $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
242                 }
243
244                 if (Addon::isEnabled("dwpost")) {
245                         $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
246                 }
247
248                 if (Addon::isEnabled("ifttt")) {
249                         $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
250                 }
251
252                 if (Addon::isEnabled("statusnet")) {
253                         $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
254                 }
255
256                 /// @TODO old-lost code (and below)?
257                 //if (Addon::isEnabled("ijpost")) {
258                 //      $r[] = array("photo" => "images/", "name" => "");
259                 //}
260
261                 if (Addon::isEnabled("libertree")) {
262                         $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
263                 }
264
265                 //if (Addon::isEnabled("ljpost")) {
266                 //      $r[] = array("photo" => "images/", "name" => "");
267                 //}
268
269                 if (Addon::isEnabled("pumpio")) {
270                         $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
271                 }
272
273                 if (Addon::isEnabled("tumblr")) {
274                         $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
275                 }
276
277                 if (Addon::isEnabled("twitter")) {
278                         $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
279                 }
280
281                 if (Addon::isEnabled("wppost")) {
282                         $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
283                 }
284
285                 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled") && !DI::config()->get("system", "dfrn_only")) {
286                         $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
287                 }
288
289                 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
290
291                 if (DBA::isResult($r)) {
292                         $con_services = [];
293                         $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
294                         $aside['$con_services'] = $con_services;
295
296                         foreach ($r as $rr) {
297                                 $entry = Renderer::replaceMacros($tpl, [
298                                         '$url' => $url,
299                                         '$photo' => $rr['photo'],
300                                         '$alt_text' => $rr['name'],
301                                 ]);
302                                 $aside['$connector_items'][] = $entry;
303                         }
304                 }
305         }
306         //end connectable services
307
308         //print right_aside
309         $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
310         DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
311 }
312
313 /**
314  * @param int|null $uid
315  * @return null
316  * @see \Friendica\Core\Theme::getBackgroundColor()
317  * @TODO Implement this function
318  */
319 function vier_get_background_color(int $uid = null)
320 {
321         return null;
322 }
323
324 /**
325  * @param int|null $uid
326  * @return null
327  * @see \Friendica\Core\Theme::getThemeColor()
328  * @TODO Implement this function
329  */
330 function vier_get_theme_color(int $uid = null)
331 {
332         return null;
333 }