'X (Twitter)', 'linkedin' => 'LinkedIn', 'facebook' => 'Facebook', 'telegram' => 'Telegram', 'whatsapp' => 'WhatsApp', 'email' => 'Email', 'raindrop' => 'Raindrop', 'reddit' => 'Reddit', 'bluesky' => 'Bluesky', 'line' => 'LINE', 'mastodon' => 'Mastodon', 'threads' => 'Threads', 'pinterest' => 'Pinterest', 'claude' => 'Claude AI', 'chatgpt' => 'ChatGPT', 'google_ai' => 'Google AI', 'gemini' => 'Gemini', 'grok' => 'Grok', 'perplexity' => 'Perplexity', 'deepseek' => 'DeepSeek', 'mistral' => 'Mistral AI', 'copilot' => 'Microsoft Copilot', 'qwen' => 'Qwen', 'meta_ai' => 'Meta AI', ); } /** * Get social media buttons list * * @return array Social media button keys. */ function ayudawp_aiss_get_social_buttons() { return array( 'twitter', 'linkedin', 'facebook', 'telegram', 'whatsapp', 'email', 'raindrop', 'reddit', 'bluesky', 'line', 'mastodon', 'threads', 'pinterest' ); } /** * Get AI buttons list * * @return array AI button keys. */ function ayudawp_aiss_get_ai_buttons() { return array( 'claude', 'chatgpt', 'google_ai', 'gemini', 'grok', 'perplexity', 'deepseek', 'mistral', 'copilot', 'qwen', 'meta_ai' ); } /** * Validate and sanitize plugin options * * @param array $input Raw input data. * @return array Validated and sanitized options. */ function ayudawp_aiss_validate_options( $input ) { $validated = array(); // Text fields. $text_fields = array( 'auto_insert_position', 'twitter_handle', 'title_text', 'title_style', 'button_order', 'button_alignment', 'button_colors', 'icon_style', 'seo_button_type', 'data_retention', 'button_size', 'ai_section_title', 'social_section_title', 'mastodon_instance', 'custom_color_bg', 'custom_color_text', ); $textarea_fields = array( 'default_prompt', 'custom_text' ); $array_fields = array( 'enabled_buttons', 'display_locations', 'auto_insert_content_types', 'button_custom_order_ai', 'button_custom_order_social' ); $boolean_fields = array( 'show_icons', 'delete_data_on_uninstall', 'exclude_noindex' ); foreach ( $text_fields as $field ) { if ( isset( $input[ $field ] ) ) { $validated[ $field ] = sanitize_text_field( $input[ $field ] ); } } foreach ( $textarea_fields as $field ) { if ( isset( $input[ $field ] ) ) { $validated[ $field ] = sanitize_textarea_field( $input[ $field ] ); } } foreach ( $array_fields as $field ) { if ( isset( $input[ $field ] ) && is_array( $input[ $field ] ) ) { $validated[ $field ] = array_map( 'sanitize_text_field', $input[ $field ] ); } else { $validated[ $field ] = array(); } } foreach ( $boolean_fields as $field ) { $validated[ $field ] = isset( $input[ $field ] ) ? (bool) $input[ $field ] : false; } // Validate seo_button_type. if ( isset( $validated['seo_button_type'] ) && ! in_array( $validated['seo_button_type'], array( 'link', 'button' ), true ) ) { $validated['seo_button_type'] = 'link'; } // Validate button_alignment. if ( isset( $validated['button_alignment'] ) && ! in_array( $validated['button_alignment'], array( 'left', 'center' ), true ) ) { $validated['button_alignment'] = 'left'; } // Validate data_retention. $valid_retention = array( '1_month', '3_months', '6_months', '1_year', 'forever' ); if ( isset( $validated['data_retention'] ) && ! in_array( $validated['data_retention'], $valid_retention, true ) ) { $validated['data_retention'] = 'forever'; } // Validate button_size. $valid_sizes = array( 'compact', 'normal', 'large', 'fluid' ); if ( isset( $validated['button_size'] ) && ! in_array( $validated['button_size'], $valid_sizes, true ) ) { $validated['button_size'] = 'normal'; } // Validate button_colors. $valid_styles = array( 'minimal', 'brand', 'outline', 'dark', 'icons-only', 'custom' ); if ( isset( $validated['button_colors'] ) && ! in_array( $validated['button_colors'], $valid_styles, true ) ) { $validated['button_colors'] = 'minimal'; } // Sanitize hex colors. if ( isset( $validated['custom_color_bg'] ) ) { $validated['custom_color_bg'] = sanitize_hex_color( $validated['custom_color_bg'] ); } if ( isset( $validated['custom_color_text'] ) ) { $validated['custom_color_text'] = sanitize_hex_color( $validated['custom_color_text'] ); } // Sanitize mastodon instance URL. if ( isset( $validated['mastodon_instance'] ) ) { $validated['mastodon_instance'] = sanitize_text_field( wp_unslash( $validated['mastodon_instance'] ) ); // Remove protocol and trailing slashes. $validated['mastodon_instance'] = preg_replace( '#^https?://#', '', $validated['mastodon_instance'] ); $validated['mastodon_instance'] = rtrim( $validated['mastodon_instance'], '/' ); } return $validated; } /** * Check if buttons should be displayed in current context * * @return bool True if buttons should be displayed. */ function ayudawp_aiss_should_display_buttons() { $options = get_option( 'ayudawp_aiss_options' ); $locations = isset( $options['display_locations'] ) ? $options['display_locations'] : array(); $content_types = isset( $options['auto_insert_content_types'] ) ? $options['auto_insert_content_types'] : array(); if ( empty( $locations ) ) { return false; } if ( is_singular() ) { $post_type = get_post_type(); if ( 'post' === $post_type && in_array( 'posts', $locations, true ) && in_array( 'post', $content_types, true ) ) { return true; } if ( 'page' === $post_type && in_array( 'pages', $locations, true ) && in_array( 'page', $content_types, true ) ) { return true; } if ( 'post' !== $post_type && 'page' !== $post_type && in_array( 'cpt', $locations, true ) && in_array( $post_type, $content_types, true ) ) { return true; } } if ( ( is_archive() || is_category() || is_tag() ) && in_array( 'archives', $locations, true ) ) { return true; } if ( is_home() && in_array( 'home', $locations, true ) ) { return true; } return false; } /** * Check if a specific post is excluded from showing buttons * * Checks both the meta box exclusion and SEO noindex status. * * @since 1.4.0 * @param int $post_id Post ID to check. * @return bool True if post is excluded, false otherwise. */ function ayudawp_aiss_is_post_excluded( $post_id ) { if ( ! $post_id ) { return false; } // Check meta box exclusion. if ( class_exists( 'AyudaWP_AISS_Meta_Box' ) && AyudaWP_AISS_Meta_Box::ayudawp_is_post_excluded( $post_id ) ) { return true; } // Check SEO noindex exclusion if enabled. $options = get_option( 'ayudawp_aiss_options' ); $exclude_noindex = isset( $options['exclude_noindex'] ) ? $options['exclude_noindex'] : true; if ( $exclude_noindex && class_exists( 'AyudaWP_AISS_SEO_Integration' ) ) { if ( AyudaWP_AISS_SEO_Integration::ayudawp_is_post_noindex( $post_id ) ) { return true; } } return false; } /** * Get platform brand colors configuration * * Centralized color definitions used across CSS, JS, and admin. * * @since 1.6.0 * @return array Platform colors as key => hex pairs. */ function ayudawp_aiss_get_platform_colors() { return array( 'twitter' => '#000000', 'linkedin' => '#0077b5', 'facebook' => '#1877f2', 'telegram' => '#26A5E4', 'whatsapp' => '#25d366', 'email' => '#6c757d', 'raindrop' => '#0F66E3', 'reddit' => '#FF4500', 'bluesky' => '#0085FF', 'line' => '#00C300', 'mastodon' => '#6364FF', 'threads' => '#000000', 'pinterest' => '#BD081C', 'claude' => '#D97757', 'chatgpt' => '#10a37f', 'google_ai' => '#E84430', 'gemini' => '#8E75B2', 'grok' => '#000000', 'perplexity' => '#20808D', 'deepseek' => '#4D6BFE', 'mistral' => '#F7D046', 'copilot' => '#6264A7', 'qwen' => '#615CED', 'meta_ai' => '#0081FB', ); } /** * Enqueue frontend CSS, JS and localized data * * Centralised helper so both auto-insert (class-frontend) and * shortcode (class-shortcode) share the same enqueue logic. * Safe to call multiple times — assets are only loaded once. * * @since 1.7.2 */ function ayudawp_aiss_enqueue_frontend_assets() { if ( wp_style_is( 'ayudawp-aiss-styles', 'enqueued' ) ) { return; } wp_enqueue_style( 'ayudawp-aiss-styles', AYUDAWP_AISS_PLUGIN_URL . 'assets/css/ai-share-summarize.css', array(), AYUDAWP_AISS_VERSION ); wp_enqueue_script( 'ayudawp-aiss-scripts', AYUDAWP_AISS_PLUGIN_URL . 'assets/js/ai-share-summarize.js', array( 'jquery' ), AYUDAWP_AISS_VERSION, true ); wp_localize_script( 'ayudawp-aiss-scripts', 'ayudawpAissL10n', array( 'promptCopied' => __( 'Prompt copied to clipboard!', 'ai-share-summarize' ), // Generic copy-prompt tooltips. 'copyPromptShort' => __( 'Copy prompt & open', 'ai-share-summarize' ), 'copyPromptLong' => __( 'Copy prompt and open', 'ai-share-summarize' ), // Gemini specific tooltips. 'geminiTooltipShort' => __( 'Copy prompt & open', 'ai-share-summarize' ), 'geminiTooltipLong' => __( 'Copy prompt and open Gemini', 'ai-share-summarize' ), // DeepSeek specific tooltips. 'deepseekTooltipShort' => __( 'Copy prompt & open', 'ai-share-summarize' ), 'deepseekTooltipLong' => __( 'Copy prompt and open DeepSeek', 'ai-share-summarize' ), // Copilot specific tooltips. 'copilotTooltipShort' => __( 'Copy prompt & open', 'ai-share-summarize' ), 'copilotTooltipLong' => __( 'Copy prompt and open Copilot', 'ai-share-summarize' ), // Platform names for tooltips. 'platformNames' => array( 'twitter' => 'X (Twitter)', 'linkedin' => 'LinkedIn', 'facebook' => 'Facebook', 'telegram' => 'Telegram', 'whatsapp' => 'WhatsApp', 'email' => __( 'Email', 'ai-share-summarize' ), 'raindrop' => 'Raindrop', 'reddit' => 'Reddit', 'bluesky' => 'Bluesky', 'line' => 'LINE', 'claude' => 'Claude AI', 'chatgpt' => 'ChatGPT', 'google_ai' => 'Google AI', 'gemini' => 'Gemini', 'grok' => 'Grok', 'perplexity' => 'Perplexity', 'deepseek' => 'DeepSeek', 'mistral' => 'Mistral AI', 'copilot' => 'Microsoft Copilot', ), // Analytics click tracking (v1.5.0) - no nonce needed for public counter. 'trackUrl' => esc_url_raw( rest_url( 'aiss/v1/track' ) ), ) ); }