'floating', ]; const CONTENT_ZONES = ['incontent', 'before_content', 'after_content']; const WRAP_ZONES = ['incontent', 'before_content', 'after_content', 'selector', 'shortcode', 'hook']; public static function render(array $unit, $zone, $index = 0) { $unit = AdGhost_Helper::normalize_unit($unit); $slot_id = sanitize_html_class('adghost-' . str_replace('_', '-', $zone) . '-' . (int) $index); $sizes = str_replace(';', ',', (string) ($unit['sizes'] ?? '300x250')); if (in_array($zone, self::CONTENT_ZONES, true) && class_exists('AdGhost_Content_Analyzer')) { $sizes = str_replace(';', ',', AdGhost_Content_Analyzer::filter_sizes($sizes, AdGhost_Content_Analyzer::content_max_width())); } if (class_exists('AdGhost_AMP') && AdGhost_AMP::is_amp()) { return AdGhost_AMP::ad($unit, $zone, $sizes); } $align = $unit['align']; if (strpos($align, 'float-') === 0 && !in_array($zone, self::WRAP_ZONES, true)) { $align = 'center'; } $classes = [ 'adghost-ad-container', 'adghost-' . str_replace('_', '-', $zone), 'adghost-align-' . $align, ]; $attrs = [ 'class' => implode(' ', $classes), 'id' => $slot_id, 'data-adghost-slot' => $slot_id, 'data-adghost-id' => (string) ($unit['id'] ?? ''), 'data-adghost-unit' => AdGhost_Helper::gam_code($unit), 'data-adghost-name' => (string) ($unit['name'] ?? ''), 'data-adghost-sizes' => $sizes, 'data-adghost-position' => $zone, 'data-adghost-index' => (string) (int) $index, ]; $feature = AdGhost_Helper::served_feature($unit); $formats = self::behaviour_formats(); if (isset($formats[$feature])) { $attrs['data-adghost-format'] = $formats[$feature]; if ($feature === 'float') { $corner = (string) ($unit['corner'] ?? 'bottom-right'); $attrs['data-adghost-corner'] = in_array($corner, ['bottom-right', 'bottom-left', 'top-right', 'top-left'], true) ? $corner : 'bottom-right'; } } $rides = $feature === 'sticky' || $feature === 'elevator'; $label = self::label(); if ($label !== '') { $attrs['class'] .= ' adghost-has-label'; $attrs['data-adghost-label'] = $label; } $spacing = self::spacing($unit); $pad = (int) ($spacing['padding'] ?? 0); $style = ''; $height = self::reserved_height($sizes); if ($height > 0) { $style .= 'min-height:' . ($height + ($label !== '' ? self::LABEL_HEIGHT : 0) + 2 * $pad) . 'px;'; } $phone_height = self::reserved_height($sizes, self::PHONE_WIDTH); if ($height > 0 && $phone_height !== $height) { $attrs['data-adghost-phone-h'] = '1'; $style .= '--adghost-phone-h:' . ($phone_height > 0 ? $phone_height + ($label !== '' ? self::LABEL_HEIGHT : 0) + 2 * $pad : 0) . 'px;'; } if ($spacing['padding'] !== null) { $style .= 'box-sizing:border-box;padding:' . $pad . 'px;'; } if (!$rides) { $style .= self::margin_style($spacing); } $widest = self::widest($sizes); if ($widest > 0) { $style .= '--adghost-preview-w:' . $widest . 'px;'; } if ($rides) { $attrs['class'] .= ' adghost-sticky' . (($unit['elevatorAlign'] ?? 'top') === 'center' ? ' adghost-ride-center' : ''); $style .= '--adghost-sticky-top:' . min(400, absint($unit['stickyOffset'] ?? 16)) . 'px;--adghost-ad-h:' . max(50, $height + ($label !== '' ? self::LABEL_HEIGHT : 0) + 2 * $pad) . 'px;'; } if ($style !== '') { $attrs['style'] = $style; } $attrs = (array) apply_filters('adghost_container_attributes', $attrs, $unit, $zone); if ($unit['devices'] !== '' && class_exists('AdGhost_Targeting') && AdGhost_Targeting::device_mode() === 'browser') { $attrs['data-adghost-devices'] = str_replace(',', ' ', $unit['devices']); } $html = '