| Server IP : 43.141.49.92 / Your IP : 113.219.202.173 Web Server : Apache System : Linux VM-8-5-opencloudos 6.6.34-9.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 19 19:35:45 CST 2024 x86_64 User : www ( 1000) PHP Version : 8.1.27 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/www.ucppt.com/wp-content/plugins/wpcom-member-pro/widgets/ |
Upload File : |
<?php
namespace WPCOM\Widgets;
use WPCOM\Member;
class Premium_Download extends Widget {
public function __construct() {
$this->widget_cssclass = 'widget_wpmx_premium_download';
$this->widget_description = '文章级的付费下载可通过小工具在边栏调用展示';
$this->widget_id = 'wpmx-premium-download';
$this->widget_name = '#用户中心#付费下载';
$this->settings = array(
'info' => array(
'name' => '使用说明',
't' => 'a',
'style' => 'info',
's' => '<p>请将此小工具放置在文章详情页的边栏,其他页面以及没有付费下载的文章将不显示当前小工具。</p><p>仅针对文章级的付费下载内容,即通过后台编辑器下方设置选项添加的,文章内付费下载区块添加的无法调用</p>',
),
'auto-thumb' => array(
'name' => '自动获取缩略图',
'desc' => '未设置缩略图是是否自动获取文章特色图片作为缩略图',
't' => 't'
)
);
parent::__construct();
}
public function widget( $_args, $instance ) {
global $wpmx_options;
if(is_singular('post') && $id = get_queried_object_id()){
$post = get_post($id);
$block = Member\Premium_Download::generate_download_block($post);
$all_free = 0;
$auto_thumb = !isset($instance['auto-thumb']) || $instance['auto-thumb'] == 1;
if(isset($block['attrs']) &&isset($block['attrs']['id']) && preg_match('/^post-hidden-download-/i', $block['attrs']['id'])){
if(isset($block['attrs']['type']) && $block['attrs']['type'] == -1){
$all_free = 1;
}else{
return false;
}
}
if($block){
extract($block['attrs']);
$title = $title ?: get_the_title($post);
$vip = isset($vip) && $vip;
$has_price = false;
$btn = isset($btn) && trim($btn) !== '' ? $btn : (isset($wpmx_options['download_btn_text']) && trim($wpmx_options['download_btn_text']) !== '' ? $wpmx_options['download_btn_text'] : '立即下载');
$vip_btn = isset($wpmx_options['download_vip_btn_text']) && trim($wpmx_options['download_vip_btn_text']) !== '' ? $wpmx_options['download_vip_btn_text'] : '会员下载';
if(isset($args) && $args){
foreach($args as $item){
if(isset($item['value']) && preg_match('%PRICE%', $item['value'])) {
$has_price = true;
break;
}
}
}
if(!$has_price && !$vip && !$all_free) $title .= Member\Premium_Download::get_arg_value('%PRICE%', $block['attrs']);
$this->widget_start( $_args, $instance );?>
<div class="hidden-content-wrap premium-download-wrap" id="widget-<?php echo esc_attr($id);?>">
<?php WPCOM_MP_block_bg(); ?>
<div class="premium-download">
<?php $has_thumb = 0;if(isset($image) && $image){ $has_thumb = 1;?>
<div class="wpcom-premium-download-thumb">
<img src="<?php echo is_numeric($image) ? wp_get_attachment_url($image) : esc_url($image);?>">
<h3 class="wpcom-premium-download-title"><?php echo $title;?></h3>
</div>
<?php }else if($auto_thumb && $post_thumb = get_the_post_thumbnail(null, 'full')){
$has_thumb = 1;
echo '<div class="wpcom-premium-download-thumb">' . $post_thumb . '<h3 class="wpcom-premium-download-title">'.$title.'</h3></div>';
} ?>
<div class="wpcom-premium-download-content">
<?php
$price = isset($price) && $price ? $price : 0;
$price = $vip ? 0 : $price;
$vip_price = isset($vip_price) ? $vip_price : array();
$vip_prices = Member\VIP::get_vip_price_html($price, $vip_price, 'download');
?>
<?php if(!$has_thumb){ ?><h3 class="wpcom-premium-download-title"><?php echo $title;?></h3><?php } ?>
<?php if(!$all_free && ($vip || $vip_prices)) { ?><div class="vip-price-notice premium-download-vip-price"><?php echo $vip_prices;?></div><?php } ?>
<div class="wpcom-premium-download-info">
<?php if(isset($args) && $args){
foreach($args as $item){ ?>
<span class="wpcom-premium-download-info-label"><?php echo $item['label'];?></span>
<span class="wpcom-premium-download-info-value"><?php echo Member\Premium_Download::get_arg_value($item['value'], $block['attrs']);?></span>
<?php }
} ?>
</div>
</div>
<div class="wpcom-premium-download-action">
<?php if(!$vip){ ?>
<button type="button" class="wpcom-btn btn-primary premium-download-btn"><?php wpmx_icon('download-cloud'); echo $btn;?></button>
<?php } ?>
<?php if($vip || $vip_prices){
$user_vip = Member\VIP::get_user_vip(); ?>
<?php if($user_vip){ ?>
<button type="button" class="wpcom-btn btn-danger premium-download-btn"><?php wpmx_icon('vip-crown'); echo $vip_btn;?></button>
<?php }else{ ?>
<button class="wpcom-btn btn-danger premium-download-vip-btn j-vip-new" type="button"><?php wpmx_icon('vip-crown'); echo Member\VIP::vip_btn_text('new')?></button>
<?php } ?>
<?php } ?>
</div>
<?php $user_id = get_current_user_id(); ?>
<div class="hidden-content-refresh">已付费?<?php if(!$user_id){ ?><a class="refresh-url" href="<?php echo wp_login_url();?>">登录<?php wpmx_icon('user')?></a> 或 <?php } ?><a class="refresh-url j-refresh-premium-download" href="javascript:;">刷新<?php wpmx_icon('refresh')?></a></div>
</div>
</div>
<?php
$this->widget_end( $_args );
}
}
}
}
// register widget
add_action( 'widgets_init', function(){
register_widget( Premium_Download::class );
} );