PluginProbe
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment / 1.0.13
FireBox – WooCommerce Popup Builder, Exit Intent Popup, Email Optin & Cart Abandonment v1.0.13
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
firebox / Inc / Core / FB / Actions / Sounds.php

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

128 lines 3.0 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 1.0.13 Free
5 *
6 * @author FirePlugins <info@fireplugins.com>
7 * @link https://www.fireplugins.com
8 * @copyright Copyright © 2022 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_action('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 void
34 */
35 public function onFireBoxBeforeRender($box)
36 {
37 if (!isset($box->params))
38 {
39 return;
40 }
41
42 if (!$opening_sound = $box->params->get('opening_sound'))
43 {
44 return;
45 }
46
47 if (!isset($opening_sound->source))
48 {
49 return;
50 }
51
52 $source = $opening_sound->source;
53
54 if ($source == 'none')
55 {
56 return;
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
67 /**
68 * Returns the action script
69 *
70 * @param object $box
71 *
72 * @return string
73 */
74 protected function get_action_script($box)
75 {
76 $file = $this->get_file($box);
77
78 return 'let audio = new Audio(\'' . $file . '\'); audio.pause(); audio.currentTime = 0; me.on("open", function(evt) { audio.play(); });';
79 }
80
81 /**
82 * Returns the sound file
83 *
84 * @param object $box
85 *
86 * @return string
87 */
88 private function get_file($box)
89 {
90 $opening_sound = $box->params->get('opening_sound');
91 $source = $opening_sound->source;
92
93 // local audio file
94 $file = FBOX_MEDIA_ADMIN_URL . 'sounds/' . $source . '.mp3';
95
96 // audio comes from a custom file
97 if ($source == 'custom_file' && isset($opening_sound->file) && !empty($opening_sound->file))
98 {
99 $file = $opening_sound->file;
100 }
101 // audio comes from a custom URL
102 else if ($source == 'custom_url' && isset($opening_sound->url) && !empty($opening_sound->url))
103 {
104 $file = $opening_sound->url;
105 }
106
107 return $file;
108 }
109
110 /**
111 * Get all available sounds.
112 *
113 * @return array
114 */
115 public static function get()
116 {
117 $files = \array_diff(\scandir(FBOX_PLUGIN_DIR . '/media/admin/sounds'), ['.', '..', 'index.php']);
118
119 foreach ($files as $sound)
120 {
121 $sound_clean = pathinfo($sound, PATHINFO_FILENAME);
122 $sound_label = ucwords(str_replace('-', ' ', $sound_clean));
123 $sounds[$sound_clean] = $sound_label;
124 }
125
126 return $sounds;
127 }
128 }