158 lines
4.0 KiB
PHP
158 lines
4.0 KiB
PHP
<?php
|
|
/**
|
|
* Plugin Name: AI Proxy Manager
|
|
* Description: Маршрутизация запросов к AI API (OpenAI, Anthropic, Google) через пользовательские прокси-серверы, с режимом отладки подключения.
|
|
* Version: 1.0.9
|
|
* Requires at least: 6.0
|
|
* Requires PHP: 7.4
|
|
* Author: Александр Головин
|
|
* Author URI: https://быстросайты.рф/
|
|
* License: GPL-2.0-or-later
|
|
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
|
* Text Domain: ai-proxy-manager
|
|
*
|
|
* @package AI_Proxy_Manager
|
|
*/
|
|
|
|
defined( 'ABSPATH' ) || exit;
|
|
|
|
/**
|
|
* Базовые константы плагина.
|
|
*/
|
|
define( 'AIPMSP_VERSION', '1.0.8' );
|
|
define( 'AIPMSP_PLUGIN_FILE', __FILE__ );
|
|
define( 'AIPMSP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
|
|
define( 'AIPMSP_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
|
|
define( 'AIPMSP_OPTION_KEY', 'aipmsp_settings' );
|
|
|
|
/**
|
|
* Подключение файлов классов плагина.
|
|
*/
|
|
require_once AIPMSP_PLUGIN_DIR . 'includes/class-aipmsp-crypto.php';
|
|
require_once AIPMSP_PLUGIN_DIR . 'includes/class-aipmsp-proxy.php';
|
|
require_once AIPMSP_PLUGIN_DIR . 'includes/class-aipmsp-core.php';
|
|
require_once AIPMSP_PLUGIN_DIR . 'includes/class-aipmsp-admin.php';
|
|
require_once AIPMSP_PLUGIN_DIR . 'includes/class-aipmsp-debug.php';
|
|
require_once AIPMSP_PLUGIN_DIR . 'includes/class-aipmsp-ajax.php';
|
|
|
|
/**
|
|
* Главный класс-загрузчик плагина (singleton).
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
final class AIPMSP_Plugin {
|
|
|
|
/**
|
|
* Единственный экземпляр класса.
|
|
*
|
|
* @var AIPMSP_Plugin|null
|
|
*/
|
|
private static $instance = null;
|
|
|
|
/**
|
|
* Возвращает единственный экземпляр плагина.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @return AIPMSP_Plugin
|
|
*/
|
|
public static function instance() {
|
|
if ( null === self::$instance ) {
|
|
self::$instance = new self();
|
|
}
|
|
|
|
return self::$instance;
|
|
}
|
|
|
|
/**
|
|
* Конструктор: инициализирует компоненты плагина.
|
|
*
|
|
* @since 1.0.0
|
|
*/
|
|
private function __construct() {
|
|
add_action( 'init', array( $this, 'load_textdomain' ) );
|
|
|
|
// Ядро маршрутизации прокси работает и в админке, и на фронтенде.
|
|
new AIPMSP_Core();
|
|
|
|
if ( is_admin() ) {
|
|
new AIPMSP_Admin();
|
|
new AIPMSP_Debug();
|
|
new AIPMSP_Ajax();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Загружает переводы плагина.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @return void
|
|
*/
|
|
public function load_textdomain() {
|
|
load_plugin_textdomain(
|
|
'ai-proxy-manager',
|
|
false,
|
|
dirname( plugin_basename( AIPMSP_PLUGIN_FILE ) ) . '/languages'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Возвращает настройки плагина со значениями по умолчанию.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function get_default_settings() {
|
|
return array(
|
|
'proxy_enabled' => 0,
|
|
'debug_enabled' => 0,
|
|
'proxy_type' => 'http',
|
|
'proxies' => array(),
|
|
'domains' => array(
|
|
'api.openai.com',
|
|
'api.anthropic.com',
|
|
'generativelanguage.googleapis.com',
|
|
),
|
|
'keys' => array(
|
|
'openai' => '',
|
|
'anthropic' => '',
|
|
'google' => '',
|
|
),
|
|
'key_enabled' => array(
|
|
'openai' => 1,
|
|
'anthropic' => 1,
|
|
'google' => 1,
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Хук активации: задаёт настройки по умолчанию, если их ещё нет.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @return void
|
|
*/
|
|
public static function activate() {
|
|
if ( false === get_option( AIPMSP_OPTION_KEY, false ) ) {
|
|
add_option( AIPMSP_OPTION_KEY, self::get_default_settings() );
|
|
}
|
|
}
|
|
}
|
|
|
|
register_activation_hook( __FILE__, array( 'AIPMSP_Plugin', 'activate' ) );
|
|
|
|
/**
|
|
* Запуск плагина после загрузки всех плагинов.
|
|
*
|
|
* @since 1.0.0
|
|
*
|
|
* @return void
|
|
*/
|
|
function aipmsp_bootstrap() {
|
|
AIPMSP_Plugin::instance();
|
|
}
|
|
add_action( 'plugins_loaded', 'aipmsp_bootstrap' );
|