app = $application;
}
/**
* Register menu and sub-menus.
*/
public function register()
{
$dashBoardCapability = apply_filters('fluentform_dashboard_capability', 'fluentform_settings_manager');
add_menu_page(
__('Fluent Form', 'fluentform'),
__('Fluent Form', 'fluentform'),
$dashBoardCapability,
'fluent_forms',
array($this, 'renderFormAdminRoute'),
$this->getMenuIcon(),
25
);
add_submenu_page(
'fluent_forms',
__('All Forms', 'fluentform'),
__('All Forms', 'fluentform'),
$dashBoardCapability,
'fluent_forms',
array($this, 'renderFormAdminRoute')
);
add_submenu_page(
'fluent_forms',
__('New Form', 'fluentform'),
__('New Form', 'fluentform'),
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'),
'fluent_forms#add=1',
array($this, 'renderFormAdminRoute')
);
// Register entries intermediary page
add_submenu_page(
'fluent_forms',
__('Entries', 'fluentform'),
__('Entries', 'fluentform'),
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'),
'fluent_forms#entries',
array($this, 'renderFormAdminRoute')
);
// Register import/export sub menu page.
add_submenu_page(
'fluent_forms',
__('Export/Import', 'fluentform'),
__('Export/Import', 'fluentform'),
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'),
'fluent_forms_transfer',
array($this, 'renderTransfer')
);
// Register global settings sub menu page.
add_submenu_page(
'fluent_forms',
__('Settings', 'fluentform'),
__('Settings', 'fluentform'),
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'),
'fluent_forms_settings',
array($this, 'renderGlobalSettings')
);
// Register Documentation
add_submenu_page(
'fluent_forms',
__('Get Help', 'fluentform'),
__('Get Help', 'fluentform'),
$dashBoardCapability,
'fluent_forms_docs',
array($this, 'renderDocs')
);
}
private function getMenuIcon()
{
return 'data:image/svg+xml;base64,'.base64_encode('');
}
public function renderFormAdminRoute()
{
if (isset($_GET['route']) && isset($_GET['form_id'])) {
$version = $this->app->getVersion();
wp_enqueue_style('fluentform_settings_global', fluentformMix("css/settings_global.css"), array(), $version,
'all');
$form_id = intval($_GET['form_id']);
$formAdminMenus = array(
'editor' => array(
'slug' => 'editor',
'title' => __('Editor', 'fluentform')
),
'settings' => array(
'slug' => 'settings',
'hash' => 'basic_settings',
'title' => __('Settings', 'fluentform'),
'sub_route' => 'form_settings'
),
'entries' => array(
'slug' => 'entries',
'hash' => '/',
'title' => __('Entries', 'fluentform')
)
);
$formAdminMenus = apply_filters('fluentform_form_admin_menu', $formAdminMenus, $form_id);
$form = wpFluent()->table('fluentform_forms')->find($form_id);
if(!$form) {
echo __("
No form found
", 'fluentform');
die();
}
View::render('admin.form.form_wrapper', array(
'route' => sanitize_text_field($_GET['route']),
'form_id' => $form_id,
'form' => $form,
'menu_items' => $formAdminMenus
));
return;
}
$this->renderForms();
}
public function renderSettings($form_id)
{
$settingsMenus = array(
'form_settings' => array(
'title' => __('Form Settings', 'fluentform'),
'slug' => 'form_settings',
'hash' => 'basic_settings'
),
'email_notifications' => array(
'title' => __('Email Notifications', 'fluentform'),
'slug' => 'form_settings',
'hash' => 'email_notifications'
),
'mailchimp_integration' => array(
'title' => __('MailChimp', 'fluentform'),
'slug' => 'form_settings',
'hash' => 'mailchimp_integration'
),
'slack' => array(
'title' => __('Slack', 'fluentform'),
'slug' => 'form_settings',
'hash' => 'slack'
)
);
$settingsMenus = apply_filters('fluentform_form_settings_menu', $settingsMenus, $form_id);
$currentRoute = isset($_REQUEST['sub_route']) ? sanitize_text_field($_REQUEST['sub_route']) : '';
View::render('admin.form.settings_wrapper', array(
'form_id' => $form_id,
'settings_menus' => $settingsMenus,
'current_sub_route' => $currentRoute
));
}
public function renderFormSettings($form_id)
{
$version = $this->app->getVersion();
if (function_exists('wp_enqueue_editor')) {
wp_enqueue_editor();
}
wp_enqueue_script('fluentform_form_settings', fluentformMix("js/form_settings_app.js"), array('jquery'), $version,
false);
wp_localize_script('fluentform_form_settings', 'FluentFormApp', array(
'form_id' => $form_id,
'plugin' => $this->app->getSlug(),
'hasPro' => class_exists('FluentFormPro')
));
View::render('admin.form.settings', array(
'form_id' => $form_id
));
}
public function renderForms()
{
$version = $this->app->getVersion();
wp_enqueue_script('fluent_all_forms', fluentformMix("js/fluent-all-forms-admin.js"), array('jquery'), $version,
false);
wp_enqueue_style('fluent_all_forms', fluentformMix("css/fluent-all-forms.css"), array(), $version, 'all');
wp_localize_script('fluent_all_forms', 'FluentFormApp', array(
'plugin' => $this->app->getSlug(),
'adminUrl' => admin_url('admin.php?page=fluent_forms')
));
View::render('admin.all_forms', array());
}
public function renderEditor($form_id)
{
$this->enqueueEditorAssets();
echo View::make('admin.form.editor', array(
'plugin' => $this->app->getSlug(),
'form_id' => $form_id
));
}
public function renderDocs()
{
echo (new DocumentationModule())->render();
}
private function enqueueEditorAssets()
{
$pluginSlug = $this->app->getSlug();
$version = $this->app->getVersion();
wp_enqueue_script('fluentform_editor_script', fluentformMix("js/fluent-forms-editor.js"), ['jquery'], $version,
false);
wp_enqueue_style('fluentform_editor_style', fluentformMix("css/fluent-forms-admin-sass.css"), [], $version,
'all');
wp_enqueue_style('fluentform_editor_sass', fluentformMix("css/fluent-forms-admin.css"), [], $version, 'all');
$formId = intval($_GET['form_id']);
wp_localize_script('fluentform_editor_script', 'FluentFormApp', array(
'plugin' => $pluginSlug,
'form_id' => $formId,
'countries' => $countries = $this->app->load($this->app->appPath('Services/FormBuilder/CountryNames.php')),
'form' => wpFluent()->table('fluentform_forms')->find($formId),
'plugin_public_url' => $this->app->publicUrl(),
'preview_url' => $this->getFormPreviewUrl($formId)
));
}
/**
* Render global settings page.
*
* @throws \Exception
*/
public function renderGlobalSettings()
{
$version = $this->app->getVersion();
wp_enqueue_style(
'fluentform_settings_global',
fluentformMix("css/settings_global.css"),
[], $version, 'all'
);
// Fire an event letting others know the current component
// that fluentform is rendering for the global settings
// page. So that they can hook and load their custom
// components on this page dynamically & easily.
// N.B. native 'components' will always use
// 'settings' as their current component.
$currentComponent = apply_filters('fluentform_global_settings_current_component',
$this->app->request->get('component', 'settings')
);
$components = apply_filters('fluentform_global_settings_components', [
'reCpatcha' => [
'hash' => 're_captcha',
'title' => 'reCpatcha',
],
'mailchimp' => [
'hash' => 'mailchimp',
'title' => 'MailChimp',
]
]);
View::render('admin.settings.index', [
'components' => $components,
'currentComponent' => $currentComponent
]);
}
public function renderTransfer()
{
wp_enqueue_style(
'fluentform_settings_global',
fluentformMix("css/settings_global.css"),
[], $this->app->getVersion(), 'all'
);
wp_enqueue_script('fluentform-transfer-js',
fluentformMix("js/fluentform-transfer.js"),
['jquery'], $this->app->getVersion(), false
);
wp_localize_script('fluentform-transfer-js', 'FluentFormApp', [
'plugin' => $this->app->getSlug(),
'forms' => wpFluent()->table('fluentform_forms')->select(['id', 'title'])->get()
]);
View::render('admin.transfer.index');
}
private function getFormPreviewUrl($form_id)
{
return site_url('?fluentform_pages=1&preview_id='.$form_id).'#ff_preview';
}
public function addPreviewButton($formId)
{
echo 'Preview';
}
}