-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin.php
117 lines (93 loc) · 3.6 KB
/
plugin.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
<?php
/**
This is the PodcastAudioPlugin plugin.
This file contains the PodcastAudioPlugin plugin. It provides an audio player
feature and a shortcode for the display of the audio player.
@package urlaube\podcastaudioplugin
@version 0.1a0
@author Yahe <[email protected]>
@since 0.1a0
*/
// ===== DO NOT EDIT HERE =====
// prevent script from getting called directly
if (!defined("URLAUBE")) { die(""); }
class PodcastAudioPlugin extends BaseSingleton implements Plugin {
// CONSTANTS
const PODCAST_IMAGE = "podcast_image";
const AUDIOIMAGE = "audioimage";
const ENCLOSURE = "enclosure";
const ENCLOSURETYPE = "enclosuretype";
const IMAGE = "image";
// HELPER FUNCTIONS
protected static function getAudioPlayer($item) {
$result = value($item, CONTENT);
if (is_string($result)) {
// retrieve the audio file
$audiofile = value($item, self::ENCLOSURE);
$audiotype = value($item, self::ENCLOSURETYPE);
// retrieve the background image
$background = value($item, self::AUDIOIMAGE);
if (null === $background) {
$background = value($item, self::IMAGE);
}
if (null === $background) {
$background = value(Handlers::class, self::PODCAST_IMAGE);
}
// we at least need the audio file
if (null !== $audiofile) {
// generate audio player source code
$audioplayer = fhtml("<link href=\"%s\" rel=\"stylesheet\">".NL,
path2uri(__DIR__."/css/style.css"));
// insert the background image
if (null !== $background) {
$audioplayer .= fhtml("<div class=\"podcastaudio podcastaudio-image\">".NL.
" <img src=\"%s\" alt=\"podcast image\">".NL,
$background);
} else {
$audioplayer .= fhtml("<div class=\"podcastaudio\">".NL);
}
// insert the audio file
if (null !== $audiotype) {
$audioplayer .= fhtml(" <audio controls preload=\"metadata\">".NL.
" <source src=\"%s\" type=\"%s\">".NL.
" </audio>".NL.
"</div>",
$audiofile,
$audiotype);
} else {
$audioplayer .= fhtml(" <audio controls preload=\"metadata\">".NL.
" <source src=\"%s\">".NL.
" </audio>".NL.
"</div>",
$audiofile);
}
// replace shortcode with audio player
$result = str_ireplace("[podcastaudio]", $audioplayer, $result);
}
}
return $result;
}
// RUNTIME FUNCTIONS
public static function plugin($content) {
$result = $content;
if ($result instanceof Content) {
if ($result->isset(CONTENT)) {
$result->set(CONTENT, static::getAudioPlayer($result));
}
} else {
if (is_array($result)) {
// iterate through all content items
foreach ($result as $result_item) {
if ($result_item instanceof Content) {
if ($result_item->isset(CONTENT)) {
$result_item->set(CONTENT, static::getAudioPlayer($result_item));
}
}
}
}
}
return $result;
}
}
// register plugin
Plugins::register(PodcastAudioPlugin::class, "plugin", FILTER_CONTENT);