Plugin Directory

Changeset 3383029


Ignore:
Timestamp:
10/23/2025 03:37:51 AM (4 months ago)
Author:
hmamoun
Message:

Release version 2.1.3: Add AI Story Enhancer feature, improve social media integration, and enhance analytics dashboard

Location:
ai-story-maker
Files:
12 added
10 edited

Legend:

Unmodified
Added
Removed
  • ai-story-maker/tags/2.1.0/admin/class-aistma-admin.php

    r3376817 r3383029  
    363363        // Register hooks for auto-publishing new posts
    364364        add_action( 'transition_post_status', array( $this, 'auto_publish_to_social_media' ), 10, 3 );
    365         add_action( 'wp_insert_post', array( $this, 'handle_new_published_post' ), 10, 3 );
    366365    }
    367366
     
    881880    }
    882881
    883     /**
    884      * Handle posts that are created directly with 'publish' status.
    885      *
    886      * @param int     $post_id Post ID.
    887      * @param WP_Post $post    Post object.
    888      * @param bool    $update  Whether this is an existing post being updated.
    889      */
    890     public function handle_new_published_post( $post_id, $post, $update ) {
    891         // Only process new posts (not updates)
    892         if ( $update ) {
    893             return;
    894         }
    895 
    896         // Only process posts that are published
    897         if ( $post->post_status !== 'publish' ) {
    898             return;
    899         }
    900 
    901         // Only process standard posts (not pages, attachments, etc.)
    902         if ( $post->post_type !== 'post' ) {
    903             return;
    904         }
    905 
    906         // Call the same auto-publish logic
    907         // We simulate a transition from 'new' to 'publish' status
    908         $this->auto_publish_to_social_media( 'publish', 'new', $post );
    909     }
    910882}
    911883
  • ai-story-maker/tags/2.1.2/admin/class-aistma-admin.php

    r3379244 r3383029  
    447447        // Register hooks for auto-publishing new posts
    448448        add_action( 'transition_post_status', array( $this, 'auto_publish_to_social_media' ), 10, 3 );
    449         add_action( 'wp_insert_post', array( $this, 'handle_new_published_post' ), 10, 3 );
    450449    }
    451450
     
    13241323    }
    13251324
    1326     /**
    1327      * Handle posts that are created directly with 'publish' status.
    1328      *
    1329      * @param int     $post_id Post ID.
    1330      * @param WP_Post $post    Post object.
    1331      * @param bool    $update  Whether this is an existing post being updated.
    1332      */
    1333     public function handle_new_published_post( $post_id, $post, $update ) {
    1334         // Only process new posts (not updates)
    1335         if ( $update ) {
    1336             return;
    1337         }
    1338    
    1339         // Only process posts that are published
    1340         if ( $post->post_status !== 'publish' ) {
    1341             return;
    1342         }
    1343    
    1344         // Only process standard posts (not pages, attachments, etc.)
    1345         if ( $post->post_type !== 'post' ) {
    1346             return;
    1347         }
    1348    
    1349         // Check if this post was already shared (prevent duplicates)
    1350         $already_shared = get_post_meta( $post_id, '_aistma_social_shared', true );
    1351         if ( $already_shared ) {
    1352             return;
    1353         }
    1354    
    1355         // Mark as shared before processing
    1356         update_post_meta( $post_id, '_aistma_social_shared', true );
    1357    
    1358         // Call the same auto-publish logic
    1359         $this->auto_publish_to_social_media( 'publish', 'new', $post );
    1360     }
    13611325}
    13621326
  • ai-story-maker/trunk/README.txt

    r3379243 r3383029  
    55Tested up to: 6.8
    66Requires PHP: 7.4
    7 Stable tag: 2.1.2
     7Stable tag: 2.1.3
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    1212Author URI: https://exedotcom.ca
    1313
    14 AI-powered WordPress plugin to automatically generate unique stories, articles, and visuals using OpenAI and Unsplash APIs.
     14AI-powered WordPress plugin to generate unique stories and articles using OpenAI and Unsplash APIs. Features AI Story Enhancer for text improvement.
    1515
    1616== Description ==
    1717
    18 **AI Story Maker** helps you instantly generate unique, high-quality WordPress posts using AI and royalty-free images. It integrates with OpenAI for text generation and Unsplash for fetching dynamic images, saving you hours of content creation time.
     18**AI Story Maker** generates unique, high-quality WordPress posts using AI and royalty-free images. Integrates with OpenAI and Unsplash, saving hours of content creation time.
     19
     20**🆕 NEW: AI Story Enhancer** - Transform your content creation workflow with intelligent, AI-powered text improvement capabilities directly within your WordPress admin interface. Simply select any text in your posts and enhance it with AI for professional-quality results.
    1921
    2022Whether you're a blogger, marketer, or educator, AI Story Maker helps you build a full content strategy effortlessly.
     
    2224== Features ==
    2325
     26### AI Story Enhancer (NEW!)
     27- **Smart Text Selection** – Simply select any text in your post content and enhance it with AI
     28- **Context-Aware Improvements** – AI understands your content context and provides relevant enhancements
     29- **One-Click Access** – "AI Story Enhancer" link appears under every post in your posts list
     30- **Free Usage** – Enhanced content is free to use with usage tracking
     31- **Professional Results** – AI-powered enhancements that rival professional editors
     32- **Seamless Integration** – Works directly within your existing WordPress workflow
     33
     34### Core Features
    2435- **Subscription-Based Access** – Access AI generation through package subscriptions including free options.
    2536- **AI-Generated Stories** – Create unique, professional stories and articles using OpenAI.
     
    122133- In a PHP template file using: echo do_shortcode('[aistma_scroller]');
    123134
    124 === How to Use ===
     135=== How to Use AI Story Enhancer ===
     136
     1371. Navigate to **Posts → All Posts** in your WordPress admin
     1382. Find any post and click **"AI Story Enhancer"** under the post title
     1393. In the editor, select any text in the content preview area
     1404. Enter your enhancement instructions (e.g., "Make this more engaging", "Add more details", "Improve readability")
     1415. Click **"Improve"** to see AI-powered enhancements
     1426. Review the improved text and click **"Save Changes"** when satisfied
     143
     144**Pro Tips:**
     145- Use specific instructions for better results (e.g., "Make this more conversational" vs. "Improve this")
     146- The AI understands context, so it will enhance text appropriately for your content type
     147- You can enhance multiple sections of the same post
     148- Changes are tracked automatically - the save button only enables when you have unsaved changes
     149
     150=== How to Use Core Features ===
    125151
    1261521. Edit a page or post in WordPress.
     
    325351No additional personal user data is collected or stored.
    326352
     353== FAQ ==
     354
     355= What is AI Story Enhancer? =
     356
     357AI Story Enhancer is a new feature that allows you to enhance any text in your WordPress posts using AI. Simply select text, provide instructions, and get professional-quality improvements instantly.
     358
     359= How do I access AI Story Enhancer? =
     360
     361Navigate to **Posts → All Posts** in your WordPress admin and click **"AI Story Enhancer"** under any post title. This will open the enhancement interface.
     362
     363= Is AI Story Enhancer free to use? =
     364
     365Yes! AI Story Enhancer is completely free to use. There are no subscription fees or usage limits for content enhancement.
     366
     367= What types of improvements can AI Story Enhancer make? =
     368
     369AI Story Enhancer can improve readability, add details, enhance engagement, improve SEO, make content more conversational, and much more. The AI understands context and provides relevant enhancements.
     370
     371= Can I enhance multiple sections of the same post? =
     372
     373Yes! You can enhance as many sections as you want in the same post. Each enhancement is independent and can be saved together.
     374
     375= Does AI Story Enhancer work with all WordPress themes? =
     376
     377Yes, AI Story Enhancer is designed to work with all WordPress themes and doesn't interfere with your site's styling.
     378
     379= How does the smart save system work? =
     380
     381The save button is automatically disabled when there are no changes. It only enables when you make changes to the content, tags, or meta description, ensuring you only save when necessary.
     382
    327383== Contributing ==
    328384
     
    330386
    331387== Changelog ==
     388
     389= 2.1.3 =
     390* **NEW: AI Story Enhancer**
     391  * Added intelligent text enhancement capabilities
     392  * Smart text selection and AI-powered improvements
     393  * One-click access from posts list
     394  * Free usage with usage tracking
     395  * Professional-quality content enhancements
     396  * Seamless WordPress integration
     397  * Smart save system with change detection
     398  * Enhanced tags and SEO management
     399  * Modern, responsive interface
    332400
    333401= 2.1.2 =
  • ai-story-maker/trunk/admin/class-aistma-admin.php

    r3379243 r3383029  
    447447        // Register hooks for auto-publishing new posts
    448448        add_action( 'transition_post_status', array( $this, 'auto_publish_to_social_media' ), 10, 3 );
    449         add_action( 'wp_insert_post', array( $this, 'handle_new_published_post' ), 10, 3 );
    450449    }
    451450
     
    690689        }
    691690       
     691        $post_url = get_permalink( $post );
     692       
     693        // Add "Read More.." with post link
     694        $message .= "\n\nRead More.. " . $post_url;
     695       
    692696        // Add hashtags if enabled
    693697        $hashtags = $this->get_social_media_hashtags( $post );
     
    695699            $message .= "\n\n" . $hashtags;
    696700        }
    697        
    698         $post_url = get_permalink( $post );
    699701
    700702        // Facebook Graph API endpoint
     
    833835        }
    834836       
    835         // Add post tags as hashtags if enabled
    836         if ( ! empty( $global_settings['include_hashtags'] ) ) {
    837             $post_tags = get_the_tags( $post->ID );
    838             if ( $post_tags && ! is_wp_error( $post_tags ) ) {
    839                 foreach ( $post_tags as $tag ) {
    840                     // Convert tag name to hashtag format
    841                     $hashtag = '#' . str_replace( ' ', '', $tag->name );
    842                     $hashtags[] = $hashtag;
    843                 }
     837        // Always add post tags as hashtags
     838        $post_tags = get_the_tags( $post->ID );
     839        if ( $post_tags && ! is_wp_error( $post_tags ) ) {
     840            foreach ( $post_tags as $tag ) {
     841                // Convert tag name to hashtag format
     842                $hashtag = '#' . str_replace( ' ', '', $tag->name );
     843                $hashtags[] = $hashtag;
    844844            }
    845845        }
     
    11511151            if ( isset( $subscription_status['error'] ) ) {
    11521152                $this->aistma_log_manager->log( 'warning', 'Subscription validation failed: ' . $subscription_status['error'] );
    1153             }
    1154            
     1153                // Additional debug logging only in debug mode
     1154                if ( defined( 'WP_DEBUG' ) && WP_DEBUG && function_exists( 'wp_debug_log' ) ) {
     1155                    wp_debug_log( 'Subscription validation failed: ' . $subscription_status['error'] );
     1156                }
     1157            }
    11551158            // Try fallback: check if UI shows active subscription (packages-summary endpoint)
    11561159            $fallback_check = $this->check_subscription_via_packages_api();
     
    13241327    }
    13251328
    1326     /**
    1327      * Handle posts that are created directly with 'publish' status.
    1328      *
    1329      * @param int     $post_id Post ID.
    1330      * @param WP_Post $post    Post object.
    1331      * @param bool    $update  Whether this is an existing post being updated.
    1332      */
    1333     public function handle_new_published_post( $post_id, $post, $update ) {
    1334         // Only process new posts (not updates)
    1335         if ( $update ) {
    1336             return;
    1337         }
    1338    
    1339         // Only process posts that are published
    1340         if ( $post->post_status !== 'publish' ) {
    1341             return;
    1342         }
    1343    
    1344         // Only process standard posts (not pages, attachments, etc.)
    1345         if ( $post->post_type !== 'post' ) {
    1346             return;
    1347         }
    1348    
    1349         // Check if this post was already shared (prevent duplicates)
    1350         $already_shared = get_post_meta( $post_id, '_aistma_social_shared', true );
    1351         if ( $already_shared ) {
    1352             return;
    1353         }
    1354    
    1355         // Mark as shared before processing
    1356         update_post_meta( $post_id, '_aistma_social_shared', true );
    1357    
    1358         // Call the same auto-publish logic
    1359         $this->auto_publish_to_social_media( 'publish', 'new', $post );
    1360     }
    13611329}
    13621330
  • ai-story-maker/trunk/admin/class-aistma-settings-page.php

    r3379225 r3383029  
    154154
    155155        $url      = aistma_get_api_url( 'wp-json/exaig/v1/packages-summary' );
     156        $args = array(
     157            'timeout' => 10,
     158            'headers' => array(
     159                'X-Caller-Url' => home_url(),
     160                'X-Caller-IP'  => isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '',
     161            ),
     162        );
    156163        $response = wp_remote_get(
    157164            $url,
    158             array(
    159                 'timeout' => 10,
    160                 'headers' => array(
    161                     'X-Caller-Url' => home_url(),
    162                     'X-Caller-IP'  => isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '',
    163                 ),
    164             )
    165         );
     165            $args
     166        );
     167
     168        // Debug logging only in debug mode
     169        if ( defined( 'WP_DEBUG' ) && WP_DEBUG && function_exists( 'wp_debug_log' ) ) {
     170            wp_debug_log( 'URL: ' . $url );
     171        }
    166172
    167173        // Prepare the standardized wrapper structure
  • ai-story-maker/trunk/admin/templates/subscriptions-template.php

    r3379225 r3383029  
    283283                    ?>
    284284            </span>
     285           
     286            <?php
     287            // Display enhancements per post if available
     288            $enhancements_per_post = isset($package['enhancements_per_post']) ? intval($package['enhancements_per_post']) : 0;
     289            if ($enhancements_per_post > 0) {
     290                echo '<span style="display: block; margin-top: 4px;"><strong>Enhancements:</strong> ' . esc_html($enhancements_per_post . ' per post') . '</span>';
     291            } elseif ($enhancements_per_post === 0) {
     292                echo '<span style="display: block; margin-top: 4px;"><strong>Enhancements:</strong> Unlimited per post</span>';
     293            }
     294            ?>
    285295                <div class="aistma-current-plan-line" style="<?php echo $is_current && $status_line ? 'display:block;margin-top:8px;font-weight:600;color:#0073aa;' : 'display:none;'; ?>"><?php echo $is_current ? esc_html( $status_line ) : ''; ?></div>
    286296               
  • ai-story-maker/trunk/ai-story-maker.php

    r3379243 r3383029  
    44 * Plugin URI: https://www.storymakerplugin.com/
    55 * Description: AI-powered content generator for WordPress — create engaging stories with a single click.
    6  * Version: 2.1.2
     6 * Version: 2.1.3
    77 * Author: Hayan Mamoun
    88 * Author URI: https://exedotcom.ca
     
    2929
    3030
    31 
    3231use exedotcom\aistorymaker\AISTMA_Story_Generator;
    3332
    3433require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-plugin.php';
    3534require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-posts-gadget.php';
     35require_once plugin_dir_path( __FILE__ ) . 'admin/class-aistma-standalone-editor.php';
     36require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-content-editor-handler.php';
     37require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-open-graph.php';
    3638
    3739// Hooks.
     
    4749        echo '<!-- Posts Gadget class loaded successfully -->';
    4850    });
     51}
     52
     53// Initialize Standalone Content Editor
     54if ( class_exists( '\\exedotcom\\aistorymaker\\AISTMA_Standalone_Editor' ) ) {
     55    new \exedotcom\aistorymaker\AISTMA_Standalone_Editor();
     56}
     57
     58// Initialize Content Editor Handler
     59if ( class_exists( '\\exedotcom\\aistorymaker\\AISTMA_Content_Editor_Handler' ) ) {
     60    new \exedotcom\aistorymaker\AISTMA_Content_Editor_Handler();
     61}
     62
     63// Initialize Open Graph Meta Tags Handler
     64if ( class_exists( '\\exedotcom\\aistorymaker\\AISTMA_Open_Graph' ) ) {
     65    new \exedotcom\aistorymaker\AISTMA_Open_Graph();
    4966}
    5067
     
    6380        try {
    6481            $story_generator = new AISTMA_Story_Generator();
    65             $story_generator->generate_ai_stories_with_lock( true );
    66             wp_send_json_success( array( 'message' => 'Stories generated successfully.' ) );
     82            $result = $story_generator->generate_ai_stories_with_lock( true );
     83           
     84            if ( $result['success'] ) {
     85                wp_send_json_success( array( 'message' => $result['message'] ) );
     86            } else {
     87                wp_send_json_error( array( 'message' => $result['message'] ) );
     88            }
    6789        } catch ( \Throwable $e ) {
    6890            wp_send_json_error( array( 'message' => 'Fatal error: ' . $e->getMessage() ) );
     
    91113 */
    92114function aistma_handle_generate_story_event() {
    93     AISTMA_Story_Generator::generate_ai_stories_with_lock();
     115    $result = AISTMA_Story_Generator::generate_ai_stories_with_lock();
     116    // Log the result for cron jobs (only in debug mode)
     117    if ( defined( 'WP_DEBUG' ) && WP_DEBUG && function_exists( 'wp_debug_log' ) ) {
     118        if ( $result['success'] ) {
     119            wp_debug_log( 'AI Story Maker Cron: ' . $result['message'] );
     120        } else {
     121            wp_debug_log( 'AI Story Maker Cron Error: ' . $result['message'] );
     122        }
     123    }
    94124}
    95125function aistma_get_master_url(string $path = ''): string {
  • ai-story-maker/trunk/includes/class-aistma-story-generator.php

    r3379243 r3383029  
    7676     *
    7777     * @param  bool $force Whether to force generation regardless of lock.
    78      * @return void
     78     * @return array Array with 'success' boolean and 'message' string.
    7979     */
    8080    public static function generate_ai_stories_with_lock( $force = false ) {
     
    8383        if ( ! $force && get_transient( $lock_key ) ) {
    8484            $instance->aistma_log_manager->log( 'info', 'Story generation skipped due to active lock.' );
    85             return;
     85            return array( 'success' => false, 'message' => 'Story generation is already in progress.' );
    8686        }
    8787
     
    103103                   
    104104                    $instance->aistma_log_manager::log( 'error', $error_message );
    105                     throw new \RuntimeException( $error_message );
     105                    return array( 'success' => false, 'message' => $error_message );
    106106                } else {
    107107                    $instance->aistma_log_manager::log( 'info', 'No valid subscription found, but OpenAI API key is available. Will use direct OpenAI API calls.' );
     
    110110        } catch ( \RuntimeException $e ) {
    111111            $error = $e->getMessage();
    112             //$instance->aistma_log_manager::log( 'error', $error );
    113             throw new \RuntimeException( esc_html( $error ) );
     112            $instance->aistma_log_manager->log( 'error', $error );
     113            return array( 'success' => false, 'message' => esc_html( $error ) );
    114114        }
    115115
     
    118118            // Pass the instance with cached subscription status to generate_ai_stories
    119119            $instance->generate_ai_stories();
    120             //$instance->aistma_log_manager->log( 'info', 'Stories successfully generated.' );
     120            $instance->aistma_log_manager->log( 'info', 'Stories successfully generated.' );
     121            return array( 'success' => true, 'message' => 'Stories generated successfully.' );
    121122        } catch ( \Throwable $e ) {
    122123            $instance->aistma_log_manager->log( 'error', 'Error generating stories: ' . $e->getMessage() );
    123             delete_transient( $lock_key );
    124             wp_send_json_error( array( 'message' => 'Error generating stories: ' . $e->getMessage() ) );
     124            return array( 'success' => false, 'message' => 'Error generating stories: ' . $e->getMessage() );
    125125        } finally {
    126126            // Always delete the lock, even if an error occurs.
     
    507507        }
    508508
     509        // Determine post status based on auto_publish setting
     510        $auto_publish_value = isset( $prompt['auto_publish'] ) ? $prompt['auto_publish'] : false;
     511        $post_status = ( 1 === $auto_publish_value || true === $auto_publish_value ) ? 'publish' : 'draft';
     512       
     513        // Debug logging for auto_publish
     514        $this->aistma_log_manager->log( 'debug', 'Master API - Auto publish value: ' . ( $auto_publish_value ? 'true' : 'false' ) . ' (type: ' . gettype( $auto_publish_value ) . '), Post status: ' . $post_status );
     515
    509516        // Create the post.
    510517        $post_data = array(
     
    512519            'post_content' => $content,
    513520            'post_excerpt' => $excerpt,
    514             'post_status'  => isset( $prompt['auto_publish'] ) && 1 === $prompt['auto_publish'] ? 'publish' : 'draft',
     521            'post_status'  => $post_status,
    515522            'post_author'  => $post_author,
    516523            'post_category' => array( $category_id ),
     
    570577            update_post_meta( $post_id, 'ai_story_maker_request_id', $request_id ?? 'N/A' );
    571578            update_post_meta( $post_id, 'ai_story_maker_generated_via', 'master_api' );
     579           
     580            // Add enhancement tracking meta data
     581            $package_name = isset( $data['package_name'] ) ? sanitize_text_field( $data['package_name'] ) : '';
     582            if ( ! empty( $package_name ) ) {
     583                // Get package ID from name (this assumes packages are stored with sequential IDs)
     584                $package_id = $this->get_package_id_by_name( $package_name );
     585                if ( $package_id !== false ) {
     586                    $enhancement_limit = $this->get_package_enhancement_limit( $package_id );
     587                    update_post_meta( $post_id, 'ai_story_maker_package_id', $package_id );
     588                    update_post_meta( $post_id, 'ai_story_maker_enhancements_limit', $enhancement_limit );
     589                    update_post_meta( $post_id, 'ai_story_maker_enhancements_history', wp_json_encode( [] ) );
     590                   
     591                    // Debug logging
     592                    $this->aistma_log_manager->log( 'info', 'Enhancement meta added to post ' . $post_id . ': package_name=' . $package_name . ', package_id=' . $package_id . ', limit=' . $enhancement_limit );
     593                } else {
     594                    $this->aistma_log_manager->log( 'warning', 'Could not find package ID for package name: ' . $package_name );
     595                }
     596            } else {
     597                $this->aistma_log_manager->log( 'warning', 'No package_name found in Master API response for post ' . $post_id );
     598            }
     599           
    572600            // $this->aistma_log_manager->log( 'success', 'AI-generated news article created via Master API: ' . get_permalink( $post_id ), $request_id );
    573601        }
     
    627655        }
    628656
     657        // Determine post status based on auto_publish setting
     658        $auto_publish_value = isset( $prompt['auto_publish'] ) ? $prompt['auto_publish'] : false;
     659        $post_status = ( 1 === $auto_publish_value || true === $auto_publish_value ) ? 'publish' : 'draft';
     660       
     661        // Debug logging for auto_publish
     662        $this->aistma_log_manager->log( 'debug', 'OpenAI API - Auto publish value: ' . ( $auto_publish_value ? 'true' : 'false' ) . ' (type: ' . gettype( $auto_publish_value ) . '), Post status: ' . $post_status );
     663
    629664        // Create the post.
    630665        $post_data = array(
     
    632667            'post_content' => $content,
    633668            'post_excerpt' => $excerpt,
    634             'post_status'  => isset( $prompt['auto_publish'] ) && 1 === $prompt['auto_publish'] ? 'publish' : 'draft',
     669            'post_status'  => $post_status,
    635670            'post_author'  => $post_author,
    636671            'post_category' => array( $category_id ),
     
    662697            update_post_meta( $post_id, 'ai_story_maker_request_id', $request_id ?? 'N/A' );
    663698            update_post_meta( $post_id, 'ai_story_maker_generated_via', 'openai_api' );
     699           
     700            // Add enhancement tracking meta data for OpenAI API generated posts
     701            // For OpenAI API posts, we'll use a default package or get from subscription
     702            $subscription_info = $this->get_subscription_info();
     703            $package_name = $subscription_info['package_name'] ?? '';
     704            if ( ! empty( $package_name ) ) {
     705                $package_id = $this->get_package_id_by_name( $package_name );
     706                if ( $package_id !== false ) {
     707                    $enhancement_limit = $this->get_package_enhancement_limit( $package_id );
     708                    update_post_meta( $post_id, 'ai_story_maker_package_id', $package_id );
     709                    update_post_meta( $post_id, 'ai_story_maker_enhancements_limit', $enhancement_limit );
     710                    update_post_meta( $post_id, 'ai_story_maker_enhancements_history', wp_json_encode( [] ) );
     711                }
     712            }
     713           
    664714            $this->aistma_log_manager->log( 'success', 'AI-generated news article created via OpenAI API: ' . get_permalink( $post_id ), $request_id );
    665715        }
     
    11931243    }
    11941244
     1245
     1246
     1247    /**
     1248     * Get package ID by package name from API Gateway.
     1249     *
     1250     * @param string $package_name The package name to search for.
     1251     * @return int|false Package ID if found, false otherwise.
     1252     */
     1253    private function get_package_id_by_name( $package_name ) {
     1254        $gateway_url = aistma_get_api_url();
     1255        if ( empty( $gateway_url ) ) {
     1256            $this->aistma_log_manager->log( 'error', 'API Gateway URL not configured for package lookup' );
     1257            return false;
     1258        }
     1259
     1260        $api_url = trailingslashit( $gateway_url ) . 'wp-json/exaig/v1/packages-summary';
     1261       
     1262        $this->aistma_log_manager->log( 'info', 'Looking up package ID for: ' . $package_name . ' at URL: ' . $api_url );
     1263       
     1264        $response = wp_remote_get( $api_url, [
     1265            'timeout' => 10,
     1266            'headers' => [
     1267                'User-Agent' => 'AI-Story-Maker/1.0'
     1268            ]
     1269        ] );
     1270
     1271        if ( is_wp_error( $response ) ) {
     1272            $this->aistma_log_manager->log( 'error', 'Error fetching packages from API Gateway: ' . $response->get_error_message() );
     1273            return false;
     1274        }
     1275
     1276        $body = wp_remote_retrieve_body( $response );
     1277        $data = json_decode( $body, true );
     1278
     1279        if ( is_array( $data ) ) {
     1280            $this->aistma_log_manager->log( 'info', 'Found ' . count( $data ) . ' packages from API Gateway' );
     1281            $this->aistma_log_manager->log( 'info', 'Available packages: ' . implode( ', ', array_column( $data, 'name' ) ) );
     1282            foreach ( $data as $index => $package ) {
     1283                if ( isset( $package['name'] ) && $package['name'] === $package_name ) {
     1284                    $this->aistma_log_manager->log( 'info', 'Found matching package: ' . $package_name . ' with ID: ' . $index );
     1285                    return $index; // Return the index as package ID
     1286                }
     1287            }
     1288            $this->aistma_log_manager->log( 'warning', 'Package not found: ' . $package_name . ' in available packages: ' . implode( ', ', array_column( $data, 'name' ) ) );
     1289        } else {
     1290            $this->aistma_log_manager->log( 'error', 'Invalid packages data from API Gateway: ' . $body );
     1291        }
     1292
     1293        return false;
     1294    }
     1295
     1296    /**
     1297     * Get package enhancement limit by package ID from API Gateway.
     1298     *
     1299     * @param int $package_id The package ID.
     1300     * @return int Enhancement limit (0 = unlimited).
     1301     */
     1302    private function get_package_enhancement_limit( $package_id ) {
     1303        $gateway_url = aistma_get_api_url();
     1304        if ( empty( $gateway_url ) ) {
     1305            $this->aistma_log_manager->log( 'error', 'API Gateway URL not configured for enhancement limit lookup' );
     1306            return 0;
     1307        }
     1308
     1309        $api_url = trailingslashit( $gateway_url ) . 'wp-json/exaig/v1/packages-summary';
     1310       
     1311        $this->aistma_log_manager->log( 'info', 'Looking up enhancement limit for package ID: ' . $package_id );
     1312       
     1313        $response = wp_remote_get( $api_url, [
     1314            'timeout' => 10,
     1315            'headers' => [
     1316                'User-Agent' => 'AI-Story-Maker/1.0'
     1317            ]
     1318        ] );
     1319
     1320        if ( is_wp_error( $response ) ) {
     1321            $this->aistma_log_manager->log( 'error', 'Error fetching packages for enhancement limit: ' . $response->get_error_message() );
     1322            return 0;
     1323        }
     1324
     1325        $body = wp_remote_retrieve_body( $response );
     1326        $data = json_decode( $body, true );
     1327
     1328        if ( isset( $data[ $package_id ]['enhancements_per_post'] ) ) {
     1329            $limit = (int) $data[ $package_id ]['enhancements_per_post'];
     1330            $this->aistma_log_manager->log( 'info', 'Found enhancement limit for package ID ' . $package_id . ': ' . $limit );
     1331            return $limit;
     1332        }
     1333
     1334        $this->aistma_log_manager->log( 'warning', 'No enhancement limit found for package ID: ' . $package_id . ', defaulting to unlimited' );
     1335        return 0; // Default to unlimited
     1336    }
     1337
     1338
    11951339}
  • ai-story-maker/trunk/public/css/aistma-style.css

    r3365422 r3383029  
    6868        font-size: 0.9rem;
    6969    }
     70    .post-featured-image {
     71        max-width: 100%;
     72        height: auto;
     73        border-radius: 8px;
     74        box-shadow: 0 2px 8px rgba(0,0,0,0.1);
     75    }
    7076    .ai-story-content {
    7177        font-size: 1.1rem;
     
    110116        font-size: 0.9em; text-align: center; margin-top: 2em; color: #777;
    111117    }
     118
     119    /* Responsive design for mobile devices */
     120    @media (max-width: 768px) {
     121        .ai-story-container {
     122            flex-direction: column;
     123            padding: 10px;
     124        }
     125        .ai-story-article {
     126            padding-right: 0;
     127            margin-bottom: 20px;
     128        }
     129        .post-featured-image {
     130            max-width: 80%;
     131        }
     132    }
  • ai-story-maker/trunk/public/templates/aistma-post-template.php

    r3379225 r3383029  
    6767    <p><a href="<?php echo esc_url( home_url() ); ?>">
    6868<?php
    69 // show the icon and the title of the website, add an anchro tag to the home page.
    70 $custom_logo_id = get_theme_mod( 'custom_logo' );
    71 $logo           = wp_get_attachment_image_src( $custom_logo_id, 'full' );
    72 if ( has_custom_logo() ) {
    73     echo wp_get_attachment_image( $custom_logo_id, 'full' );
     69// Show the post's featured image if it exists, otherwise show the site logo/name
     70if ( has_post_thumbnail() ) {
     71    the_post_thumbnail( 'medium', array( 'class' => 'post-featured-image' ) );
    7472} else {
    75     echo esc_html( get_bloginfo( 'name' ) );
     73    // Fallback to site logo or name
     74    $custom_logo_id = get_theme_mod( 'custom_logo' );
     75    $logo           = wp_get_attachment_image_src( $custom_logo_id, 'full' );
     76    if ( has_custom_logo() ) {
     77        echo wp_get_attachment_image( $custom_logo_id, 'full' );
     78    } else {
     79        echo esc_html( get_bloginfo( 'name' ) );
     80    }
    7681}
    77 
    7882?>
    7983
Note: See TracChangeset for help on using the changeset viewer.