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/rabuzarus/frio/blob/master/README.md">ReadMe</a> and <a href="https://github.com/rabuzarus/frio">GitHub</a>.
6 * Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus>
10 $frio = "view/theme/frio";
14 function frio_init(&$a) {
15 set_template_engine($a, 'smarty3');
17 $baseurl = $a->get_baseurl();
19 $style = get_pconfig(local_user(), 'frio', 'style');
21 $frio = "view/theme/frio";
29 $style = get_config('frio', 'style');
32 function frio_install() {
33 register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
34 register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
35 register_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
36 register_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
38 logger("installed theme frio");
41 function frio_uninstall() {
42 unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
43 unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
44 unregister_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
46 logger("uninstalled theme frio");
49 * @brief Replace friendica photo links
51 * This function does replace the links to photos
52 * of other friendica users. Original the photos are
53 * linked to the photo page. Now they will linked directly
54 * to the photo file. This function is nessesary to use colorbox
55 * in the network stream
58 * @param array $body_info The item and its html output
60 function frio_item_photo_links(&$a, &$body_info) {
61 require_once('include/Photo.php');
63 $phototypes = Photo::supportedTypes();
65 $p = bb_find_open_close($body_info['html'], "<a", ">");
67 while($p !== false && ($occurence++ < 500)) {
68 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
71 preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
73 // Replace the link for the photo's page with a direct link to the photo itself
74 $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
76 // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
77 $newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
79 // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
80 $newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
82 $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
85 $p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
90 * @brief Replace links of the item_photo_menu
92 * This function replaces the original poke and the message links
93 * to call the addToModal javascript function so this pages can
94 * be loaded in a bootstrap modal
96 * @param app $a The app data
97 * @param array $arr Contains item data and the original photo_menu
99 function frio_item_photo_menu($a, &$arr){
101 foreach($arr["menu"] as $k =>$v) {
102 if(strpos($v,'poke/?f=&c=') === 0 || strpos($v,'message/new/') === 0) {
103 $v = "javascript:addToModal('" . $v . "'); return false;";
104 $arr["menu"][$k] = $v;
107 $args = array('item' => $item, 'menu' => $menu);
111 * @brief Replace links of the contact_photo_menu
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
116 * Additionally the profile, status and photo page links will be changed
117 * to don't open in a new tab if the contact is a friendica contact.
119 * @param app $a The app data
120 * @param array $args Contains contact data and the original photo_menu
122 function frio_contact_photo_menu($a, &$args){
128 $cid = $args["contact"]["id"];
129 $pokelink = $args["menu"]["poke"][1];
130 $pmlink = $args["menu"]["pm"][1];
132 // Set the the indicator for opening the status, profile and photo pages
133 // in a new tab to false if the contact a dfrn (friendica) contact
134 // We do this because we can go back on foreign friendica pages throuhg
135 // friendicas "magic-link" which indicates a friendica user on froreign
136 // friendica servers as remote user or visitor
138 // The value for opening in a new tab is e.g. when
139 // $args["menu"]["status"][2] is true. If the value of the [2] key is true
140 // and if it's a friendica contact we set it to false
141 foreach($args["menu"] as $k =>$v) {
142 if($k === "status" || $k === "profile" || $k === "photos") {
143 $v[2] = (($args["contact"]["network"] === "dfrn") ? false : true);
144 $args["menu"][$k][2] = $v[2];
148 // Add to pm and poke links a new key with the value 'modal'.
149 // Later we can make conditions in the corresponing templates (e.g.
150 // contact_template.tpl)
151 if(strpos($pokelink,'poke/?f=&c='. $cid) !== false)
152 $args["menu"]["poke"][3] = "modal";
154 if(strpos($pmlink,'message/new/' . $cid) !== false)
155 $args["menu"]["pm"][3] = "modal";
157 $args = array('contact' => $contact, 'menu' => &$menu);
161 * @brief Construct remote nav menu
163 * It creates a remote baseurl form $_SESSION for remote users and friendica
164 * visitors. This url will be added to some of the nav links. With this behaviour
165 * the user will come back to her/his own pages on his/her friendica server.
166 * Not all possible links are available (notifications, administrator, manage,
167 * notes aren't available because we have no way the check remote permissions)..
168 * Some links will point to the local pages because the user would expect
169 * local page (these pages are: search, community, help, apps, directory).
171 * @param app $a The App class
172 * @param array $nav The original nav menu
174 function frio_remote_nav($a,&$nav) {
175 // get the homelink from $_XSESSION
176 $homelink = get_my_url();
178 $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
180 // split up the url in it's parts (protocol,domain/directory, /profile/, nickname
181 // I'm not familiar with regex, so someone might find a better solutionen
183 // E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
184 // with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
185 // 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
187 //$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
188 preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
190 // Construct the server url of the visitor. So we could link back to his/her own menu.
191 // And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
192 // We use the webbie for search in gcontact because we don't know if gcontact table stores
193 // the right value if its http or https protocol
194 if(count($url_parts)) {
195 $server_url = $url_parts[1] . $url_parts[2];
196 $webbie = $url_parts[4] . '@' . $url_parts[2];
199 // since $userinfo isn't available for the hook we write it to the nav array
200 // this isn't optimal because the contact query will be done now twice
202 // empty the server url for local user because we won't need it
205 $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self` = 1", intval($a->user['uid']));
207 $r[0]['photo'] = (count($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
208 $r[0]['name'] = $a->user['username'];
210 } elseif(!local_user() && remote_user()) {
211 $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
212 $nav['remote'] = t("Remote");
214 } elseif(get_my_url ()) {
215 $r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
216 WHERE `addr` = '%s' AND `network` = 'dfrn'",
218 $nav['remote'] = t("Visitor");
222 $nav['userinfo'] = array(
223 'icon' => (count($r) ? $r[0]['photo'] : "images/person-48.jpg"),
224 'name' => $r[0]['name'],
228 if(!local_user() && !empty($server_url)) {
229 $nav['logout'] = Array($server_url . '/logout',t('Logout'), "", t('End this session'));
232 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations'));
233 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
234 $nav['usermenu'][] = Array($server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
235 $nav['usermenu'][] = Array($server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos'));
236 $nav['usermenu'][] = Array($server_url . '/events/', t('Events'), "", t('Your events'));
239 $nav['network'] = array($server_url . '/network', t('Network'), "", t('Conversations from your friends'));
240 $nav['events'] = Array($server_url . '/events', t('Events'), "", t('Events and Calendar'));
241 $nav['messages'] = array($server_url . '/message', t('Messages'), "", t('Private mail'));
242 $nav['settings'] = array($server_url . '/settings', t('Settings'),"", t('Account settings'));
243 $nav['contacts'] = array($server_url . '/contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
244 $nav['sitename'] = $a->config['sitename'];