Skip to content

Commit

Permalink
Merge pull request #9 from mauricerenck/develop
Browse files Browse the repository at this point in the history
trying to get along with the 3 install methods…
  • Loading branch information
mauricerenck authored Mar 31, 2019
2 parents 5a5a9c0 + 22a176d commit def344f
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 6 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
"email": "[email protected]"
}
],
"version": "1.0.0",
"version": "1.0.1",
"autoload": {
"files": [
"config.php",
"utils/PodcasterUtils.php",
"utils/PodcasterAudioUtils.php",
"utils/PodcasterStats.php",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

161 changes: 160 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,161 @@
<?php
require_once __DIR__ . '/vendor/autoload.php';
namespace Plugin\Podcaster;
use Kirby;
use Kirby\Exception\Exception;
use \PiwikTracker;
use Kirby\Http\Response;

// load([
// 'distantnative\\Retour\\Log' => 'models/Log.php',
// 'distantnative\\Retour\\Logs' => 'models/Logs.php',
// 'distantnative\\Retour\\Redirects' => 'models/Redirects.php',
// 'distantnative\\Retour\\Stats' => 'models/Stats.php',
// 'distantnative\\Retour\\System' => 'models/System.php'
// ], __DIR__);

Kirby::plugin('mauricerenck/podcaster', [
'options' => [
'statsInternal' => false,
'statsType' => 'mysql',
'statsHost' => null,
'statsDatabase' => null,
'statsUser' => null,
'statsPassword' => null,
'matomoToken' => null,
'matomoBaseUrl' => null
],
'templates' => [
'podcasterfeed' => __DIR__ . '/templates/podcasterfeed.php'
],
'blueprints' => [
'pages/podcasterfeed' => __DIR__ . '/blueprints/pages/podcasterfeed.yml',
'tabs/podcasterepisode' => __DIR__ . '/blueprints/tabs/episode.yml',
'files/podcaster-episode' => __DIR__ . '/blueprints/files/podcaster-episode.yml'
],
'sections' => [
'podcaster-stats' => [
'props' => [
'headline' => function ($headline = 'Last modified') {
return $headline;
}
]
]
],
'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-ogaudio' => __DIR__ . '/snippets/og-audio.php'
],
'routes' => [
[
'pattern' => '(:all)/podcaster-feed-style',
'action' => function () {
$string = file_get_contents(__DIR__ . '/res/feed-style.xsl');
return new Response($string, 'text/xml');
}
],
[
'pattern' => '(:all)/' . option('mauricerenck.podcaster.defaultFeed', 'feed'),
'action' => function ($slug) {
$podcasterUtils = new PodcasterUtils();
$page = $podcasterUtils->getPageFromSlug($slug. '/' . option('mauricerenck.podcaster.defaultFeed', 'feed'));

if(option('mauricerenck.podcaster.statsInternal') === true) {
$stats = new PodcasterStats();
$trackingDate = time();
$stats->increaseFeedVisits($page, $trackingDate);
}

if($page->podcasterMatomoFeedEnabled()->isTrue()) {
$matomo = new PiwikTracker($page->podcasterMatomoFeedSiteId(), option('mauricerenck.podcaster.matomoBaseUrl'));

$matomo->setTokenAuth(option('mauricerenck.podcaster.matomoToken'));
$matomo->disableSendImageResponse();
$matomo->disableCookieSupport();
$matomo->setUrl($page->url());
$matomo->setIp($_SERVER['REMOTE_ADDR']);

if($page->podcasterMatomoFeedGoalId()->isNotEmpty()) {
$matomo->doTrackGoal($page->podcasterMatomoFeedGoalId(), 1);
}

if($page->podcasterMatomoFeedEventName()->isNotEmpty()) {
$matomo->doTrackEvent($page->podcasterTitle(), $page->podcasterMatomoFeedEventName(), 1);
}

if($page->podcasterMatomoFeedAction()->isTrue()) {
$matomo->doTrackAction($page->url(), 'download');
}
}

return new Response($page->render(), 'text/xml');
}
],
[
'pattern' => '(:all)/' . option('mauricerenck.podcaster.downloadTriggerPath', 'download') . '/(:any)',
'action' => function ($slug, $filename) {

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

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

if(option('mauricerenck.podcaster.statsInternal') === true) {
$stats = new PodcasterStats();
$trackingDate = time();
$stats->increaseDownloads($episode, $trackingDate);
}

if($podcast->podcasterMatomoEnabled()->isTrue()) {
$matomo = new PiwikTracker($podcast->podcasterMatomoSiteId(), option('mauricerenck.podcaster.matomoBaseUrl'));

// setup
$matomo->setTokenAuth(option('mauricerenck.podcaster.matomoToken'));
$matomo->disableSendImageResponse();
$matomo->disableCookieSupport();
$matomo->setUrl($episode->url());
$matomo->setIp($_SERVER['REMOTE_ADDR']);

if($podcast->podcasterMatomoGoalId()->isNotEmpty()) {
$matomo->doTrackGoal($podcast->podcasterMatomoGoalId(), 1);
}

if($podcast->podcasterMatomoEventName()->isNotEmpty()) {
$matomo->doTrackEvent($podcast->podcasterTitle(), $episode->title(), $podcast->podcasterMatomoEventName());
}

if($podcast->podcasterMatomoAction()->isTrue()) {
$matomo->doTrackAction($episode->url(), 'download');
}
}

$filename = str_replace('.mp3', '', $filename);
return $podcasterUtils->getPodcastFile();
}
]
],
'hooks' => [
'file.create:after' => function ($file) {
if($file->extension() == 'mp3') {
try {
$audioUtils = new PodcasterAudioUtils();
$audioUtils->setAudioFileMeta($file);
} catch(Exception $e) {
throw new Exception(array('details' => 'the audio id3 data could not be read'));
}
}
},
'file.replace:after' => function ($file) {
if($file->extension() == 'mp3') {
try {
$audioUtils = new PodcasterAudioUtils();
$audioUtils->setAudioFileMeta($file);
} catch (Exception $e) {
throw new Exception(array('details' => 'the audio id3 data could not be read'));
}
}
}
]
]);
1 change: 0 additions & 1 deletion vendor/composer/autoload_files.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
return array(
'320cde22f66dd4f5d3fd621d3e88b98f' => $vendorDir . '/symfony/polyfill-ctype/bootstrap.php',
'6124b4c8570aa390c21fafd04a26c69f' => $vendorDir . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'ed5eafd960033377637fa9e405d3c2a7' => $baseDir . '/config.php',
'8df3dfd1f38b5f54e639d8aee9e2bd5b' => $baseDir . '/utils/PodcasterUtils.php',
'aa1a9ddc5c71d010b159c1768f7031e2' => $baseDir . '/utils/PodcasterAudioUtils.php',
'1a1828adf062a2860974d695d05734cf' => $baseDir . '/utils/PodcasterStats.php',
Expand Down
1 change: 0 additions & 1 deletion vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ComposerStaticInitf221e7d41fb5f9d943f848bde0ca9936
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
'6124b4c8570aa390c21fafd04a26c69f' => __DIR__ . '/..' . '/myclabs/deep-copy/src/DeepCopy/deep_copy.php',
'ed5eafd960033377637fa9e405d3c2a7' => __DIR__ . '/../..' . '/config.php',
'8df3dfd1f38b5f54e639d8aee9e2bd5b' => __DIR__ . '/../..' . '/utils/PodcasterUtils.php',
'aa1a9ddc5c71d010b159c1768f7031e2' => __DIR__ . '/../..' . '/utils/PodcasterAudioUtils.php',
'1a1828adf062a2860974d695d05734cf' => __DIR__ . '/../..' . '/utils/PodcasterStats.php',
Expand Down

0 comments on commit def344f

Please sign in to comment.