Skip to content

Commit

Permalink
Merge pull request #4 from mauricerenck/develop
Browse files Browse the repository at this point in the history
Some fixed and code-cleanup
  • Loading branch information
mauricerenck authored Mar 10, 2019
2 parents 673d45a + 0748099 commit 265079b
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 32 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ For first screens of the panel have a look here: https://maurice-renck.de/de/pro
* ✅ Tracking of downloads using Kirby and the episoden markdown
* ✅ Tracking of downloads using Kirby and MySQL
* ✅ Tracking of episodes/feeds using Matomo
* Statistics view in Panel
* Snippet for Podlove Subscribe box


Expand Down
6 changes: 4 additions & 2 deletions blueprints/files/podcaster-episode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ type: fields
fields:
episodeTitle:
label: Episode Title
type: test
type: text
width: 1/2
duration:
label: Duration
type: text
type: text
width: 1/2
3 changes: 2 additions & 1 deletion blueprints/pages/podcasterfeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ tabs:
html5: Standard HTML5 Player
podlove: Advanced Podlove Player
infoPlayer:
label: Add to Template
type: info
theme: info
text: You need to put the player snippet in your template file. Just add <?php snippet('podcaster-player'); ?> where you want the player to appear.
Expand Down Expand Up @@ -245,7 +246,7 @@ tabs:
- Visible
width: 1/4
podcasterPodloveTabsDownload:
label: Audio Tab
label: Download Tab
type: toggle
default: yes
text:
Expand Down
14 changes: 6 additions & 8 deletions blueprints/tabs/episode.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ label: Episode
columns:
- width: 1/3
sections:
podcasterMp3:
type: files
label: Episode mp3
max: 1
template: podcaster-episode
required: true
podcasterCover:
type: fields
fields:
headlineFiles:
label: Files
type: headline
podcasterMp3:
type: select
label: Episode mp3
options: audio
required: true
podcasterCover:
type: files
label: Cover Image
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"email": "[email protected]"
}
],
"version": "0.1.0",
"version": "0.1.2",
"autoload": {
"files": [
"config.php",
Expand Down
18 changes: 12 additions & 6 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,21 @@
],
'blueprints' => [
'pages/podcasterfeed' => __DIR__ . '/blueprints/pages/podcasterfeed.yml',
'tabs/podcasterepisode' => __DIR__ . '/blueprints/tabs/episode.yml'
'tabs/podcasterepisode' => __DIR__ . '/blueprints/tabs/episode.yml',
'files/podcaster-episode' => __DIR__ . '/blueprints/files/podcaster-episode.yml'
],
'snippets' => [
'podcaster-player' => __DIR__ . '/snippets/podcaster-player.php',
'podcaster-podlove-player' => __DIR__ . '/snippets/podlove-player.php',
'podcaster-html5-player' => __DIR__ . '/snippets/html5-player.php'
'podcaster-html5-player' => __DIR__ . '/snippets/html5-player.php',
'podcaster-ogaudio' => __DIR__ . '/snippets/og-audio.php'
],
'routes' => [
[
'pattern' => '(:all)/' . option('mauricerenck.podcaster.defaultFeed', 'feed'),
'action' => function ($slug) {
$page = page($slug . '/' . option('mauricerenck.podcaster.defaultFeed', 'feed'));
$podcasterUtils = new PodcasterUtils();
$page = $podcasterUtils->getPageFromSlug($slug. '/' . option('mauricerenck.podcaster.defaultFeed', 'feed'));

if(option('mauricerenck.podcaster.statsInternal') === true) {
$stats = new PodcasterStats();
Expand Down Expand Up @@ -67,7 +70,10 @@
[
'pattern' => '(:all)/' . option('mauricerenck.podcaster.downloadTriggerPath', 'download') . '/(:any)',
'action' => function ($slug, $filename) {
$episode = page($slug);

$podcasterUtils = new PodcasterUtils();
$episode = $podcasterUtils->getPageFromSlug($slug);

$podcast = $episode->siblings()->find('feed');

if(option('mauricerenck.podcaster.statsInternal') === true) {
Expand Down Expand Up @@ -107,7 +113,7 @@
],
'hooks' => [
'file.create:after' => function ($file) {
if($file->isAudio()) {
if($file->extension() == 'mp3') {
try {
$audioUtils = new PodcasterAudioUtils();
$audioUtils->setAudioFileMeta($file);
Expand All @@ -117,7 +123,7 @@
}
},
'file.replace:after' => function ($file) {
if ($file->isAudio()) {
if($file->extension() == 'mp3') {
try {
$audioUtils = new PodcasterAudioUtils();
$audioUtils->setAudioFileMeta($file);
Expand Down
2 changes: 1 addition & 1 deletion snippets/html5-player.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require_once __DIR__ . '/../utils/PodcasterUtils.php';

$podcasterUtils = new PodcasterUtils($podcast);
$podcasterUtils = new PodcasterUtils();
$podcasterUtils->setCurrentEpisode($page);
$audioFile = $podcasterUtils->getPodcastFile();
?>
Expand Down
12 changes: 12 additions & 0 deletions snippets/og-audio.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace Plugin\Podcaster;

require_once __DIR__ . '/../utils/PodcasterUtils.php';

$podcasterUtils = new PodcasterUtils();
$podcasterUtils->setCurrentEpisode($page);
$audioFile = $podcasterUtils->getPodcastFile();
?>
<?php if($audioFile !== null) : ?>
<meta property="og:audio" content="<?php echo $page->url() . '/download/' . str_replace('.mp3', '', $audioFile->filename()); ?>">
<?php endif; ?>
9 changes: 5 additions & 4 deletions snippets/podlove-player.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

require_once __DIR__ . '/../utils/PodcasterUtils.php';

$podcasterUtils = new PodcasterUtils($podcast);
$podcasterUtils = new PodcasterUtils();
$podcasterUtils->setFeed($podcast);
$podcasterUtils->setCurrentEpisode($page);

$cover = false;
Expand Down Expand Up @@ -36,17 +37,17 @@
title: '<?php echo $page->podcasterTitle()->or($page->title()); ?>',
subtitle: '<?php echo $page->podcasterSubtitle(); ?>',
summary: '<?php echo $page->podcasterDescription(); ?>',
publicationDate: '<?php echo date('r', $page->date()); ?>',
publicationDate: '<?php echo date('r', $page->date()->toDate()); ?>',
<?php if($cover !== false) : ?>
poster: '<?php echo $page->podcasterCover()->toFile()->resize(200)->url(); ?>',
poster: '<?php echo $cover; ?>',
<?php endif; ?>
link: '<?php echo $page->url(); ?>',
show: {
title: '<?php echo $podcast->podcasterTitle(); ?>',
subtitle: '<?php echo $podcast->podcasterSubtitle(); ?>',
summary: '<?php echo $podcast->podcasterDescription(); ?>',
<?php if($cover !== false) : ?>
poster: '<?php echo $podcast->podcasterCover()->toFile()->url(); ?>',
poster: '<?php echo $cover; ?>',
<?php endif; ?>
link: '<?php echo $podcast->podcasterLink(); ?>'
},
Expand Down
5 changes: 3 additions & 2 deletions templates/podcasterfeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
namespace Plugin\Podcaster;
use c;

$rssUtils = new PodcasterUtils($page);
$rssUtils = new PodcasterUtils();
$rssUtils->setFeed($page);
?>
<?php echo '<?xml version="1.0" encoding="utf-8"?>' . PHP_EOL; ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:cc="http://web.resource.org/cc/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:media="http://search.yahoo.com/mrss/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:psc="http://podlove.org/simple-chapters">
Expand Down Expand Up @@ -55,7 +56,7 @@
<?php endif; ?>

<guid isPermaLink="false"><?php echo $rssUtils->getGuid(); ?></guid>
<pubDate><?php echo date('r', $episode->date()); ?></pubDate>
<pubDate><?php echo date('r', $episode->date()->toDate()); ?></pubDate>
<?php $rssUtils->printFieldValue('episode', 'description', 'podcasterDescription', true); ?>

<?php $rssUtils->printFieldValue('episode', 'itunes:title', 'podcasterTitle'); ?>
Expand Down
3 changes: 2 additions & 1 deletion utils/PodcasterStatsMysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function increaseDownloads($episode, string $trackingDate) {
$downloadDate = $this->formatTrackingDate($trackingDate);
$episodeStats = $this->getEpisodeStats($episode->uid(), $downloadDate);

$podcast = str::slug($episode->siblings()->find(feed)->podcasterTitle());
$podcast = str::slug($episode->siblings()->find('feed')->podcasterTitle());
if(!$episodeStats) {
$this->setDownloads($podcast, $episode->uid(), $downloadDate);
return true;
Expand Down Expand Up @@ -160,4 +160,5 @@ private function updateFeedVisits(string $uid, string $downloadDate) {
private function formatTrackingDate($timestamp): string {
return date('Y-m-d', $timestamp);
}

}
26 changes: 20 additions & 6 deletions utils/PodcasterUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ class PodcasterUtils {
private $rssFeed;
private $episode;

public function __construct($page) {
public function setFeed($page) {
$this->rssFeed = $page;
return true;
}

public function getEpisodes() {
return $this->rssFeed->podcasterSource()->toPage()->children()->listed()->filterBy('date', '<=', time())->filter(function($child) {
return $child->hasAudio();
});
return $this->rssFeed->podcasterSource()
->toPage()
->children()
->listed()
->filter(function ($child) {
return $child->date()->toDate() <= time();
})
->filter(function($child) {
return $child->hasAudio();
})
->sortBy('date', 'desc');
}

public function setCurrentEpisode($episode) {
Expand All @@ -31,7 +39,7 @@ public function getAudioEnclosures($episode): string {
$xmlOutput = [];
$audio = $this->getPodcastFile();

$audioUrl = $episode->url() . '/' . option('mauricerenck.podcaster.downloadTriggerPath') . '/' . $audio->filename();
$audioUrl = $episode->url() . '/' . option('mauricerenck.podcaster.downloadTriggerPath', 'download') . '/' . $audio->filename();
$xmlOutput[] = '<enclosure url="' . $audioUrl .'" length="' . $audio->size() . '" type="audio/mpeg"/>';

return implode("\n", $xmlOutput);
Expand Down Expand Up @@ -120,7 +128,7 @@ public function getChapters() {
}

public function getPodcastFile() {
return $this->episode->audio($this->episode->podcasterMp3())->first();
return $this->episode->audio($this->episode->podcasterMp3()->first())->first();
}

private function parseItunesCategories(): array {
Expand All @@ -139,4 +147,10 @@ private function parseItunesCategories(): array {
return $categories;
}

public function getPageFromSlug($slug) {
$currentLanguage = kirby()->language();
$cleanedSlug = str_replace($currentLanguage . '/', '', $slug);

return page($cleanedSlug);
}
}

0 comments on commit 265079b

Please sign in to comment.