| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Registerer; |
| 4 |
|
| 5 |
use FluentForm\App\Helpers\Helper; |
| 6 |
use FluentForm\App\Modules\Activator; |
| 7 |
use FluentForm\App\Modules\AddOnModule; |
| 8 |
use FluentForm\App\Modules\DocumentationModule; |
| 9 |
use FluentForm\Framework\Foundation\Application; |
| 10 |
use FluentForm\View; |
| 11 |
|
| 12 |
class Menu |
| 13 |
{ |
| 14 |
/** |
| 15 |
* @var \FluentForm\Framework\Foundation\Application |
| 16 |
*/ |
| 17 |
protected $app; |
| 18 |
|
| 19 |
/** |
| 20 |
* Menu constructor. |
| 21 |
* |
| 22 |
* @param \FluentForm\Framework\Foundation\Application $application |
| 23 |
*/ |
| 24 |
public function __construct(Application $application) |
| 25 |
{ |
| 26 |
$this->app = $application; |
| 27 |
|
| 28 |
$this->app->addFilter('fluentform_form_settings_menu', array( |
| 29 |
$this, 'filterFormSettingsMenu' |
| 30 |
), 10, 2); |
| 31 |
} |
| 32 |
|
| 33 |
public function reisterScripts() |
| 34 |
{ |
| 35 |
if (!$this->isFluentPages()) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
$app = $this->app; |
| 40 |
|
| 41 |
wp_register_style( |
| 42 |
'fluentform_settings_global', |
| 43 |
$app->publicUrl("css/settings_global.css"), |
| 44 |
array(), |
| 45 |
FLUENTFORM_VERSION, |
| 46 |
'all' |
| 47 |
); |
| 48 |
|
| 49 |
wp_register_script( |
| 50 |
'clipboard', |
| 51 |
$app->publicUrl('libs/clipboard.min.js'), |
| 52 |
array(), |
| 53 |
false, |
| 54 |
true |
| 55 |
); |
| 56 |
|
| 57 |
wp_register_script( |
| 58 |
'copier', |
| 59 |
$app->publicUrl('js/copier.js'), |
| 60 |
array(), |
| 61 |
false, |
| 62 |
true |
| 63 |
); |
| 64 |
|
| 65 |
wp_register_script( |
| 66 |
'fluentform_form_settings', |
| 67 |
$app->publicUrl("js/form_settings_app.js"), |
| 68 |
array('jquery'), |
| 69 |
FLUENTFORM_VERSION, |
| 70 |
true |
| 71 |
); |
| 72 |
|
| 73 |
wp_register_script( |
| 74 |
'fluent_all_forms', |
| 75 |
$app->publicUrl("js/fluent-all-forms-admin.js"), |
| 76 |
array('jquery'), |
| 77 |
FLUENTFORM_VERSION, |
| 78 |
true |
| 79 |
); |
| 80 |
|
| 81 |
wp_register_style( |
| 82 |
'fluent_all_forms', |
| 83 |
$app->publicUrl("css/fluent-all-forms.css"), |
| 84 |
array(), |
| 85 |
FLUENTFORM_VERSION, |
| 86 |
'all' |
| 87 |
); |
| 88 |
|
| 89 |
wp_register_script( |
| 90 |
'fluentform_editor_script', |
| 91 |
$app->publicUrl("js/fluent-forms-editor.js"), |
| 92 |
array('jquery'), |
| 93 |
FLUENTFORM_VERSION, |
| 94 |
true |
| 95 |
); |
| 96 |
|
| 97 |
wp_register_style( |
| 98 |
'fluentform_editor_style', |
| 99 |
$app->publicUrl("css/fluent-forms-admin-sass.css"), |
| 100 |
[], |
| 101 |
FLUENTFORM_VERSION, |
| 102 |
'all' |
| 103 |
); |
| 104 |
|
| 105 |
wp_register_style( |
| 106 |
'fluentform_editor_sass', |
| 107 |
$app->publicUrl("css/fluent-forms-admin.css"), |
| 108 |
[], |
| 109 |
FLUENTFORM_VERSION, |
| 110 |
'all' |
| 111 |
); |
| 112 |
|
| 113 |
wp_register_script( |
| 114 |
'fluentform-transfer-js', |
| 115 |
$app->publicUrl("js/fluentform-transfer.js"), |
| 116 |
['jquery'], |
| 117 |
FLUENTFORM_VERSION, |
| 118 |
true |
| 119 |
); |
| 120 |
|
| 121 |
wp_register_script( |
| 122 |
'fluentform-global-settings-js', |
| 123 |
$app->publicUrl("js/fluentform-global-settings.js"), |
| 124 |
['jquery'], |
| 125 |
FLUENTFORM_VERSION, |
| 126 |
true |
| 127 |
); |
| 128 |
|
| 129 |
wp_register_script( |
| 130 |
'fluentform-modules', |
| 131 |
$app->publicUrl('js/modules.js'), |
| 132 |
['jquery'], |
| 133 |
FLUENTFORM_VERSION, |
| 134 |
true |
| 135 |
); |
| 136 |
|
| 137 |
wp_register_script( |
| 138 |
'fluentform_form_entries', |
| 139 |
$app->publicUrl('js/form_entries.js'), |
| 140 |
array('jquery'), |
| 141 |
FLUENTFORM_VERSION, |
| 142 |
true |
| 143 |
); |
| 144 |
|
| 145 |
wp_register_script( |
| 146 |
'fluentform_all_entries', |
| 147 |
$app->publicUrl('js/all_entries.js'), |
| 148 |
array('jquery'), |
| 149 |
FLUENTFORM_VERSION, |
| 150 |
true |
| 151 |
); |
| 152 |
|
| 153 |
wp_register_style( |
| 154 |
'fluentform-add-ons', |
| 155 |
$app->publicUrl('css/add-ons.css'), |
| 156 |
[], |
| 157 |
FLUENTFORM_VERSION, |
| 158 |
'all' |
| 159 |
); |
| 160 |
|
| 161 |
wp_register_style( |
| 162 |
'fluentform_doc_style', |
| 163 |
$app->publicUrl('css/admin_docs.css'), |
| 164 |
[], |
| 165 |
FLUENTFORM_VERSION, |
| 166 |
'all' |
| 167 |
); |
| 168 |
|
| 169 |
} |
| 170 |
|
| 171 |
public function isFluentPages() |
| 172 |
{ |
| 173 |
return Helper::isFluentAdminPage(); |
| 174 |
} |
| 175 |
|
| 176 |
public function enqueuePageScripts() |
| 177 |
{ |
| 178 |
if (!$this->isFluentPages()) { |
| 179 |
return; |
| 180 |
} |
| 181 |
|
| 182 |
$page = sanitize_text_field($_GET['page']); |
| 183 |
|
| 184 |
if ($page == 'fluent_forms' && isset($_GET['route']) && isset($_GET['form_id'])) { |
| 185 |
wp_enqueue_style('fluentform_settings_global'); |
| 186 |
wp_enqueue_script('clipboard'); |
| 187 |
wp_enqueue_script('copier'); |
| 188 |
|
| 189 |
if ($_GET['route'] == 'settings') { |
| 190 |
if (function_exists('wp_enqueue_editor')) { |
| 191 |
add_filter('user_can_richedit', function ($status) { |
| 192 |
return true; |
| 193 |
}); |
| 194 |
|
| 195 |
wp_enqueue_editor(); |
| 196 |
wp_enqueue_media(); |
| 197 |
} |
| 198 |
|
| 199 |
wp_enqueue_script('fluentform_form_settings'); |
| 200 |
|
| 201 |
} else if ($_GET['route'] == 'editor') { |
| 202 |
$this->enqueueEditorAssets(); |
| 203 |
} |
| 204 |
} else if ($page == 'fluent_forms') { |
| 205 |
wp_enqueue_script('fluent_all_forms'); |
| 206 |
wp_enqueue_style('fluent_all_forms'); |
| 207 |
} else if ($page == 'fluent_forms_transfer') { |
| 208 |
wp_enqueue_style('fluentform_settings_global'); |
| 209 |
wp_enqueue_script('fluentform-transfer-js'); |
| 210 |
} else if ( |
| 211 |
$page == 'fluent_forms_settings' || |
| 212 |
$page == 'fluent_form_payment_entries' || |
| 213 |
$page == 'fluent_forms_all_entries' |
| 214 |
) { |
| 215 |
wp_enqueue_style('fluentform_settings_global'); |
| 216 |
} else if ($page == 'fluent_form_add_ons') { |
| 217 |
wp_enqueue_style('fluentform-add-ons'); |
| 218 |
} else if ($page == 'fluent_forms_docs') { |
| 219 |
wp_enqueue_style('fluentform_doc_style'); |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
/** |
| 224 |
* Register menu and sub-menus. |
| 225 |
*/ |
| 226 |
public function register() |
| 227 |
{ |
| 228 |
$dashBoardCapability = apply_filters( |
| 229 |
'fluentform_dashboard_capability', 'fluentform_settings_manager' |
| 230 |
); |
| 231 |
|
| 232 |
$settingsCapability = apply_filters( |
| 233 |
'fluentform_settings_capability', 'fluentform_settings_manager' |
| 234 |
); |
| 235 |
|
| 236 |
if (!current_user_can($dashBoardCapability) && !current_user_can($settingsCapability)) { |
| 237 |
$customRoles = get_option('_fluentform_form_permission'); |
| 238 |
|
| 239 |
if (is_string($customRoles)) { |
| 240 |
$customRoles = []; |
| 241 |
} |
| 242 |
|
| 243 |
if (!$customRoles) { |
| 244 |
return; |
| 245 |
} |
| 246 |
|
| 247 |
$hasAccess = false; |
| 248 |
foreach ($customRoles as $roleName) { |
| 249 |
if (current_user_can($roleName)) { |
| 250 |
$hasAccess = true; |
| 251 |
$dashBoardCapability = $roleName; |
| 252 |
$settingsCapability = $roleName; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
if (!$hasAccess) { |
| 257 |
return; |
| 258 |
} |
| 259 |
} |
| 260 |
|
| 261 |
if (defined('FLUENTFORMPRO')) { |
| 262 |
$title = __('Fluent Forms Pro', 'fluentform'); |
| 263 |
} else { |
| 264 |
$title = __('Fluent Forms', 'fluentform'); |
| 265 |
} |
| 266 |
|
| 267 |
add_menu_page( |
| 268 |
$title, |
| 269 |
$title, |
| 270 |
$dashBoardCapability, |
| 271 |
'fluent_forms', |
| 272 |
array($this, 'renderFormAdminRoute'), |
| 273 |
$this->getMenuIcon(), |
| 274 |
25 |
| 275 |
); |
| 276 |
|
| 277 |
|
| 278 |
add_submenu_page( |
| 279 |
'fluent_forms', |
| 280 |
__('All Forms', 'fluentform'), |
| 281 |
__('All Forms', 'fluentform'), |
| 282 |
$dashBoardCapability, |
| 283 |
'fluent_forms', |
| 284 |
array($this, 'renderFormAdminRoute') |
| 285 |
); |
| 286 |
|
| 287 |
if ($settingsCapability) { |
| 288 |
add_submenu_page( |
| 289 |
'fluent_forms', |
| 290 |
__('New Form', 'fluentform'), |
| 291 |
__('New Form', 'fluentform'), |
| 292 |
$settingsCapability, |
| 293 |
'fluent_forms#add=1', |
| 294 |
array($this, 'renderFormAdminRoute') |
| 295 |
); |
| 296 |
|
| 297 |
// Register entries intermediary page |
| 298 |
add_submenu_page( |
| 299 |
'fluent_forms', |
| 300 |
__('Entries', 'fluentform'), |
| 301 |
__('Entries', 'fluentform'), |
| 302 |
$settingsCapability, |
| 303 |
'fluent_forms_all_entries', |
| 304 |
array($this, 'renderAllEntriesAdminRoute') |
| 305 |
); |
| 306 |
|
| 307 |
if (apply_filters('fluentform_show_payment_entries', false)) { |
| 308 |
add_submenu_page( |
| 309 |
'fluent_forms', |
| 310 |
__('Payments', 'fluentform'), |
| 311 |
__('Payments', 'fluentform'), |
| 312 |
$settingsCapability, |
| 313 |
'fluent_form_payment_entries', |
| 314 |
array($this, 'renderPaymentEntries') |
| 315 |
); |
| 316 |
} |
| 317 |
|
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
// Register Add-Ons |
| 322 |
add_submenu_page( |
| 323 |
'fluent_forms', |
| 324 |
__('Modules', 'fluentform'), |
| 325 |
__('Modules', 'fluentform'), |
| 326 |
$dashBoardCapability, |
| 327 |
'fluent_form_add_ons', |
| 328 |
array($this, 'renderAddOns') |
| 329 |
); |
| 330 |
|
| 331 |
if ($settingsCapability) { |
| 332 |
// Register global settings sub menu page. |
| 333 |
add_submenu_page( |
| 334 |
'fluent_forms', |
| 335 |
__('Settings', 'fluentform'), |
| 336 |
__('Settings', 'fluentform'), |
| 337 |
$settingsCapability, |
| 338 |
'fluent_forms_settings', |
| 339 |
array($this, 'renderGlobalSettings') |
| 340 |
); |
| 341 |
|
| 342 |
// Register import/export sub menu page. |
| 343 |
add_submenu_page( |
| 344 |
'fluent_forms', |
| 345 |
__('Tools', 'fluentform'), |
| 346 |
__('Tools', 'fluentform'), |
| 347 |
$settingsCapability, |
| 348 |
'fluent_forms_transfer', |
| 349 |
array($this, 'renderTransfer') |
| 350 |
); |
| 351 |
} |
| 352 |
|
| 353 |
|
| 354 |
// Register Documentation |
| 355 |
add_submenu_page( |
| 356 |
'fluent_forms', |
| 357 |
__('Get Help', 'fluentform'), |
| 358 |
__('Get Help', 'fluentform'), |
| 359 |
$dashBoardCapability, |
| 360 |
'fluent_forms_docs', |
| 361 |
array($this, 'renderDocs') |
| 362 |
); |
| 363 |
|
| 364 |
$this->commonAction(); |
| 365 |
|
| 366 |
} |
| 367 |
|
| 368 |
private function getMenuIcon() |
| 369 |
{ |
| 370 |
return 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20"><defs><style>.cls-1{fill:#fff;}</style></defs><title>dashboard_icon</title><g id="Layer_2" data-name="Layer 2"><g id="Layer_1-2" data-name="Layer 1"><path class="cls-1" d="M15.57,0H4.43A4.43,4.43,0,0,0,0,4.43V15.57A4.43,4.43,0,0,0,4.43,20H15.57A4.43,4.43,0,0,0,20,15.57V4.43A4.43,4.43,0,0,0,15.57,0ZM12.82,14a2.36,2.36,0,0,1-1.66.68H6.5A2.31,2.31,0,0,1,7.18,13a2.36,2.36,0,0,1,1.66-.68l4.66,0A2.34,2.34,0,0,1,12.82,14Zm3.3-3.46a2.36,2.36,0,0,1-1.66.68H3.21a2.25,2.25,0,0,1,.68-1.64,2.36,2.36,0,0,1,1.66-.68H16.79A2.25,2.25,0,0,1,16.12,10.53Zm0-3.73a2.36,2.36,0,0,1-1.66.68H3.21a2.25,2.25,0,0,1,.68-1.64,2.36,2.36,0,0,1,1.66-.68H16.79A2.25,2.25,0,0,1,16.12,6.81Z"/></g></g></svg>'); |
| 371 |
} |
| 372 |
|
| 373 |
public function renderFormAdminRoute() |
| 374 |
{ |
| 375 |
if (isset($_GET['route']) && isset($_GET['form_id'])) { |
| 376 |
return $this->renderFormInnerPages(); |
| 377 |
} |
| 378 |
|
| 379 |
$this->renderForms(); |
| 380 |
} |
| 381 |
|
| 382 |
public function renderAllEntriesAdminRoute() |
| 383 |
{ |
| 384 |
wp_enqueue_script('fluentform_all_entries'); |
| 385 |
View::render('admin.all_entries', array()); |
| 386 |
} |
| 387 |
|
| 388 |
private function renderFormInnerPages() |
| 389 |
{ |
| 390 |
$form_id = intval($_GET['form_id']); |
| 391 |
|
| 392 |
$form = wpFluent()->table('fluentform_forms')->find($form_id); |
| 393 |
|
| 394 |
$formAdminMenus = array( |
| 395 |
'editor' => array( |
| 396 |
'slug' => 'editor', |
| 397 |
'title' => __('Editor', 'fluentform'), |
| 398 |
'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=editor') |
| 399 |
), |
| 400 |
'settings' => array( |
| 401 |
'slug' => 'settings', |
| 402 |
'hash' => 'basic_settings', |
| 403 |
'title' => __('Settings & Integrations', 'fluentform'), |
| 404 |
'sub_route' => 'form_settings', |
| 405 |
'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=settings&sub_route=form_settings') |
| 406 |
), |
| 407 |
'entries' => array( |
| 408 |
'slug' => 'entries', |
| 409 |
'hash' => '/', |
| 410 |
'title' => __('Entries', 'fluentform'), |
| 411 |
'url' => admin_url('admin.php?page=fluent_forms&form_id=' . $form_id . '&route=entries') |
| 412 |
) |
| 413 |
); |
| 414 |
|
| 415 |
$formAdminMenus = apply_filters('fluentform_form_admin_menu', $formAdminMenus, $form_id, $form); |
| 416 |
|
| 417 |
$form = wpFluent()->table('fluentform_forms')->find($form_id); |
| 418 |
|
| 419 |
if (!$form) { |
| 420 |
echo __("<h2>No form found</h2>", 'fluentform'); |
| 421 |
return; |
| 422 |
} |
| 423 |
|
| 424 |
View::render('admin.form.form_wrapper', array( |
| 425 |
'route' => sanitize_text_field($_GET['route']), |
| 426 |
'form_id' => $form_id, |
| 427 |
'form' => $form, |
| 428 |
'menu_items' => $formAdminMenus |
| 429 |
)); |
| 430 |
} |
| 431 |
|
| 432 |
public function renderSettings($form_id) |
| 433 |
{ |
| 434 |
$settingsMenus = array( |
| 435 |
'form_settings' => array( |
| 436 |
'title' => __('Form Settings', 'fluentform'), |
| 437 |
'slug' => 'form_settings', |
| 438 |
'hash' => 'basic_settings', |
| 439 |
'route' => '/' |
| 440 |
), |
| 441 |
'email_notifications' => array( |
| 442 |
'title' => __('Email Notifications', 'fluentform'), |
| 443 |
'slug' => 'form_settings', |
| 444 |
'hash' => 'email_notifications', |
| 445 |
'route' => '/email-settings' |
| 446 |
), |
| 447 |
'other_confirmations' => array( |
| 448 |
'title' => __('Other Confirmations', 'fluentform'), |
| 449 |
'slug' => 'form_settings', |
| 450 |
'hash' => 'other_confirmations', |
| 451 |
'route' => '/other-confirmations' |
| 452 |
), |
| 453 |
'all_integrations' => array( |
| 454 |
'title' => __('Marketing & CRM Integrations', 'fluentform'), |
| 455 |
'slug' => 'form_settings', |
| 456 |
'route' => '/all-integrations' |
| 457 |
) |
| 458 |
); |
| 459 |
|
| 460 |
if (Helper::isSlackEnabled()) { |
| 461 |
$settingsMenus['slack'] = array( |
| 462 |
'title' => __('Slack', 'fluentform'), |
| 463 |
'slug' => 'form_settings', |
| 464 |
'hash' => 'slack', |
| 465 |
'route' => '/slack' |
| 466 |
); |
| 467 |
} |
| 468 |
|
| 469 |
$settingsMenus = apply_filters('fluentform_form_settings_menu', $settingsMenus, $form_id); |
| 470 |
|
| 471 |
$externalMenuItems = []; |
| 472 |
foreach ($settingsMenus as $key => $menu) { |
| 473 |
if (empty($menu['hash'])) { |
| 474 |
unset($settingsMenus[$key]); |
| 475 |
$externalMenuItems[$key] = $menu; |
| 476 |
} |
| 477 |
} |
| 478 |
|
| 479 |
$settingsMenus['custom_css_js'] = array( |
| 480 |
'title' => __('Custom CSS/JS', 'fluentform'), |
| 481 |
'slug' => 'form_settings', |
| 482 |
'hash' => 'custom_css_js', |
| 483 |
'route' => '/custom-css-js' |
| 484 |
); |
| 485 |
|
| 486 |
$settingsMenus = array_filter(array_merge($settingsMenus, $externalMenuItems)); |
| 487 |
|
| 488 |
$currentRoute = sanitize_text_field($this->app->request->get('sub_route', '')); |
| 489 |
|
| 490 |
View::render('admin.form.settings_wrapper', array( |
| 491 |
'form_id' => $form_id, |
| 492 |
'settings_menus' => $settingsMenus, |
| 493 |
'current_sub_route' => $currentRoute |
| 494 |
)); |
| 495 |
} |
| 496 |
|
| 497 |
/** |
| 498 |
* Remove the inactive addOn menu items |
| 499 |
* @param string $addOn |
| 500 |
* @return boolean |
| 501 |
*/ |
| 502 |
public function filterFormSettingsMenu($settingsMenus, $form_id) |
| 503 |
{ |
| 504 |
if (array_key_exists('mailchimp_integration', $settingsMenus)) { |
| 505 |
$option = (array)get_option('_fluentform_mailchimp_details'); |
| 506 |
if (!isset($option['status']) || !$option['status']) { |
| 507 |
unset($settingsMenus['mailchimp_integration']); |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
return $settingsMenus; |
| 512 |
} |
| 513 |
|
| 514 |
public function renderFormSettings($form_id) |
| 515 |
{ |
| 516 |
wp_localize_script('fluentform_form_settings', 'FluentFormApp', array( |
| 517 |
'form_id' => $form_id, |
| 518 |
'plugin' => $this->app->getSlug(), |
| 519 |
'hasPro' => defined('FLUENTFORMPRO'), |
| 520 |
'hasPDF' => defined('FLUENTFORM_PDF_VERSION'), |
| 521 |
'ace_path_url' => $this->app->publicUrl('libs/ace') |
| 522 |
)); |
| 523 |
|
| 524 |
View::render('admin.form.settings', array( |
| 525 |
'form_id' => $form_id |
| 526 |
)); |
| 527 |
} |
| 528 |
|
| 529 |
public function renderForms() |
| 530 |
{ |
| 531 |
if (!get_option('_fluentform_installed_version')) { |
| 532 |
(new Activator())->migrate(); |
| 533 |
} |
| 534 |
|
| 535 |
$formsCount = wpFluent()->table('fluentform_forms')->count(); |
| 536 |
|
| 537 |
wp_localize_script('fluent_all_forms', 'FluentFormApp', apply_filters('fluent_all_forms_vars', array( |
| 538 |
'plugin' => $this->app->getSlug(), |
| 539 |
'formsCount' => $formsCount, |
| 540 |
'hasPro' => defined('FLUENTFORMPRO'), |
| 541 |
'adminUrl' => admin_url('admin.php?page=fluent_forms'), |
| 542 |
'isDisableAnalytics' => apply_filters('fluentform-disabled_analytics', false) |
| 543 |
))); |
| 544 |
|
| 545 |
View::render('admin.all_forms', array()); |
| 546 |
} |
| 547 |
|
| 548 |
public function renderEditor($form_id) |
| 549 |
{ |
| 550 |
View::render('admin.form.editor', array( |
| 551 |
'plugin' => $this->app->getSlug(), |
| 552 |
'form_id' => $form_id |
| 553 |
)); |
| 554 |
} |
| 555 |
|
| 556 |
public function renderDocs() |
| 557 |
{ |
| 558 |
echo (new DocumentationModule())->render(); |
| 559 |
} |
| 560 |
|
| 561 |
public function renderAddOns() |
| 562 |
{ |
| 563 |
echo (new AddOnModule())->render(); |
| 564 |
} |
| 565 |
|
| 566 |
private function enqueueEditorAssets() |
| 567 |
{ |
| 568 |
$formId = intval($_GET['form_id']); |
| 569 |
|
| 570 |
$form = wpFluent()->table('fluentform_forms')->find($formId); |
| 571 |
|
| 572 |
do_action('fluentform_loading_editor_assets', $form); |
| 573 |
|
| 574 |
wp_enqueue_style('fluentform_editor_sass'); |
| 575 |
wp_enqueue_style('fluentform_editor_style'); |
| 576 |
|
| 577 |
$pluginSlug = $this->app->getSlug(); |
| 578 |
|
| 579 |
if (function_exists('wp_enqueue_editor')) { |
| 580 |
add_filter('user_can_richedit', '__return_true'); |
| 581 |
wp_enqueue_editor(); |
| 582 |
wp_enqueue_media(); |
| 583 |
} |
| 584 |
|
| 585 |
wp_enqueue_script('fluentform_editor_script'); |
| 586 |
|
| 587 |
$jsonData = $form->form_fields; |
| 588 |
|
| 589 |
if (!defined('FLUENTFORM_DISABLE_EDITOR_FILED_HOOOK')) { |
| 590 |
$formFields = $form->form_fields; |
| 591 |
|
| 592 |
if ($formFields) { |
| 593 |
$formFields = json_decode($formFields, true); |
| 594 |
foreach ($formFields['fields'] as $index => $formField) { |
| 595 |
$formFields['fields'][$index] = apply_filters( |
| 596 |
'fluentform_editor_init_element_' . $formField['element'], $formField, $form |
| 597 |
); |
| 598 |
|
| 599 |
if (!$formFields['fields'][$index]) { |
| 600 |
unset($formFields['fields'][$index]); |
| 601 |
continue; |
| 602 |
} |
| 603 |
|
| 604 |
if ($formField['element'] == 'container') { |
| 605 |
$columns = $formField['columns']; |
| 606 |
foreach ($columns as $columnIndex => $column) { |
| 607 |
foreach ($column['fields'] as $fieldIndex => $columnField) { |
| 608 |
$columns[$columnIndex]['fields'][$fieldIndex] = apply_filters( |
| 609 |
'fluentform_editor_init_element_' . $columnField['element'], |
| 610 |
$columnField, $form |
| 611 |
); |
| 612 |
|
| 613 |
if (!$columns[$columnIndex]['fields'][$fieldIndex]) { |
| 614 |
unset($columns[$columnIndex]['fields'][$fieldIndex]); |
| 615 |
} |
| 616 |
} |
| 617 |
} |
| 618 |
|
| 619 |
$formFields['fields'][$index]['columns'] = array_values($columns); |
| 620 |
} |
| 621 |
} |
| 622 |
|
| 623 |
$formFields['fields'] = array_values($formFields['fields']); |
| 624 |
$formFields = json_encode($formFields, true); |
| 625 |
} |
| 626 |
|
| 627 |
|
| 628 |
$form->form_fields = $formFields; |
| 629 |
} |
| 630 |
|
| 631 |
$searchTags = $this->app->load( |
| 632 |
$this->app->appPath('Services/FormBuilder/ElementSearchTags.php') |
| 633 |
); |
| 634 |
|
| 635 |
$searchTags = apply_filters( 'fluent_editor_element_search_tags', $searchTags, $form ); |
| 636 |
|
| 637 |
wp_localize_script('fluentform_editor_script', 'FluentFormApp', apply_filters('fluentform_editor_vars', array( |
| 638 |
'plugin' => $pluginSlug, |
| 639 |
'form_id' => $formId, |
| 640 |
'plugin_public_url' => $this->app->publicUrl(), |
| 641 |
'preview_url' => $this->getFormPreviewUrl($formId), |
| 642 |
'form' => $form, |
| 643 |
'hasPro' => defined('FLUENTFORMPRO'), |
| 644 |
'countries' => $this->app->load( |
| 645 |
$this->app->appPath('Services/FormBuilder/CountryNames.php') |
| 646 |
), |
| 647 |
'element_customization_settings' => $this->app->load( |
| 648 |
$this->app->appPath('Services/FormBuilder/ElementCustomization.php') |
| 649 |
), |
| 650 |
|
| 651 |
'validation_rule_settings' => $this->app->load( |
| 652 |
$this->app->appPath('Services/FormBuilder/ValidationRuleSettings.php') |
| 653 |
), |
| 654 |
|
| 655 |
'element_search_tags' => $searchTags, |
| 656 |
|
| 657 |
'element_settings_placement' => $this->app->load( |
| 658 |
$this->app->appPath('Services/FormBuilder/ElementSettingsPlacement.php') |
| 659 |
), |
| 660 |
'all_forms_url' => admin_url('admin.php?page=fluent_forms'), |
| 661 |
'has_payment_features' => !defined('FLUENTFORMPRO') |
| 662 |
))); |
| 663 |
} |
| 664 |
|
| 665 |
/** |
| 666 |
* Render global settings page. |
| 667 |
* |
| 668 |
* @throws \Exception |
| 669 |
*/ |
| 670 |
public function renderGlobalSettings() |
| 671 |
{ |
| 672 |
// Fire an event letting others know the current component |
| 673 |
// that fluentform is rendering for the global settings |
| 674 |
// page. So that they can hook and load their custom |
| 675 |
// components on this page dynamically & easily. |
| 676 |
// N.B. native 'components' will always use |
| 677 |
// 'settings' as their current component. |
| 678 |
$currentComponent = apply_filters('fluentform_global_settings_current_component', |
| 679 |
$this->app->request->get('component', 'settings') |
| 680 |
); |
| 681 |
|
| 682 |
$components = apply_filters('fluentform_global_settings_components', []); |
| 683 |
|
| 684 |
$components['reCAPTCHA'] = [ |
| 685 |
'hash' => 're_captcha', |
| 686 |
'title' => 'reCAPTCHA', |
| 687 |
]; |
| 688 |
|
| 689 |
View::render('admin.settings.index', [ |
| 690 |
'components' => $components, |
| 691 |
'currentComponent' => $currentComponent |
| 692 |
]); |
| 693 |
} |
| 694 |
|
| 695 |
public function renderTransfer() |
| 696 |
{ |
| 697 |
$forms = wpFluent()->table('fluentform_forms') |
| 698 |
->orderBy('id', 'desc') |
| 699 |
->select(['id', 'title']) |
| 700 |
->get(); |
| 701 |
|
| 702 |
wp_localize_script('fluentform-transfer-js', 'FluentFormApp', [ |
| 703 |
'plugin' => $this->app->getSlug(), |
| 704 |
'forms' => $forms, |
| 705 |
'hasPro' => defined('FLUENTFORMPRO'), |
| 706 |
]); |
| 707 |
|
| 708 |
View::render('admin.transfer.index'); |
| 709 |
} |
| 710 |
|
| 711 |
|
| 712 |
private function getFormPreviewUrl($form_id) |
| 713 |
{ |
| 714 |
return site_url('?fluentform_pages=1&design_mode=1&preview_id=' . $form_id) . '#ff_preview'; |
| 715 |
} |
| 716 |
|
| 717 |
public function addPreviewButton($formId) |
| 718 |
{ |
| 719 |
echo '<a target="_blank" class="el-button el-button--small" href="' . $this->getFormPreviewUrl($formId) . '">Preview & Design</a>'; |
| 720 |
} |
| 721 |
|
| 722 |
public function addCopyShortcodeButton($formId) |
| 723 |
{ |
| 724 |
echo '<button style="background:#dedede;color:#545454;padding:5px;" title="Click to Copy" class="btn copy" data-clipboard-text=\'[fluentform id="' . $formId . '"]\'><i class="dashicons dashicons-admin-page" style="color:#eee;text-shadow:#000 -1px 1px 1px;"></i> [fluentform id="' . $formId . '"]</button>'; |
| 725 |
return; |
| 726 |
} |
| 727 |
|
| 728 |
public function commonAction() |
| 729 |
{ |
| 730 |
$fluentFormPages = array( |
| 731 |
'fluent_forms', |
| 732 |
'fluent_forms_transfer', |
| 733 |
'fluent_forms_settings', |
| 734 |
'fluent_form_add_ons', |
| 735 |
'fluent_forms_docs' |
| 736 |
); |
| 737 |
|
| 738 |
if (isset($_GET['page']) && in_array($_GET['page'], $fluentFormPages)) { |
| 739 |
// Let's deregister existing vuejs by other devs |
| 740 |
// Other devs should not regis |
| 741 |
add_action('admin_print_scripts', function () { |
| 742 |
wp_dequeue_script('vuejs'); |
| 743 |
wp_dequeue_script('vue'); |
| 744 |
wp_deregister_script('elementor-admin-app'); |
| 745 |
}); |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
public function renderGlobalMenu() |
| 750 |
{ |
| 751 |
$showPayment = false; |
| 752 |
if(defined('FLUENTFORMPRO')) { |
| 753 |
$showPayment = !get_option('__fluentform_payment_module_settings'); |
| 754 |
if($showPayment) { |
| 755 |
$formCount = wpFluent()->table('fluentform_forms') |
| 756 |
->count(); |
| 757 |
$showPayment = $formCount > 2; |
| 758 |
} |
| 759 |
} |
| 760 |
View::render('admin.global_menu', array( |
| 761 |
'show_payment' => $showPayment, |
| 762 |
'show_payment_entries' => apply_filters('fluentform_show_payment_entries', false) |
| 763 |
)); |
| 764 |
} |
| 765 |
|
| 766 |
public function renderPaymentEntries() |
| 767 |
{ |
| 768 |
do_action('flunetform_render_payment_entries'); |
| 769 |
} |
| 770 |
} |
| 771 |
|