tags from being stripped by WordPress
private function fa_encode($str) { return base64_encode($str); }
private function fa_decode($str) {
$decoded = base64_decode($str, true);
return ($decoded !== false) ? $decoded : $str;
}
private function get_opt($key, $default = '') {
$val = get_option($key);
return (!empty($val)) ? $this->fa_decode($val) : $default;
}
public function fa_admin_assets($hook) {
if ( 'toplevel_page_floaty-ads' !== $hook ) return;
wp_enqueue_media();
wp_add_inline_script( 'jquery', "
jQuery(document).ready(function($){
$('.fa-upload-trigger').on('click', function(e) {
e.preventDefault();
var target = $(this).closest('td').find('textarea');
wp.media({ title: 'Select Image', multiple: false }).on('select', function() {
target.val(this.get('selection').first().toJSON().url);
}).open();
});
$('.fa-delete-trigger').on('click', function() {
if(confirm('Clear this ad slot?')) $(this).closest('td').find('textarea').val('');
});
});
");
}
public function fa_frontend_styles() {
$sw = $this->get_opt('fa_s_w', '180');
$hh = $this->get_opt('fa_h_h', '90');
$fh = $this->get_opt('fa_f_h', '90');
$st = $this->get_opt('fa_s_t', '10');
$show_mobile = $this->get_opt('fa_show_mobile', 'no');
$show_tablet = $this->get_opt('fa_show_tablet', 'no');
$admin_bar = is_admin_bar_showing() ? 32 : 0;
$total_top = (int)$admin_bar + (int)$hh + (int)$st;
$css = "
.fa-sticky-unit { position: fixed !important; display: flex !important; justify-content: center; z-index: 9999999; background: transparent !important; pointer-events: none; margin:0; padding:0; line-height:0; }
.fa-sticky-unit > * { pointer-events: auto; }
/* Layout logic */
.fa-side { width: {$sw}px !important; top: {$total_top}px !important; bottom: " . ((int)$fh + 10) . "px !important; height: auto !important; overflow: hidden; }
.fa-left { left: 5px !important; } .fa-right { right: 5px !important; }
.fa-header { top: {$admin_bar}px !important; left: 0 !important; width: 100% !important; height: {$hh}px !important; background: #fff !important; align-items: center; }
.fa-footer { bottom: 0 !important; left: 0 !important; width: 100% !important; height: {$fh}px !important; background: #fff !important; z-index: 10000000 !important; align-items: center; }
/* Content handling */
.fa-sticky-unit img, .fa-sticky-unit ins, .fa-sticky-unit iframe { max-width: 100% !important; height: auto !important; display: block; margin: 0 auto; }
.fa-header img, .fa-footer img { height: 100% !important; width: auto !important; }
/* Site Pushing */
body.fa-has-header { margin-top: {$hh}px !important; }
body.fa-has-footer { margin-bottom: {$fh}px !important; }
/* Controls */
.fa-close-x { position: absolute; background: #000; color: #fff; border: 1px solid #fff; cursor: pointer; padding: 2px 6px; z-index: 10000001; font-size: 12px; font-weight: bold; border-radius: 2px; top: 2px; right: 2px; line-height: 1; }
.fa-footer .fa-close-x { top: -25px; }
/* Responsive Visibility */
@media (max-width: 767px) { " . ($show_mobile === 'no' ? ".fa-sticky-unit { display: none !important; } body { margin: 0 !important; }" : "") . " }
@media (min-width: 768px) and (max-width: 1024px) { " . ($show_tablet === 'no' ? ".fa-sticky-unit { display: none !important; } body { margin: 0 !important; }" : "") . " }
";
wp_add_inline_style( 'wp-block-library', $css );
}
public function fa_settings_page() {
$keys = ['fa_left', 'fa_right', 'fa_header', 'fa_footer', 'fa_s_w', 'fa_s_t', 'fa_h_h', 'fa_f_h', 'fa_show_mobile', 'fa_show_tablet'];
if ( isset($_POST['fa_save']) ) {
foreach($keys as $key) { update_option($key, $this->fa_encode(wp_unslash($_POST[$key] ?? ''))); }
echo '
Version 7.5 Saved! Ad scripts and device settings are active.
';
}
?>
get_opt($id));
echo "
| $label |
|
|---|
";
}
public function fa_render_all_ads() {
$this->display_unit($this->get_opt('fa_left'), 'left fa-side');
$this->display_unit($this->get_opt('fa_right'), 'right fa-side');
$this->display_unit($this->get_opt('fa_header'), 'header fa-bar');
$this->display_unit($this->get_opt('fa_footer'), 'footer fa-bar');
echo "";
}
private function display_unit($content, $side_class) {
if (empty($content)) return;
$id = explode(' ', $side_class)[0];
echo "
";
echo (strpos($content, '<') !== false) ? $content : "
).")
";
echo "
";
if($id === 'header' || $id === 'footer') echo "";
}
}
new FloatyAdsUltimate();