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