MastodonHelp/web/index.php

273 lines
8.7 KiB
PHP
Raw Normal View History

2019-12-01 09:07:45 +01:00
<?php
2019-12-26 21:57:36 +01:00
define('N',"\n");
2019-12-02 20:16:26 +01:00
2020-05-07 07:24:56 +02:00
function muoribene($msg,$ec) {
echo($msg);
exit($ec);
}
2020-10-13 08:21:26 +02:00
$inifp='sec/mastostart.ini';
2020-05-07 07:24:56 +02:00
$conf=@parse_ini_file($inifp)
or muoribene('Non ho potuto aprire «'.$inifp.'».'.N,1);
if (!array_key_exists('instpath',$conf))
muoribene('«'.$inifp.'»: “instpath” non è definito.'.N,1);
2020-10-13 08:21:26 +02:00
$path=preg_replace('#\?.*$#','',$_SERVER['REQUEST_URI']);
$path=preg_replace('/^'.preg_quote($conf['instpath'],'/').'/','',$path);
2019-12-01 09:07:45 +01:00
$ndir=preg_match_all('/\//',$path)-1;
$prepath='';
for ($i=0; $i<$ndir; $i++)
$prepath.='../';
2020-04-14 07:35:58 +02:00
if (strlen($path)>0) {
while ($path[strlen($path)-1]=='/') {
$path=substr($path,0,-1);
if (strlen($path)<1)
break;
}
}
2020-10-13 08:21:26 +02:00
//echo($_SERVER['HTTP_ACCEPT_LANGUAGE']);die();
2020-04-14 07:35:58 +02:00
$supplangs=['ca','en','es','fr','it'];
if (preg_match('#/('.implode('|',$supplangs).')$#',$path,$lang)===1) {
$dlang=$lang[1];
$path=substr($path,0,-3);
} else {
$dlang=substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
2020-04-16 22:56:12 +02:00
$dlang=in_array($dlang,$supplangs) ? $dlang : 'en';
2020-04-14 07:35:58 +02:00
}
2019-12-01 09:07:45 +01:00
2019-12-02 20:16:26 +01:00
$menu=array(
2020-05-07 07:24:56 +02:00
'guide'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/'.$dlang, 'title'=>'Guide', 'selected'=>false, 'submenu'=>null),
'instances'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/instances/'.$dlang, 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'about'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/about/'.$dlang, 'title'=>'About', 'selected'=>false, 'submenu'=>null),
2019-12-03 21:35:02 +01:00
'language'=>array('liadd'=>null, 'href'=>null, 'title'=>'Language', 'selected'=>false, 'submenu'=>array(
2020-04-14 07:35:58 +02:00
'ca'=>array('liadd'=>'onmouseover="this.style.cursor=\'pointer\'"', 'href'=>null, 'title'=>'Català', 'selected'=>false, 'submenu'=>null),
'en'=>array('liadd'=>'onmouseover="this.style.cursor=\'pointer\'"', 'href'=>null, 'title'=>'English', 'selected'=>false, 'submenu'=>null),
'es'=>array('liadd'=>'onmouseover="this.style.cursor=\'pointer\'"', 'href'=>null, 'title'=>'Español', 'selected'=>false, 'submenu'=>null),
'fr'=>array('liadd'=>'onmouseover="this.style.cursor=\'pointer\'"', 'href'=>null, 'title'=>'Français', 'selected'=>false, 'submenu'=>null),
2020-10-13 08:21:26 +02:00
'it'=>array('liadd'=>'onmouseover="this.style.cursor=\'pointer\'" style="border-radius:0 0 5px 5px;"', 'href'=>null, 'title'=>'Italiano', 'selected'=>false, 'submenu'=>null)
2019-12-02 20:16:26 +01:00
)
)
);
2020-04-14 07:35:58 +02:00
foreach ($supplangs as $lang)
2020-05-07 07:24:56 +02:00
$menu['language']['submenu'][$lang]['href']=$conf['instpath'].$path.'/'.$lang;
2019-12-02 20:16:26 +01:00
2020-04-14 07:35:58 +02:00
$menu['language']['submenu'][$dlang]['href']=null;
$menu['language']['submenu'][$dlang]['liadd']=null;
$menu['language']['submenu'][$dlang]['selected']=true;
2019-12-02 20:16:26 +01:00
2020-04-14 07:35:58 +02:00
switch ($dlang) {
case 'ca':
$menu['guide']['title']='Guia';
$menu['instances']['title']='Instàncies';
$menu['about']['title']='Info';
$menu['language']['title']='Idioma';
2019-12-01 09:07:45 +01:00
break;
2019-12-02 20:16:26 +01:00
2020-04-14 07:35:58 +02:00
case 'en':
$menu['guide']['title']='Guide';
$menu['instances']['title']='Instances';
$menu['about']['title']='About';
$menu['language']['title']='Language';
2019-12-02 20:16:26 +01:00
break;
2020-04-14 07:35:58 +02:00
case 'es':
$menu['guide']['title']='Guía';
$menu['instances']['title']='Instancias';
$menu['about']['title']='Acerca de';
2020-04-14 07:35:58 +02:00
$menu['language']['title']='Idioma';
2020-03-03 15:19:22 +01:00
break;
2020-04-14 07:35:58 +02:00
case 'fr':
$menu['guide']['title']='Guide';
$menu['instances']['title']='Instances';
$menu['about']['title']='Infos';
$menu['language']['title']='Langue';
2020-04-11 06:56:24 +02:00
break;
2020-03-03 15:19:22 +01:00
2020-04-14 07:35:58 +02:00
case 'it':
$menu['guide']['title']='Guida';
$menu['instances']['title']='Istanze';
$menu['about']['title']='Info';
$menu['language']['title']='Lingua';
2020-04-13 18:43:00 +02:00
break;
2020-04-14 07:35:58 +02:00
}
2020-04-13 18:43:00 +02:00
2020-04-14 07:35:58 +02:00
$data=array(
'ca.home.atit'=>'Guia',
'ca.home.desc'=>'A thorough introduction to Mastodon', // needs translation
'ca.instances.atit'=>'Instàncies',
'ca.instances.desc'=>'Recommended Mastodon instances', // needs translation
'ca.about.atit'=>'Info',
'ca.about.desc'=>'Info about Mastodon Helps authors, contributors, license', // needs translation
2020-04-14 07:35:58 +02:00
'en.home.atit'=>'Guide',
'en.home.desc'=>'A thorough introduction to Mastodon',
'en.instances.atit'=>'Instancias',
'en.instances.desc'=>'Recommended Mastodon instances',
'en.about.atit'=>'About',
'en.about.desc'=>'Info about Mastodon Helps authors, contributors, license',
2020-04-14 07:35:58 +02:00
'es.home.atit'=>'Guía',
'es.home.desc'=>'Una introducción exhaustiva a Mastodon',
'es.instances.atit'=>'Instancias',
'es.instances.desc'=>'Instancias de Mastodon recomendadas',
'es.about.atit'=>'Acerca de',
'es.about.desc'=>'Informaciones sobre l@s autores y autoras de la página de inicio de Mastodon y su licencia',
2020-04-14 07:35:58 +02:00
'fr.home.atit'=>'Guide',
'fr.home.desc'=>'Une introduction approfondie à Mastodon',
2020-04-14 07:35:58 +02:00
'fr.instances.atit'=>'Instances',
'fr.instances.desc'=>'Instances Mastodon recommandées',
2020-04-14 07:35:58 +02:00
'fr.about.atit'=>'Infos',
'fr.about.desc'=>'Infos sur lauteur de Mastodon Help, contributeurs, licence',
2020-04-14 07:35:58 +02:00
'it.home.atit'=>'Guida',
'it.home.desc'=>'Una approfondita introduzione a Mastodon',
'it.instances.atit'=>'Istanze',
'it.instances.desc'=>'Istanze Mastodon consigliate',
'it.about.atit'=>'Info',
'it.about.desc'=>'Informazioni sugli autori, i collaboratori e la licenza di Mastodon Help'
2019-12-02 20:16:26 +01:00
2020-04-14 07:35:58 +02:00
);
2019-12-02 20:16:26 +01:00
2020-04-14 07:35:58 +02:00
switch($path) {
2020-03-03 15:19:22 +01:00
2020-04-14 07:35:58 +02:00
case '':
2020-04-11 06:56:24 +02:00
$cont=array(
2020-04-14 07:35:58 +02:00
'fp'=>'home_'.$dlang.'.php',
'atit'=>' - '.$data[$dlang.'.home.atit'],
'desc'=>$data[$dlang.'.home.desc'],
'js'=>array('shsum','guideanchors','scrolltrack')
2020-04-11 06:56:24 +02:00
);
2020-04-14 07:35:58 +02:00
$menu['guide']['liadd']='onclick="shsum()" onmouseover="this.style.cursor=\'pointer\'; this.style.textDecoration=\'underline\'" onmouseout="this.style.textDecoration=\'none\'"';
$menu['guide']['href']=null;
$menu['guide']['selected']=true;
2020-04-11 06:56:24 +02:00
break;
2020-03-03 15:19:22 +01:00
2020-04-14 07:35:58 +02:00
case '/instances':
2020-04-13 18:43:00 +02:00
$cont=array(
2020-10-13 08:21:26 +02:00
'fp'=>'instances_'.$dlang.'.old.php',
2020-04-14 07:35:58 +02:00
'atit'=>' - '.$data[$dlang.'.instances.atit'],
'desc'=>$data[$dlang.'.instances.desc'],
2020-10-13 17:48:55 +02:00
'js'=>array()
);
$menu['instances']['href']=null;
$menu['instances']['selected']=true;
break;
case '/instancesnew':
$cont=array(
'fp'=>'instances_'.$dlang.'.php',
'atit'=>' - '.$data[$dlang.'.instances.atit'],
'desc'=>$data[$dlang.'.instances.desc'],
2020-04-13 18:43:00 +02:00
'js'=>array()
);
$menu['instances']['href']=null;
$menu['instances']['selected']=true;
break;
2019-12-02 20:16:26 +01:00
case '/about':
$cont=array(
2020-04-14 07:35:58 +02:00
'fp'=>'about_'.$dlang.'.php',
'atit'=>' - '.$data[$dlang.'.about.atit'],
'desc'=>$data[$dlang.'.about.desc'],
2019-12-02 20:16:26 +01:00
'js'=>array()
2019-12-01 09:07:45 +01:00
);
2019-12-02 20:16:26 +01:00
$menu['about']['href']=null;
$menu['about']['selected']=true;
2020-04-13 18:43:00 +02:00
break;
2019-12-01 09:07:45 +01:00
default:
$cont=array(
'fp'=>'404.php',
2019-12-02 20:16:26 +01:00
'atit'=>' - 404',
2019-12-26 21:57:36 +01:00
'desc'=>'Page not found',
2019-12-02 20:16:26 +01:00
'js'=>array()
2019-12-01 09:07:45 +01:00
);
break;
}
2019-12-02 20:16:26 +01:00
/*
2020-05-07 07:24:56 +02:00
<li><a href="<?php echo($conf['instpath']); ?>">Guide</a></li>
2019-12-02 20:16:26 +01:00
<li><a href="instances">Instances</a></li>
<li><a href="about">About us</a></li>
<li onmouseover="chulsh(this,true)" onmouseout="chulsh(this,false)">Language
<ul class="ula" onmouseover="ulsh(this,true)" onmouseout="ulsh(this,false)">
<li><a href="#">English</a></li>
<li><a href="#">Italiano</a></li>
</ul>
</li>
*/
$menuout='';
function buildmenu($menu) {
global $menuout;
foreach ($menu as $key=>$arr) {
$menuout.='<li';
2019-12-03 21:35:02 +01:00
if (!is_null($arr['liadd'])) $menuout.=' '.$arr['liadd'];
2019-12-02 20:16:26 +01:00
if (!is_null($arr['submenu'])) $menuout.=' onmouseover="chulsh(this,true)" onmouseout="chulsh(this,false)"';
if ($arr['selected']) $menuout.=' class="hil"';
$menuout.='>';
if (!is_null($arr['href']))
$menuout.='<a href="'.$arr['href'].'">'.$arr['title'].'</a>';
else
$menuout.=$arr['title'];
if (!is_null($arr['submenu'])) {
2019-12-10 21:14:45 +01:00
// qui bisognerebbe aggiungere che a seconda del "livello" imposta class giusta: ula, oppure ulb per livello > 1
2019-12-02 20:16:26 +01:00
$menuout.=N.'<ul class="ula" onmouseover="ulsh(this,true)" onmouseout="ulsh(this,false)">'.N;
buildmenu($arr['submenu']);
$menuout.='</ul>'.N;
}
$menuout.='</li>'.N;
}
}
buildmenu($menu);
//echo(htmlentities($menuout));
$cjrand=rand(0,999999);
2019-12-01 09:07:45 +01:00
?>
<!DOCTYPE HTML>
2020-04-14 07:35:58 +02:00
<html lang="<?php echo($dlang); ?>">
2019-12-01 09:07:45 +01:00
<head>
<title>Mastodon Help<?php echo($cont['atit']); ?></title>
2019-12-01 09:07:45 +01:00
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2019-12-26 21:57:36 +01:00
<meta name="description" content="<?php echo($cont['desc']); ?>">
2019-12-01 09:07:45 +01:00
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
2019-12-26 21:57:36 +01:00
<link rel="icon" type="image/png" href="<?php echo($prepath); ?>imgs/icona-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="<?php echo($prepath); ?>imgs/icona-192.png" sizes="192x192">
<link rel="icon" type="image/png" href="<?php echo($prepath); ?>imgs/icona-512.png" sizes="512x512">
<link rel="apple-touch-icon-precomposed" href="<?php echo($prepath); ?>imgs/icona-180.png">
2019-12-02 20:16:26 +01:00
<link rel="stylesheet" type="text/css" href="<?php echo($prepath); ?>theme.css?v=<?php echo($cjrand); ?>">
<?php
foreach ($cont['js'] as $val)
echo('<script language="JavaScript" src="js/'.$val.'.js?v='.$cjrand.'"></script>'.N);
?>
2019-12-01 09:07:45 +01:00
<script language="JavaScript">
<!--
2019-12-02 20:16:26 +01:00
function chulsh(el,sh) {
if (sh)
el.querySelector('ul').style='display:block';
else
el.querySelector('ul').style='display:none';
2019-12-01 09:07:45 +01:00
}
2019-12-02 20:16:26 +01:00
function ulsh(el,sh) {
if (sh)
el.style='display:block';
else
el.style='display:none';
}
2019-12-01 09:07:45 +01:00
//-->
</script>
</head>
2019-12-02 20:16:26 +01:00
<?php
require($cont['fp']);
?>
2019-12-01 09:07:45 +01:00
</html>