New “gettlds();” version and some related changes

This commit is contained in:
pezcurrel 2024-10-23 23:11:08 +02:00
parent 1b939b6dc0
commit d485b65f68
3 changed files with 1540 additions and 45 deletions

View file

@ -17,12 +17,18 @@
// Logorrh, Verbose, Charliero, Tashugo? // Logorrh, Verbose, Charliero, Tashugo?
$dodebug=false;
$debug='';
require 'lib/gettlds.php'; require 'lib/gettlds.php';
$tlds=gettlds(); $tlds=gettlds('storage/tlds.txt',false);// we don't get them in "regex format" because we need them for js too, so we'll rsort them later
$retlds=implode('|',$tlds); if (!is_null($tlds['warnings'])) $debug.="GetTLDs warning: {$tlds['warnings']}.<br>\n";
$jstlds="const tlds=['".implode("', '",$tlds)."'];\n"; rsort($tlds);
if (@file_put_contents('js/tlds.js',$jstlds)===false) $retlds=implode('|',$tlds['tlds']);
dieyoung('Error: could not save «js/tlds.js»'); $jstlds="const tlds=['".implode("', '",$tlds['tlds'])."'];\n";
$jstldsfp='storage/tlds.js';
if (@file_put_contents($jstldsfp,$jstlds)===false)
dieyoung("Error: could not save «{$jstldsfp}»");
unset($tlds,$jstlds); unset($tlds,$jstlds);
require 'lib/mastodon.php'; require 'lib/mastodon.php';
require 'lib/ckratelimit.php'; require 'lib/ckratelimit.php';
@ -49,9 +55,6 @@ $now=time();
$timeout=5; $timeout=5;
$formact=preg_replace('#[^/]+$#','',$_SERVER['REQUEST_URI']); $formact=preg_replace('#[^/]+$#','',$_SERVER['REQUEST_URI']);
$dodebug=false;
$debug='';
ini_set('max_execution_time',360);// 6 minutes: default mastodon ratelimits: https://docs.joinmastodon.org/api/rate-limits/ ini_set('max_execution_time',360);// 6 minutes: default mastodon ratelimits: https://docs.joinmastodon.org/api/rate-limits/
$conf=['link'=>"\n\n[This post was split using ".SREPO.']']; $conf=['link'=>"\n\n[This post was split using ".SREPO.']'];
if (file_exists(CONFFN)) { if (file_exists(CONFFN)) {
@ -492,7 +495,7 @@ echo "<!DOCTYPE HTML>
<link rel=\"icon\" type=\"image/png\" href=\"imgs/icon-512.png\" sizes=\"512x512\"> <link rel=\"icon\" type=\"image/png\" href=\"imgs/icon-512.png\" sizes=\"512x512\">
<link rel=\"apple-touch-icon-precomposed\" href=\"imgs/icon-180.png\"> <link rel=\"apple-touch-icon-precomposed\" href=\"imgs/icon-180.png\">
<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css?v={$svers}\"> <link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css?v={$svers}\">
<script language=\"JavaScript\" src=\"js/tlds.js?v={$svers}\"></script> <script language=\"JavaScript\" src=\"{$jstldsfp}?v={$svers}\"></script>
<script language=\"JavaScript\" src=\"js/main.js?v={$svers}\"></script> <script language=\"JavaScript\" src=\"js/main.js?v={$svers}\"></script>
<script language=\"JavaScript\"> <script language=\"JavaScript\">
function swpdisp(elem,defdisp,altdisp) { function swpdisp(elem,defdisp,altdisp) {

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,9 @@
<?php <?php
// Warning: postlength function requires $retlds global variable to be defined, // Warning: postlength function requires $retlds global variable to be defined,
// it has to be a reverse ordered list of "|" separated valid tlds, you can // it has to be a reverse ordered list of valid tlds separated by "|", you can
// require gettlds.php in the calling script and use it to set it, like this: // require gettlds.php in the calling script and use it to set it like this:
// $retlds=gettlds(); $retlds=implode('|',$retlds); // $retlds=gettlds($path_to_tlds_cache_file,true);
function validtoken($token) { function validtoken($token) {
if (preg_match('#^[A-Za-z0-9_-]{43}$#',$token)===1) if (preg_match('#^[A-Za-z0-9_-]{43}$#',$token)===1)