HEX
Server: nginx/1.16.1
System: Linux VM-0-14-centos 4.18.0-348.7.1.el8_5.x86_64 #1 SMP Wed Dec 22 13:25:12 UTC 2021 x86_64
User: www (1000)
PHP: 8.3.31
Disabled: 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
Upload Files
File: /www/wwwroot/www.sceycy.com/wp-content/themes/Zing-Pro/public/dahuzi-contact.php
<?php
function app_output_buffer() {
    ob_start();
} // soi_output_buffer
add_action('init', 'app_output_buffer');

// 数据库安装
function install(){
    global $wpdb;
    
    $contact = $wpdb->prefix . 'dahuzi_contact';

    $contact_sql = "CREATE TABLE IF NOT EXISTS `{$contact}` (
        `id` int(8) NOT NULL AUTO_INCREMENT,
        `yourname` char(255) NOT NULL,
        `mail` char(255) NOT NULL,
        `phone` char(255) NOT NULL,
        `message` char(255) NOT NULL,
        `source` char(255) NOT NULL,
        `status` int(1) NOT NULL,
 
        `date` date NOT NULL,
        UNIQUE KEY `id` (`id`)
    ) ENGINE=MyISAM DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci";
    
    
    if($wpdb->get_var("show tables like $contact") != $contact) {
        $wpdb->query( $contact_sql );  
    }
} 
function dahuzi_load_theme() {   
    install(); //执行数据库安装   
} 
add_action( 'after_switch_theme', 'dahuzi_load_theme' );

function contact_menu(){
    global $wpdb;
    $contact = $wpdb->prefix . 'dahuzi_contact';
    $contact_count = $wpdb->get_var( "SELECT count(*) FROM $contact WHERE status = 1" );
    if($contact_count>0){
    add_menu_page('在线留言', '在线留言<span class="awaiting-mod"><span class="pending-count">'.$wpdb->get_var( "SELECT count(*) FROM $contact WHERE status = 1" ).'</span></span>', 'manage_options', 'contact.php','','dashicons-testimonial', 100);
    }else{
    add_menu_page('在线留言', '在线留言', 'manage_options', 'contact.php', '', 'dashicons-testimonial', 100);
    }
    add_submenu_page('contact.php','在线留言', '在线留言', 'manage_options', 'contact.php', 'contact_function');
}
add_action('admin_menu', 'contact_menu');


