HEX
Server: nginx/1.22.1
System: Linux VM-16-9-centos 3.10.0-1160.99.1.el7.x86_64 #1 SMP Wed Sep 13 14:19:20 UTC 2023 x86_64
User: www (1001)
PHP: 7.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.liangyukeji.com/wp-content/plugins/wpcopyrights/index.php
<?php
/**
Plugin Name: WPCopyRights网站防复制插件
Plugin URI: https://www.lezaiyun.com/811.html
Description: 功能强大的WordPress网站防复制插件,支持多种防护方式。公众号:老蒋朋友圈
Version: 6.1
Author: 老蒋和他的小伙伴
Author URI: https://www.laojiang.me
*/

if (!defined('ABSPATH')) {
    exit;
}

class WPCopyRights {
    private static $instance = null;
    private $options;
    private $version = '6.1';
    
    public static function getInstance() {
        if (null === self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }
    
    private function __construct() {
        $this->defineConstants();
        $this->initHooks();
    }
    
    private function defineConstants() {
        define('WP_COPY_RIGHTS_VERSION', $this->version);
        define('WP_COPY_RIGHTS_PATH', plugin_dir_path(__FILE__));
        define('WP_COPY_RIGHTS_URL', plugin_dir_url(__FILE__));
        define('WP_COPY_RIGHTS_BASE_FOLDER', plugin_basename(dirname(__FILE__)));
    }
    
    private function initHooks() {
        // 初始化钩子
        register_activation_hook(__FILE__, array($this, 'activate'));
        add_action('wp_enqueue_scripts', array($this, 'enqueueAssets'));
        add_action('admin_menu', array($this, 'addSettingPage'));
        add_filter('plugin_action_links', array($this, 'addPluginLinks'), 10, 2);
    }
    
    public function activate() {
        $default_options = array(
            'version' => WP_COPY_RIGHTS_VERSION,
            'switch'  => false,
            'options' => array(
                'disable_right_click'  => false,
                'disable_select_text'  => false,
                'disable_drag_image'   => false,
                'disable_f12'          => false,
                'disable_print'        => false,
                'disable_view_source'  => false,
                'disable_save_page'    => false,
                'disable_select_all'   => false,
                'disable_copy_content' => false,
                'disable_cut_content'  => false,
                'enable_adminer'       => false,
                'enable_loginer'       => false,
                'enable_endcopyrights' => false,
                'enable_watermark'     => false,
                'custom_message'       => '内容受保护,无法复制',
                'watermark_text'       => '',
                'exclude_pages'        => '',
                'exclude_posts'        => '',
            ),
        );
        
        if (!get_option('wp_copy_rights_options')) {
            add_option('wp_copy_rights_options', $default_options);
        }
    }
    
    public function enqueueAssets() {
        if ($this->shouldProtectContent()) {
            wp_enqueue_style(
                'wp-copy-rights-style',
                WP_COPY_RIGHTS_URL . 'assets/css/protect.css',
                array(),
                WP_COPY_RIGHTS_VERSION
            );
            
            wp_enqueue_script(
                'wp-copy-rights-script',
                WP_COPY_RIGHTS_URL . 'assets/js/protect.js',
                array('jquery'),
                WP_COPY_RIGHTS_VERSION,
                true
            );
            
            $options = $this->getOptions();
            wp_localize_script('wp-copy-rights-script', 'wpCopyRightsSettings', array(
                'options' => array_merge(
                    array('switch' => $options['switch']),
                    $options['options'],
                    array(
                        'watermark_enabled' => !empty($options['options']['watermark_text']) && !empty($options['options']['enable_watermark'])
                    )
                ),
                'messages' => array(
                    'copyWarning' => esc_html($options['options']['custom_message']),
                ),
                'ajaxUrl' => admin_url('admin-ajax.php'),
                'nonce' => wp_create_nonce('wp_copy_rights_nonce')
            ));
        }
    }
    
    private function shouldProtectContent() {
        $options = $this->getOptions();
        
        if (!$options['switch']) {
            return false;
        }
        
        // 检查管理员例外
        if ($options['options']['enable_adminer'] && current_user_can('administrator')) {
            return false;
        }
        
        // 检查登录用户例外
        if ($options['options']['enable_loginer'] && is_user_logged_in()) {
            return false;
        }
        
        // 检查特定页面例外
        if ($this->isExcludedPage()) {
            return false;
        }
        
        return true;
    }
    
    private function isExcludedPage() {
        $options = $this->getOptions();
        
        // 检查排除的页面
        if (!empty($options['options']['exclude_pages'])) {
            $excluded_pages = array_map('trim', explode(',', $options['options']['exclude_pages']));
            if (is_page() && in_array(get_the_ID(), $excluded_pages)) {
                return true;
            }
        }
        
        // 检查排除的文章
        if (!empty($options['options']['exclude_posts'])) {
            $excluded_posts = array_map('trim', explode(',', $options['options']['exclude_posts']));
            if (is_single() && in_array(get_the_ID(), $excluded_posts)) {
                return true;
            }
        }
        
        return false;
    }
    
    public function getOptions() {
        if (null === $this->options) {
            $this->options = get_option('wp_copy_rights_options');
        }
        return $this->options;
    }
    
    public function addSettingPage() {
        add_submenu_page(
            'tools.php',
            'WPCopyRights设置',
            'WPCopyRights设置',
            'manage_options',
            'wp-copy-rights',
            array($this, 'renderSettingPage')
        );
    }
    
    public function renderSettingPage() {
        if (!current_user_can('manage_options')) {
            wp_die(__('您没有足够的权限访问此页面。'));
        }
        
        require_once WP_COPY_RIGHTS_PATH . 'templates/admin-settings.php';
    }
    
    public function addPluginLinks($links, $file) {
        if (plugin_basename(__FILE__) === $file) {
            $settings_link = '<a href="' . admin_url('tools.php?page=wp-copy-rights') . '">设置</a>';
            array_unshift($links, $settings_link);
        }
        return $links;
    }
}

// 初始化插件
function wp_copy_rights_init() {
    return WPCopyRights::getInstance();
}

wp_copy_rights_init();