site-web-le-plus-beau-des-v.../podcast.php

63 lines
1.9 KiB
PHP

<?php
/**
* This file parse Podcast RSS Feed
*
* Parse RSS Feed and return HTML elements
*
* php version 8.1+
* php extensions php-xml php-intl
*
* @author Renarde-Dev <Renarde-Dev@la-taniere-solidaire.fr>
* @link https://forgejo.la-taniere-solidaire.gay/Renarde/site-web-le-plus-beau-des-voyages
*/
namespace podcast;
class Podcast
{
public string $title;
public string $description;
public string $latestEpTitle;
public string $latestEpDescription;
public string $latestEpPublicationDate;
public string $latestEpAudioData;
/**
* @param string $url RSS feed URL
*/
function __construct($url) {
$data = file_get_contents($url);
/**
* TODO : Implement caching system
*
* file_put_contents("feed.rss", $FeedData);
*/
$xml = simplexml_load_string($data,'SimpleXMLElement', LIBXML_NOCDATA);
$this->title = ucfirst(strtolower($xml->channel->title));
// Remove acast branding
$this->description = preg_replace(
"/<br \/>.+<\/p>/", "", $xml->channel->description
);
$this->latestEpTitle = $xml->channel->item[0]->title;
// Remove acast branding
$this->latestEpDescription = preg_replace(
"/<br \/>.+<\/p>/", "", $xml->channel->item[0]->description
);
// Localize the date
$fmt = new \IntlDateFormatter('fr_FR', null, null);
$fmt->setPattern('d MMMM yyyy HH:mm');
$cff = DateTime::createFromFormat(
DateTime::RFC7231,
$xml->channel->item[0]->pubDate
);
$this->latestEpPublicationDate = $fmt->format($cff);
// Generate audio tags
$rawAudioData = $xml->channel->item[0]->enclosure->attributes();
$this->latestEpAudioData = "src={$rawAudioData->url} " .
"type={$rawAudioData->type} " .
"length={$rawAudioData->length}";
}
}
?>