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/>.
21 * Description: Bootstrap V3 theme. The theme is currently under construction, so it is far from finished. For further information have a look at the <a href="https://github.com/friendica/friendica/tree/develop/view/theme/frio/README.md">ReadMe</a>.
23 * Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus>
27 use Friendica\Content\Text\Plaintext;
28 use Friendica\Content\Widget;
29 use Friendica\Core\Hook;
30 use Friendica\Core\Logger;
31 use Friendica\Core\Renderer;
32 use Friendica\Database\DBA;
35 use Friendica\Model\Item;
36 use Friendica\Model\Contact;
37 use Friendica\Model\Profile;
39 use Friendica\Util\Strings;
41 const FRIO_SCHEME_ACCENT_BLUE = '#1e87c2';
42 const FRIO_SCHEME_ACCENT_RED = '#b50404';
43 const FRIO_SCHEME_ACCENT_PURPLE = '#a54bad';
44 const FRIO_SCHEME_ACCENT_GREEN = '#218f39';
45 const FRIO_SCHEME_ACCENT_PINK = '#d900a9';
48 * This script can be included even when the app is in maintenance mode which requires us to avoid any config call
51 function frio_init(App $a)
54 $frio = 'view/theme/frio';
56 // disable the events module link in the profile tab
57 $a->setThemeInfoValue('events_in_profile', false);
58 $a->setThemeInfoValue('videowidth', 622);
60 Renderer::setActiveTemplateEngine('smarty3');
62 // if the device is a mobile device set js is_mobile
63 // variable so the js scripts can use this information
64 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
65 DI::page()['htmlhead'] .= <<< EOT
66 <script type="text/javascript">
73 function frio_install()
75 Hook::register('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
76 Hook::register('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
77 Hook::register('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
78 Hook::register('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
79 Hook::register('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
81 Logger::info('installed theme frio');
85 * Replace friendica photo links hook
87 * This function does replace the links to photos
88 * of other friendica users. Original the photos are
89 * linked to the photo page. Now they will linked directly
90 * to the photo file. This function is nessesary to use colorbox
91 * in the network stream
93 * @param App $a Unused but required by hook definition
94 * @param array $body_info The item and its html output
96 function frio_item_photo_links(App $a, &$body_info)
99 $p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>');
100 while ($p !== false && ($occurence++ < 500)) {
101 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
104 preg_match('/\/photos\/[\w]+\/image\/([\w]+)/', $link, $matches);
106 // Replace the link for the photo's page with a direct link to the photo itself
107 $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
109 // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
110 $newlink = preg_replace('/href="([^"]+)\/redir\/([^"]+)&url=([^"]+)"/', 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
112 // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
113 $newlink = preg_replace('/\/[?&]zrl=([^&"]+)/', '', $newlink);
115 $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
118 $p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>', $occurence);
123 * Replace links of the item_photo_menu hook
125 * This function replaces the original message links
126 * to call the addToModal javascript function so this pages can
127 * be loaded in a bootstrap modal
129 * @param App $a Unused but required by the hook definition
130 * @param array $arr Contains item data and the original photo_menu
132 function frio_item_photo_menu(App $a, &$arr)
134 foreach ($arr['menu'] as $k => $v) {
135 if (strpos($v, 'message/new/') === 0) {
136 $v = 'javascript:addToModal(\'' . $v . '\'); return false;';
137 $arr['menu'][$k] = $v;
143 * Replace links of the contact_photo_menu
145 * This function replaces the original message link
146 * to call the addToModal javascript function so this pages can
147 * be loaded in a bootstrap modal
148 * Additionally the profile, status and photo page links will be changed
149 * to don't open in a new tab if the contact is a friendica contact.
151 * @param App $a The app data
152 * @param array $args Contains contact data and the original photo_menu
154 function frio_contact_photo_menu(App $a, &$args)
156 $cid = $args['contact']['id'];
158 if (!empty($args['menu']['pm'])) {
159 $pmlink = $args['menu']['pm'][1];
164 // Set the the indicator for opening the status, profile and photo pages
165 // in a new tab to false if the contact a dfrn (friendica) contact
166 // We do this because we can go back on foreign friendica pages throuhg
167 // friendicas "magic-link" which indicates a friendica user on froreign
168 // friendica servers as remote user or visitor
170 // The value for opening in a new tab is e.g. when
171 // $args['menu']['status'][2] is true. If the value of the [2] key is true
172 // and if it's a friendica contact we set it to false
173 foreach ($args['menu'] as $k => $v) {
174 if ($k === 'status' || $k === 'profile' || $k === 'photos') {
175 $v[2] = (($args['contact']['network'] === 'dfrn') ? false : true);
176 $args['menu'][$k][2] = $v[2];
180 // Add to pm link a new key with the value 'modal'.
181 // Later we can make conditions in the corresponding templates (e.g.
182 // contact_template.tpl)
183 if (strpos($pmlink, 'message/new/' . $cid) !== false) {
184 $args['menu']['pm'][3] = 'modal';
189 * Construct remote nav menu
191 * It creates a remote baseurl form $_SESSION for remote users and friendica
192 * visitors. This url will be added to some of the nav links. With this behaviour
193 * the user will come back to her/his own pages on his/her friendica server.
194 * Not all possible links are available (notifications, administrator, manage,
195 * notes aren't available because we have no way the check remote permissions)..
196 * Some links will point to the local pages because the user would expect
197 * local page (these pages are: search, community, help, apps, directory).
199 * @param App $a The App class
200 * @param array $nav_info The original nav info array: nav, banner, userinfo, sitelocation
203 function frio_remote_nav(App $a, array &$nav_info)
205 if (DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
206 // get the homelink from $_SESSION
207 $homelink = Profile::getMyURL();
209 $homelink = DI::session()->get('visitor_home', '');
212 // since $userinfo isn't available for the hook we write it to the nav array
213 // this isn't optimal because the contact query will be done now twice
214 $fields = ['id', 'url', 'avatar', 'micro', 'name', 'nick', 'baseurl', 'updated'];
215 if ($a->isLoggedIn()) {
216 $remoteUser = Contact::selectFirst($fields, ['uid' => $a->getLoggedInUserId(), 'self' => true]);
217 } elseif (!DI::userSession()->getLocalUserId() && DI::userSession()->getRemoteUserId()) {
218 $remoteUser = Contact::getById(DI::userSession()->getRemoteUserId(), $fields);
219 $nav_info['nav']['remote'] = DI::l10n()->t('Guest');
220 } elseif (Profile::getMyURL()) {
221 $remoteUser = Contact::getByURL($homelink, null, $fields);
222 $nav_info['nav']['remote'] = DI::l10n()->t('Visitor');
227 if (DBA::isResult($remoteUser)) {
228 $nav_info['userinfo'] = [
229 'icon' => Contact::getMicro($remoteUser),
230 'name' => $remoteUser['name'],
232 $server_url = $remoteUser['baseurl'];
235 if (!DI::userSession()->getLocalUserId() && !empty($server_url) && !is_null($remoteUser)) {
237 $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
238 $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
239 $nav_info['nav']['usermenu'][] = [$server_url . '/photos/' . $remoteUser['nick'], DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')];
240 $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '/media', DI::l10n()->t('Media'), '', DI::l10n()->t('Your postings with media')];
241 $nav_info['nav']['usermenu'][] = [$server_url . '/calendar/', DI::l10n()->t('Calendar'), '', DI::l10n()->t('Your calendar')];
244 $nav_info['nav']['network'] = [$server_url . '/network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
245 $nav_info['nav']['calendar'] = [$server_url . '/calendar', DI::l10n()->t('Calendar'), '', DI::l10n()->t('Calendar')];
246 $nav_info['nav']['messages'] = [$server_url . '/message', DI::l10n()->t('Messages'), '', DI::l10n()->t('Private mail')];
247 $nav_info['nav']['settings'] = [$server_url . '/settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')];
248 $nav_info['nav']['contacts'] = [$server_url . '/contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')];
249 $nav_info['nav']['sitename'] = DI::config()->get('config', 'sitename');
254 function frio_display_item(App $a, &$arr)
256 // Add follow to the item menu
259 DI::userSession()->getLocalUserId()
260 && in_array($arr['item']['uid'], [0, DI::userSession()->getLocalUserId()])
261 && $arr['item']['gravity'] == Item::GRAVITY_PARENT
262 && !$arr['item']['self']
263 && !$arr['item']['mention']
266 'menu' => 'follow_thread',
267 'title' => DI::l10n()->t('Follow Thread'),
268 'action' => 'doFollowThread(' . $arr['item']['id'] . ');',
272 $arr['output']['follow_thread'] = $followThread;