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