Migrate translations to gettext
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
/*
|
||||
* Onion Link List - Configuration
|
||||
*
|
||||
* Copyright (C) 2016-2020 Daniel Winzen <daniel@danwin1210.me>
|
||||
* Copyright (C) 2016-2020 Daniel Winzen <daniel@danwin1210.de>
|
||||
*
|
||||
* 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
|
||||
@ -35,54 +35,76 @@ const PER_PAGE = 50; // Sites listed per page
|
||||
const VERSION = '1.1'; // Script version
|
||||
const DBVERSION = 8; // Database layout version
|
||||
const REQUIRE_APPROVAL = false; // require admin approval of new sites? true/false
|
||||
const CANONICAL_URL = 'https://onions.danwin1210.me'; // our preferred domain for search engines
|
||||
const CANONICAL_URL = 'https://onions.danwin1210.de'; // our preferred domain for search engines
|
||||
//Categories - new links will always be put into the first one, leave it to Unsorted
|
||||
//once configured, only add new categories at the end or you have to manually adjust the database.
|
||||
$categories=['Unsorted', 'Adult/Porn', 'Communication/Social', 'Forums', 'Hacking/Programming/Software', 'Hosting', 'Libraries/Wikis', 'Link Lists', 'Market/Shop/Store', 'Other', 'Personal Sites/Blogs', 'Security/Privacy/Encryption', 'Whistleblowing', 'Empty/Error/Unknown', 'Cryptocurrencies', 'Scams', 'Fun/Games/Joke', 'Search'];
|
||||
|
||||
// Language selection
|
||||
$I = $T = [];
|
||||
$language = LANG;
|
||||
$L=[
|
||||
'de' => 'Deutsch',
|
||||
'en' => 'English',
|
||||
'fa' => 'فارسی',
|
||||
'ja' => '日本語',
|
||||
'pt' => 'Português',
|
||||
'tr' => 'Türkçe',
|
||||
const LANGUAGES = [
|
||||
'de' => ['name' => 'Deutsch', 'locale' => 'de_DE', 'flag' => '🇩🇪', 'show_in_menu' => true, 'dir' => 'ltr'],
|
||||
'en' => ['name' => 'English', 'locale' => 'en_GB', 'flag' => '🇬🇧', 'show_in_menu' => true, 'dir' => 'ltr'],
|
||||
'fa' => ['name' => 'فارسی', 'locale' => 'fa_IR', 'flag' => '🇮🇷', 'show_in_menu' => true, 'dir' => 'rtl'],
|
||||
'ja' => ['name' => '日本語', 'locale' => 'ja_JP', 'flag' => '🇯🇵', 'show_in_menu' => true, 'dir' => 'ltr'],
|
||||
'pt' => ['name' => 'Português', 'locale' => 'pt_PT', 'flag' => '🇵🇹', 'show_in_menu' => true, 'dir' => 'ltr'],
|
||||
'tr' => ['name' => 'Türkçe', 'locale' => 'tr_TR', 'flag' => '🇹🇷', 'show_in_menu' => true, 'dir' => 'ltr'],
|
||||
];
|
||||
if(isset($_REQUEST['lang']) && isset($L[$_REQUEST['lang']])){
|
||||
$language=$_REQUEST['lang'];
|
||||
if(!isset($_COOKIE['language']) || $_COOKIE['language']!==$language){
|
||||
set_secure_cookie('language', $language);
|
||||
}
|
||||
}elseif(isset($_COOKIE['language']) && isset($L[$_COOKIE['language']])){
|
||||
$language=$_COOKIE['language'];
|
||||
}
|
||||
require_once(__DIR__.'/lang_en.php'); //always include English
|
||||
if($language!=='en'){
|
||||
require_once(__DIR__."/lang_$language.php"); //replace with translation if available
|
||||
foreach($T as $name=>$translation){
|
||||
$I[$name]=$translation;
|
||||
$language = LANG;
|
||||
$locale = LANGUAGES[LANG]['locale'];
|
||||
$dir = LANGUAGES[LANG]['dir'];
|
||||
if(isset($_REQUEST['lang']) && isset(LANGUAGES[$_REQUEST['lang']])){
|
||||
$locale = LANGUAGES[$_REQUEST['lang']]['locale'];
|
||||
$language = $_REQUEST['lang'];
|
||||
$dir = LANGUAGES[$_REQUEST['lang']]['dir'];
|
||||
setcookie('language', $_REQUEST['lang'], ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ($_SERVER['HTTPS'] ?? '' === 'on'), 'httponly' => true, 'samesite' => 'Strict']);
|
||||
}elseif(isset($_COOKIE['language']) && isset(LANGUAGES[$_COOKIE['language']])){
|
||||
$locale = LANGUAGES[$_COOKIE['language']]['locale'];
|
||||
$language = $_COOKIE['language'];
|
||||
$dir = LANGUAGES[$_COOKIE['language']]['dir'];
|
||||
}elseif(!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
||||
$prefLocales = array_reduce(
|
||||
explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']),
|
||||
function (array $res, string $el) {
|
||||
list($l, $q) = array_merge(explode(';q=', $el), [1]);
|
||||
$res[$l] = (float) $q;
|
||||
return $res;
|
||||
}, []);
|
||||
arsort($prefLocales);
|
||||
foreach($prefLocales as $l => $q){
|
||||
$lang = locale_lookup(array_keys(LANGUAGES), $l);
|
||||
if(!empty($lang)){
|
||||
$locale = LANGUAGES[$lang]['locale'];
|
||||
$language = $lang;
|
||||
$dir = LANGUAGES[$lang]['dir'];
|
||||
setcookie('language', $lang, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => ($_SERVER['HTTPS'] ?? '' === 'on'), 'httponly' => true, 'samesite' => 'Strict']);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
putenv('LC_ALL='.$locale);
|
||||
setlocale(LC_ALL, $locale);
|
||||
|
||||
function print_langs(){
|
||||
global $I, $L;
|
||||
echo "<ul class=\"list\"><li>$I[language]:</li>";
|
||||
bindtextdomain('onion-link-list', __DIR__.'/locale');
|
||||
bind_textdomain_codeset('onion-link-list', 'UTF-8');
|
||||
textdomain('onion-link-list');
|
||||
|
||||
function print_langs(): void
|
||||
{
|
||||
echo "<ul class=\"list\"><li>"._('Language:')."</li>";
|
||||
$query=ltrim(preg_replace('/&?lang=[a-z_\-]*/i', '', $_SERVER['QUERY_STRING']), '&');
|
||||
foreach($L as $code=>$name){
|
||||
foreach(LANGUAGES as $code => $data){
|
||||
if($query===''){
|
||||
$uri="?lang=$code";
|
||||
}else{
|
||||
$uri='?'.htmlspecialchars($query)."&lang=$code";
|
||||
}
|
||||
echo "<li><a href=\"$uri\" target='_self' hreflang=\"$code\">$name</a></li>";
|
||||
echo "<li><a href=\"$uri\" target='_self' hreflang=\"$code\">$data[name]</a></li>";
|
||||
}
|
||||
echo '</ul>';
|
||||
}
|
||||
|
||||
function blacklist_scams(string $address, string $content){
|
||||
function blacklist_scams(string $address, string $content): void
|
||||
{
|
||||
global $db;
|
||||
$scams = ['Black&White Cards :: Index', 'Shadow guide | The ultimate guide of dark web ', 'ONIONLIST - SAFE .ONION LINKS LISTING', 'Dir ', 'netAuth', 'POPBUY MARKET', 'Digital Goods - Verified by GoDark Search, Hidden Links, Wiki, Escrow', 'Delta - Secure Black Market', 'DeDope', 'Unlocker - iCloud Activation Services', '222LOTTO!', 'STREAMING SERVICES ACCOUNTS', 'Red Room', 'Digital Cash'];
|
||||
$cp_scams = ['Wonderful shop', '~ DROP BY TARYAXX ~', 'Magic CP', 'Lolita Club', 'Daft Tadjikskiy Sex Video _ Inductively Fiberless Porno Qom Along With Post Porn Com Numb _ Porn Zdarma', 'xPlay - hosting service for porn videos', 'DARK PRIVATE PACK', 'Good Porn'];
|
||||
@ -113,7 +135,8 @@ function blacklist_scams(string $address, string $content){
|
||||
}
|
||||
}
|
||||
|
||||
function send_headers(array $styles = []){
|
||||
function send_headers(array $styles = []): void
|
||||
{
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
header('Pragma: no-cache');
|
||||
header('Cache-Control: no-cache, no-store, must-revalidate, max-age=0, private');
|
||||
@ -130,40 +153,20 @@ function send_headers(array $styles = []){
|
||||
header("Content-Security-Policy: base-uri 'self'; default-src 'none'; form-action 'self'; frame-ancestors 'none'; img-src data: 'self'; style-src $style_hashes");
|
||||
header('X-Content-Type-Options: nosniff');
|
||||
header('X-Frame-Options: deny');
|
||||
header('X-XSS-Protection: 1; mode=block');
|
||||
header('X-XSS-Protection: 0');
|
||||
if($_SERVER['REQUEST_METHOD'] === 'HEAD'){
|
||||
exit; // headers sent, no further processing needed
|
||||
}
|
||||
}
|
||||
|
||||
function set_secure_cookie(string $name, string $value){
|
||||
if (version_compare(PHP_VERSION, '7.3.0') >= 0) {
|
||||
setcookie($name, $value, ['expires' => 0, 'path' => '/', 'domain' => '', 'secure' => is_definitely_ssl(), 'httponly' => true, 'samesite' => 'Strict']);
|
||||
}else{
|
||||
setcookie($name, $value, 0, '/', '', is_definitely_ssl(), true);
|
||||
}
|
||||
}
|
||||
|
||||
function is_definitely_ssl() : bool {
|
||||
if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
|
||||
return true;
|
||||
}
|
||||
if (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) {
|
||||
return true;
|
||||
}
|
||||
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && ('https' === $_SERVER['HTTP_X_FORWARDED_PROTO'])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function set_curl_options($ch){
|
||||
function set_curl_options($ch): void
|
||||
{
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, USERAGENT);
|
||||
curl_setopt($ch, CURLOPT_PROXY, PROXY);
|
||||
curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5_HOSTNAME);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
|
||||
curl_setopt($ch, CURLOPT_ENCODING, '');
|
||||
}
|
||||
|
Reference in New Issue
Block a user