Add language meta info and minor restructuring of code

This commit is contained in:
Daniel Winzen
2020-10-17 11:58:39 +02:00
parent 8df28af021
commit ede3d7938d

View File

@ -33,14 +33,14 @@
*/ */
// initialize and load variables/configuration // initialize and load variables/configuration
load_config();
$I=[];// Translations $I=[];// Translations
$L=[];// Languages $L=[];// Languages
$U=[];// This user data $U=[];// This user data
$db;// Database connection $db = null;// Database connection
$memcached;// Memcached connection $memcached = null;// Memcached connection
$language;// user selected language $language = LANG;// user selected language
$styles = []; //css styles $styles = []; //css styles
load_config();
// set session variable to cookie if cookies are enabled // set session variable to cookie if cookies are enabled
if(!isset($_REQUEST['session']) && isset($_COOKIE[COOKIENAME])){ if(!isset($_REQUEST['session']) && isset($_COOKIE[COOKIENAME])){
$_REQUEST['session']=$_COOKIE[COOKIENAME]; $_REQUEST['session']=$_COOKIE[COOKIENAME];
@ -309,7 +309,7 @@ function credit(){
} }
function meta_html(){ function meta_html(){
return '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="Pragma" content="no-cache"><meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate, max-age=0, private"><meta http-equiv="expires" content="0"><meta name="referrer" content="no-referrer">'; return '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta name="referrer" content="no-referrer">';
} }
function form($action, $do=''){ function form($action, $do=''){
@ -349,14 +349,14 @@ function thr(){
} }
function print_start($class='', $ref=0, $url=''){ function print_start($class='', $ref=0, $url=''){
global $I; global $I, $language;
prepare_stylesheets($class === 'init'); prepare_stylesheets($class === 'init');
send_headers(); send_headers();
if(!empty($url)){ if(!empty($url)){
$url=str_replace('&amp;', '&', $url);// Don't escape "&" in URLs here, it breaks some (older) browsers and js refresh! $url=str_replace('&amp;', '&', $url);// Don't escape "&" in URLs here, it breaks some (older) browsers and js refresh!
header("Refresh: $ref; URL=$url"); header("Refresh: $ref; URL=$url");
} }
echo '<!DOCTYPE html><html><head>'.meta_html(); echo '<!DOCTYPE html><html lang="'.$language.'"><head>'.meta_html();
if(!empty($url)){ if(!empty($url)){
echo "<meta http-equiv=\"Refresh\" content=\"$ref; URL=$url\">"; echo "<meta http-equiv=\"Refresh\" content=\"$ref; URL=$url\">";
} }
@ -1401,7 +1401,7 @@ function send_frameset(){
global $I, $U, $db, $language; global $I, $U, $db, $language;
prepare_stylesheets(); prepare_stylesheets();
send_headers(); send_headers();
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"><html><head>'.meta_html(); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"><html lang="'.$language.'"><head>'.meta_html();
echo '<title>'.get_setting('chatname').'</title>'; echo '<title>'.get_setting('chatname').'</title>';
print_stylesheet(); print_stylesheet();
echo '</head>'; echo '</head>';
@ -2140,10 +2140,10 @@ function send_error($err){
} }
function send_fatal_error($err){ function send_fatal_error($err){
global $I, $styles; global $I, $language, $styles;
prepare_stylesheets(); prepare_stylesheets();
send_headers(); send_headers();
echo '<!DOCTYPE html><html><head>'.meta_html(); echo '<!DOCTYPE html><html lang="'.$language.'"><head>'.meta_html();
echo "<title>$I[fatalerror]</title>"; echo "<title>$I[fatalerror]</title>";
echo "<style type=\"text/css\">$styles[fatal_error]</style>"; echo "<style type=\"text/css\">$styles[fatal_error]</style>";
echo '</head><body>'; echo '</head><body>';
@ -2241,6 +2241,7 @@ function check_captcha($challenge, $captcha_code){
if(empty($challenge)){ if(empty($challenge)){
send_error($I['wrongcaptcha']); send_error($I['wrongcaptcha']);
} }
$code = '';
if(MEMCACHED){ if(MEMCACHED){
if(!$code=$memcached->get(DBNAME . '-' . PREFIX . "captcha-$_REQUEST[challenge]")){ if(!$code=$memcached->get(DBNAME . '-' . PREFIX . "captcha-$_REQUEST[challenge]")){
send_error($I['captchaexpire']); send_error($I['captchaexpire']);
@ -2266,13 +2267,13 @@ function check_captcha($challenge, $captcha_code){
} }
function is_definitely_ssl() { function is_definitely_ssl() {
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') { if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
return true; return true;
} }
if (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) { if (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) {
return true; return true;
} }
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ('https' == $_SERVER['HTTP_X_FORWARDED_PROTO'])) { if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ('https' === $_SERVER['HTTP_X_FORWARDED_PROTO'])) {
return true; return true;
} }
return false; return false;
@ -2280,7 +2281,7 @@ function is_definitely_ssl() {
function set_secure_cookie($name, $value){ function set_secure_cookie($name, $value){
if (version_compare(PHP_VERSION, '7.3.0') >= 0) { if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
setcookie($name, $value, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => is_definitely_ssl(), 'httponly'=>true, 'samesite' => 'Strict']); setcookie($name, $value, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => is_definitely_ssl(), 'httponly' => true, 'samesite' => 'Strict']);
}else{ }else{
setcookie($name, $value, 0, '/', '', is_definitely_ssl(), true); setcookie($name, $value, 0, '/', '', is_definitely_ssl(), true);
} }