plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_styles() { // Use Lite-specific CSS wp_enqueue_style( $this->plugin_name, plugin_dir_url( __DIR__ ) . 'assets/css/ai-post-summarizer-lite-public.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the public-facing side of the site. * * @since 1.0.0 */ public function enqueue_scripts() { wp_enqueue_script( $this->plugin_name, plugin_dir_url( __DIR__ ) . 'assets/js/ai-post-summarizer-lite-public.js', array( 'jquery' ), $this->version, false ); // Prepare data for JS (Must match Pro structure for compatibility with shared JS) $options = get_option( 'aips_lite_options' ); // Hardcoded default prompt for Lite $prompt_template = 'Summarize the article [POST_TITLE] ([POST_URL]). Focus on the main argument, key evidence, and conclusions. Keep it concise and neutral.'; // Prepare post data $post_data = array(); global $post; if ( is_singular() && $post ) { $post_data = array( 'POST_URL' => get_permalink( $post->ID ), 'POST_TITLE' => get_the_title( $post->ID ), 'POST_EXCERPT' => get_the_excerpt( $post->ID ), 'SITE_NAME' => get_bloginfo( 'name' ), 'AUTHOR_NAME' => get_the_author_meta( 'display_name', $post->post_author ), 'POST_DATE' => get_the_date( '', $post->ID ), ); // Calculate Reading Time (Words / 200 wpm) $word_count = str_word_count( wp_strip_all_tags( $post->post_content ) ); $reading_time = ceil( $word_count / 200 ); $post_data['READING_TIME'] = $reading_time; // Truncate content to ~2000 chars to avoid URL limits $content = wp_strip_all_tags( $post->post_content ); if ( strlen( $content ) > 2000 ) { $content = substr( $content, 0, 2000 ) . '...'; } $post_data['POST_CONTENT'] = $content; } wp_localize_script( $this->plugin_name, 'aips_data', array( 'prompt_template' => $prompt_template, 'post_data' => $post_data, 'floating_button_enabled' => isset( $options['floating_button_enabled'] ) ? (bool) $options['floating_button_enabled'] : false, 'floating_button_position' => isset( $options['floating_button_position'] ) ? $options['floating_button_position'] : 'bottom-right', ) ); } /** * Add AI buttons to the content. * * @since 1.0.0 */ public function add_ai_buttons_to_content( $content ) { if ( ! is_singular( 'post' ) ) { return $content; } $options = get_option( 'aips_lite_options' ); $position = isset( $options['display_position'] ) ? $options['display_position'] : 'before'; $style = isset( $options['button_style'] ) ? $options['button_style'] : 'square'; $button_size = isset( $options['button_size'] ) ? $options['button_size'] : 'small'; $container_classes = array( 'aips-lite-container', 'aips-style-' . esc_attr( $style ), 'aips-text-' . esc_attr( $button_size ), 'aips-btn-size-' . esc_attr( $button_size ), ); $button_html = '
'; $button_html .= '
'; $button_html .= '' . __( 'Summarize with:', 'ai-post-summarizer-lite' ) . ''; // Google AI Button $button_html .= ''; // ChatGPT Button $button_html .= ''; $button_html .= '
'; $button_html .= ''; $button_html .= '
'; if ( 'before' === $position ) { return $button_html . $content; } elseif ( 'after' === $position ) { return $content . $button_html; } else { return $button_html . $content . $button_html; } } /** * Render the floating summarize widget. * * @since 1.1.0 */ public function render_floating_widget() { if ( ! is_singular( 'post' ) ) { return; } $options = get_option( 'aips_lite_options' ); if ( empty( $options['floating_button_enabled'] ) ) { return; } $position = isset( $options['floating_button_position'] ) ? $options['floating_button_position'] : 'bottom-right'; ?>