Completed
Branch disable-help-tours (44228e)
by
unknown
41:31 queued 32:56
created

AdminOptionsSettings::process()   A

Complexity

Conditions 5
Paths 9

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
nc 9
nop 1
dl 0
loc 21
rs 9.2728
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\admin_pages\general_settings;
4
5
use EE_Admin_Two_Column_Layout;
6
use EE_Error;
7
use EE_Form_Section_HTML;
8
use EE_Form_Section_Proper;
9
use EE_Text_Input;
10
use EE_Yes_No_Input;
11
use EEH_HTML;
12
use EEH_Template;
13
use EventEspresso\core\exceptions\InvalidDataTypeException;
14
use EventEspresso\core\exceptions\InvalidFormSubmissionException;
15
use EventEspresso\core\libraries\form_sections\form_handlers\FormHandler;
16
use InvalidArgumentException;
17
use LogicException;
18
19
/**
20
 * Class AdminOptionsSettings
21
 * class for handling admin options settings
22
 *
23
 * @package       Event Espresso
24
 * @author        Brent Christensen
25
 */
26
class AdminOptionsSettings extends FormHandler
27
{
28
29
    protected $template_args = array();
30
31
    /**
32
     * Form constructor.
33
     *
34
     * @param \EE_Registry $registry
35
     */
36
    public function __construct(\EE_Registry $registry)
37
    {
38
        parent::__construct(
39
            esc_html__('Admin Options', 'event_espresso'),
40
            esc_html__('Admin Options', 'event_espresso'),
41
            'admin_option_settings',
42
            '',
43
            FormHandler::DO_NOT_SETUP_FORM,
44
            $registry
45
        );
46
    }
47
48
49
    /**
50
     * @param array $template_args
51
     */
52
    public function setTemplateArgs(array $template_args)
53
    {
54
        $this->template_args = $template_args;
55
    }
56
57
58
    /**
59
     * creates and returns the actual form
60
     *
61
     * @return EE_Form_Section_Proper
62
     * @throws EE_Error
63
     */
64
    public function generate()
65
    {
66
        $form = new \EE_Form_Section_Proper(
67
            array(
68
                'name'            => 'admin_option_settings',
69
                'html_id'         => 'admin_option_settings',
70
                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
71
                'subsections'     => array(
72
                    // 'help_tour_activation_hdr' => new EE_Form_Section_HTML(
73
                    //     EEH_HTML::h2(
74
                    //         esc_html__('Help Tour Global Activation', 'event_espresso')
75
                    //         . ' '
76
                    //         . EEH_HTML::span(
77
                    //             EEH_Template::get_help_tab_link('help_tour_activation_info'),
78
                    //             'help_tour_activation'
79
                    //         ),
80
                    //         '',
81
                    //         'ee-admin-settings-hdr'
82
                    //     )
83
                    // ),
84
                    // 'help_tour_activation'     => new EE_Yes_No_Input(
85
                    //     array(
86
                    //         'html_label_text' => esc_html__('Activate Global Help Tours?', 'event_espresso'),
87
                    //         'html_help_text'  => esc_html__(
88
                    //             'This toggles whether the Event Espresso help tours are active globally or not.',
89
                    //             'event_espresso'
90
                    //         ),
91
                    //         'default'         => isset($this->registry->CFG->admin->help_tour_activation)
92
                    //             ? filter_var($this->registry->CFG->admin->help_tour_activation, FILTER_VALIDATE_BOOLEAN)
93
                    //             : true,
94
                    //         'required'        => false,
95
                    //     )
96
                    // ),
97
                    'compatibility_hdr'        => new EE_Form_Section_HTML(
98
                        EEH_HTML::h2(
99
                            esc_html__('Compatibility Settings', 'event_espresso'),
100
                            '',
101
                            'ee-admin-settings-hdr'
102
                        )
103
                    ),
104
                    'encode_session_data'      => new EE_Yes_No_Input(
105
                        array(
106
                            'html_label_text' => esc_html__('Encode Session Data?', 'event_espresso'),
107
                            'html_help_text'  => sprintf(
108
                                esc_html__(
109
                                    'Some servers and database configurations can cause problems when saving the Event Espresso session data. Setting this option to "Yes" adds an extra layer of encoding to session data to prevent serialization errors, but can be incompatible with some server configurations.%1$sIf you receive "500 internal server" type errors during registration, try turning this option on.%1$sIf you get fatal PHP errors regarding missing base64 functions, then turn this option off.',
110
                                    'event_espresso'
111
                                ),
112
                                '<br>'
113
                            ),
114
                            'default'         => $this->registry->CFG->admin->encode_session_data(),
115
                            'required'        => false,
116
                        )
117
                    ),
118
                ),
119
            )
120
        );
121
        if ($this->registry->CAP->current_user_can(
122
            'manage_options',
123
            'display_admin_settings_options_promote_and_affiliate'
124
        )) {
125
            $form->add_subsections(
126
                array(
127
                    'promote_ee_hdr'  => new EE_Form_Section_HTML(
128
                        EEH_HTML::h2(
129
                            esc_html__('Promote Event Espresso', 'event_espresso')
130
                            . ' '
131
                            . EEH_HTML::span(
132
                                EEH_Template::get_help_tab_link('affiliate_info'),
133
                                'affiliate_info'
134
                            ),
135
                            '',
136
                            'ee-admin-settings-hdr'
137
                        )
138
                    ),
139
                    'show_reg_footer' => new EE_Yes_No_Input(
140
                        array(
141
                            'html_label_text' => esc_html__(
142
                                'Link to Event Espresso in your Registration Page?',
143
                                'event_espresso'
144
                            )
145
                            . EEH_Template::get_help_tab_link('email_validation_info'),
146
                            'html_help_text'  => esc_html__(
147
                                'adds an unobtrusive link to Event Espresso\'s website in the footer of your registration form. Get an affiliate link (see below) and make money if people click the link and purchase Event Espresso.',
148
                                'event_espresso'
149
                            ),
150
                            'default'         => filter_var($this->registry->CFG->admin->show_reg_footer, FILTER_VALIDATE_BOOLEAN),
151
                            'required'        => false,
152
                        )
153
                    ),
154
                    'affiliate_id'    => new EE_Text_Input(
155
                        array(
156
                            'html_label_text' => sprintf(
157
                                esc_html__('Event Espresso %1$sAffiliate%2$s ID', 'event_espresso'),
158
                                '<a href="http://eventespresso.com/affiliates/" target="_blank">',
159
                                '</a>'
160
                            ),
161
                            'html_help_text'  => esc_html__(
162
                                'Earn cash for promoting Event Espresso.',
163
                                'event_espresso'
164
                            ),
165
                            'html_class'      => 'regular-text',
166
                            'default'         => isset($this->registry->CFG->admin->affiliate_id)
167
                                ? $this->registry->CFG->admin->get_pretty('affiliate_id')
168
                                : '',
169
                            'required'        => false,
170
                        )
171
                    ),
172
                ),
173
                // 'help_tour_activation_hdr'
174
                'compatibility_hdr'
175
            );
176
        }
177
        return $form;
178
    }
179
180
181
    /**
182
     * takes the generated form and displays it along with ony other non-form HTML that may be required
183
     * returns a string of HTML that can be directly echoed in a template
184
     *
185
     * @return string
186
     * @throws LogicException
187
     * @throws \EE_Error
188
     */
189
    public function display()
190
    {
191
        add_filter(
192
            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
193
            array($this, 'handleOldAdminOptionsSettingsAction')
194
        );
195
        return parent::display();
196
    }
197
198
199
    /**
200
     * @return string
201
     */
202
    public function handleOldAdminOptionsSettingsAction()
203
    {
204
        ob_start();
205
        do_action('AHEE__admin_option_settings__template__before', $this->template_args);
206
        return ob_get_clean();
207
    }
208
209
210
    /**
211
     * handles processing the form submission
212
     * returns true or false depending on whether the form was processed successfully or not
213
     *
214
     * @param array $form_data
215
     * @return bool
216
     * @throws InvalidFormSubmissionException
217
     * @throws EE_Error
218
     * @throws LogicException
219
     * @throws InvalidArgumentException
220
     * @throws InvalidDataTypeException
221
     */
222
    public function process($form_data = array())
223
    {
224
        // process form
225
        $valid_data = (array) parent::process($form_data);
226
        if (empty($valid_data)) {
227
            return false;
228
        }
229
        $this->registry->CFG->admin->show_reg_footer = isset($form_data['show_reg_footer'])
230
            ? absint($form_data['show_reg_footer'])
231
            : $this->registry->CFG->admin->show_reg_footer;
232
        $this->registry->CFG->admin->affiliate_id = isset($form_data['affiliate_id'])
233
            ? sanitize_text_field($form_data['affiliate_id'])
234
            : $this->registry->CFG->admin->affiliate_id;
235
        // $this->registry->CFG->admin->help_tour_activation = isset($form_data['help_tour_activation'])
236
        //     ? absint($form_data['help_tour_activation'])
237
        //     : $this->registry->CFG->admin->help_tour_activation;
238
        if (isset($form_data['encode_session_data'])) {
239
            $this->registry->CFG->admin->set_encode_session_data($form_data['encode_session_data']);
240
        }
241
        return false;
242
    }
243
}
244