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>
10 use Friendica\Content\Widget;
11 use Friendica\Core\Config;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\System;
14 use Friendica\Database\DBM;
15 use Friendica\Model\Profile;
16 use Friendica\Object\Image;
18 $frio = "view/theme/frio";
22 function frio_init(App $a)
24 // disable the events module link in the profile tab
25 $a->theme_events_in_profile = false;
28 $a->set_template_engine('smarty3');
30 $baseurl = System::baseUrl();
32 $style = PConfig::get(local_user(), 'frio', 'style');
34 $frio = "view/theme/frio";
38 // if the device is a mobile device set js is_mobile
39 // variable so the js scripts can use this information
40 if ($a->is_mobile || $a->is_tablet) {
41 $a->page["htmlhead"] .= <<< EOT
42 <script type="text/javascript">
49 $style = Config::get('frio', 'style');
53 function frio_install()
55 register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
56 register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
57 register_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
58 register_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
59 register_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
60 register_hook('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
62 logger("installed theme frio");
65 function frio_uninstall()
67 unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
68 unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
69 unregister_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
70 unregister_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
71 unregister_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
72 unregister_hook('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
74 logger("uninstalled theme frio");
78 * @brief Replace friendica photo links hook
80 * This function does replace the links to photos
81 * of other friendica users. Original the photos are
82 * linked to the photo page. Now they will linked directly
83 * to the photo file. This function is nessesary to use colorbox
84 * in the network stream
86 * @param App $a Unused but required by hook definition
87 * @param array $body_info The item and its html output
89 function frio_item_photo_links(App $a, &$body_info)
91 $phototypes = Image::supportedTypes();
93 $p = bb_find_open_close($body_info['html'], "<a", ">");
95 while ($p !== false && ($occurence++ < 500)) {
96 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
99 preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
101 // Replace the link for the photo's page with a direct link to the photo itself
102 $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
104 // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
105 $newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
107 // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
108 $newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
110 $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
113 $p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
118 * @brief Replace links of the item_photo_menu hook
120 * This function replaces the original poke and the message links
121 * to call the addToModal javascript function so this pages can
122 * be loaded in a bootstrap modal
124 * @param App $a Unused but required by the hook definition
125 * @param array $arr Contains item data and the original photo_menu
127 function frio_item_photo_menu(App $a, &$arr)
129 foreach ($arr["menu"] as $k => $v) {
130 if (strpos($v, 'poke/?f=&c=') === 0 || strpos($v, 'message/new/') === 0) {
131 $v = "javascript:addToModal('" . $v . "'); return false;";
132 $arr["menu"][$k] = $v;
138 * @brief Replace links of the contact_photo_menu
140 * This function replaces the original poke and the message links
141 * to call the addToModal javascript function so this pages can
142 * be loaded in a bootstrap modal
143 * Additionally the profile, status and photo page links will be changed
144 * to don't open in a new tab if the contact is a friendica contact.
146 * @param App $a The app data
147 * @param array $args Contains contact data and the original photo_menu
149 function frio_contact_photo_menu(App $a, &$args)
151 $cid = $args["contact"]["id"];
152 $pokelink = $args["menu"]["poke"][1];
153 $pmlink = $args["menu"]["pm"][1];
155 // Set the the indicator for opening the status, profile and photo pages
156 // in a new tab to false if the contact a dfrn (friendica) contact
157 // We do this because we can go back on foreign friendica pages throuhg
158 // friendicas "magic-link" which indicates a friendica user on froreign
159 // friendica servers as remote user or visitor
161 // The value for opening in a new tab is e.g. when
162 // $args["menu"]["status"][2] is true. If the value of the [2] key is true
163 // and if it's a friendica contact we set it to false
164 foreach ($args["menu"] as $k => $v) {
165 if ($k === "status" || $k === "profile" || $k === "photos") {
166 $v[2] = (($args["contact"]["network"] === "dfrn") ? false : true);
167 $args["menu"][$k][2] = $v[2];
171 // Add to pm and poke links a new key with the value 'modal'.
172 // Later we can make conditions in the corresponing templates (e.g.
173 // contact_template.tpl)
174 if (strpos($pokelink, 'poke/?f=&c=' . $cid) !== false) {
175 $args["menu"]["poke"][3] = "modal";
178 if (strpos($pmlink, 'message/new/' . $cid) !== false) {
179 $args["menu"]["pm"][3] = "modal";
184 * @brief Construct remote nav menu
186 * It creates a remote baseurl form $_SESSION for remote users and friendica
187 * visitors. This url will be added to some of the nav links. With this behaviour
188 * the user will come back to her/his own pages on his/her friendica server.
189 * Not all possible links are available (notifications, administrator, manage,
190 * notes aren't available because we have no way the check remote permissions)..
191 * Some links will point to the local pages because the user would expect
192 * local page (these pages are: search, community, help, apps, directory).
194 * @param App $a The App class
195 * @param array $nav The original nav menu
197 function frio_remote_nav($a, &$nav)
199 // get the homelink from $_XSESSION
200 $homelink = Profile::getMyURL();
202 $homelink = defaults($_SESSION, 'visitor_home', '');
205 // split up the url in it's parts (protocol,domain/directory, /profile/, nickname
206 // I'm not familiar with regex, so someone might find a better solutionen
208 // E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
209 // with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
210 // 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
212 //$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
213 preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
215 // Construct the server url of the visitor. So we could link back to his/her own menu.
216 // And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
217 // We use the webbie for search in gcontact because we don't know if gcontact table stores
218 // the right value if its http or https protocol
219 if (count($url_parts)) {
220 $server_url = $url_parts[1] . $url_parts[2];
221 $webbie = $url_parts[4] . '@' . $url_parts[2];
224 // since $userinfo isn't available for the hook we write it to the nav array
225 // this isn't optimal because the contact query will be done now twice
227 // empty the server url for local user because we won't need it
230 $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self`", intval($a->user['uid']));
232 $r[0]['photo'] = (DBM::is_result($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
233 $r[0]['name'] = $a->user['username'];
234 } elseif (!local_user() && remote_user()) {
235 $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
236 $nav['remote'] = t("Guest");
237 } elseif (Profile::getMyURL()) {
238 $r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
239 WHERE `addr` = '%s' AND `network` = 'dfrn'",
241 $nav['remote'] = t("Visitor");
246 if (DBM::is_result($r)) {
248 'icon' => (DBM::is_result($r) ? $r[0]['photo'] : "images/person-48.jpg"),
249 'name' => $r[0]['name'],
253 if (!local_user() && !empty($server_url)) {
254 $nav['logout'] = [$server_url . '/logout', t('Logout'), "", t('End this session')];
257 $nav['usermenu'][] = [$server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations')];
258 $nav['usermenu'][] = [$server_url . '/profile/' . $a->user['nickname'] . '?tab=profile', t('Profile'), "", t('Your profile page')];
259 $nav['usermenu'][] = [$server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos')];
260 $nav['usermenu'][] = [$server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos')];
261 $nav['usermenu'][] = [$server_url . '/events/', t('Events'), "", t('Your events')];
264 $nav['network'] = [$server_url . '/network', t('Network'), "", t('Conversations from your friends')];
265 $nav['events'] = [$server_url . '/events', t('Events'), "", t('Events and Calendar')];
266 $nav['messages'] = [$server_url . '/message', t('Messages'), "", t('Private mail')];
267 $nav['settings'] = [$server_url . '/settings', t('Settings'), "", t('Account settings')];
268 $nav['contacts'] = [$server_url . '/contacts', t('Contacts'), "", t('Manage/edit friends and contacts')];
269 $nav['sitename'] = $a->config['sitename'];
274 * @brief: Search for contacts
276 * This function search for a users contacts. The code is copied from contact search
277 * in /mod/contacts.php. With this function the contacts will permitted to acl_lookup()
278 * and can grabbed as json. For this we use the type="r". This is usful to to let js
279 * grab the contact data.
280 * We use this to give the data to textcomplete and have a filter function at the
283 * @param App $a The app data @TODO Unused
284 * @param array $results The array with the originals from acl_lookup()
286 function frio_acl_lookup(App $a, &$results)
288 require_once 'mod/contacts.php';
290 $nets = x($_GET, "nets") ? notags(trim($_GET["nets"])) : "";
292 // we introduce a new search type, r should do the same query like it's
293 // done in /mod/contacts for connections
294 if ($results["type"] == "r") {
297 $search_hdr = $search;
298 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
303 $sql_extra .= " AND (`attag` LIKE '%%" . dbesc($search_txt) . "%%' OR `name` LIKE '%%" . dbesc($search_txt) . "%%' OR `nick` LIKE '%%" . dbesc($search_txt) . "%%') ";
307 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
310 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
311 WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra ",
312 intval($_SESSION['uid']));
313 if (DBM::is_result($r)) {
314 $total = $r[0]["total"];
317 $sql_extra3 = Widget::unavailableNetworks();
319 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra3 ORDER BY `name` ASC LIMIT 100 ",
320 intval($_SESSION['uid'])
325 if (DBM::is_result($r)) {
326 foreach ($r as $rr) {
327 $contacts[] = _contact_detail_for_template($rr);
331 $results["items"] = $contacts;
332 $results["tot"] = $total;
337 * @brief Manipulate the data of the item
339 * At the moment we use this function to add some own stuff to the item menu
341 * @param App $a App $a The app data
342 * @param array $arr Array with the item and the item actions<br>
343 * 'item' => Array with item data<br>
344 * 'output' => Array with item actions<br>
346 function frio_display_item(App $a, &$arr)
348 // Add subthread to the item menu
350 if (local_user() == $arr['item']['uid'] && $arr['item']['parent'] == $arr['item']['id'] && !$arr['item']['self']) {
352 'menu' => 'follow_thread',
353 'title' => t('Follow Thread'),
354 'action' => 'dosubthread(' . $arr['item']['id'] . '); return false;',
358 $arr['output']['subthread'] = $subthread;