define_constants(); $this->load_dependencies(); $this->init_hooks(); } /** * System path definition maps. */ private function define_constants() { if ( ! defined( 'AF_TRANSLATE_FILE' ) ) { define( 'AF_TRANSLATE_FILE',__FILE__ ); } if ( ! defined( 'AF_TRANSLATE_BASE' ) ) { define( 'AF_TRANSLATE_BASE', plugin_basename(AF_TRANSLATE_FILE)); } if ( ! defined( 'AF_TRANSLATE_DIR' ) ) { define( 'AF_TRANSLATE_DIR', dirname(AF_TRANSLATE_FILE)); } if ( ! defined( 'AF_TRANSLATE_PATH' ) ) { define( 'AF_TRANSLATE_PATH', plugin_dir_path( __FILE__ ) ); } if ( ! defined( 'AF_TRANSLATE_URL' ) ) { define( 'AF_TRANSLATE_URL', plugin_dir_url( __FILE__ ) ); } } /** * High-performance memory-optimized asset loading schema. */ private function load_dependencies() { // Shared global multi-dimensional localization data configurations require_once AF_TRANSLATE_PATH . 'includes/class-i18n-data.php'; require_once AF_TRANSLATE_PATH . 'includes/class-af-translate.php'; // Critical Performance Safeguard: Execute heavy analysis suites only on back-end requests if ( is_admin() ) { require_once AF_TRANSLATE_PATH . 'includes/class-bundle-analyzer.php'; require_once AF_TRANSLATE_PATH . 'includes/class-translate-scanner.php'; require_once AF_TRANSLATE_PATH . 'includes/class-project-config.php'; require_once AF_TRANSLATE_PATH . 'includes/class-project-ajax.php'; require_once AF_TRANSLATE_PATH . 'includes/class-editor-view.php'; require_once AF_TRANSLATE_PATH . 'includes/class-file-pot-generator.php'; require_once AF_TRANSLATE_PATH . 'includes/class-file-compiler.php'; require_once AF_TRANSLATE_PATH . 'includes/class-file-stream.php'; require_once AF_TRANSLATE_PATH . 'includes/class-file-ajax.php'; require_once AF_TRANSLATE_PATH . 'includes/class-editor-path-validator.php'; require_once AF_TRANSLATE_PATH . 'includes/class-editor-po-processor.php'; require_once AF_TRANSLATE_PATH . 'includes/class-editor-ajax-handler.php'; require_once AF_TRANSLATE_PATH . 'includes/class-translate-ai-engine.php'; require_once AF_TRANSLATE_PATH . 'includes/class-translate-ai-ajax.php'; require_once AF_TRANSLATE_PATH . 'includes/class-translate-ai-bridge.php'; } } /** * Standard runtime execution initialization hooks. */ private function init_hooks() { add_action( 'plugins_loaded', array( $this, 'boot_core_engine' ) ); /** * CRITICAL GLOBAL HOOK: Intercepts and redirects MO file loading metrics. * Must run globally (outside of is_admin) so frontend visitors see custom strings. */ add_filter( 'load_textdomain_mofile', array( $this, 'af_translate_load_from_uploads' ), 10, 2 ); add_filter('plugin_row_meta', [$this, 'plugin_row_meta'], 10, 2); add_filter('plugin_action_links_' . AF_TRANSLATE_BASE, [$this, 'plugin_action_links']); } public function plugin_action_links($links) { $settings_link = sprintf('%2$s', admin_url('admin.php?page=af-translate'), esc_html__('Get Started', 'af-translate')); array_unshift($links, $settings_link); $links['af-translate-ai-connecter'] = sprintf('%2$s', admin_url('admin.php?page=af-translate-ai-connecter'), esc_html__('AI Settings', 'af-translate')); return $links; } public function plugin_row_meta($plugin_meta, $plugin_file) { if (AF_TRANSLATE_BASE === $plugin_file) { $row_meta = [ 'af-translate-plugins' => sprintf('%2$s', admin_url('admin.php?page=af-translate-plugins'), esc_html__('Translate Plugins', 'af-translate')), 'af-translate-themes' => sprintf('%2$s', admin_url('admin.php?page=af-translate-themes'), esc_html__('Translate Themes', 'af-translate')), ]; $plugin_meta = array_merge($plugin_meta, $row_meta); } return $plugin_meta; } /** * Dynamic Translation Interceptor targeting the Writable Uploads Sandbox * Automatically handles text-domain isolation for both themes and plugins. */ public function af_translate_load_from_uploads( $mofile, $domain ) { // Skip core WordPress overrides if ( 'default' === $domain ) { return $mofile; } // Extract the locale from the current file string (e.g., "es_ES" out of "domain-es_ES.mo") $filename = basename( $mofile ); $locale = str_replace( array( $domain . '-', '.mo' ), '', $filename ); $upload_dir = wp_upload_dir(); $base_path = $upload_dir['basedir'] . '/af-translate/'; // 1. Check inside the custom isolated themes sandbox subdirectory $custom_theme_mofile = $base_path . 'themes/' . $domain . '-' . $locale . '.mo'; if ( file_exists( $custom_theme_mofile ) ) { return $custom_theme_mofile; } // 2. Check inside the custom isolated plugins sandbox subdirectory $custom_plugin_mofile = $base_path . 'plugins/' . $domain . '-' . $locale . '.mo'; if ( file_exists( $custom_plugin_mofile ) ) { return $custom_plugin_mofile; } // Fallback to theme or core system files if no custom upload translation exists return $mofile; } /** * Instantiates the foundational translation controller framework safely. */ public function boot_core_engine() { // 1. Boot the core foundational translation framework if ( class_exists( 'AF_Translate_Core' ) ) { new AF_Translate_Core(); } // 2. Ignite the streaming download hooks for admin-post.php if ( class_exists( 'AF_Translate_File_Streaming' ) ) { AF_Translate_File_Streaming::init_hooks(); } // 3. Editor Workbench AJAX Actions if ( class_exists( 'AF_Translate_Editor_AJAX_Handler' ) ) { add_action( 'wp_ajax_af_translate_save_pot', array( 'AF_Translate_Editor_AJAX_Handler', 'handle_save' ) ); } // 4. Extended Utilities AJAX Actions if ( class_exists( 'AF_Translate_Ajax_Extended' ) ) { add_action( 'wp_ajax_af_translate_init_locale', array( 'AF_Translate_Ajax_Extended', 'ajax_init_po_handler' ) ); add_action( 'wp_ajax_af_translate_import_po', array( 'AF_Translate_Ajax_Extended', 'ajax_import_po_handler' ) ); } /** * POLYMORPHIC ROUTER: Intercepts the shared action hook collision * and safely directs traffic to the correct engine component. */ add_action( 'wp_ajax_af_translate_sync_po', array( $this, 'route_sync_po_requests' ) ); } /** * Polymorphic AJAX Router to handle shared action hook collisions safely. * Evaluates parameters to differentiate between the editor screen and portability screen. */ public function route_sync_po_requests() { // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Operational routing controller check; verification is safely deferred to downstream workbench sync execution context handlers. if ( isset( $_POST['po_file_target'] ) && class_exists( 'AF_Translate_Editor_AJAX_Handler' ) ) { AF_Translate_Editor_AJAX_Handler::handle_sync(); exit; } // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Operational routing controller check; verification is safely deferred to downstream module dashboard sync handlers. if ( isset( $_POST['component'] ) && class_exists( 'AF_Translate_Ajax_Extended' ) ) { AF_Translate_Ajax_Extended::ajax_sync_po_handler(); exit; } wp_send_json_error( esc_html__( 'Invalid transaction routing parameter signature.', 'af-translate' ) ); } } /** * Accessor function shortcut to instantiate the architectural controller context. * * @return AF_Translate */ function af_translate_engine() { return AF_Translate::instance(); } // Ignite operational plugin setup af_translate_engine();