| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FireBox |
| 4 |
* @version 2.1.14 Free |
| 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 FireBox\Core\Controllers; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use FPFramework\Base\Form; |
| 20 |
use FPFramework\Base\FieldsParser; |
| 21 |
use FPFramework\Base\Ui\Tabs; |
| 22 |
|
| 23 |
class BoxSettings extends BaseController |
| 24 |
{ |
| 25 |
/** |
| 26 |
* The form settings name |
| 27 |
* |
| 28 |
* @var string |
| 29 |
*/ |
| 30 |
const settings_name = 'firebox_settings'; |
| 31 |
|
| 32 |
/** |
| 33 |
* Render the page content |
| 34 |
* |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
public function render() |
| 38 |
{ |
| 39 |
// page content |
| 40 |
add_action('firebox/settings_page', [$this, 'settingsPageContent']); |
| 41 |
|
| 42 |
// render layout |
| 43 |
firebox()->renderer->admin->render('pages/settings'); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Load required media files |
| 48 |
* |
| 49 |
* @return void |
| 50 |
*/ |
| 51 |
public function addMedia() |
| 52 |
{ |
| 53 |
// load geoip js |
| 54 |
wp_register_script( |
| 55 |
'fpf-geoip', |
| 56 |
FPF_MEDIA_URL . 'admin/js/fpf_geoip.js', |
| 57 |
[], |
| 58 |
FPF_VERSION, |
| 59 |
false |
| 60 |
); |
| 61 |
wp_enqueue_script('fpf-geoip'); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Callback used to handle the processing of settings. |
| 66 |
* Useful when using a Repeater field to remove the template from the list of submitted items. |
| 67 |
* |
| 68 |
* @param array $input |
| 69 |
* |
| 70 |
* @return void |
| 71 |
*/ |
| 72 |
public function processBoxSettings($input) |
| 73 |
{ |
| 74 |
if (isset($_REQUEST['firebox_download_key_notice_activate'])) |
| 75 |
{ |
| 76 |
return $input; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
// Filters the fields value |
| 82 |
\FPFramework\Helpers\FormHelper::filterFields($input, \FireBox\Core\Admin\Forms\Settings::getSettings()); |
| 83 |
|
| 84 |
add_settings_error(self::settings_name, 'settings_updated', fpframework()->_('FPF_SETTINGS_SAVED'), 'success'); |
| 85 |
|
| 86 |
return $input; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
/** |
| 92 |
* What the settings page will contain |
| 93 |
* |
| 94 |
* @return void |
| 95 |
*/ |
| 96 |
public function settingsPageContent() |
| 97 |
{ |
| 98 |
$fieldsParser = new FieldsParser([ |
| 99 |
'fields_name_prefix' => 'firebox_settings' |
| 100 |
]); |
| 101 |
|
| 102 |
$settings = \FireBox\Core\Admin\Forms\Settings::getSettings(); |
| 103 |
foreach ($settings['data'] as $key => $value) |
| 104 |
{ |
| 105 |
ob_start(); |
| 106 |
$fieldsParser->renderContentFields($value); |
| 107 |
$html = ob_get_contents(); |
| 108 |
ob_end_clean(); |
| 109 |
|
| 110 |
$settings['data'][$key]['title'] = $value['title']; |
| 111 |
$settings['data'][$key]['content'] = $html; |
| 112 |
} |
| 113 |
|
| 114 |
// render settings as tabs |
| 115 |
$tabs = new Tabs($settings); |
| 116 |
|
| 117 |
// render form |
| 118 |
$form = new Form($tabs->render(), [ |
| 119 |
'section_name' => self::settings_name |
| 120 |
]); |
| 121 |
|
| 122 |
echo $form->render(); |
| 123 |
} |
| 124 |
} |