# fluentform/1.2.4/app/Modules/Registerer/Menu.php

Fluent Forms – Customizable Contact Forms, Survey, Quiz, &amp; Conversational Form Builder, version 1.2.4. 344 lines.

- Page: https://pluginprobe.com/plugins/fluentform/1.2.4/code/app/Modules/Registerer/Menu.php
- Raw: https://pluginprobe.com/plugins/fluentform/1.2.4/raw/app/Modules/Registerer/Menu.php
- Modified: 2018-02-03T11:29:32+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluentform/1.2.4/code/app/Modules/Registerer/Menu.php#L10-L20`.

```php
<?php

namespace FluentForm\App\Modules\Registerer;

use FluentForm\App\Modules\DocumentationModule;
use FluentForm\View;
use FluentForm\Framework\Foundation\Application;

class Menu
{
    /**
     * @var \FluentForm\Framework\Foundation\Application
     */
    protected $app;

    /**
     * Menu constructor.
     *
     * @param \FluentForm\Framework\Foundation\Application $application
     */
    public function __construct(Application $application)
    {
        $this->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('<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>');
    }

    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 __("<h2>No form found</h2>", '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 '<a target="_blank" style="margin: 3px;" class="pull-right el-button el-button--primary el-button--small" href="'.$this->getFormPreviewUrl($formId).'">Preview</a>';
    }
}
```
