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/
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;
19 use Friendica\Model\Contact;
20 use Friendica\Util\Strings;
22 function vier_init(App $a)
24 $a->theme_events_in_profile = false;
26 Renderer::setActiveTemplateEngine('smarty3');
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();
31 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
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";
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";
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()
48 function hideThread(id) {
49 $("#collapsed-comments-" + id).hide()
50 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
53 function cmtBbOpen(id) {
54 $("#comment-edit-bb-" + id).show();
56 function cmtBbClose(id) {
57 $("#comment-edit-bb-" + id).hide();
62 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
63 DI::page()['htmlhead'] .= <<< EOT
65 $(document).ready(function() {
66 $(".mobile-aside-toggle a").click(function(e){
68 $("aside").toggleClass("show");
70 $(".tabs").click(function(e){
71 $(this).toggleClass("show");
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' />";
86 function get_vier_config($key, $default = false, $admin = false)
88 if (local_user() && !$admin) {
89 $result = DI::pConfig()->get(local_user(), "vier", $key);
90 if (!is_null($result)) {
95 $result = DI::config()->get("vier", $key);
96 if (!is_null($result)) {
103 function vier_community_info()
107 $show_pages = get_vier_config("show_pages", 1);
108 $show_profiles = get_vier_config("show_profiles", 1);
109 $show_helpers = get_vier_config("show_helpers", 1);
110 $show_services = get_vier_config("show_services", 1);
111 $show_friends = get_vier_config("show_friends", 1);
112 $show_lastusers = get_vier_config("show_lastusers", 1);
115 $url = DI::baseUrl();
116 $aside['$url'] = $url;
119 if ($show_profiles) {
120 $contacts = Contact::getSuggestions(local_user(), 0, 9);
122 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
123 if (DBA::isResult($contacts)) {
124 $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
125 $aside['$comunity_profiles_items'] = [];
127 foreach ($contacts as $contact) {
128 $entry = Renderer::replaceMacros($tpl, [
129 '$id' => $contact['id'],
130 '$profile_link' => 'follow/?url='.urlencode($contact['url']),
131 '$photo' => Contact::getMicro($contact),
132 '$alt_text' => $contact['name'],
134 $aside['$comunity_profiles_items'][] = $entry;
140 if ($show_lastusers) {
141 $condition = ['blocked' => false];
142 if (!DI::config()->get('system', 'publish_all')) {
143 $condition['publish'] = true;
146 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
148 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
150 if (DBA::isResult($profiles)) {
151 $aside['$lastusers_title'] = DI::l10n()->t('Last users');
152 $aside['$lastusers_items'] = [];
154 foreach ($profiles as $profile) {
155 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
156 $entry = Renderer::replaceMacros($tpl, [
157 '$id' => $profile['id'],
158 '$profile_link' => $profile_link,
159 '$photo' => DI::baseUrl()->remove($profile['thumb']),
160 '$alt_text' => $profile['name']]);
161 $aside['$lastusers_items'][] = $entry;
166 //right_aside FIND FRIENDS
167 if ($show_friends && local_user()) {
169 $nv['findpeople'] = DI::l10n()->t('Find People');
170 $nv['desc'] = DI::l10n()->t('Enter name or interest');
171 $nv['label'] = DI::l10n()->t('Connect/Follow');
172 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
173 $nv['findthem'] = DI::l10n()->t('Find');
174 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
175 $nv['similar'] = DI::l10n()->t('Similar Interests');
176 $nv['random'] = DI::l10n()->t('Random Profile');
177 $nv['inv'] = DI::l10n()->t('Invite Friends');
178 $nv['directory'] = DI::l10n()->t('Global Directory');
179 $nv['global_dir'] = Search::getGlobalDirectory();
180 $nv['local_directory'] = DI::l10n()->t('Local Directory');
185 //Community_Pages at right_aside
186 if ($show_pages && local_user()) {
187 $cid = $_GET['cid'] ?? null;
189 //sort by last updated item
192 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
193 $total = count($contacts);
194 $visible_forums = 10;
196 if (count($contacts)) {
199 foreach ($contacts as $contact) {
200 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
203 'url' => 'network?contactid=' . $contact['id'],
204 'external_url' => Contact::magicLink($contact['url']),
205 'name' => $contact['name'],
206 'cid' => $contact['id'],
207 'selected' => $selected,
208 'micro' => Contact::getMicro($contact),
215 $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
217 $page = Renderer::replaceMacros(
220 '$title' => DI::l10n()->t('Forums'),
221 '$forums' => $entries,
222 '$link_desc' => DI::l10n()->t('External link to forum'),
224 '$visible_forums' => $visible_forums,
225 '$showmore' => DI::l10n()->t('show more')]
228 $aside['$page'] = $page;
231 // END Community Page
237 $helperlist = DI::config()->get("vier", "helperlist");
239 $helpers = explode(",", $helperlist);
243 foreach ($helpers as $index => $helper) {
248 $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
251 $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
254 foreach ($r as $index => $helper) {
255 $r[$index]["url"] = Contact::magicLink($helper["url"]);
258 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
260 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
264 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
266 $aside['$helpers_items'] = [];
268 foreach ($r as $rr) {
269 $entry = Renderer::replaceMacros($tpl, [
270 '$url' => $rr['url'],
271 '$title' => $rr['name'],
273 $aside['$helpers_items'][] = $entry;
276 $aside['$helpers'] = $helpers;
281 // connectable services
282 if ($show_services) {
283 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
286 if (Addon::isEnabled("buffer")) {
287 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
290 if (Addon::isEnabled("blogger")) {
291 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
294 if (Addon::isEnabled("dwpost")) {
295 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
298 if (Addon::isEnabled("ifttt")) {
299 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
302 if (Addon::isEnabled("statusnet")) {
303 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
306 /// @TODO old-lost code (and below)?
307 //if (Addon::isEnabled("ijpost")) {
308 // $r[] = array("photo" => "images/", "name" => "");
311 if (Addon::isEnabled("libertree")) {
312 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
315 //if (Addon::isEnabled("ljpost")) {
316 // $r[] = array("photo" => "images/", "name" => "");
319 if (Addon::isEnabled("pumpio")) {
320 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
323 if (Addon::isEnabled("tumblr")) {
324 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
327 if (Addon::isEnabled("twitter")) {
328 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
331 if (Addon::isEnabled("wppost")) {
332 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
335 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled") && !DI::config()->get("system", "dfrn_only")) {
336 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
339 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
341 if (DBA::isResult($r)) {
343 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
344 $aside['$con_services'] = $con_services;
346 foreach ($r as $rr) {
347 $entry = Renderer::replaceMacros($tpl, [
349 '$photo' => $rr['photo'],
350 '$alt_text' => $rr['name'],
352 $aside['$connector_items'][] = $entry;
356 //end connectable services
359 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
360 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
364 * @param int|null $uid
366 * @see \Friendica\Core\Theme::getBackgroundColor()
367 * @TODO Implement this function
369 function vier_get_background_color(int $uid = null)
375 * @param int|null $uid
377 * @see \Friendica\Core\Theme::getThemeColor()
378 * @TODO Implement this function
380 function vier_get_theme_color(int $uid = null)