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\Model\GContact;
21 use Friendica\Util\Proxy as ProxyUtils;
22 use Friendica\Util\Strings;
24 function vier_init(App $a)
26 $a->theme_events_in_profile = false;
28 Renderer::setActiveTemplateEngine('smarty3');
30 if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . $a->user['nickname']) || $a->argv[0] === 'network' && local_user()) {
31 vier_community_info();
33 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
36 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
37 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
38 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
40 /// @todo deactivated since it doesn't work with desktop browsers at the moment
41 //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
43 DI::page()['htmlhead'] .= <<< EOT
44 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
45 <script type="text/javascript">
46 function showThread(id) {
47 $("#collapsed-comments-" + id).show()
48 $("#collapsed-comments-" + id + " .collapsed-comments").show()
50 function hideThread(id) {
51 $("#collapsed-comments-" + id).hide()
52 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
55 function cmtBbOpen(id) {
56 $("#comment-edit-bb-" + id).show();
58 function cmtBbClose(id) {
59 $("#comment-edit-bb-" + id).hide();
64 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
65 DI::page()['htmlhead'] .= <<< EOT
67 $(document).ready(function() {
68 $(".mobile-aside-toggle a").click(function(e){
70 $("aside").toggleClass("show");
72 $(".tabs").click(function(e){
73 $(this).toggleClass("show");
80 // Hide the left menu bar
81 /// @TODO maybe move this static array out where it should belong?
82 if (empty(DI::page()['aside']) && in_array($a->argv[0], ["community", "events", "help", "delegation", "notifications",
83 "probe", "webfinger", "login", "invite", "credits"])) {
84 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
88 function get_vier_config($key, $default = false, $admin = false)
90 if (local_user() && !$admin) {
91 $result = DI::pConfig()->get(local_user(), "vier", $key);
92 if (!is_null($result)) {
97 $result = DI::config()->get("vier", $key);
98 if (!is_null($result)) {
105 function vier_community_info()
109 $show_pages = get_vier_config("show_pages", 1);
110 $show_profiles = get_vier_config("show_profiles", 1);
111 $show_helpers = get_vier_config("show_helpers", 1);
112 $show_services = get_vier_config("show_services", 1);
113 $show_friends = get_vier_config("show_friends", 1);
114 $show_lastusers = get_vier_config("show_lastusers", 1);
117 $url = DI::baseUrl();
118 $aside['$url'] = $url;
121 if ($show_profiles) {
122 $r = GContact::suggestionQuery(local_user(), 0, 9);
124 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
125 if (DBA::isResult($r)) {
126 $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
127 $aside['$comunity_profiles_items'] = [];
129 foreach ($r as $rr) {
130 $entry = Renderer::replaceMacros($tpl, [
132 '$profile_link' => 'follow/?url='.urlencode($rr['url']),
133 '$photo' => ProxyUtils::proxifyUrl($rr['photo'], false, ProxyUtils::SIZE_MICRO),
134 '$alt_text' => $rr['name'],
136 $aside['$comunity_profiles_items'][] = $entry;
142 if ($show_lastusers) {
143 $condition = ['blocked' => false];
144 if (!DI::config()->get('system', 'publish_all')) {
145 $condition['publish'] = true;
148 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
150 $profiles = DBA::selectToArray('owner-view', [], $condition, ['order' => ['register_date' => true], 'limit' => [0, 9]]);
152 if (DBA::isResult($profiles)) {
153 $aside['$lastusers_title'] = DI::l10n()->t('Last users');
154 $aside['$lastusers_items'] = [];
156 foreach ($profiles as $profile) {
157 $profile_link = 'profile/' . ((strlen($profile['nickname'])) ? $profile['nickname'] : $profile['uid']);
158 $entry = Renderer::replaceMacros($tpl, [
159 '$id' => $profile['id'],
160 '$profile_link' => $profile_link,
161 '$photo' => DI::baseUrl()->remove($profile['thumb']),
162 '$alt_text' => $profile['name']]);
163 $aside['$lastusers_items'][] = $entry;
168 //right_aside FIND FRIENDS
169 if ($show_friends && local_user()) {
171 $nv['findpeople'] = DI::l10n()->t('Find People');
172 $nv['desc'] = DI::l10n()->t('Enter name or interest');
173 $nv['label'] = DI::l10n()->t('Connect/Follow');
174 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
175 $nv['findthem'] = DI::l10n()->t('Find');
176 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
177 $nv['similar'] = DI::l10n()->t('Similar Interests');
178 $nv['random'] = DI::l10n()->t('Random Profile');
179 $nv['inv'] = DI::l10n()->t('Invite Friends');
180 $nv['directory'] = DI::l10n()->t('Global Directory');
181 $nv['global_dir'] = Search::getGlobalDirectory();
182 $nv['local_directory'] = DI::l10n()->t('Local Directory');
187 //Community_Pages at right_aside
188 if ($show_pages && local_user()) {
189 $cid = $_GET['cid'] ?? null;
191 //sort by last updated item
194 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
195 $total = count($contacts);
196 $visible_forums = 10;
198 if (count($contacts)) {
201 foreach ($contacts as $contact) {
202 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
205 'url' => 'network?contactid=' . $contact['id'],
206 'external_url' => Contact::magicLink($contact['url']),
207 'name' => $contact['name'],
208 'cid' => $contact['id'],
209 'selected' => $selected,
210 'micro' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
217 $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
219 $page = Renderer::replaceMacros(
222 '$title' => DI::l10n()->t('Forums'),
223 '$forums' => $entries,
224 '$link_desc' => DI::l10n()->t('External link to forum'),
226 '$visible_forums' => $visible_forums,
227 '$showmore' => DI::l10n()->t('show more')]
230 $aside['$page'] = $page;
233 // END Community Page
239 $helperlist = DI::config()->get("vier", "helperlist");
241 $helpers = explode(",", $helperlist);
245 foreach ($helpers as $index => $helper) {
250 $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
253 $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
256 foreach ($r as $index => $helper) {
257 $r[$index]["url"] = Contact::magicLink($helper["url"]);
260 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
262 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
266 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
268 $aside['$helpers_items'] = [];
270 foreach ($r as $rr) {
271 $entry = Renderer::replaceMacros($tpl, [
272 '$url' => $rr['url'],
273 '$title' => $rr['name'],
275 $aside['$helpers_items'][] = $entry;
278 $aside['$helpers'] = $helpers;
283 // connectable services
284 if ($show_services) {
285 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
288 if (Addon::isEnabled("buffer")) {
289 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
292 if (Addon::isEnabled("blogger")) {
293 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
296 if (Addon::isEnabled("dwpost")) {
297 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
300 if (Addon::isEnabled("ifttt")) {
301 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
304 if (Addon::isEnabled("statusnet")) {
305 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
308 /// @TODO old-lost code (and below)?
309 //if (Addon::isEnabled("ijpost")) {
310 // $r[] = array("photo" => "images/", "name" => "");
313 if (Addon::isEnabled("libertree")) {
314 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
317 //if (Addon::isEnabled("ljpost")) {
318 // $r[] = array("photo" => "images/", "name" => "");
321 if (Addon::isEnabled("pumpio")) {
322 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
325 if (Addon::isEnabled("tumblr")) {
326 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
329 if (Addon::isEnabled("twitter")) {
330 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
333 if (Addon::isEnabled("wppost")) {
334 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
337 if (function_exists("imap_open") && !DI::config()->get("system", "imap_disabled") && !DI::config()->get("system", "dfrn_only")) {
338 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
341 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
343 if (DBA::isResult($r)) {
345 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
346 $aside['$con_services'] = $con_services;
348 foreach ($r as $rr) {
349 $entry = Renderer::replaceMacros($tpl, [
351 '$photo' => $rr['photo'],
352 '$alt_text' => $rr['name'],
354 $aside['$connector_items'][] = $entry;
358 //end connectable services
361 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
362 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);
366 * @param int|null $uid
368 * @see \Friendica\Core\Theme::getBackgroundColor()
369 * @TODO Implement this function
371 function vier_get_background_color(int $uid = null)
377 * @param int|null $uid
379 * @see \Friendica\Core\Theme::getThemeColor()
380 * @TODO Implement this function
382 function vier_get_theme_color(int $uid = null)