Merge PHP files and cleanup
This commit is contained in:
parent
dacbee3b50
commit
7426345889
2 changed files with 58 additions and 81 deletions
74
index.php
74
index.php
|
@ -19,31 +19,71 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="stylesheet" href="scss/styles.css" />
|
<link rel="stylesheet" href="scss/styles.css" />
|
||||||
<?php
|
</head>
|
||||||
require_once "podcast.php";
|
<?php
|
||||||
use Podcast;
|
$removeAcastBranding = function($text) {
|
||||||
$podcast = new Podcast(
|
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"
|
"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">
|
<div class="Title">
|
||||||
<h1><?php echo $podcast->title ?></h1>
|
<h1><?php echo $podcast->title ?></h1>
|
||||||
<p>Animé par Pauline</p>
|
<p>Animé par Pauline</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="Podcast-desc">
|
<p><?php echo $podcast->description ?></p>
|
||||||
<?php echo $podcast->description ?>
|
<!-- Latest episode -->
|
||||||
</p>
|
<h2>Dernier épisode :</h2>
|
||||||
<hr>
|
<div class="Latest-Ep">
|
||||||
|
<img src="https://assets.pippa.io/shows/645f2650b6652d00118486b5/1685609690535-035baa450878ca2a6a8770e8d5c7f963.jpeg" alt="podcast logo" />
|
||||||
<!-- Last episode -->
|
<div class="Latest-Ep-Header">
|
||||||
<div class="Last-episode">
|
<h3><?php echo $podcast->latestEpTitle ?></h3>
|
||||||
<h2>Le dernier épisode :</h2>
|
<div><?php echo (string) $podcast->latestEpPublicationDate ?></div>
|
||||||
<h3 class="Last-episode-title"><?php echo $podcast->latestEpTitle ?></h3>
|
</div>
|
||||||
<?php echo $podcast->latestEpPublicationDate ?>
|
<div>
|
||||||
<audio controls=true <?php echo $podcast->latestEpAudioData ?>></audio>
|
<div><?php echo $podcast->latestEpDescription ?></div>
|
||||||
<p class="Last-episode-desc"><?php echo $podcast->latestEpDescription ?></p>
|
<audio controls=true <?php echo $podcast->latestEpAudioData ?>>podcast audio</audio>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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