| @@ -1,12 +1,12 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | 3 | * @package FireBox |
| 4 | - * @version 1.0.7 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 © 2021 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; |
| @@ -21,9 +21,9 @@ | ||
| 21 | 21 | class Sounds extends Actions |
| 22 | 22 | { |
| 23 | 23 | public function __construct() |
| 24 | 24 | { |
| 25 | - add_action('firebox/box/before_render', [$this, 'onFireBoxBeforeRender']); | |
| 25 | + add_filter('firebox/box/before_render', [$this, 'onFireBoxBeforeRender']); | |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * The BeforeRender event fires before the box's layout is ready. |
| @@ -29,25 +29,25 @@ | ||
| 29 | 29 | * The BeforeRender event fires before the box's layout is ready. |
| 30 | 30 | * |
| 31 | 31 | * @param object $box The box's settings object |
| 32 | 32 | * |
| 33 | - * @return void | |
| 33 | + * @return object | |
| 34 | 34 | */ |
| 35 | 35 | public function onFireBoxBeforeRender($box) |
| 36 | 36 | { |
| 37 | 37 | if (!isset($box->params)) |
| 38 | 38 | { |
| 39 | - return; | |
| 39 | + return $box; | |
| 40 | 40 | } |
| 41 | - | |
| 41 | + | |
| 42 | 42 | if (!$opening_sound = $box->params->get('opening_sound')) |
| 43 | 43 | { |
| 44 | - return; | |
| 44 | + return $box; | |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | if (!isset($opening_sound->source)) |
| 48 | 48 | { |
| 49 | - return; | |
| 49 | + return $box; | |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $source = $opening_sound->source; |
| 53 | 53 | |
| @@ -52,9 +52,9 @@ | ||
| 52 | 52 | $source = $opening_sound->source; |
| 53 | 53 | |
| 54 | 54 | if ($source == 'none') |
| 55 | 55 | { |
| 56 | - return; | |
| 56 | + return $box; | |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | $this->actions[] = [ |
| 60 | 60 | 'box' => $box->ID, |
| @@ -61,8 +61,10 @@ | ||
| 61 | 61 | 'when' => 'open', |
| 62 | 62 | 'wrap_result' => false, |
| 63 | 63 | 'action' => $this->get_action_script($box) |
| 64 | 64 | ]; |
| 65 | + | |
| 66 | + return $box; | |
| 65 | 67 | } |
| 66 | 68 | |
| 67 | 69 | /** |
| 68 | 70 | * Returns the action script |
| @@ -74,9 +76,18 @@ | ||
| 74 | 76 | protected function get_action_script($box) |
| 75 | 77 | { |
| 76 | 78 | $file = $this->get_file($box); |
| 77 | 79 | |
| 78 | - return 'let audio = new Audio(\'' . $file . '\'); audio.pause(); audio.currentTime = 0; me.on("open", function(evt) { audio.play(); });'; | |
| 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 | + });'; | |
| 79 | 90 | } |
| 80 | 91 | |
| 81 | 92 | /** |
| 82 | 93 | * Returns the sound file |
| @@ -113,10 +124,12 @@ | ||
| 113 | 124 | * @return array |
| 114 | 125 | */ |
| 115 | 126 | public static function get() |
| 116 | 127 | { |
| 117 | - $files = \array_diff(\scandir(FBOX_PLUGIN_DIR . '/media/admin/sounds'), ['.', '..', 'index.php']); | |
| 118 | - | |
| 128 | + $files = \array_diff(\scandir(FBOX_PLUGIN_DIR . 'media/admin/sounds'), ['.', '..', 'index.php']); | |
| 129 | + | |
| 130 | + $sounds = []; | |
| 131 | + | |
| 119 | 132 | foreach ($files as $sound) |
| 120 | 133 | { |
| 121 | 134 | $sound_clean = pathinfo($sound, PATHINFO_FILENAME); |
| 122 | 135 | $sound_label = ucwords(str_replace('-', ' ', $sound_clean)); |