Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
ijianbo
rest Api To Miniprogram
提交
b08bbfba
rest Api To Miniprogram
项目概览
ijianbo
/
rest Api To Miniprogram
通知
22
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
rest Api To Miniprogram
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b08bbfba
编写于
11月 07, 2019
作者:
J
jianbo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
调整文章分类的加载
上级
a4fdb347
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
179 addition
and
40 deletion
+179
-40
includes/api/ram-rest-categories-controller.php
includes/api/ram-rest-categories-controller.php
+26
-0
includes/api/ram-rest-posts-controller.php
includes/api/ram-rest-posts-controller.php
+47
-39
includes/filter/ram-custom-category.php
includes/filter/ram-custom-category.php
+50
-0
includes/ram-util.php
includes/ram-util.php
+56
-1
未找到文件。
includes/api/ram-rest-categories-controller.php
浏览文件 @
b08bbfba
...
...
@@ -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'
];
...
...
includes/api/ram-rest-posts-controller.php
浏览文件 @
b08bbfba
...
...
@@ -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"
;
...
...
includes/filter/ram-custom-category.php
浏览文件 @
b08bbfba
...
...
@@ -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
;
}
/********* 给分类添加微信小程序封面 *********/
...
...
includes/ram-util.php
浏览文件 @
b08bbfba
...
...
@@ -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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录