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\Config;
16 use Friendica\Core\L10n;
17 use Friendica\Core\PConfig;
18 use Friendica\Core\Renderer;
19 use Friendica\Database\DBA;
21 use Friendica\Model\Contact;
22 use Friendica\Model\GContact;
23 use Friendica\Util\Proxy as ProxyUtils;
24 use Friendica\Util\Strings;
26 function vier_init(App $a)
28 $a->theme_events_in_profile = false;
30 Renderer::setActiveTemplateEngine('smarty3');
32 if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . $a->user['nickname']) || $a->argv[0] === 'network' && local_user()) {
33 vier_community_info();
35 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
38 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
39 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
40 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
42 /// @todo deactivated since it doesn't work with desktop browsers at the moment
43 //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
45 DI::page()['htmlhead'] .= <<< EOT
46 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
47 <script type="text/javascript">
48 function showThread(id) {
49 $("#collapsed-comments-" + id).show()
50 $("#collapsed-comments-" + id + " .collapsed-comments").show()
52 function hideThread(id) {
53 $("#collapsed-comments-" + id).hide()
54 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
57 function cmtBbOpen(id) {
58 $("#comment-edit-bb-" + id).show();
60 function cmtBbClose(id) {
61 $("#comment-edit-bb-" + id).hide();
66 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
67 DI::page()['htmlhead'] .= <<< EOT
69 $(document).ready(function() {
70 $(".mobile-aside-toggle a").click(function(e){
72 $("aside").toggleClass("show");
74 $(".tabs").click(function(e){
75 $(this).toggleClass("show");
82 // Hide the left menu bar
83 /// @TODO maybe move this static array out where it should belong?
84 if (empty(DI::page()['aside']) && in_array($a->argv[0], ["community", "events", "help", "delegation", "notifications",
85 "probe", "webfinger", "login", "invite", "credits"])) {
86 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
90 function get_vier_config($key, $default = false, $admin = false)
92 if (local_user() && !$admin) {
93 $result = PConfig::get(local_user(), "vier", $key);
94 if (!is_null($result)) {
99 $result = Config::get("vier", $key);
100 if (!is_null($result)) {
107 function vier_community_info()
111 $show_pages = get_vier_config("show_pages", 1);
112 $show_profiles = get_vier_config("show_profiles", 1);
113 $show_helpers = get_vier_config("show_helpers", 1);
114 $show_services = get_vier_config("show_services", 1);
115 $show_friends = get_vier_config("show_friends", 1);
116 $show_lastusers = get_vier_config("show_lastusers", 1);
119 $url = DI::baseUrl();
120 $aside['$url'] = $url;
123 if ($show_profiles) {
124 $r = GContact::suggestionQuery(local_user(), 0, 9);
126 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
127 if (DBA::isResult($r)) {
128 $aside['$comunity_profiles_title'] = L10n::t('Community Profiles');
129 $aside['$comunity_profiles_items'] = [];
131 foreach ($r as $rr) {
132 $entry = Renderer::replaceMacros($tpl, [
134 '$profile_link' => 'follow/?url='.urlencode($rr['url']),
135 '$photo' => ProxyUtils::proxifyUrl($rr['photo'], false, ProxyUtils::SIZE_MICRO),
136 '$alt_text' => $rr['name'],
138 $aside['$comunity_profiles_items'][] = $entry;
144 if ($show_lastusers) {
145 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ");
146 $order = " ORDER BY `register_date` DESC ";
148 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
150 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
151 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
152 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
157 if (DBA::isResult($r)) {
158 $aside['$lastusers_title'] = L10n::t('Last users');
159 $aside['$lastusers_items'] = [];
161 foreach ($r as $rr) {
162 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
163 $entry = Renderer::replaceMacros($tpl, [
165 '$profile_link' => $profile_link,
166 '$photo' => DI::baseUrl()->remove($rr['thumb']),
167 '$alt_text' => $rr['name']]);
168 $aside['$lastusers_items'][] = $entry;
173 //right_aside FIND FRIENDS
174 if ($show_friends && local_user()) {
176 $nv['findpeople'] = L10n::t('Find People');
177 $nv['desc'] = L10n::t('Enter name or interest');
178 $nv['label'] = L10n::t('Connect/Follow');
179 $nv['hint'] = L10n::t('Examples: Robert Morgenstein, Fishing');
180 $nv['findthem'] = L10n::t('Find');
181 $nv['suggest'] = L10n::t('Friend Suggestions');
182 $nv['similar'] = L10n::t('Similar Interests');
183 $nv['random'] = L10n::t('Random Profile');
184 $nv['inv'] = L10n::t('Invite Friends');
185 $nv['directory'] = L10n::t('Global Directory');
186 $nv['global_dir'] = get_server();
187 $nv['local_directory'] = L10n::t('Local Directory');
192 //Community_Pages at right_aside
193 if ($show_pages && local_user()) {
194 $cid = $_GET['cid'] ?? null;
196 //sort by last updated item
199 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
200 $total = count($contacts);
201 $visible_forums = 10;
203 if (count($contacts)) {
206 foreach ($contacts as $contact) {
207 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
210 'url' => 'network?cid=' . $contact['id'],
211 'external_url' => Contact::magicLink($contact['url']),
212 'name' => $contact['name'],
213 'cid' => $contact['id'],
214 'selected' => $selected,
215 'micro' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
222 $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
224 $page = Renderer::replaceMacros(
227 '$title' => L10n::t('Forums'),
228 '$forums' => $entries,
229 '$link_desc' => L10n::t('External link to forum'),
231 '$visible_forums' => $visible_forums,
232 '$showmore' => L10n::t('show more')]
235 $aside['$page'] = $page;
238 // END Community Page
244 $helperlist = Config::get("vier", "helperlist");
246 $helpers = explode(",", $helperlist);
250 foreach ($helpers as $index => $helper) {
255 $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
258 $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
261 foreach ($r as $index => $helper) {
262 $r[$index]["url"] = Contact::magicLink($helper["url"]);
265 $r[] = ["url" => "help/Quick-Start-guide", "name" => L10n::t("Quick Start")];
267 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
271 $helpers['title'] = ["", L10n::t('Help'), "", ""];
273 $aside['$helpers_items'] = [];
275 foreach ($r as $rr) {
276 $entry = Renderer::replaceMacros($tpl, [
277 '$url' => $rr['url'],
278 '$title' => $rr['name'],
280 $aside['$helpers_items'][] = $entry;
283 $aside['$helpers'] = $helpers;
288 // connectable services
289 if ($show_services) {
290 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
293 if (Addon::isEnabled("buffer")) {
294 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
297 if (Addon::isEnabled("blogger")) {
298 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
301 if (Addon::isEnabled("dwpost")) {
302 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
305 if (Addon::isEnabled("ifttt")) {
306 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
309 if (Addon::isEnabled("statusnet")) {
310 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
313 /// @TODO old-lost code (and below)?
314 //if (Addon::isEnabled("ijpost")) {
315 // $r[] = array("photo" => "images/", "name" => "");
318 if (Addon::isEnabled("libertree")) {
319 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
322 //if (Addon::isEnabled("ljpost")) {
323 // $r[] = array("photo" => "images/", "name" => "");
326 if (Addon::isEnabled("pumpio")) {
327 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
330 if (Addon::isEnabled("tumblr")) {
331 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
334 if (Addon::isEnabled("twitter")) {
335 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
338 if (Addon::isEnabled("wppost")) {
339 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
342 if (function_exists("imap_open") && !Config::get("system", "imap_disabled") && !Config::get("system", "dfrn_only")) {
343 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
346 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
348 if (DBA::isResult($r)) {
350 $con_services['title'] = ["", L10n::t('Connect Services'), "", ""];
351 $aside['$con_services'] = $con_services;
353 foreach ($r as $rr) {
354 $entry = Renderer::replaceMacros($tpl, [
356 '$photo' => $rr['photo'],
357 '$alt_text' => $rr['name'],
359 $aside['$connector_items'][] = $entry;
363 //end connectable services
366 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
367 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);