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:
parent
d939664982
commit
8c17cea4ee
1 changed files with 14 additions and 9 deletions
23
gancioff
23
gancioff
|
@ -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; won’t 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}»)";
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue