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

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

220 lines 10.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cloudflare Workers AI Image Provider Settings
4 *
5 * @package BotWriter
6 */
7
8 if (!defined('ABSPATH')) {
9 exit;
10 }
11
12 /**
13 * Get Cloudflare Workers AI models configuration
14 */
15 function botwriter_get_cloudflare_models() {
16 if (function_exists('botwriter_get_provider_image_models')) {
17 $catalog_models = botwriter_get_provider_image_models('cloudflare');
18 if (!empty($catalog_models)) {
19 return $catalog_models;
20 }
21 }
22
23 return [
24 'Flux (Black Forest Labs)' => [
25 'flux-1-schnell' => 'FLUX.1 Schnell ⭐ (Fast, FREE tier - RECOMMENDED)',
26 'flux-2-dev' => 'FLUX.2 Dev (Multi-reference, Partner - experimental)',
27 'flux-2-klein-4b' => 'FLUX.2 Klein 4B (ultra-fast)',
28 'flux-2-klein-9b' => 'FLUX.2 Klein 9B (enhanced quality)',
29 ],
30 'Leonardo' => [
31 'lucid-origin' => 'Lucid Origin',
32 'phoenix-1.0' => 'Phoenix 1.0',
33 ],
34 'Stable Diffusion' => [
35 'stable-diffusion-xl-lightning' => 'SDXL Lightning (Very fast, Beta)',
36 'stable-diffusion-xl-base-1.0' => 'SDXL Base 1.0 (Beta)',
37 ],
38 'Other' => [
39 'dreamshaper-8-lcm' => 'Dreamshaper 8 LCM (Photorealism)',
40 ],
41 ];
42 }
43
44 /**
45 * Get Cloudflare Workers AI provider info
46 */
47 function botwriter_get_cloudflare_info() {
48 return [
49 'name' => 'Cloudflare AI',
50 'description' => __('Cloudflare Workers AI provides serverless AI inference with generous free tier. Uses FLUX.1 Schnell for high-quality images.', 'botwriter'),
51 'website' => 'https://www.cloudflare.com/developer-platform/workers-ai/',
52 'api_url' => 'https://dash.cloudflare.com/?to=/:account/ai/workers-ai',
53 'docs_url' => 'https://developers.cloudflare.com/workers-ai/models/',
54 'pricing_url' => 'https://developers.cloudflare.com/workers-ai/platform/pricing/',
55 'free_credits' => __('10,000 Neurons/day FREE (~230 images with FLUX.1 Schnell!)', 'botwriter'),
56 'pricing_summary' => [
57 'FLUX.1 Schnell' => '~43 neurons (~$0.00047/image)',
58 'FLUX.2 Dev' => '~150 neurons (~$0.0017/image)',
59 'SDXL Lightning' => 'Beta pricing',
60 ],
61 'features' => [
62 __('10,000 Neurons FREE daily!', 'botwriter'),
63 __('FLUX.1 Schnell - 12B parameter model', 'botwriter'),
64 __('No GPU management needed', 'botwriter'),
65 __('Serverless & auto-scaling', 'botwriter'),
66 __('Global edge network', 'botwriter'),
67 __('Simple REST API', 'botwriter'),
68 ],
69 'pros' => [
70 __('~230 FREE images/day', 'botwriter'),
71 __('High quality FLUX model', 'botwriter'),
72 __('Very cheap after free tier', 'botwriter'),
73 __('Global Cloudflare network', 'botwriter'),
74 ],
75 'cons' => [
76 __('No image size control', 'botwriter'),
77 __('Limited to 8 steps max', 'botwriter'),
78 __('Requires Cloudflare account', 'botwriter'),
79 ],
80 ];
81 }
82
83 /**
84 * Render Cloudflare Workers AI settings tab content
85 */
86 function botwriter_render_cloudflare_settings($settings, $is_active) {
87 $info = botwriter_get_cloudflare_info();
88 $models = botwriter_get_cloudflare_models();
89 ?>
90 <div class="provider-config-section">
91 <div class="provider-config-card">
92 <h4><?php esc_html_e('API Configuration', 'botwriter'); ?></h4>
93
94 <div class="form-row">
95 <label><?php esc_html_e('Account ID:', 'botwriter'); ?></label>
96 <div class="api-key-wrapper">
97 <input type="text" name="botwriter_cloudflare_account_id" class="form-control"
98 value="<?php echo esc_attr(get_option('botwriter_cloudflare_account_id')); ?>"
99 placeholder="e.g., a1b2c3d4e5f6g7h8i9j0...">
100 </div>
101 <p class="description">
102 <?php esc_html_e('Find your Account ID in the Cloudflare Dashboard → Overview → right sidebar', 'botwriter'); ?>
103 <br><a href="https://dash.cloudflare.com/" target="_blank"><?php esc_html_e('Open Cloudflare Dashboard', 'botwriter'); ?> </a>
104 </p>
105 </div>
106
107 <div class="form-row">
108 <label><?php esc_html_e('API Token:', 'botwriter'); ?></label>
109 <div class="api-key-wrapper">
110 <input type="password" name="botwriter_cloudflare_api_key" class="form-control api-key-input"
111 value="<?php echo esc_attr(botwriter_decrypt_api_key(get_option('botwriter_cloudflare_api_key'))); ?>"
112 placeholder="Your Cloudflare API Token">
113 <button type="button" class="button toggle-api-key"><?php esc_html_e('Show', 'botwriter'); ?></button>
114 <button type="button" class="button button-secondary test-api-key" data-provider="cloudflare">
115 <span class="dashicons dashicons-yes-alt"></span> <?php esc_html_e('Test API Key', 'botwriter'); ?>
116 </button>
117 <span class="test-api-result"></span>
118 </div>
119 <p class="description">
120 <?php esc_html_e('Create a token with "Workers AI" read permission', 'botwriter'); ?>
121 <br><a href="https://dash.cloudflare.com/profile/api-tokens" target="_blank"><?php esc_html_e('Create API Token', 'botwriter'); ?> </a>
122 </p>
123 <?php botwriter_api_key_transmission_notice(); ?>
124 </div>
125
126 <div class="form-row">
127 <label><?php esc_html_e('Model:', 'botwriter'); ?></label>
128 <select name="botwriter_cloudflare_model" class="form-select" style="width: 100%; max-width: 400px;">
129 <?php foreach ($models as $group => $group_models): ?>
130 <optgroup label="<?php echo esc_attr($group); ?>">
131 <?php foreach ($group_models as $id => $name): ?>
132 <option value="<?php echo esc_attr($id); ?>" <?php selected($settings['botwriter_cloudflare_model'], $id); ?>><?php echo esc_html($name); ?></option>
133 <?php endforeach; ?>
134 </optgroup>
135 <?php endforeach; ?>
136 </select>
137 <p class="description"><?php esc_html_e('FLUX.1 Schnell recommended - best balance of quality and free tier usage', 'botwriter'); ?></p>
138 </div>
139 </div>
140
141 <div class="provider-info-card">
142 <div class="provider-info-header">
143 <h4>
144 <span class="dashicons dashicons-cloud"></span>
145 <?php echo esc_html($info['name']); ?>
146 </h4>
147 <div class="provider-links">
148 <a href="<?php echo esc_url($info['website']); ?>" target="_blank" class="provider-link">
149 <span class="dashicons dashicons-admin-site"></span> <?php esc_html_e('Website', 'botwriter'); ?>
150 </a>
151 <a href="<?php echo esc_url($info['docs_url']); ?>" target="_blank" class="provider-link">
152 <span class="dashicons dashicons-book"></span> <?php esc_html_e('Docs', 'botwriter'); ?>
153 </a>
154 <a href="<?php echo esc_url($info['pricing_url']); ?>" target="_blank" class="provider-link">
155 <span class="dashicons dashicons-money-alt"></span> <?php esc_html_e('Pricing', 'botwriter'); ?>
156 </a>
157 </div>
158 </div>
159 <p class="provider-description"><?php echo esc_html($info['description']); ?></p>
160
161 <?php if (!empty($info['free_credits'])): ?>
162 <div class="free-tier-highlight">
163 <span class="dashicons dashicons-yes-alt"></span>
164 <strong><?php echo esc_html($info['free_credits']); ?></strong>
165 </div>
166 <?php endif; ?>
167
168 <div class="provider-details-grid">
169 <div class="provider-features">
170 <h5><span class="dashicons dashicons-star-filled"></span> <?php esc_html_e('Features', 'botwriter'); ?></h5>
171 <ul>
172 <?php foreach ($info['features'] as $feature): ?>
173 <li><?php echo esc_html($feature); ?></li>
174 <?php endforeach; ?>
175 </ul>
176 </div>
177
178 <div class="provider-pricing">
179 <h5><span class="dashicons dashicons-money-alt"></span> <?php esc_html_e('Pricing', 'botwriter'); ?></h5>
180 <ul class="pricing-list">
181 <?php foreach ($info['pricing_summary'] as $model => $price): ?>
182 <li><span class="model-name"><?php echo esc_html($model); ?>:</span> <span class="price"><?php echo esc_html($price); ?></span></li>
183 <?php endforeach; ?>
184 </ul>
185 </div>
186
187 <div class="provider-pros-cons">
188 <div class="pros">
189 <h5><span class="dashicons dashicons-thumbs-up"></span> <?php esc_html_e('Pros', 'botwriter'); ?></h5>
190 <ul>
191 <?php foreach ($info['pros'] as $pro): ?>
192 <li><?php echo esc_html($pro); ?></li>
193 <?php endforeach; ?>
194 </ul>
195 </div>
196 <div class="cons">
197 <h5><span class="dashicons dashicons-thumbs-down"></span> <?php esc_html_e('Cons', 'botwriter'); ?></h5>
198 <ul>
199 <?php foreach ($info['cons'] as $con): ?>
200 <li><?php echo esc_html($con); ?></li>
201 <?php endforeach; ?>
202 </ul>
203 </div>
204 </div>
205 </div>
206
207 <div class="setup-instructions">
208 <h5><span class="dashicons dashicons-info"></span> <?php esc_html_e('Setup Instructions', 'botwriter'); ?></h5>
209 <ol>
210 <li><?php esc_html_e('Create a free Cloudflare account at cloudflare.com', 'botwriter'); ?></li>
211 <li><?php esc_html_e('Go to your dashboard and copy your Account ID from the sidebar', 'botwriter'); ?></li>
212 <li><?php esc_html_e('Create an API Token with "Workers AI" read permissions', 'botwriter'); ?></li>
213 <li><?php esc_html_e('Paste both values above', 'botwriter'); ?></li>
214 </ol>
215 </div>
216 </div>
217 </div>
218 <?php
219 }
220