*/ class Aec { /** * The single instance of the class. * * @var Aec * @since 1.0.0 */ protected static $_instance = null; /** * The loader that's responsible for maintaining and registering all hooks that power * the plugin. * * @since 1.0.0 * @access protected * @var Aec_Loader $loader Maintains and registers all hooks for the plugin. */ protected $loader; /** * The unique identifier of this plugin. * * @since 1.0.0 * @access protected * @var string $plugin_name The string used to uniquely identify this plugin. */ protected $plugin_name; /** * The current version of the plugin. * * @since 1.0.0 * @access protected * @var string $version The current version of the plugin. */ protected $version; /** * The current settings of the plugin. * * @since 1.0.0 * @access protected * @var array $settings The current settings of the plugin. */ var $settings; /** * Main AEC Instance. * * Ensures only one instance of AEC is loaded or can be loaded. * * @return Aec - Main instance. * @see AEC() * @since 1.0.0 * @static */ public static function instance() { if( is_null( self::$_instance ) ) { self::$_instance = new self(); self::$_instance->run(); } return self::$_instance; } /** * Define the core functionality of the plugin. * * Set the plugin name and the plugin version that can be used throughout the plugin. * Load the dependencies, define the locale, and set the hooks for the admin area and * the public-facing side of the site. * * @since 1.0.0 */ public function __construct() { $this->plugin_name = 'AEC Kiosque'; $this->version = defined( 'AEC_VERSION' ) ? AEC_VERSION : '1.2.2'; $this->setup_constants(); $this->setup_settings(); $this->load_dependencies(); $this->set_locale(); $this->define_admin_hooks(); $this->define_public_hooks(); } /** * Load the required dependencies for this plugin. * * Include the following files that make up the plugin: * * - Aec_Loader. Orchestrates the hooks of the plugin. * - Aec_i18n. Defines internationalization functionality. * - Aec_Admin. Defines all hooks for the admin area. * - Aec_Public. Defines all hooks for the public side of the site. * - Aec_Shortcodes. Defines the plugin shortcodes. * * Create an instance of the loader which will be used to register the hooks * with WordPress. * * @return void * @since 1.0.0 * @access private */ private function load_dependencies() { /** * The class responsible for orchestrating the actions and filters of the * core plugin. */ require_once AEC_PATH . 'includes/class-aec-loader.php'; /** * The class responsible for defining internationalization functionality * of the plugin. */ require_once AEC_PATH . 'includes/class-aec-i18n.php'; /** * The class responsible for defining all actions that occur in the admin area. */ require_once AEC_PATH . 'admin/class-aec-admin.php'; /** * The class responsible for defining all actions that occur in the public-facing * side of the site. */ require_once AEC_PATH . 'public/class-aec-public.php'; /** * The class responsible for defining all shortcodes. */ require_once AEC_PATH . 'public/class-aec-shortcodes.php'; $this->loader = new Aec_Loader(); } /** * Setup constants * * @return void * @since 1.0.0 * @access private */ private function setup_constants() { if( !defined( 'AEC' ) ) { define( 'AEC', true ); } if( !defined( 'AEC_VERSION' ) ) { define( 'AEC_VERSION', $this->version ); } if( !defined( 'AEC_MAJOR_VERSION' ) ) { define( 'AEC_MAJOR_VERSION', 1 ); } if( !defined( 'AEC_PATH' ) ) { define( 'AEC_PATH', plugin_dir_path( __DIR__ ) ); } if( !defined( 'AEC_BASENAME' ) ) { define( 'AEC_BASENAME', plugin_basename( __DIR__ ) ); } if( !defined( 'AEC_URL' ) ) { define( 'AEC_URL', plugins_url( '/aec-kiosque', AEC_PATH ) ); } if( !defined( 'AEC_ENVIRONMENT_DEV' ) ) { define( 'AEC_ENVIRONMENT_DEV', 'development' ); } if( !defined( 'AEC_LOCAL_APP_URL' ) ) { define( 'AEC_LOCAL_APP_URL', 'http://local.extranet-aec.com' ); } if( !defined( 'AEC_LOCAL_EXTRANET_URL' ) ) { define( 'AEC_LOCAL_EXTRANET_URL', 'http://local.extranet-aec.com/extranet' ); } if( !defined( 'AEC_LOAD_LOCAL_FILES' ) ) { define( 'AEC_LOAD_LOCAL_FILES', false ); } } /** * Setup settings of the plugin. * * @return void * @since 1.0.0 * @access private */ private function setup_settings() { $this->settings = array( 'name' => $this->plugin_name, 'version' => $this->version, 'client_instance' => $this->get_client_instance(), 'client_version' => $this->get_client_version(), 'establishment_type' => get_option( 'aec_etablishment_type' ), 'extranet_url' => $this->get_client_extranet_url(), 'app_url' => $this->get_client_instance_url(), 'wordpress_url' => $this->get_wordpress_url(), ); } /** * Define the locale for this plugin for internationalization. * * Uses the Aec_i18n class in order to set the domain and to register the hook * with WordPress. * * @since 1.0.0 * @access private */ private function set_locale() { $plugin_i18n = new Aec_i18n(); $this->loader->add_action( 'init', $plugin_i18n, 'load_plugin_textdomain' ); } /** * Register all of the hooks related to the admin area functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_admin_hooks() { $plugin_admin = new Aec_Admin( $this->get_plugin_name(), $this->get_version() ); $plugin_settings = new Aec_Admin_Settings( $this->get_plugin_name(), $this->get_version() ); $this->loader->add_action( 'current_screen', $plugin_settings, 'setup_guard' ); $this->loader->add_action( 'admin_head', $this, 'add_head', 5 ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); $this->loader->add_action( 'wp_before_admin_bar_render', $plugin_settings, 'add_custom_logo_on_top_menu' ); $this->loader->add_action( 'admin_menu', $plugin_settings, 'setup_plugin_options_menu' ); $this->loader->add_action( 'admin_init', $plugin_settings, 'setup_plugin_admin_settings' ); $this->loader->add_action( 'admin_init', $plugin_admin, 'add_styles_in_editor' ); } /** * Register all of the hooks related to the public-facing functionality * of the plugin. * * @since 1.0.0 * @access private */ private function define_public_hooks() { $plugin_public = new Aec_Public( $this->get_plugin_name(), $this->get_version() ); $plugin_shortcodes = new Aec_Shortcodes( $this->get_client_instance() ); $this->loader->add_action( 'wp_head', $this, 'add_head', 5 ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); $this->loader->add_shortcode( 'aec_classes', $plugin_shortcodes, 'webapp_classes' ); $this->loader->add_shortcode( 'aec_class_detail', $plugin_shortcodes, 'webapp_class_detail' ); $this->loader->add_shortcode( 'aec_events_list', $plugin_shortcodes, 'webapp_events_list' ); $this->loader->add_shortcode( 'aec_event_detail', $plugin_shortcodes, 'webapp_event_detail' ); $this->loader->add_shortcode( 'aec_next_events', $plugin_shortcodes, 'webapp_next_events' ); $this->loader->add_shortcode( 'aec_events_grid', $plugin_shortcodes, 'webapp_events_list_grid' ); $this->loader->add_shortcode( 'aec_events_wide', $plugin_shortcodes, 'webapp_events_list_wide' ); $this->loader->add_shortcode( 'aec_contact_map', $plugin_shortcodes, 'webapp_contact_map' ); $this->loader->add_shortcode( 'aec_google_map', $plugin_shortcodes, 'webapp_google_map' ); $this->loader->add_shortcode( 'aec_private_tuition', $plugin_shortcodes, 'webapp_private_tuition' ); $this->loader->add_shortcode( 'aec_classe_selection', $plugin_shortcodes, 'webapp_class_selection' ); $this->loader->add_shortcode( 'aec_student_login', $plugin_shortcodes, 'webapp_student_login' ); $this->loader->add_shortcode( 'aec_student_register', $plugin_shortcodes, 'webapp_student_register' ); $this->loader->add_shortcode( 'aec_student_account', $plugin_shortcodes, 'webapp_student_account' ); $this->loader->add_shortcode( 'aec_student_account_dashboard', $plugin_shortcodes, 'webapp_student_account_dashboard' ); $this->loader->add_shortcode( 'aec_student_controls', $plugin_shortcodes, 'webapp_student_controls' ); $this->loader->add_shortcode( 'aec_student_password_recover', $plugin_shortcodes, 'webapp_student_password_recover' ); $this->loader->add_shortcode( 'aec_student_password_reset', $plugin_shortcodes, 'webapp_student_password_reset' ); $this->loader->add_shortcode( 'aec_student_password_update', $plugin_shortcodes, 'webapp_student_password_update' ); $this->loader->add_shortcode( 'aec_products_view', $plugin_shortcodes, 'webapp_products_list' ); $this->loader->add_shortcode( 'aec_donation_form', $plugin_shortcodes, 'webapp_donation_form' ); $this->loader->add_shortcode( 'aec_classes_list_with_filters', $plugin_shortcodes, 'webapp_classes_list_with_filters' ); $this->loader->add_shortcode( 'aec_classes_catalog', $plugin_shortcodes, 'webapp_classes_catalog' ); $this->loader->add_shortcode( 'aec_classes_search_box', $plugin_shortcodes, 'webapp_classes_search_box' ); $this->loader->add_shortcode( 'aec_shopping_cart', $plugin_shortcodes, 'webapp_shopping_cart' ); $this->loader->add_shortcode( 'aec_examination_list', $plugin_shortcodes, 'webapp_examination_list' ); } /** * Run the loader to execute all of the hooks with WordPress. * * @since 1.0.0 */ public function run() { $this->loader->run(); } /** * Returns true if a setting exists for this name. * * @param string $name The setting name. * @return boolean * @since 1.0.0 * */ public function has_setting( $name ) { return isset( $this->settings[$name] ); } /** * Returns a setting or null if doesn't exist. * * @param string $name The setting name. * @return mixed * @since 1.0.0 * */ public function get_setting( $name ) { return isset( $this->settings[$name] ) ? $this->settings[$name] : null; } /** * The name of the plugin used to uniquely identify it within the context of * WordPress and to define internationalization functionality. * * @return string The name of the plugin. * @since 1.0.0 */ public function get_plugin_name() { return $this->plugin_name; } /** * The reference to the class that orchestrates the hooks with the plugin. * * @return Aec_Loader Orchestrates the hooks of the plugin. * @since 1.0.0 */ public function get_loader() { return $this->loader; } /** * Retrieve the version number of the plugin. * * @return string The version number of the plugin. * @since 1.0.0 */ public function get_version() { return $this->version; } /** * Retrieve the current locale. * * @return string The current locale. * @since 1.0.0 */ public function get_locale() { if ( function_exists( 'pll_current_language' ) ) { $current_lang = pll_current_language( 'locale' ); } else if ( has_filter( 'wpml_permalink' ) ) { $current_lang = ICL_LANGUAGE_CODE; } else { $current_lang = get_locale(); } if( strpos( $current_lang, 'en_' ) !== false ) { return 'en_US'; } switch( $current_lang ) { case 'th': $current_lang .= '_TH'; break; case 'vi': $current_lang .= '_VN'; break; case 'fr': $current_lang .= '_FR'; break; case 'en': $current_lang .= '_US'; break; case 'ar': $current_lang .= '_SA'; break; case 'kh': case 'kh_KH': $current_lang = 'km_KH'; } return $current_lang; } /** * Retrieve the client instance name. * * @return string The client instance name. * @since 1.0.0 */ public function get_client_instance() { return trim( get_option( 'aec_instance_name' ) ); } /** * Retrieve the client extranet instance name. * * @return string The client instance name. * @since 1.2.1 */ public function get_client_extranet_instance() { return trim( get_option( 'aec_extranet_instance_name' ) ); } /** * Retrieve the client verion number. * * @return string The client instance version. * @since 1.0.6 */ public function get_client_version() { $client_instance = $this->get_client_instance(); if( !$client_instance || $client_instance === 'local' ) return false; $gui = wp_remote_get( 'https://' . $client_instance . '.aec-app.com/arc-en-ciel/gui/build.txt' ); if( !$gui || $gui instanceof WP_Error) return false; return explode( ':', $gui['body'] )[2]; } /** * Retrieve the client instance name. * * @return string The client instance name. * @since 1.0.0 */ public function get_client_extranet_url() { $extranet_instance = $this->get_client_extranet_instance(); $client_instance = strlen($extranet_instance) ? $extranet_instance : $this->get_client_instance(); $client_domain = get_option( 'web_instance_domain' ); $client_domain = $client_domain ? $client_domain : "extranet-aec.com"; return $client_instance === 'local' ? AEC_LOCAL_EXTRANET_URL : "https://{$client_instance}.{$client_domain}"; } /** * Retrieve the client instance url. * * @return string The client instance url. * @since 1.0.0 */ public function get_client_instance_url() { $client_instance = $this->get_client_instance(); return $client_instance === 'local' ? AEC_LOCAL_APP_URL : "https://{$client_instance}.aec-app.com"; } /** * Retrieve the wordpress url. * * @return string The wordpress url. * @since 1.0.0 */ public function get_wordpress_url() { return AEC_LOAD_LOCAL_FILES ? '/wordpress' : ''; } /** * Translate string. * * @param string $string The string to translate. * @return string Translate string. * @since 1.0.3 */ public function t( $string ) { return __( $string, 'aec' ); } /** * Adds scripts and styles into site header * * @since 1.0.0 */ public function add_head() { echo "\n"; wp_register_style( 'nodepcss-handle', false ); wp_enqueue_style( 'nodepcss-handle' ); wp_add_inline_style('nodepcss-handle', $this->load_fonts()); wp_enqueue_style('aec-custom-css', AEC()->get_setting( 'app_url' ) . '/arc-en-ciel/dist/extranet_custom_css.php'); wp_enqueue_style('aec-font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css'); wp_enqueue_style('aec-google-font', 'https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap'); wp_print_inline_script_tag('var root_directory = "' . esc_js(AEC()->get_setting( 'extranet_url' )) . '/";'); wp_print_inline_script_tag('var aecWordpressURL = "' . esc_js(AEC()->get_setting( 'wordpress_url' )) . '";'); wp_print_inline_script_tag('var aecExtranetURL = "' . esc_js(AEC()->get_setting( 'extranet_url' )) . '/";'); wp_print_inline_script_tag('var aec_app_url = "' . esc_js(AEC()->get_setting( 'app_url' )) . '";'); wp_print_inline_script_tag('var aecExtranetWebAppsAPIKey = "' . esc_js(get_option( 'aec_extranet_api_token' )) . '";'); wp_print_inline_script_tag('var templateInUse = "' . esc_js(get_option( 'aec_template_in_use' )) . '";'); wp_print_inline_script_tag('var currentLanguage = "' . esc_js($this->get_locale()) . '";'); wp_print_inline_script_tag('var clientInstance = "' . esc_js($this->get_client_instance()) . '";'); wp_print_inline_script_tag('var aecAppWPURL = "' . esc_js(AEC()->get_setting( 'app_url' )) . '/arc-en-ciel/api' . '/";'); wp_print_inline_script_tag($this->set_session_language()); wp_enqueue_style( 'webapp-' . get_option( 'aec_etablishment_type' ), AEC()->get_setting( 'extranet_url' ) . '/css/webapp-' . AEC()->get_setting( 'establishment_type' ) . '.css', array(), null ); if( is_rtl() ) { wp_enqueue_style( 'webapp-' . get_option( 'aec_etablishment_type' ), AEC()->get_setting( 'extranet_url' ) . '/css/rtl/aec.css', array(), null ); } wp_enqueue_style( 'jqueryui', AEC()->get_setting( 'extranet_url' ) . '/css/jqueryui.css', array(), null ); } /** * Set session language * * This key is used both in Extranet and Wordpress for setting the webapp language * * @since 1.1.3 */ public function set_session_language() { $lang_to_set = $this->get_locale(); if( $lang_to_set ) return 'window.sessionStorage.setItem("langToSetFromWP", "' . esc_js($lang_to_set) . '");'; } /** * Adds scripts and styles into site header * * @since 1.0.2 */ public function load_fonts() { if( is_admin() ) { return ' @font-face { font-family: FoundersGrotesk; src: url(' . AEC_URL . '/admin/fonts/FoundersGroteskX-CondensedWeb-Semibold.eot' . ') format("embedded-opentype"), url(' . AEC_URL . '/admin/fonts/FoundersGroteskX-CondensedWeb-Semibold.woff' . ') format("woff"), url(' . AEC_URL . '/admin/fonts/FoundersGroteskX-CondensedWeb-Semibold.woff2' . ') format("woff2"); font-weight: 500; }'; } } }