config.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* Wifi Hotspot app for YunoHost
  3. * Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  4. * Contribute at https://github.com/jvaubourg/hotspot_ynh
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. // Limonade configuration
  20. function configure() {
  21. option('env', ENV_PRODUCTION);
  22. option('debug', false);
  23. option('base_uri', '<TPL:NGINX_LOCATION>/');
  24. layout("layout.html.php");
  25. define('PUBLIC_DIR', '<TPL:NGINX_LOCATION>/public');
  26. }
  27. // Not found page
  28. function not_found($errno, $errstr, $errfile=null, $errline=null) {
  29. $msg = h(rawurldecode($errstr));
  30. return render($msg, 'error_layout.html.php');
  31. }
  32. function T_($string) {
  33. return gettext($string);
  34. }
  35. // Before routing
  36. function before($route) {
  37. $lang_mapping = array(
  38. 'fr' => 'fr_FR'
  39. );
  40. /**
  41. * * Locale
  42. * */
  43. if (!isset($_SESSION['locale'])) {
  44. $locale = explode(',',$_SERVER['HTTP_ACCEPT_LANGUAGE']);
  45. $_SESSION['locale'] = strtolower(substr(chop($locale[0]),0,2));
  46. }
  47. $lang = $_SESSION['locale'];
  48. // Convert simple language code into full language code
  49. if (array_key_exists($lang, $lang_mapping)) {
  50. $lang = $lang_mapping[$lang];
  51. }
  52. $lang = $lang.'.utf8';
  53. $textdomain="localization";
  54. putenv('LANGUAGE='.$lang);
  55. putenv('LANG='.$lang);
  56. putenv('LC_ALL='.$lang);
  57. putenv('LC_MESSAGES='.$lang);
  58. setlocale(LC_ALL,$lang);
  59. setlocale(LC_CTYPE,$lang);
  60. $locales_dir = dirname(__FILE__).'/i18n';
  61. bindtextdomain($textdomain,$locales_dir);
  62. bind_textdomain_codeset($textdomain, 'UTF-8');
  63. textdomain($textdomain);
  64. // Set the $locale variable in template
  65. set('locale', $lang);
  66. }
  67. // After routing
  68. function after($output, $route) {
  69. /*
  70. $time = number_format( (float)substr(microtime(), 0, 10) - LIM_START_MICROTIME, 6);
  71. $output .= "\n<!-- page rendered in $time sec., on ".date(DATE_RFC822)." -->\n";
  72. $output .= "<!-- for route\n";
  73. $output .= print_r($route, true);
  74. $output .= "-->";
  75. */
  76. return $output;
  77. }