| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\App\Modules\Registerer; |
| 4 |
|
| 5 |
use FluentForm\App\Modules\DocumentationModule; |
| 6 |
use FluentForm\View; |
| 7 |
use FluentForm\Framework\Foundation\Application; |
| 8 |
|
| 9 |
class Menu |
| 10 |
{ |
| 11 |
/** |
| 12 |
* @var \FluentForm\Framework\Foundation\Application |
| 13 |
*/ |
| 14 |
protected $app; |
| 15 |
|
| 16 |
/** |
| 17 |
* Menu constructor. |
| 18 |
* |
| 19 |
* @param \FluentForm\Framework\Foundation\Application $application |
| 20 |
*/ |
| 21 |
public function __construct(Application $application) |
| 22 |
{ |
| 23 |
$this->app = $application; |
| 24 |
} |
| 25 |
|
| 26 |
/** |
| 27 |
* Register menu and sub-menus. |
| 28 |
*/ |
| 29 |
public function register() |
| 30 |
{ |
| 31 |
$dashBoardCapability = apply_filters('fluentform_dashboard_capability', 'fluentform_settings_manager'); |
| 32 |
add_menu_page( |
| 33 |
__('Fluent Form', 'fluentform'), |
| 34 |
__('Fluent Form', 'fluentform'), |
| 35 |
$dashBoardCapability, |
| 36 |
'fluent_forms', |
| 37 |
array($this, 'renderFormAdminRoute'), |
| 38 |
$this->getMenuIcon(), |
| 39 |
25 |
| 40 |
); |
| 41 |
|
| 42 |
add_submenu_page( |
| 43 |
'fluent_forms', |
| 44 |
__('All Forms', 'fluentform'), |
| 45 |
__('All Forms', 'fluentform'), |
| 46 |
$dashBoardCapability, |
| 47 |
'fluent_forms', |
| 48 |
array($this, 'renderFormAdminRoute') |
| 49 |
); |
| 50 |
|
| 51 |
add_submenu_page( |
| 52 |
'fluent_forms', |
| 53 |
__('New Form', 'fluentform'), |
| 54 |
__('New Form', 'fluentform'), |
| 55 |
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'), |
| 56 |
'fluent_forms#add=1', |
| 57 |
array($this, 'renderFormAdminRoute') |
| 58 |
); |
| 59 |
|
| 60 |
// Register entries intermediary page |
| 61 |
add_submenu_page( |
| 62 |
'fluent_forms', |
| 63 |
__('Entries', 'fluentform'), |
| 64 |
__('Entries', 'fluentform'), |
| 65 |
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'), |
| 66 |
'fluent_forms#entries', |
| 67 |
array($this, 'renderFormAdminRoute') |
| 68 |
); |
| 69 |
|
| 70 |
// Register import/export sub menu page. |
| 71 |
add_submenu_page( |
| 72 |
'fluent_forms', |
| 73 |
__('Export/Import', 'fluentform'), |
| 74 |
__('Export/Import', 'fluentform'), |
| 75 |
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'), |
| 76 |
'fluent_forms_transfer', |
| 77 |
array($this, 'renderTransfer') |
| 78 |
); |
| 79 |
|
| 80 |
// Register global settings sub menu page. |
| 81 |
add_submenu_page( |
| 82 |
'fluent_forms', |
| 83 |
__('Settings', 'fluentform'), |
| 84 |
__('Settings', 'fluentform'), |
| 85 |
apply_filters('fluentform_settings_capability', 'fluentform_settings_manager'), |
| 86 |
'fluent_forms_settings', |
| 87 |
array($this, 'renderGlobalSettings') |
| 88 |
); |
| 89 |
|
| 90 |
// Register Documentation |
| 91 |
add_submenu_page( |
| 92 |
'fluent_forms', |
| 93 |
__('Get Help', 'fluentform'), |
| 94 |
__('Get Help', 'fluentform'), |
| 95 |
$dashBoardCapability, |
| 96 |
'fluent_forms_docs', |
| 97 |
array($this, 'renderDocs') |
| 98 |
); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
private function getMenuIcon() |
| 103 |
{ |
| 104 |
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>'); |
| 105 |
} |
| 106 |
|
| 107 |
public function renderFormAdminRoute() |
| 108 |
{ |
| 109 |
if (isset($_GET['route']) && isset($_GET['form_id'])) { |
| 110 |
|
| 111 |
$version = $this->app->getVersion(); |
| 112 |
|
| 113 |
wp_enqueue_style('fluentform_settings_global', fluentformMix("css/settings_global.css"), array(), $version, |
| 114 |
'all'); |
| 115 |
|
| 116 |
$form_id = intval($_GET['form_id']); |
| 117 |
|
| 118 |
$formAdminMenus = array( |
| 119 |
'editor' => array( |
| 120 |
'slug' => 'editor', |
| 121 |
'title' => __('Editor', 'fluentform') |
| 122 |
), |
| 123 |
'settings' => array( |
| 124 |
'slug' => 'settings', |
| 125 |
'hash' => 'basic_settings', |
| 126 |
'title' => __('Settings', 'fluentform'), |
| 127 |
'sub_route' => 'form_settings' |
| 128 |
), |
| 129 |
'entries' => array( |
| 130 |
'slug' => 'entries', |
| 131 |
'hash' => '/', |
| 132 |
'title' => __('Entries', 'fluentform') |
| 133 |
) |
| 134 |
); |
| 135 |
|
| 136 |
$formAdminMenus = apply_filters('fluentform_form_admin_menu', $formAdminMenus, $form_id); |
| 137 |
|
| 138 |
$form = wpFluent()->table('fluentform_forms')->find($form_id); |
| 139 |
|
| 140 |
if(!$form) { |
| 141 |
echo __("<h2>No form found</h2>", 'fluentform'); |
| 142 |
die(); |
| 143 |
} |
| 144 |
|
| 145 |
View::render('admin.form.form_wrapper', array( |
| 146 |
'route' => sanitize_text_field($_GET['route']), |
| 147 |
'form_id' => $form_id, |
| 148 |
'form' => $form, |
| 149 |
'menu_items' => $formAdminMenus |
| 150 |
)); |
| 151 |
|
| 152 |
return; |
| 153 |
} |
| 154 |
$this->renderForms(); |
| 155 |
} |
| 156 |
|
| 157 |
public function renderSettings($form_id) |
| 158 |
{ |
| 159 |
$settingsMenus = array( |
| 160 |
'form_settings' => array( |
| 161 |
'title' => __('Form Settings', 'fluentform'), |
| 162 |
'slug' => 'form_settings', |
| 163 |
'hash' => 'basic_settings' |
| 164 |
), |
| 165 |
'email_notifications' => array( |
| 166 |
'title' => __('Email Notifications', 'fluentform'), |
| 167 |
'slug' => 'form_settings', |
| 168 |
'hash' => 'email_notifications' |
| 169 |
), |
| 170 |
'mailchimp_integration' => array( |
| 171 |
'title' => __('MailChimp', 'fluentform'), |
| 172 |
'slug' => 'form_settings', |
| 173 |
'hash' => 'mailchimp_integration' |
| 174 |
), |
| 175 |
'slack' => array( |
| 176 |
'title' => __('Slack', 'fluentform'), |
| 177 |
'slug' => 'form_settings', |
| 178 |
'hash' => 'slack' |
| 179 |
) |
| 180 |
); |
| 181 |
$settingsMenus = apply_filters('fluentform_form_settings_menu', $settingsMenus, $form_id); |
| 182 |
$currentRoute = isset($_REQUEST['sub_route']) ? sanitize_text_field($_REQUEST['sub_route']) : ''; |
| 183 |
|
| 184 |
View::render('admin.form.settings_wrapper', array( |
| 185 |
'form_id' => $form_id, |
| 186 |
'settings_menus' => $settingsMenus, |
| 187 |
'current_sub_route' => $currentRoute |
| 188 |
)); |
| 189 |
} |
| 190 |
|
| 191 |
public function renderFormSettings($form_id) |
| 192 |
{ |
| 193 |
$version = $this->app->getVersion(); |
| 194 |
|
| 195 |
if (function_exists('wp_enqueue_editor')) { |
| 196 |
wp_enqueue_editor(); |
| 197 |
} |
| 198 |
|
| 199 |
wp_enqueue_script('fluentform_form_settings', fluentformMix("js/form_settings_app.js"), array('jquery'), $version, |
| 200 |
false); |
| 201 |
|
| 202 |
wp_localize_script('fluentform_form_settings', 'FluentFormApp', array( |
| 203 |
'form_id' => $form_id, |
| 204 |
'plugin' => $this->app->getSlug(), |
| 205 |
'hasPro' => class_exists('FluentFormPro') |
| 206 |
)); |
| 207 |
|
| 208 |
View::render('admin.form.settings', array( |
| 209 |
'form_id' => $form_id |
| 210 |
)); |
| 211 |
} |
| 212 |
|
| 213 |
public function renderForms() |
| 214 |
{ |
| 215 |
$version = $this->app->getVersion(); |
| 216 |
|
| 217 |
|
| 218 |
wp_enqueue_script('fluent_all_forms', fluentformMix("js/fluent-all-forms-admin.js"), array('jquery'), $version, |
| 219 |
false); |
| 220 |
|
| 221 |
wp_enqueue_style('fluent_all_forms', fluentformMix("css/fluent-all-forms.css"), array(), $version, 'all'); |
| 222 |
|
| 223 |
|
| 224 |
wp_localize_script('fluent_all_forms', 'FluentFormApp', array( |
| 225 |
'plugin' => $this->app->getSlug(), |
| 226 |
'adminUrl' => admin_url('admin.php?page=fluent_forms') |
| 227 |
)); |
| 228 |
|
| 229 |
View::render('admin.all_forms', array()); |
| 230 |
} |
| 231 |
|
| 232 |
public function renderEditor($form_id) |
| 233 |
{ |
| 234 |
$this->enqueueEditorAssets(); |
| 235 |
echo View::make('admin.form.editor', array( |
| 236 |
'plugin' => $this->app->getSlug(), |
| 237 |
'form_id' => $form_id |
| 238 |
)); |
| 239 |
} |
| 240 |
|
| 241 |
public function renderDocs() |
| 242 |
{ |
| 243 |
echo (new DocumentationModule())->render(); |
| 244 |
} |
| 245 |
|
| 246 |
private function enqueueEditorAssets() |
| 247 |
{ |
| 248 |
$pluginSlug = $this->app->getSlug(); |
| 249 |
$version = $this->app->getVersion(); |
| 250 |
|
| 251 |
|
| 252 |
wp_enqueue_script('fluentform_editor_script', fluentformMix("js/fluent-forms-editor.js"), ['jquery'], $version, |
| 253 |
false); |
| 254 |
|
| 255 |
wp_enqueue_style('fluentform_editor_style', fluentformMix("css/fluent-forms-admin-sass.css"), [], $version, |
| 256 |
'all'); |
| 257 |
|
| 258 |
wp_enqueue_style('fluentform_editor_sass', fluentformMix("css/fluent-forms-admin.css"), [], $version, 'all'); |
| 259 |
|
| 260 |
$formId = intval($_GET['form_id']); |
| 261 |
wp_localize_script('fluentform_editor_script', 'FluentFormApp', array( |
| 262 |
'plugin' => $pluginSlug, |
| 263 |
'form_id' => $formId, |
| 264 |
'countries' => $countries = $this->app->load($this->app->appPath('Services/FormBuilder/CountryNames.php')), |
| 265 |
'form' => wpFluent()->table('fluentform_forms')->find($formId), |
| 266 |
'plugin_public_url' => $this->app->publicUrl(), |
| 267 |
'preview_url' => $this->getFormPreviewUrl($formId) |
| 268 |
)); |
| 269 |
} |
| 270 |
|
| 271 |
/** |
| 272 |
* Render global settings page. |
| 273 |
* |
| 274 |
* @throws \Exception |
| 275 |
*/ |
| 276 |
public function renderGlobalSettings() |
| 277 |
{ |
| 278 |
$version = $this->app->getVersion(); |
| 279 |
|
| 280 |
wp_enqueue_style( |
| 281 |
'fluentform_settings_global', |
| 282 |
fluentformMix("css/settings_global.css"), |
| 283 |
[], $version, 'all' |
| 284 |
); |
| 285 |
|
| 286 |
// Fire an event letting others know the current component |
| 287 |
// that fluentform is rendering for the global settings |
| 288 |
// page. So that they can hook and load their custom |
| 289 |
// components on this page dynamically & easily. |
| 290 |
// N.B. native 'components' will always use |
| 291 |
// 'settings' as their current component. |
| 292 |
$currentComponent = apply_filters('fluentform_global_settings_current_component', |
| 293 |
$this->app->request->get('component', 'settings') |
| 294 |
); |
| 295 |
|
| 296 |
$components = apply_filters('fluentform_global_settings_components', [ |
| 297 |
'reCpatcha' => [ |
| 298 |
'hash' => 're_captcha', |
| 299 |
'title' => 'reCpatcha', |
| 300 |
], |
| 301 |
'mailchimp' => [ |
| 302 |
'hash' => 'mailchimp', |
| 303 |
'title' => 'MailChimp', |
| 304 |
] |
| 305 |
]); |
| 306 |
|
| 307 |
View::render('admin.settings.index', [ |
| 308 |
'components' => $components, |
| 309 |
'currentComponent' => $currentComponent |
| 310 |
]); |
| 311 |
} |
| 312 |
|
| 313 |
public function renderTransfer() |
| 314 |
{ |
| 315 |
wp_enqueue_style( |
| 316 |
'fluentform_settings_global', |
| 317 |
fluentformMix("css/settings_global.css"), |
| 318 |
[], $this->app->getVersion(), 'all' |
| 319 |
); |
| 320 |
|
| 321 |
wp_enqueue_script('fluentform-transfer-js', |
| 322 |
fluentformMix("js/fluentform-transfer.js"), |
| 323 |
['jquery'], $this->app->getVersion(), false |
| 324 |
); |
| 325 |
|
| 326 |
wp_localize_script('fluentform-transfer-js', 'FluentFormApp', [ |
| 327 |
'plugin' => $this->app->getSlug(), |
| 328 |
'forms' => wpFluent()->table('fluentform_forms')->select(['id', 'title'])->get() |
| 329 |
]); |
| 330 |
|
| 331 |
View::render('admin.transfer.index'); |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
private function getFormPreviewUrl($form_id) |
| 336 |
{ |
| 337 |
return site_url('?fluentform_pages=1&preview_id='.$form_id).'#ff_preview'; |
| 338 |
} |
| 339 |
|
| 340 |
public function addPreviewButton($formId) |
| 341 |
{ |
| 342 |
echo '<a target="_blank" style="margin: 3px;" class="pull-right el-button el-button--primary el-button--small" href="'.$this->getFormPreviewUrl($formId).'">Preview</a>'; |
| 343 |
} |
| 344 |
} |