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 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 $url = DI::baseUrl();
141 $aside['$url'] = $url;
144 if ($show_profiles) {
145 $contacts = Contact\Relation::getCachedSuggestions(DI::userSession()->getLocalUserId(), 0, 9);
147 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
148 if (DBA::isResult($contacts)) {
149 $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
150 $aside['$comunity_profiles_items'] = [];
152 foreach ($contacts as $contact) {
153 $entry = Renderer::replaceMacros($tpl, [
154 '$id' => $contact['id'],
155 '$profile_link' => 'contact/follow?url=' . urlencode($contact['url']),
156 '$photo' => Contact::getMicro($contact),
157 '$alt_text' => $contact['name'],
159 $aside['$comunity_profiles_items'][] = $entry;
165 if ($show_lastusers) {
166 $condition = ['blocked' => false];
167 if (!DI::config()->get('system', 'publish_all')) {
168 $condition['publish'] = true;
171 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
173 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
175 if (DBA::isResult($profiles)) {
176 $aside['$lastusers_title'] = DI::l10n()->t('Last users');
177 $aside['$lastusers_items'] = [];
179 foreach ($profiles as $profile) {
180 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
181 $entry = Renderer::replaceMacros($tpl, [
182 '$id' => $profile['id'],
183 '$profile_link' => $profile_link,
184 '$photo' => DI::baseUrl()->remove($profile['thumb']),
185 '$alt_text' => $profile['name']]);
186 $aside['$lastusers_items'][] = $entry;
191 //right_aside FIND FRIENDS
192 if ($show_friends && DI::userSession()->getLocalUserId()) {
194 $nv['findpeople'] = DI::l10n()->t('Find People');
195 $nv['desc'] = DI::l10n()->t('Enter name or interest');
196 $nv['label'] = DI::l10n()->t('Connect/Follow');
197 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
198 $nv['findthem'] = DI::l10n()->t('Find');
199 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
200 $nv['similar'] = DI::l10n()->t('Similar Interests');
201 $nv['random'] = DI::l10n()->t('Random Profile');
202 $nv['inv'] = DI::l10n()->t('Invite Friends');
203 $nv['directory'] = DI::l10n()->t('Global Directory');
204 $nv['global_dir'] = Search::getGlobalDirectory();
205 $nv['local_directory'] = DI::l10n()->t('Local Directory');
210 //Community_Pages at right_aside
211 if ($show_pages && DI::userSession()->getLocalUserId()) {
212 $aside['$page'] = ForumManager::widget('network/forum', DI::userSession()->getLocalUserId());;
214 // END Community Page
220 $helperlist = DI::config()->get("vier", "helperlist");
222 $helpers = explode(",", $helperlist);
225 foreach ($helpers as $helper) {
226 $urls[] = Strings::normaliseLink(trim($helper));
228 $r = DBA::selectToArray('contact', ['url', 'name'], ['uid' => 0, 'nurl' => $urls]);
231 foreach ($r as $index => $helper) {
232 $r[$index]["url"] = Contact::magicLink($helper["url"]);
235 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
237 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
241 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
243 $aside['$helpers_items'] = [];
245 foreach ($r as $rr) {
246 $entry = Renderer::replaceMacros($tpl, [
247 '$url' => $rr['url'],
248 '$title' => $rr['name'],
250 $aside['$helpers_items'][] = $entry;
253 $aside['$helpers'] = $helpers;
258 // connectable services
259 if ($show_services) {
260 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
263 if (Addon::isEnabled("buffer")) {
264 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
267 if (Addon::isEnabled("blogger")) {
268 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
271 if (Addon::isEnabled("dwpost")) {
272 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
275 if (Addon::isEnabled("ifttt")) {
276 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
279 if (Addon::isEnabled("statusnet")) {
280 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
283 /// @TODO old-lost code (and below)?
284 //if (Addon::isEnabled("ijpost")) {
285 // $r[] = array("photo" => "images/", "name" => "");
288 if (Addon::isEnabled("libertree")) {
289 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
292 //if (Addon::isEnabled("ljpost")) {
293 // $r[] = array("photo" => "images/", "name" => "");
296 if (Addon::isEnabled("pumpio")) {
297 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
300 if (Addon::isEnabled("tumblr")) {
301 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
304 if (Addon::isEnabled("twitter")) {
305 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
308 if (Addon::isEnabled("wppost")) {
309 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
312 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled")) {
313 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
316 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
318 if (DBA::isResult($r)) {
320 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
321 $aside['$con_services'] = $con_services;
323 foreach ($r as $rr) {
324 $entry = Renderer::replaceMacros($tpl, [
326 '$photo' => $rr['photo'],
327 '$alt_text' => $rr['name'],
329 $aside['$connector_items'][] = $entry;
333 //end connectable services
336 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
337 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
341 * @param int|null $uid
343 * @see \Friendica\Core\Theme::getBackgroundColor()
344 * @TODO Implement this function
346 function vier_get_background_color(int $uid = null)
352 * @param int|null $uid
354 * @see \Friendica\Core\Theme::getThemeColor()
355 * @TODO Implement this function
357 function vier_get_theme_color(int $uid = null)