function contact_function(){
?>
<style>
    .user .info { margin-top: 20px; }
    .user .info table{border-collapse: collapse;  border: none; width: 100%; }
    .user .info td,.user .info th{ border: solid #CCC 1px; text-align: center; height: 30px; padding: 5px 0px; }
    .bg { background: #FFF; }
</style>
<div class="wrap user">
    <h2>在线留言记录</h2>
    <?php
        $get_message = isset( $_GET['message'] ) ? $_GET['message'] : 0;
        if( $get_message == 1 ){ 
            echo "<div id=\"message\" class=\"updated fade\"><p>状态变更成功!</p></div>";
        }else if( $get_message == 2 ){ 
            echo "<div id=\"message\" class=\"updated fade\"><p>留言删除成功!</p></div>";
        }
    ?>
    <div class="info">
        <table>
            <thead>
                <tr>
                    <th><span class="dashicons dashicons-editor-ul"></span></th>
                    <th>姓名/昵称</th>
                    <th>联系邮箱</th>
                    <?php if( get_locale() == 'zh_CN' ){ echo '<th>联系电话</th>'; }?>
                    <th>留言内容</th>
                    <th>留言日期</th>
                    <th>来源页面</th>
                    <th>当前状态</th>
                    <th>相关操作</th>
                </tr>
            </thead>
            <?php 
                global $wpdb;
                $contact = $wpdb->prefix . 'dahuzi_contact';
                $count = $wpdb->get_var( "SELECT count(*) FROM $contact" );
                $paged_count = $count/14;
                $paged = isset($_GET['paged']) ? $_GET['paged'] : 1 ;//当前页
                $d = ($paged-1)*14;
                $prev_page = $paged - 1 < 1 ? $paged : $paged - 1;//上一页
                $next_page = $paged + 1 > ceil($paged_count) ? ceil($paged) : $paged + 1;//下一页
                $contact = $wpdb->get_results( "SELECT * FROM $contact ORDER BY id DESC LIMIT $d,14");
            ?>
            <tbody>
                <?php 
                    $class = 'bg';
                    $i = 1; 
                ?>
                <?php foreach ($contact as $value) { ?>
                <tr class="<?php echo $class; ?>">
                    <td><?php echo $i; ?></td>
                    <td><?php echo $value->yourname; ?></td>
                    <td><?php echo $value->mail ?: '用户未填写'; ?></td>
                     <?php if( get_locale() == 'zh_CN' ){ echo '<td>'.$value->phone.'</td>'; }?>
                    <td style="width:20%;padding:7px 15px"><?php echo $value->message; ?></td>
                    <td><?php echo $value->date; ?></td>
                    <td style="width:15%;padding:0 10px"><?php echo $value->source; ?></td>
                    <?php
                        if( $value->status == 1){
                            echo "<td style='color:#F44336'>未处理</td>";
                        }else if( $value->status == 2 ){
                            echo "<td style='color:#009688'>处理中</td>";
                        }else if( $value->status == 3 ){
                            echo "<td style='color:#444'>已处理</td>";
                        }
                    ?>
                    <td>
                        <a href="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=contact.php&id=<?php echo $value->id; ?>&action=status#status_change">状态变更</a>&nbsp;
                        <a class='del' href="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=contact.php&id=<?php echo $value->id; ?>&action=del">删除</a>
                    </td>
                </tr>

                <?php
                        $i++;
                        $class = empty($class)?"bg":"";
                    } 
                ?>
            </tbody>
        </table>
        <script>
            jQuery(function(){

                jQuery('.del').click(function(event) {
                    event.preventDefault();
                    if(window.confirm('你确定要删除这条记录吗?')){
                        var url = jQuery(this).attr('href');
                        window.location.href=url;
                         return true;
                      }else{
                         return false;
                     }
                });

            });
        </script>
        <?php if($count>14){?>
        <div class="tablenav bottom">

            <div class="tablenav-pages">
                <span class="displaying-num"><?php echo $count; ?>条留言</span>

                <?php if($paged==1){?>
                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">«</span>
                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">‹</span>
                <?php }else{?>
                <a class="first-page button" href="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=contact.php"><span class="screen-reader-text">首页</span><span aria-hidden="true">«</span></a>
                <a class="prev-page button" href="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=contact.php&paged=<?php echo $prev_page; ?>"><span class="screen-reader-text">上一页</span><span aria-hidden="true">‹</span></a>
                <?php }?>
                <span class="screen-reader-text">当前页</span><span id="table-paging" class="paging-input"><span class="tablenav-paging-text">第<?php echo $paged; ?>页,共<span class="total-pages"><?php echo ceil($paged_count); ?></span>页</span></span>
                <?php if($paged!=ceil($paged_count)){?>
                <a class="next-page button" href="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=contact.php&paged=<?php echo $next_page; ?>"><span class="screen-reader-text">下一页</span><span aria-hidden="true">›</span></a>
                <a class="last-page button" href="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=contact.php&paged=<?php echo ceil($paged_count);?>"><span class="screen-reader-text">尾页</span><span aria-hidden="true">»</span></a></span>
                <?php }else{?>
                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">›</span>
                <span class="tablenav-pages-navspan button disabled" aria-hidden="true">»</span>
                <?php }?>
            </div>

        </div>
        <?php }?>
    </div>
    <?php
    if( isset($_GET['action']) ){
    if( $_GET['action'] == 'status' ){ ?>
    <?php
        global $wpdb;
        $id = $_GET['id'] ?: '';
        $contact_table = $wpdb->prefix . 'dahuzi_contact';
        $contact = $wpdb->get_row( "SELECT * FROM $contact_table WHERE id=$id");
        if( $_POST['publish'] == '提交' ){
            $data = array(
                'id' => $contact->id,
                'yourname' => $contact->yourname,
                'mail' => $contact->mail,
                'phone' => $contact->phone,
                'message' => $contact->message,
                'status' => $_POST['status'],
                'date' => $contact->date,
                'source' => $contact->source
            );
            $wpdb->update( $contact_table, $data, array( 'id' => $_GET['id'] ) );
            wp_redirect("admin.php?page=contact.php&message=1");
        }
    ?>
    <div style="position:fixed;height:100%;width:100%;top:0;left:0;background:#1e1e1ed9;z-index:999999;-webkit-animation:fade-zoom-in .3s forwards;-o-animation:fade-zoom-in .3s forwards;animation:fade-zoom-in .3s forwards">
    <div style="max-width:460px;padding:25px 45px;margin:auto;position:absolute;width:100%;left:0;right:0;height:200px;top:0;bottom:0;background:#fff;border-radius:5px">
    <h2 id="status_change">留言状态变更</h2>
    <form action="" method="POST">
        <table class="form-table" style="margin-bottom:25px">
            <tr>
                <th><label><?php echo $contact->yourname; ?> 的留言记录</label></th>
                <td>
                    <label style="margin-right:10px"><input name="status" type="radio" <?php $contact->status == 1 ? print('checked="checked"') : print(''); ?> value="1" />未处理</label>
                    <label style="margin-right:10px"><input name="status" type="radio" <?php $contact->status == 2 ? print('checked="checked"') : print(''); ?> value="2" />处理中</label>
                    <label style="margin-right:10px"><input name="status" type="radio" <?php $contact->status == 3 ? print('checked="checked"') : print(''); ?> value="3" />已处理</label>
                </td>
            </tr>
            
        </table>
        <input style="margin-right:10px" type="submit" name="publish" id="publish" class="button button-primary button-large" value="提交" accesskey="p">
    <a class='button button-large' href="<?php bloginfo('url'); ?>/wp-admin/admin.php?page=contact.php">返回</a>
    </form>
    </div>
    </div>
    <?php
        }
        } ?>
    <?php
    if( isset($_GET['action']) ){
        if( $_GET['action'] == 'del' ){
            global $wpdb;
            $id = $_GET['id'];
            $contact_table = $wpdb->prefix . 'dahuzi_contact';
            $wpdb->query("DELETE FROM $contact_table WHERE id=$id");
            wp_redirect("admin.php?page=contact.php&message=2");
        }
    }
    ?>
</div>

<?php
}


/** --------------------------------------------------------------------------------- *
 *  提交留言 Ajax
 *  --------------------------------------------------------------------------------- */
function dahuzi_contact_ajax(){

    if( $_POST['yourname'] == '' ){
        $error = 1;
    }
    if( $_POST['phone'] == '' && get_locale() == 'zh_CN' ){
        $error = 1;
    }
    if( $_POST['mail'] == '' && get_locale() != 'zh_CN' ){
        $error = 1;
    }
    if( $_POST['message'] == '' ){
        $error = 1;
    }

    $phonenumber = $_POST['phone'];
    $pattern = '/[一-龥]/u';

    if( !preg_match("/^1[34578]{1}\d{9}$/",$phonenumber) && get_locale() == 'zh_CN' ){

        $msg = json_encode(
            array(
                'state' => 201,
                'tips' => '提交失败,手机号码有误,请输入正确的手机号码!'
            )
        );

    }elseif( !preg_match($pattern, $_POST['message'])  && get_locale() == 'zh_CN' ) {

        $msg = json_encode(
            array(
                'state' => 201,
                'tips' => '提交失败,您的留言内容中必须包含汉字!'
            )
        );

    }elseif( !filter_var($_POST['mail'], FILTER_VALIDATE_EMAIL) && get_locale() != 'zh_CN' ) {

        $msg = json_encode(
            array(
                'state' => 201,
                'tips' => __('The e-mail address entered is invalid.', 'dahuzi_theme')
            )
        );

    }elseif( !$error ){

        global $wpdb;
        $data = array(
            'id'     => '',
            'yourname'   => htmlspecialchars($_POST['yourname'],ENT_QUOTES,"UTF-8"),
            'mail'   => htmlspecialchars($_POST['mail'],ENT_QUOTES,"UTF-8"),
            'phone'  => htmlspecialchars($_POST['phone'],ENT_QUOTES,"UTF-8"),
            'message'=> htmlspecialchars($_POST['message'],ENT_QUOTES,"UTF-8"),
            'source' => htmlspecialchars($_POST['current_url'],ENT_QUOTES,"UTF-8"),
            'status' => '1',
            'date'   => date('Y-m-d',time())
        );
        $contact = $wpdb->prefix . 'dahuzi_contact';
        $s = $wpdb->insert( $contact , $data );
        $to = dahuzi('mail_contact') ?: get_option('admin_email'); //通知邮箱
        $date_format = get_option( 'date_format' ); //获取wp后台设置的时间格式
        $time_format = get_option( 'time_format' ); //获取wp后台设置的时间格式
        $message = "您好,有一条【在线留言】信息需要您处理,详细信息如下:

        姓名/昵称:".htmlspecialchars($_POST['yourname'],ENT_QUOTES,"UTF-8")."
            
        联系邮箱:".htmlspecialchars($_POST['mail'],ENT_QUOTES,"UTF-8")."
            
        联系电话:".htmlspecialchars($_POST['phone'],ENT_QUOTES,"UTF-8")."
            
        留言内容:".htmlspecialchars($_POST['message'],ENT_QUOTES,"UTF-8")."
            
        提交时间:".date( "{$date_format} {$time_format}", current_time( 'timestamp' ) );
        $subject = "您收到一条新的【在线留言】,请及时跟进客户";

        if( $s ){
            wp_mail($to, $subject, $message, $headers);
            $msg = json_encode(
                array(
                    'state' => 200,
                    'tips' => __('Thank you for your message. It has been sent.', 'dahuzi_theme')
                )
            );
        }else{
            $msg = json_encode(
                array(
                    'state' => 201,
                    'tips' => '提交失败,未知错误,请联系站点管理员!'
                )
            );
        }

    }else{
        $msg = json_encode(
            array(
                'state' => 201,
                'tips' => __('All field is required.', 'dahuzi_theme')
            )
        );
    }

    echo $msg;
    die();
}
add_action( 'wp_ajax_dahuzi_contact_ajax', 'dahuzi_contact_ajax' );
add_action( 'wp_ajax_nopriv_dahuzi_contact_ajax' , 'dahuzi_contact_ajax' );