Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/aimogen-pro/scripts/ai-post-creator-gutenberg.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + "use strict";
2 + function assistantSelected(checkID, disableClass)
3 + {
4 + if(jQuery('#' + checkID).val() == '')
5 + {
6 + jQuery('.' + disableClass).find('option').removeAttr('disabled');
7 + }
8 + else
9 + {
10 + jQuery('.' + disableClass).find('option').attr('disabled', 'disabled');
11 + }
12 + }
13 + jQuery(document).ready(function ($)
14 + {
15 + if( $('#aiomatic_show_more').length )
16 + {
17 + $('#aiomatic_show_more').on('click', function(){
18 + if(jQuery('.aiomatic_toggle_me').is(":visible"))
19 + {
20 + jQuery(".aiomatic_toggle_me").hide();
21 + }
22 + else
23 + {
24 + jQuery(".aiomatic_toggle_me").show();
25 + }
26 + });
27 + }
28 + if( $('#aiomatic_ai_content_generator').length )
29 + {
30 + var aiomatic_ai_content_generator_btn = $('#aiomatic_ai_content_generator');
31 + }
32 + else
33 + {
34 + return;
35 + }
36 + if( $('#aiomatic_save_ai_content').length )
37 + {
38 + var aiomatic_save_ai_content_btn = $('#aiomatic_save_ai_content');
39 + }
40 + else
41 + {
42 + console.log('aiomatic_save_ai_content button not found');
43 + return;
44 + }
45 + function aiomatic_ShowError(msg){
46 + console.log(msg);
47 + }
48 + function aiomaticLoading(btn){
49 + btn.attr('disabled','disabled');
50 + if(!btn.find('spinner').length)
51 + {
52 + btn.append('<span class="spinner"></span>');
53 + }
54 + btn.find('.spinner').css('visibility','unset');
55 + }
56 + function aiomaticRmLoading(btn)
57 + {
58 + btn.removeAttr('disabled');
59 + btn.find('.spinner').remove();
60 + }
61 + function aiomaticSaveProduct(post_id, aiomatic_title, aiomatic_ai_seo, aiomatic_ai_seo_title, aiomatic_ai_content, aiomatic_ai_excerpt, aiomatic_ai_tags, aiomatic_ai_focus)
62 + {
63 + var data = {'action': 'aiomatic_save_post_ai', 'post_id': post_id, 'aiomatic_title': aiomatic_title, 'aiomatic_ai_seo': aiomatic_ai_seo, 'aiomatic_ai_seo_title': aiomatic_ai_seo_title, 'aiomatic_ai_focus': aiomatic_ai_focus, 'aiomatic_ai_content': aiomatic_ai_content, 'aiomatic_ai_excerpt': aiomatic_ai_excerpt, 'aiomatic_ai_tags': aiomatic_ai_tags, 'nonce': aiomatic_creator_object.nonce}
64 + if( $('#ai-generator-status').length )
65 + {
66 + $('#ai-generator-status').html(aiomatic_creator_object.saving_post);
67 + }
68 + $.ajax({
69 + url: aiomatic_creator_object.ajax_url,
70 + data: data,
71 + dataType: 'JSON',
72 + type: 'POST',
73 + success: function (res){
74 + if(res.success == true)
75 + {
76 + if( $('#ai-generator-status').length )
77 + {
78 + $('#ai-generator-status').html(aiomatic_creator_object.generating_done);
79 + }
80 + aiomaticRmLoading(aiomatic_save_ai_content_btn);
81 + window.location.href = res.data.content;
82 + }
83 + else
84 + {
85 + if( $('#ai-generator-status').length )
86 + {
87 + $('#ai-generator-status').html(aiomatic_creator_object.error_occurred + "!");
88 + }
89 + aiomatic_ShowError(aiomatic_creator_object.error_occurred + " " + JSON.stringify(res));
90 + aiomaticRmLoading(aiomatic_save_ai_content_btn);
91 + }
92 + },
93 + error: function ()
94 + {
95 + if( $('#ai-generator-status').length )
96 + {
97 + $('#ai-generator-status').html(aiomatic_creator_object.error_occurred);
98 + }
99 + aiomatic_ShowError(aiomatic_creator_object.error_occurred);
100 + aiomaticRmLoading(aiomatic_save_ai_content_btn);
101 + }
102 + });
103 + }
104 + function aiomaticProductGenerator(title, step, steps)
105 + {
106 + var aiomatic_next_step = step+1;
107 + var aiomatic_step = steps[step];
108 + if( $('#aiomatic_ai_model').length )
109 + {
110 + var model = $('#aiomatic_ai_model').val();
111 + }
112 + else
113 + {
114 + var model = 'gpt-4.1-mini';
115 + }
116 + if( $('#aiomatic_ai_assistant_id').length )
117 + {
118 + var assistant_id = $('#aiomatic_ai_assistant_id').val();
119 + }
120 + else
121 + {
122 + var assistant_id = '';
123 + }
124 + if( $('#ai_title_vision').length )
125 + {
126 + var ai_title_vision = $('#ai_title_vision').prop('checked') ? 1 : 0;
127 + }
128 + else
129 + {
130 + var ai_title_vision = 0;
131 + }
132 + if( $('#aiomatic_title_prompt').length )
133 + {
134 + var titlep = $('#aiomatic_title_prompt').val();
135 + }
136 + else
137 + {
138 + var titlep = '';
139 + }
140 + if( $('#aiomatic_seo_prompt').length )
141 + {
142 + var seop = $('#aiomatic_seo_prompt').val();
143 + }
144 + else
145 + {
146 + var seop = '';
147 + }
148 + if( $('#aiomatic_seo_title_prompt').length )
149 + {
150 + var seo_title = $('#aiomatic_seo_title_prompt').val();
151 + }
152 + else
153 + {
154 + var seo_title = '';
155 + }
156 + if( $('#aiomatic_focus_prompt').length )
157 + {
158 + var focus = $('#aiomatic_focus_prompt').val();
159 + }
160 + else
161 + {
162 + var focus = '';
163 + }
164 + if( $('#aiomatic_content_prompt').length )
165 + {
166 + var contentp = $('#aiomatic_content_prompt').val();
167 + }
168 + else
169 + {
170 + var contentp = '';
171 + }
172 + if( $('#aiomatic_short_prompt').length )
173 + {
174 + var shortp = $('#aiomatic_short_prompt').val();
175 + }
176 + else
177 + {
178 + var shortp = '';
179 + }
180 + if( $('#aiomatic_tag_prompt').length )
181 + {
182 + var tagp = $('#aiomatic_tag_prompt').val();
183 + }
184 + else
185 + {
186 + var tagp = '';
187 + }
188 + if( $('#post_type').length )
189 + {
190 + var post_type = $('#post_type').val();
191 + }
192 + else
193 + {
194 + var post_type = '';
195 + }
196 + if( $('#post_ID').length )
197 + {
198 + var post_id = $('#post_ID').val();
199 + }
200 + else
201 + {
202 + var post_id = '';
203 + }
204 + if( $('#aiomatic_ai_title').length )
205 + {
206 + var prod_title = $('#aiomatic_ai_title').val();
207 + }
208 + else
209 + {
210 + var prod_title = '';
211 + }
212 + if( $('#aiomatic_ai_content').length )
213 + {
214 + var prod_content = $('#aiomatic_ai_content').val();
215 + }
216 + else
217 + {
218 + var prod_content = '';
219 + }
220 + if( $('#aiomatic_ai_excerpt').length )
221 + {
222 + var prod_excerpt = $('#aiomatic_ai_excerpt').val();
223 + }
224 + else
225 + {
226 + var prod_excerpt = '';
227 + }
228 + var data = {'action': 'aiomatic_write_aicontent_info', 'model': model, 'assistant_id': assistant_id, 'vision': ai_title_vision, 'titlep': titlep, 'seo_title': seo_title, 'seop': seop, 'focus': focus, 'contentp': contentp, 'shortp': shortp, 'tagp': tagp, 'step': aiomatic_step, 'title' : title, 'post_id': post_id, 'post_type': post_type, 'prod_title': prod_title, 'prod_content': prod_content, 'prod_excerpt': prod_excerpt, 'nonce': aiomatic_creator_object.nonce}
229 + if(aiomatic_step === 'title')
230 + {
231 + if( $('#ai-generator-status').length )
232 + {
233 + $('#ai-generator-status').html(aiomatic_creator_object.generating_title);
234 + }
235 + }
236 + if(aiomatic_step === 'meta')
237 + {
238 + if( $('#ai-generator-status').length )
239 + {
240 + $('#ai-generator-status').html(aiomatic_creator_object.generating_meta);
241 + }
242 + }
243 + if(aiomatic_step === 'metatitle')
244 + {
245 + if( $('#ai-generator-status').length )
246 + {
247 + $('#ai-generator-status').html(aiomatic_creator_object.generating_meta_title);
248 + }
249 + }
250 + if(aiomatic_step === 'description')
251 + {
252 + if( $('#ai-generator-status').length )
253 + {
254 + $('#ai-generator-status').html(aiomatic_creator_object.generating_content);
255 + }
256 + }
257 + if(aiomatic_step === 'short')
258 + {
259 + if( $('#ai-generator-status').length )
260 + {
261 + $('#ai-generator-status').html(aiomatic_creator_object.generating_excerpt);
262 + }
263 + }
264 + if(aiomatic_step === 'tags')
265 + {
266 + if( $('#ai-generator-status').length )
267 + {
268 + $('#ai-generator-status').html(aiomatic_creator_object.generating_tags);
269 + }
270 + }
271 + if(aiomatic_step === 'focus')
272 + {
273 + if( $('#ai-generator-status').length )
274 + {
275 + $('#ai-generator-status').html(aiomatic_creator_object.generating_focus);
276 + }
277 + }
278 + $.ajax({
279 + url: aiomatic_creator_object.ajax_url,
280 + data: data,
281 + dataType: 'JSON',
282 + type: 'POST',
283 + success: function (res){
284 + if(res.success == true)
285 + {
286 + if(aiomatic_step === 'title')
287 + {
288 + if( $('#aiomatic_ai_title').length )
289 + {
290 + $('#aiomatic_ai_title').val(res.data.content);
291 + }
292 + }
293 + if(aiomatic_step === 'meta')
294 + {
295 + if( $('#aiomatic_ai_seo').length )
296 + {
297 + var curtag = $('#aiomatic_ai_seo').val();
298 + if(curtag == '')
299 + {
300 + $('#aiomatic_ai_seo').val(res.data.content);
301 + }
302 + else
303 + {
304 + $('#aiomatic_ai_seo').val(curtag + " " + res.data.content);
305 + }
306 + }
307 + }
308 + if(aiomatic_step === 'metatitle')
309 + {
310 + if( $('#aiomatic_ai_seo_title').length )
311 + {
312 + var curtag = $('#aiomatic_ai_seo_title').val();
313 + if(curtag == '')
314 + {
315 + $('#aiomatic_ai_seo_title').val(res.data.content);
316 + }
317 + else
318 + {
319 + $('#aiomatic_ai_seo_title').val(curtag + " " + res.data.content);
320 + }
321 + }
322 + }
323 + if(aiomatic_step === 'description')
324 + {
325 + if( $('#aiomatic_ai_content').length )
326 + {
327 + var curtag = $('#aiomatic_ai_content').val();
328 + if(curtag == '')
329 + {
330 + $('#aiomatic_ai_content').val(res.data.content);
331 + }
332 + else
333 + {
334 + $('#aiomatic_ai_content').val(curtag + " " + res.data.content);
335 + }
336 + }
337 + }
338 + if(aiomatic_step === 'short')
339 + {
340 + if( $('#aiomatic_ai_excerpt').length )
341 + {
342 + var curtag = $('#aiomatic_ai_excerpt').val();
343 + if(curtag == '')
344 + {
345 + $('#aiomatic_ai_excerpt').val(res.data.content);
346 + }
347 + else
348 + {
349 + $('#aiomatic_ai_excerpt').val(curtag + " " + res.data.content);
350 + }
351 + }
352 + }
353 + if(aiomatic_step === 'tags')
354 + {
355 + if( $('#aiomatic_ai_tags').length )
356 + {
357 + var curtag = $('#aiomatic_ai_tags').val();
358 + if(curtag == '')
359 + {
360 + $('#aiomatic_ai_tags').val(res.data.content);
361 + }
362 + else
363 + {
364 + $('#aiomatic_ai_tags').val(curtag + "," + res.data.content);
365 + }
366 + }
367 + }
368 + if(aiomatic_step === 'focus')
369 + {
370 + if( $('#aiomatic_ai_focus').length )
371 + {
372 + var curtag = $('#aiomatic_ai_focus').val();
373 + if(curtag == '')
374 + {
375 + $('#aiomatic_ai_focus').val(res.data.content);
376 + }
377 + else
378 + {
379 + $('#aiomatic_ai_focus').val(curtag + "," + res.data.content);
380 + }
381 + }
382 + }
383 + if(aiomatic_next_step === steps.length)
384 + {
385 + if( $('#ai-generator-status').length )
386 + {
387 + $('#ai-generator-status').html(aiomatic_creator_object.generating_done);
388 + }
389 + aiomaticRmLoading(aiomatic_ai_content_generator_btn);
390 + aiomaticRmLoading(aiomatic_save_ai_content_btn);
391 + if( $('#aiomatic_save_button').length )
392 + {
393 + $('#aiomatic_save_button').show();
394 + }
395 + }
396 + else
397 + {
398 + aiomaticProductGenerator(title, aiomatic_next_step, steps);
399 + }
400 + }
401 + else
402 + {
403 + if( $('#ai-generator-status').length )
404 + {
405 + $('#ai-generator-status').html(aiomatic_creator_object.error_occurred + "!");
406 + }
407 + aiomatic_ShowError(aiomatic_creator_object.error_occurred + " " + JSON.stringify(res));
408 + aiomaticRmLoading(aiomatic_ai_content_generator_btn);
409 + aiomaticRmLoading(aiomatic_save_ai_content_btn);
410 + }
411 + },
412 + error: function ()
413 + {
414 + if( $('#ai-generator-status').length )
415 + {
416 + $('#ai-generator-status').html(aiomatic_creator_object.error_occurred);
417 + }
418 + aiomatic_ShowError(aiomatic_creator_object.error_occurred);
419 + aiomaticRmLoading(aiomatic_ai_content_generator_btn);
420 + aiomaticRmLoading(aiomatic_save_ai_content_btn);
421 + }
422 + });
423 + }
424 + aiomatic_ai_content_generator_btn.on('click', function ()
425 + {
426 + if( $('#aiomatic_original_title').length )
427 + {
428 + var aiomatic_title = $('#aiomatic_original_title').val();
429 + }
430 + else
431 + {
432 + var aiomatic_title = '';
433 + }
434 + if( $('#aiomatic_ai_title').length )
435 + {
436 + var aicontent_title = $('#aiomatic_ai_title').val();
437 + }
438 + else
439 + {
440 + var aicontent_title = '';
441 + }
442 + if(aiomatic_title == '')
443 + {
444 + aiomatic_title = aicontent_title;
445 + }
446 + if( $('#aiomatic_generate_title').length )
447 + {
448 + var aiomatic_generate_title = $('#aiomatic_generate_title').prop('checked') ? 1 : 0;
449 + }
450 + else
451 + {
452 + var aiomatic_generate_title = 0;
453 + }
454 + if( $('#aiomatic_generate_description').length )
455 + {
456 + var aiomatic_generate_description = $('#aiomatic_generate_description').prop('checked') ? 1 : 0;
457 + }
458 + else
459 + {
460 + var aiomatic_generate_description = 0;
461 + }
462 + if( $('#aiomatic_generate_meta').length )
463 + {
464 + var aiomatic_generate_meta = $('#aiomatic_generate_meta').prop('checked') ? 1 : 0;
465 + }
466 + else
467 + {
468 + var aiomatic_generate_meta = 0;
469 + }
470 + if( $('#aiomatic_generate_meta_title').length )
471 + {
472 + var aiomatic_generate_meta_title = $('#aiomatic_generate_meta_title').prop('checked') ? 1 : 0;
473 + }
474 + else
475 + {
476 + var aiomatic_generate_meta_title = 0;
477 + }
478 + if( $('#aiomatic_generate_short').length )
479 + {
480 + var aiomatic_generate_short = $('#aiomatic_generate_short').prop('checked') ? 1 : 0;
481 + }
482 + else
483 + {
484 + var aiomatic_generate_short = 0;
485 + }
486 + if( $('#aiomatic_generate_tags').length )
487 + {
488 + var aiomatic_generate_tags = $('#aiomatic_generate_tags').prop('checked') ? 1 : 0;
489 + }
490 + else
491 + {
492 + var aiomatic_generate_tags = 0;
493 + }
494 + if( $('#aiomatic_generate_focus').length )
495 + {
496 + var aiomatic_generate_focus = $('#aiomatic_generate_focus').prop('checked') ? 1 : 0;
497 + }
498 + else
499 + {
500 + var aiomatic_generate_focus = 0;
501 + }
502 + var aiomaticSteps = [];
503 + if(aiomatic_generate_title)
504 + {
505 + aiomaticSteps.push('title');
506 + }
507 + if(aiomatic_generate_meta)
508 + {
509 + aiomaticSteps.push('meta');
510 + }
511 + if(aiomatic_generate_meta_title)
512 + {
513 + aiomaticSteps.push('metatitle');
514 + }
515 + if(aiomatic_generate_description)
516 + {
517 + aiomaticSteps.push('description');
518 + }
519 + if(aiomatic_generate_short)
520 + {
521 + aiomaticSteps.push('short');
522 + }
523 + if(aiomatic_generate_tags)
524 + {
525 + aiomaticSteps.push('tags');
526 + }
527 + if(aiomatic_generate_focus)
528 + {
529 + aiomaticSteps.push('focus');
530 + }
531 + if(aiomatic_title === '')
532 + {
533 + alert(aiomatic_creator_object.no_title)
534 + }
535 + else if(!aiomaticSteps.length)
536 + {
537 + alert(aiomatic_creator_object.no_step)
538 + }
539 + else
540 + {
541 + aiomaticLoading(aiomatic_ai_content_generator_btn);
542 + aiomaticLoading(aiomatic_save_ai_content_btn);
543 + aiomaticProductGenerator(aiomatic_title, 0, aiomaticSteps);
544 + }
545 + });
546 + aiomatic_save_ai_content_btn.on('click', function ()
547 + {
548 + if( $('#aiomatic_ai_title').length )
549 + {
550 + var aiomatic_title = $('#aiomatic_ai_title').val();
551 + }
552 + else
553 + {
554 + var aiomatic_title = '';
555 + }
556 + if( $('#aiomatic_ai_seo').length )
557 + {
558 + var aiomatic_ai_seo = $('#aiomatic_ai_seo').val();
559 + }
560 + else
561 + {
562 + var aiomatic_ai_seo = '';
563 + }
564 + if( $('#aiomatic_ai_seo_title').length )
565 + {
566 + var aiomatic_ai_seo_title = $('#aiomatic_ai_seo_title').val();
567 + }
568 + else
569 + {
570 + var aiomatic_ai_seo_title = '';
571 + }
572 + if( $('#aiomatic_ai_content').length )
573 + {
574 + var aiomatic_ai_content = $('#aiomatic_ai_content').val();
575 + }
576 + else
577 + {
578 + var aiomatic_ai_content = '';
579 + }
580 + if( $('#aiomatic_ai_excerpt').length )
581 + {
582 + var aiomatic_ai_excerpt = $('#aiomatic_ai_excerpt').val();
583 + }
584 + else
585 + {
586 + var aiomatic_ai_excerpt = '';
587 + }
588 + if( $('#aiomatic_ai_tags').length )
589 + {
590 + var aiomatic_ai_tags = $('#aiomatic_ai_tags').val();
591 + }
592 + else
593 + {
594 + var aiomatic_ai_tags = '';
595 + }
596 + if( $('#aiomatic_ai_focus').length )
597 + {
598 + var aiomatic_ai_focus = $('#aiomatic_ai_focus').val();
599 + }
600 + else
601 + {
602 + var aiomatic_ai_focus = '';
603 + }
604 + if(aiomatic_title == '' && aiomatic_ai_seo == '' && aiomatic_ai_seo_title == '' && aiomatic_ai_content == '' && aiomatic_ai_excerpt == '' && aiomatic_ai_tags == '' && aiomatic_ai_focus == '')
605 + {
606 + alert(aiomatic_creator_object.no_change);
607 + }
608 + else
609 + {
610 + aiomaticLoading(aiomatic_save_ai_content_btn);
611 + if(aiomatic_creator_object.post_id != '' && aiomatic_creator_object.post_id !== undefined && aiomatic_creator_object.post_id !== null)
612 + {
613 + aiomaticSaveProduct(aiomatic_creator_object.post_id, aiomatic_title, aiomatic_ai_seo, aiomatic_ai_seo_title, aiomatic_ai_content, aiomatic_ai_excerpt, aiomatic_ai_tags, aiomatic_ai_focus);
614 + }
615 + else
616 + {
617 + alert(aiomatic_creator_object.no_post_id);
618 + }
619 + }
620 + });
621 + });