-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.php
152 lines (125 loc) · 6.35 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
namespace mauricerenck\Podcaster;
use Kirby;
use Kirby\Http\Response;
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('mauricerenck/podcaster', [
'options' => require_once(__DIR__ . '/internal/options.php'),
'blueprints' => [
'pages/podcasterfeed' => __DIR__ . '/blueprints/pages/feed.yml',
'tabs/podcasterepisode' => __DIR__ . '/blueprints/tabs/episode.yml', // backwards compatibility
'tabs/podcaster/episode' => __DIR__ . '/blueprints/tabs/episode.yml',
'tabs/podcaster/feed-base' => __DIR__ . '/blueprints/tabs/feed-base.yml',
'tabs/podcaster/feed-details' => __DIR__ . '/blueprints/tabs/feed-details.yml',
'tabs/podcaster/feed-stats' => __DIR__ . '/blueprints/tabs/feed-stats.yml',
'tabs/podcaster/feed-player' => __DIR__ . '/blueprints/tabs/feed-player.yml',
'tabs/podcaster/feed-tracking' => __DIR__ . '/blueprints/tabs/feed-tracking.yml',
'files/podcaster-episode' => __DIR__ . '/blueprints/files/podcaster-episode.yml',
'files/podcaster-cover' => __DIR__ . '/blueprints/files/podcaster-cover.yml',
'sections/podcastermp3' => function () {
return (option('mauricerenck.podcaster.compatibilityMode', false)) ? __DIR__ . '/blueprints/sections/podcastermp3.yml' : __DIR__ . '/blueprints/sections/empty.yml';
},
'sections/podcasterimage' => function () {
return (option('mauricerenck.podcaster.compatibilityMode', false)) ? __DIR__ . '/blueprints/sections/podcasterimage.yml' : __DIR__ . '/blueprints/sections/empty2.yml';
},
],
'templates' => [
'podcasterfeed' => __DIR__ . '/templates/podcasterfeed.php',
],
'pageMethods' => require_once __DIR__ . '/app/PageMethods.php',
'siteMethods' => require_once __DIR__ . '/app/SiteMethods.php',
'fileTypes' => require_once __DIR__ . '/app/FileTypes.php',
'api' => require_once(__DIR__ . '/internal/api.php'),
'hooks' => require_once(__DIR__ . '/internal/hooks.php'),
'areas' => require_once(__DIR__ . '/internal/areas.php'),
'snippets' => [
'podcaster-feed-header' => __DIR__ . '/snippets/xml/xml-header.php',
'podcaster-feed-cover' => __DIR__ . '/snippets/xml/channel-cover.php',
'podcaster-feed-author' => __DIR__ . '/snippets/xml/channel-author.php',
'podcaster-feed-owner' => __DIR__ . '/snippets/xml/channel-owner.php',
'podcaster-feed-description' => __DIR__ . '/snippets/xml/channel-description.php',
'podcaster-feed-categories' => __DIR__ . '/snippets/xml/channel-categories.php',
'podcaster-feed-item' => __DIR__ . '/snippets/xml/item.php',
'podcaster-feed-item-cover' => __DIR__ . '/snippets/xml/item-cover.php',
'podcaster-feed-item-chapter' => __DIR__ . '/snippets/xml/item-chapter.php',
'podcaster-feed-item-enclosure' => __DIR__ . '/snippets/xml/item-enclosure.php',
'podcaster-feed-item-transcript' => __DIR__ . '/snippets/xml/item-transcript.php',
'podcaster-player' => __DIR__ . '/snippets/frontend/player.php',
'podcaster-podlove-player' => __DIR__ . '/snippets/frontend/podlove-player.php',
'podcaster-html5-player' => __DIR__ . '/snippets/frontend/html5-player.php',
'podcaster-ogaudio' => __DIR__ . '/snippets/frontend/og-audio.php',
],
'routes' => [
[
'pattern' => '(:all)/' . option('mauricerenck.podcaster.defaultFeed', 'feed'),
'action' => function ($slug) {
$podcast = new Podcast();
$feedParent = $podcast->getPageFromSlug($slug);
$feed = $feedParent->children()->filterBy('intendedTemplate', 'podcasterfeed')->first();
if (!isset($feed)) {
$this->next();
}
$dbType = option('mauricerenck.podcaster.statsType', 'sqlite');
switch ($dbType) {
case 'sqlite':
$stats = new PodcasterStatsSqlite();
break;
case 'mysql':
$stats = new PodcasterStatsMysql();
break;
default:
$stats = new PodcasterStats();
break;
}
$stats->trackFeed($feed);
return new Response($feed->render(), 'text/xml');
},
],
[
'pattern' => '(:all)/' . option('mauricerenck.podcaster.downloadTriggerPath', 'download') . '/(:any)',
'action' => function ($slug) {
$podcast = new Podcast();
$dbType = option('mauricerenck.podcaster.statsType', 'sqlite');
switch ($dbType) {
case 'sqlite':
$stats = new PodcasterStatsSqlite();
break;
case 'mysql':
$stats = new PodcasterStatsMysql();
break;
default:
$stats = new PodcasterStats();
break;
}
$userAgent = $_SERVER['HTTP_USER_AGENT'];
$episode = $podcast->getPageFromSlug($slug);
if (!isset($episode)) {
$this->next();
}
$feed = $podcast->getFeedOfEpisode($episode);
if (!isset($feed)) {
$this->next();
}
$stats->trackEpisode($feed, $episode, $userAgent);
// $stats->calculateCarbonEmissions($feed, $episode);
return $podcast->getAudioFile($episode);
},
],
[
'pattern' => 'podcaster/podlove/config/(:all)',
'action' => function ($episodeSlug) {
$podcast = new Podcast();
$episode = $podcast->getPageFromSlug($episodeSlug);
return new Response(json_encode($podcast->getPodloveConfigJson($episode)), 'application/json');
}
],
[
'pattern' => 'podcaster/podlove/episode/(:all)',
'action' => function ($episodeSlug) {
$podcast = new Podcast();
$episode = $podcast->getPageFromSlug($episodeSlug);
return new Response(json_encode($podcast->getPodloveEpisodeJson($episode)), 'application/json');
}
],
],
]);