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\Core\Config;
12 use Friendica\Core\PConfig;
13 use Friendica\Core\System;
15 $frio = "view/theme/frio";
19 function frio_init(App $a) {
21 // disable the events module link in the profile tab
22 $a->theme_events_in_profile = false;
24 set_template_engine($a, 'smarty3');
26 $baseurl = System::baseUrl();
28 $style = PConfig::get(local_user(), 'frio', 'style');
30 $frio = "view/theme/frio";
34 // if the device is a mobile device set js is_mobile
35 // variable so the js scripts can use this information
36 if($a->is_mobile || $a->is_tablet) {
37 $a->page["htmlhead"] .= <<< EOT
38 <script type="text/javascript">
45 $style = Config::get('frio', 'style');
48 function frio_install() {
49 register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
50 register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
51 register_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
52 register_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
53 register_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
54 register_hook('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
56 logger("installed theme frio");
59 function frio_uninstall() {
60 unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
61 unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
62 unregister_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
63 unregister_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
64 unregister_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
65 unregister_hook('display_item', 'view/theme/frio/theme.php', 'frio_display_item');
67 logger("uninstalled theme frio");
70 * @brief Replace friendica photo links hook
72 * This function does replace the links to photos
73 * of other friendica users. Original the photos are
74 * linked to the photo page. Now they will linked directly
75 * to the photo file. This function is nessesary to use colorbox
76 * in the network stream
78 * @param App $a Unused but required by hook definition
79 * @param array $body_info The item and its html output
81 function frio_item_photo_links(App $a, &$body_info) {
82 require_once('include/Photo.php');
84 $phototypes = Photo::supportedTypes();
86 $p = bb_find_open_close($body_info['html'], "<a", ">");
88 while($p !== false && ($occurence++ < 500)) {
89 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
92 preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
94 // Replace the link for the photo's page with a direct link to the photo itself
95 $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
97 // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
98 $newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
100 // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
101 $newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
103 $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
106 $p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
111 * @brief Replace links of the item_photo_menu hook
113 * This function replaces the original poke and the message links
114 * to call the addToModal javascript function so this pages can
115 * be loaded in a bootstrap modal
117 * @param App $a Unused but required by the hook definition
118 * @param array $arr Contains item data and the original photo_menu
120 function frio_item_photo_menu(App $a, &$arr) {
122 foreach($arr["menu"] as $k =>$v) {
123 if(strpos($v,'poke/?f=&c=') === 0 || strpos($v,'message/new/') === 0) {
124 $v = "javascript:addToModal('" . $v . "'); return false;";
125 $arr["menu"][$k] = $v;
128 $args = array('item' => $item, 'menu' => $menu);
132 * @brief Replace links of the contact_photo_menu
134 * This function replaces the original poke and the message links
135 * to call the addToModal javascript function so this pages can
136 * be loaded in a bootstrap modal
137 * Additionally the profile, status and photo page links will be changed
138 * to don't open in a new tab if the contact is a friendica contact.
140 * @param App $a The app data
141 * @param array $args Contains contact data and the original photo_menu
143 function frio_contact_photo_menu(App $a, &$args){
149 $cid = $args["contact"]["id"];
150 $pokelink = $args["menu"]["poke"][1];
151 $pmlink = $args["menu"]["pm"][1];
153 // Set the the indicator for opening the status, profile and photo pages
154 // in a new tab to false if the contact a dfrn (friendica) contact
155 // We do this because we can go back on foreign friendica pages throuhg
156 // friendicas "magic-link" which indicates a friendica user on froreign
157 // friendica servers as remote user or visitor
159 // The value for opening in a new tab is e.g. when
160 // $args["menu"]["status"][2] is true. If the value of the [2] key is true
161 // and if it's a friendica contact we set it to false
162 foreach($args["menu"] as $k =>$v) {
163 if($k === "status" || $k === "profile" || $k === "photos") {
164 $v[2] = (($args["contact"]["network"] === "dfrn") ? false : true);
165 $args["menu"][$k][2] = $v[2];
169 // Add to pm and poke links a new key with the value 'modal'.
170 // Later we can make conditions in the corresponing templates (e.g.
171 // contact_template.tpl)
172 if(strpos($pokelink,'poke/?f=&c='. $cid) !== false)
173 $args["menu"]["poke"][3] = "modal";
175 if(strpos($pmlink,'message/new/' . $cid) !== false)
176 $args["menu"]["pm"][3] = "modal";
178 $args = array('contact' => $contact, 'menu' => &$menu);
182 * @brief Construct remote nav menu
184 * It creates a remote baseurl form $_SESSION for remote users and friendica
185 * visitors. This url will be added to some of the nav links. With this behaviour
186 * the user will come back to her/his own pages on his/her friendica server.
187 * Not all possible links are available (notifications, administrator, manage,
188 * notes aren't available because we have no way the check remote permissions)..
189 * Some links will point to the local pages because the user would expect
190 * local page (these pages are: search, community, help, apps, directory).
192 * @param App $a The App class
193 * @param array $nav The original nav menu
195 function frio_remote_nav($a,&$nav) {
196 // get the homelink from $_XSESSION
197 $homelink = get_my_url();
199 $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
201 // split up the url in it's parts (protocol,domain/directory, /profile/, nickname
202 // I'm not familiar with regex, so someone might find a better solutionen
204 // E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
205 // with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
206 // 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
208 //$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
209 preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
211 // Construct the server url of the visitor. So we could link back to his/her own menu.
212 // And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
213 // We use the webbie for search in gcontact because we don't know if gcontact table stores
214 // the right value if its http or https protocol
215 if(count($url_parts)) {
216 $server_url = $url_parts[1] . $url_parts[2];
217 $webbie = $url_parts[4] . '@' . $url_parts[2];
220 // since $userinfo isn't available for the hook we write it to the nav array
221 // this isn't optimal because the contact query will be done now twice
223 // empty the server url for local user because we won't need it
226 $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self`", intval($a->user['uid']));
228 $r[0]['photo'] = (dbm::is_result($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
229 $r[0]['name'] = $a->user['username'];
231 } elseif (!local_user() && remote_user()) {
232 $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
233 $nav['remote'] = t("Guest");
235 } elseif (get_my_url()) {
236 $r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
237 WHERE `addr` = '%s' AND `network` = 'dfrn'",
239 $nav['remote'] = t("Visitor");
244 if (dbm::is_result($r)) {
245 $nav['userinfo'] = array(
246 'icon' => (dbm::is_result($r) ? $r[0]['photo'] : "images/person-48.jpg"),
247 'name' => $r[0]['name'],
251 if (!local_user() && !empty($server_url)) {
252 $nav['logout'] = Array($server_url . '/logout', t('Logout'), "", t('End this session'));
255 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations'));
256 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
257 $nav['usermenu'][] = Array($server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
258 $nav['usermenu'][] = Array($server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos'));
259 $nav['usermenu'][] = Array($server_url . '/events/', t('Events'), "", t('Your events'));
262 $nav['network'] = array($server_url . '/network', t('Network'), "", t('Conversations from your friends'));
263 $nav['events'] = Array($server_url . '/events', t('Events'), "", t('Events and Calendar'));
264 $nav['messages'] = array($server_url . '/message', t('Messages'), "", t('Private mail'));
265 $nav['settings'] = array($server_url . '/settings', t('Settings'),"", t('Account settings'));
266 $nav['contacts'] = array($server_url . '/contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
267 $nav['sitename'] = $a->config['sitename'];
271 * @brief: Search for contacts
273 * This function search for a users contacts. The code is copied from contact search
274 * in /mod/contacts.php. With this function the contacts will permitted to acl_lookup()
275 * and can grabbed as json. For this we use the type="r". This is usful to to let js
276 * grab the contact data.
277 * We use this to give the data to textcomplete and have a filter function at the
280 * @param App $a The app data @TODO Unused
281 * @param array $results The array with the originals from acl_lookup()
283 function frio_acl_lookup(App $a, &$results) {
284 require_once("mod/contacts.php");
286 $nets = ((x($_GET,"nets")) ? notags(trim($_GET["nets"])) : "");
288 // we introduce a new search type, r should do the same query like it's
289 // done in /mod/contacts for connections
290 if ($results["type"] == "r") {
293 $search_hdr = $search;
294 $search_txt = dbesc(protect_sprintf(preg_quote($search)));
297 $sql_extra .= (($searching) ? " AND (`attag` LIKE '%%".dbesc($search_txt)."%%' OR `name` LIKE '%%".dbesc($search_txt)."%%' OR `nick` LIKE '%%".dbesc($search_txt)."%%') " : "");
300 $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
303 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
306 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
307 WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 ",
308 intval($_SESSION['uid']));
309 if (dbm::is_result($r)) {
310 $total = $r[0]["total"];
313 $sql_extra3 = unavailable_networks();
315 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND NOT `self` AND NOT `pending` $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT 100 ",
316 intval($_SESSION['uid'])
321 if (dbm::is_result($r)) {
322 foreach ($r as $rr) {
323 $contacts[] = _contact_detail_for_template($rr);
327 $results["items"] = $contacts;
328 $results["tot"] = $total;
333 * @brief Manipulate the data of the item
335 * At the moment we use this function to add some own stuff to the item menu
337 * @param App $a App $a The app data
338 * @param array $arr Array with the item and the item actions<br>
339 * 'item' => Array with item data<br>
340 * 'output' => Array with item actions<br>
342 function frio_display_item(App $a,&$arr) {
344 // Add subthread to the item menu
345 $subthread = array();
346 if ((local_user()) && local_user() == $arr['item']['uid'] && $arr['item']['parent'] == $arr['item']['id'] && (! $arr['item']['self'])) {
348 'menu' => 'follow_thread',
349 'title' => t('Follow Thread'),
350 'action' => 'dosubthread(' . $arr['item']['id'] . '); return false;',
354 $arr['output']['subthread'] = $subthread;