3 Commits
1.0 ... 1.2

Author SHA1 Message Date
600791f339 festive-seasons-pro.php aktualisiert 2026-02-11 19:02:20 +00:00
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,548 @@
<?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.2
Author: M_Viper Author: M_Viper
*/ */
if (!defined('ABSPATH')) { if (!defined('ABSPATH')) {
exit; exit;
} }
class Festive_Seasons_Pro { // === FESTIVE SEASONS PRO - UPDATE SYSTEM ===
public function __construct() { // Aktuelle Plugin-Version aus Plugin-Header lesen
add_action('init', [$this, 'init_plugin']); function fsp_get_plugin_version() {
} if ( ! function_exists( 'get_plugin_data' ) ) {
require_once ABSPATH . 'wp-admin/includes/plugin.php';
public function init_plugin() { }
add_action('wp_enqueue_scripts', [$this, 'load_assets']);
add_action('wp_footer', [$this, 'render_music_consent']); $plugin_data = get_plugin_data( __FILE__ );
add_action('admin_menu', [$this, 'add_admin_menu_page']); return $plugin_data['Version'] ?? '0.0.0';
add_action('admin_init', [$this, 'register_settings']); }
add_action('widgets_init', [$this, 'register_widget']);
add_shortcode('festive_event', [$this, 'render_shortcode']); // Cache löschen (manueller Refresh)
} function fsp_clear_update_cache() {
if ( isset($_GET['fsp_clear_cache']) && current_user_can('manage_options') ) {
public function get_active_events() { check_admin_referer('fsp_clear_cache_action');
if (isset($_GET['fsp_test_date'])) { delete_transient('fsp_latest_release');
$today = sanitize_text_field($_GET['fsp_test_date']); wp_redirect( admin_url('plugins.php') );
} else { exit;
$today = date('Y-m-d'); }
} }
add_action('admin_init', 'fsp_clear_update_cache');
$active_events = [];
// Neueste Release-Infos von Gitea holen
foreach ($this->get_fixed_events() as $event_key => $event_data) { function fsp_get_latest_release_info( $force_refresh = false ) {
if (isset($event_data['start'], $event_data['end']) && $today >= $event_data['start'] && $today <= $event_data['end']) { $transient_key = 'fsp_latest_release';
if (get_option("fsp_fixed_{$event_key}", 'yes') === 'yes') {
$active_events[] = $event_data; if ( $force_refresh ) {
} delete_transient( $transient_key );
} }
}
$release_info = get_transient( $transient_key );
foreach ($this->get_custom_events($today) as $event_data) {
$active_events[] = $event_data; if ( false === $release_info ) {
} $response = wp_remote_get(
'https://git.viper.ipv64.net/api/v1/repos/M_Viper/Festive-Seasons-Pro/releases/latest',
return $active_events; ['timeout' => 10]
} );
private function get_fixed_events() { if ( ! is_wp_error($response) && 200 === wp_remote_retrieve_response_code($response) ) {
$test_year = isset($_GET['fsp_test_date']) ? substr(sanitize_text_field($_GET['fsp_test_date']), 0, 4) : date('Y'); $body = wp_remote_retrieve_body($response);
$year = is_numeric($test_year) ? $test_year : date('Y'); $data = json_decode($body, true);
$easter_date = date('Y-m-d', easter_date($year));
if ( $data && isset($data['tag_name']) ) {
return [ $tag = ltrim($data['tag_name'], 'v');
'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 $release_info = [
'newyear' => ['name' => 'Silvester', 'start' => "$year-12-31", 'end' => ($year + 1) . "-01-01", 'class' => 'festive-newyear', 'effects' => ['newyear_fireworks']], 'version' => $tag,
'halloween' => ['name' => 'Halloween', 'start' => "$year-10-31", 'end' => "$year-10-31", 'class' => 'festive-halloween', 'effects' => ['spiders']], 'download_url' => $data['zipball_url'] ?? '',
'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']], 'notes' => $data['body'] ?? '',
]; 'published_at' => $data['published_at'] ?? '',
} ];
private function get_custom_events($today) { set_transient( $transient_key, $release_info, 6 * HOUR_IN_SECONDS );
$custom_events = get_option('fsp_events', []); } else {
$active_custom_events = []; set_transient( $transient_key, [], HOUR_IN_SECONDS );
$today_day_month = date('m-d', strtotime($today)); }
} else {
if (is_array($custom_events)) { set_transient( $transient_key, [], HOUR_IN_SECONDS );
foreach ($custom_events as $event) { }
if (empty($event['date']) || !is_array($event)) continue; }
$event_date = sanitize_text_field($event['date']);
$date_obj = DateTime::createFromFormat('d-m', $event_date) ?: DateTime::createFromFormat('Y-m-d', $event_date); return $release_info;
if ($date_obj && $date_obj->format('m-d') === $today_day_month) { }
$name = trim(($event['name'] ?? '') . ' ' . ($event['text'] ?? ''));
$active_custom_events[] = [ // Admin-Notice für Plugin-Update
'name' => $name ?: 'Besonderer Tag!', function fsp_show_update_notice() {
'class' => 'festive-birthday', if ( ! current_user_can('manage_options') ) {
'effects' => ['balloons', 'confetti'] return;
]; }
}
} $current_version = fsp_get_plugin_version();
} $latest_release = fsp_get_latest_release_info();
return $active_custom_events;
} if ( ! empty($latest_release['version']) && version_compare($current_version, $latest_release['version'], '<') ) {
$refresh_url = wp_nonce_url(
public function load_assets() { admin_url('plugins.php?fsp_clear_cache=1'),
$active_events = $this->get_active_events(); 'fsp_clear_cache_action'
if (empty($active_events)) return; );
?>
$body_classes = []; <div class="notice notice-warning is-dismissible">
$effects_to_load = []; <h3>Festive Seasons Pro Update verfügbar</h3>
<p>
foreach ($active_events as $event) { Aktuelle Version: <strong><?php echo esc_html($current_version); ?></strong><br>
if (!empty($event['class'])) $body_classes[] = $event['class']; Neueste Version: <strong><?php echo esc_html($latest_release['version']); ?></strong>
if (!empty($event['effects'])) $effects_to_load = array_merge($effects_to_load, $event['effects']); </p>
} <p>
<a href="<?php echo esc_url($latest_release['download_url']); ?>" class="button button-primary" target="_blank">
add_filter('body_class', function($classes) use ($body_classes) { Update herunterladen
return array_merge($classes, array_unique($body_classes)); </a>
}); <a href="https://git.viper.ipv64.net/M_Viper/Festive-Seasons-Pro/releases" class="button" target="_blank">
Release Notes
wp_enqueue_style('fsp-style', plugin_dir_url(__FILE__) . 'assets/css/festive.css', [], '3.4'); </a>
wp_enqueue_script('jquery'); <a href="<?php echo esc_url($refresh_url); ?>" class="button">
Jetzt neu prüfen
wp_localize_script('jquery', 'fsp_vars', [ </a>
'plugin_url' => plugin_dir_url(__FILE__) </p>
]); </div>
<?php
if (in_array('confetti', $effects_to_load) || in_array('newyear_fireworks', $effects_to_load)) { }
wp_enqueue_script('fsp-confetti-lib', plugin_dir_url(__FILE__) . 'assets/js/canvas-confetti.min.js', [], '3.4', true); }
} add_action('admin_notices', 'fsp_show_update_notice');
foreach (array_unique($effects_to_load) as $effect) {
switch ($effect) { class Festive_Seasons_Pro {
case 'snow':
wp_enqueue_script('fsp-snow', plugin_dir_url(__FILE__) . 'assets/js/snowstorm.js', [], '3.4', true); public function __construct() {
break; add_action('init', [$this, 'init_plugin']);
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 init_plugin() {
case 'eggs': add_action('wp_enqueue_scripts', [$this, 'load_assets']);
wp_enqueue_script('fsp-eggs', plugin_dir_url(__FILE__) . 'assets/js/easter-eggs.js', ['jquery'], '3.4', true); add_action('wp_footer', [$this, 'render_music_consent']);
break; add_action('admin_menu', [$this, 'add_admin_menu_page']);
case 'spiders': add_action('admin_init', [$this, 'register_settings']);
wp_enqueue_script('fsp-spiders', plugin_dir_url(__FILE__) . 'assets/js/halloween-spiders.js', ['jquery'], '3.4', true); add_action('admin_enqueue_scripts', [$this, 'enqueue_admin_scripts']);
break; add_action('widgets_init', [$this, 'register_widget']);
case 'balloons': add_shortcode('festive_event', [$this, 'render_shortcode']);
wp_enqueue_script('fsp-balloons', plugin_dir_url(__FILE__) . 'assets/js/balloons.js', ['jquery'], '3.4', true); }
break;
case 'star': // Admin-Scripts laden
wp_enqueue_script('fsp-star', plugin_dir_url(__FILE__) . 'assets/js/christmas-star.js', ['jquery'], '3.4', true); public function enqueue_admin_scripts($hook) {
break; // Nur auf der Plugin-Einstellungsseite laden
case 'santa': // NEU: Santa-Animation if ($hook !== 'settings_page_festive-seasons-pro') {
wp_enqueue_script('fsp-santa', plugin_dir_url(__FILE__) . 'assets/js/santa-sleigh.js', ['jquery'], '3.4', true); return;
break; }
case 'newyear_fireworks':
$this->add_newyear_script(); // jQuery ist standardmäßig in WordPress verfügbar
break; wp_enqueue_script('jquery');
}
} // Inline-Script für Event-Verwaltung
} wp_add_inline_script('jquery', '
jQuery(document).ready(function($) {
private function add_newyear_script() { // Neues Ereignis hinzufügen
$script = ' $("#fsp-add-event").on("click", function() {
jQuery(document).ready(function($) { var index = $("#fsp-events-container .fsp-event-row").length;
if (!$("body").hasClass("festive-newyear")) { var newRow = \'<div class="fsp-event-row" style="margin-bottom: 10px; display: flex; gap: 10px; align-items: center;">\' +
return; \'<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;" />\' +
if (typeof confetti === "undefined") { \'<input type="text" name="fsp_events[\' + index + \'][text]" placeholder="Text (z.B. wird 30!)" style="flex-grow: 1;" />\' +
console.error("FSP: Konfetti-Bibliothek nicht gefunden."); \'<button type="button" class="button button-secondary fsp-remove-event">Entfernen</button>\' +
return; \'</div>\';
} $("#fsp-events-container").append(newRow);
});
function runBigFireworks() {
var count = 250; // Ereignis entfernen
var defaults = { origin: { y: 0.7 }, zIndex: 999999, colors: ["#bb0000", "#ffffff", "#ff0000", "#ffbb00", "#ffee00", "#00ff00", "#0099ff", "#0000ff"] }; $(document).on("click", ".fsp-remove-event", function() {
function fire(particleRatio, opts) { $(this).closest(".fsp-event-row").remove();
confetti(Object.assign({}, defaults, opts, { particleCount: Math.floor(count * particleRatio) })); });
} });
fire(0.25, { spread: 26, startVelocity: 55 }); ');
fire(0.2, { spread: 60 }); }
fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 }); public function get_active_events() {
fire(0.1, { spread: 120, startVelocity: 45 }); if (isset($_GET['fsp_test_date'])) {
$today = sanitize_text_field($_GET['fsp_test_date']);
var rainDefaults = { origin: { y: 0 }, angle: 90, drift: 0, gravity: 1.2, scalar: 1.2, zIndex: 999999 }; } else {
confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.1, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] })); $today = date('Y-m-d');
confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.5, colors: ["#bb0000", "#ffffff", "#ffbb00", "#ffee00"] })); }
confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.9, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] }));
} $active_events = [];
function createRocket(isLastRocket) { foreach ($this->get_fixed_events() as $event_key => $event_data) {
const startX = Math.random() * window.innerWidth; 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') {
const $rocket = $("<div class=\"fsp-rocket\"></div>").css({ $active_events[] = $event_data;
position: "fixed", }
width: "6px", }
height: "25px", }
background: "linear-gradient(to top, #ff4500, #ffa500)",
bottom: "-30px", foreach ($this->get_custom_events($today) as $event_data) {
left: startX + "px", $active_events[] = $event_data;
zIndex: 999999, }
borderRadius: "50% 50% 0 0",
boxShadow: "0 0 15px 5px rgba(255, 165, 0, 0.8)" return $active_events;
}); }
$("body").append($rocket); private function get_fixed_events() {
$test_year = isset($_GET['fsp_test_date']) ? substr(sanitize_text_field($_GET['fsp_test_date']), 0, 4) : date('Y');
$rocket.animate( $year = is_numeric($test_year) ? $test_year : date('Y');
{ bottom: window.innerHeight * 0.8 }, $easter_date = date('Y-m-d', easter_date($year));
{
duration: 1800, return [
easing: "linear", 'advent' => ['name' => 'Adventszeit', 'start' => "$year-12-01", 'end' => "$year-12-23", 'class' => 'festive-advent', 'effects' => ['snow']],
complete: function() { 'christmas' => ['name' => 'Weihnachten', 'start' => "$year-12-24", 'end' => "$year-12-26", 'class' => 'festive-christmas', 'effects' => ['snow', 'music', 'star', 'santa']],
const x = startX / window.innerWidth; 'newyear' => ['name' => 'Silvester', 'start' => "$year-12-31", 'end' => ($year + 1) . "-01-01", 'class' => 'festive-newyear', 'effects' => ['newyear_fireworks']],
const y = 0.2; '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']],
confetti({ ];
particleCount: 75, }
spread: 100,
origin: { x: x, y: y }, private function get_custom_events($today) {
colors: ["#ff0000", "#ffa500", "#ffff00", "#ffffff"], $custom_events = get_option('fsp_events', []);
gravity: 1.1, $active_custom_events = [];
scalar: 1.0, $today_day_month = date('m-d', strtotime($today));
startVelocity: 40
}); if (is_array($custom_events)) {
foreach ($custom_events as $event) {
if (isLastRocket) { if (empty($event['date']) || !is_array($event)) continue;
setTimeout(runBigFireworks, 500); $event_date = sanitize_text_field($event['date']);
} $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) {
$(this).remove(); $name = trim(($event['name'] ?? '') . ' ' . ($event['text'] ?? ''));
} $active_custom_events[] = [
} 'name' => $name ?: 'Besonderer Tag!',
); 'class' => 'festive-birthday',
} 'effects' => ['balloons', 'confetti']
];
function runNewYearShow() { }
const rocketCount = 5 + Math.floor(Math.random() * 4); }
}
for (let i = 0; i < rocketCount; i++) { return $active_custom_events;
const isLast = (i === rocketCount - 1); }
setTimeout(() => createRocket(isLast), i * 400);
} public function load_assets() {
} $active_events = $this->get_active_events();
if (empty($active_events)) return;
runNewYearShow();
setInterval(runNewYearShow, 12000); $body_classes = [];
}); $effects_to_load = [];
';
wp_add_inline_script('fsp-confetti-lib', $script); foreach ($active_events as $event) {
} if (!empty($event['class'])) $body_classes[] = $event['class'];
if (!empty($event['effects'])) $effects_to_load = array_merge($effects_to_load, $event['effects']);
public function add_admin_menu_page() { }
add_options_page('Festive Seasons Pro', 'Festive Seasons', 'manage_options', 'festive-seasons-pro', [$this, 'render_admin_page']);
} add_filter('body_class', function($classes) use ($body_classes) {
return array_merge($classes, array_unique($body_classes));
public function register_settings() { });
register_setting('fsp_settings_group', 'fsp_events');
foreach (array_keys($this->get_fixed_events()) as $key) { wp_enqueue_style('fsp-style', plugin_dir_url(__FILE__) . 'assets/css/festive.css', [], '3.4');
register_setting('fsp_settings_group', "fsp_fixed_{$key}"); wp_enqueue_script('jquery');
}
register_setting('fsp_settings_group', 'fsp_enable_music'); wp_localize_script('jquery', 'fsp_vars', [
} 'plugin_url' => plugin_dir_url(__FILE__)
]);
public function render_admin_page() {
$events = get_option('fsp_events', []); if (in_array('confetti', $effects_to_load) || in_array('newyear_fireworks', $effects_to_load)) {
?> wp_enqueue_script('fsp-confetti-lib', plugin_dir_url(__FILE__) . 'assets/js/canvas-confetti.min.js', [], '3.4', true);
<div class="wrap"> }
<h1>Festive Seasons Pro Einstellungen</h1>
<form method="post" action="options.php"> foreach (array_unique($effects_to_load) as $effect) {
<?php settings_fields('fsp_settings_group'); ?> switch ($effect) {
<?php do_settings_sections('fsp_settings_group'); ?> case 'snow':
wp_enqueue_script('fsp-snow', plugin_dir_url(__FILE__) . 'assets/js/snowstorm.js', [], '3.4', true);
<h2>Allgemeine Einstellungen</h2> break;
<table class="form-table" role="presentation"> case 'confetti':
<tr> wp_add_inline_script('fsp-confetti-lib', 'jQuery(document).ready(function($) { setTimeout(() => confetti({particleCount: 200, spread: 120, origin: { y: 0.6 } }), 1000); });');
<th scope="row">Musik-Einwilligung</th> break;
<td> case 'eggs':
<fieldset> wp_enqueue_script('fsp-eggs', plugin_dir_url(__FILE__) . 'assets/js/easter-eggs.js', ['jquery'], '3.4', true);
<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> break;
</fieldset> case 'spiders':
</td> wp_enqueue_script('fsp-spiders', plugin_dir_url(__FILE__) . 'assets/js/halloween-spiders.js', ['jquery'], '3.4', true);
</tr> break;
</table> case 'balloons':
wp_enqueue_script('fsp-balloons', plugin_dir_url(__FILE__) . 'assets/js/balloons.js', ['jquery'], '3.4', true);
<h2>Feste Feiertage</h2> break;
<table class="form-table" role="presentation"> case 'star':
<?php foreach ($this->get_fixed_events() as $key => $event): ?> wp_enqueue_script('fsp-star', plugin_dir_url(__FILE__) . 'assets/js/christmas-star.js', ['jquery'], '3.4', true);
<tr> break;
<th scope="row"><?php echo esc_html($event['name']); ?></th> case 'santa':
<td> wp_enqueue_script('fsp-santa', plugin_dir_url(__FILE__) . 'assets/js/santa-sleigh.js', ['jquery'], '3.4', true);
<label><input type="checkbox" name="fsp_fixed_<?php echo $key; ?>" value="yes" <?php checked(get_option("fsp_fixed_{$key}", 'yes'), 'yes'); ?> /> Aktivieren</label> break;
</td> case 'newyear_fireworks':
</tr> $this->add_newyear_script();
<?php endforeach; ?> break;
</table> }
}
<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>
<div id="fsp-events-container"> private function add_newyear_script() {
<?php if (is_array($events)) : ?> $script = '
<?php foreach ($events as $index => $event) : ?> jQuery(document).ready(function($) {
<div class="fsp-event-row" style="margin-bottom: 10px; display: flex; gap: 10px; align-items: center;"> if (!$("body").hasClass("festive-newyear")) {
<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;" /> return;
<input type="text" name="fsp_events[<?php echo $index; ?>][date]" placeholder="Datum (TT-MM)" value="<?php echo esc_attr($event['date'] ?? ''); ?>" style="width: 100px;" /> }
<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;" /> if (typeof confetti === "undefined") {
<button type="button" class="button button-secondary fsp-remove-event">Entfernen</button> console.error("FSP: Konfetti-Bibliothek nicht gefunden.");
</div> return;
<?php endforeach; ?> }
<?php endif; ?>
</div> function runBigFireworks() {
<button type="button" id="fsp-add-event" class="button button-primary">+ Neues Ereignis hinzufügen</button> var count = 250;
var defaults = { origin: { y: 0.7 }, zIndex: 999999, colors: ["#bb0000", "#ffffff", "#ff0000", "#ffbb00", "#ffee00", "#00ff00", "#0099ff", "#0000ff"] };
<?php submit_button(); ?> function fire(particleRatio, opts) {
</form> confetti(Object.assign({}, defaults, opts, { particleCount: Math.floor(count * particleRatio) }));
</div> }
fire(0.25, { spread: 26, startVelocity: 55 });
<script> fire(0.2, { spread: 60 });
jQuery(document).ready(function($) { fire(0.35, { spread: 100, decay: 0.91, scalar: 0.8 });
$("#fsp-add-event").on("click", function() { fire(0.1, { spread: 120, startVelocity: 25, decay: 0.92, scalar: 1.2 });
var index = $("#fsp-events-container .fsp-event-row").length; fire(0.1, { spread: 120, startVelocity: 45 });
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>\';
$("#fsp-events-container").append(newRow); var rainDefaults = { origin: { y: 0 }, angle: 90, drift: 0, gravity: 1.2, scalar: 1.2, zIndex: 999999 };
}); confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.1, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] }));
$(document).on("click", ".fsp-remove-event", function() { confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.5, colors: ["#bb0000", "#ffffff", "#ffbb00", "#ffee00"] }));
$(this).closest(".fsp-event-row").remove(); confetti(Object.assign({}, rainDefaults, { particleCount: 40, x: 0.9, colors: ["#ff0000", "#00ff00", "#0000ff", "#ffff00"] }));
}); }
});
</script> function createRocket(isLastRocket) {
<?php const startX = Math.random() * window.innerWidth;
}
const $rocket = $("<div class=\"fsp-rocket\"></div>").css({
public function render_shortcode() { position: "fixed",
$active_events = $this->get_active_events(); width: "6px",
if (empty($active_events)) return ''; height: "25px",
$names = array_map(fn($e) => $e['name'], $active_events); background: "linear-gradient(to top, #ff4500, #ffa500)",
return '<div class="fsp-today">Heute feiern wir: <strong>' . esc_html(implode(' + ', $names)) . '</strong></div>'; bottom: "-30px",
} left: startX + "px",
zIndex: 999999,
public function register_widget() { borderRadius: "50% 50% 0 0",
register_widget('FSP_Widget'); boxShadow: "0 0 15px 5px rgba(255, 165, 0, 0.8)"
} });
public function render_music_consent() { $("body").append($rocket);
if (get_option('fsp_enable_music', 'yes') !== 'yes') {
return; $rocket.animate(
} { bottom: window.innerHeight * 0.8 },
{
$active_events = $this->get_active_events(); duration: 1800,
$has_music = false; easing: "linear",
foreach ($active_events as $event) { complete: function() {
if (in_array('music', $event['effects'] ?? [])) { $has_music = true; break; } const x = startX / window.innerWidth;
} const y = 0.2;
if (!$has_music) return;
confetti({
$audio_url = plugin_dir_url(__FILE__) . 'assets/audio/xmas-jingle.mp3'; particleCount: 75,
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;"> spread: 100,
<p style="margin:0 0 15px 0;">Weihnachtsmusik abspielen?</p> origin: { x: x, y: y },
<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> colors: ["#ff0000", "#ffa500", "#ffff00", "#ffffff"],
<button id="fsp-music-no" style="background:#bdc3c7;color:#333;border:none;padding:8px 15px;border-radius:5px;cursor:pointer;">Nein</button> gravity: 1.1,
</div> scalar: 1.0,
startVelocity: 40
<audio id="fsp-xmas-audio" src="' . $audio_url . '" loop style="display:none;"></audio> });
<script> if (isLastRocket) {
jQuery(function($) { setTimeout(runBigFireworks, 500);
const consentBox = $("#fsp-music-consent"); }
const audioPlayer = $("#fsp-xmas-audio")[0];
$(this).remove();
setTimeout(() => consentBox.fadeIn(500), 2000); }
}
$("#fsp-music-yes").on("click", function() { );
const playPromise = audioPlayer.play(); }
if (playPromise !== undefined) { function runNewYearShow() {
playPromise.then(_ => { const rocketCount = 5 + Math.floor(Math.random() * 4);
console.log("FSP: Musik wird abgespielt.");
}).catch(error => { for (let i = 0; i < rocketCount; i++) {
console.error("FSP: Autoplay blockiert. Zeige Steuerelemente an."); const isLast = (i === rocketCount - 1);
audioPlayer.style.position = "fixed"; setTimeout(() => createRocket(isLast), i * 400);
audioPlayer.style.bottom = "20px"; }
audioPlayer.style.left = "20px"; }
audioPlayer.style.zIndex = "99999";
audioPlayer.style.width = "250px"; runNewYearShow();
audioPlayer.style.display = "block"; setInterval(runNewYearShow, 12000);
audioPlayer.controls = true; });
}); ';
} wp_add_inline_script('fsp-confetti-lib', $script);
consentBox.fadeOut(300); }
});
public function add_admin_menu_page() {
$("#fsp-music-no").on("click", function() { add_options_page('Festive Seasons Pro', 'Festive Seasons', 'manage_options', 'festive-seasons-pro', [$this, 'render_admin_page']);
consentBox.fadeOut(300); }
});
}); public function register_settings() {
</script>'; register_setting('fsp_settings_group', 'fsp_events');
} foreach (array_keys($this->get_fixed_events()) as $key) {
} register_setting('fsp_settings_group', "fsp_fixed_{$key}");
}
class FSP_Widget extends WP_Widget { register_setting('fsp_settings_group', 'fsp_enable_music');
public function __construct() { }
parent::__construct('fsp_widget', 'Festive Seasons Anlass', ['description' => 'Zeigt den heutigen festlichen Anlass an.']);
} public function render_admin_page() {
$events = get_option('fsp_events', []);
public function widget($args, $instance) { ?>
global $festive_seasons_pro_instance; <div class="wrap">
if (!$festive_seasons_pro_instance) return; <h1>🎉 Festive Seasons Pro Einstellungen</h1>
<form method="post" action="options.php">
$active_events = $festive_seasons_pro_instance->get_active_events(); <?php settings_fields('fsp_settings_group'); ?>
if (empty($active_events)) return; <?php do_settings_sections('fsp_settings_group'); ?>
$names = array_map(fn($e) => $e['name'], $active_events); <h2>⚙️ Allgemeine Einstellungen</h2>
echo $args['before_widget']; <table class="form-table" role="presentation">
if (!empty($instance['title'])) { <tr>
echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title']; <th scope="row">Musik-Einwilligung</th>
} <td>
echo '<div style="text-align:center; padding:15px; background:rgba(255,255,255,0.2); border-radius:10px;">' . esc_html(implode(' + ', $names)) . '</div>'; <fieldset>
echo $args['after_widget']; <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>
} </fieldset>
</td>
public function form($instance) { </tr>
$title = !empty($instance['title']) ? $instance['title'] : 'Heute ist...'; </table>
?>
<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> <h2>🎄 Feste Feiertage</h2>
<?php <table class="form-table" role="presentation">
} <?php foreach ($this->get_fixed_events() as $key => $event): ?>
<tr>
public function update($new_instance, $old_instance) { <th scope="row"><?php echo esc_html($event['name']); ?></th>
$instance = []; <td>
$instance['title'] = (!empty($new_instance['title'])) ? sanitize_text_field($new_instance['title']) : ''; <label><input type="checkbox" name="fsp_fixed_<?php echo $key; ?>" value="yes" <?php checked(get_option("fsp_fixed_{$key}", 'yes'), 'yes'); ?> /> Aktivieren</label>
return $instance; </td>
} </tr>
} <?php endforeach; ?>
</table>
$festive_seasons_pro_instance = new Festive_Seasons_Pro();
<h2>🎂 Geburtstage & Jubiläen</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>
<div id="fsp-events-container" style="margin-bottom: 15px;">
<?php if (is_array($events) && !empty($events)) : ?>
<?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;" />
<input type="text" name="fsp_events[<?php echo $index; ?>][date]" placeholder="Datum (TT-MM)" value="<?php echo esc_attr($event['date'] ?? ''); ?>" style="width: 100px;" />
<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>
<?php endforeach; ?>
<?php endif; ?>
</div>
<button type="button" id="fsp-add-event" class="button button-primary" style="margin-bottom: 20px;">
<span class="dashicons dashicons-plus-alt" style="margin-top: 3px;"></span> Neues Ereignis hinzufügen
</button>
<?php submit_button('Einstellungen speichern'); ?>
</form>
</div>
<?php
}
public function render_shortcode() {
$active_events = $this->get_active_events();
if (empty($active_events)) return '';
$names = array_map(fn($e) => $e['name'], $active_events);
return '<div class="fsp-today">Heute feiern wir: <strong>' . esc_html(implode(' + ', $names)) . '</strong></div>';
}
public function register_widget() {
register_widget('FSP_Widget');
}
public function render_music_consent() {
if (get_option('fsp_enable_music', 'yes') !== 'yes') {
return;
}
$active_events = $this->get_active_events();
$has_music = false;
foreach ($active_events as $event) {
if (in_array('music', $event['effects'] ?? [])) { $has_music = true; break; }
}
if (!$has_music) return;
$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>
<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>
<button id="fsp-music-no" style="background:#bdc3c7;color:#333;border:none;padding:8px 15px;border-radius:5px;cursor:pointer;">Nein</button>
</div>
<audio id="fsp-xmas-audio" src="' . $audio_url . '" loop style="display:none;"></audio>
<script>
jQuery(function($) {
const consentBox = $("#fsp-music-consent");
const audioPlayer = $("#fsp-xmas-audio")[0];
setTimeout(() => consentBox.fadeIn(500), 2000);
$("#fsp-music-yes").on("click", function() {
const playPromise = audioPlayer.play();
if (playPromise !== undefined) {
playPromise.then(_ => {
console.log("FSP: Musik wird abgespielt.");
}).catch(error => {
console.error("FSP: Autoplay blockiert. Zeige Steuerelemente an.");
audioPlayer.style.position = "fixed";
audioPlayer.style.bottom = "20px";
audioPlayer.style.left = "20px";
audioPlayer.style.zIndex = "99999";
audioPlayer.style.width = "250px";
audioPlayer.style.display = "block";
audioPlayer.controls = true;
});
}
consentBox.fadeOut(300);
});
$("#fsp-music-no").on("click", function() {
consentBox.fadeOut(300);
});
});
</script>';
}
}
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 widget($args, $instance) {
global $festive_seasons_pro_instance;
if (!$festive_seasons_pro_instance) return;
$active_events = $festive_seasons_pro_instance->get_active_events();
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();