PluginProbe ʕ •ᴥ•ʔ
Kubio AI Page Builder / 2.8.0
Kubio AI Page Builder v2.8.0
2.8.3 2.8.2 2.8.1 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.2.1 1.2.2 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.9.0 2.0.0 2.1.1 2.1.2 2.1.3 2.2.0 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.5 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.6.2 2.6.3 2.6.5 2.6.6 2.6.7 2.7.0 2.7.1 2.7.2 2.7.3 2.8.0
kubio / lib / AI / PostImage.php
kubio / lib / AI Last commit date
Blog 9 months ago SDApi 1 year ago Shop 9 months ago admin-tab 1 year ago filters 1 year ago PostImage.php 1 year ago api.php 9 months ago index.php 1 year ago utils.php 1 year ago
PostImage.php
64 lines
1 <?php
2 namespace Kubio\AI;
3
4 use IlluminateAgnostic\Arr\Support\Arr;
5 use Kubio\Core\Importer;
6
7 class PostImage {
8
9 static $images_by_keword = array();
10 static $used_images = array();
11 public static function get_featured_image_from_keywords( $keywords ) {
12 $image_url = self::get_image_from_api( $keywords );
13
14 if ( $image_url ) {
15 $image = Importer::importRemoteFile(
16 $image_url
17 );
18
19 if ( $image ) {
20 return $image['id'];
21 }
22 }
23
24 return false;
25 }
26
27 private static function get_image_from_api( $keywords ) {
28 $cached_images = Arr::get( static::$images_by_keword, $keywords );
29 if ( $cached_images && is_array( $cached_images ) && count( $cached_images ) > 0 ) {
30 $next_image = array_shift( $cached_images );
31 while ( in_array( $next_image, static::$used_images ) && count( $cached_images ) > 0 ) {
32 $next_image = array_shift( $cached_images );
33 }
34 Arr::set( static::$images_by_keword, $keywords, $cached_images );
35 return $next_image;
36 }
37 $per_page = 5;
38 $image = kubio_ai_call_api(
39 'v1/search-media',
40 array(
41 'type' => 'image',
42 'search' => $keywords,
43 'per_page' => $per_page,
44 'orientation' => 'landscape',
45 'size' => 'small',
46 'width' => '1152',
47 'height' => '896',
48 )
49 );
50 $images = Arr::get( $image, 'content.items', array() );
51 $next_image = null;
52 if ( is_array( $images ) && count( $images ) > 0 ) {
53 $next_image = array_shift( $images );
54 while ( in_array( $next_image, static::$used_images ) && count( $images ) > 0 ) {
55 $next_image = array_shift( $images );
56 }
57 static::$used_images[] = $next_image;
58 Arr::set( static::$images_by_keword, $keywords, $images );
59 }
60
61 return $next_image;
62 }
63 }
64