Completed
Branch dev (65a946)
by
unknown
35:11 queued 25:50
created

AdminOptionsSettings::display()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
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 (
122
            $this->registry->CAP->current_user_can(
123
                'manage_options',
124
                'display_admin_settings_options_promote_and_affiliate'
125
            )
126
        ) {
127
            $form->add_subsections(
128
                array(
129
                    'promote_ee_hdr'  => new EE_Form_Section_HTML(
130
                        EEH_HTML::h2(
131
                            esc_html__('Promote Event Espresso', 'event_espresso')
132
                            . ' '
133
                            . EEH_HTML::span(
134
                                EEH_Template::get_help_tab_link('affiliate_info'),
135
                                'affiliate_info'
136
                            ),
137
                            '',
138
                            'ee-admin-settings-hdr'
139
                        )
140
                    ),
141
                    'show_reg_footer' => new EE_Yes_No_Input(
142
                        array(
143
                            'html_label_text' => esc_html__(
144
                                'Link to Event Espresso in your Registration Page?',
145
                                'event_espresso'
146
                            )
147
                            . EEH_Template::get_help_tab_link('email_validation_info'),
148
                            'html_help_text'  => esc_html__(
149
                                '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.',
150
                                'event_espresso'
151
                            ),
152
                            'default'         => filter_var($this->registry->CFG->admin->show_reg_footer, FILTER_VALIDATE_BOOLEAN),
153
                            'required'        => false,
154
                        )
155
                    ),
156
                    'affiliate_id'    => new EE_Text_Input(
157
                        array(
158
                            'html_label_text' => sprintf(
159
                                esc_html__('Event Espresso %1$sAffiliate%2$s ID', 'event_espresso'),
160
                                '<a href="http://eventespresso.com/affiliates/" target="_blank">',
161
                                '</a>'
162
                            ),
163
                            'html_help_text'  => esc_html__(
164
                                'Earn cash for promoting Event Espresso.',
165
                                'event_espresso'
166
                            ),
167
                            'html_class'      => 'regular-text',
168
                            'default'         => isset($this->registry->CFG->admin->affiliate_id)
169
                                ? $this->registry->CFG->admin->get_pretty('affiliate_id')
170
                                : '',
171
                            'required'        => false,
172
                        )
173
                    ),
174
                ),
175
                // 'help_tour_activation_hdr'
176
                'compatibility_hdr'
177
            );
178
        }
179
        return $form;
180
    }
181
182
183
    /**
184
     * takes the generated form and displays it along with ony other non-form HTML that may be required
185
     * returns a string of HTML that can be directly echoed in a template
186
     *
187
     * @return string
188
     * @throws LogicException
189
     * @throws \EE_Error
190
     */
191
    public function display()
192
    {
193
        add_filter(
194
            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_FormHandler__display__before_form',
195
            array($this, 'handleOldAdminOptionsSettingsAction')
196
        );
197
        return parent::display();
198
    }
199
200
201
    /**
202
     * @return string
203
     */
204
    public function handleOldAdminOptionsSettingsAction()
205
    {
206
        ob_start();
207
        do_action('AHEE__admin_option_settings__template__before', $this->template_args);
208
        return ob_get_clean();
209
    }
210
211
212
    /**
213
     * handles processing the form submission
214
     * returns true or false depending on whether the form was processed successfully or not
215
     *
216
     * @param array $form_data
217
     * @return bool
218
     * @throws InvalidFormSubmissionException
219
     * @throws EE_Error
220
     * @throws LogicException
221
     * @throws InvalidArgumentException
222
     * @throws InvalidDataTypeException
223
     */
224
    public function process($form_data = array())
225
    {
226
        // process form
227
        $valid_data = (array) parent::process($form_data);
228
        if (empty($valid_data)) {
229
            return false;
230
        }
231
        $this->registry->CFG->admin->show_reg_footer = isset($form_data['show_reg_footer'])
232
            ? absint($form_data['show_reg_footer'])
233
            : $this->registry->CFG->admin->show_reg_footer;
234
        $this->registry->CFG->admin->affiliate_id = isset($form_data['affiliate_id'])
235
            ? sanitize_text_field($form_data['affiliate_id'])
236
            : $this->registry->CFG->admin->affiliate_id;
237
        // $this->registry->CFG->admin->help_tour_activation = isset($form_data['help_tour_activation'])
238
        //     ? absint($form_data['help_tour_activation'])
239
        //     : $this->registry->CFG->admin->help_tour_activation;
240
        if (isset($form_data['encode_session_data'])) {
241
            $this->registry->CFG->admin->set_encode_session_data($form_data['encode_session_data']);
242
        }
243
        return false;
244
    }
245
}
246