Fixed a flaw in the code for shrinking too long posts; fixed a flaw in “getConf”; bumped version to 0.4.4

This commit is contained in:
pezcurrel 2024-10-28 22:48:24 +01:00
parent d939664982
commit 8c17cea4ee

View file

@ -18,7 +18,7 @@
$SNAME='GancioFF';
$ENAME=strtolower($SNAME);
$SVERS='0.4.3';
$SVERS='0.4.4';
require __DIR__.'/lib/gettlds.php';
require __DIR__.'/lib/mastodon-postLength.php';
@ -436,19 +436,24 @@ foreach ($feed->channel->item as $item) {
$itemsToPost++;
}
$post="{$ptext}{$plink}{$pcats}";
if (postLength($post,$tldsregex['tlds'])<=$conf['max_post_length'] && !$conf['always_link_gancio_post']) {
$postLen=postLength($post,$tldsregex['tlds']);
if ($postLen<=$conf['max_post_length'] && !$conf['always_link_gancio_post']) {
$plink='';
} else {
$pcats='';
$post="{$ptext}{$pcats}";
$postLen=postLength($post,$tldsregex['tlds']);
}
$post="{$ptext}{$plink}{$pcats}";
while (postLength($post,$tldsregex['tlds'])>$conf['max_post_length'] && $ptext!='') {
if ($postLen>$conf['max_post_length']) {
$pcats='';
$post="{$ptext}{$plink}";
$postLen=postLength($post,$tldsregex['tlds']);
}
while ($postLen>$conf['max_post_length'] && $ptext!='') {
$ptext=preg_replace('#\S+\W*$#','',$ptext);
//echo "[[[{$ptext}]]]\n";
$post="{$ptext}[…]{$plink}{$pcats}";
$postLen=postLength($post,$tldsregex['tlds']);
}
//echo "--- #{$index}: {$guid} ---\n{$post}\n--- (length: ".postLength($post,$tldsregex['tlds']).") ---\n\n";
if (postLength($post,$tldsregex['tlds'])>$conf['max_post_length']) {
if ($postLen>$conf['max_post_length']) {
fwrite(STDERR,"Warning: could not shorten post for announcement «{$guid}» to make it fit into {$conf['max_post_length']} characters; wont post.\n");
} elseif ($state=='new' || $state=='changed') {
if ($opts['do-post']) {
@ -577,7 +582,7 @@ function getConf(&$conf,&$confFP) {
if (array_key_exists($matches[1],$conf))
$nconf[$matches[1]]=$matches[2];
else
$errors[]="line {$i}: «{$matches[1]}» is an unknown key.\n";
$errors[]="line {$i}: «{$matches[1]}» is an unknown key";
} else {
$errors[]="could not interpret line {$i} («{$line}»)";
}