File "aicc_api.php"

Full Path: /www/wwwroot/shphe-en.com/admin/aicc_api.php
File size: 3.41 KB
MIME-type: --
Charset: utf-8

<?php
require_once( dirname(__FILE__) . '/../wp-load.php' );

global $wpdb;

$home_url = home_url('/');
$cdn_setting = get_option("gd_cdn_setting");
$domain = $home_url;
if($cdn_setting){
    if(strpos($home_url,'quanqiusou.cn') !== false || strpos($home_url,'goodao.net') !== false){
        $domain = trim($cdn_setting['weburl']);
    }
}
$page = isset($_GET['page'])?trim($_GET['page']):1;
$pagesize = isset($_GET['pagesize'])?trim($_GET['pagesize']):100;
$start = $pagesize*($page-1);
$type = $_GET['w'];
switch($type){
    case 'post':
        $count_posts = $wpdb->get_row("select count(*) as cnt from wp_posts where post_date_gmt!='2016-01-08 00:00:00' and post_type='post' and post_status='publish'",ARRAY_A);
        $data['count'] = $count_posts['cnt'];
        $arr = [];
        $posts = $wpdb->get_results("select ID,post_title,post_content from wp_posts where post_date_gmt!='2016-01-08 00:00:00' and post_type='post' and post_status='publish' order by ID DESC limit $start,$pagesize");
        if($posts){
            foreach ($posts as $post){
                $tmp['ttile'] = $post->post_title;
                $tmp['url'] = str_replace($home_url,$domain,get_permalink($post->ID));
                $tmp['content'] = sanitize_text_field(strip_tags($post->post_content));
                $tmp['images'] = [];
                $product_gallery = get_post_meta($post->ID,'product_gallery',true);
                if($product_gallery){
                    foreach ($product_gallery as $vv){
                        $tmp['images'][] = wp_get_attachment_url($vv);
                    }
                }
                if($tmp['content']){
                    $arr[] = $tmp;
                }
            }
        }
        $data['data'] = $arr;
        echo json_encode(['code'=>200,'data'=>$data]);exit;
        break;
    case 'page':
    case 'news':
    case 'blog':
        $count_posts = $wpdb->get_row("select count(*) as cnt from wp_posts where post_type='".$type."' and post_status='publish'",ARRAY_A);
        $data['count'] = $count_posts['cnt'];
        $arr = [];
        $posts = $wpdb->get_results("select ID,post_title,post_content from wp_posts where post_type='".$type."' and post_status='publish' order by ID DESC limit $start,$pagesize");
        if($posts){
            foreach ($posts as $post){
                $tmp['ttile'] = $post->post_title;
                $tmp['url'] = str_replace($home_url,$domain,get_permalink($post->ID));
                $tmp['content'] = sanitize_text_field(strip_tags($post->post_content));
                $tmp['images'] = [];
                if($tmp['content']){
                    $arr[] = $tmp;
                }
            }
        }
        $data['data'] = $arr;
        echo json_encode(['code'=>200,'data'=>$data]);exit;
        break;
        
    case 'banner':
        $banners = get_post_meta(50,'ad_index_banner',true);
        $img_urls = [];
        if($banners){
            foreach ($banners as $v){
                $img_urls[] = wp_get_attachment_url($v);
            }
        }
        $data['banner'] = $img_urls;
        $seos = get_option('aioseop_options');
        $data['keywords'] = '';
        if(isset($seos['aiosp_home_keywords']) && $seos['aiosp_home_keywords']){
            $data['keywords'] = $seos['aiosp_home_keywords'];
        }
        echo json_encode(['code'=>200,'data'=>$data]);exit;
        break;
    default:
        echo json_encode(['code'=>1,'msg'=>'param error']);exit;    
}