From 924faff128d4f4dedb4be6b4a6d2125a4e4ce139 Mon Sep 17 00:00:00 2001 From: pezcurrel Date: Sun, 27 Oct 2024 09:33:43 +0100 Subject: [PATCH] Added alt-text support; minor changes; bumped version to 0.4.2 --- gancioff | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/gancioff b/gancioff index 9559920..3838538 100755 --- a/gancioff +++ b/gancioff @@ -18,7 +18,7 @@ $SNAME='GancioFF'; $ENAME=strtolower($SNAME); -$SVERS='0.4.1'; +$SVERS='0.4.2'; require __DIR__.'/lib/gettlds.php'; require __DIR__.'/lib/mastodon-postLength.php'; @@ -296,8 +296,8 @@ if (is_null($conf['max_post_length'])) { } //print_r($conf); -$refs=[]; vecho($opts['verbose'],"Info: trying to load the references to already posted announcements from state file «{$conf['state_file_absolute_path']}».\n"); +$refs=[]; if (file_exists($conf['state_file_absolute_path'])) { if (!is_file($conf['state_file_absolute_path'])) dieYoung("Error: «{$conf['state_file_absolute_path']}» exists but it’s not a file.\n",1); if (!is_readable($conf['state_file_absolute_path'])) dieYoung("Error: «{$conf['state_file_absolute_path']}» exists but it’s not readable.\n",1); @@ -349,17 +349,20 @@ $goodPostsCount=0; $index=0; foreach ($feed->channel->item as $item) { $index++; - //print_r($item); if (!isset($item->guid) || !isset($item->title) || !isset($item->link) || !isset($item->description) || !isset($item->pubDate)) { fwrite(STDERR,"Warning: announcement #{$index} has unexpected format, skipping.\n"); } else { $guid=$item->guid->__toString(); $file=null; + $imgalt=''; $hash=$item->title.$item->pubDate; if (isset($item->enclosure[0]['url']) && isset($item->enclosure[0]['type']) && isset($item->enclosure[0]['length'])) { $file=['url'=>$item->enclosure[0]['url']->__toString(), 'type'=>$item->enclosure[0]['type']->__toString(), 'length'=>$item->enclosure[0]['length']->__toString()]; - $hash.=$item->enclosure[0]['url'].$item->enclosure[0]['type'].$item->enclosure[0]['length']; + if (preg_match('#([^description->__toString(),$matches)===1) $imgalt=trim($matches[1]); + $hash.=$item->enclosure[0]['url'].$item->enclosure[0]['type'].$item->enclosure[0]['length'].$imgalt; } + if ($imgalt=='') $imgalt='Flyer dell’evento'; + //

Raawwr Beats

Kassel - Werner-Hilpert-Straße 22
(samedi, 26 octobre 22:00)
This is the alt-text

$buff=$item->description->__toString(); if ($buff=='') { $ptext=''; @@ -385,7 +388,10 @@ foreach ($feed->channel->item as $item) { $pcats=''; } $hash=hash('sha256',$hash); - if (array_key_exists($guid,$refs)) { + if ($opts['test']) { + vecho($opts['verbose'],"Info: considering announcement «{$guid}» as new because we are in «test mode»; processing.\n"); + $state='new'; + } elseif (array_key_exists($guid,$refs)) { if ($hash==$refs[$guid]['hash']) { vecho($opts['verbose'],"Info: announcement «{$guid}» is not new and has not changed; skipping.\n"); $state='old'; @@ -399,7 +405,6 @@ foreach ($feed->channel->item as $item) { $state='new'; $itemsToPost++; } - if ($opts['test']) $state='new'; $post="{$ptext}{$plink}{$pcats}"; if (postLength($post,$tldsregex['tlds'])<=$conf['max_post_length'] && !$conf['always_link_gancio_post']) { $plink=''; @@ -439,7 +444,7 @@ foreach ($feed->channel->item as $item) { if (@file_put_contents($tfp,$res['content'])===false) { fwrite(STDERR,"Warning: could not save «{$tfp}»; won’t post status for {$state} announcement «{$guid}».\n"); } else { - $pd=['file'=>curl_file_create($tfp,$file['type'],'file'), 'description'=>'Flyer dell’evento']; + $pd=['file'=>curl_file_create($tfp,$file['type'],'file'), 'description'=>$imgalt]; $url="https://{$conf['fedi_hostname']}/api/v2/media"; $res=curl($url,'/api/v2/media',["Authorization: Bearer {$conf['fedi_token']}", 'Accept: application/json'],$pd); if ($res['content']===false) {