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\Core\Session;
35 use Friendica\Database\DBA;
37 use Friendica\Model\Contact;
38 use Friendica\Util\Strings;
41 * This script can be included even when the app is in maintenance mode which requires us to avoid any config call
44 function vier_init(App $a)
46 $a->setThemeInfoValue('events_in_profile', false);
48 Renderer::setActiveTemplateEngine('smarty3');
53 DI::mode()->has(App\Mode::MAINTENANCEDISABLED)
55 $args->get(0) === 'profile' && $args->get(1) === ($a->getLoggedInUserNickname() ?? '')
56 || $args->get(0) === 'network' && Session::getLocalUser()
59 vier_community_info();
61 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
64 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
65 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
66 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
68 /// @todo deactivated since it doesn't work with desktop browsers at the moment
69 //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
71 DI::page()['htmlhead'] .= <<< EOT
72 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
73 <script type="text/javascript">
74 function showThread(id) {
75 $("#collapsed-comments-" + id).show()
76 $("#collapsed-comments-" + id + " .collapsed-comments").show()
78 function hideThread(id) {
79 $("#collapsed-comments-" + id).hide()
80 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
83 function cmtBbOpen(id) {
84 $("#comment-edit-bb-" + id).show();
86 function cmtBbClose(id) {
87 $("#comment-edit-bb-" + id).hide();
92 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
93 DI::page()['htmlhead'] .= <<< EOT
95 $(document).ready(function() {
96 $(".mobile-aside-toggle a").click(function(e){
98 $("aside").toggleClass("show");
100 $(".tabs").click(function(e){
101 $(this).toggleClass("show");
108 // Hide the left menu bar
109 /// @TODO maybe move this static array out where it should belong?
110 if (empty(DI::page()['aside']) && in_array($args->get(0), ["community", "events", "help", "delegation", "notifications",
111 "probe", "webfinger", "login", "invite", "credits"])) {
112 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
116 function get_vier_config($key, $default = false, $admin = false)
118 if (Session::getLocalUser() && !$admin) {
119 $result = DI::pConfig()->get(Session::getLocalUser(), "vier", $key);
120 if (!is_null($result)) {
125 $result = DI::config()->get("vier", $key);
126 if (!is_null($result)) {
133 function vier_community_info()
135 $show_pages = get_vier_config("show_pages", 1);
136 $show_profiles = get_vier_config("show_profiles", 1);
137 $show_helpers = get_vier_config("show_helpers", 1);
138 $show_services = get_vier_config("show_services", 1);
139 $show_friends = get_vier_config("show_friends", 1);
140 $show_lastusers = get_vier_config("show_lastusers", 1);
143 $url = DI::baseUrl();
144 $aside['$url'] = $url;
147 if ($show_profiles) {
148 $contacts = Contact\Relation::getSuggestions(Session::getLocalUser(), 0, 9);
150 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
151 if (DBA::isResult($contacts)) {
152 $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
153 $aside['$comunity_profiles_items'] = [];
155 foreach ($contacts as $contact) {
156 $entry = Renderer::replaceMacros($tpl, [
157 '$id' => $contact['id'],
158 '$profile_link' => 'follow/?url='.urlencode($contact['url']),
159 '$photo' => Contact::getMicro($contact),
160 '$alt_text' => $contact['name'],
162 $aside['$comunity_profiles_items'][] = $entry;
168 if ($show_lastusers) {
169 $condition = ['blocked' => false];
170 if (!DI::config()->get('system', 'publish_all')) {
171 $condition['publish'] = true;
174 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
176 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
178 if (DBA::isResult($profiles)) {
179 $aside['$lastusers_title'] = DI::l10n()->t('Last users');
180 $aside['$lastusers_items'] = [];
182 foreach ($profiles as $profile) {
183 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
184 $entry = Renderer::replaceMacros($tpl, [
185 '$id' => $profile['id'],
186 '$profile_link' => $profile_link,
187 '$photo' => DI::baseUrl()->remove($profile['thumb']),
188 '$alt_text' => $profile['name']]);
189 $aside['$lastusers_items'][] = $entry;
194 //right_aside FIND FRIENDS
195 if ($show_friends && Session::getLocalUser()) {
197 $nv['findpeople'] = DI::l10n()->t('Find People');
198 $nv['desc'] = DI::l10n()->t('Enter name or interest');
199 $nv['label'] = DI::l10n()->t('Connect/Follow');
200 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
201 $nv['findthem'] = DI::l10n()->t('Find');
202 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
203 $nv['similar'] = DI::l10n()->t('Similar Interests');
204 $nv['random'] = DI::l10n()->t('Random Profile');
205 $nv['inv'] = DI::l10n()->t('Invite Friends');
206 $nv['directory'] = DI::l10n()->t('Global Directory');
207 $nv['global_dir'] = Search::getGlobalDirectory();
208 $nv['local_directory'] = DI::l10n()->t('Local Directory');
213 //Community_Pages at right_aside
214 if ($show_pages && Session::getLocalUser()) {
215 $aside['$page'] = ForumManager::widget('network/forum', Session::getLocalUser());;
217 // END Community Page
223 $helperlist = DI::config()->get("vier", "helperlist");
225 $helpers = explode(",", $helperlist);
228 foreach ($helpers as $helper) {
229 $urls[] = Strings::normaliseLink(trim($helper));
231 $r = DBA::selectToArray('contact', ['url', 'name'], ['uid' => 0, 'nurl' => $urls]);
234 foreach ($r as $index => $helper) {
235 $r[$index]["url"] = Contact::magicLink($helper["url"]);
238 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
240 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
244 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
246 $aside['$helpers_items'] = [];
248 foreach ($r as $rr) {
249 $entry = Renderer::replaceMacros($tpl, [
250 '$url' => $rr['url'],
251 '$title' => $rr['name'],
253 $aside['$helpers_items'][] = $entry;
256 $aside['$helpers'] = $helpers;
261 // connectable services
262 if ($show_services) {
263 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
266 if (Addon::isEnabled("buffer")) {
267 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
270 if (Addon::isEnabled("blogger")) {
271 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
274 if (Addon::isEnabled("dwpost")) {
275 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
278 if (Addon::isEnabled("ifttt")) {
279 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
282 if (Addon::isEnabled("statusnet")) {
283 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
286 /// @TODO old-lost code (and below)?
287 //if (Addon::isEnabled("ijpost")) {
288 // $r[] = array("photo" => "images/", "name" => "");
291 if (Addon::isEnabled("libertree")) {
292 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
295 //if (Addon::isEnabled("ljpost")) {
296 // $r[] = array("photo" => "images/", "name" => "");
299 if (Addon::isEnabled("pumpio")) {
300 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
303 if (Addon::isEnabled("tumblr")) {
304 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
307 if (Addon::isEnabled("twitter")) {
308 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
311 if (Addon::isEnabled("wppost")) {
312 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
315 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled")) {
316 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
319 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
321 if (DBA::isResult($r)) {
323 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
324 $aside['$con_services'] = $con_services;
326 foreach ($r as $rr) {
327 $entry = Renderer::replaceMacros($tpl, [
329 '$photo' => $rr['photo'],
330 '$alt_text' => $rr['name'],
332 $aside['$connector_items'][] = $entry;
336 //end connectable services
339 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
340 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
344 * @param int|null $uid
346 * @see \Friendica\Core\Theme::getBackgroundColor()
347 * @TODO Implement this function
349 function vier_get_background_color(int $uid = null)
355 * @param int|null $uid
357 * @see \Friendica\Core\Theme::getThemeColor()
358 * @TODO Implement this function
360 function vier_get_theme_color(int $uid = null)