| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.13 Free | |
| 4 | + * @version 3.1.14 Free | |
| 5 | 5 | * |
| 6 | 6 | * @author FirePlugins <[email protected]> |
| 7 | 7 | * @link https://www.fireplugins.com |
| 8 | - * @copyright Copyright © 2022 FirePlugins All Rights Reserved | |
| 8 | + * @copyright Copyright © 2026 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\Actions; |
| @@ -30,19 +30,27 @@ | ||
| 30 | 30 | protected $actions; |
| 31 | 31 | |
| 32 | 32 | /** |
| 33 | 33 | * Currently manipulating action item |
| 34 | - * | |
| 34 | + * | |
| 35 | 35 | * @var object |
| 36 | 36 | */ |
| 37 | 37 | protected $item; |
| 38 | 38 | |
| 39 | + /** | |
| 40 | + * The campaign whose actions are currently being rendered. The "Run Javascript" | |
| 41 | + * action needs it to check the author-based custom code gate. | |
| 42 | + * | |
| 43 | + * @var int | |
| 44 | + */ | |
| 45 | + protected $box_id = 0; | |
| 46 | + | |
| 39 | 47 | public function __construct($classes = null) |
| 40 | 48 | { |
| 41 | 49 | $this->actions = $classes; |
| 42 | 50 | |
| 43 | 51 | // renders the Actions per box |
| 44 | - add_action('firebox/box/before_render', [$this, 'onFireBoxBeforeRender']); | |
| 52 | + add_filter('firebox/box/before_render', [$this, 'onFireBoxBeforeRender']); | |
| 45 | 53 | } |
| 46 | 54 | |
| 47 | 55 | /** |
| 48 | 56 | * The BeforeRender event fires before the box's layout is ready. |
| @@ -48,22 +56,52 @@ | ||
| 48 | 56 | * The BeforeRender event fires before the box's layout is ready. |
| 49 | 57 | * |
| 50 | 58 | * @param object $box The box's settings object |
| 51 | 59 | * |
| 52 | - * @return void | |
| 60 | + * @return object | |
| 53 | 61 | */ |
| 54 | 62 | public function onFireBoxBeforeRender($box) |
| 55 | 63 | { |
| 64 | + if (!isset($box->ID)) | |
| 65 | + { | |
| 66 | + return $box; | |
| 67 | + } | |
| 68 | + | |
| 69 | + $this->box_id = (int) $box->ID; | |
| 70 | + | |
| 56 | 71 | $js = ''; |
| 57 | 72 | |
| 58 | 73 | // get actions |
| 59 | 74 | $this->getActions($js); |
| 60 | 75 | |
| 76 | + // replace Smart Tags | |
| 77 | + $this->replaceSmartTags($js, $box); | |
| 78 | + | |
| 61 | 79 | // output JS |
| 62 | 80 | $this->outputActions($js, $box->ID); |
| 81 | + | |
| 82 | + return $box; | |
| 63 | 83 | } |
| 64 | 84 | |
| 65 | 85 | /** |
| 86 | + * Replace Smart Tags in JS code. | |
| 87 | + * | |
| 88 | + * @param string $js | |
| 89 | + * @param object $box | |
| 90 | + * | |
| 91 | + * @return void | |
| 92 | + */ | |
| 93 | + private function replaceSmartTags(&$js = '', $box = '') | |
| 94 | + { | |
| 95 | + $tags = new \FPFramework\Base\SmartTags\SmartTags(); | |
| 96 | + | |
| 97 | + // register FB Smart Tags | |
| 98 | + $tags->register('\FireBox\Core\SmartTags', FBOX_BASE_FOLDER . '/Inc/Core/SmartTags', $box); | |
| 99 | + | |
| 100 | + $js = $tags->replace($js); | |
| 101 | + } | |
| 102 | + | |
| 103 | + /** | |
| 66 | 104 | * Append the box actions |
| 67 | 105 | * |
| 68 | 106 | * @param string $js |
| 69 | 107 | * |
| @@ -103,8 +141,13 @@ | ||
| 103 | 141 | |
| 104 | 142 | // prepare delay |
| 105 | 143 | if (isset($this->item['delay'])) |
| 106 | 144 | { |
| 145 | + if (!$this->item['delay']) | |
| 146 | + { | |
| 147 | + $this->item['delay'] = 0; | |
| 148 | + } | |
| 149 | + | |
| 107 | 150 | $this->item['delay'] *= 1000; |
| 108 | 151 | } |
| 109 | 152 | |
| 110 | 153 | $data = [ |
| @@ -178,36 +221,37 @@ | ||
| 178 | 221 | { |
| 179 | 222 | return; |
| 180 | 223 | } |
| 181 | 224 | |
| 182 | - $js = ' | |
| 183 | - <!-- FireBox #' . esc_html($box_id) . ' Actions Start --> | |
| 184 | - ' . $this->anonymise(' | |
| 185 | - if (!FireBox) { | |
| 225 | + $js = $this->anonymise(' | |
| 226 | + if (!FireBox) { | |
| 227 | + return; | |
| 228 | + } | |
| 229 | + | |
| 230 | + FireBox.onReady(function() { | |
| 231 | + var me = FireBox.getInstance(' . esc_html($box_id) . '); | |
| 232 | + | |
| 233 | + if (!me) { | |
| 186 | 234 | return; |
| 187 | 235 | } |
| 188 | 236 | |
| 189 | - FireBox.onReady(function() { | |
| 190 | - var me = FireBox.getInstance(' . esc_html($box_id) . '); | |
| 191 | - | |
| 192 | - if (!me) { | |
| 193 | - return; | |
| 194 | - } | |
| 237 | + ' . $js . ' | |
| 238 | + }); | |
| 239 | + '); | |
| 195 | 240 | |
| 196 | - ' . $js . ' | |
| 197 | - }); | |
| 198 | - ') . ' | |
| 199 | - <!-- FireBox #' . esc_html($box_id) . ' Actions End --> | |
| 200 | - '; | |
| 201 | - | |
| 202 | - if (!did_action('wp_head')) | |
| 241 | + if (did_action('wp_enqueue_scripts')) | |
| 203 | 242 | { |
| 204 | - add_action('wp_head', function() use ($js) { | |
| 205 | - echo '<script type="text/javascript">' . $js . '</script>'; | |
| 206 | - }); | |
| 243 | + $this->addScript($js); | |
| 207 | 244 | } |
| 208 | 245 | else |
| 209 | 246 | { |
| 210 | - echo '<script type="text/javascript">' . $js . '</script>'; | |
| 247 | + add_action('wp_enqueue_scripts', function() use ($js) { | |
| 248 | + $this->addScript($js); | |
| 249 | + }); | |
| 211 | 250 | } |
| 212 | 251 | } |
| 213 | -} | |
| 252 | + | |
| 253 | + private function addScript($js) | |
| 254 | + { | |
| 255 | + \FireBox\Core\Helpers\BoxHelper::addInlineScript($js); | |
| 256 | + } | |
| 257 | +} | |