PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.0.54
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.0.54
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / class-assetsmanager.php

class-assetsmanager.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.0.54, at public/class-assetsmanager.php

168 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin;
4
5 use Leadin\data\Filters;
6 use Leadin\admin\AdminConstants;
7 use Leadin\data\Portal_Options;
8
9 /**
10 * Class responsible of managing all the plugin assets.
11 */
12 class AssetsManager {
13 const ADMIN_CSS = 'leadin-css';
14 const BRIDGE_CSS = 'leadin-bridge-css';
15 const ADMIN_JS = 'leadin-js';
16
17 const FEEDBACK_CSS = 'leadin-feedback-css';
18 const FEEDBACK_JS = 'leadin-feedback';
19 const TRACKING_CODE = 'leadin-script-loader-js';
20 const GUTENBERG = 'leadin-gutenberg';
21 const MEETINGS_GUTENBERG = 'leadin-meetings-gutenberg';
22 const FORMS_SCRIPT = 'leadin-forms-v2';
23 const MEETINGS_SCRIPT = 'leadin-meeting';
24 const LEADIN_CONFIG = 'leadinConfig';
25 const LEADIN_I18N = 'leadinI18n';
26 const REVIEW_BANNER = 'leadin-review-banner';
27 const ELEMENTOR = 'leadin-elementor';
28 const APP_ENTRY_CSS = 'leadin-app-css';
29 const APP_EMBEDDER = 'leadin-app-embedder';
30
31 /**
32 * Register and localize all assets.
33 */
34 public static function register_assets() {
35 wp_register_style( self::ADMIN_CSS, LEADIN_ASSETS_PATH . '/style/leadin.css', array(), LEADIN_PLUGIN_VERSION );
36 wp_register_script( self::ADMIN_JS, LEADIN_JS_BASE_PATH . '/leadin.js', array( 'jquery', 'wp-element' ), LEADIN_PLUGIN_VERSION, true );
37
38 wp_localize_script( self::ADMIN_JS, self::LEADIN_CONFIG, AdminConstants::get_leadin_config() );
39 wp_register_script( self::FEEDBACK_JS, LEADIN_JS_BASE_PATH . '/feedback.js', array( 'jquery', 'thickbox' ), LEADIN_PLUGIN_VERSION, true );
40 wp_localize_script( self::FEEDBACK_JS, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
41 wp_register_style( self::FEEDBACK_CSS, LEADIN_ASSETS_PATH . '/style/leadin-feedback.css', array(), LEADIN_PLUGIN_VERSION );
42 wp_register_style( self::BRIDGE_CSS, LEADIN_ASSETS_PATH . '/style/leadin-bridge.css?', array(), LEADIN_PLUGIN_VERSION );
43 wp_register_style( self::APP_ENTRY_CSS, LEADIN_JS_BASE_PATH . '/leadin.css', array(), LEADIN_PLUGIN_VERSION );
44 }
45
46 /**
47 * Enqueue the assets needed in the admin section.
48 */
49 public static function enqueue_admin_assets() {
50 wp_enqueue_style( self::ADMIN_CSS );
51 }
52
53 /**
54 * Enqueue the assets needed to render the deactivation feedback form.
55 */
56 public static function enqueue_feedback_assets() {
57 $embed_domain = Filters::apply_script_loader_domain_filters();
58 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
59 wp_enqueue_style( self::FEEDBACK_CSS );
60 wp_enqueue_script( self::FEEDBACK_JS );
61 }
62
63 /**
64 * Enqueue the assets needed to correctly render the plugin's iframe.
65 */
66 public static function enqueue_bridge_assets() {
67 wp_enqueue_style( self::BRIDGE_CSS );
68 wp_enqueue_script( self::ADMIN_JS );
69 wp_enqueue_style( self::APP_ENTRY_CSS );
70 }
71
72
73 /**
74 * Enqueue the assets needed to correctly render the integrated forms app.
75 */
76 public static function enqueue_integrated_app_assets() {
77 $embed_domain = Filters::apply_js_base_url_filters();
78 wp_enqueue_style( self::BRIDGE_CSS );
79 wp_enqueue_script( self::ADMIN_JS );
80 wp_enqueue_style( self::APP_ENTRY_CSS );
81 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
82 }
83
84 /**
85 * Register and enqueue the HubSpot's script loader (aka tracking code), used to collect data from your visitors.
86 * https://knowledge.hubspot.com/account/how-does-hubspot-track-visitors
87 *
88 * @param Object $leadin_wordpress_info Object used to pass to the script loader.
89 */
90 public static function enqueue_script_loader( $leadin_wordpress_info ) {
91 $embed_domain = Filters::apply_script_loader_domain_filters();
92 $portal_id = Portal_Options::get_portal_id();
93 $business_unit_id = Portal_Options::get_business_unit_id();
94 $embed_url = "https://$embed_domain/$portal_id.js?integration=WordPress";
95
96 if ( $business_unit_id && '' !== $business_unit_id ) {
97 $embed_url = $embed_url . "&businessUnitId=$business_unit_id";
98 }
99
100 wp_register_script( self::TRACKING_CODE, $embed_url, array(), LEADIN_PLUGIN_VERSION, true );
101 wp_localize_script( self::TRACKING_CODE, 'leadin_wordpress', $leadin_wordpress_info );
102 wp_enqueue_script( self::TRACKING_CODE );
103 }
104
105 /**
106 * Register and enqueue forms script
107 */
108 public static function enqueue_forms_script() {
109 wp_enqueue_script(
110 self::FORMS_SCRIPT,
111 Filters::apply_forms_script_url_filters(),
112 array(),
113 LEADIN_PLUGIN_VERSION,
114 true
115 );
116 }
117
118 /**
119 * Register and enqueue meetings script
120 */
121 public static function enqueue_meetings_script() {
122 wp_enqueue_script(
123 self::MEETINGS_SCRIPT,
124 'https://static.hsappstatic.net/MeetingsEmbed/ex/MeetingsEmbedCode.js',
125 array(),
126 LEADIN_PLUGIN_VERSION,
127 true
128 );
129 }
130
131 /**
132 * Register and localize the Gutenberg scripts.
133 */
134 public static function localize_gutenberg() {
135 $embed_domain = Filters::apply_js_base_url_filters();
136 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
137 wp_register_style( self::GUTENBERG, LEADIN_JS_BASE_PATH . '/gutenberg.css', array(), LEADIN_PLUGIN_VERSION );
138 wp_enqueue_style( self::GUTENBERG );
139 wp_register_script( self::GUTENBERG, LEADIN_JS_BASE_PATH . '/gutenberg.js', array( 'wp-blocks', 'wp-element', 'wp-i18n', self::APP_EMBEDDER ), LEADIN_PLUGIN_VERSION, true );
140 wp_localize_script( self::GUTENBERG, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
141 wp_set_script_translations( self::GUTENBERG, 'leadin', __DIR__ . '/../languages' );
142 }
143
144 /**
145 * Register and enqueue a new script for tracking review banner events.
146 */
147 public static function enqueue_review_banner_tracking_script() {
148 wp_register_script( self::REVIEW_BANNER, LEADIN_JS_BASE_PATH . '/reviewBanner.js', array( 'jquery' ), LEADIN_PLUGIN_VERSION, true );
149 wp_localize_script( self::REVIEW_BANNER, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
150 wp_enqueue_script( self::REVIEW_BANNER );
151 }
152
153 /**
154 * Register and enqueue a new script/style for elementor.
155 */
156 public static function enqueue_elementor_script() {
157 $embed_domain = Filters::apply_js_base_url_filters();
158 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
159 wp_register_style( self::ELEMENTOR, LEADIN_JS_BASE_PATH . '/elementor.css', array(), LEADIN_PLUGIN_VERSION );
160 wp_enqueue_style( self::ELEMENTOR );
161 wp_register_script( self::ELEMENTOR, LEADIN_JS_BASE_PATH . '/elementor.js', array( 'wp-element', 'wp-i18n', self::APP_EMBEDDER ), LEADIN_PLUGIN_VERSION, true );
162 wp_localize_script( self::ELEMENTOR, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
163 wp_enqueue_script( self::ELEMENTOR );
164 wp_set_script_translations( self::ELEMENTOR, 'leadin', __DIR__ . '/../languages' );
165 }
166
167 }
168