Completed
Branch FET/your-org-country-input (2d1c9e)
by
unknown
09:36 queued 15s
created

OrganizationSettings::getCountrySubRegions()   B

Complexity

Conditions 9
Paths 9

Size

Total Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
nc 9
nop 1
dl 0
loc 44
rs 7.6604
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\admin_pages\general_settings;
4
5
use DomainException;
6
use EE_Admin_File_Uploader_Input;
7
use EE_Admin_Two_Column_Layout;
8
use EE_Checkbox_Multi_Input;
9
use EE_Core_Config;
10
use EE_Country;
11
use EE_Country_Select_Input;
12
use EE_Currency_Config;
13
use EE_Error;
14
use EE_Form_Section_HTML;
15
use EE_Form_Section_Proper;
16
use EE_Network_Core_Config;
17
use EE_Organization_Config;
18
use EE_Registry;
19
use EE_State_Select_Input;
20
use EE_Text_Input;
21
use EEH_HTML;
22
use EEH_Template;
23
use EEM_Country;
24
use EEM_State;
25
use EventEspresso\core\domain\services\pue\Stats;
26
use EventEspresso\core\exceptions\InvalidDataTypeException;
27
use EventEspresso\core\exceptions\InvalidFormSubmissionException;
28
use EventEspresso\core\exceptions\InvalidInterfaceException;
29
use EventEspresso\core\libraries\form_sections\form_handlers\FormHandler;
30
use EventEspresso\core\libraries\form_sections\strategies\filter\VsprintfFilter;
31
use InvalidArgumentException;
32
use LogicException;
33
use ReflectionException;
34
35
/**
36
 * OrganizationSettings
37
 * A form handler for Organization Settings
38
 *
39
 * @package EventEspresso\admin_pages\general_settings
40
 * @author  Darren Ethier
41
 * @since   4.9.63.p
42
 */
