| 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 |
return [ |
| 18 |
'gemini-2.5-flash-image' => 'Gemini 2.5 Flash Image (fast, efficient)', |
| 19 |
'gemini-3-pro-image-preview' => 'Gemini 3 Pro Image Preview (advanced, 4K)', |
| 20 |
'gemini-3.1-flash-image-preview' => 'Gemini 3.1 Flash Image Preview (latest)', |
| 21 |
]; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Get Gemini image provider info |
| 26 |
*/ |
| 27 |
function botwriter_get_gemini_image_info() { |
| 28 |
return [ |
| 29 |
'name' => 'Google Gemini', |
| 30 |
'description' => __('Google\'s AI image generation using Gemini models. Excellent quality and fast generation.', 'botwriter'), |
| 31 |
'website' => 'https://ai.google.dev', |
| 32 |
'api_url' => 'https://aistudio.google.com/apikey', |
| 33 |
'docs_url' => 'https://ai.google.dev/gemini-api/docs/image-generation', |
| 34 |
'pricing_url' => 'https://ai.google.dev/gemini-api/docs/pricing', |
| 35 |
'free_credits' => __('Uses same API key as Gemini text models', 'botwriter'), |
| 36 |
'pricing_summary' => [ |
| 37 |
'Gemini 2.5 Flash Image' => __('See pricing page', 'botwriter'), |
| 38 |
'Gemini 3 Pro Image Preview' => __('See pricing page', 'botwriter'), |
| 39 |
'Gemini 3.1 Flash Image Preview' => __('See pricing page', 'botwriter'), |
| 40 |
], |
| 41 |
'features' => [ |
| 42 |
__('Uses the same API key as Google Gemini text models', 'botwriter'), |
| 43 |
__('High-quality image generation', 'botwriter'), |
| 44 |
__('Excellent text rendering in images', 'botwriter'), |
| 45 |
__('Multiple aspect ratios supported', 'botwriter'), |
| 46 |
__('Fast generation with 2.5 Flash', 'botwriter'), |
| 47 |
], |
| 48 |
'pros' => [ |
| 49 |
__('Same API key as text models', 'botwriter'), |
| 50 |
__('Great prompt understanding', 'botwriter'), |
| 51 |
__('Fast generation speed', 'botwriter'), |
| 52 |
__('High quality outputs', 'botwriter'), |
| 53 |
], |
| 54 |
'cons' => [ |
| 55 |
__('Some content restrictions', 'botwriter'), |
| 56 |
__('Requires Google API billing', 'botwriter'), |
| 57 |
], |
| 58 |
]; |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Render Gemini image settings tab content |
| 63 |
*/ |
| 64 |
function botwriter_render_gemini_settings($settings, $is_active) { |
| 65 |
$info = botwriter_get_gemini_image_info(); |
| 66 |
$models = botwriter_get_gemini_image_models(); |
| 67 |
$current_model = $settings['botwriter_gemini_image_model'] ?? 'gemini-2.5-flash-image'; |
| 68 |
$google_api_key = $settings['botwriter_google_api_key'] ?? ''; |
| 69 |
$has_key = !empty($google_api_key); |
| 70 |
?> |
| 71 |
<div class="provider-config-section"> |
| 72 |
<div class="provider-config-card"> |
| 73 |
<h4><?php esc_html_e('API Configuration', 'botwriter'); ?></h4> |
| 74 |
|
| 75 |
<div class="info-notice"> |
| 76 |
<span class="dashicons dashicons-info"></span> |
| 77 |
<p><strong><?php esc_html_e('Gemini Images uses Google AI API.', 'botwriter'); ?></strong> |
| 78 |
<?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> |
| 79 |
</div> |
| 80 |
|
| 81 |
<div class="form-row"> |
| 82 |
<label><?php esc_html_e('Google API Key:', 'botwriter'); ?></label> |
| 83 |
<div class="api-key-wrapper"> |
| 84 |
<input type="password" |
| 85 |
name="botwriter_google_api_key" |
| 86 |
class="form-control api-key-input" |
| 87 |
value="<?php echo esc_attr(function_exists('botwriter_decrypt_api_key') ? botwriter_decrypt_api_key(get_option('botwriter_google_api_key')) : ''); ?>" |
| 88 |
placeholder="AIza..." /> |
| 89 |
<button type="button" class="button toggle-api-key"><?php esc_html_e('Show', 'botwriter'); ?></button> |
| 90 |
</div> |
| 91 |
<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> |
| 92 |
</div> |
| 93 |
|
| 94 |
<div class="form-row"> |
| 95 |
<button type="button" class="button button-secondary test-api-key" data-provider="gemini"> |
| 96 |
<span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e('Test API Key', 'botwriter'); ?> |
| 97 |
</button> |
| 98 |
<span class="test-api-result"></span> |
| 99 |
</div> |
| 100 |
|
| 101 |
<div class="form-row"> |
| 102 |
<label><?php esc_html_e('Image Model:', 'botwriter'); ?></label> |
| 103 |
<select name="botwriter_gemini_image_model" class="form-select" style="width: 100%; max-width: 400px;"> |
| 104 |
<?php foreach ($models as $id => $name): ?> |
| 105 |
<option value="<?php echo esc_attr($id); ?>" <?php selected($current_model, $id); ?>><?php echo esc_html($name); ?></option> |
| 106 |
<?php endforeach; ?> |
| 107 |
</select> |
| 108 |
<p class="description"><?php esc_html_e('2.5 Flash Image is recommended for speed. 3 Pro Preview for advanced features. 3.1 Flash Image Preview is the latest model.', 'botwriter'); ?></p> |
| 109 |
</div> |
| 110 |
</div> |
| 111 |
|
| 112 |
<div class="provider-info-card"> |
| 113 |
<h4><span class="dashicons dashicons-info-outline"></span> <?php esc_html_e('How to Use Gemini Images', 'botwriter'); ?></h4> |
| 114 |
<ol class="setup-steps"> |
| 115 |
<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> |
| 116 |
<li><?php esc_html_e('Enter your Google API key above (or in Text AI → Google Gemini)', 'botwriter'); ?></li> |
| 117 |
<li><?php esc_html_e('Select Google Gemini as your image provider here', 'botwriter'); ?></li> |
| 118 |
<li><?php esc_html_e('Choose your preferred model (2.5 Flash Image for free tier)', 'botwriter'); ?></li> |
| 119 |
<li><?php esc_html_e('That\'s it! The same API key works for both text and images', 'botwriter'); ?></li> |
| 120 |
</ol> |
| 121 |
</div> |
| 122 |
|
| 123 |
<div class="provider-pricing-card"> |
| 124 |
<h4><span class="dashicons dashicons-money-alt"></span> <?php esc_html_e('Pricing Overview', 'botwriter'); ?></h4> |
| 125 |
|
| 126 |
<div class="pricing-highlight"> |
| 127 |
<span class="free-credits-badge"><?php esc_html_e('Shared API Key', 'botwriter'); ?></span> |
| 128 |
<p><?php echo esc_html($info['free_credits']); ?></p> |
| 129 |
</div> |
| 130 |
|
| 131 |
<table class="pricing-table"> |
| 132 |
<thead> |
| 133 |
<tr> |
| 134 |
<th><?php esc_html_e('Model', 'botwriter'); ?></th> |
| 135 |
<th><?php esc_html_e('Price', 'botwriter'); ?></th> |
| 136 |
</tr> |
| 137 |
</thead> |
| 138 |
<tbody> |
| 139 |
<?php foreach ($info['pricing_summary'] as $model => $price): ?> |
| 140 |
<tr> |
| 141 |
<td><code><?php echo esc_html($model); ?></code></td> |
| 142 |
<td><strong><?php echo esc_html($price); ?></strong></td> |
| 143 |
</tr> |
| 144 |
<?php endforeach; ?> |
| 145 |
</tbody> |
| 146 |
</table> |
| 147 |
|
| 148 |
<p class="pricing-note"> |
| 149 |
<a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="button button-secondary"> |
| 150 |
<span class="dashicons dashicons-external"></span> <?php esc_html_e('View Full Pricing', 'botwriter'); ?> |
| 151 |
</a> |
| 152 |
</p> |
| 153 |
</div> |
| 154 |
|
| 155 |
<div class="provider-features-card"> |
| 156 |
<h4><span class="dashicons dashicons-star-filled"></span> <?php esc_html_e('Features & Benefits', 'botwriter'); ?></h4> |
| 157 |
<ul class="features-list"> |
| 158 |
<?php foreach ($info['features'] as $feature): ?> |
| 159 |
<li><span class="dashicons dashicons-yes-alt"></span> <?php echo esc_html($feature); ?></li> |
| 160 |
<?php endforeach; ?> |
| 161 |
</ul> |
| 162 |
|
| 163 |
<div class="pros-cons"> |
| 164 |
<div class="pros"> |
| 165 |
<h5><?php esc_html_e('Pros', 'botwriter'); ?></h5> |
| 166 |
<ul> |
| 167 |
<?php foreach ($info['pros'] as $pro): ?> |
| 168 |
<li><span class="dashicons dashicons-plus-alt2"></span> <?php echo esc_html($pro); ?></li> |
| 169 |
<?php endforeach; ?> |
| 170 |
</ul> |
| 171 |
</div> |
| 172 |
<div class="cons"> |
| 173 |
<h5><?php esc_html_e('Cons', 'botwriter'); ?></h5> |
| 174 |
<ul> |
| 175 |
<?php foreach ($info['cons'] as $con): ?> |
| 176 |
<li><span class="dashicons dashicons-minus"></span> <?php echo esc_html($con); ?></li> |
| 177 |
<?php endforeach; ?> |
| 178 |
</ul> |
| 179 |
</div> |
| 180 |
</div> |
| 181 |
</div> |
| 182 |
|
| 183 |
<div class="provider-links-card"> |
| 184 |
<h4><span class="dashicons dashicons-admin-links"></span> <?php esc_html_e('Useful Links', 'botwriter'); ?></h4> |
| 185 |
<div class="links-grid"> |
| 186 |
<a href="<?php echo esc_url($info['api_url']); ?>" target="_blank" class="link-item"> |
| 187 |
<span class="dashicons dashicons-admin-network"></span> |
| 188 |
<?php esc_html_e('Get API Key', 'botwriter'); ?> |
| 189 |
</a> |
| 190 |
<a href="<?php echo esc_url($info['docs_url']); ?>" target="_blank" class="link-item"> |
| 191 |
<span class="dashicons dashicons-book"></span> |
| 192 |
<?php esc_html_e('Image Docs', 'botwriter'); ?> |
| 193 |
</a> |
| 194 |
<a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="link-item"> |
| 195 |
<span class="dashicons dashicons-money-alt"></span> |
| 196 |
<?php esc_html_e('Pricing', 'botwriter'); ?> |
| 197 |
</a> |
| 198 |
<a href="<?php echo esc_url($info['website']); ?>" target="_blank" class="link-item"> |
| 199 |
<span class="dashicons dashicons-external"></span> |
| 200 |
<?php esc_html_e('Google AI', 'botwriter'); ?> |
| 201 |
</a> |
| 202 |
</div> |
| 203 |
</div> |
| 204 |
</div> |
| 205 |
<?php |
| 206 |
} |
| 207 |
|