3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 * Author: Fabio <http://kirgroup.com/profile/fabrixxm>
23 * Author: Ike <http://pirati.ca/profile/heluecht>
24 * Author: Beanow <https://fc.oscp.info/profile/beanow>
25 * Maintainer: Ike <http://pirati.ca/profile/heluecht>
26 * Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
30 use Friendica\Content\ForumManager;
31 use Friendica\Core\Addon;
32 use Friendica\Core\Renderer;
33 use Friendica\Core\Search;
34 use Friendica\Database\DBA;
36 use Friendica\Model\Contact;
37 use Friendica\Util\Strings;
40 * This script can be included even when the app is in maintenance mode which requires us to avoid any config call
43 function vier_init(App $a)
45 $a->setThemeInfoValue('events_in_profile', false);
47 Renderer::setActiveTemplateEngine('smarty3');
52 DI::mode()->has(App\Mode::MAINTENANCEDISABLED)
54 $args->get(0) === 'profile' && $args->get(1) === ($a->getLoggedInUserNickname() ?? '')
55 || $args->get(0) === 'network' && DI::userSession()->getLocalUserId()
58 vier_community_info();
60 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
63 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
64 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
65 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
67 /// @todo deactivated since it doesn't work with desktop browsers at the moment
68 //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
70 DI::page()['htmlhead'] .= <<< EOT
71 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
72 <script type="text/javascript">
73 function showThread(id) {
74 $("#collapsed-comments-" + id).show()
75 $("#collapsed-comments-" + id + " .collapsed-comments").show()
77 function hideThread(id) {
78 $("#collapsed-comments-" + id).hide()
79 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
82 function cmtBbOpen(id) {
83 $("#comment-edit-bb-" + id).show();
85 function cmtBbClose(id) {
86 $("#comment-edit-bb-" + id).hide();
91 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
92 DI::page()['htmlhead'] .= <<< EOT
94 $(document).ready(function() {
95 $(".mobile-aside-toggle a").click(function(e){
97 $("aside").toggleClass("show");
99 $(".tabs").click(function(e){
100 $(this).toggleClass("show");
107 // Hide the left menu bar
108 /// @TODO maybe move this static array out where it should belong?
109 if (empty(DI::page()['aside']) && in_array($args->get(0), ["community", "events", "help", "delegation", "notifications",
110 "probe", "webfinger", "login", "invite", "credits"])) {
111 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
115 function get_vier_config($key, $default = false, $admin = false)
117 if (DI::userSession()->getLocalUserId() && !$admin) {
118 $result = DI::pConfig()->get(DI::userSession()->getLocalUserId(), "vier", $key);
119 if (!is_null($result)) {
124 $result = DI::config()->get("vier", $key);
125 if (!is_null($result)) {
132 function vier_community_info()
134 $show_pages = get_vier_config("show_pages", 1);
135 $show_profiles = get_vier_config("show_profiles", 1);
136 $show_helpers = get_vier_config("show_helpers", 1);
137 $show_services = get_vier_config("show_services", 1);
138 $show_friends = get_vier_config("show_friends", 1);
139 $show_lastusers = get_vier_config("show_lastusers", 1);
142 $url = DI::baseUrl();
143 $aside['$url'] = $url;
146 if ($show_profiles) {
147 $contacts = Contact\Relation::getSuggestions(DI::userSession()->getLocalUserId(), 0, 9);
149 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
150 if (DBA::isResult($contacts)) {
151 $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
152 $aside['$comunity_profiles_items'] = [];
154 foreach ($contacts as $contact) {
155 $entry = Renderer::replaceMacros($tpl, [
156 '$id' => $contact['id'],
157 '$profile_link' => 'contact/follow/?url='.urlencode($contact['url']),
158 '$photo' => Contact::getMicro($contact),
159 '$alt_text' => $contact['name'],
161 $aside['$comunity_profiles_items'][] = $entry;
167 if ($show_lastusers) {
168 $condition = ['blocked' => false];
169 if (!DI::config()->get('system', 'publish_all')) {
170 $condition['publish'] = true;
173 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
175 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
177 if (DBA::isResult($profiles)) {
178 $aside['$lastusers_title'] = DI::l10n()->t('Last users');
179 $aside['$lastusers_items'] = [];
181 foreach ($profiles as $profile) {
182 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
183 $entry = Renderer::replaceMacros($tpl, [
184 '$id' => $profile['id'],
185 '$profile_link' => $profile_link,
186 '$photo' => DI::baseUrl()->remove($profile['thumb']),
187 '$alt_text' => $profile['name']]);
188 $aside['$lastusers_items'][] = $entry;
193 //right_aside FIND FRIENDS
194 if ($show_friends && DI::userSession()->getLocalUserId()) {
196 $nv['findpeople'] = DI::l10n()->t('Find People');
197 $nv['desc'] = DI::l10n()->t('Enter name or interest');
198 $nv['label'] = DI::l10n()->t('Connect/Follow');
199 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
200 $nv['findthem'] = DI::l10n()->t('Find');
201 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
202 $nv['similar'] = DI::l10n()->t('Similar Interests');
203 $nv['random'] = DI::l10n()->t('Random Profile');
204 $nv['inv'] = DI::l10n()->t('Invite Friends');
205 $nv['directory'] = DI::l10n()->t('Global Directory');
206 $nv['global_dir'] = Search::getGlobalDirectory();
207 $nv['local_directory'] = DI::l10n()->t('Local Directory');
212 //Community_Pages at right_aside
213 if ($show_pages && DI::userSession()->getLocalUserId()) {
214 $aside['$page'] = ForumManager::widget('network/forum', DI::userSession()->getLocalUserId());;
216 // END Community Page
222 $helperlist = DI::config()->get("vier", "helperlist");
224 $helpers = explode(",", $helperlist);
227 foreach ($helpers as $helper) {
228 $urls[] = Strings::normaliseLink(trim($helper));
230 $r = DBA::selectToArray('contact', ['url', 'name'], ['uid' => 0, 'nurl' => $urls]);
233 foreach ($r as $index => $helper) {
234 $r[$index]["url"] = Contact::magicLink($helper["url"]);
237 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
239 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
243 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
245 $aside['$helpers_items'] = [];
247 foreach ($r as $rr) {
248 $entry = Renderer::replaceMacros($tpl, [
249 '$url' => $rr['url'],
250 '$title' => $rr['name'],
252 $aside['$helpers_items'][] = $entry;
255 $aside['$helpers'] = $helpers;
260 // connectable services
261 if ($show_services) {
262 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
265 if (Addon::isEnabled("buffer")) {
266 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
269 if (Addon::isEnabled("blogger")) {
270 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
273 if (Addon::isEnabled("dwpost")) {
274 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
277 if (Addon::isEnabled("ifttt")) {
278 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
281 if (Addon::isEnabled("statusnet")) {
282 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
285 /// @TODO old-lost code (and below)?
286 //if (Addon::isEnabled("ijpost")) {
287 // $r[] = array("photo" => "images/", "name" => "");
290 if (Addon::isEnabled("libertree")) {
291 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
294 //if (Addon::isEnabled("ljpost")) {
295 // $r[] = array("photo" => "images/", "name" => "");
298 if (Addon::isEnabled("pumpio")) {
299 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
302 if (Addon::isEnabled("tumblr")) {
303 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
306 if (Addon::isEnabled("twitter")) {
307 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
310 if (Addon::isEnabled("wppost")) {
311 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
314 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled")) {
315 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
318 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
320 if (DBA::isResult($r)) {
322 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
323 $aside['$con_services'] = $con_services;
325 foreach ($r as $rr) {
326 $entry = Renderer::replaceMacros($tpl, [
328 '$photo' => $rr['photo'],
329 '$alt_text' => $rr['name'],
331 $aside['$connector_items'][] = $entry;
335 //end connectable services
338 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
339 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
343 * @param int|null $uid
345 * @see \Friendica\Core\Theme::getBackgroundColor()
346 * @TODO Implement this function
348 function vier_get_background_color(int $uid = null)
354 * @param int|null $uid
356 * @see \Friendica\Core\Theme::getThemeColor()
357 * @TODO Implement this function
359 function vier_get_theme_color(int $uid = null)