-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUSAGE_EXAMPLES.php
More file actions
267 lines (203 loc) · 6.42 KB
/
Copy pathUSAGE_EXAMPLES.php
File metadata and controls
267 lines (203 loc) · 6.42 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<?php
/**
* Beispiel: Podcastmanager Standalone Nutzung
*
* Dieses Snippet zeigt, wie man die podcastmanager Addon-Klassen
* unabhängig von Modulen/Templates verwenden kann.
*
* Diese Beispiele können als Redaxo Console Snippets verwendet werden:
* php bin/console project:run-snippet "$(cat path/to/this/file.php)"
*/
// ============================================
// Beispiel 1: Frontend Output rendern
// ============================================
// Overview aller Episoden
$output = new PodcastOutput([
'mode' => 'overview',
'limit' => 10,
'show_teaser' => true,
'show_audio' => true,
]);
echo $output->renderWithAssets();
// ============================================
// Beispiel 2: Start-Seite (Featured + Teaser)
// ============================================
$output = new PodcastOutput([
'mode' => 'start',
'show_teaser' => true,
'show_audio' => true,
]);
echo $output->render();
// ============================================
// Beispiel 3: Einzelne Episode detailliert
// ============================================
$_GET['id'] = 5; // Episode mit ID 5
$output = new PodcastOutput([
'mode' => 'detail',
'show_audio' => true,
]);
echo $output->render();
// ============================================
// Beispiel 4: RSS Feed generieren
// ============================================
// iTunes Podcast Feed
$rss = new PodcastRSS();
$feed = $rss->generate('itunes');
// $feed exportieren oder speichern
// oder klassisches RSS 2.0
$feed_rss2 = $rss->generate('rss2');
// ============================================
// Beispiel 5: Nur HTML (ohne Assets)
// ============================================
$output = new PodcastOutput([
'mode' => 'overview',
'limit' => 5,
]);
$html = $output->render(); // Nur das HTML
// ============================================
// Beispiel 6: Mit Custom Konfiguration
// ============================================
$config = [
'mode' => 'overview',
'show_teaser' => false, // Ohne Teaser Text
'limit' => 15, // 15 Episodes
'show_audio' => false, // Kein Player
'width' => 6, // 50% Breite
];
$output = new PodcastOutput($config);
echo $output->render();
// ============================================
// Beispiel 7: Dynamische Konfiguration
// ============================================
// Je nach Seite different Einstellungen
$page = rex_request('page', 'string', 'overview');
$config = [
'mode' => $page === 'featured' ? 'start' : 'overview',
'limit' => $page === 'featured' ? 3 : 20,
'show_teaser' => $page !== 'featured',
'show_audio' => $page !== 'featured',
];
$output = new PodcastOutput($config);
echo $output->render();
// ============================================
// Beispiel 8: Episoden für API ausgeben
// ============================================
// JSON API für Frontend Framework
$output = new PodcastOutput([
'mode' => 'overview',
'limit' => 50,
]);
$html = $output->render();
// Alternativ: Rohe Episoden auslesen
$episodes = rex_sql::factory()->getArray(
'SELECT * FROM rex_podcastmanager
WHERE status = 1
ORDER BY STR_TO_DATE(publishdate, "%d.%m.%Y") DESC
LIMIT 50'
);
foreach ($episodes as &$item) {
$item = podcastmanager::prepare($item);
}
echo json_encode($episodes);
// ============================================
// Beispiel 9: Multiple Ausgaben auf einer Seite
// ============================================
// Featured Episodes
$featured = new PodcastOutput([
'mode' => 'start',
'show_audio' => true,
]);
// Recent Episodes
$recent = new PodcastOutput([
'mode' => 'overview',
'limit' => 5,
'show_teaser' => false,
'show_audio' => false,
]);
echo $featured->render();
echo $recent->render();
// ============================================
// Beispiel 10: Mit Custom HTML Wrapper
// ============================================
$output = new PodcastOutput([
'mode' => 'overview',
'limit' => 10,
]);
$html = '
<div class="custom-podcast-wrapper">
<h2>Unsere Podcast Episoden</h2>
' . $output->render() . '
</div>
';
echo $html;
// ============================================
// Beispiel 11: Fehlerbehandlung
// ============================================
try {
$output = new PodcastOutput([
'mode' => 'overview',
]);
$html = $output->render();
if (empty($html)) {
echo '<p>Keine Episoden gefunden.</p>';
} else {
echo $html;
}
} catch (Exception $e) {
echo '<p>Fehler beim Laden der Episoden: ' . htmlspecialchars($e->getMessage()) . '</p>';
}
// ============================================
// Beispiel 12: Caching
// ============================================
$cache_key = 'podcast_episodes_overview_10';
// Aus Cache laden wenn vorhanden
if ($cached = rex_cache::get($cache_key)) {
echo $cached;
} else {
// Neu generieren wenn nicht im Cache
$output = new PodcastOutput([
'mode' => 'overview',
'limit' => 10,
]);
$html = $output->renderWithAssets();
// 1 Stunde cachen (3600 Sekunden)
rex_cache::set($cache_key, $html, 3600);
echo $html;
}
// ============================================
// Beispiel 13: In Fragment verwenden
// ============================================
// In einem Fragment podcast.php
$output = new PodcastOutput([
'mode' => rex_var::get('mode', 'overview'),
'limit' => rex_var::get('limit', ''),
'show_teaser' => (bool)rex_var::get('show_teaser', true),
'show_audio' => (bool)rex_var::get('show_audio', true),
]);
return $output->render();
// ============================================
// Beispiel 14: Debug Informationen
// ============================================
$output = new PodcastOutput([
'mode' => 'overview',
]);
// Config auslesen
$config = $output->getConfig(); // Falls diese Method existiert
echo '<pre>Konfiguration: ' . print_r($config, true) . '</pre>';
// HTML ausgeben
echo $output->render();
// ============================================
// Beispiel 15: Extension Integration
// ============================================
// Als Extension Hook
rex_extension::register('POD_OUTPUT_RENDER', function(rex_extension_point $ep) {
$config = $ep->getParam('config');
$output = new PodcastOutput($config);
return $output->render();
});
// Später im Code:
$html = rex_extension::registerPoint(new rex_extension_point(
'POD_OUTPUT_RENDER',
'',
['config' => ['mode' => 'overview']]
));