Merge PHP files and cleanup
This commit is contained in:
parent
dacbee3b50
commit
7426345889
2 changed files with 58 additions and 81 deletions
76
index.php
76
index.php
|
@ -19,31 +19,71 @@
|
|||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="scss/styles.css" />
|
||||
<?php
|
||||
require_once "podcast.php";
|
||||
use Podcast;
|
||||
$podcast = new Podcast(
|
||||
</head>
|
||||
<?php
|
||||
$removeAcastBranding = function($text) {
|
||||
return preg_replace(
|
||||
"/<br \/>.+<\/p>/", "", $text
|
||||
);
|
||||
};
|
||||
|
||||
$formatDate = function($locale,$date) {
|
||||
$fmt = new \IntlDateFormatter($locale, null, null);
|
||||
$fmt->setPattern('d MMMM yyyy HH:mm');
|
||||
$dateTimeCFF = DateTime::createFromFormat(
|
||||
DateTime::RFC7231,
|
||||
$date
|
||||
);
|
||||
return $fmt->format($dateTimeCFF);
|
||||
};
|
||||
|
||||
$formatAudioData = function($rawAudioData) {
|
||||
return "controls=true".
|
||||
" src={$rawAudioData->url}".
|
||||
" type={$rawAudioData->type}".
|
||||
" length={$rawAudioData->length}";
|
||||
};
|
||||
|
||||
$data = file_get_contents(
|
||||
"https://feeds.acast.com/public/shows/le-plus-beau-des-voyages"
|
||||
);
|
||||
$xml = simplexml_load_string($data,'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$podcast = (object) [
|
||||
"title" => ucfirst(
|
||||
strtolower($xml->channel->title)
|
||||
),
|
||||
"description" => $removeAcastBranding(
|
||||
$xml->channel->description
|
||||
),
|
||||
"latestEpTitle" => $xml->channel->item[0]->title,
|
||||
"latestEpPublicationDate" => $formatDate(
|
||||
"fr_FR",$xml->channel->item[0]->pubDate
|
||||
),
|
||||
"latestEpDescription" => $removeAcastBranding(
|
||||
$xml->channel->item[0]->description
|
||||
),
|
||||
"latestEpAudioData" => $formatAudioData($xml->channel->item[0]->enclosure->attributes())
|
||||
];
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<body>
|
||||
<!-- Header -->
|
||||
<div class="Title">
|
||||
<h1><?php echo $podcast->title ?></h1>
|
||||
<p>Animé par Pauline</p>
|
||||
</div>
|
||||
<p class="Podcast-desc">
|
||||
<?php echo $podcast->description ?>
|
||||
</p>
|
||||
<hr>
|
||||
|
||||
<!-- Last episode -->
|
||||
<div class="Last-episode">
|
||||
<h2>Le dernier épisode :</h2>
|
||||
<h3 class="Last-episode-title"><?php echo $podcast->latestEpTitle ?></h3>
|
||||
<?php echo $podcast->latestEpPublicationDate ?>
|
||||
<audio controls=true <?php echo $podcast->latestEpAudioData ?>></audio>
|
||||
<p class="Last-episode-desc"><?php echo $podcast->latestEpDescription ?></p>
|
||||
<p><?php echo $podcast->description ?></p>
|
||||
<!-- Latest episode -->
|
||||
<h2>Dernier épisode :</h2>
|
||||
<div class="Latest-Ep">
|
||||
<img src="https://assets.pippa.io/shows/645f2650b6652d00118486b5/1685609690535-035baa450878ca2a6a8770e8d5c7f963.jpeg" alt="podcast logo" />
|
||||
<div class="Latest-Ep-Header">
|
||||
<h3><?php echo $podcast->latestEpTitle ?></h3>
|
||||
<div><?php echo (string) $podcast->latestEpPublicationDate ?></div>
|
||||
</div>
|
||||
<div>
|
||||
<div><?php echo $podcast->latestEpDescription ?></div>
|
||||
<audio controls=true <?php echo $podcast->latestEpAudioData ?>>podcast audio</audio>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
63
podcast.php
63
podcast.php
|
@ -1,63 +0,0 @@
|
|||
<?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}";
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue