PHP completed

This commit is contained in:
Renarde-dev 2024-05-06 18:27:06 +02:00
parent 1170a04b45
commit c27bf0e11d
3 changed files with 33 additions and 21 deletions

View file

@ -45,13 +45,20 @@
<div>
<h3><?= $podcast->episodes[0]->title; ?></h3>
<div><?= $podcast->episodes[0]->pubDate; ?></div>
<p><?= $podcast->episodes[0]->desc ?></p>
<audio controls <?= $podcast->episodes[0]->getFormatedAudioData(); ?>"></audio>
<div><?= $podcast->episodes[0]->desc ?></div>
<audio controls=true <?= $podcast->episodes[0]->audioData; ?>></audio>
</div>
</div>
<script type="text/javascript" src="tools/script.js"></script>
<div hidden>
<div>
<?php foreach ($podcast->episodes as $key => $ep) {
echo "<div class=\"ep{$key}\" hidden>
<h3>{$ep->title}</h3>
<div>{$ep->pubDate}</div>
<div>{$ep->desc}</div>
<audio controls=true {$ep->audioData}></audio>
</div>";
} ?>
</div>
</body>
</html>

View file

@ -5,21 +5,33 @@ class Episode {
public string $title;
public string $pubDate;
public string $desc;
public array $audioData;
public string $audioData;
function __construct($epData) {
$this->title = $epData->title;
$this->pubDate = "date";
$this->desc = "description";
$this->audioData = [
"url" => "https",
"length" => "1",
"type" => "mp3"
];
$this->pubDate = $this->formatDate($epData->pubDate);
$this->desc = preg_replace("/<br \/>.+<\/p>/", "", $epData->description);
$this->audioData = $this->formatAudioData($epData->enclosure->attributes());
}
function formatDate($date) {
$fmt = new \IntlDateFormatter("fr_FR", null, null);
$fmt->setPattern('d MMMM yyyy HH:mm');
$dateTimeCFF = \DateTime::createFromFormat(
\DateTime::RFC7231,
$date
);
return $fmt->format($dateTimeCFF);
}
function formatAudioData($rawAudioData) {
return "src={$rawAudioData->url}".
" type={$rawAudioData->type}".
" length={$rawAudioData->length}";
}
function getFormatedAudioData() {
return "src=\"{$this->audioData["url"]}\" type={}";
return "src={$this->audioData["url"]} length={$this->audioData["length"]} type={$this->audioData["type"]}";
}
}
?>

View file

@ -10,19 +10,12 @@ class Podcast {
function __construct() {
$xml = $this->parseFeed();
$this->title = ucfirst(strtolower($xml->channel->title));
$this->desc = preg_replace(
"/<br \/>.+<\/p>/", "", $xml->channel->description
);
$this->desc = preg_replace("/<br \/>.+<\/p>/", "", $xml->channel->description);
$this->episodes = array();
foreach ($xml->channel->item as $epData) {
array_unshift($this->episodes,new Episode($epData));
}
//var_dump($this->episodes);
}
function parseFeed() {