PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 2.1.39
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v2.1.39
3.1.13 3.1.12 3.1.11 3.1.10 3.1.9 3.1.8 3.1.7 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 All 122 releases
← All changes | Inc/Core/FB/BoxBlocksParser.php +64 -77 1.0.42.1.39 View file →
@@ -1,12 +1,12 @@
1 1 <?php
2 2 /**
3 3 * @package FireBox
4 - * @version 1.0.4 Free
4 + * @version 2.1.39 Free
5 5 *
6 6 * @author FirePlugins <info@fireplugins.com>
7 7 * @link https://www.fireplugins.com
8 - * @copyright Copyright © 2021 FirePlugins All Rights Reserved
8 + * @copyright Copyright © 2025 FirePlugins All Rights Reserved
9 9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 10 */
11 11
12 12 namespace FireBox\Core\FB;
@@ -19,12 +19,35 @@
19 19 class BoxBlocksParser
20 20 {
21 21 public function __construct()
22 22 {
23 - // filter the post content by setting supported block attributes
23 + add_filter('render_block', [$this, 'maybe_load_block_extension_script'], 10, 2);
24 +
24 25 add_filter('render_block', [$this, 'modify_block_output'], 10, 2);
25 26 }
26 27
28 + public function maybe_load_block_extension_script($block_content, $block)
29 + {
30 + if (isset($block['attrs']['dataFBoxOnClick']) && in_array($block['attrs']['dataFBoxOnClick'], ['copy_clipboard', 'download_file']))
31 + {
32 + wp_enqueue_style(
33 + 'firebox-block-extensions',
34 + FBOX_MEDIA_PUBLIC_URL . 'css/block_extensions.css',
35 + [],
36 + FBOX_VERSION
37 + );
38 + wp_enqueue_script(
39 + 'firebox-block-extensions',
40 + FBOX_MEDIA_PUBLIC_URL . 'js/block_extensions.js',
41 + [],
42 + FBOX_VERSION,
43 + true
44 + );
45 + }
46 +
47 + return $block_content;
48 + }
49 +
27 50 /**
28 51 * Filters the block output by appending out custom data attributes
29 52 * on our supported blocks
30 53 *
@@ -34,8 +57,14 @@
34 57 * @return string
35 58 */
36 59 public function modify_block_output($block_content, $block)
37 60 {
61 + $atts = $this->getBlockAttributes($block);
62 + if (!$atts['utmParamsEnabled'])
63 + {
64 + return $block_content;
65 + }
66 +
38 67 if (!isset($block['blockName']))
39 68 {
40 69 return $block_content;
41 70 }
@@ -42,94 +71,51 @@
42 71
43 72 $blockName = $block['blockName'];
44 73
45 74 $parsable_blocks = [
46 - 'core/buttons',
75 + 'firebox/button',
76 + 'firebox/image',
77 + 'core/button',
47 78 'core/image'
48 79 ];
49 -
80 +
50 81 if (!in_array($blockName, $parsable_blocks))
51 82 {
52 83 return $block_content;
53 84 }
54 85
55 - /**
56 - * Handle Core Buttons Block
57 - */
58 - if ($blockName == 'core/buttons')
59 - {
60 - $buttons = isset($block['innerBlocks']) ? $block['innerBlocks'] : [];
61 - if (!$buttons)
62 - {
63 - return $block_content;
64 - }
86 + // Check if href attribute contains ? then prefix is & else prefix is ?, use regex
87 + $utmPrefix = preg_match('/href="([^"]*)\?/', $block_content) ? '&' : '?';
65 88
66 - foreach ($buttons as $button)
67 - {
68 - $block_content = $this->replaceBlockAttributes('a', $button, $block_content);
69 - }
70 - }
71 - /**
72 - * Handle Core Image Block
73 - */
74 - else if ($blockName == 'core/image')
89 + // Find utm_content
90 + $utmContent = '';
91 + if ($blockName === 'core/button')
75 92 {
76 - $new_block_html = $block['innerHTML'];
77 -
78 - // check if we have an anchor element and add attributes to this elem.
79 - $anchorExists = substr_count($new_block_html, '<a ');
80 -
81 - $element = $anchorExists ? 'a' : 'figure';
82 -
83 - $block_content = $this->replaceBlockAttributes($element, $block, $block_content);
93 + $utmContent = trim(wp_strip_all_tags($block['innerHTML']));
84 94 }
85 -
86 - return $block_content;
87 - }
88 -
89 - /**
90 - * Adds the data attributes and class($atts) to the given element($element) within the block content($block_content)
91 - *
92 - * @param string $element
93 - * @param array $block
94 - * @param string $block_element
95 - *
96 - * @return string
97 - */
98 - private function replaceBlockAttributes($element, $block, $block_content)
99 - {
100 - $atts = $this->getBlockAttributes($block);
101 - if (!$atts['enabled'])
95 + else if ($blockName === 'firebox/button')
102 96 {
103 - return $block_content;
97 + $utmContent = isset($block['attrs']['text']) ? trim(wp_strip_all_tags($block['attrs']['text'])) : '';
104 98 }
105 -
106 - $new_block_html = $block['innerHTML'];
107 -
108 - // box
109 - if ($atts['box'])
99 + else if ($blockName === 'core/image')
110 100 {
111 - $new_block_html = str_replace('<' . $element . ' ', '<' . $element . ' data-fbox="' . esc_attr($atts['box']) . '" ', $new_block_html);
101 + // Get the src attribute value from $block['innerHTML'] using regex
102 + $utmContent = preg_match('/src="([^"]*)"/', $block['innerHTML'], $matches) ? $matches[1] : '';
112 103 }
113 -
114 - // cmd
115 - if ($atts['cmd'])
104 + else if ($blockName === 'firebox/image')
116 105 {
117 - $new_block_html = str_replace('<' . $element . ' ', '<' . $element . ' data-fbox-cmd="' . esc_attr($atts['cmd']) . '" ', $new_block_html);
106 + $utmContent = isset($block['attrs']['image']['desktop']['url']) ? $block['attrs']['image']['desktop']['url'] : '';
118 107 }
108 +
109 + // Get the UTM Parameters
110 + $utmParams = $utmPrefix . 'utm_source=' . get_post_type() . '&utm_medium=' . $blockName . '&utm_campaign=' . get_the_title() . '&utm_content=' . $utmContent;
119 111
120 - // prevent default
121 - $new_block_html = str_replace('<' . $element . ' ', '<' . $element . ' data-fbox-prevent="' . esc_attr((int) $atts['preventDefault']) . '" ', $new_block_html);
112 + // Find the href attribute and append to it the utm params
113 + $block_content = preg_replace('/href="([^"]*)"/', 'href="$1' . $utmParams . '"', $block_content);
122 114
123 - // class
124 - if ($atts['class'])
125 - {
126 - $new_block_html = preg_replace('/<' . $element . '(.*)class="/', "<" . $element . "$1class=\"" . esc_attr($atts['class']) . ' ', $new_block_html);
127 - }
115 + return $block_content;
116 + }
128 117
129 - return str_replace($block['innerHTML'], $new_block_html, $block_content);
130 - }
131 -
132 118 /**
133 119 * Retrieves the block attributes
134 120 *
135 121 * @param array $block
@@ -137,15 +123,16 @@
137 123 * @return array
138 124 */
139 125 private function getBlockAttributes($block)
140 126 {
141 - $atts = [];
142 -
143 - $atts['enabled'] = isset($block['attrs']['dataFBoxEnabled']) ?: false;
144 - $atts['box'] = isset($block['attrs']['dataFBox']) ? $block['attrs']['dataFBox'] : null;
145 - $atts['cmd'] = isset($block['attrs']['dataFBoxCmd']) ? $block['attrs']['dataFBoxCmd'] : 'close';
146 - $atts['class'] = isset($block['attrs']['dataFBoxClass']) ? $block['attrs']['dataFBoxClass'] : '';
147 - $atts['preventDefault'] = isset($block['attrs']['dataFBoxPreventDefault']) ? $block['attrs']['dataFBoxPreventDefault'] : 1;
127 + $atts = [
128 + 'utmParamsEnabled' => false
129 + ];
130 +
131 + if (isset($block['attrs']['dataFBoxOnClickURLAddParameters']) && $block['attrs']['dataFBoxOnClickURLAddParameters'])
132 + {
133 + $atts['utmParamsEnabled'] = true;
134 + }
148 135
149 136 return $atts;
150 137 }
151 138 }