MastodonHelp/web/site/index.php

340 lines
12 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-10-26 16:05:59 +01:00
function muoribene($msg,$ec,$clmy=false) {
global $link;
if ($link) mysqli_close($link);
2020-05-07 07:24:56 +02:00
echo($msg);
exit($ec);
}
2020-10-18 06:53:27 +02:00
$inifp='../conf/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-26 16:05:59 +01:00
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);
2020-10-26 16:05:59 +01:00
} elseif (array_key_exists('HTTP_ACCEPT_LANGUAGE',$_SERVER)) {
2020-04-14 07:35:58 +02:00
$dlang=substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
2020-04-16 22:56:12 +02:00
$dlang=in_array($dlang,$supplangs) ? $dlang : 'en';
2020-10-26 16:05:59 +01:00
} else {
$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),
2020-10-26 16:05:59 +01:00
'about'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/about/'.$dlang, 'title'=>'About', 'selected'=>false, 'submenu'=>array(
'stats'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/stats/'.$dlang, 'title'=>'Statistics', 'selected'=>false, 'submenu'=>null),
'translate'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/translate/'.$dlang, 'title'=>'Translate', '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-10-26 16:05:59 +01:00
'ca'=>array('liadd'=>null, 'href'=>null, 'title'=>'Català', 'selected'=>false, 'submenu'=>null),
'en'=>array('liadd'=>null, 'href'=>null, 'title'=>'English', 'selected'=>false, 'submenu'=>null),
/* 'aa'=>array('liadd'=>null, 'href'=>null, 'title'=>'Prova', 'selected'=>false, 'submenu'=>array(
'bb'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/stats/'.$dlang, 'title'=>'Statistics', 'selected'=>false, 'submenu'=>null),
'cc'=>array('liadd'=>null, 'href'=>$conf['instpath'].'/translate/'.$dlang, 'title'=>'Translate', 'selected'=>false, 'submenu'=>null)
)
),*/
'es'=>array('liadd'=>null, 'href'=>null, 'title'=>'Español', 'selected'=>false, 'submenu'=>null),
'fr'=>array('liadd'=>null, 'href'=>null, 'title'=>'Français', 'selected'=>false, 'submenu'=>null),
'it'=>array('liadd'=>null, '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';
2020-10-26 16:05:59 +01:00
$menu['about']['submenu']['stats']['title']='Statistics';// needs translation
$menu['about']['submenu']['translate']['title']='Translate';// needs translation
2020-04-14 07:35:58 +02:00
$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';
2020-10-26 16:05:59 +01:00
$menu['about']['submenu']['stats']['title']='Statistics';
$menu['about']['submenu']['translate']['title']='Translate';
2020-04-14 07:35:58 +02:00
$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-10-26 16:05:59 +01:00
$menu['about']['submenu']['stats']['title']='Statistics';// needs translation
$menu['about']['submenu']['translate']['title']='Translate';// needs translation
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';
2020-10-26 16:05:59 +01:00
$menu['about']['submenu']['stats']['title']='Statistics';// needs translation
$menu['about']['submenu']['translate']['title']='Translate';// needs translation
2020-04-14 07:35:58 +02:00
$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';
2020-10-26 16:05:59 +01:00
$menu['about']['submenu']['stats']['title']='Statistiche';
$menu['about']['submenu']['translate']['title']='Traduci';
2020-04-14 07:35:58 +02:00
$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',
2020-10-26 16:05:59 +01:00
'ca.home.desc'=>'A thorough introduction to Mastodon',// needs translation
2020-04-14 07:35:58 +02:00
'ca.instances.atit'=>'Instàncies',
2020-10-26 16:05:59 +01:00
'ca.instances.desc'=>'Recommended Mastodon instances',// needs translation
2020-04-14 07:35:58 +02:00
'ca.about.atit'=>'Info',
2020-10-26 16:05:59 +01:00
'ca.about.desc'=>'Info about Mastodon Helps authors, contributors, license',// needs translation
'ca.stats.atit'=>'Statistics',// needs translation
'ca.stats.desc'=>'Statistics about Mastodon Help',// needs translation
'ca.translate.atit'=>'Translate',// needs translation
'ca.translate.desc'=>'Translate Mastodon Help',// needs translation
2020-04-14 07:35:58 +02:00
'en.home.atit'=>'Guide',
'en.home.desc'=>'A thorough introduction to Mastodon',
2020-10-26 22:49:52 +01:00
'en.instances.atit'=>'Instances',
2020-04-14 07:35:58 +02:00
'en.instances.desc'=>'Recommended Mastodon instances',
'en.about.atit'=>'About',
'en.about.desc'=>'Info about Mastodon Helps authors, contributors, license',
2020-10-26 16:05:59 +01:00
'en.stats.atit'=>'Statistics',
'en.stats.desc'=>'Statistics about Mastodon Help',
'en.translate.atit'=>'Translate',
'en.translate.desc'=>'Translate Mastodon Help',
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-10-26 16:05:59 +01:00
'es.stats.atit'=>'Statistics',// needs translation
'es.stats.desc'=>'Statistics about Mastodon Help',// needs translation
'es.translate.atit'=>'Translate',// needs translation
'es.translate.desc'=>'Translate Mastodon Help',// needs translation
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',
2020-10-26 16:05:59 +01:00
'fr.about.desc'=>'Infos sur lauteur de Mastodon Help, contributeurs, licence',
'fr.stats.atit'=>'Statistics',// needs translation
'fr.stats.desc'=>'Statistics about Mastodon Help',// needs translation
'fr.translate.atit'=>'Translate',// needs translation
'fr.translate.desc'=>'Translate Mastodon Help',// needs translation
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',
2020-10-26 16:05:59 +01:00
'it.about.desc'=>'Informazioni sugli autori, i collaboratori e la licenza di Mastodon Help',
'it.stats.atit'=>'Statistiche',
'it.stats.desc'=>'Statistiche di Mastodon Help',
'it.translate.atit'=>'Traduci',
'it.translate.desc'=>'Tradurre 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-10-26 16:05:59 +01:00
$cont=array();
$cont['css']=array('theme.css','menu.css');
$cont['js']=array('menu.js');
$bodyadd='';
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-10-26 16:05:59 +01:00
$cont['fp']='home_'.$dlang.'.php';
$cont['atit']=' - '.$data[$dlang.'.home.atit'];
$cont['desc']=$data[$dlang.'.home.desc'];
$cont['js'][]='shsum.js';
$cont['js'][]='guideanchors.js';
$cont['js'][]='scrolltrack.js';
2020-04-14 07:35:58 +02:00
$menu['guide']['href']=null;
$menu['guide']['selected']=true;
2020-10-26 16:05:59 +01:00
$bodyadd=' onscroll="scrolltrack()"';
$url='home';
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-10-26 16:05:59 +01:00
$cont['fp']='instances_'.$dlang.'.php';
$cont['atit']=' - '.$data[$dlang.'.instances.atit'];
$cont['desc']=$data[$dlang.'.instances.desc'];
$cont['css'][]='custard.css';
2020-04-13 18:43:00 +02:00
$menu['instances']['href']=null;
$menu['instances']['selected']=true;
2020-10-26 16:05:59 +01:00
$url='instances';
2020-04-13 18:43:00 +02:00
break;
2019-12-02 20:16:26 +01:00
case '/about':
2020-10-26 16:05:59 +01:00
$cont['fp']='about_'.$dlang.'.php';
$cont['atit']=' - '.$data[$dlang.'.about.atit'];
$cont['desc']=$data[$dlang.'.about.desc'];
2019-12-02 20:16:26 +01:00
$menu['about']['href']=null;
$menu['about']['selected']=true;
2020-10-26 16:05:59 +01:00
$url='about';
break;
case '/stats':
$cont['fp']='stats.php';
$cont['atit']=' - '.$data[$dlang.'.stats.atit'];
$cont['desc']=$data[$dlang.'.stats.desc'];
$cont['css'][]='stats.css';
$menu['about']['selected']=true;
$menu['about']['submenu']['stats']['href']=null;
$menu['about']['submenu']['stats']['selected']=true;
$url='stats';
break;
case '/translate':
$cont['fp']='translate.php';
$cont['atit']=' - '.$data[$dlang.'.translate.atit'];
$cont['desc']=$data[$dlang.'.translate.desc'];
$menu['about']['selected']=true;
$menu['about']['submenu']['translate']['href']=null;
$menu['about']['submenu']['translate']['selected']=true;
$url='translate';
2020-04-13 18:43:00 +02:00
break;
2019-12-01 09:07:45 +01:00
default:
2020-10-23 19:00:43 +02:00
http_response_code(404);
2020-10-26 16:05:59 +01:00
$cont['fp']='404.php';
$cont['atit']=' - Not found';
$cont['desc']='Page not found';
$url='404';
2019-12-01 09:07:45 +01:00
break;
}
2020-10-26 16:05:59 +01:00
$cont['mtit']=substr($cont['atit'],3);
2019-12-01 09:07:45 +01:00
2020-10-26 16:05:59 +01:00
$uid[]=$_SERVER['REMOTE_ADDR'];
if (array_key_exists('HTTP_USER_AGENT',$_SERVER)) $uid[]=$_SERVER['HTTP_USER_AGENT'];
if (array_key_exists('HTTP_ACCEPT',$_SERVER)) $uid[]=$_SERVER['HTTP_ACCEPT'];
if (array_key_exists('HTTP_ACCEPT_LANGUAGE',$_SERVER)) $uid[]=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
if (array_key_exists('HTTP_ACCEPT_ENCODING',$_SERVER)) $uid[]=$_SERVER['HTTP_ACCEPT_ENCODING'];
$uid=md5(implode('|',$uid));
$link=mysqli_connect($conf['db_host'],$conf['db_user_name'],$conf['db_user_password'],$conf['db_name'],$conf['db_port'],$conf['db_socket']) or muoribene('Couldnt connect to database: '.mysqli_connect_error().' ['.mysqli_connect_errno().']',2,false);
mysqli_set_charset($link,'utf8mb4');
$now=time();
$res=mysqli_query($link,'SELECT * FROM ZHits WHERE UID="'.$uid.'" ORDER BY TS DESC') or muoribene(__LINE__.': '.mysqli_error($link),2,true);
if (mysqli_num_rows($res)>0) {
$row=mysqli_fetch_assoc($res);
if ($now-$row['TS']<2) sleep(1);
}
mysqli_query($link,'INSERT INTO ZHits (UID,URL,Lang,TS) VALUES ("'.$uid.'","'.$url.'","'.$dlang.'",'.$now.')') or muoribene(__LINE__.': '.mysqli_error($link),2,true);
mysqli_close($link);
2019-12-02 20:16:26 +01:00
$menuout='';
2020-10-26 16:05:59 +01:00
function buildmenu($menu,$submenu=false) {
2019-12-02 20:16:26 +01:00
global $menuout;
foreach ($menu as $key=>$arr) {
2020-10-26 16:05:59 +01:00
$liclasses=array();
2019-12-02 20:16:26 +01:00
$menuout.='<li';
2019-12-03 21:35:02 +01:00
if (!is_null($arr['liadd'])) $menuout.=' '.$arr['liadd'];
2020-10-26 16:05:59 +01:00
if ($arr['selected']) $liclasses[]='hil';
if (!is_null($arr['submenu'])) {
$menuout.=' onmouseover="chulsh(this,true)" onmouseout="chulsh(this,false)"';
($submenu) ? $liclasses[]='lipr' : $liclasses[]='lipd';
}
if (count($liclasses)>0) $menuout.=' class="'.implode(' ',$liclasses).'"';
2019-12-02 20:16:26 +01:00
$menuout.='>';
2020-10-26 16:05:59 +01:00
if (!is_null($arr['href'])) {
2019-12-02 20:16:26 +01:00
$menuout.='<a href="'.$arr['href'].'">'.$arr['title'].'</a>';
2020-10-26 16:05:59 +01:00
} else {
2019-12-02 20:16:26 +01:00
$menuout.=$arr['title'];
2020-10-26 16:05:59 +01:00
}
2019-12-02 20:16:26 +01:00
if (!is_null($arr['submenu'])) {
2020-10-26 16:05:59 +01:00
//$menuout.='<img src="/imgs/icona-32.png" width="5" height="5" style="float:right;">';
($submenu) ? $class='ulb' : $class='ula';
$menuout.=N.'<ul class="'.$class.'" onmouseover="ulsh(this,true)" onmouseout="ulsh(this,false)">'.N;
buildmenu($arr['submenu'],true);
2019-12-02 20:16:26 +01:00
$menuout.='</ul>'.N;
}
$menuout.='</li>'.N;
}
}
buildmenu($menu);
//echo(htmlentities($menuout));
$cjrand=rand(0,999999);
2019-12-01 09:07:45 +01:00
2020-10-26 16:05:59 +01:00
echo('<!DOCTYPE HTML>
<html lang="'.$dlang.'">
2019-12-01 09:07:45 +01:00
<head>
2020-10-26 16:05:59 +01:00
<title>Mastodon Help'.$cont['atit'].'</title>
2019-12-01 09:07:45 +01:00
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
2020-10-26 16:05:59 +01:00
<meta name="description" content="'.$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">
2020-10-26 16:05:59 +01:00
<link rel="icon" type="image/png" href="'.$prepath.'imgs/icona-32.png" sizes="32x32">
<link rel="icon" type="image/png" href="'.$prepath.'imgs/icona-192.png" sizes="192x192">
<link rel="icon" type="image/png" href="'.$prepath.'imgs/icona-512.png" sizes="512x512">
<link rel="apple-touch-icon-precomposed" href="'.$prepath.'imgs/icona-180.png">'.N);
foreach ($cont['css'] as $val)
echo('<link rel="stylesheet" type="text/css" href="'.$prepath.'css/'.$val.'?v='.$cjrand.'">'.N);
2019-12-02 20:16:26 +01:00
foreach ($cont['js'] as $val)
2020-10-26 16:05:59 +01:00
echo('<script language="JavaScript" src="'.$prepath.'js/'.$val.'?v='.$cjrand.'"></script>'.N);
echo('</head>
<body'.$bodyadd.'>
<nav>
<div id="hmenu">
<img src="'.$prepath.'imgs/menuicon_inactive.svg" id="menuicon" onclick="swmenu()">
<div id="menutit">Mastodon Help'.$cont['atit'].'</div>
<div id="menu">
<ul>
'.$menuout.'
</ul>
</div>
</div>'.N);
2019-12-02 20:16:26 +01:00
require($cont['fp']);
2020-10-26 16:05:59 +01:00
echo('</body>
</html>'.N);
2019-12-02 20:16:26 +01:00
?>