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