title = $title; $this->content = $content; $this->link = $link; $this->active_option_name = $active_option_name; $this->active = $active; $this->img = $img; $this->premium = $premium; } /** * Strip HTML tags and get plain text preview */ private function getContentPreview($content, $length = 100) { $plain_text = wp_strip_all_tags($content); $plain_text = preg_replace('/\s+/', ' ', $plain_text); $plain_text = trim($plain_text); if (mb_strlen($plain_text) > $length) { return mb_substr($plain_text, 0, $length) . '...'; } return $plain_text; } /** * Generate unique modal ID for this box */ private function getModalId() { return 'aiautotool_modal_' . sanitize_key($this->active_option_name); } /** * Sanitize title - allow icon tags () for Font Awesome icons * This is safe because we only allow tags with class attribute */ private function sanitizeTitle($title) { $allowed_html = array( 'i' => array( 'class' => array(), 'aria-hidden' => array(), ), 'span' => array( 'class' => array(), ), ); return wp_kses($title, $allowed_html); } /** * Extract icon from title if it contains HTML icon * Returns array ['icon' => '...', 'text' => '...'] */ private function parseTitle($title) { // Check if title contains icon HTML if (preg_match('/]*>.*?<\/i>\s*/i', $title, $matches)) { $icon = $matches[0]; $text = trim(str_replace($icon, '', $title)); return array( 'icon' => $this->sanitizeTitle($icon), 'text' => esc_html($text) ); } // No icon found, return sanitized text return array( 'icon' => '', 'text' => esc_html($title) ); } public function generateHTML() { ?> getModalId(); $content_preview = $this->getContentPreview($this->content, 100); $has_more_content = mb_strlen(wp_strip_all_tags($this->content)) > 100; // Parse title to extract icon and text $parsed_title = $this->parseTitle($this->title); $title_with_icon = $parsed_title['icon'] ? $parsed_title['icon'] . ' ' . $parsed_title['text'] : $parsed_title['text']; $title_text_only = $parsed_title['text']; $new_badge = ''; // Build box_head with either image or Font Awesome icon if (!empty($this->img)) { // Use image if provided $box_head = '
'; } elseif (!empty($parsed_title['icon'])) { // Use Font Awesome icon from title if available $box_head = '
' . $parsed_title['icon'] . '
'; } else { // Default icon if neither image nor icon available $box_head = '
'; } // Build modal icon for modal header if (!empty($this->img)) { // Use image if provided $modal_icon = ''; } elseif (!empty($parsed_title['icon'])) { // Use Font Awesome icon from title if available $modal_icon = '' . $parsed_title['icon'] . ''; } else { // Default icon if neither image nor icon available $modal_icon = ''; } $box_content = '

' . $title_with_icon . '

' . esc_html($content_preview) . '

' . ($has_more_content ? '' : '') . '
'; if($this->premium==true){ if ( !aiautotool_premium()->is__premium_only() ) { $active_checkbox = ' '; }else{ $active_checkbox = ' '; } }else{ $active_checkbox = ' '; } // Modal content $modal_content = ''; if ($has_more_content) { $modal_content = ' '; } // Initialize modal scripts only once - check both PHP flag and JavaScript existence $modal_scripts = ''; if (!self::$modal_initialized) { self::$modal_initialized = true; $modal_scripts = ' '; } $script = ' '; $html = '
' . $new_badge . ' ' . $box_head . ' ' . $box_content . ' ' . $active_checkbox . '
' . $modal_content . ' ' . $modal_scripts . ' ' . $script; return $html; } }