PluginProbe
Visualizer – Tables & Charts Manager with Built-in AI Generator / 3.11.7
Visualizer – Tables & Charts Manager with Built-in AI Generator v3.11.7
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.2 3.1.3 3.10.0 3.10.1 3.10.10 3.10.11 3.10.12 3.10.13 3.10.14 3.10.15 3.10.2 3.10.3 3.10.4 All 148 releases
← All changes | vendor/codeinwp/themeisle-sdk/src/Modules/Script_loader.php +26 -96 4.0.43.11.7 View file →
@@ -61,33 +61,13 @@
61 61 }
62 62
63 63 add_filter( 'themeisle_sdk_dependency_script_handler', [ $this, 'get_script_handler' ], 10, 1 );
64 64 add_action( 'themeisle_sdk_dependency_enqueue_script', [ $this, 'enqueue_script' ], 10, 1 );
65 - add_filter( 'themeisle_sdk_secret_masking', [ $this, 'secret_masking' ], 10, 1 );
66 65
67 66 add_filter( 'themeisle_sdk_script_setup', '__return_true' );
68 -
69 - add_action( 'themeisle_internal_page', [ $this, 'load_survey_for_product' ], 10, 2 );
70 67 }
71 68
72 69 /**
73 - * Load survey for product using internal pages.
74 - *
75 - * @param string $product_slug Product slug.
76 - * @param string $page_slug Page slug.
77 - */
78 - public function load_survey_for_product( $product_slug, $page_slug ) {
79 - $data = apply_filters( 'themeisle-sdk/survey/' . $product_slug, [], $page_slug );
80 -
81 - if ( empty( $data ) || ! is_array( $data ) ) {
82 - return;
83 - }
84 -
85 - $handler = $this->get_script_handler( 'survey' );
86 - $this->load_survey( $handler, $data );
87 - }
88 -
89 - /**
90 70 * Get the script handler.
91 71 *
92 72 * @param string $slug The slug of the script.
93 73 *
@@ -97,9 +77,9 @@
97 77 if ( ! is_string( $slug ) ) {
98 78 return '';
99 79 }
100 80
101 - if ( 'tracking' !== $slug && 'survey' !== $slug ) {
81 + if ( 'tracking' !== $slug && 'survey' !== $slug && 'banner' !== $slug ) {
102 82 return '';
103 83 }
104 84
105 85 return apply_filters( 'themeisle_sdk_dependency_script_handler_name', 'themeisle_sdk_' . $slug . '_script', $slug );
@@ -119,8 +99,10 @@
119 99 if ( 'tracking' === $slug ) {
120 100 $this->load_tracking( $handler );
121 101 } elseif ( 'survey' === $slug ) {
122 102 $this->load_survey( $handler );
103 + } elseif ( 'banner' === $slug ) {
104 + $this->load_banner( $handler );
123 105 }
124 106 }
125 107
126 108 /**
@@ -126,13 +108,12 @@
126 108 /**
127 109 * Load the survey script.
128 110 *
129 111 * @param string $handler The script handler.
130 - * @param array $data The survey data.
131 112 *
132 113 * @return void
133 114 */
134 - public function load_survey( $handler, $data = array() ) {
115 + public function load_survey( $handler ) {
135 116 global $themeisle_sdk_max_path;
136 117 $asset_file = require $themeisle_sdk_max_path . '/assets/js/build/survey/survey_deps.asset.php';
137 118
138 119 wp_enqueue_script(
@@ -142,22 +123,9 @@
142 123 $asset_file['version'],
143 124 true
144 125 );
145 126
146 - $data = array_replace_recursive( $this->get_survey_common_data( $data ), $data );
147 -
148 - wp_localize_script( $handler, 'tsdk_survey_data', $data );
149 - }
150 -
151 - /**
152 - * Get the common data in the Formbrick survey format.
153 - *
154 - * @param array $reference_data Reference data to extrapolate common properties.
155 - *
156 - * @return array
157 - */
158 - public function get_survey_common_data( $reference_data = array() ) {
159 - $language = apply_filters( 'themeisle_sdk_current_lang', get_user_locale() );
127 + $language = get_user_locale();
160 128 $available_languages = [
161 129 'de_DE' => 'de',
162 130 'de_DE_formal' => 'de',
163 131 ];
@@ -162,61 +130,12 @@
162 130 'de_DE_formal' => 'de',
163 131 ];
164 132 $lang_code = isset( $available_languages[ $language ] ) ? $available_languages[ $language ] : 'en';
165 133
166 - $url_parts = wp_parse_url( apply_filters( 'themeisle_sdk_current_site_url', get_site_url() ) );
167 - $clean_url = str_replace( 'www.', '', $url_parts['host'] );
168 - if ( isset( $url_parts['path'] ) ) {
169 - $clean_url .= $url_parts['path'];
170 - }
171 - $user_id = 'u_' . hash( 'crc32b', $clean_url );
172 -
173 - $common_data = [
174 - 'userId' => $user_id,
175 - 'appUrl' => 'https://app.formbricks.com',
176 - 'attributes' => [
177 - 'language' => $lang_code,
178 - ],
179 - ];
180 -
181 - if (
182 - isset( $reference_data['attributes'], $reference_data['attributes']['install_days_number'] )
183 - && is_int( $reference_data['attributes']['install_days_number'] )
184 - ) {
185 - $common_data['attributes']['days_since_install'] = $this->install_time_category( $reference_data['attributes']['install_days_number'] );
186 - }
187 -
188 - return $common_data;
134 + wp_localize_script( $handler, 'tsdk_survey_attrs', [ 'language' => $lang_code ] );
189 135 }
190 136
191 137 /**
192 - * Compute the install time category.
193 - *
194 - * @param int $install_days_number The number of days passed since installation.
195 - *
196 - * @return int The category.
197 - */
198 - private function install_time_category( $install_days_number ) {
199 - if ( 1 < $install_days_number && 8 > $install_days_number ) {
200 - return 7;
201 - }
202 -
203 - if ( 8 <= $install_days_number && 31 > $install_days_number ) {
204 - return 30;
205 - }
206 -
207 - if ( 30 < $install_days_number && 90 > $install_days_number ) {
208 - return 90;
209 - }
210 -
211 - if ( 90 <= $install_days_number ) {
212 - return 91;
213 - }
214 -
215 - return 0;
216 - }
217 -
218 - /**
219 138 * Load the tracking script.
220 139 *
221 140 * @param string $handler The script handler.
222 141 *
@@ -235,19 +154,30 @@
235 154 );
236 155 }
237 156
238 157 /**
239 - * Mask a secret with `*` for half of its length.
158 + * Load the banner script.
240 159 *
241 - * @param mixed $secret The secret.
160 + * @param string $handler The script handler.
242 161 *
243 - * @return mixed The masked secret if secret is a valid string.
162 + * @return void
244 163 */
245 - public function secret_masking( $secret ) {
246 - if ( empty( $secret ) || ! is_string( $secret ) ) {
247 - return $secret;
248 - }
164 + public function load_banner( $handler ) {
165 + global $themeisle_sdk_max_path;
166 + $asset_file = require $themeisle_sdk_max_path . '/assets/js/build/banner/banner.asset.php';
249 167
250 - $half_len = intval( strlen( $secret ) / 2 );
251 - return str_repeat( '*', $half_len ) . substr( $secret, $half_len );
168 + wp_enqueue_script(
169 + $handler,
170 + $this->get_sdk_uri() . 'assets/js/build/banner/banner.js',
171 + $asset_file['dependencies'],
172 + $asset_file['version'],
173 + true
174 + );
175 +
176 + wp_enqueue_style(
177 + $handler . '_style',
178 + $this->get_sdk_uri() . 'assets/css/banner.css',
179 + [],
180 + $asset_file['version']
181 + );
252 182 }
253 183 }