Plugin Directory

Changeset 3414040


Ignore:
Timestamp:
12/08/2025 09:39:36 AM (4 months ago)
Author:
enkic
Message:

v2.3.9

Location:
ai-builder
Files:
2 added
4 edited
47 copied

Legend:

Unmodified
Added
Removed
  • ai-builder/tags/2.3.9/aibui-builder.php

    r3413458 r3414040  
    44 * Plugin URI:        https://website-ai-builder.com/
    55 * Description: This plugin is used to build your website with AI.
    6  * Version: 2.3.8
     6 * Version: 2.3.9
    77 * Author: enkic
    88 * Author URI:        https://enkicorbin.fr/
     
    1818
    1919// Définir la version du plugin
    20 define('AIBUI_VERSION', '2.3.8');
     20define('AIBUI_VERSION', '2.3.9');
    2121
    2222// Simple CSS minifier (safe whitespace/comment removal)
     
    11201120// Initialiser le gestionnaire AJAX
    11211121new AIBUI_Ajax_Handler();
     1122
     1123// -------------------------------
     1124// Multi-Page Generator: Cleanup cron and migration
     1125// -------------------------------
     1126function aibui_cleanup_old_generations() {
     1127    require_once plugin_dir_path(__FILE__) . 'includes/class-generations-storage.php';
     1128    $storage = new AIBUI_Generations_Storage();
     1129    $deleted_count = $storage->cleanup_old(30); // Delete applied generations older than 30 days
     1130   
     1131    if (defined('WP_DEBUG') && WP_DEBUG) {
     1132        error_log("[AI Builder] Cleaned up {$deleted_count} old generation files");
     1133    }
     1134}
     1135add_action('aibui_daily_cleanup', 'aibui_cleanup_old_generations');
     1136
     1137// Schedule daily cleanup if not already scheduled
     1138if (!wp_next_scheduled('aibui_daily_cleanup')) {
     1139    wp_schedule_event(time(), 'daily', 'aibui_daily_cleanup');
     1140}
     1141
     1142// Migrate old wp_options data to files (one-time migration on activation/update)
     1143function aibui_migrate_generations_to_files() {
     1144    // Check if migration already done
     1145    if (get_option('aibui_generations_migrated_to_files', false)) {
     1146        return;
     1147    }
     1148   
     1149    require_once plugin_dir_path(__FILE__) . 'includes/class-generations-storage.php';
     1150    $storage = new AIBUI_Generations_Storage();
     1151    $migrated_count = $storage->migrate_from_options();
     1152   
     1153    if ($migrated_count > 0) {
     1154        // Mark migration as done
     1155        update_option('aibui_generations_migrated_to_files', true, false);
     1156       
     1157        if (defined('WP_DEBUG') && WP_DEBUG) {
     1158            error_log("[AI Builder] Migrated {$migrated_count} generations from wp_options to files");
     1159        }
     1160    }
     1161}
     1162// Run migration on admin init (only once)
     1163add_action('admin_init', function() {
     1164    static $migration_done = false;
     1165    if (!$migration_done && current_user_can('manage_options')) {
     1166        aibui_migrate_generations_to_files();
     1167        $migration_done = true;
     1168    }
     1169}, 5);
  • ai-builder/tags/2.3.9/assets/js/multi-page.js

    r3413458 r3414040  
    186186
    187187    totalCostElement.textContent = `${totalCost} credits`;
    188     console.log(`Updating cost: ${pageCount} pages × 75 = ${totalCost} credits`);
    189188}
    190189
  • ai-builder/tags/2.3.9/includes/class-ajax-handler.php

    r3400578 r3414040  
    516516
    517517    // -----------------------------
    518     // Multi-Page: Generations store
     518    // Multi-Page: Generations store (using JSON files)
    519519    // -----------------------------
    520     private function get_generations_option()
    521     {
    522         $stored = get_option('aibui_multi_page_generations', array());
    523         if (!is_array($stored)) {
    524             $stored = array();
    525         }
    526         return $stored;
    527     }
    528 
    529     private function persist_generations_option($generations)
    530     {
    531         if (!is_array($generations)) $generations = array();
    532         update_option('aibui_multi_page_generations', $generations, false);
     520    private function get_storage()
     521    {
     522        static $storage = null;
     523        if ($storage === null) {
     524            require_once plugin_dir_path(__FILE__) . 'class-generations-storage.php';
     525            $storage = new AIBUI_Generations_Storage();
     526        }
     527        return $storage;
    533528    }
    534529
     
    553548        }
    554549
    555         $id = isset($payload['id']) && is_string($payload['id']) ? $payload['id'] : wp_generate_uuid4();
    556         $now = current_time('mysql');
    557 
    558         $item = array(
    559             'id' => $id,
    560             'title' => sanitize_text_field($payload['title'] ?? ''),
    561             'metaDesc' => sanitize_textarea_field($payload['metaDesc'] ?? ''),
    562             'cssContent' => wp_kses_post($payload['cssContent'] ?? ''),
    563             'blocksJson' => isset($payload['blocksJson']) ? $payload['blocksJson'] : array(),
    564             'status' => 'Pending review',
    565             'createdAt' => $now,
    566             'applied' => false,
    567             'pageId' => 0,
    568         );
    569 
    570         $generations = $this->get_generations_option();
    571         $generations[$id] = $item;
    572         $this->persist_generations_option($generations);
    573 
    574         wp_send_json_success($item);
     550        $storage = $this->get_storage();
     551        $result = $storage->save($payload);
     552
     553        if (is_wp_error($result)) {
     554            wp_send_json_error($result->get_error_message());
     555        }
     556
     557        wp_send_json_success($result);
    575558    }
    576559
     
    588571            wp_send_json_error('Insufficient permissions');
    589572        }
    590         $generations = $this->get_generations_option();
    591         // Return newest first
    592         $items = array_values($generations);
    593         usort($items, function($a, $b) {
    594             return strcmp($b['createdAt'] ?? '', $a['createdAt'] ?? '');
    595         });
     573
     574        $storage = $this->get_storage();
     575        $items = $storage->get_all();
     576
    596577        wp_send_json_success($items);
    597578    }
     
    611592        }
    612593        $id = sanitize_text_field(wp_unslash($_POST['id']));
    613         $generations = $this->get_generations_option();
    614         if (!isset($generations[$id])) {
    615             wp_send_json_error('Not found');
    616         }
    617         wp_send_json_success($generations[$id]);
     594
     595        $storage = $this->get_storage();
     596        $result = $storage->get($id);
     597
     598        if (is_wp_error($result)) {
     599            wp_send_json_error($result->get_error_message());
     600        }
     601
     602        wp_send_json_success($result);
    618603    }
    619604
     
    634619        $page_id = isset($_POST['page_id']) ? intval($_POST['page_id']) : 0;
    635620
    636         $generations = $this->get_generations_option();
    637         if (!isset($generations[$id])) {
    638             wp_send_json_error('Not found');
    639         }
    640         $generations[$id]['applied'] = true;
    641         if ($page_id > 0) {
    642             $generations[$id]['pageId'] = $page_id;
    643         }
    644         $generations[$id]['status'] = 'Applied';
    645         $this->persist_generations_option($generations);
    646 
    647         wp_send_json_success($generations[$id]);
     621        $storage = $this->get_storage();
     622        $result = $storage->mark_applied($id, $page_id);
     623
     624        if (is_wp_error($result)) {
     625            wp_send_json_error($result->get_error_message());
     626        }
     627
     628        wp_send_json_success($result);
    648629    }
    649630
  • ai-builder/tags/2.3.9/readme.txt

    r3413458 r3414040  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 2.3.8
     7Stable tag: 2.3.9
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • ai-builder/trunk/aibui-builder.php

    r3413458 r3414040  
    44 * Plugin URI:        https://website-ai-builder.com/
    55 * Description: This plugin is used to build your website with AI.
    6  * Version: 2.3.8
     6 * Version: 2.3.9
    77 * Author: enkic
    88 * Author URI:        https://enkicorbin.fr/
     
    1818
    1919// Définir la version du plugin
    20 define('AIBUI_VERSION', '2.3.8');
     20define('AIBUI_VERSION', '2.3.9');
    2121
    2222// Simple CSS minifier (safe whitespace/comment removal)
     
    11201120// Initialiser le gestionnaire AJAX
    11211121new AIBUI_Ajax_Handler();
     1122
     1123// -------------------------------
     1124// Multi-Page Generator: Cleanup cron and migration
     1125// -------------------------------
     1126function aibui_cleanup_old_generations() {
     1127    require_once plugin_dir_path(__FILE__) . 'includes/class-generations-storage.php';
     1128    $storage = new AIBUI_Generations_Storage();
     1129    $deleted_count = $storage->cleanup_old(30); // Delete applied generations older than 30 days
     1130   
     1131    if (defined('WP_DEBUG') && WP_DEBUG) {
     1132        error_log("[AI Builder] Cleaned up {$deleted_count} old generation files");
     1133    }
     1134}
     1135add_action('aibui_daily_cleanup', 'aibui_cleanup_old_generations');
     1136
     1137// Schedule daily cleanup if not already scheduled
     1138if (!wp_next_scheduled('aibui_daily_cleanup')) {
     1139    wp_schedule_event(time(), 'daily', 'aibui_daily_cleanup');
     1140}
     1141
     1142// Migrate old wp_options data to files (one-time migration on activation/update)
     1143function aibui_migrate_generations_to_files() {
     1144    // Check if migration already done
     1145    if (get_option('aibui_generations_migrated_to_files', false)) {
     1146        return;
     1147    }
     1148   
     1149    require_once plugin_dir_path(__FILE__) . 'includes/class-generations-storage.php';
     1150    $storage = new AIBUI_Generations_Storage();
     1151    $migrated_count = $storage->migrate_from_options();
     1152   
     1153    if ($migrated_count > 0) {
     1154        // Mark migration as done
     1155        update_option('aibui_generations_migrated_to_files', true, false);
     1156       
     1157        if (defined('WP_DEBUG') && WP_DEBUG) {
     1158            error_log("[AI Builder] Migrated {$migrated_count} generations from wp_options to files");
     1159        }
     1160    }
     1161}
     1162// Run migration on admin init (only once)
     1163add_action('admin_init', function() {
     1164    static $migration_done = false;
     1165    if (!$migration_done && current_user_can('manage_options')) {
     1166        aibui_migrate_generations_to_files();
     1167        $migration_done = true;
     1168    }
     1169}, 5);
  • ai-builder/trunk/assets/js/multi-page.js

    r3413458 r3414040  
    186186
    187187    totalCostElement.textContent = `${totalCost} credits`;
    188     console.log(`Updating cost: ${pageCount} pages × 75 = ${totalCost} credits`);
    189188}
    190189
  • ai-builder/trunk/includes/class-ajax-handler.php

    r3400578 r3414040  
    516516
    517517    // -----------------------------
    518     // Multi-Page: Generations store
     518    // Multi-Page: Generations store (using JSON files)
    519519    // -----------------------------
    520     private function get_generations_option()
    521     {
    522         $stored = get_option('aibui_multi_page_generations', array());
    523         if (!is_array($stored)) {
    524             $stored = array();
    525         }
    526         return $stored;
    527     }
    528 
    529     private function persist_generations_option($generations)
    530     {
    531         if (!is_array($generations)) $generations = array();
    532         update_option('aibui_multi_page_generations', $generations, false);
     520    private function get_storage()
     521    {
     522        static $storage = null;
     523        if ($storage === null) {
     524            require_once plugin_dir_path(__FILE__) . 'class-generations-storage.php';
     525            $storage = new AIBUI_Generations_Storage();
     526        }
     527        return $storage;
    533528    }
    534529
     
    553548        }
    554549
    555         $id = isset($payload['id']) && is_string($payload['id']) ? $payload['id'] : wp_generate_uuid4();
    556         $now = current_time('mysql');
    557 
    558         $item = array(
    559             'id' => $id,
    560             'title' => sanitize_text_field($payload['title'] ?? ''),
    561             'metaDesc' => sanitize_textarea_field($payload['metaDesc'] ?? ''),
    562             'cssContent' => wp_kses_post($payload['cssContent'] ?? ''),
    563             'blocksJson' => isset($payload['blocksJson']) ? $payload['blocksJson'] : array(),
    564             'status' => 'Pending review',
    565             'createdAt' => $now,
    566             'applied' => false,
    567             'pageId' => 0,
    568         );
    569 
    570         $generations = $this->get_generations_option();
    571         $generations[$id] = $item;
    572         $this->persist_generations_option($generations);
    573 
    574         wp_send_json_success($item);
     550        $storage = $this->get_storage();
     551        $result = $storage->save($payload);
     552
     553        if (is_wp_error($result)) {
     554            wp_send_json_error($result->get_error_message());
     555        }
     556
     557        wp_send_json_success($result);
    575558    }
    576559
     
    588571            wp_send_json_error('Insufficient permissions');
    589572        }
    590         $generations = $this->get_generations_option();
    591         // Return newest first
    592         $items = array_values($generations);
    593         usort($items, function($a, $b) {
    594             return strcmp($b['createdAt'] ?? '', $a['createdAt'] ?? '');
    595         });
     573
     574        $storage = $this->get_storage();
     575        $items = $storage->get_all();
     576
    596577        wp_send_json_success($items);
    597578    }
     
    611592        }
    612593        $id = sanitize_text_field(wp_unslash($_POST['id']));
    613         $generations = $this->get_generations_option();
    614         if (!isset($generations[$id])) {
    615             wp_send_json_error('Not found');
    616         }
    617         wp_send_json_success($generations[$id]);
     594
     595        $storage = $this->get_storage();
     596        $result = $storage->get($id);
     597
     598        if (is_wp_error($result)) {
     599            wp_send_json_error($result->get_error_message());
     600        }
     601
     602        wp_send_json_success($result);
    618603    }
    619604
     
    634619        $page_id = isset($_POST['page_id']) ? intval($_POST['page_id']) : 0;
    635620
    636         $generations = $this->get_generations_option();
    637         if (!isset($generations[$id])) {
    638             wp_send_json_error('Not found');
    639         }
    640         $generations[$id]['applied'] = true;
    641         if ($page_id > 0) {
    642             $generations[$id]['pageId'] = $page_id;
    643         }
    644         $generations[$id]['status'] = 'Applied';
    645         $this->persist_generations_option($generations);
    646 
    647         wp_send_json_success($generations[$id]);
     621        $storage = $this->get_storage();
     622        $result = $storage->mark_applied($id, $page_id);
     623
     624        if (is_wp_error($result)) {
     625            wp_send_json_error($result->get_error_message());
     626        }
     627
     628        wp_send_json_success($result);
    648629    }
    649630
  • ai-builder/trunk/readme.txt

    r3413458 r3414040  
    55Tested up to: 6.9
    66Requires PHP: 7.4
    7 Stable tag: 2.3.8
     7Stable tag: 2.3.9
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.