Changeset 3392620
- Timestamp:
- 11/10/2025 03:17:19 AM (5 months ago)
- Location:
- infility-global/trunk
- Files:
-
- 4 edited
-
infility_global.php (modified) (3 diffs)
-
readme.txt (modified) (2 diffs)
-
widgets/infility-import-data/include/infility-import-site.php (modified) (2 diffs)
-
widgets/infility-import-data/infility-import-data.php (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
infility-global/trunk/infility_global.php
r3386744 r3392620 4 4 Plugin URI: https://www.infility.cn/ 5 5 Description: Infility公共插件 6 Version: 2.14.1 66 Version: 2.14.17 7 7 Author: Infility 8 8 Author URI: https://www.infility.cn/ … … 128 128 V2.14.15 (20251029) Uzi: 开关优化实时更新标题状态 129 129 V2.14.16 (20251030) Ben: 导航文章列表bug修复 130 V2.14.17 (20251110) Ben: 抓取网页数据公共化 130 131 */ 131 132 … … 133 134 function __construct() 134 135 { 135 define( 'INFILITY_GLOBAL_VERSION', '2.14.1 6' );136 define( 'INFILITY_GLOBAL_VERSION', '2.14.17' ); 136 137 define( 'INFILITY_GLOBAL_PATH', plugin_dir_path( __FILE__ ) ); // fullpath/wp-content/plugins/infility-global/ // 有斜杠 137 138 define( 'INFILITY_GLOBAL_URL', plugins_url( '/', __FILE__ ) ); // https://the_domain/wp-content/plugins/infility-global/ // 斜杠是自己加的 -
infility-global/trunk/readme.txt
r3386744 r3392620 339 339 340 340 = 2.14.13 = 341 <<<<<<< .mine342 341 导入excel新增可以导入分类 343 342 … … 350 349 = 2.14.16 = 351 350 导航文章列表bug修复 351 352 = 2.14.17 = 353 抓取网页数据公共化 -
infility-global/trunk/widgets/infility-import-data/include/infility-import-site.php
r3283157 r3392620 693 693 } 694 694 695 public function get_progress_new($list_id){ 696 global $wpdb; 697 $list_table = $wpdb->prefix.'import_list'; 698 $table = $wpdb->prefix.'import_url'; 699 700 $sql = "SELECT * FROM $list_table WHERE id=$list_id"; 701 $list_data = $wpdb->get_row($sql,ARRAY_A); 702 $data = json_decode($list_data['data'],true); 703 704 if($data['page_type']=='post'){return 100;} 705 706 $sql = "SELECT count(*) as count FROM $table WHERE list_id=$list_id"; 707 $total_num = $wpdb->get_var($sql); 708 709 $sql = "SELECT count(*) as count FROM $table WHERE list_id=$list_id AND status=1"; 710 $finish_num = $wpdb->get_var($sql); 711 return ($finish_num/$total_num)*100; 712 } 713 695 714 public function getHtmlTag($html,$format,$type='tag',$extend_field = []){ 696 715 $dom = new \DOMDocument(); … … 831 850 return $attachment_id; // 返回附件 ID 832 851 } 852 853 function add_post_file($full_path) { 854 // 获取完整本地路径 855 // $upload_dir = wp_upload_dir(); 856 // $full_path = $upload_dir['basedir'] . '/' . ltrim($relative_path, '/'); 857 858 // 获取文件名 859 $filename = basename($full_path); 860 861 if (!file_exists($full_path)) { 862 return new WP_Error('file_not_found', '文件不存在:' . $full_path); 863 } 864 865 // 判断 MIME 类型 866 $filetype = wp_check_filetype($filename, null); 867 868 // 准备文件数组 869 $file = [ 870 'name' => $filename, 871 'type' => $filetype['type'], 872 'tmp_name' => $full_path, 873 'error' => 0, 874 'size' => filesize($full_path), 875 ]; 876 877 // 上传到媒体库 878 $overrides = [ 879 'test_form' => false, 880 'test_upload' => false, 881 ]; 882 883 $results = wp_handle_sideload($file, $overrides); 884 885 if (!empty($results['error'])) { 886 return new WP_Error('upload_failed', $results['error']); 887 } 888 889 // 创建媒体附件 890 $attachment = [ 891 'guid' => $results['url'], 892 'post_mime_type' => $results['type'], 893 'post_title' => preg_replace('/\.[^.]+$/', '', $filename), 894 'post_content' => '', 895 'post_status' => 'inherit', 896 ]; 897 898 $attach_id = wp_insert_attachment($attachment, $results['file']); 899 900 // 生成元数据 901 require_once ABSPATH . 'wp-admin/includes/image.php'; 902 $attach_data = wp_generate_attachment_metadata($attach_id, $results['file']); 903 wp_update_attachment_metadata($attach_id, $attach_data); 904 905 return $attach_id; 906 } 907 908 public function get_system_field($post_type){ 909 $field_groups = acf_get_field_groups([ 910 'post_type' => $post_type 911 ]); 912 913 $field_names = []; 914 $field_names[] = [ 915 'name'=>'post_title', 916 'label'=>'post标题' 917 ]; 918 919 foreach ($field_groups as $group) { 920 $fields = acf_get_fields($group['key']); 921 if (!$fields) continue; 922 foreach ($fields as $field) { 923 $field_names[] = $field; // 也可以用 $field['label'] 924 } 925 } 926 927 return $field_names; 928 } 929 930 public function get_field_html($system_field){ 931 $html = '<table>'; 932 $html.='<tr>'; 933 foreach($system_field as $k=>$v){ 934 $html.='<th>'.$v['label'].'</th>'; 935 } 936 $html.='</tr>'; 937 938 //选择类型 939 $html.='<tr>'; 940 foreach($system_field as $k=>$v){ 941 $html.='<td data-index="'.$k.'">'; 942 $html.='<select name="system_field['.$v['name'].'][type]" style="width: 100%;"> 943 <option value="value">文本</option> 944 <option value="html">HTML</option> 945 <option value="src">src链接</option> 946 <option value="href">href链接</option> 947 </select>'; 948 $html.='</td>'; 949 } 950 $html.='</tr>'; 951 952 //对应抓取字段 953 $html.='<tr>'; 954 foreach($system_field as $k=>$v){ 955 $html.='<td data-index="'.$k.'">'; 956 $html.='<input name="system_field['.$v['name'].'][target]" />'; 957 $html.='</td>'; 958 } 959 $html.='</tr>'; 960 961 962 $html .= '</table>'; 963 964 return $html; 965 } 966 967 public function get_post_detail($list_id){ 968 global $wpdb; 969 $table = $wpdb->prefix.'import_list'; 970 $url_table = $wpdb->prefix.'import_url'; 971 972 $sql = "SELECT * FROM $table WHERE id=$list_id"; 973 $list_data = $wpdb->get_row($sql,ARRAY_A); 974 $url = $list_data['source']; 975 $data = json_decode($list_data['data'],true); 976 $post_type = $data['post_type']; 977 $system_field = $data['system_field']; 978 979 if($data['page_type']=='category'){ 980 $sql = "SELECT * FROM $url_table WHERE list_id=$list_id AND `type`='post' AND status=0"; 981 $url_data = $wpdb->get_row($sql,ARRAY_A); 982 if(empty($url_data)){$this->error='no data';return false;} 983 $url = $url_data['url']; 984 $url_id = $url_data['id']; 985 } 986 987 $html = file_get_contents($url); 988 989 $catch_data = []; 990 foreach($system_field as $field=>$value){ 991 $get_type = $value['type']; 992 $target = $value['target']; 993 $format_target = $this->format_target($target); 994 995 $extend = []; 996 if($get_type!='text'){ 997 $extend = [$get_type]; 998 } 999 1000 $html_tag = $this->getHtmlTag($html,$format_target['format'],$format_target['type'],$extend); 1001 if(count($html_tag)>1){ 1002 foreach($html_tag as $k=>$v){ 1003 $catch_data[$field][$k] = trim($v[$get_type]); 1004 } 1005 }else{ 1006 $catch_data[$field] = trim($html_tag[0][$get_type]); 1007 } 1008 } 1009 1010 $post_id = 0; 1011 foreach($catch_data as $field=>$v){ 1012 if($field=='post_title'){ 1013 $post_data = [ 1014 'post_title'=>$v, 1015 'post_type'=>$post_type, 1016 'post_status' => 'publish', 1017 ]; 1018 1019 $post_id = wp_insert_post($post_data); 1020 if(!$post_id){ 1021 $this->error='Create New post error!'; 1022 if($data['page_type']=='category' && !empty($url_id)){ 1023 $wpdb->update($url_table,['result'=>$this->error,'data'=>json_encode($catch_data),'status'=>2],['id'=>$url_id]); 1024 } 1025 return false; 1026 } 1027 }else{ 1028 if($post_id<=0){ 1029 $this->error='No Post!'; 1030 if($data['page_type']=='category' && !empty($url_id)){ 1031 $wpdb->update($url_table,['result'=>$this->error,'data'=>json_encode($catch_data),'status'=>2],['id'=>$url_id]); 1032 } 1033 return false; 1034 } 1035 $acf_config = acf_get_field($field); 1036 $format_value = $this->format_acf_field($acf_config,$v); 1037 if(empty($format_value)){continue;} 1038 update_field($field, $format_value,$post_id); 1039 1040 if(strstr($field,'s01_image')){ 1041 if(!empty($format_value[0]['image'])){ 1042 set_post_thumbnail($post_id,$format_value[0]['image']); 1043 } 1044 } 1045 } 1046 } 1047 1048 1049 if(!empty($data['category_name']) && !empty($data['taxonomy'])){ 1050 if(taxonomy_exists($data['taxonomy'])){ 1051 $category_name_arr = explode(',',$data['category_name']); 1052 $term_ids = []; 1053 foreach($category_name_arr as $key=>$value){ 1054 $term = get_term_by('slug', $value, $data['taxonomy']); 1055 if(!empty($term->term_id)){$term_ids[] = $term->term_id;} 1056 } 1057 1058 wp_set_object_terms( $post_id, $term_ids, $data['taxonomy'], true ); 1059 1060 $data['category_name'] = ''; 1061 } 1062 } 1063 1064 1065 if($data['page_type']=='category' && !empty($url_id)){ 1066 $wpdb->update($url_table,['data'=>json_encode($catch_data),'save_id'=>$post_id,'status'=>1],['id'=>$url_id]); 1067 return $post_id; 1068 }else{ 1069 $this->error = 'ok'; 1070 return false; 1071 } 1072 } 1073 1074 public function search_category_page($list_id){ 1075 global $wpdb; 1076 $table = $wpdb->prefix.'import_list'; 1077 $url_table = $wpdb->prefix.'import_url'; 1078 1079 $sql = "SELECT * FROM $table WHERE id=$list_id"; 1080 $list_data = $wpdb->get_row($sql,ARRAY_A); 1081 $url = $list_data['source']; 1082 $data = json_decode($list_data['data'],true); 1083 $page_tag = $data['page_tag']; 1084 1085 $html = file_get_contents($url); 1086 1087 $page_format_target = $this->format_target($page_tag); 1088 $page_tag = $this->getHtmlTag($html,$page_format_target['format'],$page_format_target['type'],['href']); 1089 1090 if(empty($page_tag)){$this->error='分页数据出错';return false;} 1091 1092 1093 $sql = "SELECT url FROM $url_table WHERE list_id=$list_id AND `type`='category'"; 1094 $check_repeat = $wpdb->get_col($sql); 1095 1096 $pages = []; 1097 if(!empty($page_tag)){ 1098 $pages = []; 1099 1100 foreach($page_tag as $k=>$v){ 1101 if(empty($v['link'])){continue;} 1102 if(in_array($v['link'],$check_repeat)){continue;} 1103 if(in_array($v['link'],$pages)){continue;} 1104 $pages[] = $v['link']; 1105 } 1106 } 1107 1108 $last_page_num = $this->getLastPageFromHrefs($pages,$url); 1109 foreach($pages as $k=>$v){ 1110 $page_num = $k+1; 1111 1112 $insert = [ 1113 'list_id' => $list_id, 1114 'type' => 'category', 1115 'url' => $v, 1116 'status' => 0, 1117 'page' => $page_num, 1118 'total_page'=> $last_page_num, 1119 'add_time' => time(), 1120 ]; 1121 1122 $wpdb->insert($url_table,$insert); 1123 } 1124 1125 return true; 1126 } 1127 1128 public function search_category_post($list_id){ 1129 global $wpdb; 1130 $table = $wpdb->prefix.'import_list'; 1131 $url_table = $wpdb->prefix.'import_url'; 1132 1133 $sql = "SELECT * FROM $table WHERE id=$list_id"; 1134 $list_data = $wpdb->get_row($sql,ARRAY_A); 1135 $data = json_decode($list_data['data'],true); 1136 $list_tag = $data['list_tag']; 1137 1138 $sql = "SELECT * FROM $url_table WHERE list_id=$list_id AND `type`='category' AND status=0"; 1139 $url_data = $wpdb->get_row($sql,ARRAY_A); 1140 if(empty($url_data)){$this->error='no data';return false;} 1141 1142 $url = $url_data['url']; 1143 $url_id = $url_data['id']; 1144 1145 $html = file_get_contents($url); 1146 if(empty($html)){ 1147 $this->error='抓取html数据出错'; 1148 $wpdb->update($url_table,['result'=>json_encode($this->error),'status'=>2],['id'=>$url_id]); 1149 return false; 1150 } 1151 1152 $list_format_target = $this->format_target($list_tag); 1153 $list_tag = $this->getHtmlTag($html,$list_format_target['format'],$list_format_target['type'],['href']); 1154 if(empty($list_tag)){ 1155 $this->error='列表数据出错'; 1156 $wpdb->update($url_table,['result'=>json_encode($this->error),'status'=>2],['id'=>$url_id]); 1157 return false; 1158 } 1159 1160 $sql = "SELECT url FROM $url_table WHERE list_id=$list_id AND `type`='post'"; 1161 $check_repeat = $wpdb->get_col($sql); 1162 1163 $list = []; 1164 if(!empty($list_tag)){ 1165 foreach($list_tag as $k=>$v){ 1166 if(empty($v['link'])){continue;} 1167 if(in_array($v['link'],$check_repeat)){continue;} 1168 if(in_array($v['link'],$list)){continue;} 1169 $list[] = $v['link']; 1170 } 1171 1172 foreach($list as $k=>$v){ 1173 $insert = [ 1174 'list_id' => $list_id, 1175 'type' => 'post', 1176 'url' => $v, 1177 'status' => 0, 1178 'page' => 0, 1179 'total_page'=> 0, 1180 'add_time' => time(), 1181 ]; 1182 1183 $wpdb->insert($url_table,$insert); 1184 } 1185 } 1186 1187 $wpdb->update($url_table,['data'=>json_encode($list),'status'=>1],['id'=>$url_id]); 1188 1189 return true; 1190 } 1191 1192 public function format_acf_field($acf_config,$data){ 1193 $type = $acf_config['type']; 1194 if($type=='repeater'){ 1195 $format_value = []; 1196 1197 $is_image = false; 1198 if($acf_config['sub_fields'][0]['type']=='image'){$is_image = true;} 1199 1200 foreach($data as $k=>$v){ 1201 $first_field = $acf_config['sub_fields'][0]['name']; 1202 $info = []; 1203 if($is_image){ 1204 $attach_id = $this->add_image_to_media_library($v); 1205 $info[$first_field] = $attach_id; 1206 }else{ 1207 $info[$first_field] = $v; 1208 } 1209 1210 $format_value[] = $info; 1211 } 1212 }else if($type=='gallery'){ 1213 $format_value = []; 1214 foreach($data as $k=>$v){ 1215 $attach_id = $this->add_image_to_media_library($v); 1216 $format_value[] = $attach_id; 1217 } 1218 }else if($type=='image'){ 1219 $attach_id = $this->add_image_to_media_library($data); 1220 $format_value = $attach_id; 1221 }else{ 1222 $format_value = $data; 1223 } 1224 1225 return $format_value; 1226 } 1227 1228 public function format_target($target){ 1229 $type = 'tag'; 1230 if(strstr($target,'.')){ 1231 $type = 'class'; 1232 1233 $check_class = explode(' ',$target); 1234 if(count($check_class)>1){ 1235 $format = []; 1236 foreach($check_class as $k=>$v){ 1237 if($k==0){ 1238 $format['class'] = str_replace('.','',$v); 1239 }else if($k==1){ 1240 $format['child'] = str_replace('.','',$v); 1241 } 1242 } 1243 $type = 'class-children'; 1244 }else{ 1245 $format = str_replace('.','',$target); 1246 } 1247 }else{ 1248 $format = $target; 1249 } 1250 1251 return ['type'=>$type,'target'=>$target,'format'=>$format]; 1252 } 1253 1254 function getLastPageFromHrefs($hrefs,$baseListUrl = null){ 1255 $maxPage = null; 1256 $hasBase = false; 1257 1258 // 规范化 baseListUrl(去掉反引号/引号) 1259 if ($baseListUrl !== null) { 1260 $baseListUrl = rtrim(trim($baseListUrl, " `\"'")); 1261 } 1262 1263 foreach ($hrefs as $href) { 1264 if (!is_string($href)) continue; 1265 1266 // 去掉可能混入的反引号/引号和空白 1267 $url = trim($href, " `\"'"); 1268 1269 if ($url === '') continue; 1270 1271 // 1) 匹配 /page/N/ 风格 1272 if (preg_match('#/page/(\d+)/?#i', $url, $m)) { 1273 $n = (int)$m[1]; 1274 if ($maxPage === null || $n > $maxPage) { 1275 $maxPage = $n; 1276 } 1277 continue; 1278 } 1279 1280 // 2) 兼容 ?paged=N 在 query 中的风格 1281 $query = parse_url($url, PHP_URL_QUERY); 1282 if ($query) { 1283 parse_str($query, $params); 1284 if (isset($params['paged'])) { 1285 $n = (int)$params['paged']; 1286 if ($maxPage === null || $n > $maxPage) { 1287 $maxPage = $n; 1288 } 1289 continue; 1290 } 1291 } 1292 1293 // 3) 兜底:如果传入了分类首页并且链接等于该首页,则记为存在第一页 1294 if ($baseListUrl !== null) { 1295 // 忽略末尾斜杠差异 1296 $u1 = rtrim($url, '/'); 1297 $u2 = rtrim($baseListUrl, '/'); 1298 if (strcasecmp($u1, $u2) === 0) { 1299 $hasBase = true; 1300 } 1301 } 1302 } 1303 1304 if ($maxPage !== null) { 1305 return $maxPage; // 找到最大的 /page/N/ 1306 } 1307 if ($hasBase) { 1308 return 1; // 只有首页,视为总页数 1 1309 } 1310 return null; // 无法判断 1311 } 833 1312 } -
infility-global/trunk/widgets/infility-import-data/infility-import-data.php
r3327876 r3392620 10 10 11 11 add_action('wp_ajax_import_data',array($this,'import_data')); 12 13 add_action('wp_ajax_get_site_field',array($this,'get_site_field')); 14 add_action('wp_ajax_get_post_detail',array($this,'get_post_detail')); 15 add_action('wp_ajax_search_category_page',array($this,'search_category_page')); 16 add_action('wp_ajax_search_category_post',array($this,'search_category_post')); 17 12 18 add_action('wp_ajax_search_site_category',array($this,'search_site_category')); 13 19 add_action('wp_ajax_search_site_product',array($this,'search_site_product')); … … 17 23 add_action('wp_ajax_add_term',array($this,'add_term')); 18 24 add_action('wp_ajax_add_post',array($this,'add_post')); 25 26 19 27 add_action('wp_ajax_get_excel_field',array($this,'get_excel_field')); 20 28 add_action('wp_ajax_add_excel_post',array($this,'add_excel_post')); … … 320 328 public function import_page(){ 321 329 $post_types = get_post_types(); 330 $taxonomy_list = get_taxonomies(['public' => true]); 322 331 323 332 ob_start(); … … 371 380 </div> 372 381 <div class="row"> 373 <input type="hidden" class="list_id" >382 <input type="hidden" class="list_id" name="id"> 374 383 <button class="form_button">开始</button> 375 384 </div> … … 409 418 </div> 410 419 <div class="row"> 411 <input type="hidden" class="list_id" >420 <input type="hidden" class="list_id" name="id"> 412 421 <button class="form_button">开始</button> 413 422 </div> … … 427 436 </label> 428 437 </div> 438 <!-- <div class="row checkbox">--> 439 <!-- <label>--> 440 <!-- <span>产品分类:</span>--> 441 <!-- <input type="checkbox" name="category[product_category]" value="1" />--> 442 <!-- </label>--> 443 <!-- <label>--> 444 <!-- <span>产品:</span>--> 445 <!-- <input type="checkbox" name="category[product]" value="1" />--> 446 <!-- </label>--> 447 <!-- <label>--> 448 <!-- <span>博客:</span>--> 449 <!-- <input type="checkbox" name="category[blog]" value="1" />--> 450 <!-- </label>--> 451 <!-- </div>--> 429 452 <div class="row checkbox"> 430 453 <label> 431 <span>产品:</span> 432 <input type="checkbox" name="category[product]" value="1" /> 433 </label> 434 <label> 435 <span>博客:</span> 436 <input type="checkbox" name="category[blog]" value="1" /> 437 </label> 438 </div> 439 <div class="row"> 440 <input type="hidden" class="list_id"> 454 <span>页面类型:</span> 455 <select name="page_type"> 456 <option value="">请选择</option> 457 <option value="category">分类页</option> 458 <option value="post">详情页</option> 459 </select> 460 </label> 461 </div> 462 <div class="category_div"> 463 <div class="row checkbox"> 464 <label> 465 <span>列表产品标签:</span> 466 <input type="text" name="list_tag" value=""/> 467 </label> 468 </div> 469 <div class="row checkbox"> 470 <label> 471 <span>分页标签(可空):</span> 472 <input type="text" name="page_tag" value=""/> 473 </label> 474 </div> 475 </div> 476 <div class="row checkbox"> 477 <label> 478 <span>Post Type(类型):</span> 479 <select name="post_type"> 480 <option value="">请选择Post Type</option> 481 <?php foreach($post_types as $k=>$v){?> 482 <option value="<?php echo $v;?>"><?php echo $v?></option> 483 <?php }?> 484 </select> 485 </label> 486 </div> 487 <div class="row"> 488 <label> 489 <span>对应字段:</span> 490 <div class="field_list"></div> 491 </label> 492 </div> 493 <div class="row checkbox"> 494 <label> 495 <span>分类Taxonomy(可空):</span> 496 <select name="taxonomy"> 497 <option value="">请选择</option> 498 <?php foreach($taxonomy_list as $k=>$v){?> 499 <option value="<?php echo $v;?>"><?php echo $v?></option> 500 <?php }?> 501 </select> 502 </label> 503 </div> 504 <div class="row checkbox"> 505 <label> 506 <span>分类Slug(可空)多个英文逗号隔开:</span> 507 <input type="text" name="category_name" value=""/> 508 </label> 509 </div> 510 <div class="row"> 511 <input type="hidden" class="list_id" name="id"> 441 512 <button class="form_button">开始</button> 442 513 </div> … … 496 567 if(empty($_POST['name'])){str::e_json(['res'=>'Name is wrong'],1);} 497 568 if(empty($_POST['site'])){str::e_json(['res'=>'Site is wrong'],1);} 498 if(empty($_POST['category'])){str::e_json(['res'=>'Category is wrong'],1);} 569 if(empty($_POST['page_type'])){str::e_json(['res'=>'Page Type is wrong'],1);} 570 if(empty($_POST['post_type'])){str::e_json(['res'=>'Post Type is wrong'],1);} 499 571 500 572 $name = $_POST['name']; 501 573 $site = $_POST['site']; 502 $category = $_POST['category']; 574 $post_type = $_POST['post_type']; 575 $page_type = $_POST['page_type']; 576 $system_field = $_POST['system_field']; 503 577 504 578 if(!file_get_contents($site)){ … … 506 580 } 507 581 508 $category_data = []; 509 if(!empty($category['product'])){ 510 $category_data['product']=true; 582 foreach($system_field as $k=>$v){ 583 if(empty($v['target'])){unset($system_field[$k]);} 511 584 } 512 if(!empty($category['blog'])){ 513 $category_data['blog']=true; 585 586 if(empty($system_field)){str::e_json(['res'=>'Please fill catch field'],1);} 587 588 $data = ['page_type'=>$page_type,'post_type'=>$post_type,'system_field'=>$system_field]; 589 590 if($page_type=='category'){ 591 if(empty($_POST['list_tag'])){str::e_json(['res'=>'List tag is wrong'],1);} 592 $data['list_tag'] = $_POST['list_tag']; 593 if(!empty($_POST['page_tag'])){ 594 $data['page_tag'] = $_POST['page_tag']; 595 } 596 } 597 598 if(!empty($_POST['taxonomy'])){ 599 $data['taxonomy'] = $_POST['taxonomy']; 600 } 601 if(!empty($_POST['category_name'])){ 602 $data['category_name'] = $_POST['category_name']; 514 603 } 515 604 … … 519 608 'status'=>0, 520 609 'source'=>$site, 521 'data'=>json_encode($ category_data),610 'data'=>json_encode($data), 522 611 'add_time'=>time(), 523 612 ]; 613 524 614 $wpdb->insert($table,$list_data); 525 615 $list_id = $wpdb->insert_id; 526 616 } 527 617 528 $sql = "SELECT * FROM $table WHERE id=$list_id";529 $row = $wpdb->get_row($sql,ARRAY_A);530 $data = json_decode($row['data'],true);531 532 618 $wpdb->update($table,['status'=>0],['id'=>$list_id]); 533 619 534 return ['res'=>'ok','id'=>$list_id,'product'=>$data['product'],'blog'=>$data['blog']]; 620 return ['res'=>'ok','id'=>$list_id]; 621 } 622 623 public function get_post_detail(){ 624 $import_site_class = new infility_import_site(); 625 if(empty($_POST['id'])){str::e_json(['res'=>'参数错误'],1); } 626 $post_id = $import_site_class->get_post_detail($_POST['id']); 627 $progress = $import_site_class->get_progress_new($_POST['id']); 628 if(!$post_id){str::e_json(['res'=>$import_site_class->error,'progress'=>$progress],1);} 629 630 str::e_json(['res'=>'ok','post_id'=>$post_id,'progress'=>$progress]); 631 } 632 633 public function search_category_page(){ 634 $import_site_class = new infility_import_site(); 635 if(empty($_POST['id'])){str::e_json(['res'=>'参数错误'],1); } 636 $res = $import_site_class->search_category_page($_POST['id']); 637 $progress = $import_site_class->get_progress_new($_POST['id']); 638 if(!$res){str::e_json(['res'=>$import_site_class->error,'progress'=>$progress],1);} 639 str::e_json(['res'=>'ok','progress'=>$progress],1); 640 } 641 642 public function search_category_post(){ 643 $import_site_class = new infility_import_site(); 644 if(empty($_POST['id'])){str::e_json(['res'=>'参数错误'],1); } 645 $res = $import_site_class->search_category_post($_POST['id']); 646 $progress = $import_site_class->get_progress_new($_POST['id']); 647 if(!$res){str::e_json(['res'=>$import_site_class->error,'progress'=>$progress],1);} 648 str::e_json(['res'=>'ok','progress'=>$progress]); 649 } 650 651 public function get_site_field(){ 652 $import_site_class = new infility_import_site(); 653 if(empty($_POST['post_type'])){str::e_json(['res'=>'类型不能为空'],1); } 654 $post_type = $_POST['post_type']; 655 656 $system_field = $import_site_class->get_system_field($post_type); 657 $html = $import_site_class->get_field_html($system_field); 658 659 str::e_json(['res'=>'ok','html'=>$html]); 535 660 } 536 661
Note: See TracChangeset
for help on using the changeset viewer.