templating.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /* GNU FM -- a free network service for sharing your music listening habits
  3. Copyright (C) 2009, 2015 Free Software Foundation, Inc
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. require_once('config.php');
  16. require_once('auth.php');
  17. function displayError($error_title, $error_message) {
  18. global $smarty;
  19. $smarty->assign('pagetitle', $error_title);
  20. $smarty->assign('pageheading', $error_title); #librefm theme compat, may be removed after switch to BS3 theme
  21. $smarty->assign('error_message', $error_message);
  22. $smarty->display('error.tpl');
  23. die();
  24. }
  25. if (isset($_GET['lang'])) {
  26. $languages = array($_GET['lang'] . '.UTF-8');
  27. setcookie('lang', $_GET['lang'] . '.UTF-8', time() + 31536000, '/');
  28. } else if (isset($_COOKIE['lang'])) {
  29. $languages = array($_COOKIE['lang']);
  30. } else {
  31. // Attempt to mangle browser language strings in to valid gettext locales (needs a big lookup table to be 100% accurate)
  32. $languages = preg_split('/,/', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
  33. for ($i = 0; $i < count($languages); $i++) {
  34. $languages[$i] = preg_replace('/;q=\d\.\d/', '', $languages[$i]);
  35. if (strlen($languages[$i]) == 2) {
  36. $languages[$i] = $languages[$i] . '_' . strtoupper($languages[$i]);
  37. } else if (stristr($languages[$i], '-')) {
  38. $lcomponents = preg_split('/-/', $languages[$i]);
  39. $languages[$i] = $lcomponents[0] . '_' . strtoupper($lcomponents[1]);
  40. }
  41. $languages[$i] = $languages[$i] . '.UTF-8';
  42. }
  43. }
  44. $current_lang = setlocale(LC_ALL, $languages);
  45. if(isset($_GET['mobile']) && $_GET['mobile']) {
  46. $theme = 'mobile';
  47. } else {
  48. $theme = $default_theme;
  49. }
  50. bindtextdomain('nixtape', $install_path . '/themes/' . $theme . '/locale/');
  51. textdomain('nixtape');
  52. $smarty = new Smarty();
  53. $smarty->setTemplateDir(array(
  54. $install_path . '/themes/'. $theme . '/templates/',
  55. $install_path . '/themes/gnufm/templates/'
  56. ));
  57. $smarty->setPluginsDir(array(
  58. __DIR__ . '/vendor/smarty/smarty/libs/plugins/',
  59. $install_path. '/themes/' . $theme . '/plugins/',
  60. $install_path . '/themes/gnufm/plugins/'
  61. ));
  62. $smarty->setCompileDir($install_path . '/themes/' . $theme . '/templates_c/');
  63. $smarty->setCacheDir($install_path . '/cache/');
  64. $smarty->setConfigDir(array($install_path . '/themes/' . $theme . '/config/',
  65. $install_path . '/themes/gnufm/config/'));
  66. $current_lang = preg_replace('/.UTF-8/', '', $current_lang);
  67. $smarty->assign('lang_selector_array', array(($current_lang) => 1));
  68. $smarty->assign('base_url', $base_url);
  69. $smarty->assign('gnufm_key', $gnufm_key);
  70. $smarty->assign('default_theme', $default_theme);
  71. $smarty->assign('site_name', $site_name);
  72. $smarty->assign('img_url', $base_url . '/themes/' . $theme . '/img/');
  73. $smarty->assign('this_page', $_SERVER['REQUEST_URI']);
  74. $smarty->assign('this_page_absolute',
  75. (empty($_SERVER['HTTPS']) ? 'http://' : 'http://')
  76. . (empty($_SERVER['HOST']) ? $_SERVER['SERVER_NAME'] : $_SERVER['HOST'])
  77. . (($_SERVER['SERVER_PORT'] == 80) ? '' : (':' . $_SERVER['SERVER_PORT']))
  78. . $_SERVER['REQUEST_URI']);
  79. $smarty->assign('registration_disabled', $registration_disabled);
  80. if (isset($logged_in) && $logged_in) {
  81. $smarty->assign('logged_in', true);
  82. // Pre-fix this user's details with 'this_' to avoid confusion with other users
  83. $smarty->assign('this_user', $this_user);
  84. }
  85. header('Content-Type: text/html; charset=utf-8');