From 468ca37cc04a1b2c7f098b5fa6e079b3276e3e09 Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Sun, 25 Aug 2024 13:45:53 +0200 Subject: [PATCH] =?UTF-8?q?Now=20the=20logic=20to=20set=20the=20language?= =?UTF-8?q?=20for=20instances=20to=20be=20returned=20by=20default=20to=20t?= =?UTF-8?q?he=20browser=E2=80=99s=20one=20is=20autonomous=20from=20the=20o?= =?UTF-8?q?ne=20to=20set=20the=20locale=20for=20text=20translation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/site/instances.php | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/web/site/instances.php b/web/site/instances.php index cd921ad..d1afced 100644 --- a/web/site/instances.php +++ b/web/site/instances.php @@ -361,23 +361,26 @@ function presub() { $_GET['exlcko']=0; } + $res=tquery('SELECT Languages.ID AS Lid, Code, CONCAT(Name'.$dlanguc.', \' [\', Code, \'] (\', COUNT(Languages.ID), \')\') AS Txt FROM InstOurLangs LEFT JOIN Instances ON Instances.ID=InstOurLangs.InstID LEFT JOIN Languages ON Languages.ID=OurLangID WHERE InstOurLangs.Pos=1 AND Instances.IsMastodon=1 AND Instances.Visible=1 AND Instances.LastOkCheckTS>='.$graceline.' GROUP BY Languages.ID ORDER BY Languages.Name'.$dlanguc.' ASC',__LINE__); + while ($row=mysqli_fetch_assoc($res)) + $sellangs[$row['Code']]=$row; if (array_key_exists('lang',$_GET)) { if (preg_match('#^[0-9]+$#',$_GET['lang'])===1) - $_GET['lang']=$_GET['lang']+0; + ($_GET['lang']+0>5000000) ? $get['lang']=0 : $_GET['lang']=$_GET['lang']+0; else $_GET['lang']=0; } else { - $res=tquery('SELECT ID FROM Languages WHERE Code="'.myesc($link,$dlang).'"',__LINE__); - if (mysqli_num_rows($res)>0) { - $row=mysqli_fetch_assoc($res); - $_GET['lang']=$row['ID']; - } else { - $_GET['lang']=0; - } + foreach ($langs as $key=>$val) + if (array_key_exists($key,$sellangs)) { + debug('LANG: '.$key.N,$debug); + $_GET['lang']=$sellangs[$key]['Lid']; + break; + } + if (!isset($_GET['lang'])) + $_GET['lang']=$sellangs['en']['Lid']; } - if ($_GET['lang']>5000000000) $_GET['lang']=0; - if (array_key_exists('desc',$_GET) && preg_match('#^.+$#',$_GET['lang'])===1) + if (array_key_exists('desc',$_GET) && preg_match('#^.+$#',$_GET['desc'])===1) $_GET['desc']=trim(n2es($_GET['desc'])); else $_GET['desc']=''; @@ -447,9 +450,7 @@ function presub() {