2 Commits
1.0 ... 1.1

Author SHA1 Message Date
056cf4d287 festive-seasons-pro.php aktualisiert 2026-01-06 23:30:11 +00:00
af031542e9 festive-seasons-pro.php aktualisiert 2025-12-10 09:35:33 +00:00

View File

@@ -1,419 +1,444 @@
<?php <?php
/* /*
Plugin Name: Festive Seasons Pro (Clean & Robust) Plugin Name: Festive Seasons Pro
Description: Zeigt saisonale Effekte (Schnee, Eier, Spinnen, Ballons, Feuerwerk) für feste Feiertage und individuelle Geburtstage an. Description: Zeigt saisonale Effekte (Schnee, Eier, Spinnen, Ballons, Feuerwerk) für feste Feiertage und individuelle Geburtstage an.
Version: 3.4 Version: 1.1
Author: M_Viper Author: M_Viper
*/ */
if (!defined('ABSPATH')) { if (!defined('ABSPATH')) {
exit; exit;
} }
class Festive_Seasons_Pro { class Festive_Seasons_Pro {
public function __construct() { public function __construct() {
add_action('init', [$this, 'init_plugin']); add_action('init', [$this, 'init_plugin']);
} }
public function init_plugin() { public function init_plugin() {
add_action('wp_enqueue_scripts', [$this, 'load_assets']); add_action('wp_enqueue_scripts', [$this, 'load_assets']);
add_action('wp_footer', [$this, 'render_music_consent']); add_action('wp_footer', [$this, 'render_music_consent']);
add_action('admin_menu', [$this, 'add_admin_menu_page']); add_action('admin_menu', [$this, 'add_admin_menu_page']);
add_action('admin_init', [$this, 'register_settings']); add_action('admin_init', [$this, 'register_settings']);
add_action('widgets_init', [$this, 'register_widget']); add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']);
add_shortcode('festive_event', [$this, 'render_shortcode']); add_action('widgets_init', [$this, 'register_widget']);
} add_shortcode('festive_event', [$this, 'render_shortcode']);
}
public function get_active_events() {
if (isset($_GET['fsp_test_date'])) { // Admin-Scripts laden
$today = sanitize_text_field($_GET['fsp_test_date']); public function enqueue_admin_scripts($hook) {
} else { // Nur auf der Plugin-Einstellungsseite laden
$today = date('Y-m-d'); if ($hook !== 'settings_page_festive-seasons-pro') {
} return;
}
$active_events = [];
// jQuery ist standardmäßig in WordPress verfügbar
foreach ($this->get_fixed_events() as $event_key => $event_data) { wp_enqueue_script('jquery');
if (isset($event_data['start'], $event_data['end']) && $today >= $event_data['start'] && $today <= $event_data['end']) {
if (get_option("fsp_fixed_{$event_key}", 'yes') === 'yes') { // Inline-Script für Event-Verwaltung
$active_events[] = $event_data; wp_add_inline_script('jquery', '
} jQuery(document).ready(function($) {
} // Neues Ereignis hinzufügen
} $("#fsp-add-event").on("click", function() {
var index = $("#fsp-events-container .fsp-event-row").length;
foreach ($this->get_custom_events($today) as $event_data) { var newRow = \'<div class="fsp-event-row" style="margin-bottom: 10px; display: flex; gap: 10px; align-items: center;">\' +
$active_events[] = $event_data; \'<input type="text" name="fsp_events[\' + index + \'][name]" placeholder="Name (z.B. Max)" style="width: 200px;" />\' +
} \'<input type="text" name="fsp_events[\' + index + \'][date]" placeholder="Datum (TT-MM)" style="width: 100px;" />\' +
\'<input type="text" name="fsp_events[\' + index + \'][text]" placeholder="Text (z.B. wird 30!)" style="flex-grow: 1;" />\' +
return $active_events; \'<button type="button" class="button button-secondary fsp-remove-event">Entfernen</button>\' +
} \'</div>\';
$("#fsp-events-container").append(newRow);
private function get_fixed_events() { });
$test_year = isset($_GET['fsp_test_date']) ? substr(sanitize_text_field($_GET['fsp_test_date']), 0, 4) : date('Y');
$year = is_numeric($test_year) ? $test_year : date('Y'); // Ereignis entfernen
$easter_date = date('Y-m-d', easter_date($year)); $(document).on("click", ".fsp-remove-event", function() {
$(this).closest(".fsp-event-row").remove();
return [ });
'advent' => ['name' => 'Adventszeit', 'start' => "$year-12-01", 'end' => "$year-12-23", 'class' => 'festive-advent', 'effects' => ['snow']], });
'christmas' => ['name' => 'Weihnachten', 'start' => "$year-12-24", 'end' => "$year-12-26", 'class' => 'festive-christmas', 'effects' => ['snow', 'music', 'star', 'santa']], // NEU: Santa-Animation ');
'newyear' => ['name' => 'Silvester', 'start' => "$year-12-31", 'end' => ($year + 1) . "-01-01", 'class' => 'festive-newyear', 'effects' => ['newyear_fireworks']], }
'halloween' => ['name' => 'Halloween', 'start' => "$year-10-31", 'end' => "$year-10-31", 'class' => 'festive-halloween', 'effects' => ['spiders']],
'easter' => ['name' => 'Ostern', 'start' => date('Y-m-d', strtotime($easter_date . ' -1 day')), 'end' => date('Y-m-d', strtotime($easter_date)), 'class' => 'festive-easter', 'effects' => ['eggs']], public function get_active_events() {
]; if (isset($_GET['fsp_test_date'])) {
} $today = sanitize_text_field($_GET['fsp_test_date']);
} else {
private function get_custom_events($today) { $today = date('Y-m-d');
$custom_events = get_option('fsp_events', []); }
$active_custom_events = [];
$today_day_month = date('m-d', strtotime($today)); $active_events = [];
if (is_array($custom_events)) { foreach ($this->get_fixed_events() as $event_key => $event_data) {
foreach ($custom_events as $event) { if (isset($event_data['start'], $event_data['end']) && $today >= $event_data['start'] && $today <= $event_data['end']) {
if (empty($event['date']) || !is_array($event)) continue; if (get_option("fsp_fixed_{$event_key}", 'yes') === 'yes') {
$event_date = sanitize_text_field($event['date']); $active_events[] = $event_data;
$date_obj = DateTime::createFromFormat('d-m', $event_date) ?: DateTime::createFromFormat('Y-m-d', $event_date); }
if ($date_obj && $date_obj->format('m-d') === $today_day_month) { }
$name = trim(($event['name'] ?? '') . ' ' . ($event['text'] ?? '')); }
$active_custom_events[] = [
'name' => $name ?: 'Besonderer Tag!', foreach ($this->get_custom_events($today) as $event_data) {
'class' => 'festive-birthday', $active_events[] = $event_data;
'effects' => ['balloons', 'confetti'] }
];
} return $active_events;
} }
}
return $active_custom_events; private function get_fixed_events() {
} $test_year = isset($_GET['fsp_test_date']) ? substr(sanitize_text_field($_GET['fsp_test_date']), 0, 4) : date('Y');
$year = is_numeric($test_year) ? $test_year : date('Y');
public function load_assets() { $easter_date = date('Y-m-d', easter_date($year));
$active_events = $this->get_active_events();
if (empty($active_events)) return; return [
'advent' => ['name' => 'Adventszeit', 'start' => "$year-12-01", 'end' => "$year-12-23", 'class' => 'festive-advent', 'effects' => ['snow']],
$body_classes = []; 'christmas' => ['name' => 'Weihnachten', 'start' => "$year-12-24", 'end' => "$year-12-26", 'class' => 'festive-christmas', 'effects' => ['snow', 'music', 'star', 'santa']],
$effects_to_load = []; 'newyear' => ['name' => 'Silvester', 'start' => "$year-12-31", 'end' => ($year + 1) . "-01-01", 'class' => 'festive-newyear', 'effects' => ['newyear_fireworks']],
'halloween' => ['name' => 'Halloween', 'start' => "$year-10-31", 'end' => "$year-10-31", 'class' => 'festive-halloween', 'effects' => ['spiders']],
foreach ($active_events as $event) { 'easter' => ['name' => 'Ostern', 'start' => date('Y-m-d', strtotime($easter_date . ' -1 day')), 'end' => date('Y-m-d', strtotime($easter_date)), 'class' => 'festive-easter', 'effects' => ['eggs']],
if (!empty($event['class'])) $body_classes[] = $event['class']; ];
if (!empty($event['effects'])) $effects_to_load = array_merge($effects_to_load, $event['effects']); }
}
private function get_custom_events($today) {
add_filter('body_class', function($classes) use ($body_classes) { $custom_events = get_option('fsp_events', []);
return array_merge($classes, array_unique($body_classes)); $active_custom_events = [];
}); $today_day_month = date('m-d', strtotime($today));
wp_enqueue_style('fsp-style', plugin_dir_url(__FILE__) . 'assets/css/festive.css', [], '3.4'); if (is_array($custom_events)) {
wp_enqueue_script('jquery'); foreach ($custom_events as $event) {
if (empty($event['date']) || !is_array($event)) continue;
wp_localize_script('jquery', 'fsp_vars', [ $event_date = sanitize_text_field($event['date']);
'plugin_url' => plugin_dir_url(__FILE__) $date_obj = DateTime::createFromFormat('d-m', $event_date) ?: DateTime::createFromFormat('Y-m-d', $event_date);
]); if ($date_obj && $date_obj->format('m-d') === $today_day_month) {
$name = trim(($event['name'] ?? '') . ' ' . ($event['text'] ?? ''));
if (in_array('confetti', $effects_to_load) || in_array('newyear_fireworks', $effects_to_load)) { $active_custom_events[] = [
wp_enqueue_script('fsp-confetti-lib', plugin_dir_url(__FILE__) . 'assets/js/canvas-confetti.min.js', [], '3.4', true); 'name' => $name ?: 'Besonderer Tag!',
} 'class' => 'festive-birthday',
'effects' => ['balloons', 'confetti']
foreach (array_unique($effects_to_load) as $effect) { ];
switch ($effect) { }
case 'snow': }
wp_enqueue_script('fsp-snow', plugin_dir_url(__FILE__) . 'assets/js/snowstorm.js', [], '3.4', true); }
break; return $active_custom_events;
case 'confetti': }
wp_add_inline_script('fsp-confetti-lib', 'jQuery(document).ready(function($) { setTimeout(() => confetti({particleCount: 200, spread: 120, origin: { y: 0.6 } }), 1000); });');
break; public function load_assets() {
case 'eggs': $active_events = $this->get_active_events();
wp_enqueue_script('fsp-eggs', plugin_dir_url(__FILE__) . 'assets/js/easter-eggs.js', ['jquery'], '3.4', true); if (empty($active_events)) return;
break;
case 'spiders': $body_classes = [];
wp_enqueue_script('fsp-spiders', plugin_dir_url(__FILE__) . 'assets/js/halloween-spiders.js', ['jquery'], '3.4', true); $effects_to_load = [];
break;
case 'balloons': foreach ($active_events as $event) {
wp_enqueue_script('fsp-balloons', plugin_dir_url(__FILE__) . 'assets/js/balloons.js', ['jquery'], '3.4', true); if (!empty($event['class'])) $body_classes[] = $event['class'];
break; if (!empty($event['effects'])) $effects_to_load = array_merge($effects_to_load, $event['effects']);
case 'star': }
wp_enqueue_script('fsp-star', plugin_dir_url(__FILE__) . 'assets/js/christmas-star.js', ['jquery'], '3.4', true);
break; add_filter('body_class', function($classes) use ($body_classes) {
case 'santa': // NEU: Santa-Animation return array_merge($classes, array_unique($body_classes));
wp_enqueue_script('fsp-santa', plugin_dir_url(__FILE__) . 'assets/js/santa-sleigh.js', ['jquery'], '3.4', true); });
break;
case 'newyear_fireworks': wp_enqueue_style('fsp-style', plugin_dir_url(__FILE__) . 'assets/css/festive.css', [], '3.4');
$this->add_newyear_script(); wp_enqueue_script('jquery');
break;
} wp_localize_script('jquery', 'fsp_vars', [
} 'plugin_url' => plugin_dir_url(__FILE__)
} ]);
private function add_newyear_script() { if (in_array('confetti', $effects_to_load) || in_array('newyear_fireworks', $effects_to_load)) {
$script = ' wp_enqueue_script('fsp-confetti-lib', plugin_dir_url(__FILE__) . 'assets/js/canvas-confetti.min.js', [], '3.4', true);
jQuery(document).ready(function($) { }
if (!$("body").hasClass("festive-newyear")) {
return; foreach (array_unique($effects_to_load) as $effect) {
} switch ($effect) {
if (typeof confetti === "undefined") { case 'snow':
console.error("FSP: Konfetti-Bibliothek nicht gefunden."); wp_enqueue_script('fsp-snow', plugin_dir_url(__FILE__) . 'assets/js/snowstorm.js', [], '3.4', true);
return; break;
} case 'confetti':
wp_add_inline_script('fsp-confetti-lib', 'jQuery(document).ready(function($) { setTimeout(() => confetti({particleCount: 200, spread: 120, origin: { y: 0.6 } }), 1000); });');
function runBigFireworks() { break;
var count = 250; case 'eggs':
var defaults = { origin: { y: 0.7 }, zIndex: 999999, colors: ["#bb0000", "#ffffff", "#ff0000", "#ffbb00", "#ffee00", "#00ff00", "#0099ff", "#0000ff"] }; wp_enqueue_script('fsp-eggs', plugin_dir_url(__FILE__) . 'assets/js/easter-eggs.js', ['jquery'], '3.4', true);
function fire(particleRatio, opts) { break;
confetti(Object.assign({}, defaults, opts, { particleCount: Math.floor(count * particleRatio) })); case 'spiders':
} wp_enqueue_script('fsp-spiders', plugin_dir_url(__FILE__) . 'assets/js/halloween-spiders.js', ['jquery'], '3.4', true);
fire(0.25, { spread: 26, startVelocity: 55 }); break;
fire(0.2, { spread: 60 }); case 'balloons':
fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 }); wp_enqueue_script('fsp-balloons', plugin_dir_url(__FILE__) . 'assets/js/balloons.js', ['jquery'], '3.4', true);
fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 }); break;
fire(0.1, { spread: 120, startVelocity: 45 }); case 'star':
wp_enqueue_script('fsp-star', plugin_dir_url(__FILE__) . 'assets/js/christmas-star.js', ['jquery'], '3.4', true);
var rainDefaults = { origin: { y: 0 }, angle: 90, drift: 0, gravity: 1.2, scalar: 1.2, zIndex: 999999 }; break;
confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.1, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] })); case 'santa':
confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.5, colors: ["#bb0000", "#ffffff", "#ffbb00", "#ffee00"] })); wp_enqueue_script('fsp-santa', plugin_dir_url(__FILE__) . 'assets/js/santa-sleigh.js', ['jquery'], '3.4', true);
confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.9, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] })); break;
} case 'newyear_fireworks':
$this->add_newyear_script();
function createRocket(isLastRocket) { break;
const startX = Math.random() * window.innerWidth; }
}
const $rocket = $("<div class=\"fsp-rocket\"></div>").css({ }
position: "fixed",
width: "6px", private function add_newyear_script() {
height: "25px", $script = '
background: "linear-gradient(to top, #ff4500, #ffa500)", jQuery(document).ready(function($) {
bottom: "-30px", if (!$("body").hasClass("festive-newyear")) {
left: startX + "px", return;
zIndex: 999999, }
borderRadius: "50% 50% 0 0", if (typeof confetti === "undefined") {
boxShadow: "0 0 15px 5px rgba(255, 165, 0, 0.8)" console.error("FSP: Konfetti-Bibliothek nicht gefunden.");
}); return;
}
$("body").append($rocket);
function runBigFireworks() {
$rocket.animate( var count = 250;
{ bottom: window.innerHeight * 0.8 }, var defaults = { origin: { y: 0.7 }, zIndex: 999999, colors: ["#bb0000", "#ffffff", "#ff0000", "#ffbb00", "#ffee00", "#00ff00", "#0099ff", "#0000ff"] };
{ function fire(particleRatio, opts) {
duration: 1800, confetti(Object.assign({}, defaults, opts, { particleCount: Math.floor(count * particleRatio) }));
easing: "linear", }
complete: function() { fire(0.25, { spread: 26, startVelocity: 55 });
const x = startX / window.innerWidth; fire(0.2, { spread: 60 });
const y = 0.2; fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
confetti({ fire(0.1, { spread: 120, startVelocity: 45 });
particleCount: 75,
spread: 100, var rainDefaults = { origin: { y: 0 }, angle: 90, drift: 0, gravity: 1.2, scalar: 1.2, zIndex: 999999 };
origin: { x: x, y: y }, confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.1, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] }));
colors: ["#ff0000", "#ffa500", "#ffff00", "#ffffff"], confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.5, colors: ["#bb0000", "#ffffff", "#ffbb00", "#ffee00"] }));
gravity: 1.1, confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.9, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] }));
scalar: 1.0, }
startVelocity: 40
}); function createRocket(isLastRocket) {
const startX = Math.random() * window.innerWidth;
if (isLastRocket) {
setTimeout(runBigFireworks, 500); const $rocket = $("<div class=\"fsp-rocket\"></div>").css({
} position: "fixed",
width: "6px",
$(this).remove(); height: "25px",
} background: "linear-gradient(to top, #ff4500, #ffa500)",
} bottom: "-30px",
); left: startX + "px",
} zIndex: 999999,
borderRadius: "50% 50% 0 0",
function runNewYearShow() { boxShadow: "0 0 15px 5px rgba(255, 165, 0, 0.8)"
const rocketCount = 5 + Math.floor(Math.random() * 4); });
for (let i = 0; i < rocketCount; i++) { $("body").append($rocket);
const isLast = (i === rocketCount - 1);
setTimeout(() => createRocket(isLast), i * 400); $rocket.animate(
} { bottom: window.innerHeight * 0.8 },
} {
duration: 1800,
runNewYearShow(); easing: "linear",
setInterval(runNewYearShow, 12000); complete: function() {
}); const x = startX / window.innerWidth;
'; const y = 0.2;
wp_add_inline_script('fsp-confetti-lib', $script);
} confetti({
particleCount: 75,
public function add_admin_menu_page() { spread: 100,
add_options_page('Festive Seasons Pro', 'Festive Seasons', 'manage_options', 'festive-seasons-pro', [$this, 'render_admin_page']); origin: { x: x, y: y },
} colors: ["#ff0000", "#ffa500", "#ffff00", "#ffffff"],
gravity: 1.1,
public function register_settings() { scalar: 1.0,
register_setting('fsp_settings_group', 'fsp_events'); startVelocity: 40
foreach (array_keys($this->get_fixed_events()) as $key) { });
register_setting('fsp_settings_group', "fsp_fixed_{$key}");
} if (isLastRocket) {
register_setting('fsp_settings_group', 'fsp_enable_music'); setTimeout(runBigFireworks, 500);
} }
public function render_admin_page() { $(this).remove();
$events = get_option('fsp_events', []); }
?> }
<div class="wrap"> );
<h1>Festive Seasons Pro Einstellungen</h1> }
<form method="post" action="options.php">
<?php settings_fields('fsp_settings_group'); ?> function runNewYearShow() {
<?php do_settings_sections('fsp_settings_group'); ?> const rocketCount = 5 + Math.floor(Math.random() * 4);
<h2>Allgemeine Einstellungen</h2> for (let i = 0; i < rocketCount; i++) {
<table class="form-table" role="presentation"> const isLast = (i === rocketCount - 1);
<tr> setTimeout(() => createRocket(isLast), i * 400);
<th scope="row">Musik-Einwilligung</th> }
<td> }
<fieldset>
<label><input type="checkbox" name="fsp_enable_music" value="yes" <?php checked(get_option('fsp_enable_music', 'yes'), 'yes'); ?> /> Einwilligungsbox für Weihnachtsmusik anzeigen (funktioniert nur, wenn Weihnachten aktiv ist).</label> runNewYearShow();
</fieldset> setInterval(runNewYearShow, 12000);
</td> });
</tr> ';
</table> wp_add_inline_script('fsp-confetti-lib', $script);
}
<h2>Feste Feiertage</h2>
<table class="form-table" role="presentation"> public function add_admin_menu_page() {
<?php foreach ($this->get_fixed_events() as $key => $event): ?> add_options_page('Festive Seasons Pro', 'Festive Seasons', 'manage_options', 'festive-seasons-pro', [$this, 'render_admin_page']);
<tr> }
<th scope="row"><?php echo esc_html($event['name']); ?></th>
<td> public function register_settings() {
<label><input type="checkbox" name="fsp_fixed_<?php echo $key; ?>" value="yes" <?php checked(get_option("fsp_fixed_{$key}", 'yes'), 'yes'); ?> /> Aktivieren</label> register_setting('fsp_settings_group', 'fsp_events');
</td> foreach (array_keys($this->get_fixed_events()) as $key) {
</tr> register_setting('fsp_settings_group', "fsp_fixed_{$key}");
<?php endforeach; ?> }
</table> register_setting('fsp_settings_group', 'fsp_enable_music');
}
<h2>Geburtstage & Jubiläe</h2>
<p>Hier können Sie beliebige Ereignisse hinzufügen. Das Datum wird im Format <strong>TT-MM</strong> (z.B. 24-12) oder <strong>JJJJ-MM-TT</strong> (z.B. 2024-05-10) angegeben.</p> public function render_admin_page() {
<div id="fsp-events-container"> $events = get_option('fsp_events', []);
<?php if (is_array($events)) : ?> ?>
<?php foreach ($events as $index => $event) : ?> <div class="wrap">
<div class="fsp-event-row" style="margin-bottom: 10px; display: flex; gap: 10px; align-items: center;"> <h1>🎉 Festive Seasons Pro Einstellungen</h1>
<input type="text" name="fsp_events[<?php echo $index; ?>][name]" placeholder="Name (z.B. Max)" value="<?php echo esc_attr($event['name'] ?? ''); ?>" style="width: 200px;" /> <form method="post" action="options.php">
<input type="text" name="fsp_events[<?php echo $index; ?>][date]" placeholder="Datum (TT-MM)" value="<?php echo esc_attr($event['date'] ?? ''); ?>" style="width: 100px;" /> <?php settings_fields('fsp_settings_group'); ?>
<input type="text" name="fsp_events[<?php echo $index; ?>][text]" placeholder="Text (z.B. wird 30!)" value="<?php echo esc_attr($event['text'] ?? ''); ?>" style="flex-grow: 1;" /> <?php do_settings_sections('fsp_settings_group'); ?>
<button type="button" class="button button-secondary fsp-remove-event">Entfernen</button>
</div> <h2>⚙️ Allgemeine Einstellungen</h2>
<?php endforeach; ?> <table class="form-table" role="presentation">
<?php endif; ?> <tr>
</div> <th scope="row">Musik-Einwilligung</th>
<button type="button" id="fsp-add-event" class="button button-primary">+ Neues Ereignis hinzufügen</button> <td>
<fieldset>
<?php submit_button(); ?> <label><input type="checkbox" name="fsp_enable_music" value="yes" <?php checked(get_option('fsp_enable_music', 'yes'), 'yes'); ?> /> Einwilligungsbox für Weihnachtsmusik anzeigen (funktioniert nur, wenn Weihnachten aktiv ist).</label>
</form> </fieldset>
</div> </td>
</tr>
<script> </table>
jQuery(document).ready(function($) {
$("#fsp-add-event").on("click", function() { <h2>🎄 Feste Feiertage</h2>
var index = $("#fsp-events-container .fsp-event-row").length; <table class="form-table" role="presentation">
var newRow = \'<div class="fsp-event-row" style="margin-bottom: 10px; display: flex; gap: 10px; align-items: center;"><input type="text" name="fsp_events[\' + index + \'][name]" placeholder="Name (z.B. Max)" style="width: 200px;" /><input type="text" name="fsp_events[\' + index + \'][date]" placeholder="Datum (TT-MM)" style="width: 100px;" /><input type="text" name="fsp_events[\' + index + \'][text]" placeholder="Text (z.B. wird 30!)" style="flex-grow: 1;" /><button type="button" class="button button-secondary fsp-remove-event">Entfernen</button></div>\'; <?php foreach ($this->get_fixed_events() as $key => $event): ?>
$("#fsp-events-container").append(newRow); <tr>
}); <th scope="row"><?php echo esc_html($event['name']); ?></th>
$(document).on("click", ".fsp-remove-event", function() { <td>
$(this).closest(".fsp-event-row").remove(); <label><input type="checkbox" name="fsp_fixed_<?php echo $key; ?>" value="yes" <?php checked(get_option("fsp_fixed_{$key}", 'yes'), 'yes'); ?> /> Aktivieren</label>
}); </td>
}); </tr>
</script> <?php endforeach; ?>
<?php </table>
}
<h2>🎂 Geburtstage & Jubiläen</h2>
public function render_shortcode() { <p>Hier können Sie beliebige Ereignisse hinzufügen. Das Datum wird im Format <strong>TT-MM</strong> (z.B. 24-12) oder <strong>JJJJ-MM-TT</strong> (z.B. 2024-05-10) angegeben.</p>
$active_events = $this->get_active_events();
if (empty($active_events)) return ''; <div id="fsp-events-container" style="margin-bottom: 15px;">
$names = array_map(fn($e) => $e['name'], $active_events); <?php if (is_array($events) && !empty($events)) : ?>
return '<div class="fsp-today">Heute feiern wir: <strong>' . esc_html(implode(' + ', $names)) . '</strong></div>'; <?php foreach ($events as $index => $event) : ?>
} <div class="fsp-event-row" style="margin-bottom: 10px; display: flex; gap: 10px; align-items: center;">
<input type="text" name="fsp_events[<?php echo $index; ?>][name]" placeholder="Name (z.B. Max)" value="<?php echo esc_attr($event['name'] ?? ''); ?>" style="width: 200px;" />
public function register_widget() { <input type="text" name="fsp_events[<?php echo $index; ?>][date]" placeholder="Datum (TT-MM)" value="<?php echo esc_attr($event['date'] ?? ''); ?>" style="width: 100px;" />
register_widget('FSP_Widget'); <input type="text" name="fsp_events[<?php echo $index; ?>][text]" placeholder="Text (z.B. wird 30!)" value="<?php echo esc_attr($event['text'] ?? ''); ?>" style="flex-grow: 1;" />
} <button type="button" class="button button-secondary fsp-remove-event">Entfernen</button>
</div>
public function render_music_consent() { <?php endforeach; ?>
if (get_option('fsp_enable_music', 'yes') !== 'yes') { <?php endif; ?>
return; </div>
}
<button type="button" id="fsp-add-event" class="button button-primary" style="margin-bottom: 20px;">
$active_events = $this->get_active_events(); <span class="dashicons dashicons-plus-alt" style="margin-top: 3px;"></span> Neues Ereignis hinzufügen
$has_music = false; </button>
foreach ($active_events as $event) {
if (in_array('music', $event['effects'] ?? [])) { $has_music = true; break; } <?php submit_button('Einstellungen speichern'); ?>
} </form>
if (!$has_music) return; </div>
<?php
$audio_url = plugin_dir_url(__FILE__) . 'assets/audio/xmas-jingle.mp3'; }
echo '<div id="fsp-music-consent" style="position:fixed;bottom:20px;right:20px;background:#fff;color:#333;padding:20px;border-radius:8px;z-index:99999;box-shadow:0 4px 15px rgba(0,0,0,0.2);display:none;max-width:300px;">
<p style="margin:0 0 15px 0;">Weihnachtsmusik abspielen?</p> public function render_shortcode() {
<button id="fsp-music-yes" style="background:#c0392b;color:#fff;border:none;padding:8px 15px;border-radius:5px;cursor:pointer;margin-right:10px;">Ja</button> $active_events = $this->get_active_events();
<button id="fsp-music-no" style="background:#bdc3c7;color:#333;border:none;padding:8px 15px;border-radius:5px;cursor:pointer;">Nein</button> if (empty($active_events)) return '';
</div> $names = array_map(fn($e) => $e['name'], $active_events);
return '<div class="fsp-today">Heute feiern wir: <strong>' . esc_html(implode(' + ', $names)) . '</strong></div>';
<audio id="fsp-xmas-audio" src="' . $audio_url . '" loop style="display:none;"></audio> }
<script> public function register_widget() {
jQuery(function($) { register_widget('FSP_Widget');
const consentBox = $("#fsp-music-consent"); }
const audioPlayer = $("#fsp-xmas-audio")[0];
public function render_music_consent() {
setTimeout(() => consentBox.fadeIn(500), 2000); if (get_option('fsp_enable_music', 'yes') !== 'yes') {
return;
$("#fsp-music-yes").on("click", function() { }
const playPromise = audioPlayer.play();
$active_events = $this->get_active_events();
if (playPromise !== undefined) { $has_music = false;
playPromise.then(_ => { foreach ($active_events as $event) {
console.log("FSP: Musik wird abgespielt."); if (in_array('music', $event['effects'] ?? [])) { $has_music = true; break; }
}).catch(error => { }
console.error("FSP: Autoplay blockiert. Zeige Steuerelemente an."); if (!$has_music) return;
audioPlayer.style.position = "fixed";
audioPlayer.style.bottom = "20px"; $audio_url = plugin_dir_url(__FILE__) . 'assets/audio/xmas-jingle.mp3';
audioPlayer.style.left = "20px"; echo '<div id="fsp-music-consent" style="position:fixed;bottom:20px;right:20px;background:#fff;color:#333;padding:20px;border-radius:8px;z-index:99999;box-shadow:0 4px 15px rgba(0,0,0,0.2);display:none;max-width:300px;">
audioPlayer.style.zIndex = "99999"; <p style="margin:0 0 15px 0;">🎵 Weihnachtsmusik abspielen?</p>
audioPlayer.style.width = "250px"; <button id="fsp-music-yes" style="background:#c0392b;color:#fff;border:none;padding:8px 15px;border-radius:5px;cursor:pointer;margin-right:10px;">Ja</button>
audioPlayer.style.display = "block"; <button id="fsp-music-no" style="background:#bdc3c7;color:#333;border:none;padding:8px 15px;border-radius:5px;cursor:pointer;">Nein</button>
audioPlayer.controls = true; </div>
});
} <audio id="fsp-xmas-audio" src="' . $audio_url . '" loop style="display:none;"></audio>
consentBox.fadeOut(300);
}); <script>
jQuery(function($) {
$("#fsp-music-no").on("click", function() { const consentBox = $("#fsp-music-consent");
consentBox.fadeOut(300); const audioPlayer = $("#fsp-xmas-audio")[0];
});
}); setTimeout(() => consentBox.fadeIn(500), 2000);
</script>';
} $("#fsp-music-yes").on("click", function() {
} const playPromise = audioPlayer.play();
class FSP_Widget extends WP_Widget { if (playPromise !== undefined) {
public function __construct() { playPromise.then(_ => {
parent::__construct('fsp_widget', 'Festive Seasons Anlass', ['description' => 'Zeigt den heutigen festlichen Anlass an.']); console.log("FSP: Musik wird abgespielt.");
} }).catch(error => {
console.error("FSP: Autoplay blockiert. Zeige Steuerelemente an.");
public function widget($args, $instance) { audioPlayer.style.position = "fixed";
global $festive_seasons_pro_instance; audioPlayer.style.bottom = "20px";
if (!$festive_seasons_pro_instance) return; audioPlayer.style.left = "20px";
audioPlayer.style.zIndex = "99999";
$active_events = $festive_seasons_pro_instance->get_active_events(); audioPlayer.style.width = "250px";
if (empty($active_events)) return; audioPlayer.style.display = "block";
audioPlayer.controls = true;
$names = array_map(fn($e) => $e['name'], $active_events); });
echo $args['before_widget']; }
if (!empty($instance['title'])) { consentBox.fadeOut(300);
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; });
}
echo '<div style="text-align:center; padding:15px; background:rgba(255,255,255,0.2); border-radius:10px;">' . esc_html(implode(' + ', $names)) . '</div>'; $("#fsp-music-no").on("click", function() {
echo $args['after_widget']; consentBox.fadeOut(300);
} });
});
public function form($instance) { </script>';
$title = !empty($instance['title']) ? $instance['title'] : 'Heute ist...'; }
?> }
<p><label for="<?php echo esc_attr($this->get_field_id('title')); ?>">Titel:</label><input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>"></p>
<?php class FSP_Widget extends WP_Widget {
} public function __construct() {
parent::__construct('fsp_widget', 'Festive Seasons Anlass', ['description' => 'Zeigt den heutigen festlichen Anlass an.']);
public function update($new_instance, $old_instance) { }
$instance = [];
$instance['title'] = (!empty($new_instance['title'])) ? sanitize_text_field($new_instance['title']) : ''; public function widget($args, $instance) {
return $instance; global $festive_seasons_pro_instance;
} if (!$festive_seasons_pro_instance) return;
}
$active_events = $festive_seasons_pro_instance->get_active_events();
$festive_seasons_pro_instance = new Festive_Seasons_Pro(); if (empty($active_events)) return;
$names = array_map(fn($e) => $e['name'], $active_events);
echo $args['before_widget'];
if (!empty($instance['title'])) {
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
}
echo '<div style="text-align:center; padding:15px; background:rgba(255,255,255,0.2); border-radius:10px;">' . esc_html(implode(' + ', $names)) . '</div>';
echo $args['after_widget'];
}
public function form($instance) {
$title = !empty($instance['title']) ? $instance['title'] : 'Heute ist...';
?>
<p><label for="<?php echo esc_attr($this->get_field_id('title')); ?>">Titel:</label><input class="widefat" id="<?php echo esc_attr($this->get_field_id('title')); ?>" name="<?php echo esc_attr($this->get_field_name('title')); ?>" type="text" value="<?php echo esc_attr($title); ?>"></p>
<?php
}
public function update($new_instance, $old_instance) {
$instance = [];
$instance['title'] = (!empty($new_instance['title'])) ? sanitize_text_field($new_instance['title']) : '';
return $instance;
}
}
$festive_seasons_pro_instance = new Festive_Seasons_Pro();