MastodonStartpage/web/index.php
pezcurrel 74727aa0c1 ...
2019-12-10 21:14:45 +01:00

223 lines
6.3 KiB
PHP

<?php
const N="\n";
$instpath='/mastostart';
$path=preg_replace('/^'.preg_quote($instpath,'/').'/','',$_SERVER['REQUEST_URI']);
$ndir=preg_match_all('/\//',$path)-1;
$prepath='';
for ($i=0; $i<$ndir; $i++)
$prepath.='../';
$menu=array(
'guide'=>array('liadd'=>null, 'href'=>$instpath, 'title'=>'Guide', 'selected'=>false, 'submenu'=>null),
'instances'=>array('liadd'=>null, 'href'=>$instpath.'/instances', 'title'=>'Instances', 'selected'=>false, 'submenu'=>null),
'about'=>array('liadd'=>null, 'href'=>$instpath.'/about', 'title'=>'About', 'selected'=>false, 'submenu'=>null),
'language'=>array('liadd'=>null, 'href'=>null, 'title'=>'Language', 'selected'=>false, 'submenu'=>array(
'inglese'=>array('liadd'=>'onclick="golang(\'en\')" onmouseover="this.style.cursor=\'pointer\'"', 'href'=>null, 'title'=>'English', 'selected'=>false, 'submenu'=>null),
'italiano'=>array('liadd'=>'onclick="golang(\'it\')" onmouseover="this.style.cursor=\'pointer\'"', 'href'=>null, 'title'=>'Italiano', 'selected'=>false, 'submenu'=>null)
)
)
);
function tradmenu($lang) {
global $menu;
switch ($lang) {
case 'it':
$menu['guide']['title']='Guida';
$menu['guide']['href'].='/it';
$menu['instances']['title']='Istanze';
$menu['instances']['href'].='/it';
$menu['about']['title']='Info';
$menu['about']['href'].='/it';
$menu['language']['title']='Lingua';
break;
}
}
switch($path) {
case '/':
$cont=array(
'fp'=>'home_en.php',
'lang'=>'en',
'atit'=>' - Guide',
'js'=>array('shsum','guideanchors','scrolltrack')
);
$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;
$menu['language']['submenu']['inglese']['liadd']=null;
$menu['language']['submenu']['inglese']['selected']=true;
break;
case '/it':
$cont=array(
'fp'=>'home_it.php',
'lang'=>'it',
'atit'=>' - Guida',
'js'=>array('shsum','guideanchors','scrolltrack')
);
tradmenu('it');
$menu['guide']['liadd']='onclick="shsum()" onmouseover="this.style.cursor=\'pointer\'"';
$menu['guide']['href']=null;
$menu['guide']['selected']=true;
$menu['language']['submenu']['italiano']['liadd']=null;
$menu['language']['submenu']['italiano']['selected']=true;
break;
case '/instances':
$cont=array(
'fp'=>'instances_en.php',
'lang'=>'en',
'atit'=>' - Instances',
'js'=>array()
);
$menu['instances']['href']=null;
$menu['instances']['selected']=true;
$menu['language']['submenu']['inglese']['liadd']=null;
$menu['language']['submenu']['inglese']['selected']=true;
break;
case '/instances/it':
$cont=array(
'fp'=>'instances_it.php',
'lang'=>'it',
'atit'=>' - Istanze',
'js'=>array()
);
tradmenu('it');
$menu['instances']['href']=null;
$menu['instances']['selected']=true;
$menu['language']['submenu']['italiano']['liadd']=null;
$menu['language']['submenu']['italiano']['selected']=true;
break;
case '/about':
$cont=array(
'fp'=>'about_en.php',
'lang'=>'en',
'atit'=>' - About us',
'js'=>array()
);
$menu['about']['href']=null;
$menu['about']['selected']=true;
$menu['language']['submenu']['inglese']['liadd']=null;
$menu['language']['submenu']['inglese']['selected']=true;
break;
case '/about/it':
$cont=array(
'fp'=>'about_it.php',
'lang'=>'it',
'atit'=>' - Info',
'js'=>array()
);
tradmenu('it');
$menu['about']['href']=null;
$menu['about']['selected']=true;
$menu['language']['submenu']['italiano']['liadd']=null;
$menu['language']['submenu']['italiano']['selected']=true;
break;
default:
$cont=array(
'fp'=>'404.php',
'lang'=>'en',
'atit'=>' - 404',
'js'=>array()
);
break;
}
/*
<li><a href="<?php echo($instpath); ?>">Guide</a></li>
<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';
if (!is_null($arr['liadd'])) $menuout.=' '.$arr['liadd'];
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'])) {
// qui bisognerebbe aggiungere che a seconda del "livello" imposta class giusta: ula, oppure ulb per livello > 1
$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);
?>
<!DOCTYPE HTML>
<html lang="<?php echo($cont['lang']); ?>">
<head>
<title>Mastodon Startpage<?php echo($cont['atit']); ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="description" content="A thorough introduction to Mastodon">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="shortcut icon" href="<?php echo($prepath); ?>favicon.ico">
<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);
?>
<script language="JavaScript">
<!--
function chulsh(el,sh) {
if (sh)
el.querySelector('ul').style='display:block';
else
el.querySelector('ul').style='display:none';
}
function ulsh(el,sh) {
if (sh)
el.style='display:block';
else
el.style='display:none';
}
function golang(lang) {
var loc=document.location.href;
loc=loc.replace(/#.*$/,'');
loc=loc.replace(/\/$/,'');
if (document.documentElement.lang=='en') {
if (lang!='en')
document.location.href=loc+'/'+lang;
} else {
if (lang!='en')
document.location.href=loc.substr(0,loc.length-3)+'/'+lang;
else
document.location.href=loc.substr(0,loc.length-3);
}
}
//-->
</script>
</head>
<?php
require($cont['fp']);
?>
</html>