File "llms.php"
Full Path: /www/wwwroot/shphe-en.com/admin/llms.php
File size: 11.72 KB
MIME-type: --
Charset: utf-8
<?php
require_once( dirname(__FILE__) . '/../wp-load.php' );
global $wpdb;
$txt_content = '';
$dir_llms = ABSPATH.'llms.txt';
$home_url = home_url('/');
$show_domain = $home_url;
$is_split = 0;
if(strpos($home_url,'quanqiusou.cn') !== false || strpos($home_url,'goodao.net') !== false){
$cdn_setting = get_option("gd_cdn_setting");
$cdn_weburl = $cdn_setting['weburl'];
$show_domain = $cdn_weburl;
$is_split = 1;
$dir_llms = ABSPATH.'wp-content/cache/all/llms.txt';
}
$aioseop_options = get_option('aioseop_options');
if(isset($aioseop_options['aiosp_home_title'])){
$txt_content .='# '.$aioseop_options['aiosp_home_title'].PHP_EOL.PHP_EOL;
}
if(isset($aioseop_options['aiosp_home_description'])){
$txt_content .='> '.$aioseop_options['aiosp_home_description'].PHP_EOL.PHP_EOL;
}
$company = get_post_meta(50,'lianxi_company',true);
if($company){
$txt_content .='### Company'.PHP_EOL.$company.PHP_EOL.PHP_EOL;
}
$description = get_post_meta(50,'about_text',true);
if($description){
$description = html_to_str($description,10000);
$txt_content .='### Description'.PHP_EOL.$description.PHP_EOL.PHP_EOL;
}
$address = get_post_meta(50,'lianxi_adress',true);
if($address){
$txt_content .='### Address'.PHP_EOL.$address.PHP_EOL.PHP_EOL;
}
$phone1 = get_post_meta(50,'lianxi_phone_01',true);
if($phone1){
$txt_content .='### Phone'.PHP_EOL.$phone1.PHP_EOL.PHP_EOL;
}
$phone2 = get_post_meta(50,'lianxi_phone_02',true);
if($phone2){
$txt_content .='### Mobile'.PHP_EOL.$phone2.PHP_EOL.PHP_EOL;
}
$mail1 = get_post_meta(50,'lianxi_mail_01',true);
if($mail1){
$txt_content .='### Email'.PHP_EOL.$mail1.PHP_EOL.PHP_EOL;
}
$mail2 = get_post_meta(50,'lianxi_mail_02',true);
if($mail2){
$txt_content .='### Email'.PHP_EOL.$mail2.PHP_EOL.PHP_EOL;
}
$fax = get_post_meta(50,'lianxi_fax',true);
if($fax){
$txt_content .='### Fax'.PHP_EOL.$fax.PHP_EOL.PHP_EOL;
}
$whatsapp = get_post_meta(50,'lianxi_whatsapp',true);
if($whatsapp){
$txt_content .='### WhatsApp'.PHP_EOL.$whatsapp.PHP_EOL.PHP_EOL;
}
$whatsapp1 = get_post_meta(50,'lianxi_whatsapp01',true);
if($whatsapp1){
$txt_content .='### WhatsApp'.PHP_EOL.$whatsapp1.PHP_EOL.PHP_EOL;
}
$txt_content .= '## Home'.PHP_EOL.'[Home]('.$show_domain.')'.PHP_EOL.PHP_EOL;
$use_ai_tdk = get_option('tdk_use_ai');
$pages = $wpdb->get_results("select ID,post_title,post_content from wp_posts where post_type='page' and post_status='publish' order by ID desc limit 1000",ARRAY_A);
if($pages){ //页面
foreach ($pages as $v){
$post_id = $v['ID'];
$title = html_to_str($v['post_title'],300);
$url = get_permalink($post_id);
if(preg_match('/login|logout|register|lostpassword|resetpass|your-profile/',$url)){
continue;
}
$seo_description = get_post_meta($post_id,'_aioseop_description',true);
$url = str_replace($home_url,$show_domain,$url);
$description = $title;
if($seo_description){
$description = $seo_description;
}else{
if($use_ai_tdk == 1){
$tdk_info = $wpdb->get_row("select * from wp_tdks where type=4 and pid=".$post_id." order by id desc limit 1",ARRAY_A);
if($tdk_info){
$description = html_to_str($tdk_info['meta_description'],150);
}
}else{
if($v['post_content']){
$description = html_to_str($v['post_content'],150);
}
}
}
$txt_content .= '## '.$title.PHP_EOL.'['.$title.']('.$url.'):'.$description.PHP_EOL.PHP_EOL;
}
}
$has_ai_blog_flg = 0;
$ai_blog = json_decode(curl_zdy('https://admin.globalso.com/api/get_top_blogs?domain='.$show_domain),true);
if(isset($ai_blog['code']) && $ai_blog['code'] == 200){
$has_ai_blog_flg = 1;
$txt_content .= '## Top blog link'.PHP_EOL.'[Top blog]('.$show_domain.'top-blog/'.')'.PHP_EOL.PHP_EOL;
foreach ($ai_blog['data'] as $v){
$txt_content .= '## '.$v['seo_title'].PHP_EOL.'['.$v['seo_title'].']('.$show_domain.'blog/'.$v['url'].'/):'.$v['seo_description'].PHP_EOL.PHP_EOL;
}
}
$categories = get_categories( ['hide_empty' => 0] );
if($categories){ //产品分类及产品
foreach ($categories as $cate){
$title = $cate->name;
$url = get_category_link($cate->term_id);
$url = str_replace($home_url,$show_domain,$url);
$txt_content .= '## '.$title.PHP_EOL.'['.$title.']('.$url.')'.PHP_EOL.PHP_EOL;
}
$featured_id = $featured_post_id = [];
foreach ($categories as $cate){
if(in_array($cate->name,['Featured Products','Featured']) ){
$featured_id[] = $cate->term_taxonomy_id;
}
}
if($featured_id){
$featured_posts = $wpdb->get_results("select object_id from wp_term_relationships where term_taxonomy_id in (".implode(',',$featured_id).") order by object_id desc",ARRAY_A);
if($featured_posts){
$featured_post_id = array_column($featured_posts,'object_id');
}
}
if($featured_post_id){
$post_lists = $wpdb->get_results("select ID from wp_posts where post_type='post' and post_status='publish' order by ID desc",ARRAY_A);
$post_ids = [];
$i = 0;
if($post_lists){
foreach ($post_lists as $post){
if(!in_array($post['ID'],$featured_post_id)){
if($i>1000){
continue;
}
$post_ids[] = $post['ID'];
$i++;
}
}
}
if(count($post_ids) < 1000){
$post_ids = array_merge($post_ids,array_slice($featured_post_id,0,1000-count($post_ids)));
}
if($post_ids){
$posts = $wpdb->get_results("select ID,post_title,post_content from wp_posts where ID in(".implode(',',$post_ids).")",ARRAY_A);
}
}else{
$posts = $wpdb->get_results("select ID,post_title,post_content from wp_posts where post_type='post' and post_status='publish' order by ID desc limit 1000",ARRAY_A);
}
if($posts){
foreach ($posts as $post){
$post_id = $post['ID'];
$title = html_to_str($post['post_title'],300);
$seo_description = get_post_meta($post_id,'_aioseop_description',true);
$url = get_permalink($post_id);
$url = str_replace($home_url,$show_domain,$url);
$description = $title;
if($seo_description){
$description = $seo_description;
}else{
if($use_ai_tdk == 1){
$tdk_info = $wpdb->get_row("select * from wp_tdks where type=3 and pid=".$post_id." order by id desc limit 1",ARRAY_A);
if($tdk_info){
$description = html_to_str($tdk_info['meta_description'],150);
}
}else{
if($post['post_content']){
$description = html_to_str($post['post_content'],150);
}
}
}
$txt_content .= '## '.$title.PHP_EOL.'['.$title.']('.$url.'):'.$description.PHP_EOL.PHP_EOL;
}
}
}
$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','project'];
$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'];
}
}
if($post_types){//自定义类型 包含 新闻
foreach ($post_types as $v){
$url = $show_domain.$v.'/';
$txt_content .= '## '.$v.' link'.PHP_EOL.'['.$v.']('.$url.')'.PHP_EOL.PHP_EOL;
$posts = $wpdb->get_results("select ID,post_title,post_content from wp_posts where post_type='".$v."' and post_status='publish' order by ID desc limit 1000",ARRAY_A);
if($posts){
foreach ($posts as $post){
$post_id = $post['ID'];
$title = html_to_str($post['post_title'],300);
$url = get_permalink($post_id);
$url = str_replace($home_url,$show_domain,$url);
if($post['post_content']){
$description = html_to_str($post['post_content'],150);
$txt_content .= '## '.$title.PHP_EOL.'['.$title.']('.$url.'):'.$description.PHP_EOL.PHP_EOL;
}else{
$txt_content .= '## '.$title.PHP_EOL.'['.$title.']('.$url.'):'.$title.PHP_EOL.PHP_EOL;
}
}
}
}
}
if($has_ai_blog_flg == 1){
$txt_content .= '## Top search link'.PHP_EOL.'[Top search]('.$show_domain.'top-search/)'.PHP_EOL.PHP_EOL;
}
$tags = get_tags(['hide_empty'=>0,'number'=>3000,'orderby'=>'term_id','order'=>'desc']);
if($tags){//标签页
foreach ($tags as $tag){
$title = $tag->name;
$url = get_tag_link ($tag->term_id);
$url = str_replace($home_url,$show_domain,$url);
$description = $title;
if($use_ai_tdk){
$tdk_info = $wpdb->get_row("select * from wp_tdks where type=1 and pid=".$tag->term_id.' order by id desc limit 1',ARRAY_A);
if($tdk_info){
$description = $tdk_info['meta_description'];
}
}else{
$description = do_shortcode('[rand_pre]');
if(strlen($description) < 150){
$description .= ' '.$title;
}
if(strlen($description) < 150){
$description .= ', '.do_shortcode('[rand_keywords]');
}
if(strlen($description) < 150){
$description .= ', '.do_shortcode('[rand_keywords]');
}
if(strlen($description) < 150){
$description .= ', '.do_shortcode('[rand_keywords]');
}
if(strlen($description) < 150){
$description .= ', '.do_shortcode('[rand_suffix]');
}
if(strlen($description) < 150){
$description .= ', The product will supply to all over the world, such as Europe, America, Australia,';
}
}
$description = html_to_str($description);
$txt_content .= '## '.$title.PHP_EOL.'['.$title.']('.$url.'):'.$description.PHP_EOL.PHP_EOL;
}
}
file_put_contents($dir_llms,$txt_content);
if($is_split == 0){
if(is_dir(ABSPATH.'wp-content/cache/all/')){
file_put_contents(ABSPATH.'wp-content/cache/all/llms.txt',$txt_content);
}
}else{
curl_zdy($home_url.'extend_api.php?w=rsync');
}
echo 200;exit;
//html转纯字符串
function html_to_str($content,$lenth=150){
$str = strip_tags($content);
$str = str_replace(' ',' ',$str);
$str = str_replace(' ',' ',$str);
$str = substr(str_replace(["\r\n", "\r", "\n"], " ",$str),0,$lenth);
return $str;
}
function curl_zdy($url){
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_USERAGENT, 'Mozilla/5.0 ( Windows NT 10.0; Win64; x64) AppleWebKit/537.36 ( KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246' );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 50 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 50 );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 50 );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch, CURLOPT_SSLVERSION, 'all' );
$content = curl_exec( $ch );
curl_close( $ch );
return $content;
}