/** * Render the javascript for the appropriate page * */ public function render_js() { header('HTTP/1.1 200 OK'); header('Content-Type: application/javascript; charset=utf-8', true, 200); // Aggressive caching to save future requests from the same client. $etag = '"' . md5(__FILE__ . $_GET[self::LOAD_JS_PARAMETER]) . '"'; header('ETag: ' . $etag); $max_age = 31536000; // One Year header('Expires: ' . gmdate('D, d M Y H:i:s', Ai1ec_Time_Utility::current_time() + $max_age) . ' GMT'); header('Cache-Control: public, max-age=' . $max_age); if (empty($_SERVER['HTTP_IF_NONE_MATCH']) || $etag !== stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) { // compress data if possible if (Ai1ec_Http_Utility::client_use_gzip()) { ob_start('ob_gzhandler'); header('Content-Encoding: gzip'); } else { ob_start(); } $js_path = AI1EC_ADMIN_THEME_JS_PATH . DIRECTORY_SEPARATOR; $common_js = ''; $page_to_load = $_GET[self::LOAD_JS_PARAMETER]; if ($_GET[self::IS_BACKEND_PARAMETER] === self::TRUE_PARAM) { $common_js = file_get_contents($js_path . 'pages/common_backend.js'); } else { if ($page_to_load === self::EVENT_PAGE_JS || $page_to_load === self::CALENDAR_PAGE_JS || $page_to_load === self::LOAD_ONLY_FRONTEND_SCRIPTS) { if ($page_to_load === self::LOAD_ONLY_FRONTEND_SCRIPTS && true === self::$frontend_scripts_loaded) { return; } if (false === self::$frontend_scripts_loaded) { $common_js = file_get_contents($js_path . 'pages/common_frontend.js'); self::$frontend_scripts_loaded = true; } } } // create the config object for require js $require_config = $this->create_require_js_config_object(); // load require $require = file_get_contents($js_path . 'require.js'); // get jquery $jquery = $this->get_jquery_version_based_on_browser($_SERVER['HTTP_USER_AGENT']); // load the script for the page $page_js = ''; if ($page_to_load !== self::LOAD_ONLY_BACKEND_SCRIPTS && $page_to_load !== self::LOAD_ONLY_FRONTEND_SCRIPTS) { $page_js = file_get_contents($js_path . 'pages/' . $page_to_load); } $translation = $this->get_frontend_translation_data(); $permalink = get_permalink($this->settings->calendar_page_id); $translation['calendar_url'] = $permalink; $tranlsation_module = $this->create_require_js_module(self::FRONTEND_CONFIG_MODULE, $translation); $config = $this->create_require_js_module('ai1ec_config', $this->get_translation_data()); echo $require . $require_config . $tranlsation_module . $config . $jquery . $page_js . $common_js; ob_end_flush(); } else { // Not modified! status_header(304); } // We're done! ai1ec_stop(0); }
// = Initialize and setup CONTROLLERS = // ==================================== global $ai1ec_app_controller, $ai1ec_settings_controller, $ai1ec_events_controller, $ai1ec_calendar_controller, $ai1ec_importer_controller, $ai1ec_exporter_controller, $ai1ec_platform_controller, $ai1ec_duplicate_controller, $ai1ec_oauth_controller, $ai1ec_logging_controller; $ai1ec_settings_controller = Ai1ec_Settings_Controller::get_instance(); $ai1ec_events_controller = Ai1ec_Events_Controller::get_instance(); $ai1ec_calendar_controller = Ai1ec_Calendar_Controller::get_instance(); $ai1ec_importer_controller = Ai1ec_Importer_Controller::get_instance(); $ai1ec_exporter_controller = Ai1ec_Exporter_Controller::get_instance(); $ai1ec_platform_controller = Ai1ec_Platform_Controller::get_instance(); $ai1ec_duplicate_controller = Ai1ec_Duplicate_Controller::get_instance(); $ai1ec_oauth_controller = Ai1ec_Oauth_Controller::get_instance(); $ai1ec_logging_controller = Ai1ec_Logging_Controller::get_instance(); // Initialize other global classes global $ai1ec_requirejs_controller, $ai1ec_rss_feed, $ai1ec_tax_meta_class; // Create the instance of the class that handles javascript loading $ai1ec_requirejs_controller = new Ai1ec_Requirejs_Controller(); // Inject settings $ai1ec_requirejs_controller->set_settings($ai1ec_settings); // Inject calendar controller $ai1ec_requirejs_controller->set_events_helper($ai1ec_events_helper); // Se the themes controller $ai1ec_requirejs_controller->set_ai1ec_themes_controller($ai1ec_themes_controller); // ================================== // = Add the hook to render the js = // ================================== if (isset($_GET[Ai1ec_Requirejs_Controller::WEB_WIDGET_GET_PARAMETER])) { add_action('template_redirect', array($ai1ec_requirejs_controller, 'render_web_widget'), 20); } if (isset($_GET[Ai1ec_Requirejs_Controller::LOAD_JS_PARAMETER])) { add_action('wp_loaded', array($ai1ec_requirejs_controller, 'render_js'), 20); }