mirror of
https://github.com/yunluo/gdk.git
synced 2024-05-23 16:42:19 +02:00
增加很多功能
This commit is contained in:
parent
51b968da8e
commit
4bab586b66
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,12 @@
|
|||
<?php
|
||||
|
||||
include( 'clean-up.php' );//数据库清理
|
||||
include( 'local_avatars.php' );//本地头像
|
||||
include( 'Payjs.php' );//支付功能
|
||||
|
||||
include( 'updates.php' );//在线更新
|
||||
include( 'widget_cache.php' );//小工具缓存
|
||||
|
||||
if(gdk_option('gdk_payjs')){
|
||||
include( 'Payjs.php' );//支付功能
|
||||
include( 'points/points.php' );//积分功能
|
||||
}
|
453
class/points/class-points-admin.php
Normal file
453
class/points/class-points-admin.php
Normal file
|
@ -0,0 +1,453 @@
|
|||
<?php
|
||||
/**
|
||||
* Points Table class
|
||||
*/
|
||||
|
||||
// WP_List_Table is not loaded automatically so we need to load it in our application
|
||||
if ( !class_exists( 'WP_List_Table' ) ) {
|
||||
require_once (ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
|
||||
}
|
||||
|
||||
class Points_List_Table extends WP_List_Table {
|
||||
/**
|
||||
* Prepare the items for the table to process
|
||||
*
|
||||
* @return Void
|
||||
*/
|
||||
public function prepare_items() {
|
||||
$columns = $this->get_columns();
|
||||
$hidden = $this->get_hidden_columns();
|
||||
$sortable = $this->get_sortable_columns();
|
||||
$data = $this->table_data();
|
||||
usort( $data, [ &$this, 'sort_data' ] );
|
||||
$perPage = 30;//每页30个数据
|
||||
$currentPage = $this->get_pagenum();
|
||||
$totalItems = count( $data );
|
||||
$this->set_pagination_args( [
|
||||
'total_items' => $totalItems,
|
||||
'per_page' => $perPage
|
||||
] );
|
||||
|
||||
$data = array_slice( $data, (($currentPage - 1) * $perPage), $perPage );
|
||||
|
||||
$this->_column_headers = [
|
||||
$columns,
|
||||
$hidden,
|
||||
$sortable
|
||||
];
|
||||
$this->items = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the parent columns method.
|
||||
* Defines the columns to use in your listing table
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_columns() {
|
||||
$columns = [
|
||||
'point_id' => 'ID',
|
||||
'user_id' => '用户ID',
|
||||
'points' => '金币',
|
||||
'description' => '描述',
|
||||
'datetime' => '日期&时间',
|
||||
'status' => '状态',
|
||||
'actions' => '操作'
|
||||
];
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define which columns are hidden
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_hidden_columns() {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the sortable columns
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
public function get_sortable_columns() {
|
||||
return [
|
||||
'point_id' => [
|
||||
'point_id',
|
||||
false
|
||||
],
|
||||
'user_id' => [
|
||||
'user_id',
|
||||
false
|
||||
],
|
||||
'points' => [
|
||||
'points',
|
||||
false
|
||||
],
|
||||
'description' => [
|
||||
'description',
|
||||
false
|
||||
],
|
||||
'datetime' => [
|
||||
'datetime',
|
||||
false
|
||||
],
|
||||
'status' => [
|
||||
'status',
|
||||
false
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the table data
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
private function table_data() {
|
||||
$data = [];
|
||||
$data = Points::get_points( null, null, null, ARRAY_A );
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Define what data to show on each column of the table
|
||||
*
|
||||
* @param Array $item
|
||||
* Data
|
||||
* @param String $column_name
|
||||
* - Current column name
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
public function column_default( $item, $column_name ) {
|
||||
switch ( $column_name ) {
|
||||
case 'point_id' :
|
||||
case 'user_id' :
|
||||
case 'description' :
|
||||
case 'points' :
|
||||
case 'datetime' :
|
||||
case 'status' :
|
||||
return $item[$column_name];
|
||||
break;
|
||||
case 'actions':
|
||||
$actions = [
|
||||
'edit' => sprintf('<a href="?page=%s&action=%s&point_id=%s">编辑</a>',$_REQUEST['page'],'edit',$item['point_id']),
|
||||
'delete' => sprintf('<a href="?page=%s&action=%s&point_id=%s">删除</a>',$_REQUEST['page'],'delete',$item['point_id']),
|
||||
];
|
||||
|
||||
//Return the title contents
|
||||
return sprintf('%1$s%2$s',$item[$column_name]??"",
|
||||
$this->row_actions($actions, true)
|
||||
);
|
||||
break;
|
||||
default :
|
||||
return print_r( $item, true );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to sort the data by the variables set in the $_GET
|
||||
*
|
||||
* @return Mixed
|
||||
*/
|
||||
private function sort_data( $a, $b ) {
|
||||
// Set defaults
|
||||
$orderby = 'point_id';
|
||||
$order = 'desc';
|
||||
|
||||
// If orderby is set, use this as the sort column
|
||||
if ( !empty( $_GET['orderby'] ) ) {
|
||||
$orderby = $_GET['orderby'];
|
||||
}
|
||||
|
||||
// If order is set use this as the order
|
||||
if ( !empty( $_GET['order'] ) ) {
|
||||
$order = $_GET['order'];
|
||||
}
|
||||
|
||||
$result = strnatcmp( $a[$orderby], $b[$orderby] );
|
||||
|
||||
if ( $order === 'asc' ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return -$result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Points Admin class
|
||||
*/
|
||||
class Points_Admin {
|
||||
|
||||
public static function init () {
|
||||
add_action( 'admin_notices', [ __CLASS__, 'admin_notices' ] );
|
||||
add_action( 'admin_menu', [ __CLASS__, 'admin_menu' ], 'manage_options' );
|
||||
}
|
||||
|
||||
public static function admin_notices() {
|
||||
if ( !empty( self::$notices ) ) {
|
||||
foreach ( self::$notices as $notice ) {
|
||||
echo $notice;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the admin section.
|
||||
*/
|
||||
public static function admin_menu() {
|
||||
$admin_page = add_menu_page('金币','金币','manage_options','points',[ __CLASS__, 'points_menu'],'dashicons-awards');
|
||||
}
|
||||
|
||||
public static function points_menu() {
|
||||
$alert = "";
|
||||
if(isset( $_POST['psearch'] )){
|
||||
$sdata = trim($_POST['psearch']);
|
||||
if(preg_match('/E20/', $sdata)){//order id
|
||||
global $wpdb;
|
||||
$point_id = $wpdb->get_row("SELECT point_id FROM " . Points_Database::points_get_table( "users" ) . " WHERE description = '{$sdata}'", ARRAY_A )['point_id'];
|
||||
$points = Points::get_point( $point_id );
|
||||
}elseif(filter_var($sdata, FILTER_VALIDATE_EMAIL)){//email
|
||||
$user = get_user_by( 'email', $sdata );
|
||||
$points = Points::get_points_by_user( $user->ID );
|
||||
$k[] = '<div style="margin-bottom:10px;">用户ID:'.$user->ID.' 总金币为:'.Points::get_user_total_points( $user->ID ).'</div>';
|
||||
}else{//userid
|
||||
$points = Points::get_points_by_user( $sdata );
|
||||
$k[] = '<div style="margin-bottom:10px;">用户ID:'.$sdata.' 总金币为:'.Points::get_user_total_points( $sdata ).'</div>';
|
||||
}
|
||||
if(is_array($points)){
|
||||
foreach ( $points as $point ) {
|
||||
$k[] = '<div style="margin-bottom:5px;">金币:'.$point->points.' 描述:'.$point->description.' 日期:'.$point->datetime.'</div>';
|
||||
}
|
||||
}else{
|
||||
$k[] = '<div style="margin-bottom:5px;">金币:'.$points->points.' 描述:'.$points->description.' 日期:'.$points->datetime.'</div>';
|
||||
}
|
||||
$alert = implode(" ", $k);
|
||||
}
|
||||
|
||||
if ( isset( $_POST['save'] ) && isset( $_POST['action'] ) ) {
|
||||
if ( $_POST['action'] == "edit" ) {
|
||||
$point_id = isset($_POST['point_id'])?intval( $_POST['point_id'] ) : null;
|
||||
$points = Points::get_point( $point_id );
|
||||
$data = array();
|
||||
if ( isset( $_POST['user_mail'] ) ) {
|
||||
$data['user_mail'] = $_POST['user_mail'];
|
||||
}
|
||||
if ( isset( $_POST['user_id'] ) ) {
|
||||
$data['user_id'] = $_POST['user_id'];
|
||||
}
|
||||
if ( isset( $_POST['datetime'] ) ) {
|
||||
$data['datetime'] = $_POST['datetime'];
|
||||
}
|
||||
if ( isset( $_POST['description'] ) ) {
|
||||
$data['description'] = $_POST['description'];
|
||||
}
|
||||
if ( isset( $_POST['status'] ) ) {
|
||||
$data['status'] = $_POST['status'];
|
||||
}
|
||||
if ( isset( $_POST['points'] ) ) {
|
||||
$data['points'] = $_POST['points'];
|
||||
}
|
||||
|
||||
if ( $points ) { // 编辑金币
|
||||
Points::update_points($point_id, $data);
|
||||
} else { // 增加金币
|
||||
if ( isset( $_POST['user_mail'] ) ) {//如果输入邮箱的话
|
||||
$usermail = $data['user_mail'];
|
||||
$user = get_user_by( 'email', $usermail );
|
||||
$userid = $user->ID;
|
||||
$username = $user->display_name;
|
||||
}
|
||||
if ( isset( $_POST['user_id'] ) ) {//如果输入用户ID的话
|
||||
$user = get_user_by( 'id', $data['user_id'] );
|
||||
$usermail = $user->user_email;
|
||||
$userid = $data['user_id'];
|
||||
$username = $user->display_name;
|
||||
}
|
||||
Points::set_points($_POST['points'], $userid, $data);
|
||||
$message = '<div class="emailcontent" style="width:100%;max-width:720px;text-align:left;margin:0 auto;padding-top:80px;padding-bottom:20px"><div class="emailtitle"><h1 style="color:#fff;background:#51a0e3;line-height:70px;font-size:24px;font-weight:400;padding-left:40px;margin:0">金币金额调整通知</h1><div class="emailtext" style="background:#fff;padding:20px 32px 40px"><div style="padding:0;font-weight:700;color:#6e6e6e;font-size:16px">尊敬的'.$username.',您好!</div><p style="color:#6e6e6e;font-size:13px;line-height:24px">您的金币金额被管理员调整,请查收!</p><table cellpadding="0" cellspacing="0" border="0" style="width:100%;border-top:1px solid #eee;border-left:1px solid #eee;color:#6e6e6e;font-size:16px;font-weight:normal"><thead><tr><th colspan="2" style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;background:#f8f8f8">您的金币详细情况</th></tr></thead><tbody><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center;width:100px">用户名</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">'.$username.'</td></tr><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">调整金币</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">'.$_POST['points'].'</td></tr><tr><td style="padding:10px 0;border-right:1px solid #eee;border-bottom:1px solid #eee;text-align:center">金币总额</td><td style="padding:10px 20px 10px 30px;border-right:1px solid #eee;border-bottom:1px solid #eee;line-height:30px">'.Points::get_user_total_points($userid, 'accepted' ).'</td></tr></tbody></table><p style="color:#6e6e6e;font-size:13px;line-height:24px">如果您的金币金额有异常,请您在第一时间和我们取得联系哦,联系邮箱:'.get_bloginfo('admin_email').'</p></div><div class="emailad" style="margin-top:4px"><a href="'.home_url().'"><img src="http://reg.163.com/images/secmail/adv.png" alt="" style="margin:auto;width:100%;max-width:700px;height:auto"></a></div></div></div>';
|
||||
$headers = "Content-Type:text/html;charset=UTF-8\n";
|
||||
wp_mail( $usermail , 'Hi,'.$username.',金币账户金额增加通知!', $message ,$headers);
|
||||
}
|
||||
}
|
||||
$alert= "金币已更新";
|
||||
}
|
||||
if ( isset( $_GET["action"] ) ) {
|
||||
$action = $_GET["action"];
|
||||
if ( $action !== null ) {
|
||||
switch ( $action ) {
|
||||
case 'edit' :
|
||||
if ( isset( $_GET['point_id'] ) && ( $_GET['point_id'] !== null ) ) {
|
||||
return self::points_admin_points_edit( intval( $_GET['point_id'] ) );
|
||||
} else {
|
||||
return self::points_admin_points_edit();
|
||||
}
|
||||
break;
|
||||
case 'delete' :
|
||||
if ( $_GET['point_id'] !== null ) {
|
||||
if ( current_user_can( 'administrator' ) ) {
|
||||
Points::remove_points( $_GET['point_id'] );
|
||||
global $wpdb;
|
||||
$wcu_sql = "DELETE FROM " . Points_Database::points_get_table( "users" ) . " WHERE status = 'removed'";
|
||||
$wpdb->query($wcu_sql);
|
||||
$alert= "金币已删除";
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($alert != "") {
|
||||
echo '<div style="background-color: #ffffe0;border: 1px solid #993;padding: 1em;margin-right: 1em;">' . $alert . '</div>';
|
||||
}
|
||||
|
||||
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
$cancel_url = remove_query_arg( 'point_id', remove_query_arg( 'action', $current_url ) );
|
||||
$current_url = remove_query_arg( 'point_id', $current_url );
|
||||
$current_url = remove_query_arg( 'action', $current_url );
|
||||
$exampleListTable = new Points_List_Table();
|
||||
$exampleListTable->prepare_items();
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h2>金币管理</h2>
|
||||
<span class="manage add">
|
||||
<a class="add button" href="<?php echo esc_url( add_query_arg( 'action', 'edit', $current_url ) ); ?>" title="点击手动添加金币">添加金币</a>
|
||||
</span>
|
||||
<form method="POST" style="float:right;">
|
||||
<input size="40" placeholder="搜索用户ID/用户邮箱/订单号" type="search" name="psearch" value="" />
|
||||
</form>
|
||||
<?php echo '<style type="text/css">tbody#the-list tr:hover{background:rgba(132,219,162,.61)}</style>';$exampleListTable->display(); ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
public static function points_admin_points_edit( $point_id = null ) {
|
||||
global $wpdb;
|
||||
$output = '';
|
||||
|
||||
if ( !current_user_can( 'administrator' ) ) {
|
||||
wp_die( 'Access denied.' );
|
||||
}
|
||||
|
||||
$current_url = ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
|
||||
$cancel_url = remove_query_arg( 'point_id', remove_query_arg( 'action', $current_url ) );
|
||||
$current_url = remove_query_arg( 'point_id', $current_url );
|
||||
$current_url = remove_query_arg( 'action', $current_url );
|
||||
|
||||
$saved = false; // temporal
|
||||
|
||||
if ( $point_id !== null ) {
|
||||
$points = Points::get_point( $point_id );
|
||||
|
||||
if ( $points !== null ) {
|
||||
$user_id = $points->user_id;
|
||||
$num_points = $points->points;
|
||||
$description = $points->description;
|
||||
$datetime = $points->datetime;
|
||||
$status = $points->status;
|
||||
}
|
||||
} else {
|
||||
$user_id = "";
|
||||
$num_points = 0;
|
||||
$description = "ADD";
|
||||
$datetime = "";
|
||||
$status = 'accepted';
|
||||
}
|
||||
|
||||
if ( empty( $point_id ) ) {
|
||||
$pointsclass = 'newpoint';
|
||||
} else {
|
||||
$pointsclass = 'editpoint';
|
||||
}
|
||||
$output .= '<div class="points '.$pointsclass.'">';
|
||||
$output .= '<h2>';
|
||||
if ( empty( $point_id ) ) {
|
||||
$output .= '新金币';
|
||||
} else {
|
||||
$output .= '编辑金币';
|
||||
}
|
||||
$output .= '</h2>';
|
||||
$output .= '<form id="points" action="' . $current_url . '" method="post">';
|
||||
$output .= '<div>';
|
||||
|
||||
if ( $point_id ) {
|
||||
$output .= sprintf( '<input type="hidden" name="point_id" value="%d" />', intval( $point_id ) );
|
||||
}
|
||||
|
||||
$output .= '<input type="hidden" name="action" value="edit" />';
|
||||
$output .= '<p class="usermail">';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">用户邮箱</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="user_mail" value="%s" />', $user_mail );
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">用户在网站的注册邮箱</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p class="userid">';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">用户ID</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="user_id" value="%s" />', $user_id );
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">输入用户ID,与用户邮箱勿冲突</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">日期&时间</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="datetime" value="%s" id="datetimepicker" />', esc_attr( $datetime ) );
|
||||
$output .= ' ';
|
||||
$output .= '<span class="description">格式 : YYYY-MM-DD HH:MM:SS【可忽略,自动生成】</span>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">描述</span>';
|
||||
$output .= '<br>';
|
||||
$output .= '<textarea name="description">';
|
||||
$output .= stripslashes( $description );
|
||||
$output .= '</textarea>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">金币</span>';
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<input type="text" name="points" value="%s" />', esc_attr( $num_points ) );
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$status_descriptions = array(
|
||||
'accepted' => '正常',
|
||||
'pending' => '待审',
|
||||
'rejected' => '驳回',
|
||||
);
|
||||
$output .= '<p>';
|
||||
$output .= '<label>';
|
||||
$output .= '<span class="title">状态</span>';
|
||||
$output .= ' ';
|
||||
$output .= '<select name="status">';
|
||||
foreach ( $status_descriptions as $key => $label ) {
|
||||
$selected = $key == $status ? ' selected="selected" ' : '';
|
||||
$output .= '<option ' . $selected . ' value="' . esc_attr( $key ) . '">' . $label . '</option>';
|
||||
}
|
||||
$output .= '</select>';
|
||||
$output .= '</label>';
|
||||
$output .= '</p>';
|
||||
$output .= wp_nonce_field( 'save', 'points-nonce', true, false );
|
||||
$output .= sprintf( '<input class="button" type="submit" name="save" value="%s"/>', '保存' );
|
||||
$output .= ' ';
|
||||
$output .= sprintf( '<a class="cancel" href="%s">%s</a>', $cancel_url, $saved ? '返回' : '取消' );
|
||||
$output .= '</div>';
|
||||
$output .= '</form>';
|
||||
$output .= '</div>';
|
||||
echo $output;
|
||||
}
|
||||
}
|
174
class/points/class-points-shortcodes.php
Normal file
174
class/points/class-points-shortcodes.php
Normal file
|
@ -0,0 +1,174 @@
|
|||
<?php
|
||||
/**
|
||||
* class-points-shortcodes.php
|
||||
*/
|
||||
class Points_Shortcodes {
|
||||
/**
|
||||
* Add shortcodes.
|
||||
*/
|
||||
public static function init() {
|
||||
add_shortcode( 'points_users_list', [ __CLASS__, 'points_users_list' ] );
|
||||
add_shortcode( 'points_user_points', [ __CLASS__, 'points_user_points' ] );
|
||||
add_shortcode( 'pay', [__CLASS__, 'pay' ] );
|
||||
add_shortcode( 'points_user_points_details', [ __CLASS__, 'points_user_points_details' ] );
|
||||
|
||||
}
|
||||
public static function points_users_list ( $atts, $content = null ) {
|
||||
$options = shortcode_atts(
|
||||
[
|
||||
'limit' => 10,
|
||||
'order_by' => 'points',
|
||||
'order' => 'DESC'
|
||||
],
|
||||
$atts
|
||||
);
|
||||
extract( $options );
|
||||
$output = "";
|
||||
$pointsusers = Points::get_users();
|
||||
if ( sizeof( $pointsusers )>0 ) {
|
||||
foreach ( $pointsusers as $pointsuser ) {
|
||||
$total = Points::get_user_total_points( $pointsuser );
|
||||
$output .='<div class="points-user">';
|
||||
$output .= '<span style="font-weight:bold;width:100%;" class="points-user-username">';
|
||||
$output .= get_user_meta ( $pointsuser, 'nickname', true );
|
||||
$output .= ':</span>';
|
||||
$output .= '<span class="points-user-points">';
|
||||
$output .= " ". $total . " 金币";
|
||||
$output .= '</span>';
|
||||
$output .= '</div>';
|
||||
}
|
||||
} else {
|
||||
$output .= '<p>No users</p>';
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
public static function points_user_points ( $atts, $content = null ) {
|
||||
$output = "";
|
||||
$options = shortcode_atts(['id' => ""],
|
||||
$atts
|
||||
);
|
||||
extract( $options );
|
||||
if ( $id == "" ) {
|
||||
$id = get_current_user_id();
|
||||
}
|
||||
if ( $id !== 0 ) {
|
||||
$points = Points::get_user_total_points( $id, 'accepted' );
|
||||
$output .= $points;
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/*付费可见短代码开始*/
|
||||
|
||||
public static function pay($atts, $content = null) {
|
||||
global $wpdb;
|
||||
$user_id = get_current_user_id();
|
||||
$description = get_the_ID();
|
||||
$result = $wpdb->get_row("SELECT description FROM " . Points_Database::points_get_table("users") . " WHERE user_id=" . $user_id . " AND description=" . $description . " AND status='accepted' LIMIT 0, 3;", ARRAY_A )['description']; //验证是否支付
|
||||
extract(shortcode_atts(['point' => "10"], $atts));
|
||||
$notice = '';
|
||||
$pay_content = get_post_meta($description, 'pay_content', true);
|
||||
if (!empty($pay_content) && $pay_content != $content) {
|
||||
update_post_meta($description, 'pay_content', $content, true);
|
||||
} else {
|
||||
add_post_meta($description, 'pay_content', $content, true);
|
||||
}
|
||||
if (is_user_logged_in()) {
|
||||
if ($result == $description || current_user_can('administrator')) {
|
||||
$notice.= '<div class="alert alert-info"">';
|
||||
$notice.= $content;
|
||||
$notice.= '</div>';
|
||||
} else {
|
||||
if (Points::get_user_total_points($user_id, 'accepted') < $point) {
|
||||
$notice.= '<div class="alert alert-info"">';
|
||||
$notice.= '<p style="color:red;">本段内容需要支付 ' . $point . '金币查看</p>';
|
||||
$notice.= '<p style="color:red;">您当前拥有 <em><strong>' . Points::get_user_total_points($user_id, 'accepted') . '</strong></em> 金币,您的金币不足,请充值</p>';
|
||||
$notice.= '<p><a class="lhb" href="' . get_permalink(git_page_id('chongzhi')) . '" target="_blank" rel="nofollow" data-original-title="立即充值" title="">立即充值</a></p>';
|
||||
$notice.= '</div>';
|
||||
} else {
|
||||
$notice.= '<div id="pay_notice" class="alert alert-info"">';
|
||||
$notice.= '<p style="color:red;">本段内容需要付费查看,您当前拥有 <em><strong>' . Points::get_user_total_points($user_id, 'accepted') . '</strong></em> 金币</p>';
|
||||
$notice.= '<p><a class="lhb" style="cursor: pointer;" onclick="pay_point();">点击购买</a></p>';
|
||||
$notice.= '</div>';
|
||||
$notice.= '<p id="pay_success"></p>';
|
||||
echo '<script type="text/javascript">
|
||||
function pay_point() {
|
||||
ajax.post("' . admin_url('admin-ajax.php') . '", "action=pay_buy&point=' . $point . '&userid=' . $user_id . '&id=' . $description . '", function(n) {
|
||||
null != n && (document.getElementById("pay_notice").style.display = "none", document.getElementById("pay_success").innerHTML = "<div class=\"alert alert-info\">" + n + "</div>");
|
||||
});
|
||||
}</script>';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
global $wp;
|
||||
$current_url = home_url(add_query_arg([] , $wp->request));
|
||||
$login_uri = '<a href="' . esc_url(wp_login_url($current_url)) . '" data-original-title="点击登录">点击登录</a>';
|
||||
$notice.= '<div class="alert alert-info"">';
|
||||
$notice.= '<p style="color:red;">查看本段内容需要支付 ' . $point . ' 金币</p>';
|
||||
$notice.= '<p style="color:red;">您尚未登录,请 ' . $login_uri . ' 或者 <a href="' . esc_url(wp_registration_url()) . '">立即注册</a> </p>';
|
||||
$notice.= '</div>';
|
||||
}
|
||||
return $notice;
|
||||
}
|
||||
/*付费可见短代码结束*/
|
||||
/**
|
||||
* Shortcode. 显示用户的金币细节
|
||||
*/
|
||||
public static function points_user_points_details ( $atts, $content = null ) {
|
||||
$options = shortcode_atts(
|
||||
[
|
||||
'user_id' => '',
|
||||
'order_by' => 'point_id',
|
||||
'order' => 'DESC',
|
||||
'description' => true
|
||||
],
|
||||
$atts
|
||||
);
|
||||
extract( $options );
|
||||
date_default_timezone_set('Asia/Shanghai');
|
||||
if ( is_string( $description ) && ( ( $description == '0' ) || ( strtolower( $description ) == 'false' ) ) ) {
|
||||
$description = false;
|
||||
}
|
||||
|
||||
$desc_th = '';
|
||||
if ( $description ) {
|
||||
$desc_th = '<th>描述</th>';
|
||||
}
|
||||
global $wp_query;
|
||||
$curauth = $wp_query->get_queried_object();
|
||||
$user_id = $curauth->ID;
|
||||
$points = Points::get_points_by_user( $user_id );
|
||||
$output = '<table class="points_user_points_table">' .
|
||||
'<tr>' .
|
||||
'<th>日期时间' .
|
||||
'<th>金币</th>' .
|
||||
'<th>类别</th>' .
|
||||
'<th>状态</th>' .
|
||||
$desc_th .
|
||||
'</tr>';
|
||||
if ( $user_id !== 0 ) {
|
||||
if ( sizeof( $points ) > 0 ) {
|
||||
foreach ( $points as $point ) {
|
||||
$desc_td = '';
|
||||
if ( $description ) {
|
||||
$desc_td = '<td>' . $point->description . '</td>';
|
||||
}
|
||||
if($point->points > 0){ $leibie = '充值';}elseif($point->points < 0){$leibie = '消费';}
|
||||
$output .= '<tr>' .
|
||||
'<td>' . $point->datetime . '</td>' .
|
||||
'<td>' . $point->points . '</td>' .
|
||||
'<td>' . $leibie . '</td>' .
|
||||
'<td>' . $point->status . '</td>' .
|
||||
$desc_td .
|
||||
'</tr>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= '</table>';
|
||||
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
Points_Shortcodes::init();
|
228
class/points/class-points.php
Normal file
228
class/points/class-points.php
Normal file
|
@ -0,0 +1,228 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Points_Database class
|
||||
*/
|
||||
class Points_Database {
|
||||
public static $prefix = "points_";
|
||||
public static function points_get_table( $table ) {
|
||||
global $wpdb;
|
||||
$result = "";
|
||||
switch ( $table ) {
|
||||
case "users":
|
||||
$result = $wpdb->prefix . self::$prefix . "users";
|
||||
break;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Points class
|
||||
*/
|
||||
class Points {
|
||||
|
||||
public static function get_points_by_user ( $user_id, $limit = null, $order_by = null, $order = null, $output = OBJECT, $offset = 0 ) {
|
||||
global $wpdb;
|
||||
|
||||
$limit_str = '';
|
||||
if ( isset( $limit ) && ( $limit !== null ) ) {
|
||||
$limit_str = ' LIMIT ' . $offset . ' ,' . $limit;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if ( isset( $order_by ) && ( $order_by !== null ) ) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if ( isset( $order ) && ( $order !== null ) ) {
|
||||
$order_str = " " . $order;
|
||||
}
|
||||
|
||||
$result = $wpdb->get_results('SELECT * FROM ' . Points_Database::points_get_table( 'users' ) . " WHERE user_id = '$user_id'" . $order_by_str . $order_str . $limit_str, $output );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_user_total_points ( $user_id, $status = null ) {
|
||||
global $wpdb;
|
||||
|
||||
$result = 0;
|
||||
|
||||
$where_status = '';
|
||||
if ( $status !== null ) {
|
||||
$where_status = " AND status = '" . $status . "'";
|
||||
}
|
||||
$points = $wpdb->get_row("SELECT SUM(points) as total FROM " . Points_Database::points_get_table( "users" ) . " WHERE user_id = '$user_id' " . $where_status);
|
||||
|
||||
if ( $points && ( $points->total !== NULL ) ) {
|
||||
$result = $points->total;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_users_total_points ( $limit = null, $order_by = null, $order = null, $status = null ) {
|
||||
global $wpdb;
|
||||
|
||||
$where_status = '';
|
||||
if ( $status !== null ) {
|
||||
$where_status = " WHERE status = '" . $status . "'";
|
||||
}
|
||||
$points = $wpdb->get_results("SELECT SUM(points) as total, user_id FROM " . Points_Database::points_get_table( "users" ) . $where_status . " GROUP BY user_id");
|
||||
|
||||
return $points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get users id who have some points
|
||||
* @param $user_id
|
||||
* @return array
|
||||
*/
|
||||
public static function get_users() {
|
||||
global $wpdb;
|
||||
|
||||
$users_id = $wpdb->get_results("SELECT user_id FROM " . Points_Database::points_get_table( "users" ) . " GROUP BY user_id");
|
||||
|
||||
$result = array();
|
||||
if ( sizeof( $users_id ) > 0 ) {
|
||||
foreach ( $users_id as $user_id ) {
|
||||
$result[] = $user_id->user_id;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function set_points ( $points, $user_id, $info = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$values = array( 'points' => $points );
|
||||
|
||||
if ( isset( $info['datetime'] ) && ( $info['datetime'] !== "" ) ) {
|
||||
$values['datetime'] = $info['datetime'];
|
||||
} else {
|
||||
$values['datetime'] = date('Y-m-d H:i:s', time() );
|
||||
}
|
||||
if ( isset( $info['description'] ) ) {
|
||||
$values['description'] = $info['description'];
|
||||
}
|
||||
if ( isset( $info['status'] ) ) {
|
||||
$values['status'] = $info['status'];
|
||||
}
|
||||
if ( isset( $info['type'] ) ) {
|
||||
$values['type'] = $info['type'];
|
||||
}
|
||||
if ( isset( $info['data'] ) ) {
|
||||
$values['data'] = $info['data']; // yet serialized
|
||||
}
|
||||
if ( isset( $info['ip'] ) ) {
|
||||
$values['ip'] = $info['ip'];
|
||||
}
|
||||
if ( isset( $info['ipv6'] ) ) {
|
||||
$values['ipv6'] = $info['ipv6'];
|
||||
}
|
||||
$values['user_id'] = $user_id;
|
||||
|
||||
$rows_affected = $wpdb->insert( Points_Database::points_get_table("users"), $values );
|
||||
|
||||
return $rows_affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a points list.
|
||||
* @param int $limit
|
||||
* @param string $order_by
|
||||
* @param string $order
|
||||
* @return Ambigous <mixed, NULL, multitype:, multitype:multitype: , multitype:Ambigous <multitype:, NULL> >
|
||||
*/
|
||||
public static function get_points ( $limit = null, $order_by = null, $order = null, $output = OBJECT ) {
|
||||
global $wpdb;
|
||||
|
||||
$where_str = " WHERE status != 'removed'";
|
||||
|
||||
$limit_str = "";
|
||||
if ( isset( $limit ) && ( $limit !== null ) ) {
|
||||
$limit_str = " LIMIT 0 ," . $limit;
|
||||
}
|
||||
$order_by_str = "";
|
||||
if ( isset( $order_by ) && ( $order_by !== null ) ) {
|
||||
$order_by_str = " ORDER BY " . $order_by;
|
||||
}
|
||||
$order_str = "";
|
||||
if ( isset( $order ) && ( $order !== null ) ) {
|
||||
$order_str = " " . $order;
|
||||
}
|
||||
|
||||
$result = $wpdb->get_results("SELECT * FROM " . Points_Database::points_get_table( "users" ) . $where_str . $order_by_str . $order_str . $limit_str, $output );
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function get_point ( $point_id = null ) {
|
||||
global $wpdb;
|
||||
|
||||
$result = null;
|
||||
|
||||
if ( isset( $point_id ) && ( $point_id !== null ) ) {
|
||||
|
||||
$points_id_str = " WHERE point_id = " . (int)$point_id;
|
||||
$result = $wpdb->get_row("SELECT * FROM " . Points_Database::points_get_table( "users" ) . $points_id_str );
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function remove_points( $point_id ) {
|
||||
global $wpdb;
|
||||
|
||||
$values = array();
|
||||
$values['status'] = 'removed';
|
||||
|
||||
$rows_affected = $wpdb->update( Points_Database::points_get_table("users"), $values , array( 'point_id' => $point_id ) );
|
||||
|
||||
if ( !$rows_affected ) {
|
||||
$rows_affected = null;
|
||||
}
|
||||
return $rows_affected;
|
||||
}
|
||||
|
||||
public static function update_points( $point_id, $info = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
$values = array();
|
||||
|
||||
if ( isset( $info['user_id'] ) ) {
|
||||
$values['user_id'] = $info['user_id'];
|
||||
}
|
||||
if ( isset( $info['datetime'] ) ) {
|
||||
$values['datetime'] = $info['datetime'];
|
||||
}
|
||||
if ( isset( $info['description'] ) ) {
|
||||
$values['description'] = $info['description'];
|
||||
}
|
||||
if ( isset( $info['status'] ) ) {
|
||||
$values['status'] = $info['status'];
|
||||
}
|
||||
if ( isset( $info['points'] ) ) {
|
||||
$values['points'] = $info['points'];
|
||||
}
|
||||
if ( isset( $info['type'] ) ) {
|
||||
$values['type'] = $info['type'];
|
||||
}
|
||||
if ( isset( $info['data'] ) ) {
|
||||
$values['data'] = $info['data']; // yet serialized
|
||||
}
|
||||
if ( isset( $info['ip'] ) ) {
|
||||
$values['ip'] = $info['ip'];
|
||||
}
|
||||
if ( isset( $info['ipv6'] ) ) {
|
||||
$values['ipv6'] = $info['ipv6'];
|
||||
}
|
||||
|
||||
$rows_affected = $wpdb->update( Points_Database::points_get_table("users"), $values , array( 'point_id' => $point_id ) );
|
||||
|
||||
if ( !$rows_affected ) { // insert
|
||||
$rows_affected = null;
|
||||
}
|
||||
return $rows_affected;
|
||||
}
|
||||
}
|
59
class/points/points.php
Normal file
59
class/points/points.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
|
||||
include 'class-points.php';
|
||||
include 'class-points-admin.php';
|
||||
include 'class-points-shortcodes.php';
|
||||
|
||||
|
||||
class Points_Class {
|
||||
private static $notices = [];
|
||||
public static function init() {
|
||||
add_action( 'init', [ __CLASS__, 'wp_init' ] );
|
||||
add_action( 'admin_init', [ __CLASS__, 'activate' ] );
|
||||
}
|
||||
|
||||
public static function wp_init() {
|
||||
Points_Admin::init();
|
||||
}
|
||||
|
||||
/**
|
||||
* activation work.
|
||||
*
|
||||
*/
|
||||
public static function activate() {
|
||||
global $wpdb;
|
||||
|
||||
$charset_collate = '';
|
||||
if ( ! empty( $wpdb->charset ) ) {
|
||||
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
||||
}
|
||||
if ( ! empty( $wpdb->collate ) ) {
|
||||
$charset_collate .= " COLLATE $wpdb->collate";
|
||||
}
|
||||
|
||||
// create tables
|
||||
$points_users_table = Points_Database::points_get_table("users");
|
||||
if ( $wpdb->get_var( "SHOW TABLES LIKE '$points_users_table'" ) != $points_users_table ) {
|
||||
$queries[] = "CREATE TABLE $points_users_table (
|
||||
point_id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
user_id BIGINT(20) UNSIGNED NOT NULL,
|
||||
points BIGINT(20) DEFAULT 0,
|
||||
datetime datetime NOT NULL,
|
||||
description varchar(5000),
|
||||
ref_id BIGINT(20) DEFAULT null,
|
||||
ip int(10) unsigned default NULL,
|
||||
ipv6 decimal(39,0) unsigned default NULL,
|
||||
data longtext default NULL,
|
||||
status varchar(10) NOT NULL DEFAULT 'accepted',
|
||||
type varchar(32) NULL,
|
||||
PRIMARY KEY (point_id)
|
||||
) $charset_collate;";
|
||||
}
|
||||
if ( !empty( $queries ) ) {
|
||||
require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
|
||||
dbDelta( $queries );
|
||||
}
|
||||
}
|
||||
}
|
||||
Points_Class::init();
|
|
@ -302,7 +302,7 @@ $gdk_options = [
|
|||
],
|
||||
[
|
||||
'name' => '关键词,IP,邮箱屏蔽',
|
||||
'desc' => '开启 【启用后,在WordPress-设置-讨论-黑名单中添加想要屏蔽的关键词,邮箱,网址,IP地址,每行一个】<a class="key_word" target="_blank" href="https://img.alicdn.com/imgextra/i4/1597576229/TB2FnxnlpXXXXcDXXXXXXXXXXXX_!!1597576229.png">如图设置</a>',
|
||||
'desc' => '开启 【启用后,在WordPress-设置-讨论-黑名单中添加想要屏蔽的关键词,邮箱,网址,IP地址,每行一个】<a class="key_word" target="_blank" href="https://ae03.alicdn.com/kf/U146356e193b14a6da3f7cbb9cf507ea3D.png">点击查看如图设置</a>',
|
||||
'id' => 'git_spam_keywords',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
|
@ -317,79 +317,66 @@ $gdk_options = [
|
|||
'desc' => '开启 【启用后,屏蔽含有过长网址(超过50个字符)的评论,当然如果你已经选择了上面的选项的话,就不用选择了】',
|
||||
'id' => 'git_spam_long',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
[
|
||||
'name' => '文章版权声明',
|
||||
'desc' => '此处输入的文字将出现在每篇文章最底部,你可以使用:{{title}}表示文章标题,{{link}}表示文章链接',
|
||||
'id' => 'git_copyright_b',
|
||||
'type' => 'textarea',
|
||||
'std' => '极客公园 , 版权所有丨如未注明 , 均为原创丨本网站采用<a href="http://creativecommons.org/licenses/by-nc-sa/3.0/" rel="nofollow" target="_blank" title="BY-NC-SA授权协议">BY-NC-SA</a>协议进行授权 <br >转载请注明原文链接:<a href="{{link}}" target="_blank" title="{{title}}">{{title}}</a>'
|
||||
]
|
||||
],
|
||||
'支付设置' => [
|
||||
'高级设置' => [
|
||||
[
|
||||
'title' => '统一支付设置',
|
||||
'type' => 'title'
|
||||
],
|
||||
[
|
||||
'name' => '金币和RMB兑换关系',
|
||||
'desc' => '请输入兑换关系,比如1RMB=10金币,请慎重选择,一旦设置好后面不能修改的',
|
||||
'id' => 'git_payjs_rate',
|
||||
'type' => 'number',
|
||||
'std' => 10
|
||||
],
|
||||
[
|
||||
'name' => '选择一个支付方式',
|
||||
'desc' => '两种方案选择其中一种,必须选择一个哦',
|
||||
'id' => 'git_payjs',
|
||||
'name' => '网站支付功能',
|
||||
'desc' => '开启网站支付功能需要HTTPS支持,需要开通Payjs使用,<a class="key_word" href="https://payjs.cn/ref/ZVEMKD" target="_blank" >点击注册Payjs</a>',
|
||||
'id' => 'gdk_payjs',
|
||||
'type' => 'radio',
|
||||
'options' => [
|
||||
'0' => '禁用',
|
||||
'1' => '开启'
|
||||
],
|
||||
'std' => '1'
|
||||
'std' => '0'
|
||||
],
|
||||
[
|
||||
'title' => 'PayJs支付设置 <a href="https://payjs.cn/ref/ZVEMKD" target="_blank" >注册PayJs</a> 【微信官方,微信正规渠道,强烈推荐】',
|
||||
'type' => 'title'
|
||||
'name' => '金币和RMB兑换关系',
|
||||
'desc' => '请输入兑换关系,默认1RMB=10金币,请慎重选择,一旦设置好后面不能修改的,本选项仅对会员金币支付生效,游客免登陆支持不受影响',
|
||||
'id' => 'gdk_rate',
|
||||
'type' => 'number',
|
||||
'std' => 10
|
||||
],
|
||||
[
|
||||
'name' => 'PayJs商户号',
|
||||
'desc' => '',
|
||||
'id' => 'git_payjs_id',
|
||||
'id' => 'gdk_payjs_id',
|
||||
'type' => 'text',
|
||||
'std' => 2333333333
|
||||
],
|
||||
[
|
||||
'name' => 'PayJs密钥',
|
||||
'desc' => '',
|
||||
'id' => 'git_payjs_secret',
|
||||
'id' => 'gdk_payjs_key',
|
||||
'type' => 'text',
|
||||
'std' => 444444444
|
||||
]
|
||||
],
|
||||
'高级设置' => [
|
||||
[
|
||||
'name' => 'jQuery来源设置',
|
||||
'desc' => '选择一个适合自己的jQuery公共库来源',
|
||||
'id' => 'git_jq',
|
||||
'name' => 'jQuery加载位置设置',
|
||||
'desc' => '选择一个适合自己网站的jQuery加载位置,默认是底部加载',
|
||||
'id' => 'gdk_jq',
|
||||
'type' => 'radio',
|
||||
'options' => [
|
||||
'1' => '远程jQuery库【底部加载,速度快,兼容差】',
|
||||
'0' => '本地jQuery库【头部加载,速度慢,兼容好】'
|
||||
'1' => '底部加载,速度快',
|
||||
'0' => '头部加载,兼容好'
|
||||
],
|
||||
'std' => '1'
|
||||
],
|
||||
[
|
||||
'name' => 'HTML代码压缩',
|
||||
'desc' => '启用 【开启后,将压缩网页HTML代码,可读性会降低,但是性能略有提升】',
|
||||
'id' => 'git_compress',
|
||||
'id' => 'gdk_compress',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
[
|
||||
'name' => '图片懒加载',
|
||||
'desc' => '启用 【开启后,网站图片将进行懒加载】',
|
||||
'id' => 'git_lazyload',
|
||||
'id' => 'gdk_lazyload',
|
||||
'type' => 'checkbox'
|
||||
],
|
||||
[
|
||||
|
|
|
@ -361,8 +361,9 @@ depend('gdk_lock_login','#row-gdk_failed_login_limit,#row-gdk_lockout_duration')
|
|||
depend('gdk_smtp','#row-gdk_smtp_username,#row-gdk_smtp_host,#row-gdk_smtp_port,#row-gdk_smtp_mail,#row-gdk_smtp_password');
|
||||
depend('gdk_baidu_push','#row-gdk_baidu_api');
|
||||
depend('gdk_tag_link','#row-gdk_tag_num');
|
||||
depend('gdk_cdn','#row-gdk_cdn_host,#row-gdk_cdn_ext,#row-gdk_cdn_dir,#row-gdk_cdn_style,#row-git_cdn_water');
|
||||
depend('gdk_cdn','#row-gdk_cdn_host,#row-gdk_cdn_ext,#row-gdk_cdn_dir,#row-gdk_cdn_style,#row-gdk_cdn_water');
|
||||
depend('gdk_h5notice','#row-git_notification_title,#row-git_notification_days,#row-git_notification_cookie,#row-git_notification_icon,#row-git_notification_link,#row-git_notification_body');
|
||||
depend('gdk_payjs','#row-gdk_rate,#row-git_payjs_rate,#row-gdk_payjs_id,#row-gdk_payjs_key');
|
||||
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -44,6 +44,7 @@ add_action('login_head', 'gdk_wps_login_error');
|
|||
add_filter('pre_option_link_manager_enabled', '__return_true');
|
||||
|
||||
add_filter('show_admin_bar', '__return_false');
|
||||
add_filter('run_wptexturize', '__return_false');
|
||||
|
||||
//移除 WP_Head 无关紧要的代码
|
||||
if(gdk_option('gdk_diasble_head_useless')){
|
||||
|
|
|
@ -261,6 +261,43 @@ function git_list_shortcode_handler($atts, $content = '') {
|
|||
add_shortcode('list', 'git_list_shortcode_handler');
|
||||
|
||||
|
||||
//表格短代码
|
||||
function table_shortcode_handler( $atts, $content='' ) {
|
||||
extract( shortcode_atts( ['width' => '100%'], $atts ) );
|
||||
$output = '';
|
||||
$content = trim($content);
|
||||
$trs = explode("\r\n", $content);
|
||||
$ths = explode(" ", $trs[0]);//表头数组
|
||||
$output .= '<thead><tr>';
|
||||
//var_dump($ths);
|
||||
foreach($ths as $th){
|
||||
$output .= '<th>'.$th.'</th>';
|
||||
}
|
||||
$output .= '</tr></thead>';
|
||||
$output .= '<tbody>';
|
||||
unset($trs[0]);
|
||||
foreach($trs as $tr){
|
||||
$tr = trim($tr);
|
||||
if($tr){
|
||||
$tds = explode(" ", $tr);
|
||||
$output .= '<tr>';
|
||||
foreach($tds as $td){
|
||||
$td = trim($td);
|
||||
if($td){
|
||||
$output .= '<td>'.$td.'</td>';
|
||||
}
|
||||
}
|
||||
$output .= '</tr>';
|
||||
}
|
||||
}
|
||||
$output .= '</tbody>';
|
||||
$width = ' width="'.$width.'"';
|
||||
$output = '<table class="gdk-table"'.$width.' >'.$output.'</table>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
add_shortcode( 'table', 'table_shortcode_handler' );
|
||||
|
||||
//WordPress 段代码按钮集合
|
||||
function gdk_shortcode_list() {
|
||||
$wpshortcodes = [
|
||||
|
|
|
@ -26,7 +26,7 @@ define('GDK_BASE_URL', plugin_dir_url( __FILE__ ) );//插件目录url
|
|||
define('GDK_ROOT_PATH', plugin_dir_path( __FILE__ ) );//插件目录路径
|
||||
|
||||
//加载各种资源
|
||||
include('class/class_load.php');//加载各种类
|
||||
include('framework/frame_load.php');//加载后台框架
|
||||
include('class/class_load.php');//加载各种类
|
||||
include('functions/func_load.php');//加载函数
|
||||
include('assets/assets_load.php');//加载静态资源
|
||||
|
|
Loading…
Reference in a new issue