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 / gemini.php

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

228 lines 11.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Google Gemini Image Provider Settings
4 *
5 * @package BotWriter
6 * @since 2.0.4
7 */
8
9 if (!defined('ABSPATH')) {
10 exit;
11 }
12
13 /**
14 * Get Gemini image models configuration
15 */
16 function botwriter_get_gemini_image_models() {
17 if (function_exists('botwriter_get_provider_image_models')) {
18 $grouped = botwriter_get_provider_image_models('gemini');
19 if (!empty($grouped)) {
20 $flat = array();
21 foreach ($grouped as $group_models) {
22 if (!is_array($group_models)) {
23 continue;
24 }
25 foreach ($group_models as $id => $name) {
26 $flat[$id] = $name;
27 }
28 }
29 if (!empty($flat)) {
30 return $flat;
31 }
32 }
33 }
34
35 return [
36 'gemini-3.1-flash-lite-image' => 'Gemini 3.1 Flash Lite Image (fastest, lowest cost)',
37 'gemini-3.1-flash-image' => 'Gemini 3.1 Flash Image (balanced, recommended)',
38 'gemini-3-pro-image' => 'Gemini 3 Pro Image (advanced, 4K)',
39 'gemini-2.5-flash-image' => 'Gemini 2.5 Flash Image (legacy)',
40 ];
41 }
42
43 /**
44 * Get Gemini image provider info
45 */
46 function botwriter_get_gemini_image_info() {
47 return [
48 'name' => 'Google Gemini',
49 'description' => __('Google\'s AI image generation using Gemini models. Excellent quality and fast generation.', 'botwriter'),
50 'website' => 'https://ai.google.dev',
51 'api_url' => 'https://aistudio.google.com/apikey',
52 'docs_url' => 'https://ai.google.dev/gemini-api/docs/image-generation',
53 'pricing_url' => 'https://ai.google.dev/gemini-api/docs/pricing',
54 'free_credits' => __('Uses same API key as Gemini text models', 'botwriter'),
55 'pricing_summary' => [
56 'Gemini 3.1 Flash Lite Image' => __('See pricing page', 'botwriter'),
57 'Gemini 3.1 Flash Image' => __('See pricing page', 'botwriter'),
58 'Gemini 3 Pro Image' => __('See pricing page', 'botwriter'),
59 'Gemini 2.5 Flash Image (legacy)' => __('See pricing page', 'botwriter'),
60 ],
61 'features' => [
62 __('Uses the same API key as Google Gemini text models', 'botwriter'),
63 __('High-quality image generation', 'botwriter'),
64 __('Excellent text rendering in images', 'botwriter'),
65 __('Multiple aspect ratios supported', 'botwriter'),
66 __('Supports Nano Banana 2 / 2 Lite / Pro families', 'botwriter'),
67 ],
68 'pros' => [
69 __('Same API key as text models', 'botwriter'),
70 __('Great prompt understanding', 'botwriter'),
71 __('Fast generation speed', 'botwriter'),
72 __('High quality outputs', 'botwriter'),
73 ],
74 'cons' => [
75 __('Some content restrictions', 'botwriter'),
76 __('Requires Google API billing', 'botwriter'),
77 ],
78 ];
79 }
80
81 /**
82 * Render Gemini image settings tab content
83 */
84 function botwriter_render_gemini_settings($settings, $is_active) {
85 $info = botwriter_get_gemini_image_info();
86 $models = botwriter_get_gemini_image_models();
87 $current_model = $settings['botwriter_gemini_image_model'] ?? 'gemini-3.1-flash-lite-image';
88 $google_api_key = $settings['botwriter_google_api_key'] ?? '';
89 $has_key = !empty($google_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('Gemini Images uses Google AI API.', 'botwriter'); ?></strong>
98 <?php esc_html_e('This is the same API key used in Text AI → Google Gemini. You can configure it from either tab.', 'botwriter'); ?></p>
99 </div>
100
101 <div class="form-row">
102 <label><?php esc_html_e('Google API Key:', 'botwriter'); ?></label>
103 <div class="api-key-wrapper">
104 <input type="password"
105 name="botwriter_google_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_google_api_key')) : ''); ?>"
108 placeholder="AIza..." />
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">Google AI Studio</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="gemini">
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('Image Model:', 'botwriter'); ?></label>
124 <select name="botwriter_gemini_image_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($current_model, $id); ?>><?php echo esc_html($name); ?></option>
127 <?php endforeach; ?>
128 </select>
129 <p class="description"><?php esc_html_e('3.1 Flash Lite Image is recommended for lowest cost. 3.1 Flash Image is the best balance. 3 Pro Image is best for premium quality and complex prompts.', 'botwriter'); ?></p>
130 </div>
131 </div>
132
133 <div class="provider-info-card">
134 <h4><span class="dashicons dashicons-info-outline"></span> <?php esc_html_e('How to Use Gemini Images', 'botwriter'); ?></h4>
135 <ol class="setup-steps">
136 <li><?php esc_html_e('Get a free API key from', 'botwriter'); ?> <a href="<?php echo esc_url($info['api_url']); ?>" target="_blank"><?php esc_html_e('Google AI Studio', 'botwriter'); ?></a></li>
137 <li><?php esc_html_e('Enter your Google API key above (or in Text AI → Google Gemini)', 'botwriter'); ?></li>
138 <li><?php esc_html_e('Select Google Gemini as your image provider here', 'botwriter'); ?></li>
139 <li><?php esc_html_e('Choose your preferred model (3.1 Flash Lite for lowest cost, 3.1 Flash for best balance)', 'botwriter'); ?></li>
140 <li><?php esc_html_e('That\'s it! The same API key works for both text and images', 'botwriter'); ?></li>
141 </ol>
142 </div>
143
144 <div class="provider-pricing-card">
145 <h4><span class="dashicons dashicons-money-alt"></span> <?php esc_html_e('Pricing Overview', 'botwriter'); ?></h4>
146
147 <div class="pricing-highlight">
148 <span class="free-credits-badge"><?php esc_html_e('Shared API Key', 'botwriter'); ?></span>
149 <p><?php echo esc_html($info['free_credits']); ?></p>
150 </div>
151
152 <table class="pricing-table">
153 <thead>
154 <tr>
155 <th><?php esc_html_e('Model', 'botwriter'); ?></th>
156 <th><?php esc_html_e('Price', 'botwriter'); ?></th>
157 </tr>
158 </thead>
159 <tbody>
160 <?php foreach ($info['pricing_summary'] as $model => $price): ?>
161 <tr>
162 <td><code><?php echo esc_html($model); ?></code></td>
163 <td><strong><?php echo esc_html($price); ?></strong></td>
164 </tr>
165 <?php endforeach; ?>
166 </tbody>
167 </table>
168
169 <p class="pricing-note">
170 <a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="button button-secondary">
171 <span class="dashicons dashicons-external"></span> <?php esc_html_e('View Full Pricing', 'botwriter'); ?>
172 </a>
173 </p>
174 </div>
175
176 <div class="provider-features-card">
177 <h4><span class="dashicons dashicons-star-filled"></span> <?php esc_html_e('Features & Benefits', 'botwriter'); ?></h4>
178 <ul class="features-list">
179 <?php foreach ($info['features'] as $feature): ?>
180 <li><span class="dashicons dashicons-yes-alt"></span> <?php echo esc_html($feature); ?></li>
181 <?php endforeach; ?>
182 </ul>
183
184 <div class="pros-cons">
185 <div class="pros">
186 <h5><?php esc_html_e('Pros', 'botwriter'); ?></h5>
187 <ul>
188 <?php foreach ($info['pros'] as $pro): ?>
189 <li><span class="dashicons dashicons-plus-alt2"></span> <?php echo esc_html($pro); ?></li>
190 <?php endforeach; ?>
191 </ul>
192 </div>
193 <div class="cons">
194 <h5><?php esc_html_e('Cons', 'botwriter'); ?></h5>
195 <ul>
196 <?php foreach ($info['cons'] as $con): ?>
197 <li><span class="dashicons dashicons-minus"></span> <?php echo esc_html($con); ?></li>
198 <?php endforeach; ?>
199 </ul>
200 </div>
201 </div>
202 </div>
203
204 <div class="provider-links-card">
205 <h4><span class="dashicons dashicons-admin-links"></span> <?php esc_html_e('Useful Links', 'botwriter'); ?></h4>
206 <div class="links-grid">
207 <a href="<?php echo esc_url($info['api_url']); ?>" target="_blank" class="link-item">
208 <span class="dashicons dashicons-admin-network"></span>
209 <?php esc_html_e('Get API Key', 'botwriter'); ?>
210 </a>
211 <a href="<?php echo esc_url($info['docs_url']); ?>" target="_blank" class="link-item">
212 <span class="dashicons dashicons-book"></span>
213 <?php esc_html_e('Image Docs', 'botwriter'); ?>
214 </a>
215 <a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="link-item">
216 <span class="dashicons dashicons-money-alt"></span>
217 <?php esc_html_e('Pricing', 'botwriter'); ?>
218 </a>
219 <a href="<?php echo esc_url($info['website']); ?>" target="_blank" class="link-item">
220 <span class="dashicons dashicons-external"></span>
221 <?php esc_html_e('Google AI', 'botwriter'); ?>
222 </a>
223 </div>
224 </div>
225 </div>
226 <?php
227 }
228