提交 fcc47cb5 编写于 作者: J jianbo

加入广告设置

上级 dbca4f3c
......@@ -31,6 +31,17 @@ function custom_post_fields( $data, $post, $request) {
$_data['post_full_image']=$images['post_full_image'];
$_data['post_all_images']=$images['post_all_images'];
//获取广告参数
$listAdId=empty(get_option('wf_list_ad_id'))?'':get_option('wf_list_ad_id');
$listAd=empty(get_option('wf_list_ad'))?'0':"1";
$listAdEvery=empty(get_option('wf_list_ad_every'))?5:(int)get_option('wf_list_ad_every');
$_data['listAd']=$listAd;
$_data['listAdId']=$listAdId;
$_data['listAdEvery']=$listAdEvery;
$comments_count = wp_count_comments($post_id);
$_data['total_comments']=$comments_count->approved;
$category =get_the_category($post_id);
......@@ -49,11 +60,38 @@ function custom_post_fields( $data, $post, $request) {
$params = $request->get_params();
if ( isset( $params['id'] ) ) {
$praiseWord=get_option('wf_praise_word');
$praiseWord=empty($praiseWord)?'鼓励':$praiseWord;
$_data['praiseWord']=$praiseWord;
//获取广告参数
$detailAdId=empty(get_option('wf_detail_ad_id'))?'':get_option('wf_detail_ad_id');
$detailAd=empty(get_option('wf_detail_ad'))?'0':"1";
$_data['detailAdId']=$detailAdId;
$_data['detailAd']=$detailAd;
$enterpriseMinapp=get_option('wf_enterprise_minapp');
$praiseWord=empty($enterpriseMinapp)?'0':$enterpriseMinapp;
$_data['enterpriseMinapp']=$enterpriseMinapp;
$vcontent =get_post_qq_video($content);//解析腾讯视频
if(!empty($vcontent))
{
$content=$vcontent;
}
//解析音频
$audios= get_post_content_audio($post->post_content);
$_data['audios']=$audios;
$sql="select post_content from ".$wpdb->posts." where id=".$post_id;
$postContent = $wpdb->get_var($sql);
if(has_shortcode($postContent, 'gallery' ))//处理内容里的相册显示
{
$content= get_content_gallery($postContent,true);
}
$_content['rendered'] =$content;
$_content['raw'] =$raw;//古腾堡编辑器需要该属性,否则报错
$_content['protected'] =$content_protected;
......
......@@ -545,4 +545,62 @@ function get_post_qq_video($content)
}
return $vcontent;
}
function get_post_content_audio($post_content){
if(!$post_content){
$the_post = get_post();
$post_content = $the_post->post_content;
}
$list = array();
$c1 = preg_match_all('/<audio\s.*?>/', do_shortcode($post_content), $m1); //先取出所有img标签文本
for($i=0; $i<$c1; $i++) { //对所有的img标签进行取属性
$c2 = preg_match_all('/(\w+)\s*=\s*(?:(?:(["\'])(.*?)(?=\2))|([^\/\s]*))/', $m1[0][$i], $m2); //匹配出所有的属性
for($j=0; $j<$c2; $j++) { //将匹配完的结果进行结构重组
$list[$i][$m2[1][$j]] = !empty($m2[4][$j]) ? $m2[4][$j] : $m2[3][$j];
}
}
return $list;
}
function get_content_gallery($content,$flag){
$list = array();
//$content=self::nl2p($content,true,false);//把换行转换成p标签
if($flag)
{
$content=nl2br($content);
}
$vcontent=$content;
$c1 = preg_match_all('|\[gallery.*?ids=[\'"](.*?)[\'"].*?\]|i',$content, $m1); //先取出所有gallery短代码
for($i=0; $i<$c1; $i++) { //对所有的img标签进行取属性
$c2 = preg_match_all('/(\w+)\s*=\s*(?:(?:(["\'])(.*?)(?=\2))|([^\/\s]*))/', $m1[0][$i], $m2); //匹配出所有的属性
for($j=0; $j<$c2; $j++) { //将匹配完的结果进行结构重组
$list[$i][$m2[1][$j]] = !empty($m2[4][$j]) ? $m2[4][$j] : $m2[3][$j];
}
}
$ids =$list[0]['ids'];
if(!empty($ids))
{
$ids =explode(',',$ids);
$img='';
foreach($ids as $id)
{
$image=wp_get_attachment_image_src((int)$id,'full');
$img .='<img width="'.$image[1].'" height="'.$image[2].'" src="'.$image[0].'" />';
}
$vcontent = preg_replace('~\[gallery (.*?)\]~s',$img,$content);
}
return $vcontent;
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
function weixinapp_create_menu() {
// 创建新的顶级菜单
add_menu_page('微慕小程序设置', '微慕小程序设置', 'administrator', 'weixinapp_slug', 'weixinapp_settings_page', plugins_url('rest-api-to-miniprogram/includes/images/icon16.png'),null);
add_menu_page('微慕小程序', '微慕小程序', 'administrator', 'weixinapp_slug', 'weixinapp_settings_page', plugins_url('rest-api-to-miniprogram/includes/images/icon16.png'),null);
// 调用注册设置函数
add_action( 'admin_init', 'register_weixinappsettings' );
}
......@@ -30,6 +30,28 @@ function register_weixinappsettings() {
register_setting( 'weixinapp-group', 'wf_poster_imageurl' );
register_setting( 'weixinapp-group', 'wf_enable_comment_option' );
register_setting( 'weixinapp-group', 'wf_enable_comment_check' );
register_setting( 'weixinapp-group', 'wf_praise_word' );
register_setting( 'weixinapp-group', 'wf_enterprise_minapp' );
register_setting( 'weixinapp-group', 'wf_list_ad' );
register_setting( 'weixinapp-group', 'wf_list_ad_id' );
register_setting( 'weixinapp-group', 'wf_list_ad_every' );
register_setting( 'weixinapp-group', 'wf_detail_ad' );
register_setting( 'weixinapp-group', 'wf_detail_ad_id' );
......@@ -128,22 +150,66 @@ if (version_compare(PHP_VERSION, '5.6.0', '<=') )
<th scope="row">海报图片默认地址</th>
<td><input type="text" name="wf_poster_imageurl" style="width:400px; height:40px" value="<?php echo esc_attr( get_option('wf_poster_imageurl') ); ?>" /><br/><p style="color: #959595; display:inline">* 请输完整的图片地址,例如:https://www.watch-life.net/images/poster.jpg</p></td>
</tr>
<tr valign="top">
<th scope="row">"赞赏"文字调整为</th>
<td><input type="text" name="wf_praise_word" placeholder="喜欢" style="width:400px; height:40px" value="<?php echo esc_attr( get_option('wf_praise_word') ); ?>" /><br /><p style="color: #959595; display:inline">* 例如:<code>鼓励</code>,<code>喜欢</code><code>稀罕</code>,不要超过两个汉字</p></td>
</tr>
<tr valign="top">
<th scope="row">小程序是否是企业主体</th>
<td>
<?php
$wf_enterprise_minapp =get_option('wf_enterprise_minapp');
$checkbox=empty($wf_enterprise_minapp)?'':'checked';
echo '<input name="wf_enterprise_minapp" type="checkbox" value="1" '.$checkbox. ' />';
?><p style="color: #959595; display:inline">* 如果是企业主体的小程序,请勾选</p>
</td>
</tr>
</table>
</div>
<h2>广告设置</h2>
<div class="section">
<table class="form-table">
<tr valign="top">
<th scope="row">开启文章列表广告</th>
<td>
<?php
$wf_list_ad =get_option('wf_list_ad');
$checkbox=empty($wf_list_ad)?'':'checked';
echo '<input name="wf_list_ad" type="checkbox" value="1" '.$checkbox. ' />';
?>
&emsp;&emsp;&emsp;广告id:&emsp;<input type="text" name="wf_list_ad_id" style="width:300px; height:40px" value="<?php echo esc_attr( get_option('wf_list_ad_id') ); ?>" />
<br/>&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;<input type="number" name="wf_list_ad_every" style="width:40px; height:40px" value="<?php echo esc_attr( get_option('wf_list_ad_every') ); ?>" />条列表展示一条广告<br/><p style="color: #959595; display:inline">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;请输入整数,否则无法正常展示广告</p>
</td>
</td>
</tr>
<tr valign="top">
<th scope="row">开启内容详情页广告</th>
<td>
<?php
$wf_detail_ad =get_option('wf_detail_ad');
$checkbox=empty($wf_detail_ad)?'':'checked';
echo '<input name="wf_detail_ad" type="checkbox" value="1" '.$checkbox. ' />';
?>
&emsp;&emsp;&emsp;广告id:&emsp;<input type="text" name="wf_detail_ad_id" style="width:300px; height:40px" value="<?php echo esc_attr( get_option('wf_detail_ad_id') ); ?>" />
</td>
</tr>
</table>
</div>
<h2>微慕增强版</h2>
<div class="section">
<div style="display: flex; flex-direction: row; margin-bottom: 10px">
<a href="https://www.minapper.com" target="_blank" style="text-decoration: none"><div style="width:120px; height:32px; background-color: #fc6e6e; border-radius: 4px; color: #fff;display: flex;justify-content: center; align-items: center;margin-right: 16px">微慕官网</div></a>
<a href="https://mall.minapper.com" target="_blank" style="text-decoration: none"><div style="width:120px; height:32px; background-color: #fff; border: 1px solid #fc6e6e; border-radius: 4px; box-sizing: border-box; color: #fc6e6e;display: flex;justify-content: center; align-items: center">微慕商城</div></a>
<a href="https://www.minapper.com" target="_blank" style="text-decoration: none"><div style="width:120px; height:32px; background-color: #ff8f3b; border-radius: 4px; color: #fff;display: flex;justify-content: center; align-items: center;margin-right: 16px">微慕官网</div></a>
<a href="https://mall.minapper.com" target="_blank" style="text-decoration: none"><div style="width:120px; height:32px; background-color: #fff; border: 1px solid #ff8f3b; border-radius: 4px; box-sizing: border-box; color: #ff8f3b;display: flex;justify-content: center; align-items: center">微慕商城</div></a>
</div>
<p style="color: #4c4c4c;text-align:justify; line-height: 2">微慕版wordpress小程序和插件,在“守望轩”开源小程序的基础上,架构完全重构,在性能上大幅度优化,增加了<span style="font-weight:bold">动态圈子、积分系统、文章投稿、发布动态、付费阅读、会员权限、多种图文列表样式、预约表单、模板消息</span>等功能,并且免费提供标准版、旅游版、图片版、企业版4套前端模板,可使用微信扫描下方小程序码直接体验:</p>
<p style="color: #4c4c4c;text-align:justify; line-height: 2">微慕Plus小程序是一款,在原守望轩开源小程序(现微慕开源小程序)基础上重新架构、设计、优化过的wordpress多端小程序,性能和用户体验更佳,界面设计更加简洁清新,同时打通<span style="font-weight:bold">微信小程序、QQ小程序、百度小程序、支付宝小程序、头条小程序...真正实现一站多端</span>,可使用微信扫描下方小程序码直接体验:</p>
<div>
<img src="https://www.minapper.com/wp-content/uploads/2018/09/2018091118195979.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://www.minapper.com/wp-content/uploads/2018/11/2018110915511992.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://www.minapper.com/wp-content/uploads/2018/09/2018091118200015.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://www.minapper.com/wp-content/uploads/2018/11/2018110822512777.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://plusimg.minapper.com/wp-content/uploads/2019/08/1565183497-%E5%BE%AE%E6%85%95%E6%B5%B7%E6%8A%A5-2019%E5%B9%B47%E6%9C%88.jpg" alt="微慕增强版" width="100%"></img>
</div>
</div>
......@@ -155,10 +221,8 @@ if (version_compare(PHP_VERSION, '5.6.0', '<=') )
</div>
<p style="color: #4c4c4c;text-align:justify; line-height: 2">微慕版wordpress小程序和插件,在“守望轩”开源小程序的基础上,架构完全重构,在性能上大幅度优化,增加了<span style="font-weight:bold">动态圈子、积分系统、文章投稿、发布动态、付费阅读、会员权限、多种图文列表样式、预约表单、模板消息</span>等功能,并且免费提供标准版、旅游版、图片版、企业版4套前端模板,可使用微信扫描下方小程序码直接体验:</p>
<div>
<img src="https://www.minapper.com/wp-content/uploads/2018/09/2018091118195979.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://www.minapper.com/wp-content/uploads/2018/11/2018110915511992.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://www.minapper.com/wp-content/uploads/2018/09/2018091118200015.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://www.minapper.com/wp-content/uploads/2018/11/2018110822512777.jpg" alt="Smiley face" width="120px" height="270px"></img>
<img src="https://www.watch-life.net/images/2019/10/minapper-professional-2-624x351.jpg" alt="微慕专业版" width="100%"></img>
</div>
</div>
......
......@@ -3,7 +3,7 @@
Plugin Name: REST API TO MiniProgram
Plugin URI: http://www.watch-life.net
Description: 为微信小程序、app提供定制WordPress REST API 输出.支持微信支付、微信小程序模板消息.
Version: 1.5.7
Version: 1.5.8
Author: jianbo
Author URI: http://www.minapper.com
License: GPL v3
......@@ -33,7 +33,9 @@ if ( ! class_exists( 'RestAPIMiniProgram' ) ) {
//定制化内容输出,对pc端和api都生效
add_filter( 'the_content', 'custocm_content_filter' );
//对文章的自定义输出
add_filter( 'rest_prepare_post', 'custom_post_fields', 10, 3 );
add_filter( 'rest_prepare_post', 'custom_post_fields', 10, 3 );
//对页面的自定义输出
add_filter( 'rest_prepare_page', 'custom_post_fields', 10, 3 );
//对评论的自定义输出
add_filter( 'rest_prepare_comment', 'custom_comment_fields', 10, 3 );
add_filter( 'rest_prepare_category', 'custom_fields_rest_prepare_category', 10, 3 ); //获取分类的封面图片
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册