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\Renderer;
17 use Friendica\Core\Search;
18 use Friendica\Database\DBA;
20 use Friendica\Model\Contact;
21 use Friendica\Model\GContact;
22 use Friendica\Util\Proxy as ProxyUtils;
23 use Friendica\Util\Strings;
25 function vier_init(App $a)
27 $a->theme_events_in_profile = false;
29 Renderer::setActiveTemplateEngine('smarty3');
31 if (!empty($a->argv[0]) && ($a->argv[0] . ($a->argv[1] ?? '')) === ('profile' . $a->user['nickname']) || $a->argv[0] === 'network' && local_user()) {
32 vier_community_info();
34 DI::page()['htmlhead'] .= "<link rel='stylesheet' type='text/css' href='view/theme/vier/wide.css' media='screen and (min-width: 1300px)'/>\n";
37 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
38 DI::page()['htmlhead'] .= '<meta name=viewport content="width=device-width, initial-scale=1">'."\n";
39 DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen"/>'."\n";
41 /// @todo deactivated since it doesn't work with desktop browsers at the moment
42 //DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="view/theme/vier/mobile.css" media="screen and (max-width: 1000px)"/>'."\n";
44 DI::page()['htmlhead'] .= <<< EOT
45 <link rel='stylesheet' type='text/css' href='view/theme/vier/narrow.css' media='screen and (max-width: 1100px)' />
46 <script type="text/javascript">
47 function showThread(id) {
48 $("#collapsed-comments-" + id).show()
49 $("#collapsed-comments-" + id + " .collapsed-comments").show()
51 function hideThread(id) {
52 $("#collapsed-comments-" + id).hide()
53 $("#collapsed-comments-" + id + " .collapsed-comments").hide()
56 function cmtBbOpen(id) {
57 $("#comment-edit-bb-" + id).show();
59 function cmtBbClose(id) {
60 $("#comment-edit-bb-" + id).hide();
65 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
66 DI::page()['htmlhead'] .= <<< EOT
68 $(document).ready(function() {
69 $(".mobile-aside-toggle a").click(function(e){
71 $("aside").toggleClass("show");
73 $(".tabs").click(function(e){
74 $(this).toggleClass("show");
81 // Hide the left menu bar
82 /// @TODO maybe move this static array out where it should belong?
83 if (empty(DI::page()['aside']) && in_array($a->argv[0], ["community", "events", "help", "delegation", "notifications",
84 "probe", "webfinger", "login", "invite", "credits"])) {
85 DI::page()['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
89 function get_vier_config($key, $default = false, $admin = false)
91 if (local_user() && !$admin) {
92 $result = DI::pConfig()->get(local_user(), "vier", $key);
93 if (!is_null($result)) {
98 $result = Config::get("vier", $key);
99 if (!is_null($result)) {
106 function vier_community_info()
110 $show_pages = get_vier_config("show_pages", 1);
111 $show_profiles = get_vier_config("show_profiles", 1);
112 $show_helpers = get_vier_config("show_helpers", 1);
113 $show_services = get_vier_config("show_services", 1);
114 $show_friends = get_vier_config("show_friends", 1);
115 $show_lastusers = get_vier_config("show_lastusers", 1);
118 $url = DI::baseUrl();
119 $aside['$url'] = $url;
122 if ($show_profiles) {
123 $r = GContact::suggestionQuery(local_user(), 0, 9);
125 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
126 if (DBA::isResult($r)) {
127 $aside['$comunity_profiles_title'] = DI::l10n()->t('Community Profiles');
128 $aside['$comunity_profiles_items'] = [];
130 foreach ($r as $rr) {
131 $entry = Renderer::replaceMacros($tpl, [
133 '$profile_link' => 'follow/?url='.urlencode($rr['url']),
134 '$photo' => ProxyUtils::proxifyUrl($rr['photo'], false, ProxyUtils::SIZE_MICRO),
135 '$alt_text' => $rr['name'],
137 $aside['$comunity_profiles_items'][] = $entry;
143 if ($show_lastusers) {
144 $publish = (Config::get('system', 'publish_all') ? '' : " AND `publish` = 1 ");
145 $order = " ORDER BY `register_date` DESC ";
147 $tpl = Renderer::getMarkupTemplate('ch_directory_item.tpl');
149 $r = q("SELECT `profile`.*, `profile`.`uid` AS `profile_uid`, `user`.`nickname`
150 FROM `profile` LEFT JOIN `user` ON `user`.`uid` = `profile`.`uid`
151 WHERE `is-default` = 1 $publish AND `user`.`blocked` = 0 $order LIMIT %d , %d ",
156 if (DBA::isResult($r)) {
157 $aside['$lastusers_title'] = DI::l10n()->t('Last users');
158 $aside['$lastusers_items'] = [];
160 foreach ($r as $rr) {
161 $profile_link = 'profile/' . ((strlen($rr['nickname'])) ? $rr['nickname'] : $rr['profile_uid']);
162 $entry = Renderer::replaceMacros($tpl, [
164 '$profile_link' => $profile_link,
165 '$photo' => DI::baseUrl()->remove($rr['thumb']),
166 '$alt_text' => $rr['name']]);
167 $aside['$lastusers_items'][] = $entry;
172 //right_aside FIND FRIENDS
173 if ($show_friends && local_user()) {
175 $nv['findpeople'] = DI::l10n()->t('Find People');
176 $nv['desc'] = DI::l10n()->t('Enter name or interest');
177 $nv['label'] = DI::l10n()->t('Connect/Follow');
178 $nv['hint'] = DI::l10n()->t('Examples: Robert Morgenstein, Fishing');
179 $nv['findthem'] = DI::l10n()->t('Find');
180 $nv['suggest'] = DI::l10n()->t('Friend Suggestions');
181 $nv['similar'] = DI::l10n()->t('Similar Interests');
182 $nv['random'] = DI::l10n()->t('Random Profile');
183 $nv['inv'] = DI::l10n()->t('Invite Friends');
184 $nv['directory'] = DI::l10n()->t('Global Directory');
185 $nv['global_dir'] = Search::getGlobalDirectory();
186 $nv['local_directory'] = DI::l10n()->t('Local Directory');
191 //Community_Pages at right_aside
192 if ($show_pages && local_user()) {
193 $cid = $_GET['cid'] ?? null;
195 //sort by last updated item
198 $contacts = ForumManager::getList($a->user['uid'], $lastitem, true, true);
199 $total = count($contacts);
200 $visible_forums = 10;
202 if (count($contacts)) {
205 foreach ($contacts as $contact) {
206 $selected = (($cid == $contact['id']) ? ' forum-selected' : '');
209 'url' => 'network?cid=' . $contact['id'],
210 'external_url' => Contact::magicLink($contact['url']),
211 'name' => $contact['name'],
212 'cid' => $contact['id'],
213 'selected' => $selected,
214 'micro' => DI::baseUrl()->remove(ProxyUtils::proxifyUrl($contact['micro'], false, ProxyUtils::SIZE_MICRO)),
221 $tpl = Renderer::getMarkupTemplate('widget_forumlist_right.tpl');
223 $page = Renderer::replaceMacros(
226 '$title' => DI::l10n()->t('Forums'),
227 '$forums' => $entries,
228 '$link_desc' => DI::l10n()->t('External link to forum'),
230 '$visible_forums' => $visible_forums,
231 '$showmore' => DI::l10n()->t('show more')]
234 $aside['$page'] = $page;
237 // END Community Page
243 $helperlist = Config::get("vier", "helperlist");
245 $helpers = explode(",", $helperlist);
249 foreach ($helpers as $index => $helper) {
254 $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'";
257 $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);
260 foreach ($r as $index => $helper) {
261 $r[$index]["url"] = Contact::magicLink($helper["url"]);
264 $r[] = ["url" => "help/Quick-Start-guide", "name" => DI::l10n()->t("Quick Start")];
266 $tpl = Renderer::getMarkupTemplate('ch_helpers.tpl');
270 $helpers['title'] = ["", DI::l10n()->t('Help'), "", ""];
272 $aside['$helpers_items'] = [];
274 foreach ($r as $rr) {
275 $entry = Renderer::replaceMacros($tpl, [
276 '$url' => $rr['url'],
277 '$title' => $rr['name'],
279 $aside['$helpers_items'][] = $entry;
282 $aside['$helpers'] = $helpers;
287 // connectable services
288 if ($show_services) {
289 /// @TODO This whole thing is hard-coded, better rewrite to Intercepting Filter Pattern (future-todo)
292 if (Addon::isEnabled("buffer")) {
293 $r[] = ["photo" => "images/buffer.png", "name" => "Buffer"];
296 if (Addon::isEnabled("blogger")) {
297 $r[] = ["photo" => "images/blogger.png", "name" => "Blogger"];
300 if (Addon::isEnabled("dwpost")) {
301 $r[] = ["photo" => "images/dreamwidth.png", "name" => "Dreamwidth"];
304 if (Addon::isEnabled("ifttt")) {
305 $r[] = ["photo" => "addon/ifttt/ifttt.png", "name" => "IFTTT"];
308 if (Addon::isEnabled("statusnet")) {
309 $r[] = ["photo" => "images/gnusocial.png", "name" => "GNU Social"];
312 /// @TODO old-lost code (and below)?
313 //if (Addon::isEnabled("ijpost")) {
314 // $r[] = array("photo" => "images/", "name" => "");
317 if (Addon::isEnabled("libertree")) {
318 $r[] = ["photo" => "images/libertree.png", "name" => "Libertree"];
321 //if (Addon::isEnabled("ljpost")) {
322 // $r[] = array("photo" => "images/", "name" => "");
325 if (Addon::isEnabled("pumpio")) {
326 $r[] = ["photo" => "images/pumpio.png", "name" => "pump.io"];
329 if (Addon::isEnabled("tumblr")) {
330 $r[] = ["photo" => "images/tumblr.png", "name" => "Tumblr"];
333 if (Addon::isEnabled("twitter")) {
334 $r[] = ["photo" => "images/twitter.png", "name" => "Twitter"];
337 if (Addon::isEnabled("wppost")) {
338 $r[] = ["photo" => "images/wordpress.png", "name" => "Wordpress"];
341 if (function_exists("imap_open") && !Config::get("system", "imap_disabled") && !Config::get("system", "dfrn_only")) {
342 $r[] = ["photo" => "images/mail.png", "name" => "E-Mail"];
345 $tpl = Renderer::getMarkupTemplate('ch_connectors.tpl');
347 if (DBA::isResult($r)) {
349 $con_services['title'] = ["", DI::l10n()->t('Connect Services'), "", ""];
350 $aside['$con_services'] = $con_services;
352 foreach ($r as $rr) {
353 $entry = Renderer::replaceMacros($tpl, [
355 '$photo' => $rr['photo'],
356 '$alt_text' => $rr['name'],
358 $aside['$connector_items'][] = $entry;
362 //end connectable services
365 $tpl = Renderer::getMarkupTemplate('communityhome.tpl');
366 DI::page()['right_aside'] = Renderer::replaceMacros($tpl, $aside);