extend_api.php 61.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
<?php
require_once( dirname(__FILE__) . '/wp-load.php' );
global $wpdb;

$type = $_GET['w'];
switch($type){
    case 1: //cms5.0版本输出api
        //统计数据
        $day = date('Y-m-d',time()-86400);
        $res = $wpdb->get_row("select pv,uv,ip from wp_stats_day_count where day ='$day'",ARRAY_A);
        $data['yesterday_pv'] = (int)$res['pv'];
        $data['yesterday_ip'] = (int)$res['ip'];
        $data['yesterday_uv'] = (int)$res['uv'];
        //全部访问统计
        $res = array();
        $res = $wpdb->get_row("select ip, pv, uv from wp_stats_year_count",ARRAY_A);
        $totol_ip = $wpdb->get_row("select count(id) t_ip, sum(pv) t_pv from wp_stats_day_ip where is_spider=1",ARRAY_A);
        $data['total_ip'] = (int)$totol_ip['t_ip'];
        $data['total_pv'] = (int)$totol_ip['t_pv'];
        $data['total_uv'] = (int)$res['uv'];
        //全部询盘数
        if(isset($_GET['a'])){
            $res = $wpdb->get_row("SELECT count(*) as cnt FROM wp_cf7_data",ARRAY_A);
        }else{
            $res = $wpdb->get_row("SELECT count(*) as cnt FROM wp_cf7_data_entry where cf7_id=19 and name='submit_time'",ARRAY_A);
        }
        $data['cf_count']= (int)$res['cnt'];
        //询盘转化率
        $data['total_cf_f']= number_format(($data['cf_count']/$data['total_ip']), 4)*100;
        //月访问统计
        for($k=-30;$k<=-1;$k++){
            $d = date('Y-m-d',strtotime ( "$k day"));
            $res =array();
            $res = $wpdb->get_row("select day, ip, pv, uv from wp_stats_day_count where day='$d'",ARRAY_A);
            $res['ip']=$res['ip']?$res['ip']:0;
            $res['pv']=$res['pv']?$res['pv']:0;
            $res['uv']=$res['uv']?$res['uv']:0;
            $res['day']=$res['day']?$res['day']:$d;
            $data['last30days_ip'][]=(int)$res['ip'];
            $data['last30days_pv'][]=(int)$res['pv'];
            $data['last30days_uv'][]=(int)$res['uv'];
            //$data['last30days'][$d]=$res;
        }
        $data['last7days_start_y']=date('Y',strtotime ( "-30 day"));
        $data['last7days_start_m']=intval(date('m',strtotime ( "-30 day")));
        $data['last7days_start_d']=intval(date('d',strtotime ( "-30 day")));
        $data['last7days_end_y']=date('Y',strtotime ( "-1 day"));
        $data['last7days_end_m']=intval(date('m'),strtotime ( "-1 day"));
        $data['last7days_end_d']=intval(date('d'),strtotime ( "-1 day"));

        //访问国家前10
        $res = array();
        $sql = 'select * from ( 
				select count(1) ip_area,ip_area show_area, SUM(pv) show_pv, SUM(uv) show_uv, count(ip) show_ip 
				from wp_stats_day_ip t 
				group by t.ip_area 
				order by count(1) desc 
				) t_1 limit 0, 15';
        $wpdb->query($sql);
        $country_top10 = $wpdb->last_result;
        $tmp_i = 0;
        $data['country_top10_country'] = $data['country_top10_pv'] = $data['country_top10_ip'] = [];
        foreach($country_top10 as $key=>$v){
            if($v->show_area!='Unknown' && $v->show_area!='香港' && $v->show_area!='中国' && $v->show_area!='台湾' && $v->show_area!=''){
                if($tmp_i < 10){
                    $data['country_top10_country'][]=$v->show_area;
                    $data['country_top10_pv'][]=(int)$v->show_pv;
                    $data['country_top10_ip'][]=(int)$v->show_ip;
                }
                $tmp_i ++;
            }
        }
        //访问来源前10

        $res =array();
        $sql = "select * from ( 
				select count(1) num_referrer,referrer
				from wp_stats_day_ip t 
				group by t.referrer 
				order by count(1) desc 
				) t_1 limit 0, 15";
        $wpdb->query($sql);
        $referrer_top8 = array();
        if($wpdb->last_result){
            foreach($wpdb->last_result as $val){
                if(($val->referrer != '')){
                    if(strpos($val->referrer,home_url()) !== 0){
                        if(strlen($val->referrer) > 50){
                            $val->referrer = substr($val->referrer,0,50);
                        }
                        $t_ar['num_referrer'] = $val->num_referrer;
                        $t_ar['referrer'] = $val->referrer;
                        $referrer_top8[] = $t_ar;
                    }
                }
            }
        }
        $data['referrer_top8'] = $referrer_top8;

        //访问国家top15
        $country_top15_area = array();
        $sql = "select * from ( 
					select count(1) ip_area,ip_area show_area
					from wp_stats_day_ip t 
					group by t.ip_area 
					order by count(1) desc 
					) t_1 limit 0, 19";
        $res = $wpdb->get_results($sql,ARRAY_A);
        if($res){
            foreach($res as $val){
                if($val['show_area'] != '中国' && $val['show_area'] != '台湾' && $val['show_area'] != '香港' && $val['show_area'] != 'Unknown' && $val['show_area'] != ''){
                    $country_top15_area[] = $val;
                }
            }
        }
        $data['country_top15'] = $country_top15_area;
        $data['page_num'] = count(query_posts(array( 'post_type' => 'page','posts_per_page'=>-1)));
        $data['news_num'] = count(query_posts(array( 'post_type' => 'news','posts_per_page'=>-1)));
        /*$categories = get_categories( $args );
        $excpt = [];
        if($categories){
            foreach($categories as $k=>$v){
                if($v->name == 'Featured'){
                    $excpt[] = $v->term_id;
                }
            }
        }
        $data['posts_num'] = count(query_posts(array('post_type' => 'post','category__not_in'=> $excpt,'showposts' => 10000)));

        $posts_num123 = $wpdb->get_results("select ID from wp_posts where not post_date_gmt='2016-01-08 00:00:00' and post_type='post' and post_status='publish'",ARRAY_A);
        $data['posts_num'] = count($posts_num123);*/
        $posts_num_all = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM wp_posts WHERE post_type=%s AND post_status = %s", 'post', 'publish' ) );
        $feature =  $wpdb->get_row("SELECT count(*) as cnt_feature FROM `wp_term_relationships` WHERE `term_taxonomy_id` = 635");
        $data['posts_num'] =count($posts_num_all)- $feature->cnt_feature;
        //
        //询盘国家统计
        $res_cf7_ip = $wpdb->get_results("select b.`value` as ip from wp_cf7_data as d left join wp_cf7_data_entry as b on d.id=b.data_id where b.`name`='submit_ip'",ARRAY_A);
        $ar_tmp_ip = array();
        if($res_cf7_ip){
            foreach($res_cf7_ip as $k=>$v){
                if(!in_array($v['ip'],$ar_tmp_ip)){
                    $ar_tmp_ip[] = $v['ip'];
                }
            }
        }
        $country_all_area = array();
        if($ar_tmp_ip){
            $sql = "select * from (select count(1) ip_area,ip_area show_area from (select ip,ip_area from wp_stats_day_ip where ip in ('".implode("','",$ar_tmp_ip)."') group by ip) as t group by t.ip_area order by count(1) desc ) t_1 limit 0, 19";
            $wpdb->query($sql);
            if($wpdb->last_result){
                foreach($wpdb->last_result as $val){
                    if($val->show_area != '台湾' && $val->show_area != '香港' && $val->show_area != 'Unknown' && $val->show_area != ''){
                        $t_ar = [];
                        $t_ar['ip_area'] = $val->ip_area;
                        $t_ar['show_area'] = $val->show_area;
                        $country_all_area[] = $t_ar;
                    }
                }
            }
        }
        $data['xunpan_dis'] = $country_all_area;
        $email_info = get_post_meta(19,'_mail');
        $email = $email_info[0]['recipient'];
        $data['email'] = $email;
        $data['phone'] = get_option('sms_phone_num',true);
		$smtp_server = get_option('wp_email_smtp_option_name')['from_email'];
        if($smtp_server == 'mail@goodao.cn'){
            $smtp_type = 1;
        }elseif($smtp_server == 'goodao@globalso.com.cn'){
            $smtp_type = 2;
        }else{
            $smtp_type = 3;
        }
        $data['smtp_type'] = $smtp_type;
        //print_r($data);exit;
        echo json_encode($data);exit;
        break;
    case 2://输出询盘信息
        $timelist = $wpdb->get_results("select * from wp_cf7_data order by id desc limit 50",ARRAY_A);
        $data = [];
        if($timelist){
            foreach ($timelist as $v){
                $ids[] = $v['id'];
            }
            $datas = $wpdb->get_results("select * from wp_cf7_data_entry where cf7_id=19 and data_id in(".implode(',',$ids).")",ARRAY_A);
            if($datas){
                foreach ($timelist as $k=>$v){
                    foreach ($datas as $kk=>$vv){
                        if($v['id'] == $vv['data_id']){
                            $data[$v['id']][$vv['name']] = $vv['value'];
                            if($vv['name'] == 'Message'){
                                $data[$v['id']][$vv['name']] = str_replace('"','',trim($vv['value']));
                                $data[$v['id']][$vv['name']] = str_replace("\n",' ',$data[$v['id']][$vv['name']]);
                                $data[$v['id']][$vv['name']] = str_replace("<br />",' ',$data[$v['id']][$vv['name']]);
                            }
                        }
                    }
                }
            }
            foreach ($data as $k=>$v){
                $day = date("Y-m-d",strtotime($v['submit_time']));
                $rq = $wpdb->get_results('select time_str,request from wp_stats_day_data where ip=\''.$v['submit_ip'].'\' and day_at=\''.$day.'\' order by time_str desc',ARRAY_A);
                $data[$k]['request'] = $rq;
            }
        }
        print_r(json_encode($data));exit;
        break;
    case 22://输出昨天询盘信息
        $start = date("Y-m-d",time()-86400).' 00:00:00';
        $end = date("Y-m-d",time()-86400).' 23:59:59';
        $timelist = $wpdb->get_results("select * from wp_cf7_data where created>='".$start."' and created<='".$end."' order by id desc limit 10",ARRAY_A);
        $data = [];
        if($timelist){
            foreach ($timelist as $v){
                $ids[] = $v['id'];
            }
            $datas = $wpdb->get_results("select * from wp_cf7_data_entry where cf7_id=19 and data_id in(".implode(',',$ids).")",ARRAY_A);
            if($datas){
                foreach ($timelist as $k=>$v){
                    foreach ($datas as $kk=>$vv){
                        if($v['id'] == $vv['data_id']){
                            $data[$v['id']][$vv['name']] = $vv['value'];
                            if($vv['name'] == 'Message'){
                                $data[$v['id']][$vv['name']] = str_replace('"','',trim($vv['value']));
                                $data[$v['id']][$vv['name']] = str_replace("\n",' ',$data[$v['id']][$vv['name']]);
                                $data[$v['id']][$vv['name']] = str_replace("<br />",' ',$data[$v['id']][$vv['name']]);
                            }
                        }
                    }
                }
            }
            foreach ($data as $k=>$v){
                $day = date("Y-m-d",strtotime($v['submit_time']));
                $rq = $wpdb->get_results('select time_str,request from wp_stats_day_data where ip=\''.$v['submit_ip'].'\' and day_at=\''.$day.'\' order by time_str desc',ARRAY_A);
                $data[$k]['request'] = $rq;
            }
        }
        print_r(json_encode($data));exit;
        break;
    case 3://输出链接
        $rq = $wpdb->get_results('select time_str,request from wp_stats_day_data where ip=\''.$_GET['ip'].'\' order by time desc',ARRAY_A);
        print_r(json_encode($rq));exit;
        break;
    case 44://更新footer文件
        $rootdir = __DIR__;
        $file_path = $rootdir.'/wp-content/themes/global/footer.php';
        if(file_exists($file_path)){ //有文件直接修改文件
            $data = file_get_contents($file_path);
            if(strpos($data,"wp-admin/admin-ajax.php") !== false){
                $data = str_replace('var src="<?php echo home_url("/"); ?>wp-admin/admin-ajax.php?action=stats_init&assort=0&referrer="+referrer+"&currweb="+currweb+"&firstshow="+firstshow+"&screenwidth="+screenwidth+"&screenheight="+screenheight+"&screencolordepth="+screencolordepth+"&ranstr="+Math.random()','$.get("/statistic.php", { action:\'stats_init\', assort:0, referrer:referrer, currweb:currweb , firstshow:firstshow ,screenwidth:screenwidth, screenheight: screenheight, screencolordepth: screencolordepth, ranstr: Math.random()},function(data){}, "json");',$data);
                $data = str_replace("$('body').append('<iframe style=\"display:none\" src='+src+'></iframe>')",'',$data);
                file_put_contents($file_path,$data);
            }
        }
        echo 1;exit;
        break;
    case 8://ip 查询来路域名
        $ip = trim($_GET['ip']);
        if(!$ip){
            echo 'no ip';exit;
        }
        $date = trim($_GET['date']);
        if(!$date){
            echo 'no date';exit;
        }
        $refer_info = $wpdb->get_row("select referrer from wp_stats_day_ip where ip='".$ip."' and day='".$date."'",ARRAY_A);
        echo $refer_info['referrer'];exit;
        break;
    case 9://停掉询盘插件插件
        $active_plugins = get_option('active_plugins');
        $flg = 0;
        foreach($active_plugins as $k=>$v){
            if($v == 'wp-automatic/wp-automatic.php'){
                unset($active_plugins[$k]);
                $flg = 1;
                break;
            }
        }
        if($flg == 1){
            //update_option('active_plugins',$active_plugins);
        }
        echo 200;exit;
        break;
    case 5://更新gd-admin 密码
        echo 1;exit;
        break;
	case 'change_url'://更新siteurl  home 链接
        $cur_url = trim($_GET['url']);
        if(!$cur_url){
            echo '没有传入url';exit;
        }
        $cur_url_s = $_SERVER['SERVER_NAME'];
        //print_r($cur_url_s);exit;
        if(strpos($cur_url,$cur_url_s) !== false){
    		$target_url = get_option('siteurl');
    		if($target_url != $cur_url){
    			update_option('siteurl',$cur_url);
    			update_option('home',$cur_url);
    			update_option('admin_email','service@goodao.cn');
    		}
    		echo 200;exit;
        }else{
            echo '传入的链接不匹配';exit;
        }
        break;
	case 'delete_user'://删除特殊的用户
        $wpdb->query("delete from wp_users where user_login like '%wpuser_%'");
		echo 200;exit;
        break;
    case 55://更新sitemap 设置
        $sitemap_setting = get_option('aioseop_options');
        $sitemap_setting['modules']['aiosp_sitemap_options']['aiosp_sitemap_prio_post'] = '0.8';
        $sitemap_setting['modules']['aiosp_sitemap_options']['aiosp_sitemap_prio_taxonomies'] = '0.9';
        $sitemap_setting['modules']['aiosp_sitemap_options']['aiosp_sitemap_google'] = 'on';
        $sitemap_setting['modules']['aiosp_sitemap_options']['aiosp_sitemap_bing'] = 'on';
        $sitemap_setting['modules']['aiosp_sitemap_options']['aiosp_sitemap_rewrite'] = 'on';
        update_option('aioseop_options',$sitemap_setting);
        //print_r($sitemap_setting['modules']['aiosp_sitemap_options']);exit;
        echo 1;exit;
        break;
    case 555://检查更新版本
        echo 1;exit;
        break;
    case 6://sitemap url输出
        $ar_url = array();
        $ar_url[] = home_url("/");
        $ar_url[] = home_url("/").'news/';
        $args = array(
            'hide_empty'  => 0
        );
        $categories = get_categories( $args );
        //print_r($categories);exit;
        $per_page_num = get_option('posts_per_page');
        $cat_ids = array();
        foreach($categories as $category){
            //if($category->term_id != 623){
            $cat_ids[] = $category->term_id;
            $categoryid = $category->term_id;
            $category_link = get_category_link( $categoryid );
            $ar_url[] = $category_link;
            if($category->count > $per_page_num){
                $page_count = ceil($category->count/$per_page_num);
                for($i=2;$i<=$page_count;$i++){
                    $ar_url[] = $category_link.'page/'.$i.'/';
                }
            }
            //}
        }
        //gallery 分类
        $gallery_url = get_cate_zdy_url('gallery',$per_page_num);
        if($gallery_url){
            $ar_url = array_merge($ar_url,$gallery_url);
        }
        //download 分类
        $download_url = get_cate_zdy_url('download',$per_page_num);
        if($download_url){
            $ar_url = array_merge($ar_url,$download_url);
        }
        //solution 分类
        $solutions_url = get_cate_zdy_url('solutions',$per_page_num);
        if($solutions_url){
            $ar_url = array_merge($ar_url,$solutions_url);
        }
        //exhibition 分类
        $exhibition_url = get_cate_zdy_url('exhibition',$per_page_num);
        if($exhibition_url){
            $ar_url = array_merge($ar_url,$exhibition_url);
        }
        //video  分类
        $video_url = get_cate_zdy_url('video',$per_page_num);
        if($video_url){
            $ar_url = array_merge($ar_url,$video_url);
        }
        //news 分类
        $news_url = get_cate_zdy_url('news',$per_page_num);
        if($news_url){
            $ar_url = array_merge($ar_url,$news_url);
        }
        query_posts(array( 'post_type' => 'page','showposts' => 5000) ); while (have_posts()) : the_post();
        $ar_url[] = get_permalink($post->ID);
    endwhile; wp_reset_query();
        query_posts(array( 'post_type' => 'news','showposts' => 5000) ); while (have_posts()) : the_post();
        $ar_url[] = get_permalink($post->ID);
    endwhile; wp_reset_query();
        query_posts(array( 'post_type' => 'guide','showposts' => 5000) ); while (have_posts()) : the_post();
        $ar_url[] = get_permalink($post->ID);
    endwhile; wp_reset_query();
        foreach($categories as $category){
            //if($category->term_id != 623){
            query_posts(array( 'cat' => $category->term_id,'post_type' => 'post','showposts' => 10000));while ( have_posts() ) : the_post();
                $ar_url[] = get_permalink($post->ID);
            endwhile; wp_reset_query();
            //}
        }
        $ar_url = array_unique($ar_url);
        echo implode('<br/>',$ar_url);
        echo '<br/>' ;
        $tags = get_tags();
        foreach($tags as $tag){
            echo get_tag_link ($tag->term_id);
            echo '<br/>' ;
        }
        exit;
        break;
    case 66://翻译url输出
        $except_post_type = ['3code','acf','admin','ad_img','attachment','banner','banner-sidebar','banner_sidebar','cf7_entry','dw_license','fl-builder-template','gd-admin','helppage','home','import_users','lianxi','nav_menu_item','p','pro','pro_detail','pro_shuxing','skype','sns','title','transall','v','wpcf7_contact_form','ww','post','page','revision','vs','wp_automatic','qq','xunpan','sitemap','help'];
        $post_types_res = $wpdb->get_results('select post_type from wp_posts group by post_type',ARRAY_A);
        $post_types = [];
        foreach ($post_types_res as $v){
            if(!in_array($v['post_type'],$except_post_type)){
                $post_types[] = $v['post_type'];
            }
        }
        $ar_url = array();
        $ar_url[] = home_url("/");
        $args = array(
            'hide_empty'  => 0
        );

        $categories = get_categories( $args );
        $per_page_num = get_option('posts_per_page');
        $cat_ids = array();
        foreach($categories as $category){
            if($category->name != 'Featured' && $category->name != 'Featured Products'){
                $cat_ids[] = $category->term_id;
                $categoryid = $category->term_id;
                $category_link = get_category_link( $categoryid );
                $ar_url[] = $category_link;
                if($category->count > $per_page_num){
                    $page_count = ceil($category->count/$per_page_num);
                    for($i=2;$i<=$page_count;$i++){
                        $ar_url[] = $category_link.'page/'.$i.'/';
                    }
                }
            }
        }

        if($post_types){
            foreach ($post_types as $v){
                $gallery_url = get_cate_zdy_url($v,$per_page_num);
                if($gallery_url){
                    $ar_url = array_merge($ar_url,$gallery_url);
                }
                $ar_url[] = home_url("/").$v.'/';
                $news_num = count(query_posts(array( 'post_type' => $v,'posts_per_page'=>-1)));
                if($news_num>$per_page_num){
                    $page_count = ceil($news_num/$per_page_num);
                    for($i=2;$i<=$page_count;$i++){
                        $ar_url[] = home_url("/").$v.'/'.'page/'.$i.'/';
                    }
                }

                query_posts(array( 'post_type' => $v,'showposts' => 5000) ); while (have_posts()) : the_post();
                    $ar_url[] = get_permalink($post->ID);
                endwhile; wp_reset_query();
            }
        }
        query_posts(array( 'post_type' => 'page','showposts' => 5000) ); while (have_posts()) : the_post();
			$temp_url=get_permalink($post->ID);
			if(!preg_match('/login|logout|register|lostpassword|resetpass|your-profile/',$temp_url)){
				$ar_url[] = $temp_url;
			}
		endwhile; wp_reset_query();
        $ar_url_cnt = count($ar_url);
        foreach($categories as $category){
            if($category->name != 'Featured' && $category->name != 'Featured Products'){

                query_posts(array( 'cat' => $category->term_id,'post_type' => 'post','showposts' => 10000));while ( have_posts() ) : the_post();
                    $cur_url = get_permalink($post->ID);
                    if(!in_array($cur_url,$ar_url) && $ar_url_cnt <= 30000){
                        $ar_url[] = $cur_url;
                        $ar_url_cnt++;
                    }
                endwhile; wp_reset_query();
            }
        }
        $ar_url = array_unique($ar_url);
        echo implode('<br/>',$ar_url);
        exit;
        break;
    case 666://所有featured tags
        $ar_url = [];
        $posts = $wpdb->get_results("select * from wp_term_relationships where term_taxonomy_id=635");
        if($posts){
            $ar_url[] = home_url('/').'featured/';
            foreach($posts as $post){
                $ar_url[] = get_permalink($post->object_id);
            }
        }
        $tags = get_tags();
        foreach($tags as $tag){
            $ar_url[] = get_tag_link ($tag->term_id);
        }
        if($ar_url){
            print_r(implode("<br/>",$ar_url));exit;
        }
        break;
    case 6666://featured 分页
        $ar_url = [];
        $ar_url[] = home_url('/').'featured/';
        $per_page_num = get_option('posts_per_page');
        $posts = $wpdb->get_row("select count(*) as cnt from wp_term_relationships where term_taxonomy_id=635");
        if($posts->cnt > $per_page_num){
            for($i=2;$i<ceil($posts->cnt/$per_page_num);$i++){
                $ar_url[] = home_url('/').'featured/page/'.$i;
            }
        }
        print_r(implode("<br/>",$ar_url));exit;
        break;
    case 7://更新多语言关闭按钮和 email
        echo 1;exit;
        break;
    case 77://社交验证信息清除
        $wpdb->query("delete from wp_b2s_user");
        echo 200;exit;
        break;
    case 78://社交验证信息清除
        $wpdb->query("DELETE  FROM `wp_b2s_user` WHERE `token` = 'v3_RWhUMEVIVG1CVFgzMnpFTU5QWGtuWGFxYXpjMTVtK2pVWDJjejM1c2dEVWlPUTEvY2tQUkVTRmxNbnhBbE83aWEyZzYwc081dWtwUU84dHBHRHdUNlk2dW91MGlsYjU5aFR3RFlaRjVjNTlWL2NLTnBZK1BMZmRGdlR0YkszVnZMVTJNL1RNMFJXckpzejdoa0luNGR3PT06OjlnNEJWRC9WdnExSU0yMUU,'");
        echo 200;exit;
        break;
    case 200://更新程序文件
        $way = $_GET['ways'];
        if($way == 2){
            $new_version = '5.1';
        }elseif($way == 3){
            $new_version = '5.2';
        }elseif($way == 4){
            $new_version = '4.1';
        }
        $url="http://www.quanqiusou.cn/cms-update/".urlencode(iconv("GB2312","UTF-8","update".$new_version.".zip"));
        $save_dir = __DIR__.'/';
        $dir_path = downFile($url, $save_dir);
        $z = new Unzip();
        $res = $z->unzip($dir_path,'./', true, true);
        if($res){
            echo 200;exit;
        }else{
            echo 4;exit;
        }
        break;
	case 'rsync':
		/* 执行rsync同步到正式站 start */
		$domain = parse_url(home_url());
		if(strpos($domain['host'],'goodao.net') !== false || strpos($domain['host'],'quanqiusou.cn') !== false){
			$shell_ar = file_get_contents("http://www.quanqiusou.cn/extend_api/api/rsync.txt");
			$shell_ar = explode("\n",$shell_ar);
			foreach ($shell_ar as $v){
				if($v){
					$v = trim($v);
					if(strpos($v,$domain['host']) !== false || strpos($v,str_replace('.','_',$domain['host'])) !== false){
						$ar_info = explode('|',$v);
						shell_exec('rsync -avu --progress /www/wwwroot/'.$ar_info[0].'/wp-content/cache/all/ root@'.$ar_info[1].' > /dev/null 2>&1 &');
						shell_exec('rsync -avu --progress /www/wwwroot/'.$ar_info[0].'/uploads/ root@'.$ar_info[1].'-uploads > /dev/null 2>&1 &');
						global $wpdb;
						$file_info = $wpdb->get_row("SELECT * FROM wp_posts where post_type='attachment' order BY post_date DESC LIMIT 1",ARRAY_A);
						$new_media_time = get_option('cdn_file_update_time');
						if(!$new_media_time){
							update_option('cdn_file_update_time',$file_info['post_date']);
							shell_exec('rsync -avu --progress /www/wwwroot/'.$ar_info[0].'/uploads/ root@1.116.183.193::cdn-'.$ar_info[2].'-uploads > /dev/null 2>&1 &');
						}else{
							if($new_media_time<$file_info['post_date']){
								update_option('cdn_file_update_time',$file_info['post_date']);
								shell_exec('rsync -avu --progress /www/wwwroot/'.$ar_info[0].'/uploads/ root@1.116.183.193::cdn-'.$ar_info[2].'-uploads > /dev/null 2>&1 &');
							}
						}
					}
				}
			}
		}
		/* 执行rsync同步到正式站 end */
		$wpdb->query("delete FROM wp_term_relationships where term_taxonomy_id=496 AND object_id NOT in (SELECT ID FROM wp_posts where post_type='post')");
		echo 200;exit;
    case 'update_tags'://更新archive-tags.php 文件
        $path = get_stylesheet_directory().'/';
        $tags_file = file_get_contents(ABSPATH.'wp-content/archive-tags.php');
        if($tags_file){
            file_put_contents($path.'archive-tags.php',$tags_file);
            echo 200;exit;
        }
        echo 1;exit;
        break;
    case 'visit_detail'://访问明细接口
        $page = 1;
        if(isset($_GET['page']) && $_GET['page']){
            $page = $_GET['page'];
        }
        $pagesize = 200;
        $start = ($page-1)*$pagesize;
        $count = $wpdb->get_row("SELECT count(id) as cnt FROM `wp_stats_day_ip`",ARRAY_A);
        $lists = $wpdb->get_results("SELECT * FROM `wp_stats_day_ip` ORDER BY `id` DESC limit $start,$pagesize",ARRAY_A);
        $data['list'] = $lists;
        $data['count'] = $count['cnt'];
        print_r(json_encode($data));exit;
        break;
	case 'inquiry_new'://精准询盘新接口
        $page = 1;
        if(isset($_GET['page']) && $_GET['page']){
            $page = $_GET['page'];
        }
        $pagesize = 20;
		if(isset($_GET['pagesize']) && $_GET['pagesize']){
            $pagesize = $_GET['pagesize'];
        }
		$cf7_id = 19;
		if(isset($_GET['cf7_id']) && $_GET['cf7_id']){
            $cf7_id = $_GET['cf7_id'];
        }
        $start = ($page-1)*$pagesize;
        $count = $wpdb->get_row("SELECT count(*) as cnt FROM wp_cf7_data",ARRAY_A);
        $list_ids = $wpdb->get_results("SELECT * FROM wp_cf7_data_entry where cf7_id=cf7_id group by data_id ORDER BY `id` DESC limit $start,$pagesize",ARRAY_A);
        $ids = array_column($list_ids,'data_id');
        //echo implode(',',$ids);exit;
        $lists = [];
        $lists_data = $wpdb->get_results("SELECT * FROM wp_cf7_data_entry where data_id in(".implode(',',$ids).") ",ARRAY_A);
        foreach($ids as $id){
            $tmp['name'] = $tmp['submit_ip'] = $tmp['submit_time'] = $tmp['refer'] = $tmp['email'] = $tmp['phone'] = $tmp['message'] = $tmp['ip_area'] = $tmp['readed'] ='';
            foreach ($lists_data as $vv){
                if($id == $vv['data_id']){

                    if($vv['name'] == 'Name'){
                        $tmp['name'] = $vv['value'];
                    }
                    if($vv['name'] == 'Phone'){
                        if($vv['value']){
                            $tmp['phone'] = $vv['value'];
                        }
                    }
                    if($vv['name'] == 'Email'){
                        $tmp['email'] = $vv['value'];
                    }
                    if($vv['name'] == 'submit_ip'){
                        $tmp['submit_ip'] = $vv['value'];
                    }
                    if($vv['name'] == 'submit_time'){
                        $tmp['submit_time'] = $vv['value'];
                    }
                    if($vv['name'] == 'refer'){
                        $tmp['refer'] = $vv['value'];
                    }
                    if($vv['name'] == 'ip_area'){
                        $tmp['ip_area'] = $vv['value'];
                    }
                    if($vv['name'] == 'Message'){
                        $tmp['message'] = $vv['value'];
                    }
                    if($vv['name'] == 'readed'){
                        $tmp['readed'] = $vv['value'];
                    }
                }
            }
            if(empty($tmp['ip_area'])){
                $tmp['ip_area'] = file_get_contents('http://ip.globalso.com?ip='.$tmp['submit_ip']);
            }
            $lists[] = $tmp;
        }
		$data['code'] = 200;
        $data['data'] = $lists;
        $data['count'] = $count['cnt'];
        print_r(json_encode($data));exit;
        break;
    case 'inquiry'://精准询盘接口
        $page = 1;
        if(isset($_GET['page']) && $_GET['page']){
            $page = $_GET['page'];
        }
        $pagesize = 20;
        $start = ($page-1)*$pagesize;
        $count = $wpdb->get_row("SELECT count(*) as cnt FROM wp_cf7_data",ARRAY_A);
        $list_ids = $wpdb->get_results("SELECT * FROM wp_cf7_data_entry where cf7_id=19 group by data_id ORDER BY `id` DESC limit $start,$pagesize",ARRAY_A);
        $ids = array_column($list_ids,'data_id');
        //echo implode(',',$ids);exit;
        $lists = [];
        $lists_data = $wpdb->get_results("SELECT * FROM wp_cf7_data_entry where data_id in(".implode(',',$ids).") ",ARRAY_A);
        foreach($ids as $id){
            $tmp['name'] = $tmp['submit_ip'] = $tmp['submit_time'] = $tmp['refer'] = $tmp['email'] = $tmp['phone'] = $tmp['message'] = $tmp['ip_area'] = '';
            foreach ($lists_data as $vv){
                if($id == $vv['data_id']){

                    if($vv['name'] == 'Name'){
                        $tmp['name'] = $vv['value'];
                    }
                    if($vv['name'] == 'Phone'){
                        if($vv['value']){
                            $tmp['phone'] = substr($vv['value'],0,4).'***';
                        }
                    }
                    if($vv['name'] == 'Email'){
                        $tmp['email'] = substr($vv['value'],0,4).'***';
                    }
                    if($vv['name'] == 'submit_ip'){
                        $tmp['submit_ip'] = $vv['value'];
                    }
                    if($vv['name'] == 'submit_time'){
                        $tmp['submit_time'] = $vv['value'];
                    }
                    if($vv['name'] == 'refer'){
                        $tmp['refer'] = $vv['value'];
                    }
                    if($vv['name'] == 'ip_area'){
                        $tmp['ip_area'] = $vv['value'];
                    }
                    if($vv['name'] == 'Message'){
                        $tmp['message'] = $vv['value'];
                    }
                    if($vv['name'] == 'readed'){
                        $tmp['readed'] = $vv['value'];
                    }
                }
            }
            if(empty($tmp['ip_area'])){
                $tmp['ip_area'] = file_get_contents('http://ip.globalso.com?ip='.$tmp['submit_ip']);
            }
            $lists[] = $tmp;
        }
        $data['list'] = $lists;
        $data['count'] = $count['cnt'];
        print_r(json_encode($data));exit;
        break;
    case 'case_home'://案例首页数据
        $count = $wpdb->get_row("SELECT count(*) as cnt FROM wp_cf7_data",ARRAY_A);
        $count_90 = $wpdb->get_row("SELECT count(*) as cnt FROM wp_cf7_data where created > '".date("Y-m-d 00:00:00",time()-86400*90)."'",ARRAY_A);
        $totol_ip = $wpdb->get_row("select count(id) t_ip, sum(pv) t_pv from wp_stats_day_ip where is_spider=1",ARRAY_A);
        $data['total_ip'] = (int)$totol_ip['t_ip'];
        $data['total_pv'] = (int)$totol_ip['t_pv'];
        $data['inquiry_conut'] = $count['cnt'];
        $data['inquiry_conut_90'] = $count_90['cnt'];
        print_r(json_encode($data));exit;
        break;
    case 'get_company_product'://返回公司信息 及部分产品信息。dst帝释天
        $args = array(
            'hide_empty'  => 0
        );
        $weburl = home_url('/');
        $ar = [];
        $categories = get_categories( $args );
        $excpt = [];
        $product_service=[];
        if($categories){
            if(count($categories)>10){
                foreach($categories as $k=>$v){
                    if($v->name != 'Featured' && $v->name != 'Featured Products'){
                        if(count($product_service)<11){
                            array_push($product_service,$v->name);
                        }
                        $posts = query_posts(array('post_type' => 'post','category__in'=> array($v->term_id),'showposts' => 2));
                        while ( have_posts() ) : the_post();
                            $str_img= get_field('product_gallery');
                            if($str_img){
                                $arr_img=array();
                                foreach ($str_img as $vo){
                                    if($vo['url']){
                                        array_push($arr_img,$vo['url']);
                                    }
                                }
                                if($arr_img){
                                    $str_img=implode(',',$arr_img);
                                }else{
                                    $str_img='';
                                }
                            }
                            $ar[] = array(
                                'product_name'=>$post->post_title,
                                'product_type'=>$v->name,
                                'product_url'=>$post->guid,
                                'product_img'=>$str_img,
                                'is_show'=>2,
                            );

                        endwhile; wp_reset_query();

                    }
                }
            }else{
                foreach($categories as $k=>$v){
                    if($v->name != 'Featured' && $v->name != 'Featured Products'){
                        array_push($product_service,$v->name);
                        $posts = query_posts(array('post_type' => 'post','category__in'=> array($v->term_id),'showposts' => 5));
                        while ( have_posts() ) : the_post();
                            $str_img= get_field('product_gallery');
                            if($str_img){
                                $arr_img=array();
                                foreach ($str_img as $vo){
                                    if($vo['url']){
                                        array_push($arr_img,$vo['url']);
                                    }
                                }
                                if($arr_img){
                                    $str_img=implode(',',$arr_img);
                                }else{
                                    $str_img='';
                                }
                            }
                            $ar[] = array(
                                'product_name'=>$post->post_title,
                                'product_type'=>$v->name,
                                'product_url'=>$post->guid,
                                'product_img'=>$str_img,
                                'is_show'=>2,
                            );

                        endwhile; wp_reset_query();

                    }
                }
            }

        }

        $cimgs=get_post_meta(50,'about_us_image',true);
        $cmpurl='';
        if($cimgs){
            if(is_array($cimgs)){
                $cmpurl=     get_post_meta($cimgs[0],'_wp_attached_file',true);

            }else{
                $cmpurl=     get_post_meta($cimgs,'_wp_attached_file',true);

            }
        }else{
            $cimgs=get_post_meta(50,'about_img',true);
            if($cimgs){

                if(is_array($cimgs)){
                    $cmpurl=     get_post_meta($cimgs[0],'_wp_attached_file',true);


                }else{
                    $cmpurl=     get_post_meta($cimgs,'_wp_attached_file',true);
                }

            }
        }
        $company_info=array(
            'company'=> get_post_meta(50,'lianxi_company',true),
            'company_img'=>$weburl.'uploads/'.$cmpurl,
            'company_logo'=>$weburl.'uploads/'.get_post_meta(get_post_meta(50,'ad_logo',true),'_wp_attached_file',true),
            'main_markets'=> 'Africa , Americas , Asia , Middle East , Worldwide',
            'showroom'=> $weburl,
            'website'=> $weburl,
            'is_show'=> 2,
            'product_service'=> implode(',',$product_service),
            'company_address'=> get_post_meta(50,'lianxi_adress',true),
            'registration_info'=> get_post_meta(50,'about_text',true),
        );
        echo json_encode(['company'=>array_filter($company_info),'product'=>array_filter($ar)]);

        break;
	//更新流量统计数据日和月数据
	case 'update_status_day_month':
		$month  = $_GET['month']?$_GET['month']:date("Y-m");
		$start = $month.'-01';
		$end = date('Y-m-01',strtotime('+1 month',strtotime($start)));
		$all_days = $wpdb->get_results("select * from wp_stats_day_count where day>='".$start."' and day<'".$end."' ",ARRAY_A);
		foreach ($all_days as $v){
			$res = $wpdb->get_row("select sum(pv) as pv,count(ip) as ip,sum(uv) as uv from wp_stats_day_ip where day='".$v['day']."'",ARRAY_A);
			if($res['pv'] != $v['pv'] || $res['ip'] != $v['ip'] || $res['uv'] != $v['uv']){
				$wpdb->query("update wp_stats_day_count set pv=".$res['pv'].",ip=".$res['ip'].",uv=".$res['uv']." where day='".$v['day']."'");
			}
		} 
		$month_data = $wpdb->get_row("select * from wp_stats_moth_count where year=".date("Y",strtotime($start))." and moth=".date("m",strtotime($start)),ARRAY_A);
		$count_month_data = $wpdb->get_row("select sum(pv) as pv,count(ip) as ip,sum(uv) as uv from wp_stats_day_ip where day>='".$start."' and day<'".$end."'",ARRAY_A);
		if($month_data['pv'] != $count_month_data['pv'] || $month_data['ip'] != $count_month_data['ip'] || $month_data['uv'] != $count_month_data['uv']){
			$wpdb->query("update wp_stats_moth_count set pv=".$count_month_data['pv'].",ip=".$count_month_data['ip'].",uv=".$count_month_data['uv']." where year=".date("Y",strtotime($start))." and moth=".date("m",strtotime($start)));
		}
		echo 200;
		break;
	//更新流量统计日统计数据
	case 'update_stats':
		$data = $wpdb->get_results("SELECT day FROM `wp_stats_day_count`" ,ARRAY_A);
		$result = array_reduce($data, function ($result, $value) {return array_merge($result, array_values($value));}, array());
		$table = "wp_stats_day_count";
		$repeat_no = getRepeat($result);
		foreach($repeat_no as $v){
			$value = $wpdb->get_results("SELECT * FROM `wp_stats_day_count` WHERE `day` = '$v'" ,ARRAY_A);
			$value_v = $value[0];
			$wpdb->query("DELETE FROM `wp_stats_day_count` WHERE `day` = '$v'");
			$data_array = array( 'day' => $value_v['day'], 'ip' => $value_v['ip'], 'pv' => $value_v['pv'], 'uv' => $value_v['uv'], 'updatetime' => $value_v['updatetime']);
			$wpdb->insert($table,$data_array);
		  }
		$wpdb->query("ALTER TABLE `wp_stats_day_count` ADD UNIQUE(`day`);");
		echo 200;
		break;
	//小语言产品匹配
    case 'match_products':
        $temp_title=$_GET['keywords'];
        $args = [];
        $categories = get_categories($args);
        $excpt = [];
        $product_featured = [];//首页产品分类
        if ($categories) {
            foreach ($categories as $k => $v) {
                if ($v->name == 'Featured'||$v->name=='Featured Products') {
                    $excpt[] = $v->term_id;
                }
                // if ($v->name == 'Featured Products') {
                //     $product_featured[] = $v->term_id;
                // }
            }
        }
        $args = array(
            's' => $temp_title,
            'paged' => '-1',
            //'category__not_in'=>$excpt,
            'meta_key' => '_listorder',
            'post_type' => 'post',
            'post_status' => 'publish',
            'orderby' => 'rand',
            'showposts' => '7'
        );
        if ($excpt) {
            $args['category__not_in'] = $excpt;
        }

        $query = query_posts($args);//整个关键词匹配产品

        $product_arr = [];//关键词匹配产品
        $pid = [];

        $num = count($query);//匹配产品个数
        if ($num < 7) {//匹配产品大于0小于7个
            if ($query) {
                foreach ($query as $vo) {
                    $product_arr[] = $vo;
                    $pid[] = $vo->ID;
                }
            }

            $kw_arr = array_filter(explode(' ', $temp_title));//切分为单个词语
            $word_num = count($kw_arr);//单词数

            if ($word_num > 1) {//关键词单词数大于1
                if (count($product_arr) < 7) {
                    for ($i = 1; $i < $word_num; $i++) {//从前往后每次少一个单词
                        if (count($product_arr) == 7) {
                            continue;
                        }
                        $ms = implode(' ', array_slice($kw_arr, $i));//从前往后少一个word匹配

                        $args = array(
                            's' => $ms,
                            'post__not_in' => $pid,
                            'paged' => '-1',
                            'meta_key' => '_listorder',
                            'post_type' => 'post',
                            'orderby' => 'rand',
                            'post_status' => 'publish',
                            'showposts' => 7 - count($product_arr)
                        );
                        if ($excpt) {
                            $args['category__not_in'] = $excpt;
                        }
                        $query = query_posts($args);//关键词匹配产品
                        if ($query) {
                            foreach ($query as $vo) {
                                $product_arr[] = $vo;
                                $pid[] = $vo->ID;
                            }
                        }
                    }
                }
                if (count($product_arr) < 7) {
                    for ($j = $word_num - 1; $j > 0; $j--) {
                        if (count($product_arr) == 7) {
                            continue;
                        }
                        $ms = implode(' ', array_slice($kw_arr, 0, $j));///从后往前少一个word匹配
                        $args = array(
                            's' => $ms,
                            'post__not_in' => $pid,
                            'paged' => '-1',
                            'meta_key' => '_listorder',
                            'post_type' => 'post',
                            'orderby' => 'rand',
                            'post_status' => 'publish',
                            'showposts' => 7 - count($product_arr)
                        );
                        if ($excpt) {
                            $args['category__not_in'] = $excpt;
                        }
                        $query = query_posts($args);//关键词匹配产品

                        if ($query) {
                            foreach ($query as $vo) {
                                $product_arr[] = $vo;
                                $pid[] = $vo->ID;
                            }
                        }
                    }
                }

                if (count($product_arr) < 7) {
                    for ($i = 1; $i < $word_num - 1; $i++) {
                        if (count($product_arr) == 7) {
                            continue;
                        }
                        $ms = $kw_arr[$i - 1];////从第二个单词到最后第二个单词,从往前后每次取一个单词
                        $args = array(
                            's' => $ms,
                            'post__not_in' => $pid,
                            'paged' => '-1',
                            'meta_key' => '_listorder',
                            'post_type' => 'post',
                            'orderby' => 'rand',
                            'post_status' => 'publish',
                            'showposts' => 7 - count($product_arr)
                        );
                        if ($excpt) {
                            $args['category__not_in'] = $excpt;
                        }
                        $query = query_posts($args);//关键词匹配产品

                        if ($query) {
                            foreach ($query as $vo) {
                                $product_arr[] = $vo;
                                $pid[] = $vo->ID;
                            }
                        }
                    }
                }
            }

            if (count($product_arr) < 7) {//匹配后产品数仍然小于7个,随机 7-已匹配产品个数

                $args = array(
                    'post__not_in' => $pid,
                    'paged' => '-1',
                    'orderby' => 'rand',
                    'meta_key' => '_listorder',
                    'post_type' => 'post',
                    'post_status' => 'publish',
                    'showposts' => 7 - count($product_arr)

                );
                if ($excpt) {
                    $args['category__not_in'] = $excpt;
                }
                $query = query_posts($args);//关键词匹配产品

                if ($query) {
                    foreach ($query as $vo) {
                        $product_arr[] = $vo;
                        $pid[] = $vo->ID;
                    }
                }
            }


        } else {
            $product_arr = array_slice($query, 0, 7);//取前7个产品
            foreach ($product_arr as $vo) {
                $pid[] = $vo->ID;
            }
        }
  
        foreach ($product_arr as $key=>$vo){
            
            
                $link_url =get_permalink($vo->ID);
                $iamge1 = get_field('product_gallery', $vo->ID);


                        if(!$iamge1[0]['url']){
                            foreach( $iamge1 as $key=>$image ){

                                if(!is_array($iamge1[$key])){
                                    $eric_id = $image;
                                    $eric_urcs = wp_get_attachment_image_src($eric_id, $size='full');
                                    $eric_urc = $eric_urcs[0];
                                    $image = array(
                                        'id' => $eric_id,
                                        'url' => $eric_urc,
                                        'sizes' => array('thumbnail' => $eric_urc)
                                    );
                                    $iamge1[$key] = $image;

                                }
                            }


                        }
                         $product_arr[$key]->image=$iamge1;
                         $product_arr[$key]->link_url=$link_url;
          
        }   

        //随机12个产品
        $args = array(
            'post__not_in' => $pid,
            'paged' => '-1',
            'orderby' => 'rand',
            'meta_key' => '_listorder',
            'post_type' => 'post',
            'post_status' => 'publish',
            'showposts' => 12
        );
        if ($excpt) {
            $args['category__not_in'] = $excpt;//
        }
        $rand_product = query_posts($args);//关键词匹配产品

        foreach ($rand_product as $key=>$vo){
            
            
                $link_url =get_permalink($vo->ID);
                $iamge1 = get_field('product_gallery', $vo->ID);


                        if(!$iamge1[0]['url']){
                            foreach( $iamge1 as $key=>$image ){

                                if(!is_array($iamge1[$key])){
                                    $eric_id = $image;
                                    $eric_urcs = wp_get_attachment_image_src($eric_id, $size='full');
                                    $eric_urc = $eric_urcs[0];
                                    $image = array(
                                        'id' => $eric_id,
                                        'url' => $eric_urc,
                                        'sizes' => array('thumbnail' => $eric_urc)
                                    );
                                    $iamge1[$key] = $image;

                                }
                            }
                        }
                         $rand_product[$key]->image=$iamge1;
                         $rand_product[$key]->link_url=$link_url;
        }   

       $tar=array(' - <i>Factory, Suppliers, Manufacturers from China</i>', ' - <i>China Factory, Suppliers, Manufacturers</i>', ' - </i>China Manufacturers, Factory, Suppliers</i>', ' - <i>China Manufacturers, Suppliers, Factory</i>', ' - <i>Manufacturers, Factory, Suppliers from China</i>', ' - <i>Manufacturers, Suppliers, Factory from China</i>');
       $desc[]=$tar[mt_rand(0,count($tar)-1)] ;
       
       $desc[]=do_shortcode('[rand_pre]').'&&&'.', '.do_shortcode('[rand_suffix]').'The product will supply to all over the world, such as Europe, America, Australia,'.do_shortcode('[rand_country]').', '.do_shortcode('[rand_country]').', '.do_shortcode('[rand_country]').', '.do_shortcode('[rand_country]').do_shortcode('[rand_l_suffix]');
   
       global $eric_g_id;
        if($eric_g_id){
            $post_id = $eric_g_id;
        }else{
            global $wpdb;
            $res = $wpdb->get_row("SELECT ID FROM $wpdb->posts  WHERE post_status='publish' and post_type='ad_img' ORDER BY post_date DESC LIMIT 0,1");
            if(!$res) return false;
            $post_id = $res->ID;
        }
       $banner_arr =get_field('ad_index_banner', $post_id);
           function create_news_video(){//创建表存储 关键词爬取的谷歌新闻及youtobe视频
                global $wpdb;
                $tb_flag = 'wp_news_video';
                $is_exist= $wpdb->query('SHOW TABLES LIKE "' . $tb_flag . '"');//是否存在表
                if(!$is_exist){//不存在表,创建表
                    $table_flag=$wpdb->query("CREATE TABLE IF NOT EXISTS `wp_news_video` (`id` int(11) NOT NULL AUTO_INCREMENT,`term` varchar(512) DEFAULT NULL COMMENT '关键词',`term_id` int(11) DEFAULT NULL COMMENT '关键词表id', `kcontent` longtext COMMENT '爬取返回数据', `stime` datetime DEFAULT NULL COMMENT '保存时间',PRIMARY KEY (`id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC");
//                    var_dump($table_flag);die();
                    if($table_flag){//表创建成功
                        setcookie("wp_news_video", true,time()+3600*24*365);
                    }
                }
            }
            if(!$_COOKIE["wp_news_video"]){//判断创建表
                create_news_video();
            }
            $gnews=[];
            $yvideo=[];
            //判断是否为空
            if(trim($temp_title)){
                $term=get_term_by('slug',sanitize_title(trim($temp_title)),'post_tag');//获取关键词id
                //    var_dump($term);die();
                global $wpdb;
                $news_data= $wpdb->get_row($wpdb->prepare( "SELECT * FROM wp_news_video WHERE term_id = %d", $term->term_id), ARRAY_A );

                $current_domain=$_SERVER['HTTP_HOST'];
                // var_dump($news_data);die();
                if($news_data){//数据已存在
                    //判断时间 7天
                    $ntime=time()-(7*24*3600);
                    if(strtotime($news_data['stime'])>$ntime){//未超期
                        $news_video=$news_data['kcontent'];
                    }else{

                        //获取关键词新闻及视频
                        $current_domain=$_SERVER['HTTP_HOST'];
                        //            var_dump($current_domain);
                        //            echo('<br/>');
                        //  $current_domain='www.donsen.com';
                        $kw=urlencode(trim($temp_title));//关键词
                        //            var_dump($kw);
                        //            echo('<br/>');
                        // $kw='Pvc%20Bypass%20Bend';//关键词

                        $kurl='http://api.quanqiusou.cn/google-rank/get_tags_info.php?keyword='.$kw.'&url='.$current_domain;
                        $news_video= @file_get_contents($kurl);
                        $news_video=$news_video?$news_video:'';
                        $rd=$wpdb->query($wpdb->prepare("UPDATE wp_news_video SET kcontent=%s,stime=%s WHERE id = %d",$news_video,date('Y-m-d H:i:s'),$news_data['id']));

                    }

                }else{

                    //获取关键词新闻及视频

                    //            var_dump($current_domain);
                    //            echo('<br/>');
                    //  $current_domain='www.donsen.com';
                    $kw=urlencode(trim($temp_title));//关键词
                    //            var_dump($kw);
                    //            echo('<br/>');
                    // $kw='Pvc%20Bypass%20Bend';//关键词

                    $kurl='http://api.quanqiusou.cn/google-rank/get_tags_info.php?keyword='.$kw.'&url='.$current_domain;

                    $news_video= @file_get_contents($kurl);

                    $news_video=$news_video?$news_video:'';
                    if($news_video){
                        global $wpdb;//再次查询
                        $news_data= $wpdb->get_row($wpdb->prepare( "SELECT * FROM wp_news_video WHERE term_id = %d", $term->term_id), ARRAY_A );

                        if(!$news_data){

                            $wpdb->query($wpdb->prepare("INSERT INTO wp_news_video (term,term_id,kcontent,stime) VALUES (%s,%d,%s,%s)",$term->name,$term->term_id,$news_video,date('Y-m-d H:i:s')));

                        }else{

                            $wpdb->query($wpdb->prepare("UPDATE wp_news_video SET kcontent=%s,stime=%s WHERE id = %d",$news_video,date('Y-m-d H:i:s'),$news_data['id']));
                        }
                    }
                }


                if($news_video){//
                    $news_video_arr=json_decode($news_video,true);
                    if(isset($news_video_arr['news'])&&$news_video_arr['news']){
                        $gnews=$news_video_arr['news'];
                    }
                    if(isset($news_video_arr['videos'])&&$news_video_arr['videos']){
                        $yvideo=$news_video_arr['videos'];
                    }
                }
            }
          function randTimes($startime, $endtime, $is = true, $num = 6)
                                {//生成随机评论时间
                                    $i = 0;
                                    $begin = strtotime($startime);
                                    $end = strtotime($endtime);
                                    $array = array();
                                    while ($i < $num) {
                                        $date = rand($begin, $end);
                                        $array[] = $is ? date("Y.m.d H:i:s", $date) : $date;
                                        $i++;
                                    }
                                    rsort($array);
                                    return $array;
                                }

         $name_arr = randTimes('2021-01-12 09:00:00', '2022-01-11 09:59:59', true, 6);//生成6条随机评论时间
         
         $comment=[];
         foreach ($name_arr as $k=>$v){
           $comment[$k]['time']  =$v;
            $comment[$k]['rand_feedback_name']  =do_shortcode('[rand_feedback_name]');
            $comment[$k]['rand_feedback']  =do_shortcode('[rand_feedback]');
         }
       
       
       
        echo json_encode(array($banner_arr,$desc,$product_arr,$rand_product,$gnews,$yvideo,$comment));

         break;
    default: //输出分类、产品的链接和名称
        $args = array(
            'hide_empty'  => 0
        );
        $weburl = home_url('/');
        $ar = [];
        $categories = get_categories( $args );
        $excpt = [];
        if($categories){
            foreach($categories as $k=>$v){
                if($v->name != 'Featured' && $v->name != 'Featured Products'){
                    $ar[] = get_category_link($v->term_id).'|'.$v->name;
                }else{
                    $excpt[] = $v->term_id;
                }
            }
        }
        if($excpt){
            $posts = query_posts(array('post_type' => 'post','category__not_in'=> $excpt,'showposts' => 10000));while ( have_posts() ) : the_post();
                $ar[] = get_permalink($post->ID).'|'.$post->post_title;
            endwhile; wp_reset_query();
        }else{
            $posts = query_posts(array('post_type' => 'post','showposts' => 10000));while ( have_posts() ) : the_post();
                $ar[] = get_permalink($post->ID).'|'.$post->post_title;
            endwhile; wp_reset_query();
        }
        print_r(json_encode($ar));exit;
}
//获取自定义分类url
function get_cate_zdy_url($cat_type = 'news',$per_page_num = 0,$has_parent = 1){
    $count_g = 0;
	$taxnomy = $cat_type.'_catalog';
    $arg = array(
        'taxonomy' => $taxnomy,
        'orderby' => 'name',
        'show_count' => 1,
        'pad_counts' => 0,
        'hierarchical' => 0
    );
    $ar_url = array();
    $categories = get_categories( $arg );
    if(isset($categories['errors'])){
        return $ar_url;
    }
    foreach($categories as $category){
        $categoryid = $category->term_id;
		$category_link = home_url("/").$cat_type.'_catalog/'.$category->slug.'/';
        $ar_url[] = $category_link;
        if($category->count > $per_page_num){
            $page_count = ceil($category->count/$per_page_num);
            for($i=2;$i<=$page_count;$i++){
                $ar_url[] = $category_link.'page/'.$i.'/';
            }
        }
        if($has_parent == 0){
            $count_g += $category->count;
        }
    }
    if($has_parent == 0){
        $ar_url[] = home_url("/").$cat_type.'/';
        $g_page_count = ceil($count_g/$per_page_num);
        for($i=2;$i<=$g_page_count;$i++){
            $ar_url[] = home_url("/").$cat_type.'/page/'.$i.'/';
        }
    }
    return $ar_url;
}
class Unzip{
    public function __construct(){
        header("content-type:text/html;charset=utf8");
    }
    public function unzip($src_file, $dest_dir=false, $create_zip_name_dir=true, $overwrite=true){
        if ($zip = zip_open($src_file)){
            if ($zip){
                $splitter = ($create_zip_name_dir === true) ? "." : "/";
                if($dest_dir === false){
                    $dest_dir = substr($src_file, 0, strrpos($src_file, $splitter))."/";
                }
                // 如果不存在 创建目标解压目录
                $this->create_dirs($dest_dir);
                // 对每个文件进行解压
                while ($zip_entry = zip_read($zip)){
                    // 文件不在根目录
                    $pos_last_slash = strrpos(zip_entry_name($zip_entry), "/");
                    if ($pos_last_slash !== false){
                        // 创建目录 在末尾带 /
                        $this->create_dirs($dest_dir.substr(zip_entry_name($zip_entry), 0, $pos_last_slash+1));
                    }

                    // 打开包
                    if (zip_entry_open($zip,$zip_entry,"r")){
                        // 文件名保存在磁盘上
                        $file_name = $dest_dir.zip_entry_name($zip_entry);
                        // 检查文件是否需要重写
                        if ($overwrite === true || $overwrite === false && !is_file($file_name)){
                            // 读取压缩文件的内容
                            $fstream = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
                            @file_put_contents($file_name, $fstream);
                            // 设置权限
                            chmod($file_name, 0755);

                        }

                        // 关闭入口
                        zip_entry_close($zip_entry);
                    }
                }
                // 关闭压缩包
                zip_close($zip);
            }
        }else{
            return false;
        }
        return true;
    }
    /**
     * 创建目录
     */
    public function create_dirs($path){
        if (!is_dir($path)){
            $directory_path = "";
            $directories = explode("/",$path);
            array_pop($directories);
            foreach($directories as $directory){
                $directory_path .= $directory."/";
                if (!is_dir($directory_path)){
                    mkdir($directory_path);
                    chmod($directory_path, 0755);
                }
            }
        }
    }

}
function file_exists_zdy($url) {
    $curl = curl_init($url);
    // 不取回数据
    curl_setopt($curl, CURLOPT_NOBODY, true);
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
    // 发送请求
    $result = curl_exec($curl);
    $found = 0;
    // 如果请求没有发送失败
    if ($result !== false) {
        // 再检查http响应码是否为200
        $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
        if ($statusCode == 200) {
            $found = 1;
        }
    }
    curl_close($curl);
    return $found;
}
function downFile($url,$path){
    $arr = parse_url($url);
    $fileName = basename($arr['path']);
    $file = file_get_contents($url);
    file_put_contents($path.$fileName,$file);
    return $path.$fileName;
}

function getRepeat($arr) {
    $unique_arr = array_unique ( $arr );   
    $repeat_arr = array_diff_assoc ( $arr, $unique_arr );
    return $repeat_arr;
}