43
class OrganizationSettings extends FormHandler
44
{
45
46
    /**
47
     * @var EE_Organization_Config
48
     */
49
    protected $organization_config;
50
51
    /**
52
     * @var EE_Core_Config
53
     */
54
    protected $core_config;
55
56
57
    /**
58
     * @var EE_Network_Core_Config
59
     */
60
    protected $network_core_config;
61
62
    /**
63
     * Form constructor.
64
     *
65
     * @param EE_Registry             $registry
66
     * @param EE_Organization_Config  $organization_config
67
     * @param EE_Core_Config          $core_config
68
     * @param EE_Network_Core_Config $network_core_config
69
     * @throws InvalidArgumentException
70
     * @throws InvalidDataTypeException
71
     * @throws DomainException
72
     */
73
    public function __construct(
74
        EE_Registry $registry,
75
        EE_Organization_Config $organization_config,
76
        EE_Core_Config $core_config,
77
        EE_Network_Core_Config $network_core_config
78
    ) {
79
        $this->organization_config = $organization_config;
80
        $this->core_config = $core_config;
81
        $this->network_core_config = $network_core_config;
82
        parent::__construct(
83
            esc_html__('Your Organization Settings', 'event_espresso'),
84
            esc_html__('Your Organization Settings', 'event_espresso'),
85
            'organization_settings',
86
            '',
87
            FormHandler::DO_NOT_SETUP_FORM,
88
            $registry
89
        );
90
    }
91
92
93
    /**
94
     * creates and returns the actual form
95
     *
96
     * @return EE_Form_Section_Proper
97
     * @throws EE_Error
98
     * @throws InvalidArgumentException
99
     * @throws InvalidDataTypeException
100
     * @throws InvalidInterfaceException
101
     * @throws ReflectionException
102
     */
103
    public function generate()
104
    {
105
        $has_sub_regions = EEM_State::instance()->count(
106
            array(array('Country.CNT_ISO' => $this->organization_config->CNT_ISO))
107
        );
108
        $form = new EE_Form_Section_Proper(
109
            array(
110
                'name'            => 'organization_settings',
111
                'html_id'         => 'organization_settings',
112
                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
113
                'subsections'     => array(
114
                    'contact_information_hdr'        => new EE_Form_Section_HTML(
115
                        EEH_HTML::h2(
116
                            esc_html__('Contact Information', 'event_espresso')
117
                            . ' '
118
                            . EEH_HTML::span(EEH_Template::get_help_tab_link('contact_info_info')),
119
                            '',
120
                            'contact-information-hdr'
121
                        )
122
                    ),
123
                    'organization_name'      => new EE_Text_Input(
124
                        array(
125
                            'html_name' => 'organization_name',
126
                            'html_label_text' => esc_html__('Organization Name', 'event_espresso'),
127
                            'html_help_text'  => esc_html__(
128
                                'Displayed on all emails and invoices.',
129
                                'event_espresso'
130
                            ),
131
                            'default'         => $this->organization_config->get_pretty('name'),
132
                            'required'        => false,
133
                        )
134
                    ),
135
                    'organization_address_1'      => new EE_Text_Input(
136
                        array(
137
                            'html_name' => 'organization_address_1',
138
                            'html_label_text' => esc_html__('Street Address', 'event_espresso'),
139
                            'default'         => $this->organization_config->get_pretty('address_1'),
140
                            'required'        => false,
141
                        )
142
                    ),
143
                    'organization_address_2'      => new EE_Text_Input(
144
                        array(
145
                            'html_name' => 'organization_address_2',
146
                            'html_label_text' => esc_html__('Street Address 2', 'event_espresso'),
147
                            'default'         => $this->organization_config->get_pretty('address_2'),
148
                            'required'        => false,
149
                        )
150
                    ),
151
                    'organization_city'      => new EE_Text_Input(
152
                        array(
153
                            'html_name' => 'organization_city',
154
                            'html_label_text' => esc_html__('City', 'event_espresso'),
155
                            'default'         => $this->organization_config->get_pretty('city'),
156
                            'required'        => false,
157
                        )
158
                    ),
159
                    'organization_country'      => new EE_Country_Select_Input(
160
                        null,
161
                        array(
162
                            EE_Country_Select_Input::OPTION_GET_KEY => EE_Country_Select_Input::OPTION_GET_ALL,
163
                            'html_name'       => 'organization_country',
164
                            'html_label_text' => esc_html__('Country', 'event_espresso'),
165
                            'default'         => $this->organization_config->CNT_ISO,
166
                            'required'        => false,
167
                            'html_help_text'  => sprintf(
168
                                esc_html__(
169
                                    '%1$sThe Country set here will have the effect of setting the currency used for all ticket prices.%2$s',
170
                                    'event_espresso'
171
                                ),
172
                                '<span class="reminder-spn">',
173
                                '</span>'
174
                            ),
175
                        )
176
                    ),
177
                    'organization_state' => new EE_State_Select_Input(
178
                        null,
179
                        array(
180
                            'html_name'       => 'organization_state',
181
                            'html_label_text' => esc_html__('State/Province', 'event_espresso'),
182
                            'default'         => $this->organization_config->STA_ID,
183
                            'required'        => false,
184
                            'html_help_text' => empty($this->organization_config->STA_ID) || ! $has_sub_regions
185
                                ? sprintf(
186
                                    esc_html__(
187
                                        'If the States/Provinces for the selected Country do not appear in this list, then click "Save".%3$sIf data exists, then the list will be populated when the page reloads and you will be able to make a selection at that time.%3$s%1$sMake sure you click "Save" again after selecting a State/Province that has just been loaded in order to keep that selection.%2$s',
188
                                        'event_espresso'
189
                                    ),
190
                                    '<span class="reminder-spn">',
191
                                    '</span>',
192
                                    '<br />'
193
                                )
194
                                : '',
195
                        )
196
                    ),
197
                    'organization_zip'      => new EE_Text_Input(
198
                        array(
199
                            'html_name' => 'organization_zip',
200
                            'html_label_text' => esc_html__('Zip/Postal Code', 'event_espresso'),
201
                            'default'         => $this->organization_config->get_pretty('zip'),
202
                            'required'        => false,
203
                        )
204
                    ),
205
                    'organization_email'      => new EE_Text_Input(
206
                        array(
207
                            'html_name' => 'organization_email',
208
                            'html_label_text' => esc_html__('Primary Contact Email', 'event_espresso'),
209
                            'html_help_text'  => sprintf(
210
                                esc_html__(
211
                                    'This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.',
212
                                    'event_espresso'
213
                                ),
214
                                '<code>[CO_FORMATTED_EMAIL]</code>',
215
                                '<code>[CO_EMAIL]</code>'
216
                            ),
217
                            'default'         => $this->organization_config->get_pretty('email'),
218
                            'required'        => false,
219
                        )
220
                    ),
221
                    'organization_phone'      => new EE_Text_Input(
222
                        array(
223
                            'html_name' => 'organization_phone',
224
                            'html_label_text' => esc_html__('Phone Number', 'event_espresso'),
225
                            'html_help_text'  => esc_html__(
226
                                'The phone number for your organization.',
227
                                'event_espresso'
228
                            ),
229
                            'default'         => $this->organization_config->get_pretty('phone'),
230
                            'required'        => false,
231
                        )
232
                    ),
233
                    'organization_vat'      => new EE_Text_Input(
234
                        array(
235
                            'html_name' => 'organization_vat',
236
                            'html_label_text' => esc_html__('VAT/Tax Number', 'event_espresso'),
237
                            'html_help_text'  => esc_html__(
238
                                'The VAT/Tax Number may be displayed on invoices and receipts.',
239
                                'event_espresso'
240
                            ),
241
                            'default'         => $this->organization_config->get_pretty('vat'),
242
                            'required'        => false,
243
                        )
244
                    ),
245
                    'company_logo_hdr'        => new EE_Form_Section_HTML(
246
                        EEH_HTML::h2(
247
                            esc_html__('Company Logo', 'event_espresso')
248
                            . ' '
249
                            . EEH_HTML::span(EEH_Template::get_help_tab_link('organization_logo_info')),
250
                            '',
251
                            'company-logo-hdr'
252
                        )
253
                    ),
254
                    'organization_logo_url'      => new EE_Admin_File_Uploader_Input(
255
                        array(
256
                            'html_name' => 'organization_logo_url',
257
                            'html_label_text' => esc_html__('Upload New Logo', 'event_espresso'),
258
                            'html_help_text'  => esc_html__(
259
                                'Your logo will be used on custom invoices, tickets, certificates, and payment templates.',
260
                                'event_espresso'
261
                            ),
262
                            'default'         => $this->organization_config->get_pretty('logo_url'),
263
                            'required'        => false,
264
                        )
265
                    ),
266
                    'social_links_hdr'        => new EE_Form_Section_HTML(
267
                        EEH_HTML::h2(
268
                            esc_html__('Social Links', 'event_espresso')
269
                            . ' '
270
                            . EEH_HTML::span(EEH_Template::get_help_tab_link('social_links_info'))
271
                            . EEH_HTML::br()
272
                            . EEH_HTML::p(
273
                                esc_html__(
274
                                    'Enter any links to social accounts for your organization here',
275
                                    'event_espresso'
276
                                ),
277
                                '',
278
                                'description'
279
                            ),
280
                            '',
281
                            'social-links-hdr'
282
                        )
283
                    ),
284
                    'organization_facebook'      => new EE_Text_Input(
285
                        array(
286
                            'html_name' => 'organization_facebook',
287
                            'html_label_text' => esc_html__('Facebook', 'event_espresso'),
288
                            'other_html_attributes' => ' placeholder="facebook.com/profile.name"',
289
                            'default'         => $this->organization_config->get_pretty('facebook'),
290
                            'required'        => false,
291
                        )
292
                    ),
293
                    'organization_twitter'      => new EE_Text_Input(
294
                        array(
295
                            'html_name' => 'organization_twitter',
296
                            'html_label_text' => esc_html__('Twitter', 'event_espresso'),
297
                            'other_html_attributes' => ' placeholder="twitter.com/twitterhandle"',
298
                            'default'         => $this->organization_config->get_pretty('twitter'),
299
                            'required'        => false,
300
                        )
301
                    ),
302
                    'organization_linkedin'      => new EE_Text_Input(
303
                        array(
304
                            'html_name' => 'organization_linkedin',
305
                            'html_label_text' => esc_html__('LinkedIn', 'event_espresso'),
306
                            'other_html_attributes' => ' placeholder="linkedin.com/in/profilename"',
307
                            'default'         => $this->organization_config->get_pretty('linkedin'),
308
                            'required'        => false,
309
                        )
310
                    ),
311
                    'organization_pinterest'      => new EE_Text_Input(
312
                        array(
313
                            'html_name' => 'organization_pinterest',
314
                            'html_label_text' => esc_html__('Pinterest', 'event_espresso'),
315
                            'other_html_attributes' => ' placeholder="pinterest.com/profilename"',
316
                            'default'         => $this->organization_config->get_pretty('pinterest'),
317
                            'required'        => false,
318
                        )
319
                    ),
320
                    'organization_google'      => new EE_Text_Input(
321
                        array(
322
                            'html_name' => 'organization_google',
323
                            'html_label_text' => esc_html__('Google+', 'event_espresso'),
324
                            'other_html_attributes' => ' placeholder="google.com/+profilename"',
325
                            'default'         => $this->organization_config->get_pretty('google'),
326
                            'required'        => false,
327
                        )
328
                    ),
329
                    'organization_instagram'      => new EE_Text_Input(
330
                        array(
331
                            'html_name' => 'organization_instagram',
332
                            'html_label_text' => esc_html__('Instagram', 'event_espresso'),
333
                            'other_html_attributes' => ' placeholder="instagram.com/handle"',
334
                            'default'         => $this->organization_config->get_pretty('instagram'),
335
                            'required'        => false,
336
                        )
337
                    ),
338
                ),
339
            )
340
        );
341
        if (is_main_site()) {
342
            $form->add_subsections(
343
                array(
344
                    'site_license_key_hdr' => new EE_Form_Section_HTML(
345
                        EEH_HTML::h2(
346
                            esc_html__('Your Event Espresso License Key', 'event_espresso')
347
                            . ' '
348
                            . EEH_HTML::span(
349
                                EEH_Template::get_help_tab_link('site_license_key_info'),
350
                                'help_tour_activation'
351
                            ),
352
                            '',
353
                            'site-license-key-hdr'
354
                        )
355
                    ),
356
                    'site_license_key' => $this->getSiteLicenseKeyField()
357
                )
358
            );
359
            $form->add_subsections(
360
                array(
361
                    'uxip_optin_hdr' => new EE_Form_Section_HTML(
362
                        $this->uxipOptinText()
363
                    ),
364
                    'ueip_optin' => new EE_Checkbox_Multi_Input(
365
                        array(
366
                            true => __('Yes! I want to help improve Event Espresso!', 'event_espresso')
367
                        ),
368
                        array(
369
                            'html_name' => EE_Core_Config::OPTION_NAME_UXIP,
370
                            'html_label_text' => esc_html__(
371
                                'UXIP Opt In?',
372
                                'event_espresso'
373
                            ),
374
                            'default'         => isset($this->core_config->ee_ueip_optin)
375
                                ? filter_var($this->core_config->ee_ueip_optin, FILTER_VALIDATE_BOOLEAN)
376
                                : false,
377
                            'required'        => false,
378
                        )
379
                    ),
380
                ),
381
                'organization_instagram',
382
                false
383
            );
384
        }
385
        return $form;
386
    }
387
388
389
    /**
390
     * takes the generated form and displays it along with ony other non-form HTML that may be required
391
     * returns a string of HTML that can be directly echoed in a template
392
     *
393
     * @return string
394
     * @throws EE_Error
395
     * @throws InvalidArgumentException
396
     * @throws InvalidDataTypeException
397
     * @throws InvalidInterfaceException
398
     * @throws LogicException
399
     */
400
    public function display()
401
    {
402
        $this->form()->enqueue_js();
403
        return parent::display();
404
    }
405
406
407
    /**
408
     * handles processing the form submission
409
     * returns true or false depending on whether the form was processed successfully or not
410
     *
411
     * @param array $form_data
412
     * @return bool
413
     * @throws InvalidFormSubmissionException
414
     * @throws EE_Error
415
     * @throws LogicException
416
     * @throws InvalidArgumentException
417
     * @throws InvalidDataTypeException
418
     * @throws ReflectionException
419
     */
420
    public function process($form_data = array())
421
    {
422
        // process form
423
        $valid_data = (array) parent::process($form_data);
424
        if (empty($valid_data)) {
425
            return false;
426
        }
427
428
        if (is_main_site()) {
429
            $this->network_core_config->site_license_key = isset($form_data['ee_site_license_key'])
430
                ? sanitize_text_field($form_data['ee_site_license_key'])
431
                : $this->network_core_config->site_license_key;
432
        }
433
        $this->organization_config->name = isset($form_data['organization_name'])
434
            ? sanitize_text_field($form_data['organization_name'])
435
            : $this->organization_config->name;
436
        $this->organization_config->address_1 = isset($form_data['organization_address_1'])
437
            ? sanitize_text_field($form_data['organization_address_1'])
438
            : $this->organization_config->address_1;
439
        $this->organization_config->address_2 = isset($form_data['organization_address_2'])
440
            ? sanitize_text_field($form_data['organization_address_2'])
441
            : $this->organization_config->address_2;
442
        $this->organization_config->city = isset($form_data['organization_city'])
443
            ? sanitize_text_field($form_data['organization_city'])
444
            : $this->organization_config->city;
445
        $this->organization_config->STA_ID = isset($form_data['organization_state'])
446
            ? absint($form_data['organization_state'])
447
            : $this->organization_config->STA_ID;
448
        $this->organization_config->CNT_ISO = isset($form_data['organization_country'])
449
            ? sanitize_text_field($form_data['organization_country'])
450
            : $this->organization_config->CNT_ISO;
451
        $this->organization_config->zip = isset($form_data['organization_zip'])
452
            ? sanitize_text_field($form_data['organization_zip'])
453
            : $this->organization_config->zip;
454
        $this->organization_config->email = isset($form_data['organization_email'])
455
            ? sanitize_email($form_data['organization_email'])
456
            : $this->organization_config->email;
457
        $this->organization_config->vat = isset($form_data['organization_vat'])
458
            ? sanitize_text_field($form_data['organization_vat'])
459
            : $this->organization_config->vat;
460
        $this->organization_config->phone = isset($form_data['organization_phone'])
461
            ? sanitize_text_field($form_data['organization_phone'])
462
            : $this->organization_config->phone;
463
        $this->organization_config->logo_url = isset($form_data['organization_logo_url'])
464
            ? esc_url_raw($form_data['organization_logo_url'])
465
            : $this->organization_config->logo_url;
466
        $this->organization_config->facebook = isset($form_data['organization_facebook'])
467
            ? esc_url_raw($form_data['organization_facebook'])
468
            : $this->organization_config->facebook;
469
        $this->organization_config->twitter = isset($form_data['organization_twitter'])
470
            ? esc_url_raw($form_data['organization_twitter'])
471
            : $this->organization_config->twitter;
472
        $this->organization_config->linkedin = isset($form_data['organization_linkedin'])
473
            ? esc_url_raw($form_data['organization_linkedin'])
474
            : $this->organization_config->linkedin;
475
        $this->organization_config->pinterest = isset($form_data['organization_pinterest'])
476
            ? esc_url_raw($form_data['organization_pinterest'])
477
            : $this->organization_config->pinterest;
478
        $this->organization_config->google = isset($form_data['organization_google'])
479
            ? esc_url_raw($form_data['organization_google'])
480
            : $this->organization_config->google;
481
        $this->organization_config->instagram = isset($form_data['organization_instagram'])
482
            ? esc_url_raw($form_data['organization_instagram'])
483
            : $this->organization_config->instagram;
484
        $this->core_config->ee_ueip_optin = isset($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0])
485
            ? filter_var($form_data[ EE_Core_Config::OPTION_NAME_UXIP ][0], FILTER_VALIDATE_BOOLEAN)
486
            : false;
487
        $this->core_config->ee_ueip_has_notified = true;
488
489
        $this->registry->CFG->currency = new EE_Currency_Config(
490
            $this->organization_config->CNT_ISO
491
        );
492
        /** @var EE_Country $country */
493
        $country = EEM_Country::instance()->get_one_by_ID($this->organization_config->CNT_ISO);
494
        if ($country instanceof EE_Country) {
495
            $country->set('CNT_active', 1);
496
            $country->save();
497
            $this->getCountrySubRegions($country);
498
        }
499
        return true;
500
    }
