PluginProbe ʕ •ᴥ•ʔ
Hustle – Email Marketing, Lead Generation, Optins, Popups / 7.8.14
Hustle – Email Marketing, Lead Generation, Optins, Popups v7.8.14
7.8.14 7.8.14.1 7.8.13 7.8.13.1 trunk 3.0 3.1 3.1.1 3.1.2 3.1.3 3.1.4 4.3.2 4.4.4 4.4.5 4.4.5.1 4.4.5.4 4.6 4.6.1.1 4.6.1.4 4.7.0.2 4.7.0.3 4.7.0.7 4.7.0.9 4.7.1.0 4.7.1.1 4.8.0.0 5.0.0 5.0.1 5.0.1.1 5.0.1.2 5.1 5.1.1 5.1.2 5.1.3 5.1.3.1 5.1.3.2 5.1.4 5.1.5 6.0 6.0.1 6.0.2 6.0.3 6.0.4.2 6.0.5 6.0.6.1 6.0.7 6.0.8.1 6.0.9 7.0.0.1 7.0.2 7.0.3 7.0.4 7.1.0 7.1.1 7.2.0 7.2.1 7.3.0 7.3.1 7.3.3 7.3.5 7.3.6 7.3.7 7.4.0 7.4.1 7.4.11 7.4.13 7.4.13.1 7.4.2 7.4.3 7.4.4 7.4.5 7.4.5.1 7.4.5.2 7.4.6 7.4.7 7.5.0 7.6.0 7.6.1 7.6.3 7.6.4 7.6.6 7.7.0 7.7.1 7.8.0 7.8.1 7.8.10 7.8.10.1 7.8.10.2 7.8.11 7.8.12 7.8.12.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.8.9.1 7.8.9.2 7.8.9.3
wordpress-popup / inc / front / hustle-renderer-sshare.php
wordpress-popup / inc / front Last commit date
non-sshare-styles 1 month ago class-hustle-decorator-non-sshare.php 3 months ago class-hustle-decorator-sshare.php 3 months ago class-hustle-decorator_abstract.php 3 years ago class-hustle-module-preview.php 1 year ago hustle-module-front-ajax.php 3 days ago hustle-module-front.php 3 days ago hustle-module-inline-style-queue.php 3 months ago hustle-module-renderer.php 1 month ago hustle-renderer-abstract.php 3 months ago hustle-renderer-sshare.php 3 days ago
hustle-renderer-sshare.php
465 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 /**
3 * Hustle_Renderer_Sshare
4 *
5 * @package Hustle
6 */
7
8 /**
9 * Class Hustle_Renderer_Sshare
10 * Used to render Social sharing modules.
11 *
12 * @since 4.0
13 */
14 class Hustle_Renderer_Sshare extends Hustle_Renderer_Abstract {
15
16 /**
17 * Get the content container tag.
18 *
19 * @since 4.0
20 * @param string $subtype Sub type.
21 * @param string $custom_classes Custom classes.
22 * @return string
23 */
24 protected function get_wrapper_main( $subtype, $custom_classes ) {
25
26 $module_id = $this->module->module_id;
27 $display = $this->module->display;
28
29 // Tracking enabled data.
30 $tracking_enabled_data = $this->module->is_tracking_enabled( $subtype ) ? 'enabled' : 'disabled';
31
32 // Type of module
33 // Applies for all except "float" modules.
34 $module_type = 'inline';
35
36 // Main data attributes for module.
37 $module_data = sprintf(
38 '
39 data-id="%s"
40 data-render-id="%d"
41 data-tracking="%s"
42 data-sub-type="%s"
43 ',
44 esc_attr( $module_id ),
45 self::$render_ids[ $module_id ],
46 esc_attr( $tracking_enabled_data ),
47 esc_attr( $subtype )
48 );
49
50 // If this instance is a floating module.
51 // This happens when floating is enabled in either desktop or mobile.
52 if ( Hustle_SShare_Model::FLOAT_MODULE === $subtype ) {
53
54 $module_type = 'float';
55
56 // Check if the module has floating active for desktop.
57 if ( self::$is_preview ) {
58 $module_data .= 'data-desktop="true"';
59 } elseif ( $this->module->is_display_type_active( Hustle_SShare_Model::FLOAT_DESKTOP ) ) {
60
61 $offset = 'css_selector' === $display->float_desktop_offset ? 'selector' : $display->float_desktop_offset;
62 $selector = 'selector' === $offset ? trim( $display->float_desktop_css_selector ) : '';
63 $position_x = $display->float_desktop_position;
64 $position_y = $display->float_desktop_position_y;
65
66 $module_data .= sprintf(
67 '
68 data-desktop="true"
69 data-desktop-offset="%s"
70 data-desktop-selector="%s"
71 data-desktop-positionX="%s"
72 data-desktop-positionY="%s"
73 ',
74 esc_attr( $offset ),
75 esc_attr( $selector ),
76 esc_attr( $position_x ),
77 esc_attr( $position_y )
78 );
79 } else {
80 $module_data .= 'data-desktop="false"';
81 }
82
83 // Check if the module has floating active for mobile.
84 if ( $this->module->is_display_type_active( Hustle_SShare_Model::FLOAT_MOBILE ) ) {
85
86 $offset = 'css_selector' === $display->float_mobile_offset ? 'selector' : $display->float_mobile_offset;
87 $selector = 'selector' === $offset ? trim( $display->float_mobile_css_selector ) : '';
88 $position_x = $display->float_mobile_position;
89 $position_y = $display->float_mobile_position_y;
90
91 $module_data .= sprintf(
92 '
93 data-mobiles="true"
94 data-mobiles-offset="%s"
95 data-mobiles-selector="%s"
96 data-mobiles-positionX="%s"
97 data-mobiles-positionY="%s"
98 ',
99 esc_attr( $offset ),
100 esc_attr( $selector ),
101 esc_attr( $position_x ),
102 esc_attr( $position_y )
103 );
104 } else {
105 $module_data .= 'data-mobiles="false"';
106 }
107 } else {
108
109 $module_data .= sprintf(
110 '
111 data-delay="%s"
112 data-intro="%s"
113 ',
114 '0',
115 'no_animation'
116 );
117
118 if ( Hustle_SShare_Model::INLINE_MODULE === $subtype ) {
119
120 $module_data .= sprintf(
121 'data-alignment="%s"',
122 esc_attr( $display->inline_align )
123 );
124 }
125 }
126
127 $inline_style = ! self::$is_preview ? 'style="opacity:0;"' : 'style="opacity:1;"';
128
129 if ( self::$is_preview ) {
130 $custom_classes .= ' hustle-displaying-in-large';
131 }
132
133 $html = sprintf(
134 '<div class="hustle-ui hustle-%s hustle_module_id_%d %s" %s %s>',
135 esc_attr( $module_type ),
136 $this->module->module_id,
137 esc_attr( $custom_classes ),
138 $module_data,
139 $inline_style
140 );
141
142 return $html;
143 }
144
145 /**
146 * Get the wrapper content.
147 *
148 * @since 4.0
149 *
150 * @param string $subtype Sub type.
151 * @return string
152 */
153 protected function get_wrapper_content( $subtype ) {
154
155 $module_type = 'inline';
156
157 if ( Hustle_SShare_Model::FLOAT_MODULE === $subtype ) {
158 $module_type = 'float';
159 }
160
161 $html = sprintf(
162 '<div class="hustle-%s-content">',
163 $module_type
164 );
165
166 return $html;
167 }
168
169 /**
170 * Get the body content.
171 *
172 * @since 4.0
173 *
174 * @param string $subtype Sub type.
175 * @return string
176 */
177 protected function get_module_body( $subtype ) {
178
179 $html = '';
180
181 $module_id = $this->module->module_id;
182
183 // Prevent php error messages on wizard preview when no services are active.
184 $content = $this->module->content;
185 $display = $this->module->display;
186 $design = $this->module->design;
187
188 $icons_design = $design->icon_style;
189 $icons_custom_color = 'false';
190 $icons_grid_desktop = 'inline';
191 $icons_grid_mobiles = 'inline';
192 $icons_counter = 'none';
193 $icons_animated = false;
194 $icons_animation = 'zoom';
195
196 if ( 'flat' === $icons_design ) {
197 $icons_design = 'default';
198 } elseif ( 'outline' === $icons_design ) {
199 $icons_design = 'outlined';
200 }
201
202 if ( Hustle_SShare_Model::FLOAT_MODULE === $subtype ) {
203
204 // Check if icons custom color is enabled.
205 $icons_custom_color = ( '1' === $design->floating_customize_colors ) ? 'true' : 'false';
206
207 // Check if the module has floating active for desktop.
208 if ( $this->module->is_display_type_active( Hustle_SShare_Model::FLOAT_DESKTOP ) ) {
209
210 $position_x = $display->float_desktop_position;
211 $position_y = $display->float_desktop_position_y;
212
213 if ( 'center' !== $display->float_desktop_position ) {
214 $icons_grid_desktop = 'stacked';
215 }
216
217 if ( 'center' === $position_x ) {
218
219 if ( 'top' === $position_y ) {
220 $icons_animation = 'bounceDownUp';
221 } else {
222 $icons_animation = 'bounceUpDown';
223 }
224 }
225 }
226
227 // Check if the module has floating active for mobile.
228 if ( $this->module->is_display_type_active( Hustle_SShare_Model::FLOAT_MOBILE ) ) {
229
230 $position_x = $display->float_mobile_position;
231 $position_y = $display->float_mobile_position_y;
232
233 if ( 'center' !== $display->float_mobile_position ) {
234 $icons_grid_mobiles = 'stacked';
235 }
236
237 if ( 'center' === $position_x ) {
238
239 if ( 'top' === $position_y ) {
240 $icons_animation = 'bounceDownUp';
241 } else {
242 $icons_animation = 'bounceUpDown';
243 }
244 }
245 }
246
247 if ( self::$is_preview ) {
248 $icons_grid_desktop = 'stacked';
249 $icons_grid_mobiles = 'stacked';
250 }
251
252 // Check if counter is enabled.
253 if ( '1' === $content->counter_enabled ) {
254 $icons_counter = ( '1' === $design->floating_inline_count ) ? 'inline' : 'stacked';
255 }
256
257 // Check if icons are animated.
258 if ( '1' === $design->floating_animate_icons ) {
259 $icons_animated = true;
260 }
261 } else {
262
263 // Check if icons custom color is enabled.
264 $icons_custom_color = ( '1' === $design->widget_customize_colors ) ? 'true' : 'false';
265
266 // Check if counter is enabled.
267 if ( '1' === $content->counter_enabled ) {
268 $icons_counter = ( '1' === $design->widget_inline_count ) ? 'inline' : 'stacked';
269 }
270
271 // Check if icons are animated.
272 if ( '1' === $design->widget_animate_icons ) {
273 $icons_animated = true;
274 }
275 }
276
277 $html .= sprintf(
278 '<div class="hustle-social hustle-social--%s" data-custom="%s" data-grid-desktop="%s" data-grid-mobiles="%s">',
279 esc_attr( $icons_design ),
280 esc_attr( $icons_custom_color ),
281 esc_attr( $icons_grid_desktop ),
282 esc_attr( $icons_grid_mobiles )
283 );
284
285 $html .= sprintf(
286 '<ul class="hustle-counter--%s%s"%s>',
287 esc_attr( $icons_counter ),
288 ( true === $icons_animated ? ' hustle-animated' : '' ),
289 ( true === $icons_animated ? ' data-animation="' . esc_attr( $icons_animation ) . '"' : '' )
290 );
291
292 $social_icons = $content->social_icons;
293
294 /**
295 * Filters the icons to be shown.
296 * Here you can add custom icons to be printed. It only works for networks
297 * using custom links (non-native ones), and without counters.
298 * The icon and visual attributes must be handled via custom CSS.
299 *
300 * @since 4.1.2
301 *
302 * @param array $social_icons {
303 * Selected social networks for the module.
304 * Contains an array for each platform. The platform's slug is the key of its array.
305 * The array for each platform must contain:
306 *
307 * @type string 'platform' The network's slug. Same as the array key. Lowercase, no spaces nor special chars.
308 * @type string 'label' The network's display name.
309 * @type string 'type' click|native Whether the counter would be retrieved from clicks or an API. Use 'click'.
310 * @type string 'link' The URL to which the user will go when clicking the icon. Required if a sharing
311 * endpoint isn't especified in the filter @see hustle_native_share_enpoints.
312 * @type int 'counter' The default number for the counter. This will be static, it won't increase for now.
313 * }
314 */
315 $social_icons = apply_filters( 'hustle_social_sharing_get_selected_networks', $social_icons, $this->module );
316
317 // Extra indentation to mimic html tree.
318 if ( ! empty( $social_icons ) ) {
319
320 foreach ( $social_icons as $icon => $data ) {
321
322 $type = isset( $data['type'] ) ? $data['type'] : '';
323 $label = isset( $data['label'] ) ? $data['label'] : '';
324 $link = isset( $data['link'] ) ? $data['link'] : '';
325
326 if ( 'facebook' === $data['platform'] ) {
327 $type = 'click';
328
329 // Build the Facebook share URL when no custom link is provided.
330 if ( '' === $link ) {
331 global $wp;
332 $current_url = rawurlencode( home_url( $wp->request ) );
333
334 if ( ! empty( $data['app_id'] ) ) {
335 // Use the Share Dialog when an App ID is available.
336 $link = 'https://www.facebook.com/dialog/share?app_id=' . rawurlencode( sanitize_text_field( $data['app_id'] ) ) . '&href=' . $current_url;
337 } else {
338 // Fallback for existing entries saved before the App ID field was added.
339 $link = 'https://www.facebook.com/sharer/sharer.php?u=' . $current_url;
340 }
341 }
342 }
343
344 if ( '' === $link && 'email' !== $icon ) {
345
346 $href_value = 'href="#"';
347 $link_type = 'native';
348
349 } else {
350 // Check if is email to insert mailto.
351 if ( 'email' === $icon ) {
352
353 $query_args = array(
354 'subject' => rawurlencode( Opt_In_Utils::replace_global_placeholders( $data['title'] ) ),
355 'body' => rawurlencode( Opt_In_Utils::replace_global_placeholders( $data['message'] ) ),
356 );
357 $mail_url = add_query_arg( $query_args, 'mailto:' );
358 $href_value = 'href="' . esc_url( $mail_url ) . '"';
359 $title = apply_filters( 'hustle_social_share_platform_title', rawurlencode( html_entity_decode( esc_html( get_the_title() ) ) ) );
360
361 } else {
362 $link = apply_filters( 'hustle_social_share_custom_link', $link, $data, $this->module );
363 $href_value = 'href="' . esc_url( $link ) . '" target="_blank" rel="noopener"';
364 }
365
366 $link_type = 'custom';
367
368 }
369
370 if ( 'fivehundredpx' === $icon ) {
371 $icon = '500px';
372 $network = 'fivehundredpx';
373 } else {
374 $network = $icon;
375 }
376
377 $html .= '<li>';
378
379 $html .= sprintf(
380 '<a %1$s class="hustle-share-icon hustle-share--%2$s" data-network="%3$s" data-counter="%4$s" data-link="%5$s" data-count="%6$s">',
381 $href_value,
382 esc_attr( $icon ),
383 esc_attr( $network ),
384 '0' === $content->counter_enabled ? 'none' : esc_attr( $type ),
385 esc_attr( $link_type ),
386 esc_attr( $data['counter'] )
387 );
388
389 $html .= sprintf(
390 '<i class="hustle-icon-social-%s" aria-hidden="true"></i>',
391 esc_attr( $icon )
392 );
393
394 if ( '1' === $content->counter_enabled ) {
395
396 if ( 'native' === $type && ! self::$is_preview ) {
397 $counter_content = '<i class="hustle-icon-loader hustle-loading-icon" aria-hidden="true"></i>';
398
399 } else {
400 $counter_content = ( '' !== $data['counter'] ) ? esc_attr( $data['counter'] ) : '0';
401 }
402
403 $html .= sprintf(
404 '<span class="hustle-counter" aria-hidden="true">%s</span>',
405 $counter_content
406 );
407 }
408
409 $html .= sprintf(
410 '<span class="hustle-screen-reader">Share on %s</span>',
411 esc_html( $label )
412 );
413
414 $html .= '</a>';
415
416 $html .= '</li>';
417
418 }
419 }
420
421 $html .= '</ul>';
422
423 $html .= '</div>';
424
425 return $html;
426 }
427
428 /**
429 * Handle AJAX display
430 *
431 * @since 4.0
432 * @param Hustle_Sshare_Model $module Module.
433 * @param array $data Data.
434 * @param bool $is_preview Is preview.
435 * @return string
436 */
437 public function ajax_display( Hustle_Sshare_Model $module, $data = array(), $is_preview = true ) {
438
439 self::$is_preview = $is_preview;
440
441 if ( ! empty( $data ) ) {
442 $this->module = $module->load_preview( $data );
443 } else {
444 $this->module = $module->load();
445 }
446
447 $response = array(
448 'style' => array(),
449 'script' => array(),
450 'module' => $this->module,
451 );
452
453 $response['floatingHtml'] = $this->get_module( Hustle_SShare_Model::FLOAT_MODULE, 'hustle-show', $is_preview );
454 $response['widgetHtml'] = $this->get_module( Hustle_SShare_Model::WIDGET_MODULE, 'hustle-show', $is_preview );
455
456 // This might be used later for ajax loading.
457 ob_start();
458 $this->print_styles( $is_preview );
459 $styles = ob_get_clean();
460 $response['style'] = $styles;
461
462 return $response;
463 }
464 }
465