| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 3.1.7 Free | |
| 4 | + * @version 2.1.4 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <info@fireplugins.com> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2026 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2024 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; |
| @@ -22,8 +22,13 @@ | ||
| 22 | 22 | { |
| 23 | 23 | add_filter('render_block', [$this, 'maybe_load_block_extension_script'], 10, 2); |
| 24 | 24 | |
| 25 | 25 | add_filter('render_block', [$this, 'modify_block_output'], 10, 2); |
| 26 | + | |
| 27 | + // DEPRECATED-START - Remove on 2024-01-01 | |
| 28 | + // filter the post content by setting supported block attributes | |
| 29 | + add_filter('render_block', [$this, 'deprecated_modify_block_output'], 10, 2); | |
| 30 | + // DEPRECATED-END | |
| 26 | 31 | } |
| 27 | 32 | |
| 28 | 33 | public function maybe_load_block_extension_script($block_content, $block) |
| 29 | 34 | { |
| @@ -89,13 +94,13 @@ | ||
| 89 | 94 | // Find utm_content |
| 90 | 95 | $utmContent = ''; |
| 91 | 96 | if ($blockName === 'core/button') |
| 92 | 97 | { |
| 93 | - $utmContent = trim(wp_strip_all_tags($block['innerHTML'])); | |
| 98 | + $utmContent = trim(strip_tags($block['innerHTML'])); | |
| 94 | 99 | } |
| 95 | 100 | else if ($blockName === 'firebox/button') |
| 96 | 101 | { |
| 97 | - $utmContent = isset($block['attrs']['text']) ? trim(wp_strip_all_tags($block['attrs']['text'])) : ''; | |
| 102 | + $utmContent = isset($block['attrs']['text']) ? trim(strip_tags($block['attrs']['text'])) : ''; | |
| 98 | 103 | } |
| 99 | 104 | else if ($blockName === 'core/image') |
| 100 | 105 | { |
| 101 | 106 | // Get the src attribute value from $block['innerHTML'] using regex |
| @@ -114,9 +119,122 @@ | ||
| 114 | 119 | |
| 115 | 120 | return $block_content; |
| 116 | 121 | } |
| 117 | 122 | |
| 123 | + // DEPRECATED-START - Remove on 2025-01-01 | |
| 118 | 124 | /** |
| 125 | + * Filters the block output by appending out custom data attributes | |
| 126 | + * on our supported blocks | |
| 127 | + * | |
| 128 | + * @param string $block_content | |
| 129 | + * @param array $block | |
| 130 | + * | |
| 131 | + * @return string | |
| 132 | + */ | |
| 133 | + public function deprecated_modify_block_output($block_content, $block) | |
| 134 | + { | |
| 135 | + if (!isset($block['blockName'])) | |
| 136 | + { | |
| 137 | + return $block_content; | |
| 138 | + } | |
| 139 | + | |
| 140 | + $blockName = $block['blockName']; | |
| 141 | + | |
| 142 | + $parsable_blocks = [ | |
| 143 | + 'firebox/buttons', | |
| 144 | + 'firebox/image', | |
| 145 | + 'core/buttons', | |
| 146 | + 'core/image' | |
| 147 | + ]; | |
| 148 | + | |
| 149 | + if (!in_array($blockName, $parsable_blocks)) | |
| 150 | + { | |
| 151 | + return $block_content; | |
| 152 | + } | |
| 153 | + | |
| 154 | + /** | |
| 155 | + * Handle Core Buttons Block | |
| 156 | + */ | |
| 157 | + if (in_array($blockName, ['core/buttons', 'firebox/buttons'])) | |
| 158 | + { | |
| 159 | + $buttons = isset($block['innerBlocks']) ? $block['innerBlocks'] : []; | |
| 160 | + if (!$buttons) | |
| 161 | + { | |
| 162 | + return $block_content; | |
| 163 | + } | |
| 164 | + | |
| 165 | + foreach ($buttons as $button) | |
| 166 | + { | |
| 167 | + $block_content = $this->replaceBlockAttributes('a', $button, $block_content); | |
| 168 | + } | |
| 169 | + } | |
| 170 | + /** | |
| 171 | + * Handle Core Image Block | |
| 172 | + */ | |
| 173 | + else if (in_array($blockName, ['core/image', 'firebox/image'])) | |
| 174 | + { | |
| 175 | + $new_block_html = $block['innerHTML']; | |
| 176 | + | |
| 177 | + // check if we have an anchor element and add attributes to this elem. | |
| 178 | + $anchorExists = substr_count($new_block_html, '<a '); | |
| 179 | + | |
| 180 | + $element = $anchorExists ? 'a' : 'figure'; | |
| 181 | + | |
| 182 | + $block_content = $this->replaceBlockAttributes($element, $block, $block_content); | |
| 183 | + } | |
| 184 | + | |
| 185 | + return $block_content; | |
| 186 | + } | |
| 187 | + | |
| 188 | + /** | |
| 189 | + * Adds the data attributes and class($atts) to the given element($element) within the block content($block_content) | |
| 190 | + * | |
| 191 | + * @param string $element | |
| 192 | + * @param array $block | |
| 193 | + * @param string $block_element | |
| 194 | + * | |
| 195 | + * @return string | |
| 196 | + */ | |
| 197 | + private function replaceBlockAttributes($element, $block, $block_content) | |
| 198 | + { | |
| 199 | + $atts = $this->getBlockAttributes($block); | |
| 200 | + | |
| 201 | + if (!$atts['enabled']) | |
| 202 | + { | |
| 203 | + return $block_content; | |
| 204 | + } | |
| 205 | + | |
| 206 | + $new_block_html = $block['innerHTML']; | |
| 207 | + | |
| 208 | + // box | |
| 209 | + if (!is_null($atts['box']) && $atts['box'] !== 'none') | |
| 210 | + { | |
| 211 | + if ($atts['box'] !== 'current') | |
| 212 | + { | |
| 213 | + $new_block_html = str_replace('<' . $element . ' ', '<' . $element . ' data-fbox="' . esc_attr($atts['box']) . '" ', $new_block_html); | |
| 214 | + } | |
| 215 | + | |
| 216 | + // cmd | |
| 217 | + if ($atts['cmd']) | |
| 218 | + { | |
| 219 | + $new_block_html = str_replace('<' . $element . ' ', '<' . $element . ' data-fbox-cmd="' . esc_attr($atts['cmd']) . '" ', $new_block_html); | |
| 220 | + } | |
| 221 | + | |
| 222 | + // prevent default | |
| 223 | + $new_block_html = str_replace('<' . $element . ' ', '<' . $element . ' data-fbox-prevent="1" ', $new_block_html); | |
| 224 | + } | |
| 225 | + | |
| 226 | + // class | |
| 227 | + if (isset($atts['class']) && !empty($atts['class'])) | |
| 228 | + { | |
| 229 | + $new_block_html = preg_replace('/<' . $element . '(.*)class="/', "<" . $element . "$1class=\"" . esc_attr($atts['class']) . ' ', $new_block_html); | |
| 230 | + } | |
| 231 | + | |
| 232 | + return str_replace($block['innerHTML'], $new_block_html, $block_content); | |
| 233 | + } | |
| 234 | + // DEPRECATED-END | |
| 235 | + | |
| 236 | + /** | |
| 119 | 237 | * Retrieves the block attributes |
| 120 | 238 | * |
| 121 | 239 | * @param array $block |
| 122 | 240 | * |
| @@ -131,8 +249,22 @@ | ||
| 131 | 249 | if (isset($block['attrs']['dataFBoxOnClickURLAddParameters']) && $block['attrs']['dataFBoxOnClickURLAddParameters']) |
| 132 | 250 | { |
| 133 | 251 | $atts['utmParamsEnabled'] = true; |
| 134 | 252 | } |
| 253 | + | |
| 254 | + // DEPRECATED-START | |
| 255 | + // FireBox settings | |
| 256 | + $atts['enabled'] = isset($block['attrs']['dataFBoxEnabled']) && $block['attrs']['dataFBoxEnabled']; | |
| 257 | + | |
| 258 | + if (!$atts['enabled']) | |
| 259 | + { | |
| 260 | + return $atts; | |
| 261 | + } | |
| 262 | + | |
| 263 | + $atts['box'] = isset($block['attrs']['dataFBox']) ? $block['attrs']['dataFBox'] : 'current'; | |
| 264 | + $atts['cmd'] = isset($block['attrs']['dataFBoxCmd']) ? $block['attrs']['dataFBoxCmd'] : 'open'; | |
| 265 | + $atts['class'] = isset($block['attrs']['dataFBoxClass']) ? $block['attrs']['dataFBoxClass'] : ''; | |
| 266 | + // DEPRECATED-END | |
| 135 | 267 | |
| 136 | 268 | return $atts; |
| 137 | 269 | } |
| 138 | 270 | } |