]> git.mxchange.org Git - friendica.git/blob - view/theme/frio/theme.php
Merge pull request #2605 from rabuzarus/1306-aside-group-fix
[friendica.git] / view / theme / frio / theme.php
1 <?php
2 /*
3  * Name: frio
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>.
5  * Version: V.0.2 Alpha
6  * Author: Rabuzarus <https://friendica.kommune4.de/profile/rabuzarus>
7  * 
8  */
9
10 $frio = "view/theme/frio";
11
12 global $frio;
13
14 function frio_init(&$a) {
15         set_template_engine($a, 'smarty3');
16
17         $baseurl = $a->get_baseurl();
18
19         $style = get_pconfig(local_user(), 'frio', 'style');
20
21         $frio = "view/theme/frio";
22
23         global $frio;
24
25         // if the device is a mobile device set js is_mobile
26         // variable so the js scripts can use this information
27         if($a->is_mobile || $a->is_tablet) {
28                 $a->page["htmlhead"] .= <<< EOT
29                         <script>
30                                 var is_mobile = 1;
31                         </script>
32 EOT;
33                         }
34
35         if ($style == "")
36                 $style = get_config('frio', 'style');
37 }
38
39 function frio_install() {
40         register_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
41         register_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
42         register_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
43         register_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
44         register_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
45
46         logger("installed theme frio");
47 }
48
49 function frio_uninstall() {
50         unregister_hook('prepare_body_final', 'view/theme/frio/theme.php', 'frio_item_photo_links');
51         unregister_hook('item_photo_menu', 'view/theme/frio/theme.php', 'frio_item_photo_menu');
52         unregister_hook('contact_photo_menu', 'view/theme/frio/theme.php', 'frio_contact_photo_menu');
53         unregister_hook('nav_info', 'view/theme/frio/theme.php', 'frio_remote_nav');
54         unregister_hook('acl_lookup_end', 'view/theme/frio/theme.php', 'frio_acl_lookup');
55
56         logger("uninstalled theme frio");
57 }
58 /**
59  * @brief Replace friendica photo links
60  * 
61  *  This function does replace the links to photos
62  *  of other friendica users. Original the photos are
63  *  linked to the photo page. Now they will linked directly
64  *  to the photo file. This function is nessesary to use colorbox
65  *  in the network stream
66  * 
67  * @param App $a
68  * @param array $body_info The item and its html output
69  */
70 function frio_item_photo_links(&$a, &$body_info) {
71         require_once('include/Photo.php');
72
73         $phototypes = Photo::supportedTypes();
74         $occurence = 1;
75         $p = bb_find_open_close($body_info['html'], "<a", ">");
76
77         while($p !== false && ($occurence++ < 500)) {
78                 $link = substr($body_info['html'], $p['start'], $p['end'] - $p['start']);
79                 $matches = array();
80
81                 preg_match("/\/photos\/[\w]+\/image\/([\w]+)/", $link, $matches);
82                 if($matches) {
83                         // Replace the link for the photo's page with a direct link to the photo itself
84                         $newlink = str_replace($matches[0], "/photo/{$matches[1]}", $link);
85
86                         // Add a "quiet" parameter to any redir links to prevent the "XX welcomes YY" info boxes
87                         $newlink = preg_replace("/href=\"([^\"]+)\/redir\/([^\"]+)&url=([^\"]+)\"/", 'href="$1/redir/$2&quiet=1&url=$3"', $newlink);
88
89                          // Having any arguments to the link for Colorbox causes it to fetch base64 code instead of the image
90                         $newlink = preg_replace("/\/[?&]zrl=([^&\"]+)/", '', $newlink);
91
92                         $body_info['html'] = str_replace($link, $newlink, $body_info['html']);
93                 }
94
95                 $p = bb_find_open_close($body_info['html'], "<a", ">", $occurence);
96         }
97 }
98
99 /**
100  * @brief Replace links of the item_photo_menu
101  * 
102  *  This function replaces the original poke and the message links
103  *  to call the addToModal javascript function so this pages can
104  *  be loaded in a bootstrap modal
105  * 
106  * @param app $a The app data
107  * @param array $arr Contains item data and the original photo_menu
108  */
109 function frio_item_photo_menu($a, &$arr){
110
111         foreach($arr["menu"] as $k =>$v) {
112                 if(strpos($v,'poke/?f=&c=') === 0 || strpos($v,'message/new/') === 0) {
113                         $v = "javascript:addToModal('" . $v . "'); return false;";
114                         $arr["menu"][$k] = $v;
115                 }
116         }
117         $args = array('item' => $item, 'menu' => $menu);
118 }
119
120 /**
121  * @brief Replace links of the contact_photo_menu
122  * 
123  *  This function replaces the original poke and the message links
124  *  to call the addToModal javascript function so this pages can
125  *  be loaded in a bootstrap modal
126  *  Additionally the profile, status and photo page links  will be changed
127  *  to don't open in a new tab if the contact is a friendica contact.
128  * 
129  * @param app $a The app data
130  * @param array $args Contains contact data and the original photo_menu
131  */
132 function frio_contact_photo_menu($a, &$args){
133
134         $pokelink = "";
135         $pmlink = "";
136         $cid = "";
137
138         $cid = $args["contact"]["id"];
139         $pokelink = $args["menu"]["poke"][1];
140         $pmlink = $args["menu"]["pm"][1];
141
142         // Set the the indicator for opening the status, profile and photo pages
143         // in a new tab to false if the contact a dfrn (friendica) contact
144         // We do this because we can go back on foreign friendica pages throuhg
145         // friendicas "magic-link" which indicates a friendica user on froreign
146         // friendica servers as remote user or visitor
147         //
148         // The value for opening in a new tab is e.g. when 
149         // $args["menu"]["status"][2] is true. If the value of the [2] key is true
150         // and if it's a friendica contact we set it to false
151         foreach($args["menu"] as $k =>$v) {
152                 if($k === "status" || $k === "profile" || $k === "photos") {
153                         $v[2] = (($args["contact"]["network"] === "dfrn") ? false : true);
154                         $args["menu"][$k][2] = $v[2];
155                 }
156         }
157
158         // Add to pm and poke links a new key with the value 'modal'.
159         // Later we can make conditions in the corresponing templates (e.g.
160         // contact_template.tpl)
161         if(strpos($pokelink,'poke/?f=&c='. $cid) !== false)
162                 $args["menu"]["poke"][3] = "modal";
163
164         if(strpos($pmlink,'message/new/' . $cid) !== false)
165                 $args["menu"]["pm"][3] = "modal";
166
167         $args = array('contact' => $contact, 'menu' => &$menu);
168 }
169
170 /**
171  * @brief Construct remote nav menu
172  * 
173  *  It creates a remote baseurl form $_SESSION for remote users and friendica
174  *  visitors. This url will be added to some of the nav links. With this behaviour 
175  *  the user will come back to her/his own pages on his/her friendica server.
176  *  Not all possible links are available (notifications, administrator, manage,
177  *  notes aren't available because we have no way the check remote permissions)..
178  *  Some links will point to the local pages because the user would expect
179  *  local page (these pages are: search, community, help, apps, directory).
180  * 
181  * @param app $a The App class
182  * @param array $nav The original nav menu
183  */
184 function frio_remote_nav($a,&$nav) {
185         // get the homelink from $_XSESSION
186         $homelink = get_my_url();
187         if(! $homelink)
188                 $homelink = ((x($_SESSION,'visitor_home')) ? $_SESSION['visitor_home'] : '');
189
190         // split up the url in it's parts (protocol,domain/directory, /profile/, nickname
191         // I'm not familiar with regex, so someone might find a better solutionen
192         // 
193         // E.g $homelink = 'https://friendica.domain.com/profile/mickey' should result in an array
194         // with 0 => 'https://friendica.domain.com/profile/mickey' 1 => 'https://',
195         // 2 => 'friendica.domain.com' 3 => '/profile/' 4 => 'mickey'
196         // 
197         //$server_url = preg_match('/^(https?:\/\/.*?)\/profile\//2', $homelink);
198         preg_match('/^(https?:\/\/)?(.*?)(\/profile\/)(.*)/', $homelink, $url_parts);
199
200         // Construct the server url of the visitor. So we could link back to his/her own menu.
201         // And construct a webbie (e.g. mickey@friendica.domain.com for the search in gcontact
202         // We use the webbie for search in gcontact because we don't know if gcontact table stores
203         // the right value if its http or https protocol
204         if(count($url_parts)) {
205                 $server_url = $url_parts[1] . $url_parts[2];
206                 $webbie = $url_parts[4] . '@' . $url_parts[2];
207         }
208
209         // since $userinfo isn't available for the hook we write it to the nav array
210         // this isn't optimal because the contact query will be done now twice
211         if(local_user()) {
212                 // empty the server url for local user because we won't need it
213                 $server_url = '';
214                 // user info
215                 $r = q("SELECT `micro` FROM `contact` WHERE `uid` = %d AND `self` = 1", intval($a->user['uid']));
216                 
217                 $r[0]['photo'] = (count($r) ? $a->remove_baseurl($r[0]['micro']) : "images/person-48.jpg");
218                 $r[0]['name'] = $a->user['username'];
219
220         } elseif(!local_user() && remote_user()) {
221                 $r = q("SELECT `name`, `nick`, `micro` AS `photo` FROM `contact` WHERE `id` = %d", intval(remote_user()));
222                 $nav['remote'] = t("Remote");
223
224         } elseif(get_my_url ()) {
225                 $r = q("SELECT `name`, `nick`, `photo` FROM `gcontact`
226                                 WHERE `addr` = '%s' AND `network` = 'dfrn'",
227                         dbesc($webbie));
228                 $nav['remote'] = t("Visitor");
229         }
230
231         if(count($r)){
232                         $nav['userinfo'] = array(
233                                 'icon' => (count($r) ? $r[0]['photo'] : "images/person-48.jpg"),
234                                 'name' => $r[0]['name'],
235                         );
236                 }
237
238         if(!local_user() && !empty($server_url)) {
239                 $nav['logout'] = Array($server_url . '/logout',t('Logout'), "", t('End this session'));
240
241                 // user menu
242                 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname'], t('Status'), "", t('Your posts and conversations'));
243                 $nav['usermenu'][] = Array($server_url . '/profile/' . $a->user['nickname']. '?tab=profile', t('Profile'), "", t('Your profile page'));
244                 $nav['usermenu'][] = Array($server_url . '/photos/' . $a->user['nickname'], t('Photos'), "", t('Your photos'));
245                 $nav['usermenu'][] = Array($server_url . '/videos/' . $a->user['nickname'], t('Videos'), "", t('Your videos'));
246                 $nav['usermenu'][] = Array($server_url . '/events/', t('Events'), "", t('Your events'));
247
248                 // navbar links
249                 $nav['network'] = array($server_url . '/network', t('Network'), "", t('Conversations from your friends'));
250                 $nav['events'] = Array($server_url . '/events', t('Events'), "", t('Events and Calendar'));
251                 $nav['messages'] = array($server_url . '/message', t('Messages'), "", t('Private mail'));
252                 $nav['settings'] = array($server_url . '/settings', t('Settings'),"", t('Account settings'));
253                 $nav['contacts'] = array($server_url . '/contacts', t('Contacts'),"", t('Manage/edit friends and contacts'));
254                 $nav['sitename'] = $a->config['sitename'];
255         }
256 }
257 /**
258  * @brief: Search for contacts
259  * 
260  * This function search for a users contacts. The code is copied from contact search
261  * in /mod/contacts.php. With this function the contacts will permitted to acl_lookup()
262  * and can grabbed as json. For this we use the type="r". This is usful to to let js 
263  * grab the contact data.
264  * We use this to give the data to textcomplete and have a filter function at the
265  * contact page.
266  * 
267  * @param App $a The app data
268  * @param array $results The array with the originals from acl_lookup()
269  */
270 function frio_acl_lookup($a, &$results) {
271         require_once("mod/contacts.php");
272
273         $nets = ((x($_GET,"nets")) ? notags(trim($_GET["nets"])) : "");
274
275         // we introduce a new search type, r should do the same query like it's
276         // done in /mod/contacts for connections
277         if($results["type"] == "r") {
278                 $searching = false;
279                 if($search) {
280                         $search_hdr = $search;
281                         $search_txt = dbesc(protect_sprintf(preg_quote($search)));
282                         $searching = true;
283                 }
284                 $sql_extra .= (($searching) ? " AND (`attag` LIKE '%%".dbesc($search_txt)."%%' OR `name` LIKE '%%".dbesc($search_txt)."%%' OR `nick` LIKE '%%".dbesc($search_txt)."%%') " : "");
285
286                 if($nets)
287                         $sql_extra .= sprintf(" AND network = '%s' ", dbesc($nets));
288
289                 $sql_extra2 = ((($sort_type > 0) && ($sort_type <= CONTACT_IS_FRIEND)) ? sprintf(" AND `rel` = %d ",intval($sort_type)) : '');
290
291
292                 $r = q("SELECT COUNT(*) AS `total` FROM `contact`
293                         WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 ",
294                         intval($_SESSION['uid']));
295                 if(count($r)) {
296                         $total = $r[0]["total"];
297                 }
298
299                 $sql_extra3 = unavailable_networks();
300
301                 $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 0 AND `pending` = 0 $sql_extra $sql_extra2 $sql_extra3 ORDER BY `name` ASC LIMIT 100 ",
302                         intval($_SESSION['uid'])
303                 );
304
305                 $contacts = array();
306
307                 if(count($r)) {
308                         foreach($r as $rr) {
309                                 $contacts[] = _contact_detail_for_template($rr);
310                         }
311                 }
312
313                 $results["items"] = $contacts;
314                 $results["tot"] = $total;
315         }
316 }