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\Core\Session;
33 use Friendica\Database\DBA;
36 use Friendica\Model\Contact;
38 use Friendica\Util\Strings;
40 const FRIO_SCHEME_ACCENT_BLUE = '#1e87c2';
41 const FRIO_SCHEME_ACCENT_RED = '#b50404';
42 const FRIO_SCHEME_ACCENT_PURPLE = '#a54bad';
43 const FRIO_SCHEME_ACCENT_GREEN = '#218f39';
44 const FRIO_SCHEME_ACCENT_PINK = '#d900a9';
47 * This script can be included even when the app is in maintenance mode which requires us to avoid any config call
50 function frio_init(App $a)
53 $frio = 'view/theme/frio';
55 // disable the events module link in the profile tab
56 $a->setThemeInfoValue('events_in_profile', false);
57 $a->setThemeInfoValue('videowidth', 622);
59 Renderer::setActiveTemplateEngine('smarty3');
61 // if the device is a mobile device set js is_mobile
62 // variable so the js scripts can use this information
63 if (DI::mode()->isMobile() || DI::mode()->isMobile()) {
64 DI::page()['htmlhead'] .= <<< EOT
65 <script type="text/javascript">
72 function frio_install()
74 Hook::register('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
75 Hook::register('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
76 Hook::register('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
77 Hook::register('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
78 Hook::register('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
80 Logger::info('installed theme frio');
84 * Replace friendica photo links hook
86 * This function does replace the links to photos
87 * of other friendica users. Original the photos are
88 * linked to the photo page. Now they will linked directly
89 * to the photo file. This function is nessesary to use colorbox
90 * in the network stream
92 * @param App $a Unused but required by hook definition
93 * @param array $body_info The item and its html output
95 function frio_item_photo_links(App $a, &$body_info)
98 $p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>');
99 while ($p !== false && ($occurence++ < 500)) {
100 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
103 preg_match('/\/photos\/[\w]+\/image\/([\w]+)/', $link, $matches);
105 // Replace the link for the photo's page with a direct link to the photo itself
106 $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
108 // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
109 $newlink = preg_replace('/href="([^"]+)\/redir\/([^"]+)&url=([^"]+)"/', 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
111 // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
112 $newlink = preg_replace('/\/[?&]zrl=([^&"]+)/', '', $newlink);
114 $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
117 $p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>', $occurence);
122 * Replace links of the item_photo_menu hook
124 * This function replaces the original message links
125 * to call the addToModal javascript function so this pages can
126 * be loaded in a bootstrap modal
128 * @param App $a Unused but required by the hook definition
129 * @param array $arr Contains item data and the original photo_menu
131 function frio_item_photo_menu(App $a, &$arr)
133 foreach ($arr['menu'] as $k => $v) {
134 if (strpos($v, 'message/new/') === 0) {
135 $v = 'javascript:addToModal(\'' . $v . '\'); return false;';
136 $arr['menu'][$k] = $v;
142 * Replace links of the contact_photo_menu
144 * This function replaces the original message link
145 * to call the addToModal javascript function so this pages can
146 * be loaded in a bootstrap modal
147 * Additionally the profile, status and photo page links will be changed
148 * to don't open in a new tab if the contact is a friendica contact.
150 * @param App $a The app data
151 * @param array $args Contains contact data and the original photo_menu
153 function frio_contact_photo_menu(App $a, &$args)
155 $cid = $args['contact']['id'];
157 if (!empty($args['menu']['pm'])) {
158 $pmlink = $args['menu']['pm'][1];
163 // Set the the indicator for opening the status, profile and photo pages
164 // in a new tab to false if the contact a dfrn (friendica) contact
165 // We do this because we can go back on foreign friendica pages throuhg
166 // friendicas "magic-link" which indicates a friendica user on froreign
167 // friendica servers as remote user or visitor
169 // The value for opening in a new tab is e.g. when
170 // $args['menu']['status'][2] is true. If the value of the [2] key is true
171 // and if it's a friendica contact we set it to false
172 foreach ($args['menu'] as $k => $v) {
173 if ($k === 'status' || $k === 'profile' || $k === 'photos') {
174 $v[2] = (($args['contact']['network'] === 'dfrn') ? false : true);
175 $args['menu'][$k][2] = $v[2];
179 // Add to pm link a new key with the value 'modal'.
180 // Later we can make conditions in the corresponding templates (e.g.
181 // contact_template.tpl)
182 if (strpos($pmlink, 'message/new/' . $cid) !== false) {
183 $args['menu']['pm'][3] = 'modal';
188 * Construct remote nav menu
190 * It creates a remote baseurl form $_SESSION for remote users and friendica
191 * visitors. This url will be added to some of the nav links. With this behaviour
192 * the user will come back to her/his own pages on his/her friendica server.
193 * Not all possible links are available (notifications, administrator, manage,
194 * notes aren't available because we have no way the check remote permissions)..
195 * Some links will point to the local pages because the user would expect
196 * local page (these pages are: search, community, help, apps, directory).
198 * @param App $a The App class
199 * @param array $nav_info The original nav info array: nav, banner, userinfo, sitelocation
202 function frio_remote_nav(App $a, array &$nav_info)
204 if (DI::mode()->has(App\Mode::MAINTENANCEDISABLED)) {
205 // get the homelink from $_SESSION
206 $homelink = Model\Profile::getMyURL();
208 $homelink = Session::get('visitor_home', '');
211 // since $userinfo isn't available for the hook we write it to the nav array
212 // this isn't optimal because the contact query will be done now twice
213 $fields = ['id', 'url', 'avatar', 'micro', 'name', 'nick', 'baseurl', 'updated'];
214 if ($a->isLoggedIn()) {
215 $remoteUser = Contact::selectFirst($fields, ['uid' => $a->getLoggedInUserId(), 'self' => true]);
216 } elseif (!local_user() && remote_user()) {
217 $remoteUser = Contact::getById(remote_user(), $fields);
218 $nav_info['nav']['remote'] = DI::l10n()->t('Guest');
219 } elseif (Model\Profile::getMyURL()) {
220 $remoteUser = Contact::getByURL($homelink, null, $fields);
221 $nav_info['nav']['remote'] = DI::l10n()->t('Visitor');
226 if (DBA::isResult($remoteUser)) {
227 $nav_info['userinfo'] = [
228 'icon' => Contact::getMicro($remoteUser),
229 'name' => $remoteUser['name'],
231 $server_url = $remoteUser['baseurl'];
234 if (!local_user() && !empty($server_url) && !is_null($remoteUser)) {
236 $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'], DI::l10n()->t('Status'), '', DI::l10n()->t('Your posts and conversations')];
237 $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '/profile', DI::l10n()->t('Profile'), '', DI::l10n()->t('Your profile page')];
238 $nav_info['nav']['usermenu'][] = [$server_url . '/photos/' . $remoteUser['nick'], DI::l10n()->t('Photos'), '', DI::l10n()->t('Your photos')];
239 $nav_info['nav']['usermenu'][] = [$server_url . '/profile/' . $remoteUser['nick'] . '/media', DI::l10n()->t('Media'), '', DI::l10n()->t('Your postings with media')];
240 $nav_info['nav']['usermenu'][] = [$server_url . '/events/', DI::l10n()->t('Events'), '', DI::l10n()->t('Your events')];
243 $nav_info['nav']['network'] = [$server_url . '/network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')];
244 $nav_info['nav']['events'] = [$server_url . '/events', DI::l10n()->t('Events'), '', DI::l10n()->t('Events and Calendar')];
245 $nav_info['nav']['messages'] = [$server_url . '/message', DI::l10n()->t('Messages'), '', DI::l10n()->t('Private mail')];
246 $nav_info['nav']['settings'] = [$server_url . '/settings', DI::l10n()->t('Settings'), '', DI::l10n()->t('Account settings')];
247 $nav_info['nav']['contacts'] = [$server_url . '/contact', DI::l10n()->t('Contacts'), '', DI::l10n()->t('Manage/edit friends and contacts')];
248 $nav_info['nav']['sitename'] = DI::config()->get('config', 'sitename');
253 function frio_display_item(App $a, &$arr)
255 // Add follow to the item menu
259 && in_array($arr['item']['uid'], [0, local_user()])
260 && $arr['item']['gravity'] == GRAVITY_PARENT
261 && !$arr['item']['self']
262 && !$arr['item']['mention']
265 'menu' => 'follow_thread',
266 'title' => DI::l10n()->t('Follow Thread'),
267 'action' => 'doFollowThread(' . $arr['item']['id'] . ');',
271 $arr['output']['follow_thread'] = $followThread;