| 1 |
<?php |
| 2 |
|
| 3 |
namespace FormLayer; |
| 4 |
|
| 5 |
if(!defined('ABSPATH')){ |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class Admin{ |
| 10 |
|
| 11 |
static function init(){ |
| 12 |
add_action('admin_menu', '\FormLayer\Admin::register_menu'); |
| 13 |
// enqueue |
| 14 |
add_action('admin_enqueue_scripts', '\FormLayer\Admin::enqueue_admin_assets'); |
| 15 |
} |
| 16 |
|
| 17 |
static function register_menu(){ |
| 18 |
if(defined('FORMLAYER_PRO_VERSION')){ |
| 19 |
$unread = \FormLayerPro\Util::get_unread_count(); |
| 20 |
$count_html = $unread > 0 ? ' <span class="update-plugins count-' . $unread . '"><span class="plugin-count">' . $unread . '</span></span>' : ''; |
| 21 |
} else { |
| 22 |
$count_html = ''; |
| 23 |
} |
| 24 |
|
| 25 |
add_menu_page(__('FormLayer', 'formlayer') ,__( 'FormLayer', 'formlayer' ) . $count_html, 'manage_options', 'formlayer', '\FormLayer\Admin::render_admin_page', FORMLAYER_ASSETS_URL.'/img/formlayer-logo-30.png'); |
| 26 |
|
| 27 |
add_submenu_page('formlayer', __( 'Dashboard', 'formlayer' ), __( 'Dashboard', 'formlayer' ), 'manage_options', 'formlayer' ,'\FormLayer\Admin::render_admin_page'); |
| 28 |
|
| 29 |
} |
| 30 |
|
| 31 |
static function render_admin_page(){ |
| 32 |
\FormLayer\Settings\UI::header(); |
| 33 |
|
| 34 |
echo '<div id="formlayer-tab-forms" class="formlayer-tab-content">'; |
| 35 |
\FormLayer\Settings\UI::forms_tab(); |
| 36 |
echo '</div>'; |
| 37 |
|
| 38 |
// Form Builder tab |
| 39 |
echo '<div id="formlayer-tab-formbuilder" class="formlayer-tab-content" style="display:none;">'; |
| 40 |
\FormLayer\Settings\UI::formbuilder_tab(); |
| 41 |
echo '</div>'; |
| 42 |
echo '<div id="formlayer-tab-entries" class="formlayer-tab-content" style="display:none;">'; |
| 43 |
\FormLayer\Settings\UI::entries_tab(); |
| 44 |
echo '</div>'; |
| 45 |
|
| 46 |
echo '<div id="formlayer-tab-reports" class="formlayer-tab-content" style="display:none;">'; |
| 47 |
\FormLayer\Settings\UI::reports_tab(); |
| 48 |
echo '</div>'; |
| 49 |
|
| 50 |
echo '<div id="formlayer-tab-integrations" class="formlayer-tab-content" style="display:none;">'; |
| 51 |
\FormLayer\Settings\UI::integrations_tab(); |
| 52 |
echo '</div>'; |
| 53 |
|
| 54 |
echo '<div id="formlayer-tab-settings" class="formlayer-tab-content" style="display:none;">'; |
| 55 |
\FormLayer\Settings\UI::settings_tab(); |
| 56 |
echo '</div>'; |
| 57 |
|
| 58 |
echo'<div id="formlayer-tab-support" class="formlayer-tab-content" style="display:none;">'; |
| 59 |
\FormLayer\Settings\UI::support_tab(); |
| 60 |
echo'</div>'; |
| 61 |
|
| 62 |
echo'<div id="formlayer-tab-tools" class="formlayer-tab-content" style="display:none;">'; |
| 63 |
do_action('formlayer_render_tools_tab'); |
| 64 |
echo'</div>'; |
| 65 |
|
| 66 |
if(defined('FORMLAYER_PRO_VERSION')){ |
| 67 |
echo '<div id="formlayer-tab-license" class="formlayer-tab-content" style="display:none;">'; |
| 68 |
do_action('formlayer_render_license_page'); |
| 69 |
echo '</div>'; |
| 70 |
} |
| 71 |
|
| 72 |
\FormLayer\Settings\UI::footer(); |
| 73 |
} |
| 74 |
|
| 75 |
static function enqueue_admin_assets($hook){ |
| 76 |
if(strpos( $hook, 'formlayer' ) === false){ |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
wp_enqueue_style('formlayer-admin-css', FORMLAYER_PLUGIN_URL . 'assets/css/admin.css', [],FORMLAYER_VERSION); |
| 81 |
|
| 82 |
wp_enqueue_script('formlayer-admin-js', FORMLAYER_PLUGIN_URL . 'assets/js/admin.js', ['jquery'], FORMLAYER_VERSION, true); |
| 83 |
|
| 84 |
$categories = [ |
| 85 |
['id' => 'general', 'label' => __('General Fields', 'formlayer'), 'open' => true], |
| 86 |
['id' => 'advanced', 'label' => __('Advanced Fields', 'formlayer'), 'open' => false] |
| 87 |
]; |
| 88 |
|
| 89 |
$field_types = [ |
| 90 |
['type' => 'name', 'label' => 'Name Fields', 'icon' => 'dashicons-admin-users', 'category' => 'general'], |
| 91 |
['type' => 'email', 'label' => 'Email', 'icon' => 'dashicons-email', 'category' => 'general'], |
| 92 |
['type' => 'text', 'label' => 'Simple Text', 'icon' => 'dashicons-edit', 'category' => 'general'], |
| 93 |
['type' => 'mask', 'label' => 'Mask Input', 'icon' => 'dashicons-shield', 'category' => 'general'], |
| 94 |
['type' => 'textarea', 'label' => 'Text Area', 'icon' => 'dashicons-editor-alignleft', 'category' => 'general'], |
| 95 |
['type' => 'country', 'label' => 'Country List', 'icon' => 'dashicons-flag', 'category' => 'general'], |
| 96 |
['type' => 'number', 'label' => 'Numeric Field', 'icon' => 'dashicons-editor-ol', 'category' => 'general'], |
| 97 |
['type' => 'dropdown', 'label' => 'Dropdown', 'icon' => 'dashicons-arrow-down-alt2', 'category' => 'general'], |
| 98 |
['type' => 'radio', 'label' => 'Radio Field', 'icon' => 'dashicons-marker', 'category' => 'general'], |
| 99 |
['type' => 'checkbox', 'label' => 'Checkbox', 'icon' => 'dashicons-yes', 'category' => 'general'], |
| 100 |
['type' => 'multiple', 'label' => 'Multiple Choice', 'icon' => 'dashicons-list-view', 'category' => 'general'], |
| 101 |
['type' => 'section', 'label' => 'Section Break', 'icon' => 'dashicons-minus', 'category' => 'general'], |
| 102 |
['type' => 'rating', 'label' => 'Ratings', 'icon' => 'dashicons-star-filled', 'category' => 'advanced'], |
| 103 |
['type' => 'terms', 'label' => 'Terms & Conditions', 'icon' => 'dashicons-media-text', 'category' => 'advanced'], |
| 104 |
['type' => 'gdpr', 'label' => 'GDPR Agreement', 'icon' => 'dashicons-shield', 'category' => 'advanced'], |
| 105 |
['type' => 'captcha', 'label' => 'Captcha Protection', 'icon' => 'dashicons-shield-alt', 'category' => 'advanced'], |
| 106 |
['type' => 'submit', 'label' => 'Submit Button', 'icon' => 'dashicons-plus-alt', 'category' => 'advanced'] |
| 107 |
]; |
| 108 |
|
| 109 |
wp_localize_script('formlayer-admin-js', 'formlayer_admin', [ |
| 110 |
'ajax_url' => admin_url( 'admin-ajax.php' ), |
| 111 |
'process_url' => admin_url( 'admin.php?page=formlayer&action=process_choice' ), |
| 112 |
'nonce' => wp_create_nonce('formlayer_admin_nonce'), |
| 113 |
'form_id' => isset($_GET['form_id']) ? intval($_GET['form_id']) : 0, |
| 114 |
'categories' => apply_filters('formlayer_builder_categories', $categories), |
| 115 |
'fieldTypes' => apply_filters('formlayer_field_types', $field_types), |
| 116 |
'is_pro' => defined('FORMLAYER_PRO_VERSION'), |
| 117 |
'captcha_settings' => get_option('formlayer_settings', []), |
| 118 |
'templates' => \FormLayer\Templates::get_all(), |
| 119 |
'html_templates' => \FormLayer\Templates::js_templates() |
| 120 |
]); |
| 121 |
} |
| 122 |
} |