PluginProbe
BotWriter – AI Writer & SEO Content Generator / trunk
BotWriter – AI Writer & SEO Content Generator vtrunk
3.4.10 3.4.9 3.4.8 3.4.7 3.4.6 3.4.4 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 3.3.0 3.2.8 trunk 1.3.0 1.3.1 1.3.2 1.3.3 All 51 releases
botwriter / includes / settings / dalle.php

dalle.php in BotWriter – AI Writer & SEO Content Generator trunk, at includes/settings/dalle.php

222 lines 10.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * DALL-E (OpenAI) Image Provider Settings
4 *
5 * @package BotWriter
6 */
7
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 /**
13 * Get DALL-E models configuration
14 */
15 function botwriter_get_dalle_models() {
16 if (function_exists('botwriter_get_provider_image_models')) {
17 $grouped = botwriter_get_provider_image_models('dalle');
18 if (!empty($grouped)) {
19 $flat = array();
20 foreach ($grouped as $group_models) {
21 if (!is_array($group_models)) {
22 continue;
23 }
24 foreach ($group_models as $id => $name) {
25 $flat[$id] = $name;
26 }
27 }
28 if (!empty($flat)) {
29 return $flat;
30 }
31 }
32 }
33
34 return [
35 'gpt-image-2' => 'GPT Image 2 (latest)',
36 'gpt-image-1.5' => 'GPT Image 1.5',
37 'gpt-image-1' => 'GPT Image 1 (stable)',
38 'gpt-image-1-mini' => 'GPT Image 1 Mini',
39 'dall-e-3' => 'DALL-E 3 (high quality)',
40 'dall-e-2' => 'DALL-E 2 (legacy)',
41 ];
42 }
43
44 /**
45 * Get DALL-E provider info
46 */
47 function botwriter_get_dalle_info() {
48 return [
49 'name' => 'DALL-E (OpenAI)',
50 'description' => __('OpenAI\'s image generation models. The latest GPT Image 1 offers the best quality and prompt adherence.', 'botwriter'),
51 'website' => 'https://openai.com',
52 'api_url' => 'https://platform.openai.com/api-keys',
53 'docs_url' => 'https://platform.openai.com/docs/guides/images',
54 'pricing_url' => 'https://openai.com/api/pricing/',
55 'free_credits' => __('Included in OpenAI API free credits ($5 for new accounts)', 'botwriter'),
56 'pricing_summary' => [
57 'GPT Image 1 (Low)' => '~$0.01/image',
58 'GPT Image 1 (Medium)' => '~$0.04/image',
59 'GPT Image 1 (High)' => '~$0.17/image',
60 'DALL-E 3 (1024x1024)' => '$0.04/image',
61 'DALL-E 3 (1792x1024)' => '$0.08/image',
62 ],
63 'features' => [
64 __('Uses the same API key as OpenAI text models', 'botwriter'),
65 __('Excellent prompt understanding', 'botwriter'),
66 __('High quality, realistic images', 'botwriter'),
67 __('Multiple size/quality options', 'botwriter'),
68 __('Great for product images and illustrations', 'botwriter'),
69 ],
70 'pros' => [
71 __('Same API key as text models', 'botwriter'),
72 __('Best prompt understanding', 'botwriter'),
73 __('Very realistic outputs', 'botwriter'),
74 ],
75 'cons' => [
76 __('Higher cost than alternatives', 'botwriter'),
77 __('Limited style controls', 'botwriter'),
78 ],
79 ];
80 }
81
82 /**
83 * Render DALL-E settings tab content
84 */
85 function botwriter_render_dalle_settings($settings, $is_active) {
86 $info = botwriter_get_dalle_info();
87 $models = botwriter_get_dalle_models();
88 $openai_api_key = $settings['botwriter_openai_api_key'] ?? '';
89 $has_key = !empty($openai_api_key);
90 ?>
91 <div class="provider-config-section">
92 <div class="provider-config-card">
93 <h4><?php esc_html_e('API Configuration', 'botwriter'); ?></h4>
94
95 <div class="info-notice">
96 <span class="dashicons dashicons-info"></span>
97 <p><strong><?php esc_html_e('DALL-E uses OpenAI API.', 'botwriter'); ?></strong>
98 <?php esc_html_e('This is the same API key used in Text AI → OpenAI. You can configure it from either tab.', 'botwriter'); ?></p>
99 </div>
100
101 <div class="form-row">
102 <label><?php esc_html_e('OpenAI API Key:', 'botwriter'); ?></label>
103 <div class="api-key-wrapper">
104 <input type="password"
105 name="botwriter_openai_api_key"
106 class="form-control api-key-input"
107 value="<?php echo esc_attr(function_exists('botwriter_decrypt_api_key') ? botwriter_decrypt_api_key(get_option('botwriter_openai_api_key')) : ''); ?>"
108 placeholder="sk-..." />
109 <button type="button" class="button toggle-api-key"><?php esc_html_e('Show', 'botwriter'); ?></button>
110 </div>
111 <p class="description"><?php esc_html_e('Get your API key from', 'botwriter'); ?> <a href="<?php echo esc_url($info['api_url']); ?>" target="_blank">platform.openai.com/api-keys</a></p>
112 <?php botwriter_api_key_transmission_notice(); ?>
113 </div>
114
115 <div class="form-row">
116 <button type="button" class="button button-secondary test-api-key" data-provider="dalle">
117 <span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e('Test API Key', 'botwriter'); ?>
118 </button>
119 <span class="test-api-result"></span>
120 </div>
121
122 <div class="form-row">
123 <label><?php esc_html_e('Model:', 'botwriter'); ?></label>
124 <select name="botwriter_dalle_model" class="form-select" style="width: 100%; max-width: 400px;">
125 <?php foreach ($models as $id => $name): ?>
126 <option value="<?php echo esc_attr($id); ?>" <?php selected($settings['botwriter_dalle_model'], $id); ?>><?php echo esc_html($name); ?></option>
127 <?php endforeach; ?>
128 </select>
129 </div>
130 </div>
131
132 <div class="provider-info-card">
133 <h4><span class="dashicons dashicons-info-outline"></span> <?php esc_html_e('How to Use DALL-E', 'botwriter'); ?></h4>
134 <ol class="setup-steps">
135 <li><?php esc_html_e('Enter your OpenAI API key above (or in Text AI → OpenAI)', 'botwriter'); ?></li>
136 <li><?php esc_html_e('Select DALL-E as your image provider here', 'botwriter'); ?></li>
137 <li><?php esc_html_e('Choose your preferred model and quality settings', 'botwriter'); ?></li>
138 <li><?php esc_html_e('That\'s it! The same API key works for both text and images', 'botwriter'); ?></li>
139 </ol>
140 </div>
141
142 <div class="provider-pricing-card">
143 <h4><span class="dashicons dashicons-money-alt"></span> <?php esc_html_e('Pricing Overview', 'botwriter'); ?></h4>
144
145 <div class="pricing-highlight">
146 <span class="free-credits-badge"><?php esc_html_e('Shared Credits', 'botwriter'); ?></span>
147 <p><?php echo esc_html($info['free_credits']); ?></p>
148 </div>
149
150 <table class="pricing-table">
151 <thead>
152 <tr>
153 <th><?php esc_html_e('Model / Quality', 'botwriter'); ?></th>
154 <th><?php esc_html_e('Price', 'botwriter'); ?></th>
155 </tr>
156 </thead>
157 <tbody>
158 <?php foreach ($info['pricing_summary'] as $model => $price): ?>
159 <tr>
160 <td><code><?php echo esc_html($model); ?></code></td>
161 <td><?php echo esc_html($price); ?></td>
162 </tr>
163 <?php endforeach; ?>
164 </tbody>
165 </table>
166
167 <p class="pricing-note">
168 <a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="button button-secondary">
169 <span class="dashicons dashicons-external"></span> <?php esc_html_e('View Full Pricing', 'botwriter'); ?>
170 </a>
171 </p>
172 </div>
173
174 <div class="provider-features-card">
175 <h4><span class="dashicons dashicons-star-filled"></span> <?php esc_html_e('Features & Benefits', 'botwriter'); ?></h4>
176 <ul class="features-list">
177 <?php foreach ($info['features'] as $feature): ?>
178 <li><span class="dashicons dashicons-yes-alt"></span> <?php echo esc_html($feature); ?></li>
179 <?php endforeach; ?>
180 </ul>
181
182 <div class="pros-cons">
183 <div class="pros">
184 <h5><?php esc_html_e('Pros', 'botwriter'); ?></h5>
185 <ul>
186 <?php foreach ($info['pros'] as $pro): ?>
187 <li><span class="dashicons dashicons-plus-alt2"></span> <?php echo esc_html($pro); ?></li>
188 <?php endforeach; ?>
189 </ul>
190 </div>
191 <div class="cons">
192 <h5><?php esc_html_e('Cons', 'botwriter'); ?></h5>
193 <ul>
194 <?php foreach ($info['cons'] as $con): ?>
195 <li><span class="dashicons dashicons-minus"></span> <?php echo esc_html($con); ?></li>
196 <?php endforeach; ?>
197 </ul>
198 </div>
199 </div>
200 </div>
201
202 <div class="provider-links-card">
203 <h4><span class="dashicons dashicons-admin-links"></span> <?php esc_html_e('Useful Links', 'botwriter'); ?></h4>
204 <div class="links-grid">
205 <a href="<?php echo esc_url($info['api_url']); ?>" target="_blank" class="link-item">
206 <span class="dashicons dashicons-admin-network"></span>
207 <?php esc_html_e('OpenAI API Keys', 'botwriter'); ?>
208 </a>
209 <a href="<?php echo esc_url($info['docs_url']); ?>" target="_blank" class="link-item">
210 <span class="dashicons dashicons-book"></span>
211 <?php esc_html_e('Image Docs', 'botwriter'); ?>
212 </a>
213 <a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="link-item">
214 <span class="dashicons dashicons-money-alt"></span>
215 <?php esc_html_e('Pricing', 'botwriter'); ?>
216 </a>
217 </div>
218 </div>
219 </div>
220 <?php
221 }
222