diff --git a/gancioff b/gancioff index 3c4f3f7..849c6b2 100755 --- a/gancioff +++ b/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}»)"; }