Upload via GUI (41 Dateien)
This commit is contained in:
+133
-60
@@ -131,6 +131,10 @@ function statistik_manager_get_statistics() {
|
|||||||
|
|
||||||
// Banner-Funktion
|
// Banner-Funktion
|
||||||
function statistik_manager_display_banner($position) {
|
function statistik_manager_display_banner($position) {
|
||||||
|
static $rendered = false;
|
||||||
|
if ($rendered) {
|
||||||
|
return; // verhindert doppelte Ausgabe (wp_body_open + Footer-Fallback)
|
||||||
|
}
|
||||||
if (!get_option('statistik_manager_banner_enabled', 1)) {
|
if (!get_option('statistik_manager_banner_enabled', 1)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -161,21 +165,31 @@ function statistik_manager_get_statistics() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standard-Styles für das Banner
|
$rendered = true;
|
||||||
$style = "background-color: " . esc_attr($banner_color) . ";
|
|
||||||
color: #fff;
|
|
||||||
text-align: center;
|
|
||||||
padding: 10px;
|
|
||||||
width: 100%;
|
|
||||||
height: 50px; /* Feste Höhe */
|
|
||||||
line-height: 30px; /* Zentrierte Schrift */
|
|
||||||
z-index: 9999;
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;";
|
|
||||||
|
|
||||||
$text_style = "font-size: " . esc_attr($font_size_css) . ";";
|
// Standard-Styles für das Banner (auto-Höhe, zentriert, umbruchfähig).
|
||||||
$icon_style = "font-size: 24px; margin-right: 8px;"; // Feste Größe für Icon
|
// !important, damit aktive Themes (z. B. Sueva) Farbe/Breite/Position
|
||||||
|
// nicht per eigener !important-Regel überschreiben können.
|
||||||
|
// top/bottom bewusst ohne !important: wird per Script unter fixe Leisten gesetzt.
|
||||||
|
$vertical_imp = ($position === 'bottom') ? 'bottom: 0;' : 'top: 0;';
|
||||||
|
$style = "background-color: " . esc_attr($banner_color) . " !important;
|
||||||
|
color: #fff !important;
|
||||||
|
text-align: center !important;
|
||||||
|
padding: 12px 16px !important;
|
||||||
|
margin: 0 !important;
|
||||||
|
width: 100% !important;
|
||||||
|
box-sizing: border-box !important;
|
||||||
|
z-index: 99990 !important;
|
||||||
|
position: fixed !important;
|
||||||
|
left: 0 !important;
|
||||||
|
$vertical_imp
|
||||||
|
display: flex !important;
|
||||||
|
align-items: center !important;
|
||||||
|
justify-content: center !important;
|
||||||
|
gap: 8px !important;";
|
||||||
|
|
||||||
|
$text_style = "font-size: " . esc_attr($font_size_css) . " !important; color: #fff !important; margin: 0 !important; line-height: 1.4 !important;";
|
||||||
|
$icon_style = "font-size: 24px !important; margin-right: 8px !important; color: #fff !important;"; // Feste Größe für Icon
|
||||||
|
|
||||||
echo '<div class="statistik-manager-banner" id="statistik-manager-banner" style="' . esc_attr($style) . '">';
|
echo '<div class="statistik-manager-banner" id="statistik-manager-banner" style="' . esc_attr($style) . '">';
|
||||||
|
|
||||||
@@ -188,54 +202,113 @@ function statistik_manager_get_statistics() {
|
|||||||
echo '</div>';
|
echo '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Funktion für das Banner im Header (nach <body>)
|
// Banner an der richtigen Stelle einhängen – abhängig von der konfigurierten
|
||||||
function statistik_manager_display_banner_header() {
|
// Position. Nur wenn das Banner auch wirklich aktiviert ist.
|
||||||
add_action('wp_body_open', function() {
|
function statistik_manager_register_banner() {
|
||||||
statistik_manager_display_banner('top');
|
if (!get_option('statistik_manager_banner_enabled', 1)) {
|
||||||
});
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Falls `wp_body_open` nicht unterstützt wird, als Fallback `wp_footer` nutzen
|
|
||||||
function statistik_manager_display_banner_header_fallback() {
|
|
||||||
add_action('wp_footer', function() {
|
|
||||||
statistik_manager_display_banner('top');
|
|
||||||
}, 5);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Funktion für das Banner im Footer
|
|
||||||
function statistik_manager_display_banner_footer() {
|
|
||||||
add_action('wp_footer', function() {
|
|
||||||
statistik_manager_display_banner('bottom');
|
|
||||||
}, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Banner laden (Header mit Fallback)
|
|
||||||
if (function_exists('wp_body_open')) {
|
|
||||||
statistik_manager_display_banner_header();
|
|
||||||
} else {
|
|
||||||
statistik_manager_display_banner_header_fallback();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix: Admin-Leiste (Wenn Admin angemeldet ist, Banner nach unten verschieben)
|
|
||||||
function statistik_manager_admin_bar_fix() {
|
|
||||||
if (is_admin_bar_showing()) {
|
|
||||||
echo '<style>
|
|
||||||
#statistik-manager-banner {
|
|
||||||
top: 32px !important; /* Admin-Leiste ausgleichen */
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
padding-top: 82px !important; /* Extra Platz für Admin-Leiste */
|
|
||||||
}
|
|
||||||
</style>';
|
|
||||||
} else {
|
|
||||||
echo '<style>
|
|
||||||
body {
|
|
||||||
padding-top: 70px !important; /* Standard Abstand */
|
|
||||||
}
|
|
||||||
</style>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$pos = get_option('statistik_manager_banner_position', 'top');
|
||||||
|
|
||||||
|
if ($pos === 'bottom') {
|
||||||
|
// Unten: im Footer ausgeben
|
||||||
|
add_action('wp_footer', function() {
|
||||||
|
statistik_manager_display_banner('bottom');
|
||||||
|
}, 10);
|
||||||
|
} else {
|
||||||
|
// Oben: bevorzugt direkt nach <body>, plus Footer-Fallback für Themes
|
||||||
|
// ohne wp_body_open (die statische Sperre verhindert Doppelausgabe).
|
||||||
|
add_action('wp_body_open', function() {
|
||||||
|
statistik_manager_display_banner('top');
|
||||||
|
});
|
||||||
|
add_action('wp_footer', function() {
|
||||||
|
statistik_manager_display_banner('top');
|
||||||
|
}, 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Abstand für den Seiteninhalt, damit das fixe Banner nichts verdeckt
|
||||||
|
add_action('wp_head', 'statistik_manager_banner_offset');
|
||||||
|
|
||||||
|
// Am Seitenende sofort nachrechnen – dann sind Banner und fixe Leisten
|
||||||
|
// (z. B. ShiftNav) garantiert im DOM, auch wenn DOMContentLoaded spät kommt.
|
||||||
|
add_action('wp_footer', function() {
|
||||||
|
echo '<script>window.statistikManagerBannerAdjust&&window.statistikManagerBannerAdjust();</script>';
|
||||||
|
}, 999);
|
||||||
|
}
|
||||||
|
add_action('wp', 'statistik_manager_register_banner');
|
||||||
|
|
||||||
|
// Fügt NUR bei aktivem Banner den passenden Abstand hinzu – auf der richtigen
|
||||||
|
// Seite (oben/unten) und mit Rücksicht auf die WordPress-Admin-Leiste.
|
||||||
|
function statistik_manager_banner_offset() {
|
||||||
|
if (!get_option('statistik_manager_banner_enabled', 1)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pos = get_option('statistik_manager_banner_position', 'top');
|
||||||
|
$h = 56; // ungefähre Bannerhöhe – nur für den No-JS-Fallback
|
||||||
|
|
||||||
|
// Fallback ohne JavaScript (WordPress verschiebt die Seite für die
|
||||||
|
// Admin-Leiste bereits selbst per html-margin, daher hier nicht addieren).
|
||||||
|
echo '<noscript><style>';
|
||||||
|
if ($pos === 'bottom') {
|
||||||
|
echo 'body { padding-bottom: ' . $h . 'px !important; }';
|
||||||
|
} else {
|
||||||
|
echo 'body { padding-top: ' . $h . 'px !important; }';
|
||||||
|
if (is_admin_bar_showing()) {
|
||||||
|
echo '#statistik-manager-banner { top: 32px !important; }';
|
||||||
|
echo '@media screen and (max-width: 782px) { #statistik-manager-banner { top: 46px !important; } }';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo '</style></noscript>';
|
||||||
|
|
||||||
|
// Mit JavaScript: Banner exakt unter fixe Leisten oben setzen (WP-Admin-Leiste,
|
||||||
|
// ShiftNav-Menüleiste), sonst verdecken diese es. Der Inhalt wird nur um die
|
||||||
|
// tatsächliche Bannerhöhe verschoben – zusätzlich zum vorhandenen Abstand
|
||||||
|
// des Themes, damit das Layout ansonsten unverändert bleibt.
|
||||||
|
$is_bottom = ($pos === 'bottom') ? 'true' : 'false';
|
||||||
|
echo '<script>(function(){'
|
||||||
|
. 'var isBottom=' . $is_bottom . ';'
|
||||||
|
. 'var bars=["wpadminbar","shiftnav-toggle-main"];'
|
||||||
|
. 'function adjust(){'
|
||||||
|
. 'var b=document.getElementById("statistik-manager-banner");'
|
||||||
|
. 'if(!b){return;}'
|
||||||
|
. 'var s=document.body.style,prop=isBottom?"padding-bottom":"padding-top";'
|
||||||
|
. 's.removeProperty(prop);'
|
||||||
|
. 'var base=parseFloat(getComputedStyle(document.body)[isBottom?"paddingBottom":"paddingTop"])||0;'
|
||||||
|
. 'var extra=0;'
|
||||||
|
. 'if(!isBottom){'
|
||||||
|
. 'var off=0;'
|
||||||
|
. 'bars.forEach(function(id){'
|
||||||
|
. 'var e=document.getElementById(id);if(!e){return;}'
|
||||||
|
. 'var c=getComputedStyle(e);'
|
||||||
|
. 'if(c.position!=="fixed"||c.display==="none"||c.visibility==="hidden"){return;}'
|
||||||
|
. 'var r=e.getBoundingClientRect();'
|
||||||
|
. 'if(r.height>0&&r.bottom>off){off=r.bottom;}'
|
||||||
|
. '});'
|
||||||
|
. 'b.style.setProperty("top",off+"px","important");'
|
||||||
|
// Inhalt komplett unter Leisten + Banner beginnen lassen; die Admin-Leiste
|
||||||
|
// hat WordPress per html-margin bereits berücksichtigt.
|
||||||
|
. 'var hm=parseFloat(getComputedStyle(document.documentElement).marginTop)||0;'
|
||||||
|
. 'extra=Math.max(0,off-hm);'
|
||||||
|
. '}'
|
||||||
|
. 's.setProperty(prop,(base+extra+b.offsetHeight)+"px","important");'
|
||||||
|
. '}'
|
||||||
|
. 'window.statistikManagerBannerAdjust=adjust;'
|
||||||
|
. 'function watch(){'
|
||||||
|
. 'adjust();'
|
||||||
|
// Nachzügler abfangen (verzögert geladene CSS/JS anderer Plugins)
|
||||||
|
. '[300,1000,2500,5000].forEach(function(t){setTimeout(adjust,t);});'
|
||||||
|
. 'if(window.ResizeObserver){'
|
||||||
|
. 'var ro=new ResizeObserver(function(){adjust();});'
|
||||||
|
. '["statistik-manager-banner"].concat(bars).forEach(function(id){var e=document.getElementById(id);if(e){ro.observe(e);}});'
|
||||||
|
. '}'
|
||||||
|
. '}'
|
||||||
|
. 'if(document.readyState!=="loading"){watch();}else{document.addEventListener("DOMContentLoaded",watch);}'
|
||||||
|
. 'window.addEventListener("load",adjust);'
|
||||||
|
. 'window.addEventListener("resize",adjust);'
|
||||||
|
. '})();</script>';
|
||||||
}
|
}
|
||||||
add_action('wp_head', 'statistik_manager_admin_bar_fix');
|
|
||||||
|
|
||||||
// Shortcode für die Anzeige der Statistiken
|
// Shortcode für die Anzeige der Statistiken
|
||||||
function statistik_manager_shortcode() {
|
function statistik_manager_shortcode() {
|
||||||
|
|||||||
Reference in New Issue
Block a user