2019-12-01 09:07:45 +01:00
< ? php
2023-01-03 23:31:38 +01:00
define ( 'N' , " \n " );
2023-01-03 18:52:47 +01:00
2023-01-03 23:31:38 +01:00
function dienice ( $msg , $ec ) {
2020-10-26 16:05:59 +01:00
global $link ;
2023-01-03 18:52:47 +01:00
if ( isset ( $link ) && $link !== false ) 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' ;
2023-01-03 23:31:38 +01:00
$conf =@ parse_ini_file ( $inifp );
if ( $conf === false ) dienice ( 'Could not open configuration file.' . N , 1 );
if ( ! array_key_exists ( 'instpath' , $conf )) dienice ( 'Configuration file: «instpath» is not defined.' . N , 1 );
2020-10-13 08:21:26 +02:00
$path = preg_replace ( '#\?.*$#' , '' , $_SERVER [ 'REQUEST_URI' ]);
$path = preg_replace ( '/^' . preg_quote ( $conf [ 'instpath' ], '/' ) . '/' , '' , $path );
2022-12-08 19:53:18 +01:00
$ndir = preg_match_all ( '#/#' , $path ) - 1 ;
2019-12-01 09:07:45 +01:00
$prepath = '' ;
for ( $i = 0 ; $i < $ndir ; $i ++ )
$prepath .= '../' ;
2022-12-08 19:53:18 +01:00
$path = preg_replace ( '#/+$#' , '' , $path );
2020-10-26 16:05:59 +01:00
2023-01-07 12:55:43 +01:00
$blang = 'en' ;
if ( array_key_exists ( 'HTTP_ACCEPT_LANGUAGE' , $_SERVER )) {
2022-12-08 14:16:12 +01:00
$langs = [];
$buff = explode ( ',' , $_SERVER [ 'HTTP_ACCEPT_LANGUAGE' ]);
foreach ( $buff as $ent ) {
$ent = trim ( $ent );
$ent = explode ( ';' , $ent );
( count ( $ent ) < 2 ) ? $ent [ 1 ] = 1 : $ent [ 1 ] = preg_replace ( '/^q=/' , '' , $ent [ 1 ]) + 0 ;
2023-01-07 12:55:43 +01:00
$ent [ 0 ] = locale_canonicalize ( $ent [ 0 ]);
2022-12-08 14:16:12 +01:00
$langs [ $ent [ 0 ]] = $ent [ 1 ];
}
arsort ( $langs );
2023-01-07 12:55:43 +01:00
$blang = array_key_first ( $langs );
}
$supplangs = [ 'ca' , 'de' , 'en' , 'es' , 'fr' , 'gl' , 'it' , 'pt_BR' , 'uk' ]; // when adding a language code here, it is necessary to add it also to "$menu" in this same file, to "$hlmap" in stats.php, to "$hitslang" and "$langs" in ../clitools/mustool.php, to "langs" in ../clitools/updtrans.bash (if missing), to function "getlangid" in ../clitools/getinstinfo.php; and to run "../clitools/addlang.php <new language code>" locally and on the server
$dlang = null ;
if ( preg_match ( '#/(' . implode ( '|' , $supplangs ) . ')$#' , $path , $lang ) === 1 ) {
$dlang = $lang [ 1 ];
$path = preg_replace ( '#/[^/]+$#' , '' , $path );
} elseif ( array_key_exists ( 'HTTP_ACCEPT_LANGUAGE' , $_SERVER )) {
2022-12-08 14:16:12 +01:00
foreach ( $langs as $lang => $val ) {
if ( in_array ( $lang , $supplangs )) {
$dlang = $lang ;
break ;
}
}
2022-12-18 11:46:01 +01:00
if ( is_null ( $dlang )) {
foreach ( $langs as $lang => $val ) {
foreach ( $supplangs as $slang ) {
if ( preg_match ( '/^' . preg_quote ( $lang , '/' ) . '/' , $slang )) {
$dlang = $slang ;
break ( 2 );
}
}
}
}
2020-04-14 07:35:58 +02:00
}
2022-12-18 11:46:01 +01:00
if ( is_null ( $dlang )) $dlang = 'en' ;
2019-12-01 09:07:45 +01:00
2020-10-27 16:32:23 +01:00
$locale = $dlang ;
2020-10-31 13:31:11 +01:00
// il blocale è per non dover avere installate tutte le locale corrispondenti
2020-10-27 16:32:23 +01:00
$blocale = 'en_US.UTF-8' ;
//putenv('LC_ALL='.$blocale);
setlocale ( LC_ALL , $blocale );
bindtextdomain ( 'masthelp' , './locale/' . $locale );
textdomain ( 'masthelp' );
2021-02-14 19:03:52 +01:00
$needstrans = false ;
2019-12-02 20:16:26 +01:00
$menu = array (
2020-10-27 16:32:23 +01: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 ),
2023-06-27 16:34:58 +02:00
'links' => array ( 'liadd' => null , 'href' => $conf [ 'instpath' ] . '/links/' . $dlang , 'title' => _ ( 'Links' ), 'selected' => false , 'submenu' => null ),
2020-10-27 16:32:23 +01:00
'about' => array ( 'liadd' => null , 'href' => $conf [ 'instpath' ] . '/about/' . $dlang , 'title' => _ ( 'About' ), 'selected' => false , 'submenu' => array (
2020-11-01 09:14:31 +01:00
'stats' => array ( 'liadd' => null , 'href' => $conf [ 'instpath' ] . '/stats/' . $dlang , 'title' => _ ( 'Statistics' ), 'selected' => false , 'submenu' => null ),
2020-10-27 16:32:23 +01:00
'contribute' => array ( 'liadd' => null , 'href' => $conf [ 'instpath' ] . '/contribute/' . $dlang , 'title' => _ ( 'Contribute' ), 'selected' => false , 'submenu' => null )
2020-10-26 16:05:59 +01:00
)
),
2020-10-27 16:32:23 +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 ),
2022-12-02 16:29:24 +01:00
'de' => array ( 'liadd' => null , 'href' => null , 'title' => 'Deutsch' , 'selected' => false , 'submenu' => null ),
2020-10-26 16:05:59 +01:00
'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 ),
2020-10-27 16:32:23 +01:00
'cc' => array ( 'liadd' => null , 'href' => $conf [ 'instpath' ] . '/contribute/' . $dlang , 'title' => 'Contribute' , 'selected' => false , 'submenu' => null )
2020-10-26 16:05:59 +01:00
)
), */
'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 ),
2022-02-12 09:35:20 +01:00
'gl' => array ( 'liadd' => null , 'href' => null , 'title' => 'Galego' , 'selected' => false , 'submenu' => null ),
2022-11-23 17:48:44 +01:00
'it' => array ( 'liadd' => null , 'href' => null , 'title' => 'Italiano' , 'selected' => false , 'submenu' => null ),
2022-12-08 14:16:12 +01:00
'pt_BR' => array ( 'liadd' => null , 'href' => null , 'title' => 'Português (BR)' , 'selected' => false , 'submenu' => null ),
2022-11-23 17:48:44 +01:00
'uk' => array ( 'liadd' => null , 'href' => null , 'title' => 'Українська' , '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-10-26 16:05:59 +01:00
$cont = array ();
2020-10-27 16:32:23 +01:00
2020-10-26 16:05:59 +01:00
$cont [ 'css' ] = array ( 'theme.css' , 'menu.css' );
$cont [ 'js' ] = array ( 'menu.js' );
2020-10-27 16:32:23 +01:00
$cont [ 'bodyadd' ] = '' ;
2020-10-26 16:05:59 +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 '' :
2021-02-14 19:03:52 +01:00
$cont [ 'fp' ] = 'home.php' ;
2020-10-27 16:32:23 +01:00
$cont [ 'atit' ] = ' - ' . _ ( 'Guide' );
$cont [ 'desc' ] = _ ( 'A thorough introduction to Mastodon' );
2020-10-26 16:05:59 +01:00
$cont [ 'js' ][] = 'shsum.js' ;
$cont [ 'js' ][] = 'guideanchors.js' ;
$cont [ 'js' ][] = 'scrolltrack.js' ;
2020-10-27 16:32:23 +01:00
$cont [ 'bodyadd' ] = ' onscroll="scrolltrack()"' ;
2020-04-14 07:35:58 +02:00
$menu [ 'guide' ][ 'href' ] = null ;
$menu [ 'guide' ][ 'selected' ] = true ;
2020-10-26 16:05:59 +01:00
$url = 'home' ;
2021-02-14 19:21:48 +01:00
if ( in_array ( $dlang , array ( 'ca' ))) $needstrans = 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-10-27 16:32:23 +01:00
$cont [ 'fp' ] = 'instances.php' ;
$cont [ 'atit' ] = ' - ' . _ ( 'Instances' );
2022-12-16 19:08:39 +01:00
$cont [ 'desc' ] = _ ( 'Mastodon instances' );
2020-10-27 16:32:23 +01:00
$cont [ 'css' ][] = 'instances.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' ;
2022-11-21 12:48:44 +01:00
if ( in_array ( $dlang , array ( 'ca' , 'es' ))) $needstrans = true ;
2020-04-13 18:43:00 +02:00
break ;
2022-12-16 19:08:39 +01:00
case '/users' :
$cont [ 'fp' ] = 'users.php' ;
$cont [ 'atit' ] = ' - ' . _ ( 'Users' );
$cont [ 'desc' ] = _ ( 'Directory of Mastodon users' );
$cont [ 'css' ][] = 'instances.css' ;
/* $menu [ 'instances' ][ 'href' ] = null ;
$menu [ 'instances' ][ 'selected' ] = true ; */
$url = 'users' ;
break ;
2019-12-02 20:16:26 +01:00
case '/about' :
2020-10-27 16:32:23 +01:00
$cont [ 'fp' ] = 'about.php' ;
$cont [ 'atit' ] = ' - ' . _ ( 'About' );
$cont [ 'desc' ] = _ ( 'Info about Mastodon Help’ s authors, contributors, license' );
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' ;
2021-02-14 19:21:48 +01:00
if ( in_array ( $dlang , array ( 'ca' , 'es' ))) $needstrans = true ;
2020-10-26 16:05:59 +01:00
break ;
case '/stats' :
$cont [ 'fp' ] = 'stats.php' ;
2020-10-27 16:32:23 +01:00
$cont [ 'atit' ] = ' - ' . _ ( 'Statistics' );
$cont [ 'desc' ] = _ ( 'Statistics about Mastodon Help' );
2020-10-26 16:05:59 +01:00
$cont [ 'css' ][] = 'stats.css' ;
$menu [ 'about' ][ 'selected' ] = true ;
$menu [ 'about' ][ 'submenu' ][ 'stats' ][ 'href' ] = null ;
$menu [ 'about' ][ 'submenu' ][ 'stats' ][ 'selected' ] = true ;
$url = 'stats' ;
2021-02-15 05:41:37 +01:00
if ( in_array ( $dlang , array ( 'ca' , 'es' ))) $needstrans = true ;
2020-10-26 16:05:59 +01:00
break ;
2020-10-27 16:32:23 +01:00
case '/contribute' :
$cont [ 'fp' ] = 'contribute.php' ;
$cont [ 'atit' ] = ' - ' . _ ( 'Contribute' );
$cont [ 'desc' ] = _ ( 'Contribute to Mastodon Help development' );
2020-10-26 16:05:59 +01:00
$menu [ 'about' ][ 'selected' ] = true ;
2020-10-27 16:32:23 +01:00
$menu [ 'about' ][ 'submenu' ][ 'contribute' ][ 'href' ] = null ;
$menu [ 'about' ][ 'submenu' ][ 'contribute' ][ 'selected' ] = true ;
$url = 'contribute' ;
2021-02-14 19:21:48 +01:00
if ( in_array ( $dlang , array ( 'ca' , 'es' ))) $needstrans = true ;
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' ;
2022-11-29 09:01:14 +01:00
$cont [ 'atit' ] = ' - ' . _ ( 'Resource not found' );
$cont [ 'desc' ] = _ ( 'Resource not found' );
2020-10-26 16:05:59 +01:00
$url = '404' ;
2020-11-18 06:22:07 +01:00
/* $nffp = '404.log' ;
2020-10-30 07:10:32 +01:00
$nff =@ fopen ( $nffp , 'a' );
if ( $nff ) {
fwrite ( $nff , $_SERVER [ 'REQUEST_URI' ] . N );
fclose ( $nff );
} else {
echo ( 'Mannaggia!' );
2020-11-18 06:22:07 +01:00
} */
2021-02-14 19:21:48 +01:00
if ( in_array ( $dlang , array ( 'ca' , 'es' ))) $needstrans = true ;
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
2023-01-03 23:31:38 +01:00
$uid = [];
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 ));
2023-01-04 20:28:10 +01:00
try { $link = mysqli_connect ( $conf [ 'db_host' ], $conf [ 'db_user_name' ], $conf [ 'db_user_password' ], $conf [ 'db_name' ], $conf [ 'db_port' ], $conf [ 'db_socket' ]); }
catch ( Exception $error ) { dienice ( _ ( 'Couldn’ t connect to database: ' ) . mysqli_connect_error () . ' [' . mysqli_connect_errno () . '].' , 2 , false ); }
if ( $link === false ) dienice ( _ ( 'Couldn’ t connect to database: ' ) . mysqli_connect_error () . ' [' . mysqli_connect_errno () . '].' , 2 , false );
2020-10-26 16:05:59 +01:00
mysqli_set_charset ( $link , 'utf8mb4' );
2023-01-03 23:31:38 +01:00
mysqli_query ( $link , 'INSERT INTO ZHits (UID,URL,Lang,TS) VALUES ("' . $uid . '","' . $url . '","' . $dlang . '",' . time () . ')' ) or dienice ( __LINE__ . ': ' . mysqli_error ( $link ), 2 , true );
2020-10-26 16:05:59 +01:00
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));
2021-04-29 05:44:52 +02:00
$cjrand = rand ( 0 , 999999 );
//$cjrand='0.1';
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 " >
2021-02-15 12:14:08 +01:00
< meta property = " og:image " content = " '. $prepath .'imgs/ogimage03.png " >
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 >
2020-10-27 16:32:23 +01:00
< body '.$cont[' bodyadd '].' >
2020-10-26 16:05:59 +01:00
< 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
2022-11-21 12:48:44 +01:00
//if ($needstrans) printf('<div id="transd">'._('This translation is missing, incomplete or not up-to-date. Please click <a href="/contribute/%s">here</a> if you’ d like to help, or <span class="transc" onclick="document.getElementById(\'transd\').style.display=\'none\'">here</span> to close this message').'</div>'.N,$dlang);
2021-02-14 19:03:52 +01:00
2020-10-26 16:05:59 +01:00
echo ( ' </ body >
</ html > ' . N );
2019-12-02 20:16:26 +01:00
?>