501
502
503
    /**
504
     * @param EE_Country $country
505
     * @return string
506
     * @throws EE_Error
507
     * @throws InvalidArgumentException
508
     * @throws InvalidDataTypeException
509
     * @throws InvalidInterfaceException
510
     * @throws ReflectionException
511
     */
512
    private function getCountrySubRegions(EE_Country $country)
513
    {
514
        $CNT_ISO = $country->ID();
515
        $has_sub_regions = EEM_State::instance()->count(array(array('Country.CNT_ISO' => $CNT_ISO)));
516
        if ($has_sub_regions) {
517
            return;
518
        }
519
        $json = $this->getCountryJson(
520
            'https://raw.githubusercontent.com/astockwell/countries-and-provinces-states-regions/master/countries.json'
521
        );
522
        if (is_array($json)) {
523
            foreach ($json as $country) {
524
                if ($country->code === $CNT_ISO) {
525
                    if($country->filename !== null) {
526
                        $sub_regions = $this->getCountryJson(
527
                            'https://raw.githubusercontent.com/astockwell/countries-and-provinces-states-regions/master/countries/'
528
                            . $country->filename . '.json'
529
                        );
530
                        if (is_array($sub_regions)) {
531
                            foreach ($sub_regions as $sub_region) {
532
                                $abbrev = str_replace(
533
                                    $CNT_ISO . '-',
534
                                    '',
535
                                    sanitize_text_field($sub_region->code)
536
                                );
537
                                if(absint($abbrev) !== 0){
538
                                    $abbrev = sanitize_text_field($sub_region->code);
539
                                }
540
                                EEM_State::instance()->insert(
541
                                    array(
542
                                        // STA_ID	CNT_ISO	STA_abbrev	STA_name	STA_active
543
                                        'CNT_ISO'    => $CNT_ISO,
544
                                        'STA_abbrev' => $abbrev,
545
                                        'STA_name'   => sanitize_text_field($sub_region->name),
546
                                        'STA_active' => 1,
547
                                    )
548
                                );
549
                            }
550
                        }
551
                    }
552
                }
553
            }
554
        }
555
    }
