MastodonHelp/web/clitools/populangs.php

67 lines
2.4 KiB
PHP
Raw Normal View History

2020-05-08 18:03:11 +02:00
#!/usr/bin/php
2020-03-24 23:22:07 +01:00
<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2020-10-21 15:26:31 +02:00
require(__DIR__.'/../site/mustard/include/mb_ucfirst.php');
2020-04-07 19:39:06 +02:00
2020-03-24 23:22:07 +01:00
define('N',"\n");
use function mysqli_real_escape_string as myesc;
2020-10-18 06:53:27 +02:00
$inifp=__DIR__.'/../conf/mustard.ini';
2020-03-24 23:22:07 +01:00
$iniarr=@parse_ini_file($inifp)
or mexit('Impossibile aprire il file di configurazione «'.$inifp.'»'.N,1);
$link=@mysqli_connect($iniarr['db_host'],$iniarr['db_admin_name'],$iniarr['db_admin_password'],$iniarr['db_name'],$iniarr['db_port'],$iniarr['db_socket'])
or mexit('Impossibile connettersi al server MySQL: '.mysqli_connect_error().N,1);
mysqli_set_charset($link,'utf8mb4')
or mexit(mysqli_error($link).N,1);
$localesfp='locales.json';
$locales=@file_get_contents($localesfp);
if ($locales===false)
mexit('Non ho potuto aprire il file «'.$localesfp.'».'.N,1);
$locales=json_decode($locales,true);
print_r($locales);
2020-10-13 14:41:55 +02:00
//mexit('Ecco.'.N,1);
2020-03-24 23:22:07 +01:00
foreach ($locales as $key=>$val) {
$code=myesc($link,$key);
2020-04-21 12:35:53 +02:00
$NameOrig=myesc($link,mb_ucfirst(locale_get_display_name($key,$key)));
$NameCa=myesc($link,mb_ucfirst(locale_get_display_name($key,'ca')));
2020-04-07 19:39:06 +02:00
$NameEn=myesc($link,mb_ucfirst(locale_get_display_name($key,'en')));
$NameEs=myesc($link,mb_ucfirst(locale_get_display_name($key,'es')));
$NameFr=myesc($link,mb_ucfirst(locale_get_display_name($key,'fr')));
2020-04-21 12:35:53 +02:00
$NameIt=myesc($link,mb_ucfirst(locale_get_display_name($key,'it')));
$que='INSERT INTO Languages (ID, Code, NameOrig, NameCA, NameEN, NameES, NameFR, NameIT) VALUES (NULL, \''.$code.'\', \''.$NameOrig.'\', \''.$NameCa.'\', \''.$NameEn.'\', \''.$NameEs.'\', \''.$NameFr.'\', \''.$NameIt.'\')';
2020-03-24 23:22:07 +01:00
echo($que.N);
mysqli_query($link,$que)
or mexit(mysqli_error($link).N,2);
}
mysqli_close($link);
exit(0);
function mexit($msg,$rv) {
global $link;
if ($link)
mysqli_close($link);
echo($msg);
exit($rv);
}
?>