PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.4.0
ShopBuilder – WooCommerce Builder For Elementor v3.4.0
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / AI / MetaBoxScripts.php

MetaBoxScripts.php in ShopBuilder – WooCommerce Builder For Elementor 3.4.0, at app/AI/MetaBoxScripts.php

122 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\AI;
4
5 // Do not allow directly accessing this file.
6 use Exception;
7 use RadiusTheme\SB\AI\AIServices\DeepSeekAdapter;
8 use RadiusTheme\SB\AI\AIServices\GeminiAdapter;
9 use RadiusTheme\SB\AI\AIServices\OpenAIAdapter;
10 use RadiusTheme\SB\Traits\SingletonTrait;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit( 'This script cannot be accessed directly.' );
14 }
15
16 /**
17 * AIPower Model
18 *
19 * Manages AI service initialization and adapter creation for various AI providers
20 * including OpenAI, Gemini, and DeepSeek.
21 *
22 * @since 1.0.0
23 */
24 class MetaBoxScripts {
25 /**
26 * Singleton Trait.
27 */
28 use SingletonTrait;
29
30 /**
31 * Enqueue scripts and styles for product edit page.
32 *
33 * @param string $hook Current admin page hook.
34 * @return void
35 */
36 public function admin_enqueue_scripts( $hook ) {
37 // Only load on product edit page.
38 if ( 'post.php' !== $hook && 'post-new.php' !== $hook ) {
39 return;
40 }
41 $screen = get_current_screen();
42 if ( ! $screen || 'product' !== $screen->post_type ) {
43 return;
44 }
45 $ai_data = AIFns::activated_ai_data();
46 $version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : RTSB_VERSION;
47 // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
48 if ( in_array( 'sitepress-multilingual-cms/sitepress.php', get_option( 'active_plugins' ) ) ) {
49 $ajaxurl = admin_url( 'admin-ajax.php?lang=' . ICL_LANGUAGE_CODE );
50 } else {
51 $ajaxurl = admin_url( 'admin-ajax.php' );
52 }
53 wp_enqueue_script( 'rtsb-ai-product-helper', rtsb()->get_assets_uri( 'js/backend/product-ai-init.js' ), [ 'wp-element' ], $version, true );
54 wp_enqueue_style( 'rtsb-ai-product-ai-init', rtsb()->get_assets_uri( 'css/backend/product-ai-init.css' ), '', $version );
55
56 // Localize script with data.
57 wp_localize_script(
58 'rtsb-ai-product-helper',
59 'rtsbAIHelper',
60 [
61 'ajaxUrl' => $ajaxurl,
62 'settingsUrl' => admin_url( 'admin.php?page=rtsb-settings' ),
63 'aiActivated' => ! empty( $ai_data ),
64 'nonce' => wp_create_nonce( 'rtsb_ai_nonce' ),
65 'i18n' => [
66 'chars' => esc_html__( 'chars', 'shopbuilder' ),
67 'aiConfigError' => esc_html__( 'AI Configuration mismatch', 'shopbuilder' ),
68 'writePrompt' => esc_html__( 'Write a prompt for AI', 'shopbuilder' ),
69 'regenerateBtnTxt' => esc_html__( 'Regenerate', 'shopbuilder' ),
70 'promptPlaceholder' => esc_html__( 'e.g., Premium handmade cotton t-shirt for men, made from 100% organic cotton with unique printed designs, perfect for casual wear', 'shopbuilder' ),
71 // Title Generator Modal.
72 'generateTitle' => esc_html__( 'Generate Product Title with AI', 'shopbuilder' ),
73 'applyTitleBtnTxt' => esc_html__( 'Apply Title', 'shopbuilder' ),
74 'cancelBtnTxt' => esc_html__( 'Cancel', 'shopbuilder' ),
75 'generateTitleBtnTxt' => esc_html__( 'Generate Titles', 'shopbuilder' ),
76 'promptTitleHelperText' => esc_html__( 'AI will use this info to generate optimized title ideas.', 'shopbuilder' ),
77 'generatedTitles' => esc_html__( 'Generated Titles', 'shopbuilder' ),
78 // Description Generator Modal.
79 'aiDescriptionGenerator' => esc_html__( 'Generate Full Description with AI', 'shopbuilder' ),
80 'descPromptPlaceholder' => esc_html__( 'e.g., Premium handmade cotton t-shirt for men, made from 100% organic cotton with unique printed designs, perfect for casual wear. Available in multiple sizes and colors.', 'shopbuilder' ),
81 'promptDescHelperText' => esc_html__( 'AI will use this info to generate a comprehensive product description.', 'shopbuilder' ),
82 'generatedDescription' => esc_html__( 'Generated Description', 'shopbuilder' ),
83 'applyDescriptionBtnTxt' => esc_html__( 'Apply Description', 'shopbuilder' ),
84 'generateDescriptionBtnTxt' => esc_html__( 'Generate Description', 'shopbuilder' ),
85 // Short Description Generator Modal.
86 'generateShortDesc' => esc_html__( 'Generate Short Description with AI', 'shopbuilder' ),
87 'aiShortDescGenerator' => esc_html__( 'AI Short Description Generator', 'shopbuilder' ),
88 'shortDescPromptPlaceholder' => esc_html__( 'e.g., Premium handmade cotton t-shirt for men, made from 100% organic cotton with unique printed designs, perfect for casual wear.', 'shopbuilder' ),
89 'promptShortDescHelperText' => esc_html__( 'Short descriptions are usually 1–2 sentences long and appear in product listings or summaries.', 'shopbuilder' ),
90 'generatedShortDescription' => esc_html__( 'Generated Short Description', 'shopbuilder' ),
91 'applyShortDescriptionBtnTxt' => esc_html__( 'Apply Short Description', 'shopbuilder' ),
92 'generateShortDescBtnTxt' => esc_html__( 'Generate Short Description', 'shopbuilder' ),
93 // Notifications.
94 'provideInfoFirst' => esc_html__( 'Please provide product information first.', 'shopbuilder' ),
95 'descGeneratedSuccess' => esc_html__( 'Description generated successfully!', 'shopbuilder' ),
96 'shortDescGeneratedSuccess' => esc_html__( 'Short description generated successfully!', 'shopbuilder' ),
97 'descGenerateFailed' => esc_html__( 'Failed to generate description.', 'shopbuilder' ),
98 'shortDescGenerateFailed' => esc_html__( 'Failed to generate short description.', 'shopbuilder' ),
99 'somethingWentWrong' => esc_html__( 'Something went wrong.', 'shopbuilder' ),
100 'descAppliedSuccess' => esc_html__( 'Description applied successfully!', 'shopbuilder' ),
101 'shortDescAppliedSuccess' => esc_html__( 'Short description applied successfully!', 'shopbuilder' ),
102 'descFieldNotFound' => esc_html__( 'Product description field not found!', 'shopbuilder' ),
103 'shortDescFieldNotFound' => esc_html__( 'Product short description field not found!', 'shopbuilder' ),
104 'selectDescriptionFirst' => esc_html__( 'Please select a description first.', 'shopbuilder' ),
105 'selectShortDescFirst' => esc_html__( 'Please select a short description first.', 'shopbuilder' ),
106 ],
107 ]
108 );
109 }
110
111 /**
112 * Render meta box content
113 *
114 * @return void
115 */
116 public function render_meta_box() {
117 ?>
118 <div id="rtsb-ai-product-helper-root"></div>
119 <?php
120 }
121 }
122