| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.1.102 |
| 5 |
* |
| 6 |
* @author FirePlugins <info@fireplugins.com> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2024 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Helpers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
class HTML |
| 20 |
{ |
| 21 |
/** |
| 22 |
* Generates a Pro button |
| 23 |
* |
| 24 |
* @param string $label |
| 25 |
* @param string $feature_label |
| 26 |
* @param string $plugin |
| 27 |
* |
| 28 |
* @return string |
| 29 |
*/ |
| 30 |
public static function renderProButton($label = '', $feature_label = '', $plugin = '') |
| 31 |
{ |
| 32 |
if (!is_string($label) && !is_string($feature_label)) |
| 33 |
{ |
| 34 |
return; |
| 35 |
} |
| 36 |
|
| 37 |
$class = '\FPFramework\Base\Fields\Pro'; |
| 38 |
|
| 39 |
$options = [ |
| 40 |
'type' => 'Pro', |
| 41 |
'plugin' => $plugin, |
| 42 |
'label' => $label, |
| 43 |
'feature_label' => $feature_label, |
| 44 |
'render_group' => false |
| 45 |
]; |
| 46 |
|
| 47 |
$field = new $class($options); |
| 48 |
|
| 49 |
ob_start(); |
| 50 |
$field->render(); |
| 51 |
$html = ob_get_contents(); |
| 52 |
ob_end_clean(); |
| 53 |
|
| 54 |
return $html; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Generates a FPToggle input |
| 59 |
* |
| 60 |
* @param string $atts |
| 61 |
* |
| 62 |
* @return string |
| 63 |
*/ |
| 64 |
public static function renderFPToggle($atts) |
| 65 |
{ |
| 66 |
if (!$atts && !is_array($atts)) |
| 67 |
{ |
| 68 |
return; |
| 69 |
} |
| 70 |
|
| 71 |
$class = '\FPFramework\Base\Fields\FPToggle'; |
| 72 |
|
| 73 |
$options = [ |
| 74 |
'type' => 'FPToggle', |
| 75 |
'render_group' => false |
| 76 |
]; |
| 77 |
|
| 78 |
$options = array_merge($options, $atts); |
| 79 |
|
| 80 |
$field = new $class($options); |
| 81 |
|
| 82 |
ob_start(); |
| 83 |
$field->render(); |
| 84 |
$html = ob_get_contents(); |
| 85 |
ob_end_clean(); |
| 86 |
|
| 87 |
return $html; |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Renders a heading |
| 92 |
* |
| 93 |
* @param array $atts |
| 94 |
* |
| 95 |
* @return string |
| 96 |
*/ |
| 97 |
public static function renderHeading($atts) |
| 98 |
{ |
| 99 |
if (!$atts && !is_array($atts)) |
| 100 |
{ |
| 101 |
return; |
| 102 |
} |
| 103 |
|
| 104 |
$class = '\FPFramework\Base\Fields\Heading'; |
| 105 |
|
| 106 |
$options = [ |
| 107 |
'type' => 'Heading', |
| 108 |
'render_group' => false |
| 109 |
]; |
| 110 |
|
| 111 |
$options = array_merge($options, $atts); |
| 112 |
|
| 113 |
$field = new $class($options); |
| 114 |
|
| 115 |
ob_start(); |
| 116 |
$field->render(); |
| 117 |
$html = ob_get_contents(); |
| 118 |
ob_end_clean(); |
| 119 |
|
| 120 |
return $html; |
| 121 |
} |
| 122 |
|
| 123 |
/** |
| 124 |
* Renders the opening of a div |
| 125 |
* |
| 126 |
* @param array $atts |
| 127 |
* |
| 128 |
* @return string |
| 129 |
*/ |
| 130 |
public static function renderStartDiv($atts) |
| 131 |
{ |
| 132 |
if (!$atts && !is_array($atts)) |
| 133 |
{ |
| 134 |
return; |
| 135 |
} |
| 136 |
|
| 137 |
$class = '\\FPFramework\\Base\\Fields\\CustomDiv'; |
| 138 |
|
| 139 |
$options = ['type' => 'CustomDiv']; |
| 140 |
$options = array_merge($options, $atts); |
| 141 |
|
| 142 |
$field = new $class($options); |
| 143 |
|
| 144 |
ob_start(); |
| 145 |
$field->render(); |
| 146 |
$html = ob_get_contents(); |
| 147 |
ob_end_clean(); |
| 148 |
|
| 149 |
return $html; |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Renders the closing of a div |
| 154 |
* |
| 155 |
* @return string |
| 156 |
*/ |
| 157 |
public static function renderEndDiv() |
| 158 |
{ |
| 159 |
$class = '\\FPFramework\\Base\\Fields\\CustomDiv'; |
| 160 |
|
| 161 |
$options = [ |
| 162 |
'type' => 'CustomDiv', |
| 163 |
'position' => 'end' |
| 164 |
]; |
| 165 |
|
| 166 |
$field = new $class($options); |
| 167 |
|
| 168 |
ob_start(); |
| 169 |
$field->render(); |
| 170 |
$html = ob_get_contents(); |
| 171 |
ob_end_clean(); |
| 172 |
|
| 173 |
return $html; |
| 174 |
} |
| 175 |
|
| 176 |
/** |
| 177 |
* Renders an image of the pro feature with an Upgrade to Pro button. |
| 178 |
* |
| 179 |
* @param array $atts |
| 180 |
* |
| 181 |
* @return string |
| 182 |
*/ |
| 183 |
public static function renderImageProFeature($atts = []) |
| 184 |
{ |
| 185 |
if (!$atts) |
| 186 |
{ |
| 187 |
return; |
| 188 |
} |
| 189 |
|
| 190 |
fpframework()->renderer->upgrades->render('pro_image', $atts); |
| 191 |
} |
| 192 |
|
| 193 |
/** |
| 194 |
* Renders a modal. |
| 195 |
* |
| 196 |
* @param array $payload |
| 197 |
* @param boolean $return |
| 198 |
* |
| 199 |
* @return mixed |
| 200 |
*/ |
| 201 |
public static function renderModal($payload = [], $return = false) |
| 202 |
{ |
| 203 |
if (!$payload && !is_array($payload)) |
| 204 |
{ |
| 205 |
return; |
| 206 |
} |
| 207 |
|
| 208 |
if (!is_bool($return)) |
| 209 |
{ |
| 210 |
return; |
| 211 |
} |
| 212 |
|
| 213 |
// JS |
| 214 |
wp_register_script( |
| 215 |
'fpframework-modal', |
| 216 |
FPF_MEDIA_URL . 'admin/js/fpf_modal.js', |
| 217 |
[], |
| 218 |
FPF_VERSION, |
| 219 |
true |
| 220 |
); |
| 221 |
wp_enqueue_script('fpframework-modal'); |
| 222 |
|
| 223 |
if ($return) |
| 224 |
{ |
| 225 |
return fpframework()->renderer->admin->render('modal', $payload, $return); |
| 226 |
} |
| 227 |
|
| 228 |
fpframework()->renderer->admin->render('modal', $payload); |
| 229 |
} |
| 230 |
|
| 231 |
/** |
| 232 |
* Render the conditions list. |
| 233 |
* |
| 234 |
* @param array $opts |
| 235 |
* |
| 236 |
* @return string |
| 237 |
*/ |
| 238 |
public static function renderConditions($opts = []) |
| 239 |
{ |
| 240 |
$class = '\FPFramework\Base\Fields\Conditions'; |
| 241 |
|
| 242 |
$options = [ |
| 243 |
'type' => 'SearchDropdown', |
| 244 |
'path' => '\FPFramework\Helpers\ConditionsHelper', |
| 245 |
'render_group' => false |
| 246 |
]; |
| 247 |
$options = array_merge($options, $opts); |
| 248 |
$field = new $class($options); |
| 249 |
|
| 250 |
ob_start(); |
| 251 |
$field->render(); |
| 252 |
$html = ob_get_contents(); |
| 253 |
ob_end_clean(); |
| 254 |
|
| 255 |
return $html; |
| 256 |
} |
| 257 |
} |