mirror of
https://github.com/WenPai-org/lelms-copyright.git
synced 2025-08-03 04:08:45 +08:00
244 lines
9.5 KiB
PHP
244 lines
9.5 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: LeLMS Copyright
|
|
* Plugin URI: https://wenpai.org/plugins/lelms-copyright
|
|
* Description: Adds watermark with username and prevents unauthorized screenshots
|
|
* Version: 1.1.1
|
|
* Author: LeLMS.com
|
|
* Author URI: https://lelms.com
|
|
* License: GPL v2 or later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
* Requires at least: 5.9
|
|
* Requires PHP: 7.4
|
|
* Text Domain: lelms-copyright
|
|
* Domain Path: /languages
|
|
*/
|
|
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class LELMS_Copyright {
|
|
private $options;
|
|
|
|
public function __construct() {
|
|
load_plugin_textdomain('lelms-copyright', false, dirname(plugin_basename(__FILE__)) . '/languages/');
|
|
|
|
$defaults = array(
|
|
'watermark_opacity' => 0.1,
|
|
'watermark_size' => 20,
|
|
'watermark_spacing' => 150,
|
|
'watermark_color' => '#000000',
|
|
'watermark_angle' => -45,
|
|
'enable_devtools_protection' => 'yes',
|
|
'enable_print_protection' => 'yes',
|
|
'enable_copy_protection' => 'yes'
|
|
);
|
|
$this->options = wp_parse_args(get_option('lelms_copyright_options', array()), $defaults);
|
|
|
|
add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'));
|
|
if (did_action('wp_body_open')) {
|
|
add_action('wp_body_open', array($this, 'add_watermark_container'));
|
|
} else {
|
|
add_action('wp_footer', array($this, 'add_watermark_container'));
|
|
}
|
|
add_action('admin_menu', array($this, 'add_admin_menu'));
|
|
add_action('admin_init', array($this, 'register_settings'));
|
|
}
|
|
|
|
public function add_admin_menu() {
|
|
add_options_page(
|
|
__('LeLMS Copyright Settings', 'lelms-copyright'),
|
|
__('Copyright', 'lelms-copyright'),
|
|
'manage_options',
|
|
'lelms-copyright',
|
|
array($this, 'options_page')
|
|
);
|
|
}
|
|
|
|
public function register_settings() {
|
|
register_setting('lelms_copyright', 'lelms_copyright_options', array($this, 'sanitize_options'));
|
|
|
|
add_settings_section(
|
|
'lelms_copyright_section',
|
|
__('Watermark Settings', 'lelms-copyright'),
|
|
array($this, 'section_description'),
|
|
'lelms-copyright'
|
|
);
|
|
|
|
$this->add_settings_fields();
|
|
}
|
|
|
|
public function section_description() {
|
|
echo '<p>';
|
|
esc_html_e('Customize the watermark appearance and protection settings to secure your content.', 'lelms-copyright');
|
|
echo '</p>';
|
|
}
|
|
|
|
public function sanitize_options($input) {
|
|
$sanitized = array();
|
|
$defaults = array(
|
|
'watermark_opacity' => 0.1,
|
|
'watermark_size' => 20,
|
|
'watermark_spacing' => 150,
|
|
'watermark_color' => '#000000',
|
|
'watermark_angle' => -45,
|
|
'enable_devtools_protection' => 'yes',
|
|
'enable_print_protection' => 'yes',
|
|
'enable_copy_protection' => 'yes'
|
|
);
|
|
|
|
$sanitized['watermark_opacity'] = min(max(floatval($input['watermark_opacity']), 0), 1);
|
|
$sanitized['watermark_size'] = absint($input['watermark_size']);
|
|
$sanitized['watermark_spacing'] = absint($input['watermark_spacing']);
|
|
$sanitized['watermark_color'] = sanitize_hex_color($input['watermark_color']);
|
|
$sanitized['watermark_angle'] = intval($input['watermark_angle']);
|
|
$sanitized['enable_devtools_protection'] = isset($input['enable_devtools_protection']) ? 'yes' : 'no';
|
|
$sanitized['enable_print_protection'] = isset($input['enable_print_protection']) ? 'yes' : 'no';
|
|
$sanitized['enable_copy_protection'] = isset($input['enable_copy_protection']) ? 'yes' : 'no';
|
|
|
|
return wp_parse_args($sanitized, $defaults);
|
|
}
|
|
|
|
public function add_watermark_container() {
|
|
if (is_user_logged_in()) {
|
|
echo '<div id="lelms-watermark"></div>';
|
|
}
|
|
}
|
|
|
|
private function add_settings_fields() {
|
|
$fields = array(
|
|
'watermark_opacity' => array(
|
|
'title' => __('Watermark Opacity', 'lelms-copyright'),
|
|
'type' => 'number',
|
|
'attrs' => 'step="0.1" min="0" max="1"',
|
|
'description' => __('Set the transparency of the watermark (0 = fully transparent, 1 = fully opaque).', 'lelms-copyright')
|
|
),
|
|
'watermark_size' => array(
|
|
'title' => __('Watermark Size (px)', 'lelms-copyright'),
|
|
'type' => 'number',
|
|
'description' => __('Define the font size of the watermark text in pixels.', 'lelms-copyright')
|
|
),
|
|
'watermark_spacing' => array(
|
|
'title' => __('Watermark Spacing (px)', 'lelms-copyright'),
|
|
'type' => 'number',
|
|
'description' => __('Set the distance between each watermark in pixels.', 'lelms-copyright')
|
|
),
|
|
'watermark_color' => array(
|
|
'title' => __('Watermark Color', 'lelms-copyright'),
|
|
'type' => 'color',
|
|
'description' => __('Choose the color of the watermark text.', 'lelms-copyright')
|
|
),
|
|
'watermark_angle' => array(
|
|
'title' => __('Watermark Angle', 'lelms-copyright'),
|
|
'type' => 'number',
|
|
'description' => __('Set the rotation angle of the watermark text in degrees (e.g., -45 for diagonal).', 'lelms-copyright')
|
|
),
|
|
'enable_devtools_protection' => array(
|
|
'title' => __('Enable DevTools Protection', 'lelms-copyright'),
|
|
'type' => 'checkbox',
|
|
'description' => __('Prevent users from opening browser developer tools (e.g., F12 or Ctrl+Shift+I).', 'lelms-copyright')
|
|
),
|
|
'enable_print_protection' => array(
|
|
'title' => __('Enable Print Protection', 'lelms-copyright'),
|
|
'type' => 'checkbox',
|
|
'description' => __('Block printing of the page to protect your content.', 'lelms-copyright')
|
|
),
|
|
'enable_copy_protection' => array(
|
|
'title' => __('Enable Copy Protection', 'lelms-copyright'),
|
|
'type' => 'checkbox',
|
|
'description' => __('Disable copying of text and right-click menus outside of form fields.', 'lelms-copyright')
|
|
)
|
|
);
|
|
|
|
foreach ($fields as $key => $field) {
|
|
add_settings_field(
|
|
$key,
|
|
$field['title'],
|
|
array($this, 'render_field'),
|
|
'lelms-copyright',
|
|
'lelms_copyright_section',
|
|
array(
|
|
'key' => $key,
|
|
'type' => $field['type'],
|
|
'attrs' => isset($field['attrs']) ? $field['attrs'] : '',
|
|
'description' => $field['description'] // Pass the description to the callback
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
public function render_field($args) {
|
|
$key = $args['key'];
|
|
$type = $args['type'];
|
|
$value = isset($this->options[$key]) ? $this->options[$key] : '';
|
|
$attrs = isset($args['attrs']) ? $args['attrs'] : '';
|
|
$description = isset($args['description']) ? $args['description'] : '';
|
|
|
|
if ($type === 'checkbox') {
|
|
printf(
|
|
'<input type="checkbox" name="lelms_copyright_options[%s]" %s value="yes" %s>',
|
|
esc_attr($key),
|
|
$attrs,
|
|
checked($value, 'yes', false)
|
|
);
|
|
} else {
|
|
printf(
|
|
'<input type="%s" name="lelms_copyright_options[%s]" value="%s" %s>',
|
|
esc_attr($type),
|
|
esc_attr($key),
|
|
esc_attr($value),
|
|
$attrs
|
|
);
|
|
}
|
|
|
|
// Output the description below the field
|
|
if ($description) {
|
|
echo '<p class="description">';
|
|
echo esc_html($description); // Use esc_html to safely output the translated description
|
|
echo '</p>';
|
|
}
|
|
}
|
|
|
|
public function options_page() {
|
|
?>
|
|
<div class="wrap">
|
|
<h1><?php esc_html_e('LeLMS Copyright Settings', 'lelms-copyright'); ?></h1>
|
|
<form method="post" action="options.php">
|
|
<?php
|
|
settings_fields('lelms_copyright');
|
|
do_settings_sections('lelms-copyright');
|
|
submit_button(__('Save Changes', 'lelms-copyright'));
|
|
?>
|
|
</form>
|
|
</div>
|
|
<?php
|
|
}
|
|
|
|
public function enqueue_scripts() {
|
|
if (is_user_logged_in()) {
|
|
wp_enqueue_style('lelms-copyright', plugins_url('css/style.css', __FILE__), array(), '1.1.1');
|
|
wp_enqueue_script('lelms-copyright', plugins_url('js/watermark.js', __FILE__), array('jquery'), '1.1.1', true);
|
|
|
|
$current_user = wp_get_current_user();
|
|
wp_localize_script('lelms-copyright', 'lelmsData', array(
|
|
'username' => '@' . $current_user->user_login,
|
|
'options' => $this->options,
|
|
'warningMessage' => __('This action is disabled on this site.', 'lelms-copyright')
|
|
));
|
|
}
|
|
}
|
|
}
|
|
|
|
new LELMS_Copyright();
|
|
|
|
// Integrate UpdatePulse Server for updates using PUC v5.3
|
|
require_once plugin_dir_path(__FILE__) . 'lib/plugin-update-checker/plugin-update-checker.php';
|
|
use YahnisElsts\PluginUpdateChecker\v5p3\PucFactory;
|
|
|
|
$lelmsUpdateChecker = PucFactory::buildUpdateChecker(
|
|
'https://updates.weixiaoduo.com/updatepulse.json',
|
|
__FILE__,
|
|
'lelms-copyright'
|
|
);
|