| @@ -3,12 +3,11 @@ | ||
| 3 | 3 | |
| 4 | 4 | use Elementor\Core\Common\Modules\Connect\Apps\Library; |
| 5 | 5 | use Elementor\Modules\Ai\Module; |
| 6 | 6 | use Elementor\Utils as ElementorUtils; |
| 7 | -use Elementor\Plugin; | |
| 8 | 7 | |
| 9 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | - exit; // Exit if accessed directly. | |
| 9 | + exit; // Exit if accessed directly | |
| 11 | 10 | } |
| 12 | 11 | |
| 13 | 12 | class Ai extends Library { |
| 14 | 13 | const API_URL = 'https://my.elementor.com/api/v2/ai/'; |
| @@ -18,10 +17,8 @@ | ||
| 18 | 17 | const IMAGE_STRENGTH = 'image_strength'; |
| 19 | 18 | const ASPECT_RATIO = 'ratio'; |
| 20 | 19 | const IMAGE_RESOLUTION = 'image_resolution'; |
| 21 | 20 | |
| 22 | - const IMAGE_BACKGROUND_COLOR = 'background_color'; | |
| 23 | - | |
| 24 | 21 | const PROMPT = 'prompt'; |
| 25 | 22 | |
| 26 | 23 | public function get_title() { |
| 27 | 24 | return esc_html__( 'AI', 'elementor' ); |
| @@ -41,8 +38,21 @@ | ||
| 41 | 38 | ] |
| 42 | 39 | ); |
| 43 | 40 | } |
| 44 | 41 | |
| 42 | + public function get_cached_usage() { | |
| 43 | + $cache_key = 'elementor_ai_usage'; | |
| 44 | + $cache_time = 24 * HOUR_IN_SECONDS; | |
| 45 | + $usage = get_site_transient( $cache_key ); | |
| 46 | + | |
| 47 | + if ( ! $usage ) { | |
| 48 | + $usage = $this->get_usage(); | |
| 49 | + set_site_transient( $cache_key, $usage, $cache_time ); | |
| 50 | + } | |
| 51 | + | |
| 52 | + return $usage; | |
| 53 | + } | |
| 54 | + | |
| 45 | 55 | public function get_remote_config() { |
| 46 | 56 | return $this->ai_request( |
| 47 | 57 | 'GET', |
| 48 | 58 | 'remote-config/config', |
| @@ -52,55 +62,10 @@ | ||
| 52 | 62 | ] |
| 53 | 63 | ); |
| 54 | 64 | } |
| 55 | 65 | |
| 56 | - public function get_remote_frontend_config( $data ) { | |
| 57 | - return $this->ai_request( | |
| 58 | - 'POST', | |
| 59 | - 'remote-config/frontend-config', | |
| 60 | - [ | |
| 61 | - 'client_name' => $data['payload']['client_name'], | |
| 62 | - 'client_version' => $data['payload']['client_version'], | |
| 63 | - 'client_session_id' => $data['payload']['client_session_id'], | |
| 64 | - | |
| 65 | - 'api_version' => ELEMENTOR_VERSION, | |
| 66 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 67 | - ], | |
| 68 | - false, | |
| 69 | - '', | |
| 70 | - 'json' | |
| 71 | - ); | |
| 72 | - } | |
| 73 | - | |
| 74 | 66 | /** |
| 75 | - * @param array $event_data { | |
| 76 | - * @type string $name | |
| 77 | - * @type array $data | |
| 78 | - * @type array $client { | |
| 79 | - * @type string $name | |
| 80 | - * @type string $version | |
| 81 | - * @type string $session_id | |
| 82 | - * } | |
| 83 | - * } | |
| 84 | - */ | |
| 85 | - public function send_event( array $event_data ): void { | |
| 86 | - $this->ai_request( | |
| 87 | - 'POST', | |
| 88 | - 'client-events/events', | |
| 89 | - [ | |
| 90 | - 'payload' => $event_data, | |
| 91 | - 'api_version' => ELEMENTOR_VERSION, | |
| 92 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 93 | - ], | |
| 94 | - false, | |
| 95 | - '', | |
| 96 | - 'json' | |
| 97 | - ); | |
| 98 | - } | |
| 99 | - | |
| 100 | - /** | |
| 101 | - * Get file upload get_file_payload | |
| 102 | - * | |
| 67 | + * get_file_payload | |
| 103 | 68 | * @param $filename |
| 104 | 69 | * @param $file_type |
| 105 | 70 | * @param $file_path |
| 106 | 71 | * @param $boundary |
| @@ -226,37 +191,14 @@ | ||
| 226 | 191 | 'context' => wp_json_encode( $context ), |
| 227 | 192 | 'ids' => $request_ids, |
| 228 | 193 | 'api_version' => ELEMENTOR_VERSION, |
| 229 | 194 | 'site_lang' => get_bloginfo( 'language' ), |
| 230 | - ], | |
| 231 | - false, | |
| 232 | - '', | |
| 233 | - 'json' | |
| 195 | + ] | |
| 234 | 196 | ); |
| 235 | 197 | } |
| 236 | 198 | |
| 237 | - public function get_excerpt( $prompt, $context, $request_ids ) { | |
| 238 | - $excerpt_length = apply_filters( 'excerpt_length', 55 ); | |
| 239 | - return $this->ai_request( | |
| 240 | - 'POST', | |
| 241 | - 'text/get-excerpt', | |
| 242 | - [ | |
| 243 | - 'content' => $prompt, | |
| 244 | - 'maxLength' => $excerpt_length, | |
| 245 | - 'context' => wp_json_encode( $context ), | |
| 246 | - 'ids' => $request_ids, | |
| 247 | - 'api_version' => ELEMENTOR_VERSION, | |
| 248 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 249 | - ], | |
| 250 | - false, | |
| 251 | - '', | |
| 252 | - 'json' | |
| 253 | - ); | |
| 254 | - } | |
| 255 | - | |
| 256 | 199 | /** |
| 257 | - * Get Image Prompt Enhanced get_image_prompt_enhanced | |
| 258 | - * | |
| 200 | + * get_image_prompt_enhanced | |
| 259 | 201 | * @param $prompt |
| 260 | 202 | * |
| 261 | 203 | * @return mixed|\WP_Error |
| 262 | 204 | */ |
| @@ -284,12 +226,9 @@ | ||
| 284 | 226 | 'context' => wp_json_encode( $context ), |
| 285 | 227 | 'ids' => $request_ids, |
| 286 | 228 | 'api_version' => ELEMENTOR_VERSION, |
| 287 | 229 | 'site_lang' => get_bloginfo( 'language' ), |
| 288 | - ], | |
| 289 | - false, | |
| 290 | - '', | |
| 291 | - 'json' | |
| 230 | + ] | |
| 292 | 231 | ); |
| 293 | 232 | } |
| 294 | 233 | |
| 295 | 234 | public function get_custom_code( $data, $context, $request_ids ) { |
| @@ -302,12 +241,9 @@ | ||
| 302 | 241 | 'context' => wp_json_encode( $context ), |
| 303 | 242 | 'ids' => $request_ids, |
| 304 | 243 | 'api_version' => ELEMENTOR_VERSION, |
| 305 | 244 | 'site_lang' => get_bloginfo( 'language' ), |
| 306 | - ], | |
| 307 | - false, | |
| 308 | - '', | |
| 309 | - 'json' | |
| 245 | + ] | |
| 310 | 246 | ); |
| 311 | 247 | } |
| 312 | 248 | |
| 313 | 249 | public function get_custom_css( $data, $context, $request_ids ) { |
| @@ -321,18 +257,14 @@ | ||
| 321 | 257 | 'context' => wp_json_encode( $context ), |
| 322 | 258 | 'ids' => $request_ids, |
| 323 | 259 | 'api_version' => ELEMENTOR_VERSION, |
| 324 | 260 | 'site_lang' => get_bloginfo( 'language' ), |
| 325 | - ], | |
| 326 | - false, | |
| 327 | - '', | |
| 328 | - 'json' | |
| 261 | + ] | |
| 329 | 262 | ); |
| 330 | 263 | } |
| 331 | 264 | |
| 332 | 265 | /** |
| 333 | - * Get text to image get_text_to_image | |
| 334 | - * | |
| 266 | + * get_text_to_image | |
| 335 | 267 | * @param $prompt |
| 336 | 268 | * @param $prompt_settings |
| 337 | 269 | * |
| 338 | 270 | * @return mixed|\WP_Error |
| @@ -342,57 +274,25 @@ | ||
| 342 | 274 | 'POST', |
| 343 | 275 | 'image/text-to-image', |
| 344 | 276 | [ |
| 345 | 277 | self::PROMPT => $data['payload']['prompt'], |
| 346 | - self::IMAGE_TYPE => $data['payload']['settings'][ self::IMAGE_TYPE ] . '/' . $data['payload']['settings'][ self::STYLE_PRESET ], | |
| 347 | - self::ASPECT_RATIO => $data['payload']['settings'][ self::ASPECT_RATIO ], | |
| 278 | + self::IMAGE_TYPE => $data['payload']['promptSettings'][ self::IMAGE_TYPE ] . '/' . $data['payload']['promptSettings'][ self::STYLE_PRESET ], | |
| 279 | + self::ASPECT_RATIO => $data['payload']['promptSettings'][ self::ASPECT_RATIO ], | |
| 348 | 280 | 'context' => wp_json_encode( $context ), |
| 349 | 281 | 'ids' => $request_ids, |
| 350 | 282 | 'api_version' => ELEMENTOR_VERSION, |
| 351 | 283 | 'site_lang' => get_bloginfo( 'language' ), |
| 352 | - ], | |
| 353 | - false, | |
| 354 | - '', | |
| 355 | - 'json' | |
| 284 | + ] | |
| 356 | 285 | ); |
| 357 | 286 | } |
| 358 | 287 | |
| 359 | 288 | /** |
| 360 | - * Get_Featured_Image get_featured_image | |
| 289 | + * get_image_to_image | |
| 290 | + * @param $image_data | |
| 361 | 291 | * |
| 362 | - * @param $data | |
| 363 | - * @param $context | |
| 364 | - * @param $request_ids | |
| 365 | 292 | * @return mixed|\WP_Error |
| 293 | + * @throws \Exception | |
| 366 | 294 | */ |
| 367 | - public function get_featured_image( $data, $context, $request_ids ) { | |
| 368 | - return $this->ai_request( | |
| 369 | - 'POST', | |
| 370 | - 'image/text-to-image/featured-image', | |
| 371 | - [ | |
| 372 | - self::PROMPT => $data['payload']['prompt'], | |
| 373 | - self::IMAGE_TYPE => $data['payload']['settings'][ self::IMAGE_TYPE ] . '/' . $data['payload']['settings'][ self::STYLE_PRESET ], | |
| 374 | - self::ASPECT_RATIO => $data['payload']['settings'][ self::ASPECT_RATIO ], | |
| 375 | - 'context' => wp_json_encode( $context ), | |
| 376 | - 'ids' => $request_ids, | |
| 377 | - 'api_version' => ELEMENTOR_VERSION, | |
| 378 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 379 | - ], | |
| 380 | - false, | |
| 381 | - '', | |
| 382 | - 'json' | |
| 383 | - ); | |
| 384 | - } | |
| 385 | - | |
| 386 | - /** | |
| 387 | - * Get Image To Image get_image_to_image | |
| 388 | - * | |
| 389 | - * @param $image_data | |
| 390 | - * @param $context | |
| 391 | - * @param $request_ids | |
| 392 | - * @return mixed|\WP_Error | |
| 393 | - * @throws \Exception If image file not found. | |
| 394 | - */ | |
| 395 | 295 | public function get_image_to_image( $image_data, $context, $request_ids ) { |
| 396 | 296 | $image_file = get_attached_file( $image_data['attachment_id'] ); |
| 397 | 297 | |
| 398 | 298 | if ( ! $image_file ) { |
| @@ -418,85 +318,14 @@ | ||
| 418 | 318 | |
| 419 | 319 | return $result; |
| 420 | 320 | } |
| 421 | 321 | |
| 422 | - | |
| 423 | - private function resizeImageIfNeeded( $original_url ) { | |
| 424 | - try { | |
| 425 | - $max_file_size = 4194304; | |
| 426 | - $current_size = filesize( $original_url ); | |
| 427 | - | |
| 428 | - if ( $current_size <= $max_file_size ) { | |
| 429 | - return $original_url; | |
| 430 | - } | |
| 431 | - | |
| 432 | - $image_editor = wp_get_image_editor( $original_url ); | |
| 433 | - | |
| 434 | - if ( is_wp_error( $image_editor ) ) { | |
| 435 | - return $original_url; | |
| 436 | - } | |
| 437 | - | |
| 438 | - $dimensions = $image_editor->get_size(); | |
| 439 | - $original_width = $dimensions['width']; | |
| 440 | - $original_height = $dimensions['height']; | |
| 441 | - | |
| 442 | - $scaling_factor = sqrt( $max_file_size / $current_size ); | |
| 443 | - | |
| 444 | - $new_width = (int) ( $original_width * $scaling_factor ); | |
| 445 | - $new_height = (int) ( $original_height * $scaling_factor ); | |
| 446 | - | |
| 447 | - $image_editor->resize( $new_width, $new_height, true ); | |
| 448 | - | |
| 449 | - $file_extension = pathinfo( $original_url, PATHINFO_EXTENSION ); | |
| 450 | - $temp_image = tempnam( sys_get_temp_dir(), 'resized_' ) . '.' . $file_extension; | |
| 451 | - | |
| 452 | - $image_editor->save( $temp_image ); | |
| 453 | - return $temp_image; | |
| 454 | - } catch ( \Exception $e ) { | |
| 455 | - return $original_url; | |
| 456 | - } | |
| 457 | - } | |
| 458 | - | |
| 459 | - public function get_unify_product_images( $image_data, $context, $request_ids ) { | |
| 460 | - $image_file = get_attached_file( $image_data['attachment_id'] ); | |
| 461 | - | |
| 462 | - if ( ! $image_file ) { | |
| 463 | - throw new \Exception( 'Image file not found' ); | |
| 464 | - } | |
| 465 | - | |
| 466 | - $final_path = $this->resizeImageIfNeeded( $image_file ); | |
| 467 | - | |
| 468 | - $result = $this->ai_request( | |
| 469 | - 'POST', | |
| 470 | - 'image/image-to-image/unify-product-images', | |
| 471 | - [ | |
| 472 | - 'aspectRatio' => $image_data['promptSettings'][ self::ASPECT_RATIO ], | |
| 473 | - 'backgroundColor' => $image_data['promptSettings'][ self::IMAGE_BACKGROUND_COLOR ], | |
| 474 | - 'featureIdentifier' => $image_data['featureIdentifier'], | |
| 475 | - 'context' => wp_json_encode( $context ), | |
| 476 | - 'ids' => $request_ids, | |
| 477 | - 'api_version' => ELEMENTOR_VERSION, | |
| 478 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 479 | - ], | |
| 480 | - $final_path, | |
| 481 | - 'image' | |
| 482 | - ); | |
| 483 | - | |
| 484 | - if ( $image_file !== $final_path ) { | |
| 485 | - unlink( $final_path ); | |
| 486 | - } | |
| 487 | - | |
| 488 | - return $result; | |
| 489 | - } | |
| 490 | - | |
| 491 | 322 | /** |
| 492 | - * Get Image To Image Upscale get_image_to_image_upscale | |
| 323 | + * get_image_to_image_upscale | |
| 324 | + * @param $image_data | |
| 493 | 325 | * |
| 494 | - * @param $image_data | |
| 495 | - * @param $context | |
| 496 | - * @param $request_ids | |
| 497 | 326 | * @return mixed|\WP_Error |
| 498 | - * @throws \Exception If image file not found. | |
| 327 | + * @throws \Exception | |
| 499 | 328 | */ |
| 500 | 329 | public function get_image_to_image_upscale( $image_data, $context, $request_ids ) { |
| 501 | 330 | $image_file = get_attached_file( $image_data['attachment_id'] ); |
| 502 | 331 | |
| @@ -521,15 +350,13 @@ | ||
| 521 | 350 | return $result; |
| 522 | 351 | } |
| 523 | 352 | |
| 524 | 353 | /** |
| 525 | - * Get Image To Image Remove Background get_image_to_image_remove_background | |
| 354 | + * get_image_to_image_remove_background | |
| 355 | + * @param $image_data | |
| 526 | 356 | * |
| 527 | - * @param $image_data | |
| 528 | - * @param $context | |
| 529 | - * @param $request_ids | |
| 530 | 357 | * @return mixed|\WP_Error |
| 531 | - * @throws \Exception If image file not found. | |
| 358 | + * @throws \Exception | |
| 532 | 359 | */ |
| 533 | 360 | public function get_image_to_image_remove_background( $image_data, $context, $request_ids ) { |
| 534 | 361 | $image_file = get_attached_file( $image_data['attachment_id'] ); |
| 535 | 362 | |
| @@ -553,15 +380,13 @@ | ||
| 553 | 380 | return $result; |
| 554 | 381 | } |
| 555 | 382 | |
| 556 | 383 | /** |
| 557 | - * Get Image To Image Remove Text get_image_to_image_remove_text | |
| 384 | + * get_image_to_image_remove_text | |
| 385 | + * @param $image_data | |
| 558 | 386 | * |
| 559 | - * @param $image_data | |
| 560 | - * @param $context | |
| 561 | - * @param $request_ids | |
| 562 | 387 | * @return mixed|\WP_Error |
| 563 | - * @throws \Exception If image file not found. | |
| 388 | + * @throws \Exception | |
| 564 | 389 | */ |
| 565 | 390 | public function get_image_to_image_replace_background( $image_data, $context, $request_ids ) { |
| 566 | 391 | $image_file = get_attached_file( $image_data['attachment_id'] ); |
| 567 | 392 | |
| @@ -586,11 +411,10 @@ | ||
| 586 | 411 | return $result; |
| 587 | 412 | } |
| 588 | 413 | |
| 589 | 414 | /** |
| 590 | - * Store Temp File store_temp_file | |
| 415 | + * store_temp_file | |
| 591 | 416 | * used to store a temp file for the AI request and deletes it once the request is done |
| 592 | - * | |
| 593 | 417 | * @param $file_content |
| 594 | 418 | * @param $file_ext |
| 595 | 419 | * |
| 596 | 420 | * @return string |
| @@ -607,15 +431,13 @@ | ||
| 607 | 431 | return $temp_file; |
| 608 | 432 | } |
| 609 | 433 | |
| 610 | 434 | /** |
| 611 | - * Get Image To Image Out Painting get_image_to_image_out_painting | |
| 435 | + * get_image_to_image_out_painting | |
| 436 | + * @param $image_data | |
| 612 | 437 | * |
| 613 | - * @param $image_data | |
| 614 | - * @param $context | |
| 615 | - * @param $request_ids | |
| 616 | 438 | * @return mixed|\WP_Error |
| 617 | - * @throws \Exception If image file not found. | |
| 439 | + * @throws \Exception | |
| 618 | 440 | */ |
| 619 | 441 | public function get_image_to_image_out_painting( $image_data, $context, $request_ids ) { |
| 620 | 442 | $img_content = str_replace( ' ', '+', $image_data['mask'] ); |
| 621 | 443 | $img_content = substr( $img_content, strpos( $img_content, ',' ) + 1 ); |
| @@ -629,16 +451,14 @@ | ||
| 629 | 451 | $result = $this->ai_request( |
| 630 | 452 | 'POST', |
| 631 | 453 | 'image/image-to-image/outpainting', |
| 632 | 454 | [ |
| 455 | + self::PROMPT => $image_data[ self::PROMPT ], | |
| 456 | + self::IMAGE_TYPE => '', | |
| 633 | 457 | 'context' => wp_json_encode( $context ), |
| 634 | 458 | 'ids' => $request_ids, |
| 635 | 459 | 'api_version' => ELEMENTOR_VERSION, |
| 636 | 460 | 'site_lang' => get_bloginfo( 'language' ), |
| 637 | - 'size' => wp_json_encode( $image_data['size'] ), | |
| 638 | - 'position' => wp_json_encode( $image_data['position'] ), | |
| 639 | - 'image_base64' => $image_data['image_base64'], | |
| 640 | - $image_data['image'], | |
| 641 | 461 | ], |
| 642 | 462 | [ |
| 643 | 463 | [ |
| 644 | 464 | 'name' => 'image', |
| @@ -651,15 +471,13 @@ | ||
| 651 | 471 | return $result; |
| 652 | 472 | } |
| 653 | 473 | |
| 654 | 474 | /** |
| 655 | - * Get Image To Image Mask get_image_to_image_mask | |
| 475 | + * get_image_to_image_mask | |
| 476 | + * @param $image_data | |
| 656 | 477 | * |
| 657 | - * @param $image_data | |
| 658 | - * @param $context | |
| 659 | - * @param $request_ids | |
| 660 | 478 | * @return mixed|\WP_Error |
| 661 | - * @throws \Exception If image file not found. | |
| 479 | + * @throws \Exception | |
| 662 | 480 | */ |
| 663 | 481 | public function get_image_to_image_mask( $image_data, $context, $request_ids ) { |
| 664 | 482 | $image_file = get_attached_file( $image_data['attachment_id'] ); |
| 665 | 483 | $mask_file = $this->store_temp_file( $image_data['mask'], '.svg' ); |
| @@ -676,13 +494,14 @@ | ||
| 676 | 494 | 'POST', |
| 677 | 495 | 'image/image-to-image/inpainting', |
| 678 | 496 | [ |
| 679 | 497 | self::PROMPT => $image_data[ self::PROMPT ], |
| 498 | + self::IMAGE_TYPE => $image_data['promptSettings'][ self::IMAGE_TYPE ] . '/' . $image_data['promptSettings'][ self::STYLE_PRESET ], | |
| 499 | + self::IMAGE_STRENGTH => $image_data['promptSettings'][ self::IMAGE_STRENGTH ], | |
| 680 | 500 | 'context' => wp_json_encode( $context ), |
| 681 | 501 | 'ids' => $request_ids, |
| 682 | 502 | 'api_version' => ELEMENTOR_VERSION, |
| 683 | 503 | 'site_lang' => get_bloginfo( 'language' ), |
| 684 | - 'image_base64' => $image_data['image_base64'], | |
| 685 | 504 | ], |
| 686 | 505 | [ |
| 687 | 506 | [ |
| 688 | 507 | 'name' => 'image', |
| @@ -698,48 +517,9 @@ | ||
| 698 | 517 | ); |
| 699 | 518 | |
| 700 | 519 | return $result; |
| 701 | 520 | } |
| 702 | - public function get_image_to_image_mask_cleanup( $image_data, $context, $request_ids ) { | |
| 703 | - $image_file = get_attached_file( $image_data['attachment_id'] ); | |
| 704 | - $mask_file = $this->store_temp_file( $image_data['mask'], '.svg' ); | |
| 705 | 521 | |
| 706 | - if ( ! $image_file ) { | |
| 707 | - throw new \Exception( 'Image file not found' ); | |
| 708 | - } | |
| 709 | - | |
| 710 | - if ( ! $mask_file ) { | |
| 711 | - throw new \Exception( 'Mask file not found' ); | |
| 712 | - } | |
| 713 | - | |
| 714 | - $result = $this->ai_request( | |
| 715 | - 'POST', | |
| 716 | - 'image/image-to-image/cleanup', | |
| 717 | - [ | |
| 718 | - self::PROMPT => $image_data[ self::PROMPT ], | |
| 719 | - 'context' => wp_json_encode( $context ), | |
| 720 | - 'ids' => $request_ids, | |
| 721 | - 'api_version' => ELEMENTOR_VERSION, | |
| 722 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 723 | - 'image_base64' => $image_data['image_base64'], | |
| 724 | - ], | |
| 725 | - [ | |
| 726 | - [ | |
| 727 | - 'name' => 'image', | |
| 728 | - 'type' => 'image', | |
| 729 | - 'path' => $image_file, | |
| 730 | - ], | |
| 731 | - [ | |
| 732 | - 'name' => 'mask_image', | |
| 733 | - 'type' => 'image/svg+xml', | |
| 734 | - 'path' => $mask_file, | |
| 735 | - ], | |
| 736 | - ] | |
| 737 | - ); | |
| 738 | - | |
| 739 | - return $result; | |
| 740 | - } | |
| 741 | - | |
| 742 | 522 | public function generate_layout( $data, $context ) { |
| 743 | 523 | $endpoint = 'generate/layout'; |
| 744 | 524 | |
| 745 | 525 | $body = [ |
| @@ -771,9 +551,8 @@ | ||
| 771 | 551 | |
| 772 | 552 | $html = wp_json_encode( $attachment['content'] ); |
| 773 | 553 | |
| 774 | 554 | $body['html'] = $html; |
| 775 | - $body['htmlFetchedUrl'] = $attachment['label']; | |
| 776 | 555 | |
| 777 | 556 | break; |
| 778 | 557 | } |
| 779 | 558 | } |
| @@ -778,28 +557,15 @@ | ||
| 778 | 557 | } |
| 779 | 558 | } |
| 780 | 559 | |
| 781 | 560 | $context['currentContext'] = $data['currentContext']; |
| 782 | - $context['features'] = [ | |
| 783 | - 'supportedFeatures' => [ 'Taxonomy' ], | |
| 784 | - ]; | |
| 785 | 561 | |
| 786 | 562 | if ( ElementorUtils::has_pro() ) { |
| 787 | - $context['features']['subscriptions'] = [ 'Pro' ]; | |
| 563 | + $context['features'] = [ | |
| 564 | + 'subscriptions' => [ 'Pro' ], | |
| 565 | + ]; | |
| 788 | 566 | } |
| 789 | 567 | |
| 790 | - if ( Plugin::instance()->experiments->is_feature_active( 'container' ) ) { | |
| 791 | - $context['features']['supportedFeatures'][] = 'Nested'; | |
| 792 | - } | |
| 793 | - | |
| 794 | - if ( Plugin::instance()->experiments->get_active_features()['mega-menu'] ) { | |
| 795 | - $context['features']['supportedFeatures'][] = 'MegaMenu'; | |
| 796 | - } | |
| 797 | - | |
| 798 | - if ( class_exists( 'WC' ) ) { | |
| 799 | - $context['features']['supportedFeatures'][] = 'WooCommerce'; | |
| 800 | - } | |
| 801 | - | |
| 802 | 568 | $metadata = [ |
| 803 | 569 | 'context' => $context, |
| 804 | 570 | 'api_version' => ELEMENTOR_VERSION, |
| 805 | 571 | 'site_lang' => get_bloginfo( 'language' ), |
| @@ -834,12 +600,9 @@ | ||
| 834 | 600 | 'enhance_type' => $enhance_type, |
| 835 | 601 | 'context' => wp_json_encode( $context ), |
| 836 | 602 | 'api_version' => ELEMENTOR_VERSION, |
| 837 | 603 | 'site_lang' => get_bloginfo( 'language' ), |
| 838 | - ], | |
| 839 | - false, | |
| 840 | - '', | |
| 841 | - 'json' | |
| 604 | + ] | |
| 842 | 605 | ); |
| 843 | 606 | } |
| 844 | 607 | |
| 845 | 608 | public function get_history_by_type( $type, $page, $limit, $context = [] ) { |
| @@ -872,34 +635,15 @@ | ||
| 872 | 635 | ); |
| 873 | 636 | } |
| 874 | 637 | |
| 875 | 638 | public function toggle_favorite_history_item( $id, $context = [] ) { |
| 876 | - $sanitized_id = str_replace( '%', '%%', $id ); | |
| 877 | 639 | return $this->ai_request( |
| 878 | - 'POST', sprintf( 'history/%s/favorite', $sanitized_id ), | |
| 640 | + 'POST', sprintf( 'history/%s/favorite', $id ), | |
| 879 | 641 | [ |
| 880 | 642 | 'context' => wp_json_encode( $context ), |
| 881 | 643 | 'api_version' => ELEMENTOR_VERSION, |
| 882 | 644 | 'site_lang' => get_bloginfo( 'language' ), |
| 883 | 645 | ] |
| 884 | - ); | |
| 885 | - } | |
| 886 | - | |
| 887 | - public function get_animation( $data, $context, $request_ids ) { | |
| 888 | - return $this->ai_request( | |
| 889 | - 'POST', | |
| 890 | - 'text/get-motion-effect', | |
| 891 | - [ | |
| 892 | - 'prompt' => $data['payload']['prompt'], | |
| 893 | - 'motionEffectType' => $data['payload']['motionEffectType'], | |
| 894 | - 'context' => wp_json_encode( $context ), | |
| 895 | - 'ids' => $request_ids, | |
| 896 | - 'api_version' => ELEMENTOR_VERSION, | |
| 897 | - 'site_lang' => get_bloginfo( 'language' ), | |
| 898 | - ], | |
| 899 | - false, | |
| 900 | - '', | |
| 901 | - 'json' | |
| 902 | 646 | ); |
| 903 | 647 | } |
| 904 | 648 | |
| 905 | 649 | protected function init() {} |