3 * @copyright Copyright (C) 2010-2023, 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\GroupManager;
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 Renderer::setActiveTemplateEngine('smarty3');
50 DI::mode()->has(App\Mode::MAINTENANCEDISABLED)
52 $args->get(0) === 'profile' && $args->get(1) === ($a->getLoggedInUserNickname() ?? '')
53 || $args->get(0) === 'network' && DI::userSession()->getLocalUserId()
56 vier_community_info();
58 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
61 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
62 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
63 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
65 /// @todo deactivated since it doesn't work with desktop browsers at the moment
66 //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
68 DI::page()['htmlhead'] .= <<< EOT
69 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
70 <script type="text/javascript">
71 function showThread(id) {
72 $("#collapsed-comments-" + id).show()
73 $("#collapsed-comments-" + id + " .collapsed-comments").show()
75 function hideThread(id) {
76 $("#collapsed-comments-" + id).hide()
77 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
80 function cmtBbOpen(id) {
81 $("#comment-edit-bb-" + id).show();
83 function cmtBbClose(id) {
84 $("#comment-edit-bb-" + id).hide();
89 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
90 DI::page()['htmlhead'] .= <<< EOT
92 $(document).ready(function() {
93 $(".mobile-aside-toggle a").click(function(e){
95 $("aside").toggleClass("show");
97 $(".tabs").click(function(e){
98 $(this).toggleClass("show");
105 // Hide the left menu bar
106 /// @TODO maybe move this static array out where it should belong?
107 if (empty(DI::page()['aside']) && in_array($args->get(0), ["community", "calendar", "help", "delegation", "notifications",
108 "probe", "webfinger", "login", "invite", "credits"])) {
109 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
113 function get_vier_config($key, $default = false, $admin = false)
115 if (DI::userSession()->getLocalUserId() && !$admin) {
116 $result = DI::pConfig()->get(DI::userSession()->getLocalUserId(), "vier", $key);
117 if (!is_null($result)) {
122 $result = DI::config()->get("vier", $key);
123 if (!is_null($result)) {
130 function vier_community_info()
132 $show_pages = get_vier_config("show_pages", 1);
133 $show_profiles = get_vier_config("show_profiles", 1);
134 $show_helpers = get_vier_config("show_helpers", 1);
135 $show_services = get_vier_config("show_services", 1);
136 $show_friends = get_vier_config("show_friends", 1);
137 $show_lastusers = get_vier_config("show_lastusers", 1);
140 $aside['$url'] = $url = (string)DI::baseUrl();
142 // community_profiles
143 if ($show_profiles) {
144 $contacts = Contact\Relation::getCachedSuggestions(DI::userSession()->getLocalUserId(), 0, 9);
146 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
147 if (DBA::isResult($contacts)) {
148 $aside['$community_profiles_title'] = DI::l10n()->t('Community Profiles');
149 $aside['$community_profiles_items'] = [];
151 foreach ($contacts as $contact) {
152 $entry = Renderer::replaceMacros($tpl, [
153 '$id' => $contact['id'],
154 '$profile_link' => 'contact/follow?url=' . urlencode($contact['url']),
155 '$photo' => Contact::getMicro($contact),
156 '$alt_text' => $contact['name'],
158 $aside['$community_profiles_items'][] = $entry;
164 if ($show_lastusers) {
165 $condition = ['blocked' => false];
166 if (!DI::config()->get('system', 'publish_all')) {
167 $condition['publish'] = true;
170 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
172 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
174 if (DBA::isResult($profiles)) {
175 $aside['$lastusers_title'] = DI::l10n()->t('Last users');
176 $aside['$lastusers_items'] = [];
178 foreach ($profiles as $profile) {
179 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
180 $entry = Renderer::replaceMacros($tpl, [
181 '$id' => $profile['id'],
182 '$profile_link' => $profile_link,
183 '$photo' => DI::baseUrl()->remove($profile['thumb']),
184 '$alt_text' => $profile['name']]);
185 $aside['$lastusers_items'][] = $entry;
190 //right_aside FIND FRIENDS
191 if ($show_friends && DI::userSession()->getLocalUserId()) {
193 $nv['findpeople'] = DI::l10n()->t('Find People');
194 $nv['desc'] = DI::l10n()->t('Enter name or interest');
195 $nv['label'] = DI::l10n()->t('Connect/Follow');
196 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
197 $nv['findthem'] = DI::l10n()->t('Find');
198 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
199 $nv['similar'] = DI::l10n()->t('Similar Interests');
200 $nv['random'] = DI::l10n()->t('Random Profile');
201 $nv['inv'] = DI::l10n()->t('Invite Friends');
202 $nv['directory'] = DI::l10n()->t('Global Directory');
203 $nv['global_dir'] = Search::getGlobalDirectory();
204 $nv['local_directory'] = DI::l10n()->t('Local Directory');
209 //Community_Pages at right_aside
210 if ($show_pages && DI::userSession()->getLocalUserId()) {
211 $aside['$page'] = GroupManager::widget('network/group', DI::userSession()->getLocalUserId());;
213 // END Community Page
219 $helperlist = DI::config()->get("vier", "helperlist");
221 $helpers = explode(",", $helperlist);
224 foreach ($helpers as $helper) {
225 $urls[] = Strings::normaliseLink(trim($helper));
227 $r = DBA::selectToArray('contact', ['url', 'name'], ['uid' => 0, 'nurl' => $urls]);
230 foreach ($r as $index => $helper) {
231 $r[$index]["url"] = Contact::magicLink($helper["url"]);
234 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
236 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
240 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
242 $aside['$helpers_items'] = [];
244 foreach ($r as $rr) {
245 $entry = Renderer::replaceMacros($tpl, [
246 '$url' => $rr['url'],
247 '$title' => $rr['name'],
249 $aside['$helpers_items'][] = $entry;
252 $aside['$helpers'] = $helpers;
257 // connectable services
258 if ($show_services) {
259 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
262 if (Addon::isEnabled("buffer")) {
263 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
266 if (Addon::isEnabled("blogger")) {
267 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
270 if (Addon::isEnabled("dwpost")) {
271 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
274 if (Addon::isEnabled("ifttt")) {
275 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
278 if (Addon::isEnabled("statusnet")) {
279 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
282 /// @TODO old-lost code (and below)?
283 //if (Addon::isEnabled("ijpost")) {
284 // $r[] = array("photo" => "images/", "name" => "");
287 if (Addon::isEnabled("libertree")) {
288 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
291 //if (Addon::isEnabled("ljpost")) {
292 // $r[] = array("photo" => "images/", "name" => "");
295 if (Addon::isEnabled("pumpio")) {
296 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
299 if (Addon::isEnabled("tumblr")) {
300 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
303 if (Addon::isEnabled("twitter")) {
304 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
307 if (Addon::isEnabled("wppost")) {
308 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
311 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled")) {
312 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
315 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
317 if (DBA::isResult($r)) {
319 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
320 $aside['$con_services'] = $con_services;
322 foreach ($r as $rr) {
323 $entry = Renderer::replaceMacros($tpl, [
325 '$photo' => $rr['photo'],
326 '$alt_text' => $rr['name'],
328 $aside['$connector_items'][] = $entry;
332 //end connectable services
335 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
336 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
340 * @param int|null $uid
342 * @see \Friendica\Core\Theme::getBackgroundColor()
343 * @TODO Implement this function
345 function vier_get_background_color(int $uid = null)
351 * @param int|null $uid
353 * @see \Friendica\Core\Theme::getThemeColor()
354 * @TODO Implement this function
356 function vier_get_theme_color(int $uid = null)