4 * 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>.
6 * Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus>
11 use Friendica\Content\Text\Plaintext;
12 use Friendica\Content\Widget;
13 use Friendica\Core\Addon;
14 use Friendica\Core\Config;
15 use Friendica\Core\L10n;
16 use Friendica\Core\PConfig;
17 use Friendica\Core\System;
18 use Friendica\Database\DBA;
19 use Friendica\Model\Profile;
21 $frio = 'view/theme/frio';
25 function frio_init(App $a)
27 // disable the events module link in the profile tab
28 $a->theme_events_in_profile = false;
31 $a->set_template_engine('smarty3');
33 $baseurl = System::baseUrl();
35 $style = PConfig::get(local_user(), 'frio', 'style');
37 $frio = 'view/theme/frio';
41 // if the device is a mobile device set js is_mobile
42 // variable so the js scripts can use this information
43 if ($a->is_mobile || $a->is_tablet) {
44 $a->page['htmlhead'] .= <<< EOT
45 <script type="text/javascript">
52 $style = Config::get('frio', 'style');
56 function frio_install()
58 Addon::registerHook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
59 Addon::registerHook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
60 Addon::registerHook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
61 Addon::registerHook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
62 Addon::registerHook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
63 Addon::registerHook('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
65 logger('installed theme frio');
68 function frio_uninstall()
70 Addon::unregisterHook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
71 Addon::unregisterHook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
72 Addon::unregisterHook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
73 Addon::unregisterHook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
74 Addon::unregisterHook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
75 Addon::unregisterHook('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
77 logger('uninstalled theme frio');
81 * @brief Replace friendica photo links hook
83 * This function does replace the links to photos
84 * of other friendica users. Original the photos are
85 * linked to the photo page. Now they will linked directly
86 * to the photo file. This function is nessesary to use colorbox
87 * in the network stream
89 * @param App $a Unused but required by hook definition
90 * @param array $body_info The item and its html output
92 function frio_item_photo_links(App $a, &$body_info)
95 $p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>');
96 while ($p !== false && ($occurence++ < 500)) {
97 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
100 preg_match('/\/photos\/[\w]+\/image\/([\w]+)/', $link, $matches);
102 // Replace the link for the photo's page with a direct link to the photo itself
103 $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
105 // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
106 $newlink = preg_replace('/href="([^"]+)\/redir\/([^"]+)&url=([^"]+)"/', 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
108 // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
109 $newlink = preg_replace('/\/[?&]zrl=([^&"]+)/', '', $newlink);
111 $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
114 $p = Plaintext::getBoundariesPosition($body_info['html'], '<a', '>', $occurence);
119 * @brief Replace links of the item_photo_menu hook
121 * This function replaces the original poke and the message links
122 * to call the addToModal javascript function so this pages can
123 * be loaded in a bootstrap modal
125 * @param App $a Unused but required by the hook definition
126 * @param array $arr Contains item data and the original photo_menu
128 function frio_item_photo_menu(App $a, &$arr)
130 foreach ($arr['menu'] as $k => $v) {
131 if (strpos($v, 'poke/?f=&c=') === 0 || strpos($v, 'message/new/') === 0) {
132 $v = 'javascript:addToModal(\'' . $v . '\'); return false;';
133 $arr['menu'][$k] = $v;
139 * @brief Replace links of the contact_photo_menu
141 * This function replaces the original poke and the message links
142 * to call the addToModal javascript function so this pages can
143 * be loaded in a bootstrap modal
144 * Additionally the profile, status and photo page links will be changed
145 * to don't open in a new tab if the contact is a friendica contact.
147 * @param App $a The app data
148 * @param array $args Contains contact data and the original photo_menu
150 function frio_contact_photo_menu(App $a, &$args)
152 $cid = $args['contact']['id'];
154 if (!empty($args['menu']['poke'])) {
155 $pokelink = $args['menu']['poke'][1];
160 if (!empty($args['menu']['poke'])) {
161 $pmlink = $args['menu']['pm'][1];
166 // Set the the indicator for opening the status, profile and photo pages
167 // in a new tab to false if the contact a dfrn (friendica) contact
168 // We do this because we can go back on foreign friendica pages throuhg
169 // friendicas "magic-link" which indicates a friendica user on froreign
170 // friendica servers as remote user or visitor
172 // The value for opening in a new tab is e.g. when
173 // $args['menu']['status'][2] is true. If the value of the [2] key is true
174 // and if it's a friendica contact we set it to false
175 foreach ($args['menu'] as $k => $v) {
176 if ($k === 'status' || $k === 'profile' || $k === 'photos') {
177 $v[2] = (($args['contact']['network'] === 'dfrn') ? false : true);
178 $args['menu'][$k][2] = $v[2];
182 // Add to pm and poke links a new key with the value 'modal'.
183 // Later we can make conditions in the corresponing templates (e.g.
184 // contact_template.tpl)
185 if (strpos($pokelink, 'poke/?f=&c=' . $cid) !== false) {
186 $args['menu']['poke'][3] = 'modal';
189 if (strpos($pmlink, 'message/new/' . $cid) !== false) {
190 $args['menu']['pm'][3] = 'modal';
195 * @brief Construct remote nav menu
197 * It creates a remote baseurl form $_SESSION for remote users and friendica
198 * visitors. This url will be added to some of the nav links. With this behaviour
199 * the user will come back to her/his own pages on his/her friendica server.
200 * Not all possible links are available (notifications, administrator, manage,
201 * notes aren't available because we have no way the check remote permissions)..
202 * Some links will point to the local pages because the user would expect
203 * local page (these pages are: search, community, help, apps, directory).
205 * @param App $a The App class
206 * @param array $nav The original nav menu
208 function frio_remote_nav($a, &$nav)
210 // get the homelink from $_XSESSION
211 $homelink = Profile::getMyURL();
213 $homelink = defaults($_SESSION, 'visitor_home', '');
216 // split up the url in it's parts (protocol,domain/directory, /profile/, nickname
217 // I'm not familiar with regex, so someone might find a better solutionen
219 // E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
220 // with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
221 // 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
223 //$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
224 preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
226 // Construct the server url of the visitor. So we could link back to his/her own menu.
227 // And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
228 // We use the webbie for search in gcontact because we don't know if gcontact table stores
229 // the right value if its http or https protocol
231 if (count($url_parts)) {
232 $server_url = $url_parts[1] . $url_parts[2];
233 $webbie = $url_parts[4] . '@' . $url_parts[2];
236 // since $userinfo isn't available for the hook we write it to the nav array
237 // this isn't optimal because the contact query will be done now twice
239 // empty the server url for local user because we won't need it
242 $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self`", intval($a->user['uid']));
244 $r[0]['photo'] = (DBA::isResult($r) ? $a->remove_baseurl($r[0]['micro']) : 'images/person-48.jpg');
245 $r[0]['name'] = $a->user['username'];
246 } elseif (!local_user() && remote_user()) {
247 $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
248 $nav['remote'] = L10n::t('Guest');
249 } elseif (Profile::getMyURL()) {
250 $r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
251 WHERE `addr` = '%s' AND `network` = 'dfrn'",
252 DBA::escape($webbie));
253 $nav['remote'] = L10n::t('Visitor');
258 if (DBA::isResult($r)) {
260 'icon' => (DBA::isResult($r) ? $r[0]['photo'] : 'images/person-48.jpg'),
261 'name' => $r[0]['name'],
265 if (!local_user() && !empty($server_url)) {
266 $nav['logout'] = [$server_url . '/logout', L10n::t('Logout'), '', L10n::t('End this session')];
269 $nav['usermenu'][] = [$server_url . '/profile/' . $a->user['nickname'], L10n::t('Status'), '', L10n::t('Your posts and conversations')];
270 $nav['usermenu'][] = [$server_url . '/profile/' . $a->user['nickname'] . '?tab=profile', L10n::t('Profile'), '', L10n::t('Your profile page')];
271 $nav['usermenu'][] = [$server_url . '/photos/' . $a->user['nickname'], L10n::t('Photos'), '', L10n::t('Your photos')];
272 $nav['usermenu'][] = [$server_url . '/videos/' . $a->user['nickname'], L10n::t('Videos'), '', L10n::t('Your videos')];
273 $nav['usermenu'][] = [$server_url . '/events/', L10n::t('Events'), '', L10n::t('Your events')];
276 $nav['network'] = [$server_url . '/network', L10n::t('Network'), '', L10n::t('Conversations from your friends')];
277 $nav['events'] = [$server_url . '/events', L10n::t('Events'), '', L10n::t('Events and Calendar')];
278 $nav['messages'] = [$server_url . '/message', L10n::t('Messages'), '', L10n::t('Private mail')];
279 $nav['settings'] = [$server_url . '/settings', L10n::t('Settings'), '', L10n::t('Account settings')];
280 $nav['contacts'] = [$server_url . '/contacts', L10n::t('Contacts'), '', L10n::t('Manage/edit friends and contacts')];
281 $nav['sitename'] = Config::get('config', 'sitename');
286 * @brief: Search for contacts
288 * This function search for a users contacts. The code is copied from contact search
289 * in /mod/contacts.php. With this function the contacts will permitted to acl_lookup()
290 * and can grabbed as json. For this we use the type="r". This is usful to to let js
291 * grab the contact data.
292 * We use this to give the data to textcomplete and have a filter function at the
295 * @param App $a The app data @TODO Unused
296 * @param array $results The array with the originals from acl_lookup()
298 function frio_acl_lookup(App $a, &$results)
300 require_once 'mod/contacts.php';
302 $nets = x($_GET, 'nets') ? notags(trim($_GET['nets'])) : '';
304 // we introduce a new search type, r should do the same query like it's
305 // done in /mod/contacts for connections
306 if ($results['type'] !== 'r') {
311 if ($results['search']) {
312 $search_txt = DBA::escape(protect_sprintf(preg_quote($results['search'])));
313 $sql_extra .= " AND (`attag` LIKE '%%" . $search_txt . "%%' OR `name` LIKE '%%" . $search_txt . "%%' OR `nick` LIKE '%%" . $search_txt . "%%') ";
317 $sql_extra .= sprintf(" AND network = '%s' ", DBA::escape($nets));
321 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
322 WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra ", intval($_SESSION['uid']));
323 if (DBA::isResult($r)) {
324 $total = $r[0]['total'];
327 $sql_extra3 = Widget::unavailableNetworks();
329 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra3 ORDER BY `name` ASC LIMIT %d, %d ",
330 intval($_SESSION['uid']), intval($results['start']), intval($results['count'])
335 if (DBA::isResult($r)) {
336 foreach ($r as $rr) {
337 $contacts[] = _contact_detail_for_template($rr);
341 $results['items'] = $contacts;
342 $results['tot'] = $total;
346 * @brief Manipulate the data of the item
348 * At the moment we use this function to add some own stuff to the item menu
350 * @param App $a App $a The app data
351 * @param array $arr Array with the item and the item actions<br>
352 * 'item' => Array with item data<br>
353 * 'output' => Array with item actions<br>
355 function frio_display_item(App $a, &$arr)
357 // Add subthread to the item menu
361 && local_user() == $arr['item']['uid']
362 && $arr['item']['parent'] == $arr['item']['id']
363 && !$arr['item']['self'])
366 'menu' => 'follow_thread',
367 'title' => L10n::t('Follow Thread'),
368 'action' => 'dosubthread(' . $arr['item']['id'] . '); return false;',
372 $arr['output']['subthread'] = $subthread;