556
557
558
    /**
559
     * @param string $url
560
     * @return array
561
     */
562
    private function getCountryJson($url='')
563
    {
564
        if (empty($url)) {
565
            return array();
566
        }
567
        $request = wp_safe_remote_get($url);
568
        if (is_wp_error($request)) {
569
            return array();
570
        }
571
        $body = wp_remote_retrieve_body($request);
572
        return json_decode($body);
573
    }
574
575
576
    /**
577
     * @return string
578
     */
579
    private function uxipOptinText()
580
    {
581
        ob_start();
582
        Stats::optinText(false);
583
        return ob_get_clean();
584
    }
585
586
587
    /**
588
     * Return whether the site license key has been verified or not.
589
     * @return bool
590
     */
591
    private function licenseKeyVerified()
592
    {
593
        if (empty($this->network_core_config->site_license_key)) {
594
            return false;
595
        }
596
        $ver_option_key = 'puvererr_' . basename(EE_PLUGIN_BASENAME);
597
        $verify_fail = get_option($ver_option_key, false);
598
        return $verify_fail === false
599
                  || (! empty($this->network_core_config->site_license_key)
600
                        && $verify_fail === false
601
                  );
602
    }
603
604
605
    /**
606
     * @return EE_Text_Input
607
     */
608
    private function getSiteLicenseKeyField()
