PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.75
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.75
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.3.75, at public/class-assetsmanager.php

191 lines 7.6 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 FORMS_V4_SCRIPT = 'leadin-forms-v4';
24 const MEETINGS_SCRIPT = 'leadin-meeting';
25 const LEADIN_CONFIG = 'leadinConfig';
26 const LEADIN_I18N = 'leadinI18n';
27 const REVIEW_BANNER = 'leadin-review-banner';
28 const ELEMENTOR = 'leadin-elementor';
29 const APP_ENTRY_CSS = 'leadin-app-css';
30 const APP_EMBEDDER = 'leadin-app-embedder';
31
32 /**
33 * Register and localize all assets.
34 */
35 public static function register_assets() {
36 wp_register_style( self::ADMIN_CSS, LEADIN_ASSETS_PATH . '/style/leadin.css', array(), LEADIN_PLUGIN_VERSION );
37 wp_register_script( self::ADMIN_JS, LEADIN_JS_BASE_PATH . '/leadin.js', array( 'jquery', 'wp-element' ), LEADIN_PLUGIN_VERSION, true );
38
39 wp_localize_script( self::ADMIN_JS, self::LEADIN_CONFIG, AdminConstants::get_leadin_config() );
40 wp_register_script( self::FEEDBACK_JS, LEADIN_JS_BASE_PATH . '/feedback.js', array( 'jquery', 'thickbox' ), LEADIN_PLUGIN_VERSION, true );
41 wp_localize_script( self::FEEDBACK_JS, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
42 wp_register_style( self::FEEDBACK_CSS, LEADIN_ASSETS_PATH . '/style/leadin-feedback.css', array(), LEADIN_PLUGIN_VERSION );
43 wp_register_style( self::BRIDGE_CSS, LEADIN_ASSETS_PATH . '/style/leadin-bridge.css?', array(), LEADIN_PLUGIN_VERSION );
44 wp_register_style( self::APP_ENTRY_CSS, LEADIN_JS_BASE_PATH . '/leadin.css', array(), LEADIN_PLUGIN_VERSION );
45 }
46
47 /**
48 * Enqueue the assets needed in the admin section.
49 */
50 public static function enqueue_admin_assets() {
51 wp_enqueue_style( self::ADMIN_CSS );
52 }
53
54 /**
55 * Enqueue the assets needed to render the deactivation feedback form.
56 */
57 public static function enqueue_feedback_assets() {
58 $embed_domain = Filters::apply_script_loader_domain_filters();
59 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
60 wp_enqueue_style( self::FEEDBACK_CSS );
61 wp_enqueue_script( self::FEEDBACK_JS );
62 }
63
64 /**
65 * Enqueue the assets needed to correctly render the plugin's iframe.
66 */
67 public static function enqueue_bridge_assets() {
68 wp_enqueue_style( self::BRIDGE_CSS );
69 wp_enqueue_script( self::ADMIN_JS );
70 wp_enqueue_style( self::APP_ENTRY_CSS );
71 }
72
73
74 /**
75 * Enqueue the assets needed to correctly render the integrated forms app.
76 */
77 public static function enqueue_integrated_app_assets() {
78 $embed_domain = Filters::apply_js_base_url_filters();
79 wp_enqueue_style( self::BRIDGE_CSS );
80 wp_enqueue_script( self::ADMIN_JS );
81 wp_enqueue_style( self::APP_ENTRY_CSS );
82 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
83 }
84
85 /**
86 * Register and enqueue the HubSpot's script loader (aka tracking code), used to collect data from your visitors.
87 * https://knowledge.hubspot.com/account/how-does-hubspot-track-visitors
88 *
89 * @param Object $leadin_wordpress_info Object used to pass to the script loader.
90 */
91 public static function enqueue_script_loader( $leadin_wordpress_info ) {
92 $embed_domain = Filters::apply_script_loader_domain_filters();
93 $portal_id = Portal_Options::get_portal_id();
94 $business_unit_id = Portal_Options::get_business_unit_id();
95 $embed_url = "https://$embed_domain/$portal_id.js?integration=WordPress";
96
97 if ( $business_unit_id && '' !== $business_unit_id ) {
98 $embed_url = $embed_url . "&businessUnitId=$business_unit_id";
99 }
100
101 wp_register_script( self::TRACKING_CODE, $embed_url, array(), LEADIN_PLUGIN_VERSION, true );
102 wp_localize_script( self::TRACKING_CODE, 'leadin_wordpress', $leadin_wordpress_info );
103 wp_enqueue_script( self::TRACKING_CODE );
104 }
105
106 /**
107 * Register and enqueue forms script
108 */
109 public static function enqueue_forms_script() {
110 wp_enqueue_script(
111 self::FORMS_SCRIPT,
112 Filters::apply_forms_script_url_filters(),
113 array(),
114 LEADIN_PLUGIN_VERSION,
115 true
116 );
117 }
118
119 /**
120 * Register and enqueue forms v4 script
121 *
122 * @param string $portal_id The portal ID.
123 */
124 public static function enqueue_form_v4_script( $portal_id ) {
125 wp_enqueue_script(
126 self::FORMS_V4_SCRIPT,
127 Filters::apply_forms_v4_script_url_filters( $portal_id ),
128 array(),
129 LEADIN_PLUGIN_VERSION,
130 true
131 );
132 }
133
134 /**
135 * Register and enqueue meetings script
136 */
137 public static function enqueue_meetings_script() {
138 wp_enqueue_script(
139 self::MEETINGS_SCRIPT,
140 'https://static.hsappstatic.net/MeetingsEmbed/ex/MeetingsEmbedCode.js',
141 array(),
142 LEADIN_PLUGIN_VERSION,
143 true
144 );
145 }
146
147 /**
148 * Register and localize the Gutenberg scripts.
149 */
150 public static function localize_gutenberg() {
151 $embed_domain = Filters::apply_js_base_url_filters();
152 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
153 self::enqueue_forms_script();
154 // The v4 forms embed script is intentionally not enqueued here: in the
155 // WP 6.3+ iframed editor the block renders `.hs-form-frame` inside the
156 // canvas iframe, so PreviewForm injects the embed script into that
157 // iframe instead. A top-frame copy would pre-empt the iframe copy's
158 // init guard and leave the preview blank.
159 self::enqueue_meetings_script();
160 wp_register_style( self::GUTENBERG, LEADIN_JS_BASE_PATH . '/gutenberg.css', array(), LEADIN_PLUGIN_VERSION );
161 wp_enqueue_style( self::GUTENBERG );
162 wp_register_script( self::GUTENBERG, LEADIN_JS_BASE_PATH . '/gutenberg.js', array( 'wp-blocks', 'wp-element', 'wp-i18n', self::APP_EMBEDDER, self::MEETINGS_SCRIPT, self::FORMS_SCRIPT ), LEADIN_PLUGIN_VERSION, true );
163 wp_localize_script( self::GUTENBERG, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
164 wp_set_script_translations( self::GUTENBERG, 'leadin', __DIR__ . '/../languages' );
165 }
166
167 /**
168 * Register and enqueue a new script for tracking review banner events.
169 */
170 public static function enqueue_review_banner_tracking_script() {
171 wp_register_script( self::REVIEW_BANNER, LEADIN_JS_BASE_PATH . '/reviewBanner.js', array( 'jquery' ), LEADIN_PLUGIN_VERSION, true );
172 wp_localize_script( self::REVIEW_BANNER, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
173 wp_enqueue_script( self::REVIEW_BANNER );
174 }
175
176 /**
177 * Register and enqueue a new script/style for elementor.
178 */
179 public static function enqueue_elementor_script() {
180 $embed_domain = Filters::apply_js_base_url_filters();
181 wp_enqueue_script( self::APP_EMBEDDER, "$embed_domain/integrated-app-embedder/v1.js", array(), LEADIN_PLUGIN_VERSION, true );
182 wp_register_style( self::ELEMENTOR, LEADIN_JS_BASE_PATH . '/elementor.css', array(), LEADIN_PLUGIN_VERSION );
183 wp_enqueue_style( self::ELEMENTOR );
184 wp_register_script( self::ELEMENTOR, LEADIN_JS_BASE_PATH . '/elementor.js', array( 'wp-element', 'wp-i18n', self::APP_EMBEDDER ), LEADIN_PLUGIN_VERSION, true );
185 wp_localize_script( self::ELEMENTOR, self::LEADIN_CONFIG, AdminConstants::get_background_leadin_config() );
186 wp_enqueue_script( self::ELEMENTOR );
187 wp_set_script_translations( self::ELEMENTOR, 'leadin', __DIR__ . '/../languages' );
188 }
189
190 }
191