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