diff --git a/includes/api/ram-rest-categories-controller.php b/includes/api/ram-rest-categories-controller.php index 096fcfe56d62c255b85ab79ddb78f2d222f75e72..17ca4e45b4299e8dc87efc6dcc833c7ef98b7cb1 100644 --- a/includes/api/ram-rest-categories-controller.php +++ b/includes/api/ram-rest-categories-controller.php @@ -50,8 +50,23 @@ class RAM_REST_Categories_Controller extends WP_REST_Controller{ // Register our schema callback. 'schema' => array( $this, 'get_public_item_schema' ), ) ); + + register_rest_route( $this->namespace, '/' . $this->resource_name.'/ids', array( + // Here we register the readable endpoint for collections. + array( + 'methods' => 'GET', + 'callback' => array( $this, 'get_categories_ids' ), + //'permission_callback' => array( $this, 'get_item_permissions_check' ) + + ), + // Register our schema callback. + 'schema' => array( $this, 'get_public_item_schema' ), + ) ); + } + + public function postSubscription($request) { global $wpdb; @@ -185,6 +200,17 @@ class RAM_REST_Categories_Controller extends WP_REST_Controller{ } + public function get_categories_ids() + { + $categoriesId =get_option('wf_display_categories'); + + + $result['Ids'] =$categoriesId; + + $response = rest_ensure_response($result); + return $response; + } + public function post_item_permissions_check($request) { $openid= $request['openid']; diff --git a/includes/api/ram-rest-posts-controller.php b/includes/api/ram-rest-posts-controller.php index e5ee51bca16a109e7585045739cac399a4ec20a9..2bc6a1005cce1c6d3c6a680e5f6fda7051a0cea9 100644 --- a/includes/api/ram-rest-posts-controller.php +++ b/includes/api/ram-rest-posts-controller.php @@ -190,7 +190,48 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{ ), // Register our schema callback. 'schema' => array( $this, 'get_public_item_schema' ), - ) ); + ) ); + + register_rest_route( $this->namespace, '/' . $this->resource_name.'/about', array( + // Here we register the readable endpoint for collections. + array( + 'methods' => 'GET', + 'callback' => array( $this, 'getPostAbout' ), + 'permission_callback' => array( $this, 'get_item_permissions_check' ) + + ), + // Register our schema callback. + 'schema' => array( $this, 'get_public_item_schema' ), + ) ); + } + + function getPostAbout($request) + { + + $aboutId= get_option("wf_about"); + if(empty($aboutId)) + { + return new WP_Error( 'error', '未设置关于页面' , array( 'status' => "404" ) ); + } + else{ + + $posts =getPosts($aboutId); + if(count($posts)>0) + { + $post=$posts[0]; + $response = rest_ensure_response($post); + return $response; + + } + else{ + + return new WP_Error( 'error', '关于页面设置有错误' , array( 'status' => "404" ) ); + + } + + } + + } function getallpraise ($request) @@ -421,9 +462,9 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{ $_data['post_thumbnail_image_624']=$images['post_thumbnail_image_624']; $_data['post_frist_image']=$images['post_frist_image']; $_data['post_medium_image']=$images['post_medium_image']; - $_data['post_large_image']=$images['post_large_image']; - $_data['post_full_image']=$images['post_full_image']; - $_data['post_all_images']=$images['post_all_images']; + $_data['post_large_image']=$images['post_large_image']; + $_data['post_full_image']=$images['post_full_image']; + $_data['post_all_images']=$images['post_all_images']; $posts[] = $_data; @@ -528,6 +569,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{ return $response; } + function getPostSwipe($request) { global $wpdb; @@ -535,41 +577,7 @@ class RAM_REST_Posts_Controller extends WP_REST_Controller{ $posts =array(); if(!empty($postSwipeIDs)) { - $sql="SELECT * from ".$wpdb->posts." where id in(".$postSwipeIDs.") ORDER BY find_in_set(id,'".$postSwipeIDs."')"; - $_posts = $wpdb->get_results($sql); - - foreach ($_posts as $post) { - $post_id = (int) $post->ID; - $post_title = stripslashes($post->post_title); - $post_date =$post->post_date; - $post_permalink = get_permalink($post->ID); - $_data["id"] =$post_id; - $_data["post_title"] =$post_title; - $_data["post_date"] =$post_date; - $_data["post_permalink"] =$post_permalink; - $_data['type']="detailpage"; - - $pageviews = (int) get_post_meta( $post_id, 'wl_pageviews',true); - $_data['pageviews'] = $pageviews; - - $comment_total = $wpdb->get_var("SELECT COUNT(1) FROM ".$wpdb->comments." where comment_approved = '1' and comment_post_ID=".$post_id); - $_data['comment_total']= $comment_total; - - $images =getPostImages($post->post_content,$post_id); - - $_data['post_thumbnail_image']=$images['post_thumbnail_image']; - $_data['content_first_image']=$images['content_first_image']; - $_data['post_medium_image_300']=$images['post_medium_image_300']; - $_data['post_thumbnail_image_624']=$images['post_thumbnail_image_624']; - - $_data['post_frist_image']=$images['post_frist_image']; - $_data['post_medium_image']=$images['post_medium_image']; - $_data['post_large_image']=$images['post_large_image']; - $_data['post_full_image']=$images['post_full_image']; - $_data['post_all_images']=$images['post_all_images']; - $posts[] = $_data; - } - + $posts=getPosts($postSwipeIDs); $result["code"]="success"; $result["message"]= "获取轮播图成功"; $result["status"]="200"; diff --git a/includes/filter/ram-custom-category.php b/includes/filter/ram-custom-category.php index 2825c160e634b29cea196a42150010761819372d..879b77bb0878d7c5fb12368b504dd878126ef9c4 100644 --- a/includes/filter/ram-custom-category.php +++ b/includes/filter/ram-custom-category.php @@ -3,6 +3,30 @@ function custom_fields_rest_prepare_category( $data, $item, $request ) { $category_thumbnail_image=''; $temp=''; + $openid= $request["openid"]; + $subscription =getSubscription($openid); + $id =(string)$item->term_id; + if(empty($subscription)) + { + $data->data['subimg'] ="subscription.png"; + $data->data['subflag'] ="0"; + } + else + { + if(array_search($id,$subscription )) + { + $data->data['subimg'] ="subscription-on.png"; + $data->data['subflag'] ="1"; + } + else + { + $data->data['subimg'] ="subscription.png"; + $data->data['subflag'] ="0"; + + } + } + + if($temp=get_term_meta($item->term_id,'catcover',true)) { $category_thumbnail_image=$temp; @@ -17,6 +41,32 @@ function custom_fields_rest_prepare_category( $data, $item, $request ) { return $data; } +function getSubscription($openid) + { + global $wpdb; + $user_id =0; + $user = get_user_by('login', $openid); + $subscription= array(); + if($user) + { + $user_id = $user->ID; + $usermeta = get_user_meta($user_id); + if (!empty($usermeta)) + { + if(!empty($usermeta['wl_sub'])) + { + $subscription=$usermeta['wl_sub']; + } + } + + } + return $subscription; + + } + + + + /********* 给分类添加微信小程序封面 *********/ diff --git a/includes/ram-util.php b/includes/ram-util.php index 627dcc9a1ac470cb07dda9f500d4a72e1433a5c1..751e11215ce4aeb7ad99ad7c8dcb8a71a2e31925 100644 --- a/includes/ram-util.php +++ b/includes/ram-util.php @@ -603,4 +603,59 @@ function get_content_gallery($content,$flag){ return $vcontent; -} \ No newline at end of file +} + +function getPosts($ids) + { + global $wpdb; + $sql="SELECT * from ".$wpdb->posts." where id in(".$ids.") ORDER BY find_in_set(id,'".$ids."')"; + $_posts = $wpdb->get_results($sql); + $posts =array(); + if(!empty($_posts)) + { + foreach ($_posts as $post) { + $post_id = (int) $post->ID; + $post_title = stripslashes($post->post_title); + $post_content= nl2br($post->post_content); + $post_date =$post->post_date; + $post_permalink = get_permalink($post->ID); + $_data["id"] =$post_id; + $_data["post_title"] =$post_title; + $_data["post_content"] =$post_content; + $_data["post_date"] =$post_date; + $_data["post_permalink"] =$post_permalink; + $_data['type']="detailpage"; + + $enterpriseMinapp=get_option('wf_enterprise_minapp'); + $enterpriseMinapp=empty($enterpriseMinapp)?'0':$enterpriseMinapp; + $_data['enterpriseMinapp']=$enterpriseMinapp; + + $praiseWord=get_option('wf_praise_word'); + $praiseWord=empty($praiseWord)?'鼓励':$praiseWord; + $_data['praiseWord']=$praiseWord; + + $pageviews = (int) get_post_meta( $post_id, 'wl_pageviews',true); + $_data['pageviews'] = $pageviews; + + $comment_total = $wpdb->get_var("SELECT COUNT(1) FROM ".$wpdb->comments." where comment_approved = '1' and comment_post_ID=".$post_id); + $_data['comment_total']= $comment_total; + + $images =getPostImages($post->post_content,$post_id); + + $_data['post_thumbnail_image']=$images['post_thumbnail_image']; + $_data['content_first_image']=$images['content_first_image']; + $_data['post_medium_image_300']=$images['post_medium_image_300']; + $_data['post_thumbnail_image_624']=$images['post_thumbnail_image_624']; + + $_data['post_frist_image']=$images['post_frist_image']; + $_data['post_medium_image']=$images['post_medium_image']; + $_data['post_large_image']=$images['post_large_image']; + $_data['post_full_image']=$images['post_full_image']; + $_data['post_all_images']=$images['post_all_images']; + $posts[] = $_data; + } + + } + return $posts; + + } \ No newline at end of file