Added alt-text support; minor changes; bumped version to 0.4.2
This commit is contained in:
parent
aa966e1685
commit
924faff128
1 changed files with 12 additions and 7 deletions
19
gancioff
19
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('#<img alt="([^"]+)"#',$item->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';
|
||||
//<h3>Raawwr Beats</h3><strong>Kassel - Werner-Hilpert-Straße 22</strong><br/><small>(samedi, 26 octobre 22:00)</small><br/><img alt="This is the alt-text" src="https://demo.gancio.org/media/fcb4ac7e55cb5a53a4008e7c49200dbd.jpg"/><p></p>
|
||||
$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) {
|
||||
|
|
Loading…
Reference in a new issue