| 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 |
trait ActionsTrait |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Execute code block with a delay |
| 23 |
* |
| 24 |
* @param string $function |
| 25 |
* |
| 26 |
* @return string |
| 27 |
*/ |
| 28 |
protected function delayFunction($delay = 0, $function = '') |
| 29 |
{ |
| 30 |
if ($delay == 0) |
| 31 |
{ |
| 32 |
return $function; |
| 33 |
} |
| 34 |
|
| 35 |
return 'setTimeout(function() { ' . $function . ' }, ' . esc_attr($delay) . ');'; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* The script for the "Open a Box" action. It opens the specified the box. |
| 40 |
* |
| 41 |
* @return string |
| 42 |
*/ |
| 43 |
private function _OpenBox() |
| 44 |
{ |
| 45 |
return $this->delayFunction($this->item['delay'], 'FireBox.getInstance(' . $this->item['box'] . ').open();'); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* The script for the "Close a Box" action. It closes the specified the box. |
| 50 |
* |
| 51 |
* @return string |
| 52 |
*/ |
| 53 |
private function _CloseBox() |
| 54 |
{ |
| 55 |
return $this->delayFunction($this->item['delay'], 'FireBox.getInstance(' . $this->item['box'] . ').close();'); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* The script for the "Close all opened Boxes" action. It used the closeAll() static method to close all boxes. |
| 60 |
* |
| 61 |
* @return string |
| 62 |
*/ |
| 63 |
private function _CloseAll() |
| 64 |
{ |
| 65 |
return 'FireBox.closeAll();'; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* The script for the "Destroy Box" action. It destroys the box instance. |
| 70 |
* |
| 71 |
* @return string |
| 72 |
*/ |
| 73 |
private function _DestroyBox() |
| 74 |
{ |
| 75 |
return 'FireBox.getInstance(' . esc_attr($this->item['box']) . ').destroy();'; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* The script for the "Redirect to a URL" action. It redirects the visitor to a URL. |
| 80 |
* |
| 81 |
* @return string |
| 82 |
*/ |
| 83 |
private function _GoToURL() |
| 84 |
{ |
| 85 |
$target = isset($this->item['newtab']) && $this->item['newtab'] ? '_blank' : '_self'; |
| 86 |
return 'window.open("' . esc_url($this->item['url']) . '", "' . esc_attr($target) . '")'; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* The script for the "Reload Page" action. |
| 91 |
* |
| 92 |
* @return string |
| 93 |
*/ |
| 94 |
private function _ReloadPage() |
| 95 |
{ |
| 96 |
return 'location.reload();'; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* The script for the "Run Javascript" action. It executes the custom Javascript code specified by the administrator. |
| 101 |
* |
| 102 |
* @return string |
| 103 |
*/ |
| 104 |
private function _Custom() |
| 105 |
{ |
| 106 |
return $this->item['customcode']; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Protect code scope by wrapping it with an anonymous fuction |
| 111 |
* |
| 112 |
* @param string $string The code to anonymise |
| 113 |
* |
| 114 |
* @return string |
| 115 |
*/ |
| 116 |
protected function anonymise($string) |
| 117 |
{ |
| 118 |
// Keep the new line character inside return for code presentation purposes. |
| 119 |
return ' |
| 120 |
!(function() { ' . $string . ' })();'; |
| 121 |
} |
| 122 |
} |