PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.65
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.65
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 / data / class-filters.php

class-filters.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.65, at public/data/class-filters.php

225 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Leadin\data;
3
4 use Leadin\data\Portal_Options;
5 use Leadin\Proxy_Mappings;
6
7 /**
8 * Class containing all the custom filters defined to be used instead of constants.
9 */
10 class Filters {
11
12 /**
13 * Return the current hublet.
14 */
15 public static function apply_hublet_filters() {
16 return apply_filters( LEADIN_PREFIX . '_hublet', Portal_Options::get_hublet() );
17 }
18
19 /**
20 * Return the prefix for UI urls.
21 */
22 public static function apply_app_prefix_filters() {
23 return self::resolve_hublet( apply_filters( LEADIN_PREFIX . '_app_prefix', 'app' ) );
24 }
25
26 /**
27 * Return the prefix for UI urls.
28 */
29 public static function apply_js_prefix_filters() {
30 return self::resolve_hublet( apply_filters( LEADIN_PREFIX . '_js_prefix', 'js' ) );
31 }
32
33 /**
34 * Return the prefix for API urls.
35 */
36 public static function apply_api_prefix_filters() {
37 return self::resolve_hublet( apply_filters( LEADIN_PREFIX . '_api_prefix', 'api' ) );
38 }
39
40 /**
41 * Return the Hubspot domain.
42 */
43 public static function apply_hubspot_domain_filters() {
44 return apply_filters( LEADIN_PREFIX . '_hubspot_domain', 'hubspot.com' );
45 }
46
47 /**
48 * Apply leadin_base_url filter.
49 *
50 * @param boolean $cross_hublet if false it's use non-hublet specific prefix. For example, "app" instead of "app-eu1".
51 */
52 public static function apply_base_url_filters( $cross_hublet = true ) {
53 $prefix = $cross_hublet ? self::apply_app_prefix_filters() : apply_filters( LEADIN_PREFIX . '_app_prefix', 'app' );
54 $domain = self::apply_hubspot_domain_filters();
55 return apply_filters( LEADIN_PREFIX . '_base_url', "https://$prefix.$domain" );
56 }
57
58 /**
59 * Apply leadin_js_base_url filter.
60 */
61 public static function apply_js_base_url_filters() {
62 $prefix = self::apply_js_prefix_filters();
63 $domain = self::apply_hubspot_domain_filters();
64 return apply_filters( LEADIN_PREFIX . '_js_base_url', "https://$prefix.$domain" );
65 }
66
67 /**
68 * Apply filter to get the base url for the HubSpot api.
69 *
70 * @param boolean $cross_hublet if true it's use non-hublet specific prefix. For example, "api" instead of "api-eu1".
71 */
72 public static function apply_base_api_url_filters( $cross_hublet = false ) {
73 $prefix = $cross_hublet ? 'api' : self::apply_api_prefix_filters();
74 $domain = self::apply_hubspot_domain_filters();
75 return apply_filters( LEADIN_PREFIX . '_base_api_url', "https://$prefix.$domain" );
76 }
77
78 /**
79 * Apply leadin_signup_base_url filter.
80 */
81 public static function apply_signup_base_url_filters() {
82 $domain = self::apply_hubspot_domain_filters();
83 return apply_filters( LEADIN_PREFIX . '_signup_base_url', "https://app.$domain" );
84 }
85
86 /**
87 * Apply leadin_forms_script_url filter.
88 */
89 public static function apply_forms_script_url_filters() {
90 $hublet_domain = self::resolve_hublet( 'js' );
91 return apply_filters( LEADIN_PREFIX . '_forms_script_url', "https://$hublet_domain.hsforms.net/forms/embed/v2.js" );
92 }
93
94 /**
95 * Apply leadin_forms_v4_script_url filter.
96 *
97 * @param string $portal_id The portal ID.
98 */
99 public static function apply_forms_v4_script_url_filters( $portal_id ) {
100 $hublet_domain = self::resolve_hublet( 'js' );
101 return apply_filters( LEADIN_PREFIX . '_forms_v4_script_url', "https://$hublet_domain.hsforms.net/forms/embed/$portal_id.js" );
102 }
103
104 /**
105 * Apply leadin_meetings_script_url filter.
106 */
107 public static function apply_meetings_script_url_filters() {
108 return apply_filters( LEADIN_PREFIX . '_meetings_script_url', 'https://static.hsappstatic.net/MeetingsEmbed/ex/MeetingsEmbedCode.js' );
109 }
110
111 /**
112 * Apply leadin_script_loader_domain filter.
113 */
114 public static function apply_script_loader_domain_filters() {
115 $hublet_domain = self::resolve_hublet( 'js' );
116 return apply_filters( LEADIN_PREFIX . '_script_loader_domain', "$hublet_domain.hs-scripts.com" );
117 }
118
119 /**
120 * Apply leadin_forms_payload filter.
121 */
122 public static function apply_forms_payload_filters() {
123 return apply_filters( LEADIN_PREFIX . '_forms_payload', '' );
124 }
125
126 /**
127 * Apply leadin_forms_v4_payload filter.
128 */
129 public static function apply_forms_v4_payload_filters() {
130 return apply_filters( LEADIN_PREFIX . '_forms_v4_payload', '' );
131 }
132
133 /**
134 * Apply leadin_forms_payload_url filter.
135 */
136 public static function apply_page_content_type_filters() {
137 if ( is_single() ) {
138 $content_type = 'blog-post';
139 } elseif ( is_archive() || is_search() ) {
140 $content_type = 'listing-page';
141 } else {
142 $content_type = 'standard-page';
143 }
144
145 return apply_filters( LEADIN_PREFIX . '_page_content_type', $content_type );
146 }
147
148 /**
149 * Apply leadin_view_plugin_menu_capability filter.
150 */
151 public static function apply_view_plugin_menu_capability_filters() {
152 return apply_filters( LEADIN_PREFIX . '_view_plugin_menu_capability', 'edit_posts' );
153 }
154
155 /**
156 * Apply leadin_connect_plugin_capability filter.
157 */
158 public static function apply_connect_plugin_capability_filters() {
159 return apply_filters( LEADIN_PREFIX . '_connect_plugin_capability', 'manage_options' );
160 }
161
162 /**
163 * Apply leadin_impact_code filter.
164 */
165 public static function apply_impact_code_filters() {
166 return apply_filters( LEADIN_PREFIX . '_impact_code', null );
167 }
168
169 /**
170 * Apply leadin_query_params filter.
171 */
172 public static function apply_query_params_filters() {
173 return apply_filters( LEADIN_PREFIX . '_query_params', '' );
174 }
175
176 /**
177 * Add hublet to the prefix.
178 *
179 * @param String $prefix Prefix to add the hublet to.
180 */
181 private static function resolve_hublet( $prefix ) {
182 $hublet = self::apply_hublet_filters();
183 $result = $prefix;
184 if ( ! empty( $hublet ) && 'na1' !== $hublet ) {
185 $result = "$prefix-$hublet";
186 }
187 return $result;
188 }
189
190 /**
191 * Add swimlane to the prefix when hublet is NA1.
192 *
193 * @param String $prefix Prefix to add the swimlane.
194 */
195 private static function resolve_swimlane_for_na1( $prefix ) {
196 $hublet = self::apply_hublet_filters();
197 $result = $prefix;
198 if ( ! empty( $hublet ) && 'na1' === $hublet ) {
199 // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.intdivFound
200 $swimlane = intdiv( Portal_Options::get_portal_id(), 10 ) % 5;
201 $result = $prefix . $swimlane . '0';
202 }
203 return $result;
204 }
205
206 /**
207 * Apply filter to get the get all proxy mapping url.
208 */
209 public static function apply_plugin_mappings_api_url() {
210 $base_url = self::apply_base_api_url_filters( false );
211 return apply_filters( LEADIN_PREFIX . '_plugin_mappings_api_url', "$base_url/cos-domains/v1/wp-plugin-mappings/get-all" );
212 }
213
214
215 /**
216 * Apply leadin_sites_proxy_cdn filter.
217 */
218 public static function apply_sites_proxy_cdn_filters() {
219 $portal_id = Portal_Options::get_portal_id();
220 $domain = self::resolve_swimlane_for_na1( self::resolve_hublet( 'sites-proxy.hscoscdn' ) );
221 return apply_filters( LEADIN_PREFIX . '_sites_proxy_cdn', "https://$portal_id.$domain.net" );
222 }
223
224 }
225