Changeset 3383029
- Timestamp:
- 10/23/2025 03:37:51 AM (4 months ago)
- Location:
- ai-story-maker
- Files:
-
- 12 added
- 10 edited
-
svn (added)
-
svn/ai-story-maker (added)
-
svn/ai-story-maker/trunk (added)
-
tags/2.1.0/admin/class-aistma-admin.php (modified) (2 diffs)
-
tags/2.1.2/admin/class-aistma-admin.php (modified) (2 diffs)
-
trunk/README.txt (modified) (6 diffs)
-
trunk/admin/class-aistma-admin.php (modified) (6 diffs)
-
trunk/admin/class-aistma-content-editor.php (added)
-
trunk/admin/class-aistma-settings-page.php (modified) (1 diff)
-
trunk/admin/class-aistma-standalone-editor.php (added)
-
trunk/admin/css/content-editor.css (added)
-
trunk/admin/css/standalone-editor.css (added)
-
trunk/admin/js/block-editor-integration.js (added)
-
trunk/admin/js/content-editor.js (added)
-
trunk/admin/js/standalone-editor.js (added)
-
trunk/admin/templates/subscriptions-template.php (modified) (1 diff)
-
trunk/ai-story-maker.php (modified) (5 diffs)
-
trunk/includes/class-aistma-content-editor-handler.php (added)
-
trunk/includes/class-aistma-open-graph.php (added)
-
trunk/includes/class-aistma-story-generator.php (modified) (12 diffs)
-
trunk/public/css/aistma-style.css (modified) (2 diffs)
-
trunk/public/templates/aistma-post-template.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
ai-story-maker/tags/2.1.0/admin/class-aistma-admin.php
r3376817 r3383029 363 363 // Register hooks for auto-publishing new posts 364 364 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 );366 365 } 367 366 … … 881 880 } 882 881 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 published897 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 logic907 // We simulate a transition from 'new' to 'publish' status908 $this->auto_publish_to_social_media( 'publish', 'new', $post );909 }910 882 } 911 883 -
ai-story-maker/tags/2.1.2/admin/class-aistma-admin.php
r3379244 r3383029 447 447 // Register hooks for auto-publishing new posts 448 448 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 );450 449 } 451 450 … … 1324 1323 } 1325 1324 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 published1340 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 processing1356 update_post_meta( $post_id, '_aistma_social_shared', true );1357 1358 // Call the same auto-publish logic1359 $this->auto_publish_to_social_media( 'publish', 'new', $post );1360 }1361 1325 } 1362 1326 -
ai-story-maker/trunk/README.txt
r3379243 r3383029 5 5 Tested up to: 6.8 6 6 Requires PHP: 7.4 7 Stable tag: 2.1. 27 Stable tag: 2.1.3 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 12 12 Author URI: https://exedotcom.ca 13 13 14 AI-powered WordPress plugin to automatically generate unique stories, articles, and visuals using OpenAI and Unsplash APIs.14 AI-powered WordPress plugin to generate unique stories and articles using OpenAI and Unsplash APIs. Features AI Story Enhancer for text improvement. 15 15 16 16 == Description == 17 17 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. 19 21 20 22 Whether you're a blogger, marketer, or educator, AI Story Maker helps you build a full content strategy effortlessly. … … 22 24 == Features == 23 25 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 24 35 - **Subscription-Based Access** – Access AI generation through package subscriptions including free options. 25 36 - **AI-Generated Stories** – Create unique, professional stories and articles using OpenAI. … … 122 133 - In a PHP template file using: echo do_shortcode('[aistma_scroller]'); 123 134 124 === How to Use === 135 === How to Use AI Story Enhancer === 136 137 1. Navigate to **Posts → All Posts** in your WordPress admin 138 2. Find any post and click **"AI Story Enhancer"** under the post title 139 3. In the editor, select any text in the content preview area 140 4. Enter your enhancement instructions (e.g., "Make this more engaging", "Add more details", "Improve readability") 141 5. Click **"Improve"** to see AI-powered enhancements 142 6. 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 === 125 151 126 152 1. Edit a page or post in WordPress. … … 325 351 No additional personal user data is collected or stored. 326 352 353 == FAQ == 354 355 = What is AI Story Enhancer? = 356 357 AI 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 361 Navigate 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 365 Yes! 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 369 AI 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 373 Yes! 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 377 Yes, 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 381 The 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 327 383 == Contributing == 328 384 … … 330 386 331 387 == 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 332 400 333 401 = 2.1.2 = -
ai-story-maker/trunk/admin/class-aistma-admin.php
r3379243 r3383029 447 447 // Register hooks for auto-publishing new posts 448 448 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 );450 449 } 451 450 … … 690 689 } 691 690 691 $post_url = get_permalink( $post ); 692 693 // Add "Read More.." with post link 694 $message .= "\n\nRead More.. " . $post_url; 695 692 696 // Add hashtags if enabled 693 697 $hashtags = $this->get_social_media_hashtags( $post ); … … 695 699 $message .= "\n\n" . $hashtags; 696 700 } 697 698 $post_url = get_permalink( $post );699 701 700 702 // Facebook Graph API endpoint … … 833 835 } 834 836 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; 844 844 } 845 845 } … … 1151 1151 if ( isset( $subscription_status['error'] ) ) { 1152 1152 $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 } 1155 1158 // Try fallback: check if UI shows active subscription (packages-summary endpoint) 1156 1159 $fallback_check = $this->check_subscription_via_packages_api(); … … 1324 1327 } 1325 1328 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 published1340 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 processing1356 update_post_meta( $post_id, '_aistma_social_shared', true );1357 1358 // Call the same auto-publish logic1359 $this->auto_publish_to_social_media( 'publish', 'new', $post );1360 }1361 1329 } 1362 1330 -
ai-story-maker/trunk/admin/class-aistma-settings-page.php
r3379225 r3383029 154 154 155 155 $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 ); 156 163 $response = wp_remote_get( 157 164 $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 } 166 172 167 173 // Prepare the standardized wrapper structure -
ai-story-maker/trunk/admin/templates/subscriptions-template.php
r3379225 r3383029 283 283 ?> 284 284 </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 ?> 285 295 <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> 286 296 -
ai-story-maker/trunk/ai-story-maker.php
r3379243 r3383029 4 4 * Plugin URI: https://www.storymakerplugin.com/ 5 5 * Description: AI-powered content generator for WordPress — create engaging stories with a single click. 6 * Version: 2.1. 26 * Version: 2.1.3 7 7 * Author: Hayan Mamoun 8 8 * Author URI: https://exedotcom.ca … … 29 29 30 30 31 32 31 use exedotcom\aistorymaker\AISTMA_Story_Generator; 33 32 34 33 require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-plugin.php'; 35 34 require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-posts-gadget.php'; 35 require_once plugin_dir_path( __FILE__ ) . 'admin/class-aistma-standalone-editor.php'; 36 require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-content-editor-handler.php'; 37 require_once plugin_dir_path( __FILE__ ) . 'includes/class-aistma-open-graph.php'; 36 38 37 39 // Hooks. … … 47 49 echo '<!-- Posts Gadget class loaded successfully -->'; 48 50 }); 51 } 52 53 // Initialize Standalone Content Editor 54 if ( class_exists( '\\exedotcom\\aistorymaker\\AISTMA_Standalone_Editor' ) ) { 55 new \exedotcom\aistorymaker\AISTMA_Standalone_Editor(); 56 } 57 58 // Initialize Content Editor Handler 59 if ( 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 64 if ( class_exists( '\\exedotcom\\aistorymaker\\AISTMA_Open_Graph' ) ) { 65 new \exedotcom\aistorymaker\AISTMA_Open_Graph(); 49 66 } 50 67 … … 63 80 try { 64 81 $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 } 67 89 } catch ( \Throwable $e ) { 68 90 wp_send_json_error( array( 'message' => 'Fatal error: ' . $e->getMessage() ) ); … … 91 113 */ 92 114 function 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 } 94 124 } 95 125 function aistma_get_master_url(string $path = ''): string { -
ai-story-maker/trunk/includes/class-aistma-story-generator.php
r3379243 r3383029 76 76 * 77 77 * @param bool $force Whether to force generation regardless of lock. 78 * @return void78 * @return array Array with 'success' boolean and 'message' string. 79 79 */ 80 80 public static function generate_ai_stories_with_lock( $force = false ) { … … 83 83 if ( ! $force && get_transient( $lock_key ) ) { 84 84 $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.' ); 86 86 } 87 87 … … 103 103 104 104 $instance->aistma_log_manager::log( 'error', $error_message ); 105 throw new \RuntimeException($error_message );105 return array( 'success' => false, 'message' => $error_message ); 106 106 } else { 107 107 $instance->aistma_log_manager::log( 'info', 'No valid subscription found, but OpenAI API key is available. Will use direct OpenAI API calls.' ); … … 110 110 } catch ( \RuntimeException $e ) { 111 111 $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 ) ); 114 114 } 115 115 … … 118 118 // Pass the instance with cached subscription status to generate_ai_stories 119 119 $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.' ); 121 122 } catch ( \Throwable $e ) { 122 123 $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() ); 125 125 } finally { 126 126 // Always delete the lock, even if an error occurs. … … 507 507 } 508 508 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 509 516 // Create the post. 510 517 $post_data = array( … … 512 519 'post_content' => $content, 513 520 'post_excerpt' => $excerpt, 514 'post_status' => isset( $prompt['auto_publish'] ) && 1 === $prompt['auto_publish'] ? 'publish' : 'draft',521 'post_status' => $post_status, 515 522 'post_author' => $post_author, 516 523 'post_category' => array( $category_id ), … … 570 577 update_post_meta( $post_id, 'ai_story_maker_request_id', $request_id ?? 'N/A' ); 571 578 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 572 600 // $this->aistma_log_manager->log( 'success', 'AI-generated news article created via Master API: ' . get_permalink( $post_id ), $request_id ); 573 601 } … … 627 655 } 628 656 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 629 664 // Create the post. 630 665 $post_data = array( … … 632 667 'post_content' => $content, 633 668 'post_excerpt' => $excerpt, 634 'post_status' => isset( $prompt['auto_publish'] ) && 1 === $prompt['auto_publish'] ? 'publish' : 'draft',669 'post_status' => $post_status, 635 670 'post_author' => $post_author, 636 671 'post_category' => array( $category_id ), … … 662 697 update_post_meta( $post_id, 'ai_story_maker_request_id', $request_id ?? 'N/A' ); 663 698 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 664 714 $this->aistma_log_manager->log( 'success', 'AI-generated news article created via OpenAI API: ' . get_permalink( $post_id ), $request_id ); 665 715 } … … 1193 1243 } 1194 1244 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 1195 1339 } -
ai-story-maker/trunk/public/css/aistma-style.css
r3365422 r3383029 68 68 font-size: 0.9rem; 69 69 } 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 } 70 76 .ai-story-content { 71 77 font-size: 1.1rem; … … 110 116 font-size: 0.9em; text-align: center; margin-top: 2em; color: #777; 111 117 } 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 67 67 <p><a href="<?php echo esc_url( home_url() ); ?>"> 68 68 <?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 70 if ( has_post_thumbnail() ) { 71 the_post_thumbnail( 'medium', array( 'class' => 'post-featured-image' ) ); 74 72 } 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 } 76 81 } 77 78 82 ?> 79 83
Note: See TracChangeset
for help on using the changeset viewer.