PHP completed
This commit is contained in:
parent
1170a04b45
commit
c27bf0e11d
3 changed files with 33 additions and 21 deletions
15
index.php
15
index.php
|
@ -45,13 +45,20 @@
|
||||||
<div>
|
<div>
|
||||||
<h3><?= $podcast->episodes[0]->title; ?></h3>
|
<h3><?= $podcast->episodes[0]->title; ?></h3>
|
||||||
<div><?= $podcast->episodes[0]->pubDate; ?></div>
|
<div><?= $podcast->episodes[0]->pubDate; ?></div>
|
||||||
<p><?= $podcast->episodes[0]->desc ?></p>
|
<div><?= $podcast->episodes[0]->desc ?></div>
|
||||||
<audio controls <?= $podcast->episodes[0]->getFormatedAudioData(); ?>"></audio>
|
<audio controls=true <?= $podcast->episodes[0]->audioData; ?>></audio>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript" src="tools/script.js"></script>
|
<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>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -5,21 +5,33 @@ class Episode {
|
||||||
public string $title;
|
public string $title;
|
||||||
public string $pubDate;
|
public string $pubDate;
|
||||||
public string $desc;
|
public string $desc;
|
||||||
public array $audioData;
|
public string $audioData;
|
||||||
|
|
||||||
function __construct($epData) {
|
function __construct($epData) {
|
||||||
$this->title = $epData->title;
|
$this->title = $epData->title;
|
||||||
$this->pubDate = "date";
|
$this->pubDate = $this->formatDate($epData->pubDate);
|
||||||
$this->desc = "description";
|
$this->desc = preg_replace("/<br \/>.+<\/p>/", "", $epData->description);
|
||||||
$this->audioData = [
|
$this->audioData = $this->formatAudioData($epData->enclosure->attributes());
|
||||||
"url" => "https",
|
}
|
||||||
"length" => "1",
|
|
||||||
"type" => "mp3"
|
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() {
|
function getFormatedAudioData() {
|
||||||
return "src=\"{$this->audioData["url"]}\" type={}";
|
return "src={$this->audioData["url"]} length={$this->audioData["length"]} type={$this->audioData["type"]}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -10,19 +10,12 @@ class Podcast {
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
$xml = $this->parseFeed();
|
$xml = $this->parseFeed();
|
||||||
|
|
||||||
$this->title = ucfirst(strtolower($xml->channel->title));
|
$this->title = ucfirst(strtolower($xml->channel->title));
|
||||||
$this->desc = preg_replace(
|
$this->desc = preg_replace("/<br \/>.+<\/p>/", "", $xml->channel->description);
|
||||||
"/<br \/>.+<\/p>/", "", $xml->channel->description
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->episodes = array();
|
$this->episodes = array();
|
||||||
foreach ($xml->channel->item as $epData) {
|
foreach ($xml->channel->item as $epData) {
|
||||||
array_unshift($this->episodes,new Episode($epData));
|
array_unshift($this->episodes,new Episode($epData));
|
||||||
}
|
}
|
||||||
|
|
||||||
//var_dump($this->episodes);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseFeed() {
|
function parseFeed() {
|
||||||
|
|
Loading…
Reference in a new issue