re-segment PHP for better readability and compliance on PSR1
This commit is contained in:
parent
27c7fad79d
commit
55082814f0
3 changed files with 99 additions and 81 deletions
117
index.php
117
index.php
|
@ -1,73 +1,35 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<!-- favicons -->
|
||||
<link rel="apple-touch-icon" sizes="180x180"
|
||||
href="assets/favicons/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32"
|
||||
href="assets/favicons/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16"
|
||||
href="assets/favicons/favicon-16x16.png">
|
||||
<link rel="manifest" href="assets/favicons/site.webmanifest">
|
||||
<link rel="mask-icon"
|
||||
href="assets/favicons/safari-pinned-tab.svg" color="#5bbad5">
|
||||
<meta name="msapplication-TileColor" content="#da532c">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<link rel="favicon" type="ico" href="assets/favicons/favicon.ico">
|
||||
<!-- head data -->
|
||||
<title>Le plus beau des voyages</title>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="stylesheet" href="scss/styles.css" />
|
||||
<!-- favicons -->
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/assets/favicons/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/assets/favicons/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/assets/favicons/favicon-16x16.png">
|
||||
<link rel="manifest" href="/assets/favicons/site.webmanifest">
|
||||
<link rel="mask-icon" href="/assets/favicons/safari-pinned-tab.svg" color="#5bbad5">
|
||||
<link rel="shortcut icon" href="/assets/favicons/favicon.ico">
|
||||
<meta name="msapplication-TileColor" content="#00aba9">
|
||||
<meta name="msapplication-config" content="/assets/favicons/browserconfig.xml">
|
||||
<meta name="theme-color" content="#ffffff">
|
||||
<!-- bootstrap -->
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
|
||||
<!-- head data -->
|
||||
<link rel="stylesheet" href="assets/style.css" />
|
||||
<title>Le plus beau des voyages</title>
|
||||
</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())
|
||||
];
|
||||
?>
|
||||
<body>
|
||||
<?php
|
||||
require_once "tools/podcast.php";
|
||||
$podcast = new feed\Podcast;
|
||||
?>
|
||||
<div class="container">
|
||||
<h1 class="cursive_font_bold text-center pt-3 pb-2"><?php echo $podcast->title ?></h1>
|
||||
<!-- Header -->
|
||||
<h1 class="cursive_font_bold text-center pt-3 pb-2">
|
||||
<?= $podcast->title ?>
|
||||
</h1>
|
||||
<div class="row">
|
||||
<div class="col-sm"></div>
|
||||
<div class="col-sm">
|
||||
|
@ -75,28 +37,21 @@
|
|||
</div>
|
||||
<div class="col-sm"></div>
|
||||
</div>
|
||||
<p class="text-center"><?php echo $podcast->description ?></p>
|
||||
<p class="podcast_desc text-center">
|
||||
<?= $podcast->desc ?>
|
||||
</p>
|
||||
<hr class="ms-2 me-2">
|
||||
<!-- Episodes -->
|
||||
<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>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
||||
<!--
|
||||
<h1 class="cursive_font_bold"><?php echo $podcast->title ?></h1>
|
||||
<p class="text-end">un podcast animé par Pauline</p>
|
||||
<p><?php echo $podcast->description ?></p>
|
||||
<h2>Épisodes :</h2>
|
||||
<div>
|
||||
<h3><?php echo $podcast->latestEpTitle ?></h3>
|
||||
<p><?php echo $podcast->latestEpPublicationDate ?></p>
|
||||
<div><?php echo $podcast->latestEpDescription ?></div>
|
||||
<audio controls=true <?php echo $podcast->latestEpAudioData ?>>podcast audio</audio>
|
||||
<script type="text/javascript" src="tools/script.js"></script>
|
||||
<div hidden>
|
||||
|
||||
</div>
|
||||
|
||||
-->
|
||||
</body>
|
||||
</html>
|
25
tools/episode.php
Normal file
25
tools/episode.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
namespace feed;
|
||||
|
||||
class Episode {
|
||||
public string $title;
|
||||
public string $pubDate;
|
||||
public string $desc;
|
||||
public array $audioData;
|
||||
|
||||
function __construct($epData) {
|
||||
$this->title = $epData->title;
|
||||
$this->pubDate = "date";
|
||||
$this->desc = "description";
|
||||
$this->audioData = [
|
||||
"url" => "https",
|
||||
"length" => "1",
|
||||
"type" => "mp3"
|
||||
];
|
||||
}
|
||||
|
||||
function getFormatedAudioData() {
|
||||
return "src=\"{$this->audioData["url"]}\" type={}";
|
||||
}
|
||||
}
|
||||
?>
|
38
tools/podcast.php
Normal file
38
tools/podcast.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
namespace feed;
|
||||
|
||||
require_once "episode.php";
|
||||
|
||||
class Podcast {
|
||||
public string $title;
|
||||
public string $desc;
|
||||
public array $episodes;
|
||||
|
||||
function __construct() {
|
||||
$xml = $this->parseFeed();
|
||||
|
||||
$this->title = ucfirst(strtolower($xml->channel->title));
|
||||
$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() {
|
||||
// Renew cache if older than 5 minutes
|
||||
if (time() - filemtime("assets/podcast.rss") > 5*60) {
|
||||
$data = file_get_contents("https://feeds.acast.com/public/shows/le-plus-beau-des-voyages");
|
||||
file_put_contents("assets/podcast.rss",$data);
|
||||
}
|
||||
$cachedFeedData = file_get_contents("tools/podcast.rss");
|
||||
return simplexml_load_string($cachedFeedData,'SimpleXMLElement', LIBXML_NOCDATA);;
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in a new issue