PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 3.1.10
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v3.1.10
3.1.14 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 All 123 releases
firebox / Inc / Core / FB / Actions / Sounds.php

Sounds.php in FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment 3.1.10, at Inc/Core/FB/Actions/Sounds.php

141 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package FireBox
4 * @version 3.1.10 Free
5 *
6 * @author FirePlugins <[email protected]>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2026 FirePlugins All Rights Reserved
9 * @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
10 */
11
12 namespace FireBox\Core\FB\Actions;
13
14 if (!defined('ABSPATH'))
15 {
16 exit; // Exit if accessed directly.
17 }
18
19 use FPFramework\Libs\Registry;
20
21 class Sounds extends Actions
22 {
23 public function __construct()
24 {
25 add_filter('firebox/box/before_render', [$this, 'onFireBoxBeforeRender']);
26 }
27
28 /**
29 * The BeforeRender event fires before the box's layout is ready.
30 *
31 * @param object $box The box's settings object
32 *
33 * @return object
34 */
35 public function onFireBoxBeforeRender($box)
36 {
37 if (!isset($box->params))
38 {
39 return $box;
40 }
41
42 if (!$opening_sound = $box->params->get('opening_sound'))
43 {
44 return $box;
45 }
46
47 if (!isset($opening_sound->source))
48 {
49 return $box;
50 }
51
52 $source = $opening_sound->source;
53
54 if ($source == 'none')
55 {
56 return $box;
57 }
58
59 $this->actions[] = [
60 'box' => $box->ID,
61 'when' => 'open',
62 'wrap_result' => false,
63 'action' => $this->get_action_script($box)
64 ];
65
66 return $box;
67 }
68
69 /**
70 * Returns the action script
71 *
72 * @param object $box
73 *
74 * @return string
75 */
76 protected function get_action_script($box)
77 {
78 $file = $this->get_file($box);
79
80 return 'let audio = new Audio(\'' . $file . '\');
81 audio.pause();
82 audio.currentTime = 0;
83 audio.play();
84
85 // Stop the audio when the campaign closes
86 me.on("close", function() {
87 audio.pause();
88 audio.currentTime = 0;
89 });';
90 }
91
92 /**
93 * Returns the sound file
94 *
95 * @param object $box
96 *
97 * @return string
98 */
99 private function get_file($box)
100 {
101 $opening_sound = $box->params->get('opening_sound');
102 $source = $opening_sound->source;
103
104 // local audio file
105 $file = FBOX_MEDIA_ADMIN_URL . 'sounds/' . $source . '.mp3';
106
107 // audio comes from a custom file
108 if ($source == 'custom_file' && isset($opening_sound->file) && !empty($opening_sound->file))
109 {
110 $file = $opening_sound->file;
111 }
112 // audio comes from a custom URL
113 else if ($source == 'custom_url' && isset($opening_sound->url) && !empty($opening_sound->url))
114 {
115 $file = $opening_sound->url;
116 }
117
118 return $file;
119 }
120
121 /**
122 * Get all available sounds.
123 *
124 * @return array
125 */
126 public static function get()
127 {
128 $files = \array_diff(\scandir(FBOX_PLUGIN_DIR . 'media/admin/sounds'), ['.', '..', 'index.php']);
129
130 $sounds = [];
131
132 foreach ($files as $sound)
133 {
134 $sound_clean = pathinfo($sound, PATHINFO_FILENAME);
135 $sound_label = ucwords(str_replace('-', ' ', $sound_clean));
136 $sounds[$sound_clean] = $sound_label;
137 }
138
139 return $sounds;
140 }
141 }