Plugin Directory

Changeset 3109334


Ignore:
Timestamp:
06/28/2024 03:08:08 PM (21 months ago)
Author:
allimages
Message:

v1.0.1

Location:
all-images-ai/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • all-images-ai/trunk/admin/class-all-images-ai-admin.php

    r3100802 r3109334  
    139139            10
    140140        );
     141    }
     142
     143    public function get_screen_options()
     144    {
     145        $screen = get_current_screen();
     146
     147        if (!is_object($screen) || 'all-images_page_all-images-ai-generations' !== $screen->id) {
     148            return;
     149        }
     150
     151        $option_name = 'per_page';
     152        add_screen_option($option_name);
     153    }
     154
     155    public function set_options($status, $option, $value)
     156    {
     157        if (isset($_POST['screenoptionnonce']) && wp_verify_nonce(
     158                sanitize_text_field(wp_unslash($_POST['screenoptionnonce'])),
     159                'screen-options-nonce'
     160            )) {
     161            if ( 'all_images_page_all_images_ai_generations_per_page' === $option ) {
     162                $value = max(0, (int)$value);
     163            }
     164        }
     165
     166        return $value;
    141167    }
    142168
     
    186212            )
    187213        );
     214
     215        add_settings_field(
     216            'all_images_image_format',
     217            __('Image format', 'all-images-ai'),
     218            array($this, 'display_select_format'),
     219            $page,
     220            'all_images_settings_general',
     221            array(
     222                'name'  => 'all_images_image_format',
     223                'value' => (empty($this->settings['all_images_image_format']))
     224                    ? '' : $this->settings['all_images_image_format'],
     225                'hint' => '(default 3:2)'
     226            )
     227        );
    188228        add_settings_field(
    189229            'all_images_use_post_title_as_alt',
     
    195235                'type'  => 'checkbox',
    196236                'name'  => 'all_images_use_post_title_as_alt',
    197                 'placeholder'  => __('eg: 1200px', 'all-images-ai'),
    198237                'checked' => (!isset($this->settings['all_images_use_post_title_as_alt']))
    199238                    ? false : true
     239            )
     240        );
     241        add_settings_field(
     242            'all_images_max_additional_prompt',
     243            __('Additional prompt, added at the beginning', 'all-images-ai'),
     244            array($this, 'display_form_input'),
     245            $page,
     246            'all_images_settings_general',
     247            array(
     248                'type'  => 'textarea',
     249                'name'  => 'all_images_max_additional_prompt',
     250                'placeholder'  => '',
     251                'value' => (!empty($this->settings['all_images_max_additional_prompt']))
     252                    ? trim($this->settings['all_images_max_additional_prompt']) : ''
    200253            )
    201254        );
     
    482535
    483536        switch ($args['type']) {
     537            case 'textarea':
     538?>
     539                <textarea name="<?php echo esc_attr($name); ?>" placeholder="<?php echo esc_attr($args['placeholder']); ?>"><?php if ($args['value']) {
     540                    echo esc_attr($args['value']);
     541                } ?></textarea>
     542                <?php if (isset($args['hint'])) {
     543                echo wp_kses_post($args['hint']);
     544                } ?>
     545            <?php break;
    484546            case 'text':
    485547            case 'number':
     
    501563    }
    502564
     565    public function display_select_format($args)
     566    {
     567        $options = [
     568            '3:2' => '3:2 (1344x896)',
     569            '1:1' => '1:1 (1024x1024)',
     570            '4:7' => '4:7 (832x1456)',
     571            '5:4' => '5:4 (1200x960)',
     572            '2:3' => '2:3 (896x1344)',
     573            '7:4' => '7:4 (1456x832)',
     574            '9:16' => '9:16 (744x1304)',
     575            '16:9' => '16:9 (1304x744)',
     576        ]
     577        ?>
     578        <select name="<?php echo esc_attr('all-images-ai-settings[' . $args['name'] . ']'); ?>">
     579            <option value=""><?php esc_html_e('Select an image format', 'all-images-ai'); ?></option>
     580            <?php foreach ($options as $value => $label) { ?>
     581                <option value="<?php esc_attr_e($value); ?>"<?php echo ( $args['value'] === $value ? ' selected' : '' ); ?>><?php echo esc_html($label); ?></option>
     582            <?php } ?>
     583        </select>
     584        <?php if (isset($args['hint'])) {
     585            echo wp_kses_post($args['hint']);
     586        }
     587    }
     588
    503589    public function include_main_partial()
    504590    {
     
    511597        if (!empty($this->api_key)) {
    512598            $posts = isset($_GET['posts']) ? array_map('intval', $_GET['posts']) : [];
     599            if (!empty($posts)) {
     600                $posts_with_generation_ids = $this->get_posts_with_generation($posts);
     601                $elligible_ids = array_diff($posts, $posts_with_generation_ids);
     602
     603                $label = sprintf(
     604                    _n(
     605                        '%s post selected',
     606                        '%s posts selected',
     607                        max(count($elligible_ids), 1),
     608                        'all-images-ai'
     609                    ),
     610                    number_format_i18n(count($elligible_ids))
     611                );
     612
     613                $label_count = count($posts_with_generation_ids) > 0 ? sprintf(
     614                    '%s (%s)',
     615                    $label,
     616                    sprintf(
     617                        _n(
     618                            '%s post already in progress',
     619                            '%s posts already in progress',
     620                            max(count($posts_with_generation_ids), 1),
     621                            'all-images-ai'
     622                        ),
     623                        number_format_i18n(count($posts_with_generation_ids))
     624                    )
     625                ) : $label;
     626            }
    513627
    514628            add_action('admin_notices', array($this, 'display_credits'));
     
    716830    }
    717831
     832    public function get_posts_with_generation($ids)
     833    {
     834        $d = implode(
     835            ',',
     836            array_fill(0, count($ids), '%d')
     837        );
     838
     839        $query = $this->wpdb->prepare(<<<SQL
     840SELECT DISTINCT post_id
     841FROM {$this->tablename}
     842WHERE post_id IN ($d)
     843  AND status NOT IN ('print.failed', 'print.completed');
     844SQL,
     845            $ids
     846        );
     847
     848        $result = $this->wpdb->get_col($query);
     849
     850        return is_array($result) ? array_map('intval', $result) : [];
     851    }
     852
    718853    public function get_selected_posts()
    719854    {
     
    733868
    734869        $ids = $this->select_posts_for_generation($params);
     870        $progress_ids = $this->get_posts_with_generation($ids);
     871        $elligible_ids = array_diff($ids, $progress_ids);
     872
     873        $label = sprintf(
     874            _n(
     875                '%s post selected',
     876                '%s posts selected',
     877                max(count($elligible_ids), 1),
     878                'all-images-ai'
     879            ),
     880            number_format_i18n(count($elligible_ids))
     881        );
    735882
    736883        wp_send_json_success(array(
    737             'post_ids' => $ids,
    738             'message' => sprintf(
    739                 _n('%s post selected', '%s posts selected', count($ids), 'all-images-ai'),
    740                 number_format_i18n(count($ids))
    741             ),
     884            'post_ids' => $elligible_ids,
     885            'message' => count($progress_ids) > 0 ? sprintf(
     886                '%s (%s)',
     887                $label,
     888                sprintf(
     889                    _n(
     890                        '%s post already in progress',
     891                        '%s posts already in progress',
     892                        max(count($progress_ids), 1),
     893                        'all-images-ai'
     894                    ),
     895                    number_format_i18n(count($progress_ids))
     896                )
     897            ) : $label,
    742898        ));
    743899    }
     
    8791035                );
    8801036            }
    881 
    882             update_option('all-images-ai-settings', $this->settings);
    883         }
     1037        }
     1038
     1039        update_option('all-images-ai-settings', $this->settings);
    8841040    }
    8851041
     
    9351091        foreach ($ids as $id) {
    9361092            $my_post = get_post($id);
     1093            $post_h2_indexes_asked = [];
    9371094
    9381095            foreach ($images as $image) {
     
    9411098                    'name' => $my_post->ID . ' - ' . $my_post->post_title,
    9421099                    'mode' => 'simple',
     1100                    'additionalPrompt' => ( !empty($this->settings['all_images_max_additional_prompt']) ? esc_html($this->settings['all_images_max_additional_prompt']) : '' ),
    9431101                    'optimizePrompt' => true,
    9441102                    'params' => array(
    9451103                        array(
    946                             'format' => '3:2'
     1104                            'name' => 'format',
     1105                            'value' => ( !empty($this->settings['all_images_image_format']) ? esc_html($this->settings['all_images_image_format']) : '3:2' )
    9471106                        )
    948                     )
     1107                    ),
     1108                    'prompt' => []
    9491109                );
    9501110
     1111                $params['prompt'][] = esc_html($my_post->post_title);
    9511112                switch ($image['prompt']) {
    9521113                    case 'post_title':
    953                         $params['prompt'] = esc_html($my_post->post_title);
     1114                        $params['prompt'][] = esc_html($my_post->post_title);
    9541115                        break;
    9551116                    case 'post_h1':
    9561117                        $title = $this->_getTextBetweenTags($my_post->post_content, 'h1');
    9571118                        if (!empty($title)) {
    958                             $params['prompt'] = esc_html($title);
     1119                            $params['prompt'][] = esc_html($title);
    9591120                        } else {
    960                             $params['prompt'] = esc_html($my_post->post_title);
     1121                            $params['prompt'][] = esc_html($my_post->post_title);
    9611122                        }
    9621123                        break;
    9631124                    case 'category':
    964                         $cat = get_the_category($my_post->ID)[0];
    965                         if ($cat->term_id == 1) {
    966                             $params['prompt'] = esc_html($my_post->post_title);
     1125                        $categories = get_the_category($my_post->ID);
     1126                        if (isset($categories[0]) && $categories[0]->term_id !== 1) {
     1127                            $params['prompt'][] = esc_html($categories[0]->name);
    9671128                        } else {
    968                             $params['prompt'] = esc_html($cat->name);
     1129                            $params['prompt'][] = esc_html($my_post->post_title);
    9691130                        }
    9701131                        break;
    9711132                }
    9721133
    973                 if (isset($image['position']) && $image['position'] == 'all_h2') {
    974                     // CREATE GENERATION FOR EVERY H2
     1134                if (isset($image['position']) && in_array($image['position'], ['first_h2', 'last_h2', 'all_h2', 'random_h2'])) {
     1135                    // CREATE GENERATION FOR H2
    9751136                    $doc = new toolsDomDocument\SmartDOMDocument();
    9761137                    $doc->loadPartialHTML($my_post->post_content);
    9771138                    $h2s = $doc->getElementsByTagName('h2');
    978                     if ($h2s) {
    979                         foreach ($h2s as $i => $h2) {
    980 
    981                             if ($image['prompt'] == 'corresponding_h2') {
    982                                 $params['prompt'] = $this->_getTextBetweenTags($my_post->post_content, 'h2', $i);
    983                             }
    984 
    985                             $return = $this->wpdb->insert(
    986                                 $this->tablename,
    987                                 array(
    988                                     'time' => date('Y-m-d H:i:s'),
    989                                     'post_id' => $my_post->ID,
    990                                     'type' => $image['type'],
    991                                     'position' => 'h2_' . $i,
    992                                     'picking' => $image['picking'],
    993                                     'size' => isset($image['size']) ? $image['size'] : null,
    994                                     'prompt' => $params['prompt'],
    995                                 )
    996                             );
    997 
    998                             if ($return === false) {
    999                                 $this->errors[] = sprintf(__('Cannot insert row for post id %d and h2 index %d', 'all-images-ai'), $my_post->ID, $i);
    1000                                 continue;
    1001                             }
    1002 
    1003                             $id = (int) $this->wpdb->insert_id;
    1004                             if ($generation_id = $this->_query_generation($params)) {
    1005                                 $this->wpdb->update($this->tablename, array(
    1006                                     'generation_id' => sanitize_text_field($generation_id),
    1007                                     'status' => 'created',
    1008                                 ), array(
    1009                                     'id' => $id,
    1010                                 ));
    1011 
    1012                                 $generation_ids[] = $generation_id;
    1013                             }
     1139                    $random_index = -1;
     1140
     1141                    if ($h2s->length === 0) {
     1142                        $this->errors[] = sprintf(__('No h2 found for post id %d', 'all-images-ai'), $my_post->ID);
     1143                        continue;
     1144                    }
     1145
     1146                    if ($image['position'] === 'random_h2') {
     1147                        $indexes = array_diff(range(0, $h2s->length-1), $post_h2_indexes_asked);
     1148                        $random_index = array_rand($indexes);
     1149                    }
     1150
     1151                    foreach ($h2s as $i => $h2) {
     1152                        switch ($image['position']) {
     1153                            case 'first_h2':
     1154                                if ($i > 0) {
     1155                                    break;
     1156                                }
     1157                                break;
     1158                            case 'last_h2':
     1159                                if ($i < $h2s->length - 1) {
     1160                                    continue 2;
     1161                                }
     1162                                break;
     1163                            case 'random_h2':
     1164                                if ($i !== $random_index) {
     1165                                    continue 2;
     1166                                }
     1167                            break;
     1168                        }
     1169
     1170                        if (in_array($i, $post_h2_indexes_asked, true)) {
     1171                            $this->errors[] = sprintf(__('h2 index %d already processed for post id %d', 'all-images-ai'), $i, $my_post->ID);
     1172                            continue;
     1173                        }
     1174
     1175                        $post_h2_indexes_asked[] = $i;
     1176
     1177                        if ($image['prompt'] == 'corresponding_h2') {
     1178                            $params['prompt'][] = $this->_getTextBetweenTags($my_post->post_content, 'h2', $i);
     1179                        }
     1180
     1181                        $params['prompt'] = sprintf('###%s###', implode('###', $params['prompt']));
     1182
     1183                        $return = $this->wpdb->insert(
     1184                            $this->tablename,
     1185                            array(
     1186                                'time' => date('Y-m-d H:i:s'),
     1187                                'post_id' => $my_post->ID,
     1188                                'type' => $image['type'],
     1189                                'position' => 'h2_' . $i,
     1190                                'picking' => $image['picking'],
     1191                                'size' => isset($image['size']) ? $image['size'] : null,
     1192                                'prompt' => $params['prompt'],
     1193                            )
     1194                        );
     1195
     1196                        if ($return === false) {
     1197                            $this->errors[] = sprintf(__('Cannot insert row for post id %d and h2 index %d', 'all-images-ai'), $my_post->ID, $i);
     1198                            continue;
     1199                        }
     1200
     1201                        $insert_id = (int) $this->wpdb->insert_id;
     1202                        if ($generation_id = $this->_query_generation($params)) {
     1203                            $this->wpdb->update($this->tablename, array(
     1204                                'generation_id' => sanitize_text_field($generation_id),
     1205                                'status' => 'created',
     1206                            ), array(
     1207                                'id' => $insert_id,
     1208                            ));
     1209
     1210                            $generation_ids[] = $generation_id;
    10141211                        }
    10151212                    }
    10161213                } else {
     1214
     1215                    $params['prompt'] = sprintf('###%s###', implode('###', $params['prompt']));
    10171216
    10181217                    $return = $this->wpdb->insert(
     
    10341233                    }
    10351234
    1036                     $id = (int) $this->wpdb->insert_id;
     1235                    $insert_id = (int) $this->wpdb->insert_id;
    10371236                    if ($generation_id = $this->_query_generation($params)) {
    10381237                        $this->wpdb->update($this->tablename, array(
     
    10401239                            'status' => 'created',
    10411240                        ), array(
    1042                             'id' => $id,
     1241                            'id' => $insert_id,
    10431242                        ));
    10441243
     
    11301329    {
    11311330        if (isset($_GET['image-ai']) && check_admin_referer('trash-image-ai-' . $_GET['image-ai'])) {
    1132             $this->wpdb->delete($this->tablename, array('id' => $_GET['image-ai']));
     1331            $this->delete_image_by_id($_GET['image-ai']);
    11331332            wp_redirect(add_query_arg('paged', isset($_GET['paged']) ? absint($_GET['paged']) : 1, admin_url('/admin.php?page=all-images-ai-generations')));
    11341333            exit;
    11351334        }
     1335
     1336        $action = $this->current_action();
     1337
     1338        if (empty($action)) {
     1339            return;
     1340        }
     1341
     1342        $ids = isset($_REQUEST['element']) ? wp_parse_id_list(wp_unslash($_REQUEST['element'])) : array();
     1343
     1344        if (empty($ids)) {
     1345            return;
     1346        }
     1347
     1348        check_admin_referer('bulk-all-images_page_all-images-ai-generations');
     1349
     1350        switch ($action) {
     1351            case 'delete':
     1352                list($count, $failures) = $this->delete_image_by_ids($ids);
     1353
     1354                if (!function_exists('add_settings_error')) {
     1355                    require_once ABSPATH.'wp-admin/includes/template.php';
     1356                }
     1357
     1358                if ($failures) {
     1359                    add_settings_error(
     1360                        'all-images-ai',
     1361                        'bulk_action',
     1362                        sprintf(
     1363                            _n(
     1364                                '%d image generation failed to delete.',
     1365                                '%d images generations failed to delete.',
     1366                                $failures,
     1367                                'all-images-ai'
     1368                            ),
     1369                            $failures
     1370                        )
     1371                    );
     1372                }
     1373
     1374                if ($count) {
     1375                    add_settings_error(
     1376                        'all-images-ai',
     1377                        'bulk_action',
     1378                        sprintf(
     1379                            _n(
     1380                                '%d image generation deleted successfully.',
     1381                                '%d images generations deleted successfully.',
     1382                                $count,
     1383                                'all-images-ai'
     1384                            ),
     1385                            $count
     1386                        ),
     1387                        'success'
     1388                    );
     1389                }
     1390
     1391                break;
     1392        }
     1393    }
     1394
     1395    private function delete_image_by_id($id)
     1396    {
     1397        $query = $this->wpdb->prepare("SELECT generation_id FROM {$this->tablename} WHERE id = %d", (int)$id);
     1398        $gen = $this->wpdb->get_row($query);
     1399
     1400        if (!empty($gen->generation_id)) {
     1401            $this->_send_request('DELETE', '/image-generations', array(
     1402                'body' => json_encode([
     1403                    'printIds' => [$gen->generation_id]
     1404                ]),
     1405            ));
     1406        }
     1407
     1408        return $this->wpdb->delete($this->tablename, array('id' => (int)$id));
     1409    }
     1410
     1411    private function delete_image_by_ids($ids)
     1412    {
     1413        $d = implode(
     1414            ',',
     1415            array_fill(0, count($ids), '%d')
     1416        );
     1417
     1418        $query = $this->wpdb->prepare(<<<SQL
     1419SELECT DISTINCT id, generation_id
     1420FROM {$this->tablename}
     1421WHERE id IN ($d)
     1422  AND generation_id IS NOT NULL;
     1423SQL,
     1424            $ids
     1425        );
     1426
     1427        $result = $this->wpdb->get_results($query, ARRAY_A);
     1428
     1429        $generation_id_by_id = [];
     1430        foreach ($result as $row) {
     1431            $generation_id_by_id[$row['id']] = $row['generation_id'];
     1432        }
     1433
     1434        $count = $failures = 0;
     1435        $generation_to_delete = [];
     1436        foreach($ids as $id) {
     1437            if ($this->wpdb->delete($this->tablename, array('id' => (int)$id))) {
     1438                $count++;
     1439                if (!empty($generation_id_by_id[$id])) {
     1440                    $generation_to_delete[] = $generation_id_by_id[$id];
     1441                }
     1442            } else {
     1443                $failures++;
     1444            }
     1445        }
     1446
     1447        if (!empty($generation_to_delete)) {
     1448            $this->_send_request('DELETE', '/image-generations', array(
     1449                'body' => json_encode([
     1450                    'printIds' => $generation_to_delete
     1451                ]),
     1452            ));
     1453        }
     1454
     1455        return [$count, $failures];
     1456    }
     1457
     1458    public function current_action() {
     1459        if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) ) {
     1460            return false;
     1461        }
     1462
     1463        if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] ) {
     1464            return $_REQUEST['action'];
     1465        }
     1466
     1467        return false;
    11361468    }
    11371469
     
    11391471    {
    11401472        global $post;
    1141         $link = esc_url(add_query_arg('posts', array($post->ID), admin_url('admin.php?page=all-images-ai')));
    1142         $actions['generate-image'] = "<a href=\"$link\">" . esc_html__('Generate image', 'all-images-ai') . "</a>";
     1473        $progress_ids = $this->get_posts_with_generation(array($post->ID));
     1474
     1475        if (empty($progress_ids)) {
     1476            $link = esc_url(add_query_arg('posts', array($post->ID), admin_url('admin.php?page=all-images-ai')));
     1477            $actions['generate-image'] = "<a href=\"$link\">" . esc_html__('Generate image', 'all-images-ai') . "</a>";
     1478        }
    11431479
    11441480        return $actions;
     
    14931829                    $content = $img_html . $my_post->post_content;
    14941830                    break;
    1495                 case 'first_h2':
    1496                     $h2 = $doc->getElementsByTagName('h2')->item(0);
    1497                     $img = $doc->createElement("img", "");
    1498                     $img->setAttribute('src', $img_src);
    1499                     if (isset($metadata['alt_text'])) {
    1500                         $img->setAttribute('alt', $metadata['alt_text']);
    1501                     }
    1502                     $img->setAttribute('class', 'alignnone size-' . $gen->size . ' wp-image-' . $image_id);
    1503                     $img->setAttribute('data-generation-id', $gen->id);
    1504                     $h2->parentNode->insertBefore($img, $h2->nextSibling);
    1505                     $content = $doc->saveHTMLExact();
    1506                     break;
    1507                 case 'last_h2':
    1508                     $h2s = $doc->getElementsByTagName('h2');
    1509                     $h2 = $doc->getElementsByTagName('h2')->item($h2s->length - 1);
    1510                     $img = $doc->createElement("img", "");
    1511                     $img->setAttribute('src', $img_src);
    1512                     if (isset($metadata['alt_text'])) {
    1513                         $img->setAttribute('alt', $metadata['alt_text']);
    1514                     }
    1515                     $img->setAttribute('class', 'alignnone size-' . $gen->size . ' wp-image-' . $image_id);
    1516                     $img->setAttribute('data-generation-id', $gen->id);
    1517                     $h2->parentNode->insertBefore($img, $h2->nextSibling);
    1518                     $content = $doc->saveHTMLExact();
    1519                     break;
    1520                 case 'all_h2':
    1521                     $h2s = $doc->getElementsByTagName('h2');
    1522                     foreach ($h2s as $h2) {
    1523                         $img = $doc->createElement("img", "");
    1524                         $img->setAttribute('src', $img_src);
    1525                         if (isset($metadata['alt_text'])) {
    1526                             $img->setAttribute('alt', $metadata['alt_text']);
    1527                         }
    1528                         $img->setAttribute('class', 'alignnone size-' . $gen->size . ' wp-image-' . $image_id);
    1529                         $img->setAttribute('data-generation-id', $gen->id);
    1530                         $h2->parentNode->insertBefore($img, $h2->nextSibling);
    1531                     }
    1532                     $content = $doc->saveHTMLExact();
    1533                     break;
    1534                 case 'random_h2':
    1535                     $h2s = $doc->getElementsByTagName('h2');
    1536                     $h2 = $doc->getElementsByTagName('h2')->item(random_int(0, $h2s->length - 1));
    1537                     $img = $doc->createElement("img", "");
    1538                     $img->setAttribute('src', $img_src);
    1539                     if (isset($metadata['alt_text'])) {
    1540                         $img->setAttribute('alt', $metadata['alt_text']);
    1541                     }
    1542                     $img->setAttribute('class', 'alignnone size-' . $gen->size . ' wp-image-' . $image_id);
    1543                     $img->setAttribute('data-generation-id', $gen->id);
    1544                     $h2->parentNode->insertBefore($img, $h2->nextSibling);
    1545                     $content = $doc->saveHTMLExact();
    1546                     break;
    15471831                case strpos($gen->position, 'h2_') > -1:
    1548 
    15491832                    $arr = explode('_', $gen->position);
    15501833                    $h2 = $doc->getElementsByTagName('h2')->item($arr[1]);
     
    15931876
    15941877        $url = 'https://api.all-images.ai/v1' . $uri;
    1595         if ($method === 'POST') {
     1878        if (in_array($method, ['POST', 'PUT', 'DELETE'])) {
     1879            if ($method !== 'POST') {
     1880                $args['method'] = $method;
     1881            }
    15961882            $response = wp_remote_post($url, $args);
    15971883        } else {
     
    16081894                $date = new DateTime();
    16091895                $log = sprintf('%s - %s - %s - %s - %s', $date->format('Y-m-d H:i:s'), $method, $url, json_encode($args), wp_remote_retrieve_body($response));
    1610                 @file_put_contents($log_path . 'all-images-ai.log', $log, FILE_APPEND);
     1896                @file_put_contents($log_path . 'all-images-ai.log', $log."\n", FILE_APPEND);
    16111897            }
    16121898        }
  • all-images-ai/trunk/admin/css/all-images-ai-admin.css

    r3100802 r3109334  
    245245    vertical-align:middle;
    246246    font-size: 18px;
     247}
     248.strikethrough {
     249    text-decoration: line-through;
    247250}
    248251#collapse-accordions {
     
    284287}
    285288.all-images-image-wrapper.small-image img {
    286     max-width:12rem;
     289    width:105px;
    287290}
    288291.generation-row .all-images-image-wrapper {
  • all-images-ai/trunk/admin/js/all-images-ai-admin.js

    r3100802 r3109334  
    403403
    404404            // ON POSITION CHANGE OR ON IMAGE TYPE CHANGE
    405             let correspondingH2 = $('option[value="corresponding_h2"]').clone();
     405            let correspondingH2 = $('option[value="corresponding_h2"]').first().text();
    406406            $(document).on('change', '.position-field', function() {
    407407                $tr = $(this).closest('tr');
     
    412412                    default:
    413413                        if(!$tr.find('.prompt-field option[value="corresponding_h2"]').length) {
    414                             $tr.find('.prompt-field').append(correspondingH2);
     414                            $tr.find('.prompt-field').append($('<option>', {
     415                                value: 'corresponding_h2',
     416                                text: correspondingH2
     417                            }));
    415418                        }
    416419                        break;
  • all-images-ai/trunk/admin/partials/all-images-ai-admin-automatic-form.php

    r3100802 r3109334  
    1717            <button type="button" id="collapse-accordions" data-opened-text="<?php esc_attr_e('Collapse all tabs', 'all-images-ai'); ?>" class="button button-primary"><?php esc_html_e('Expand all tabs', 'all-images-ai'); ?></button>
    1818            <div class="accordion-wrapper">
    19                 <?php foreach($post_types as $i => $post_type) {
     19                <?php foreach($post_types as $post_type) {
    2020
    2121                    $hasData = (isset($this->settings['all_images_automatic']) && !empty($this->settings['all_images_automatic'][$post_type->name]));
     
    4646                                    <select id="allimages_<?php echo esc_attr($post_type->name); ?>_has_featured_image" name="allimages-auto[<?php echo esc_attr($post_type->name); ?>][allimages_has_featured_image]">
    4747                                        <option selected value=""><?php esc_html_e('Select an option', 'all-images-ai'); ?></option>
    48                                         <option value="true"><?php esc_html_e('With', 'all-images-ai'); ?></option>
    49                                         <option value="false"><?php esc_html_e('Without', 'all-images-ai'); ?></option>
     48                                        <option value="true" <?php if($values['allimages_has_featured_image'] == 'true') echo 'selected'; ?>><?php esc_html_e('With', 'all-images-ai'); ?></option>
     49                                        <option value="false" <?php if($values['allimages_has_featured_image'] == 'false') echo 'selected'; ?>><?php esc_html_e('Without', 'all-images-ai'); ?></option>
    5050                                    </select>
    5151
     
    5353                                    <select id="allimages_<?php echo esc_attr($post_type->name); ?>_has_content_image" name="allimages-auto[<?php echo esc_attr($post_type->name); ?>][allimages_has_content_image]">
    5454                                        <option selected value=""><?php esc_html_e('Select an option', 'all-images-ai'); ?></option>
    55                                         <option value="true"><?php esc_html_e('With', 'all-images-ai'); ?></option>
    56                                         <option value="false"><?php esc_html_e('Without', 'all-images-ai'); ?></option>
     55                                        <option value="true" <?php if($values['allimages_has_content_image'] == 'true') echo 'selected'; ?>><?php esc_html_e('With', 'all-images-ai'); ?></option>
     56                                        <option value="false" <?php if($values['allimages_has_content_image'] == 'false') echo 'selected'; ?>><?php esc_html_e('Without', 'all-images-ai'); ?></option>
    5757                                    </select>
    5858                                </td>
     
    9191                                </th>
    9292                            </tr>
    93                             <?php if($values) {
     93                            <?php if($values && !empty($values['images'])) {
    9494                                $images = json_decode($values['images'], true);
    9595                                foreach($images as $i => $image) { ?>
  • all-images-ai/trunk/admin/partials/all-images-ai-admin-bulk-form.php

    r3100802 r3109334  
    3030                        <?php foreach($posts as $p_id) { ?>
    3131                            <li>
    32                                 <?php printf('%d - %s', (int)$p_id, get_the_title((int)$p_id)); ?>
     32                                <span<?php echo ( !in_array($p_id, $elligible_ids) ? ' class="strikethrough"' : '' ); ?>><?php printf('%d - %s', (int)$p_id, get_the_title((int)$p_id)); ?></span>
     33                                <?php if( in_array($p_id, $elligible_ids)) { ?>
    3334                                <input type="hidden" name="posts[]" value="<?php echo esc_attr($p_id); ?>" />
     35                                <?php } ?>
    3436                            </li>
    3537                        <?php } ?>
     
    106108                <?php
    107109                if(count($posts)) {
    108                     printf(
    109                         _n('%s post selected', '%s posts selected', count($posts), 'all-images-ai'),
    110                         number_format_i18n(count($posts))
    111                     );
     110                    echo esc_html($label_count);
    112111                } ?>
    113112            </p>
  • all-images-ai/trunk/all-images-ai.php

    r3100802 r3109334  
    1717 * Plugin URI:        https://app.all-images.ai
    1818 * Description:       Find or generate the best images for your posts
    19  * Version:           1.0.0
     19 * Version:           1.0.1
    2020 * Author:            Weable
    2121 * Author URI:        https://weable.fr/
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define('ALL_IMAGES_AI_VERSION', '1.0.0');
     38define('ALL_IMAGES_AI_VERSION', '1.0.1');
    3939
    4040/**
  • all-images-ai/trunk/includes/class-all-images-ai.php

    r3100802 r3109334  
    158158        $this->loader->add_action('admin_menu', $plugin_admin, 'add_admin_menus');
    159159        $this->loader->add_action('admin_init', $plugin_admin, 'register_settings');
     160        $this->loader->add_action('load-all-images_page_all-images-ai-generations', $plugin_admin, 'get_screen_options');
     161        $this->loader->add_filter('set-screen-option', $plugin_admin, 'set_options', 10, 3);
    160162
    161163        $this->loader->add_action('admin_enqueue_scripts', $plugin_admin, 'enqueue_styles');
  • all-images-ai/trunk/readme.txt

    r3100802 r3109334  
    1 === All-Images.ai - IA Image Bank and Custom Image creation ===
     1=== All-Images.ai IA Image Bank and Custom Image creation ===
    22Contributors: allimages
    3 Tags: images, generated, ai, automatic, unsplash, pexel, pixabay, midjourney, api
     3Tags: image, generated, ai, automatic, unsplash, pexel, pixabay, midjourney, api, bank photos, stock photos
     4Requires PHP: 5.2.1
    45Requires at least: 5.0
    56Tested up to: 6.3.1
    6 Stable tag: 1.0.0
     7Stable tag: 1.0.1
    78License: GPLv2
    89
     
    1112== Description ==
    1213
    13 Effortlessly import images from All-Images, Unsplash, Pixabay, or Pexels directly to your WordPress website, all within the WordPress interface!
     14Transform your WordPress site into a visual masterpiece with the All Images plugin. Whether you're a blogger, a theme developer, or a digital marketer, All Images brings the power of visual enhancement right within your WordPress dashboard. This powerful plugin not only improves the aesthetic appeal of your site but also boosts engagement and SEO performance through its unique features.
    1415
    15 Automatic generation of custom images for your articles
     16= Core Services =
     171. **AI Image Bank + Free Stock Photo Image Bank:** Gain instant access to over 2 million+ unique images from our extensive library and popular free stock photo platforms like Unsplash, Pixabay, and Pexels. This service allows you to effortlessly add high-quality visuals to your website without leaving WordPress, ensuring your site always has fresh, captivating content.
     18
     192. **Custom Image Creation:** Tailor images to fit the essence of your content. This feature leverages AI to generate images based on specific needs, such as post titles, categories, or H2 tags. Each image is perfectly aligned with your content’s theme, enhancing the overall coherence and visual impact of your site.
     20
     213. **Automated Bulk Images:** Streamline the visual enhancement of your site with our AI that intelligently adds images to new posts, pages, or portfolios. This service automates the process of maintaining a visually appealing site by automatically populating it with relevant images, saving you time and effort.
     22
     23**/!\ Exclusive Image Usage:** The best part about using All Images is the exclusivity it offers. Once you download any image, it is removed from our accessible database, and **you become the sole holder of that image**, ensuring that no one else can purchase or use the same image on their website. This unique feature sets All Images apart, providing you with exclusive content that truly stands out. Moreover, Google values unique content, and using exclusive images can significantly enhance your SEO, helping your site rank higher in search results and attract more organic traffic.
     24Transform your WordPress into a dynamic visual platform with All Images – where functionality meets creativity and exclusivity.
     25
     26= Features =
     27– **Expansive Image Search**: Quickly navigate through multiple vast databases to find the right image for any topic within seconds.
     28
     29– **Flexible Image Orientation**: Choose from landscape, portrait, or square formats to fit the design of your page perfectly.
     30
     31– **Efficiency at Its Best**: Save time by uploading high-quality stock images directly from the WordPress admin panel, streamlining your workflow.
     32
     33– **Developer-Friendly**: Ideal for theme and plugin developers looking to prototype and build with tailor-made imagery.
     34
     35– **Enhanced Engagement for Marketers**: Boost your site’s engagement effortlessly, eliminating the need for costly graphic design resources.
     36
     37– **Gutenberg Integration**: Works seamlessly within Gutenberg through a dedicated plugin sidebar, enhancing your editing experience.
     38
     39– **Comprehensive Media Modal**: Accessible as a tab within the WordPress Media Modal, making it easy to manage visuals.
     40Page Builder Compatibility: Integrates smoothly with major page builders like Elementor, Beaver Builder, WP Bakery, Brizy, and Divi.
     41
     42– **Metadata Management**: Fine-tune image metadata (filename, alt text, caption) before upload to maximize SEO impact.
     43
     44– **Accessibility Features**: Automatically includes relevant alt descriptions for improved accessibility and SEO.
     45
     46– **User-Friendly Interface**: Simple and intuitive—select an image, and it’s instantly uploaded to your media library.
     47
     48Upgrade your WordPress site with All Images, and turn every post into a visual treat that captures and retains your audience’s attention.
     49
     50
     51
     52= Website =
     53[https://all-images.ai/](https://all-images.ai/)
     54
     55
    1656
    1757== Installation ==
    1858
    19591. Download and activate the plugin.
    20 2. Optional: configure providers' apis keys from the plugin settings page
     602. Required for image generation and bank images no free : configure [your api key](https://app.all-images.ai/en/api-keys) from the plugin settings page
     613. Optional: configure providers' apis keys from the plugin settings page
    2162
    22 == Third-party services ==
    23 
    24 This plugin utilizes third-party services to enhance its functionality. By using this plugin, you agree to the terms and conditions outlined below for each third-party service.
    25 
    26 1. All Images API
    27 
    28 - Description: Our plugin relies on the All Images API to streamline the process of generating and optimizing images.
    29 - Service Provider: All Images (https://www.all-images.ai)
    30 - Service Terms of Use and Privacy Policy: Please review the All Images Terms of Use (https://all-images.ai/mentions-legales/) and Privacy Policy (https://all-images.ai/politique-de-confidentialite/) for detailed information about their services.
    31 
    32 ### Important Notes:
    33 
    34 - Use of this plugin implies acceptance of the terms and conditions of the third-party services mentioned above.
    35 - The plugin developers do not have control over changes to third-party services. Any modifications to the third-party services' APIs, terms, or privacy policies are subject to the respective service providers' discretion.
    36 - It is advisable to regularly review the terms and policies of the third-party services to stay informed about any updates.
    37 
     63== Frequently Asked Questions ==
    3864
    3965== Changelog ==
    4066
     67= 1.0.1 =
     68* Bug fixes
     69* Setting: new field "additional prompt". Add indications that will not be altered during generation, useful for specifying a site theme or image style.
     70* Setting: new field "format image".
     71
    4172= 1.0.0 =
    4273* Initial release
     74
     75== Upgrade Notice ==
     76= 1.0.1 =
     77This version fixes several important bugs.
  • all-images-ai/trunk/uninstall.php

    r3100802 r3109334  
    3131}
    3232
    33 delete_option('all-images-ai-settings');
    34 delete_option('all-images-ai-webhook-id');
    35 
    3633if (defined('WP_CONTENT_DIR')) {
    3734    $log_path = WP_CONTENT_DIR . '/all-images-ai-logs/';
     
    4239}
    4340
     41$api_key = get_option('all-images-api-key');
     42
    4443global $wpdb;
    45 $table_name = $wpdb->prefix . "allimages_generations";
    46 $wpdb->query( "DROP TABLE IF EXISTS ".$table_name );
     44$tablename = $wpdb->prefix."allimages_generations";
     45
     46if (!empty($api_key)) {
     47    $result = $wpdb->get_col(
     48        <<<SQL
     49SELECT DISTINCT generation_id
     50FROM {$tablename}
     51WHERE generation_id IS NOT NULL;
     52SQL
     53    );
     54
     55    if (!empty($result)) {
     56        $options['headers'] = [
     57            'Content-Type' => 'application/json',
     58            'api-key' => $api_key
     59        ];
     60
     61        $options['body'] = json_encode([
     62            'printIds' => $result
     63        ]);
     64
     65        $args = wp_parse_args(
     66            $options,
     67            [
     68                'method' => 'DELETE',
     69                'timeout' => '5',
     70                'redirection' => '5',
     71                'httpversion' => '1.0',
     72                'blocking' => false,
     73                'cookies' => [],
     74            ]
     75        );
     76
     77        $url = 'https://api.all-images.ai/v1/image-generations';
     78        $response = wp_remote_post($url, $args);
     79    }
     80}
     81
     82$wpdb->query( "DROP TABLE IF EXISTS ".$tablename );
     83
     84delete_option('all-images-ai-settings');
     85delete_option('all-images-api-key');
Note: See TracChangeset for help on using the changeset viewer.