Changeset 3109334
- Timestamp:
- 06/28/2024 03:08:08 PM (21 months ago)
- Location:
- all-images-ai/trunk
- Files:
-
- 9 edited
-
admin/class-all-images-ai-admin.php (modified) (18 diffs)
-
admin/css/all-images-ai-admin.css (modified) (2 diffs)
-
admin/js/all-images-ai-admin.js (modified) (2 diffs)
-
admin/partials/all-images-ai-admin-automatic-form.php (modified) (4 diffs)
-
admin/partials/all-images-ai-admin-bulk-form.php (modified) (2 diffs)
-
all-images-ai.php (modified) (2 diffs)
-
includes/class-all-images-ai.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
uninstall.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
all-images-ai/trunk/admin/class-all-images-ai-admin.php
r3100802 r3109334 139 139 10 140 140 ); 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; 141 167 } 142 168 … … 186 212 ) 187 213 ); 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 ); 188 228 add_settings_field( 189 229 'all_images_use_post_title_as_alt', … … 195 235 'type' => 'checkbox', 196 236 'name' => 'all_images_use_post_title_as_alt', 197 'placeholder' => __('eg: 1200px', 'all-images-ai'),198 237 'checked' => (!isset($this->settings['all_images_use_post_title_as_alt'])) 199 238 ? 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']) : '' 200 253 ) 201 254 ); … … 482 535 483 536 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; 484 546 case 'text': 485 547 case 'number': … … 501 563 } 502 564 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 503 589 public function include_main_partial() 504 590 { … … 511 597 if (!empty($this->api_key)) { 512 598 $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 } 513 627 514 628 add_action('admin_notices', array($this, 'display_credits')); … … 716 830 } 717 831 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 840 SELECT DISTINCT post_id 841 FROM {$this->tablename} 842 WHERE post_id IN ($d) 843 AND status NOT IN ('print.failed', 'print.completed'); 844 SQL, 845 $ids 846 ); 847 848 $result = $this->wpdb->get_col($query); 849 850 return is_array($result) ? array_map('intval', $result) : []; 851 } 852 718 853 public function get_selected_posts() 719 854 { … … 733 868 734 869 $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 ); 735 882 736 883 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, 742 898 )); 743 899 } … … 879 1035 ); 880 1036 } 881 882 update_option('all-images-ai-settings', $this->settings); 883 }1037 } 1038 1039 update_option('all-images-ai-settings', $this->settings); 884 1040 } 885 1041 … … 935 1091 foreach ($ids as $id) { 936 1092 $my_post = get_post($id); 1093 $post_h2_indexes_asked = []; 937 1094 938 1095 foreach ($images as $image) { … … 941 1098 'name' => $my_post->ID . ' - ' . $my_post->post_title, 942 1099 'mode' => 'simple', 1100 'additionalPrompt' => ( !empty($this->settings['all_images_max_additional_prompt']) ? esc_html($this->settings['all_images_max_additional_prompt']) : '' ), 943 1101 'optimizePrompt' => true, 944 1102 'params' => array( 945 1103 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' ) 947 1106 ) 948 ) 1107 ), 1108 'prompt' => [] 949 1109 ); 950 1110 1111 $params['prompt'][] = esc_html($my_post->post_title); 951 1112 switch ($image['prompt']) { 952 1113 case 'post_title': 953 $params['prompt'] = esc_html($my_post->post_title);1114 $params['prompt'][] = esc_html($my_post->post_title); 954 1115 break; 955 1116 case 'post_h1': 956 1117 $title = $this->_getTextBetweenTags($my_post->post_content, 'h1'); 957 1118 if (!empty($title)) { 958 $params['prompt'] = esc_html($title);1119 $params['prompt'][] = esc_html($title); 959 1120 } else { 960 $params['prompt'] = esc_html($my_post->post_title);1121 $params['prompt'][] = esc_html($my_post->post_title); 961 1122 } 962 1123 break; 963 1124 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); 967 1128 } else { 968 $params['prompt'] = esc_html($cat->name);1129 $params['prompt'][] = esc_html($my_post->post_title); 969 1130 } 970 1131 break; 971 1132 } 972 1133 973 if (isset($image['position']) && $image['position'] == 'all_h2') {974 // CREATE GENERATION FOR EVERYH21134 if (isset($image['position']) && in_array($image['position'], ['first_h2', 'last_h2', 'all_h2', 'random_h2'])) { 1135 // CREATE GENERATION FOR H2 975 1136 $doc = new toolsDomDocument\SmartDOMDocument(); 976 1137 $doc->loadPartialHTML($my_post->post_content); 977 1138 $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; 1014 1211 } 1015 1212 } 1016 1213 } else { 1214 1215 $params['prompt'] = sprintf('###%s###', implode('###', $params['prompt'])); 1017 1216 1018 1217 $return = $this->wpdb->insert( … … 1034 1233 } 1035 1234 1036 $i d = (int) $this->wpdb->insert_id;1235 $insert_id = (int) $this->wpdb->insert_id; 1037 1236 if ($generation_id = $this->_query_generation($params)) { 1038 1237 $this->wpdb->update($this->tablename, array( … … 1040 1239 'status' => 'created', 1041 1240 ), array( 1042 'id' => $i d,1241 'id' => $insert_id, 1043 1242 )); 1044 1243 … … 1130 1329 { 1131 1330 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']); 1133 1332 wp_redirect(add_query_arg('paged', isset($_GET['paged']) ? absint($_GET['paged']) : 1, admin_url('/admin.php?page=all-images-ai-generations'))); 1134 1333 exit; 1135 1334 } 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 1419 SELECT DISTINCT id, generation_id 1420 FROM {$this->tablename} 1421 WHERE id IN ($d) 1422 AND generation_id IS NOT NULL; 1423 SQL, 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; 1136 1468 } 1137 1469 … … 1139 1471 { 1140 1472 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 } 1143 1479 1144 1480 return $actions; … … 1493 1829 $content = $img_html . $my_post->post_content; 1494 1830 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;1547 1831 case strpos($gen->position, 'h2_') > -1: 1548 1549 1832 $arr = explode('_', $gen->position); 1550 1833 $h2 = $doc->getElementsByTagName('h2')->item($arr[1]); … … 1593 1876 1594 1877 $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 } 1596 1882 $response = wp_remote_post($url, $args); 1597 1883 } else { … … 1608 1894 $date = new DateTime(); 1609 1895 $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); 1611 1897 } 1612 1898 } -
all-images-ai/trunk/admin/css/all-images-ai-admin.css
r3100802 r3109334 245 245 vertical-align:middle; 246 246 font-size: 18px; 247 } 248 .strikethrough { 249 text-decoration: line-through; 247 250 } 248 251 #collapse-accordions { … … 284 287 } 285 288 .all-images-image-wrapper.small-image img { 286 max-width:12rem;289 width:105px; 287 290 } 288 291 .generation-row .all-images-image-wrapper { -
all-images-ai/trunk/admin/js/all-images-ai-admin.js
r3100802 r3109334 403 403 404 404 // 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(); 406 406 $(document).on('change', '.position-field', function() { 407 407 $tr = $(this).closest('tr'); … … 412 412 default: 413 413 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 })); 415 418 } 416 419 break; -
all-images-ai/trunk/admin/partials/all-images-ai-admin-automatic-form.php
r3100802 r3109334 17 17 <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> 18 18 <div class="accordion-wrapper"> 19 <?php foreach($post_types as $ i => $post_type) {19 <?php foreach($post_types as $post_type) { 20 20 21 21 $hasData = (isset($this->settings['all_images_automatic']) && !empty($this->settings['all_images_automatic'][$post_type->name])); … … 46 46 <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]"> 47 47 <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> 50 50 </select> 51 51 … … 53 53 <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]"> 54 54 <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> 57 57 </select> 58 58 </td> … … 91 91 </th> 92 92 </tr> 93 <?php if($values ) {93 <?php if($values && !empty($values['images'])) { 94 94 $images = json_decode($values['images'], true); 95 95 foreach($images as $i => $image) { ?> -
all-images-ai/trunk/admin/partials/all-images-ai-admin-bulk-form.php
r3100802 r3109334 30 30 <?php foreach($posts as $p_id) { ?> 31 31 <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)) { ?> 33 34 <input type="hidden" name="posts[]" value="<?php echo esc_attr($p_id); ?>" /> 35 <?php } ?> 34 36 </li> 35 37 <?php } ?> … … 106 108 <?php 107 109 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); 112 111 } ?> 113 112 </p> -
all-images-ai/trunk/all-images-ai.php
r3100802 r3109334 17 17 * Plugin URI: https://app.all-images.ai 18 18 * Description: Find or generate the best images for your posts 19 * Version: 1.0. 019 * Version: 1.0.1 20 20 * Author: Weable 21 21 * Author URI: https://weable.fr/ … … 36 36 * Rename this for your plugin and update it as you release new versions. 37 37 */ 38 define('ALL_IMAGES_AI_VERSION', '1.0. 0');38 define('ALL_IMAGES_AI_VERSION', '1.0.1'); 39 39 40 40 /** -
all-images-ai/trunk/includes/class-all-images-ai.php
r3100802 r3109334 158 158 $this->loader->add_action('admin_menu', $plugin_admin, 'add_admin_menus'); 159 159 $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); 160 162 161 163 $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 === 2 2 Contributors: allimages 3 Tags: images, generated, ai, automatic, unsplash, pexel, pixabay, midjourney, api 3 Tags: image, generated, ai, automatic, unsplash, pexel, pixabay, midjourney, api, bank photos, stock photos 4 Requires PHP: 5.2.1 4 5 Requires at least: 5.0 5 6 Tested up to: 6.3.1 6 Stable tag: 1.0. 07 Stable tag: 1.0.1 7 8 License: GPLv2 8 9 … … 11 12 == Description == 12 13 13 Effortlessly import images from All-Images, Unsplash, Pixabay, or Pexels directly to your WordPress website, all within the WordPress interface! 14 Transform 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. 14 15 15 Automatic generation of custom images for your articles 16 = Core Services = 17 1. **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 19 2. **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 21 3. **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. 24 Transform 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. 40 Page 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 48 Upgrade 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 — 16 56 17 57 == Installation == 18 58 19 59 1. Download and activate the plugin. 20 2. Optional: configure providers' apis keys from the plugin settings page 60 2. 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 61 3. Optional: configure providers' apis keys from the plugin settings page 21 62 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 == 38 64 39 65 == Changelog == 40 66 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 41 72 = 1.0.0 = 42 73 * Initial release 74 75 == Upgrade Notice == 76 = 1.0.1 = 77 This version fixes several important bugs. -
all-images-ai/trunk/uninstall.php
r3100802 r3109334 31 31 } 32 32 33 delete_option('all-images-ai-settings');34 delete_option('all-images-ai-webhook-id');35 36 33 if (defined('WP_CONTENT_DIR')) { 37 34 $log_path = WP_CONTENT_DIR . '/all-images-ai-logs/'; … … 42 39 } 43 40 41 $api_key = get_option('all-images-api-key'); 42 44 43 global $wpdb; 45 $table_name = $wpdb->prefix . "allimages_generations"; 46 $wpdb->query( "DROP TABLE IF EXISTS ".$table_name ); 44 $tablename = $wpdb->prefix."allimages_generations"; 45 46 if (!empty($api_key)) { 47 $result = $wpdb->get_col( 48 <<<SQL 49 SELECT DISTINCT generation_id 50 FROM {$tablename} 51 WHERE generation_id IS NOT NULL; 52 SQL 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 84 delete_option('all-images-ai-settings'); 85 delete_option('all-images-api-key');
Note: See TracChangeset
for help on using the changeset viewer.