609
    {
610
        $text_input = new EE_Text_Input(
611
            array(
612
                'html_name' => 'ee_site_license_key',
613
                'html_id' => 'site_license_key',
614
                'html_label_text' => esc_html__('Support License Key', 'event_espresso'),
615
                /** phpcs:disable WordPress.WP.I18n.UnorderedPlaceholdersText */
616
                'html_help_text'  => sprintf(
617
                    esc_html__(
618
                        'Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.',
619
                        'event_espresso'
620
                    ),
621
                    '<strong>',
622
                    '</strong>'
623
                ),
624
                /** phpcs:enable */
625
                'default'         => isset($this->network_core_config->site_license_key)
626
                    ? $this->network_core_config->site_license_key
627
                    : '',
628
                'required'        => false,
629
                'form_html_filter' => new VsprintfFilter(
630
                    '%2$s %1$s',
631
                    array($this->getValidationIndicator())
632
                )
633
            )
634
        );
635
        return $text_input;
636
    }
637
638
639
    /**
640
     * @return string
641
     */
642
    private function getValidationIndicator()
643
    {
644
        $verified_class = $this->licenseKeyVerified() ? 'ee-icon-color-ee-green' : 'ee-icon-color-ee-red';
645
        return '<span class="dashicons dashicons-admin-network ' . $verified_class . ' ee-icon-size-20"></span>';
646
    }
647
}
648