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);
242 foreach ($helpers as $helper) {
243 $urls[] = Strings::normaliseLink(trim($helper));
245 $r = DBA::selectToArray('contact', ['url', 'name'], ['uid' => 0, 'nurl' => $urls]);
248 foreach ($r as $index => $helper) {
249 $r[$index]["url"] = Contact::magicLink($helper["url"]);
252 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
254 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
258 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
260 $aside['$helpers_items'] = [];
262 foreach ($r as $rr) {
263 $entry = Renderer::replaceMacros($tpl, [
264 '$url' => $rr['url'],
265 '$title' => $rr['name'],
267 $aside['$helpers_items'][] = $entry;
270 $aside['$helpers'] = $helpers;
275 // connectable services
276 if ($show_services) {
277 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
280 if (Addon::isEnabled("buffer")) {
281 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
284 if (Addon::isEnabled("blogger")) {
285 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
288 if (Addon::isEnabled("dwpost")) {
289 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
292 if (Addon::isEnabled("ifttt")) {
293 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
296 if (Addon::isEnabled("statusnet")) {
297 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
300 /// @TODO old-lost code (and below)?
301 //if (Addon::isEnabled("ijpost")) {
302 // $r[] = array("photo" => "images/", "name" => "");
305 if (Addon::isEnabled("libertree")) {
306 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
309 //if (Addon::isEnabled("ljpost")) {
310 // $r[] = array("photo" => "images/", "name" => "");
313 if (Addon::isEnabled("pumpio")) {
314 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
317 if (Addon::isEnabled("tumblr")) {
318 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
321 if (Addon::isEnabled("twitter")) {
322 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
325 if (Addon::isEnabled("wppost")) {
326 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
329 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled") && !DI::config()->get("system", "dfrn_only")) {
330 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
333 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
335 if (DBA::isResult($r)) {
337 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
338 $aside['$con_services'] = $con_services;
340 foreach ($r as $rr) {
341 $entry = Renderer::replaceMacros($tpl, [
343 '$photo' => $rr['photo'],
344 '$alt_text' => $rr['name'],
346 $aside['$connector_items'][] = $entry;
350 //end connectable services
353 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
354 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
358 * @param int|null $uid
360 * @see \Friendica\Core\Theme::getBackgroundColor()
361 * @TODO Implement this function
363 function vier_get_background_color(int $uid = null)
369 * @param int|null $uid
371 * @see \Friendica\Core\Theme::getThemeColor()
372 * @TODO Implement this function
374 function vier_get_theme_color(int $uid = null)