Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 368
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ucp_register
0.00% covered (danger)
0.00%
0 / 366
0.00% covered (danger)
0.00%
0 / 3
5852
0.00% covered (danger)
0.00%
0 / 1
 main
0.00% covered (danger)
0.00%
0 / 353
0.00% covered (danger)
0.00%
0 / 1
5112
 get_login_link_data_array
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
12
 get_login_link_data_for_hidden_fields
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @ignore
16*/
17if (!defined('IN_PHPBB'))
18{
19    exit;
20}
21
22/**
23* ucp_register
24* Board registration
25*/
26class ucp_register
27{
28    var $u_action;
29
30    function main($id, $mode)
31    {
32        global $config, $db, $user, $template, $phpbb_root_path, $phpEx;
33        global $request, $phpbb_container, $phpbb_dispatcher;
34
35        //
36        if ($config['require_activation'] == USER_ACTIVATION_DISABLE ||
37            (in_array($config['require_activation'], array(USER_ACTIVATION_SELF, USER_ACTIVATION_ADMIN)) && !$config['email_enable']))
38        {
39            trigger_error('UCP_REGISTER_DISABLE');
40        }
41
42        $coppa            = $request->is_set('coppa_yes') ? 1 : ($request->is_set('coppa_no') ? 0 : false);
43        $coppa            = $request->is_set('coppa') ? $request->variable('coppa', 0) : $coppa;
44        $agreed            = $request->variable('agreed', false);
45        $submit            = $request->is_set_post('submit');
46        $change_lang    = $request->variable('change_lang', '');
47        $user_lang        = $request->variable('lang', $user->lang_name);
48
49        if ($agreed && !check_form_key('ucp_register'))
50        {
51            $agreed = false;
52        }
53
54        if ($coppa !== false && !check_form_key('ucp_register'))
55        {
56            $coppa = false;
57        }
58
59        /**
60        * Add UCP register data before they are assigned to the template or submitted
61        *
62        * To assign data to the template, use $template->assign_vars()
63        *
64        * @event core.ucp_register_requests_after
65        * @var    bool    coppa        Is set coppa
66        * @var    bool    agreed        Did user agree to coppa?
67        * @var    bool    submit        Is set post submit?
68        * @var    string    change_lang    Change language request
69        * @var    string    user_lang    User language request
70        * @since 3.1.11-RC1
71        */
72        $vars = array(
73            'coppa',
74            'agreed',
75            'submit',
76            'change_lang',
77            'user_lang',
78        );
79        extract($phpbb_dispatcher->trigger_event('core.ucp_register_requests_after', compact($vars)));
80
81        add_form_key('ucp_register');
82
83        if ($change_lang || $user_lang != $config['default_lang'])
84        {
85            $use_lang = ($change_lang) ? basename($change_lang) : basename($user_lang);
86
87            if (!validate_language_iso_name($use_lang))
88            {
89                if ($change_lang)
90                {
91                    $submit = false;
92
93                    // Setting back agreed to let the user view the agreement in his/her language
94                    $agreed = false;
95                }
96
97                $user_lang = $use_lang;
98            }
99            else
100            {
101                $change_lang = '';
102                $user_lang = $user->lang_name;
103            }
104        }
105
106        /* @var $cp \phpbb\profilefields\manager */
107        $cp = $phpbb_container->get('profilefields.manager');
108
109        $error = $cp_data = array();
110        $s_hidden_fields = array();
111
112        // Handle login_link data added to $_hidden_fields
113        $login_link_data = $this->get_login_link_data_array();
114
115        if (!empty($login_link_data))
116        {
117            // Confirm that we have all necessary data
118            /* @var $provider_collection \phpbb\auth\provider_collection */
119            $provider_collection = $phpbb_container->get('auth.provider_collection');
120            $auth_provider = $provider_collection->get_provider($request->variable('auth_provider', ''));
121
122            $result = $auth_provider->login_link_has_necessary_data($login_link_data);
123            if ($result !== null)
124            {
125                $error[] = $user->lang[$result];
126            }
127
128            $s_hidden_fields = array_merge($s_hidden_fields, $this->get_login_link_data_for_hidden_fields($login_link_data));
129        }
130
131        if (!$agreed || ($coppa === false && $config['coppa_enable']) || ($coppa && !$config['coppa_enable']))
132        {
133            $add_coppa = ($coppa !== false) ? '&amp;coppa=' . $coppa : '';
134
135            $s_hidden_fields = array_merge($s_hidden_fields, array(
136                'change_lang'    => '',
137            ));
138
139            // If we change the language, we want to pass on some more possible parameter.
140            if ($change_lang)
141            {
142                // We do not include the password
143                $s_hidden_fields = array_merge($s_hidden_fields, array(
144                    'username'            => $request->variable('username', '', true),
145                    'email'                => strtolower($request->variable('email', '')),
146                    'lang'                => $user->lang_name,
147                    'tz'                => $request->variable('tz', $config['board_timezone']),
148                ));
149
150            }
151
152            // Checking amount of available languages
153            $sql = 'SELECT lang_iso, lang_local_name
154                FROM ' . LANG_TABLE . '
155                ORDER BY lang_english_name';
156            $result = $db->sql_query($sql);
157            $lang_row = (array) $db->sql_fetchrowset($result);
158            $db->sql_freeresult($result);
159
160            $lang_options = phpbb_language_select($db, $user_lang, $lang_row);
161
162            if ($coppa === false && $config['coppa_enable'])
163            {
164                $now = getdate();
165                $coppa_birthday = $user->create_datetime()
166                    ->setDate($now['year'] - 13, $now['mon'], $now['mday'] - 1)
167                    ->setTime(0, 0, 0)
168                    ->format($user->lang['DATE_FORMAT'], true);
169                unset($now);
170
171                $template_vars = array(
172                    'LANG_OPTIONS'        => [
173                        'id'        => 'lang',
174                        'name'        => 'lang',
175                        'options'    => $lang_options,
176                    ],
177                    'L_COPPA_NO'        => $user->lang('UCP_COPPA_BEFORE', $coppa_birthday),
178                    'L_COPPA_YES'        => $user->lang('UCP_COPPA_ON_AFTER', $coppa_birthday),
179
180                    'S_SHOW_COPPA'        => true,
181                    'S_HIDDEN_FIELDS'    => build_hidden_fields($s_hidden_fields),
182                    'S_UCP_ACTION'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
183
184                    'COOKIE_NAME'        => $config['cookie_name'],
185                    'COOKIE_PATH'        => $config['cookie_path'],
186                );
187            }
188            else
189            {
190                $template_vars = array(
191                    'LANG_OPTIONS'        => [
192                        'id'        => 'lang',
193                        'name'        => 'lang',
194                        'options'    => $lang_options,
195                    ],
196                    'L_TERMS_OF_USE'    => sprintf($user->lang['TERMS_OF_USE_CONTENT'], $config['sitename'], generate_board_url()),
197
198                    'S_SHOW_COPPA'        => false,
199                    'S_REGISTRATION'    => true,
200                    'S_HIDDEN_FIELDS'    => build_hidden_fields($s_hidden_fields),
201                    'S_UCP_ACTION'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register' . $add_coppa),
202
203                    'COOKIE_NAME'        => $config['cookie_name'],
204                    'COOKIE_PATH'        => $config['cookie_path'],
205                );
206            }
207
208            $tpl_name = 'ucp_agreement';
209
210            /**
211            * Allows to modify the agreements.
212            *
213            * @event core.ucp_register_agreement_modify_template_data
214            * @var    string    tpl_name            Template file
215            * @var    array    template_vars        Array with data about to be assigned to the template
216            * @var    array    s_hidden_fields        Array with hidden form elements
217            * @var    array    lang_row            Array with available languages, read only
218            * @since 3.2.2-RC1
219            */
220            $vars = array('tpl_name', 'template_vars', 's_hidden_fields', 'lang_row');
221            extract($phpbb_dispatcher->trigger_event('core.ucp_register_agreement_modify_template_data', compact($vars)));
222
223            unset($lang_row);
224
225            $template_vars = array_merge($template_vars, array(
226                'S_HIDDEN_FIELDS' => build_hidden_fields($s_hidden_fields),
227            ));
228
229            $template->assign_vars($template_vars);
230
231            $this->tpl_name = $tpl_name;
232            return;
233        }
234
235        // The CAPTCHA kicks in here. We can't help that the information gets lost on language change.
236        if ($config['enable_confirm'])
237        {
238            /** @var \phpbb\captcha\factory $captcha_factory */
239            $captcha_factory = $phpbb_container->get('captcha.factory');
240            $captcha = $captcha_factory->get_instance($config['captcha_plugin']);
241            $captcha->init(\phpbb\captcha\plugins\confirm_type::REGISTRATION);
242        }
243
244        $timezone = $config['board_timezone'];
245
246        $data = array(
247            'username'            => $request->variable('username', '', true),
248            'new_password'        => $request->variable('new_password', '', true),
249            'password_confirm'    => $request->variable('password_confirm', '', true),
250            'email'                => strtolower($request->variable('email', '')),
251            'lang'                => basename($request->variable('lang', $user->lang_name)),
252            'tz'                => $request->variable('tz', $timezone),
253        );
254        /**
255        * Add UCP register data before they are assigned to the template or submitted
256        *
257        * To assign data to the template, use $template->assign_vars()
258        *
259        * @event core.ucp_register_data_before
260        * @var    bool    submit        Do we display the form only
261        *                            or did the user press submit
262        * @var    array    data        Array with current ucp registration data
263        * @since 3.1.4-RC1
264        */
265        $vars = array('submit', 'data');
266        extract($phpbb_dispatcher->trigger_event('core.ucp_register_data_before', compact($vars)));
267
268        // Check and initialize some variables if needed
269        if ($submit)
270        {
271            $error = validate_data($data, array(
272                'username'            => array(
273                    array('string', false, $config['min_name_chars'], $config['max_name_chars']),
274                    array('username', '')),
275                'new_password'        => array(
276                    array('string', false, $config['min_pass_chars'], 0),
277                    array('password')),
278                'password_confirm'    => array('string', false, $config['min_pass_chars'], 0),
279                'email'                => array(
280                    array('string', false, 6, 60),
281                    array('user_email')),
282                'tz'                => array('timezone'),
283                'lang'                => array('language_iso_name'),
284            ));
285
286            if (!check_form_key('ucp_register'))
287            {
288                $error[] = $user->lang['FORM_INVALID'];
289            }
290
291            // Replace "error" strings with their real, localised form
292            $error = array_map(array($user, 'lang'), $error);
293
294            if ($config['enable_confirm'])
295            {
296                if ($captcha->validate() !== true)
297                {
298                    $error[] = $captcha->get_error();
299                }
300
301                if ($config['max_reg_attempts'] && $captcha->get_attempt_count() > $config['max_reg_attempts'])
302                {
303                    trigger_error('TOO_MANY_REGISTERS');
304                }
305            }
306
307            // DNSBL check
308            if ($config['check_dnsbl'])
309            {
310                if (($dnsbl = $user->check_dnsbl('register')) !== false)
311                {
312                    $error[] = sprintf($user->lang['IP_BLACKLISTED'], $user->ip, $dnsbl[1]);
313                }
314            }
315
316            // validate custom profile fields
317            $cp->submit_cp_field('register', $user->get_iso_lang_id(), $cp_data, $error);
318
319            if (!count($error))
320            {
321                if ($data['new_password'] != $data['password_confirm'])
322                {
323                    $error[] = $user->lang['NEW_PASSWORD_ERROR'];
324                }
325            }
326            /**
327            * Check UCP registration data after they are submitted
328            *
329            * @event core.ucp_register_data_after
330            * @var    bool    submit        Do we display the form only
331            *                            or did the user press submit
332            * @var    array     data        Array with current ucp registration data
333            * @var    array    cp_data        Array with custom profile fields data
334            * @var    array     error        Array with list of errors
335            * @since 3.1.4-RC1
336            */
337            $vars = array('submit', 'data', 'cp_data', 'error');
338            extract($phpbb_dispatcher->trigger_event('core.ucp_register_data_after', compact($vars)));
339
340            if (!count($error))
341            {
342                $server_url = generate_board_url();
343
344                // Which group by default?
345                $group_name = ($coppa) ? 'REGISTERED_COPPA' : 'REGISTERED';
346
347                $sql = 'SELECT group_id
348                    FROM ' . GROUPS_TABLE . "
349                    WHERE group_name = '" . $db->sql_escape($group_name) . "'
350                        AND group_type = " . GROUP_SPECIAL;
351                $result = $db->sql_query($sql);
352                $row = $db->sql_fetchrow($result);
353                $db->sql_freeresult($result);
354
355                if (!$row)
356                {
357                    trigger_error('NO_GROUP');
358                }
359
360                $group_id = $row['group_id'];
361
362                if (($coppa ||
363                    $config['require_activation'] == USER_ACTIVATION_SELF ||
364                    $config['require_activation'] == USER_ACTIVATION_ADMIN) && $config['email_enable'])
365                {
366                    $user_actkey = strtolower(gen_rand_string(32));
367                    $user_type = USER_INACTIVE;
368                    $user_inactive_reason = INACTIVE_REGISTER;
369                    $user_inactive_time = time();
370                }
371                else
372                {
373                    $user_type = USER_NORMAL;
374                    $user_actkey = '';
375                    $user_inactive_reason = 0;
376                    $user_inactive_time = 0;
377                }
378
379                // Instantiate passwords manager
380                /* @var $passwords_manager \phpbb\passwords\manager */
381                $passwords_manager = $phpbb_container->get('passwords.manager');
382
383                $user_row = array(
384                    'username'                    => $data['username'],
385                    'user_password'                => $passwords_manager->hash($data['new_password']),
386                    'user_email'                => $data['email'],
387                    'group_id'                    => (int) $group_id,
388                    'user_timezone'                => $data['tz'],
389                    'user_lang'                    => $data['lang'],
390                    'user_type'                    => $user_type,
391                    'user_actkey'                => $user_actkey,
392                    'user_actkey_expiration'    => $user::get_token_expiration(),
393                    'user_ip'                    => $user->ip,
394                    'user_regdate'                => time(),
395                    'user_inactive_reason'        => $user_inactive_reason,
396                    'user_inactive_time'        => $user_inactive_time,
397                );
398
399                if ($config['new_member_post_limit'])
400                {
401                    $user_row['user_new'] = 1;
402                }
403                /**
404                * Add into $user_row before user_add
405                *
406                * user_add allows adding more data into the users table
407                *
408                * @event core.ucp_register_user_row_after
409                * @var    bool    submit        Do we display the form only
410                *                            or did the user press submit
411                * @var    array    data        Array with current ucp registration data
412                * @var    array    cp_data        Array with custom profile fields data
413                * @var    array    user_row    Array with user data that will be inserted
414                * @since 3.1.4-RC1
415                * @changed 3.2.10-RC1 Added data array
416                */
417                $vars = array('submit', 'data', 'cp_data', 'user_row');
418                extract($phpbb_dispatcher->trigger_event('core.ucp_register_user_row_after', compact($vars)));
419
420                // Register user...
421                $user_id = user_add($user_row, $cp_data);
422
423                // This should not happen, because the required variables are listed above...
424                if ((bool) $user_id === false)
425                {
426                    trigger_error('NO_USER', E_USER_ERROR);
427                }
428
429                // Okay, captcha, your job is done.
430                if ($config['enable_confirm'])
431                {
432                    $captcha->reset();
433                }
434
435                if ($coppa && $config['email_enable'])
436                {
437                    $message = $user->lang['ACCOUNT_COPPA'];
438                    $email_template = 'coppa_welcome_inactive';
439                }
440                else if ($config['require_activation'] == USER_ACTIVATION_SELF && $config['email_enable'])
441                {
442                    $message = $user->lang['ACCOUNT_INACTIVE'];
443                    $email_template = 'user_welcome_inactive';
444                }
445                else if ($config['require_activation'] == USER_ACTIVATION_ADMIN && $config['email_enable'])
446                {
447                    $message = $user->lang['ACCOUNT_INACTIVE_ADMIN'];
448                    $email_template = 'admin_welcome_inactive';
449                }
450                else
451                {
452                    $message = $user->lang['ACCOUNT_ADDED'];
453                    $email_template = 'user_welcome';
454
455                    // Autologin after registration
456                    $user->session_create($user_id, 0, false, 1);
457                }
458
459                if ($config['email_enable'])
460                {
461                    /** var \phpbb\messenger\method\email */
462                    $email_method = $phpbb_container->get('messenger.method.email');
463                    $email_method->set_use_queue(false);
464                    $email_method->template($email_template, $data['lang']);
465                    $email_method->to($data['email'], $data['username']);
466                    $email_method->anti_abuse_headers($config, $user);
467                    $email_method->assign_vars([
468                        'WELCOME_MSG'    => html_entity_decode(sprintf($user->lang['WELCOME_SUBJECT'], $config['sitename']), ENT_COMPAT),
469                        'USERNAME'        => html_entity_decode($data['username'], ENT_COMPAT),
470                        'PASSWORD'        => html_entity_decode($data['new_password'], ENT_COMPAT),
471                        'U_ACTIVATE'    => "$server_url/ucp.$phpEx?mode=activate&u=$user_id&k=$user_actkey",
472                    ]);
473
474                    if ($coppa)
475                    {
476                        $email_method->assign_vars([
477                            'FAX_INFO'        => $config['coppa_fax'],
478                            'MAIL_INFO'        => $config['coppa_mail'],
479                            'EMAIL_ADDRESS'    => $data['email'],
480                        ]);
481                    }
482
483                    /**
484                    * Modify messenger data before welcome mail is sent
485                    *
486                    * @event core.ucp_register_welcome_email_before
487                    * @var    array        user_row    Array with user registration data
488                    * @var    array        cp_data        Array with custom profile fields data
489                    * @var    array        data        Array with current ucp registration data
490                    * @var    string        message        Message to be displayed to the user after registration
491                    * @var    string        server_url    Server URL
492                    * @var    int            user_id        New user ID
493                    * @var    string        user_actkey    User activation key
494                    * @var    \phpbb\messenger\method\email    email_method    phpBB email notification method
495                    * @since 3.2.4-RC1
496                    * @changed 4.0.0-a1 Added vars: email_method. Removed vars: messenger.
497                    */
498                    $vars = array(
499                        'user_row',
500                        'cp_data',
501                        'data',
502                        'message',
503                        'server_url',
504                        'user_id',
505                        'user_actkey',
506                        'email_method',
507                    );
508                    extract($phpbb_dispatcher->trigger_event('core.ucp_register_welcome_email_before', compact($vars)));
509
510                    $email_method->send();
511                }
512
513                if ($config['require_activation'] == USER_ACTIVATION_ADMIN)
514                {
515                    /* @var $phpbb_notifications \phpbb\notification\manager */
516                    $phpbb_notifications = $phpbb_container->get('notification_manager');
517                    $phpbb_notifications->add_notifications('notification.type.admin_activate_user', array(
518                        'user_id'        => $user_id,
519                        'user_actkey'    => $user_row['user_actkey'],
520                        'user_regdate'    => $user_row['user_regdate'],
521                    ));
522                }
523
524                // Perform account linking if necessary
525                if (!empty($login_link_data))
526                {
527                    $login_link_data['user_id'] = $user_id;
528
529                    $result = $auth_provider->link_account($login_link_data);
530
531                    if ($result)
532                    {
533                        $message = $message . '<br /><br />' . $user->lang[$result];
534                    }
535                }
536
537                /**
538                * Perform additional actions after user registration
539                *
540                * @event core.ucp_register_register_after
541                * @var    array        user_row    Array with user registration data
542                * @var    array        cp_data        Array with custom profile fields data
543                * @var    array        data        Array with current ucp registration data
544                * @var    string        message        Message to be displayed to the user after registration
545                * @var    string        server_url    Server URL
546                * @var    int            user_id        New user ID
547                * @var    string        user_actkey    User activation key
548                * @since 3.2.4-RC1
549                */
550                $vars = array(
551                    'user_row',
552                    'cp_data',
553                    'data',
554                    'message',
555                    'server_url',
556                    'user_id',
557                    'user_actkey',
558                );
559                extract($phpbb_dispatcher->trigger_event('core.ucp_register_register_after', compact($vars)));
560
561                $message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a>');
562                trigger_error($message);
563            }
564        }
565
566        $s_hidden_fields = array_merge($s_hidden_fields, array(
567            'agreed'        => 'true',
568            'change_lang'    => 0,
569        ));
570
571        if ($config['coppa_enable'])
572        {
573            $s_hidden_fields['coppa'] = $coppa;
574        }
575
576        if ($config['enable_confirm'])
577        {
578            $s_hidden_fields = array_merge($s_hidden_fields, $captcha->get_hidden_fields());
579        }
580
581        // Visual Confirmation - Show images
582        if ($config['enable_confirm'])
583        {
584            $template->assign_vars(array(
585                'CAPTCHA_TEMPLATE'        => $captcha->get_template(),
586            ));
587        }
588
589        //
590        $l_reg_cond = '';
591        switch ($config['require_activation'])
592        {
593            case USER_ACTIVATION_SELF:
594                $l_reg_cond = $user->lang['UCP_EMAIL_ACTIVATE'];
595            break;
596
597            case USER_ACTIVATION_ADMIN:
598                $l_reg_cond = $user->lang['UCP_ADMIN_ACTIVATE'];
599            break;
600        }
601
602        /* @var $provider_collection \phpbb\auth\provider_collection */
603        $provider_collection = $phpbb_container->get('auth.provider_collection');
604        $auth_provider = $provider_collection->get_provider();
605
606        $auth_provider_data = $auth_provider->get_login_data();
607        if ($auth_provider_data)
608        {
609            if (isset($auth_provider_data['VARS']))
610            {
611                $template->assign_vars($auth_provider_data['VARS']);
612            }
613
614            if (isset($auth_provider_data['BLOCK_VAR_NAME']))
615            {
616                foreach ($auth_provider_data['BLOCK_VARS'] as $block_vars)
617                {
618                    $template->assign_block_vars($auth_provider_data['BLOCK_VAR_NAME'], $block_vars);
619                }
620            }
621
622            $template->assign_vars(array(
623                'PROVIDER_TEMPLATE_FILE' => $auth_provider_data['TEMPLATE_FILE'],
624            ));
625        }
626
627        // Assign template vars for timezone select
628        $timezone_select = phpbb_timezone_select($user, $data['tz'], true);
629
630        // Checking amount of available languages
631        $sql = 'SELECT lang_iso, lang_local_name
632            FROM ' . LANG_TABLE . '
633            ORDER BY lang_english_name';
634        $result = $db->sql_query($sql);
635        $lang_row = (array) $db->sql_fetchrowset($result);
636        $db->sql_freeresult($result);
637
638        $lang_options = phpbb_language_select($db, $data['lang'], $lang_row);
639
640        $template_vars = array(
641            'USERNAME'            => $data['username'],
642            'PASSWORD'            => $data['new_password'],
643            'PASSWORD_CONFIRM'    => $data['password_confirm'],
644            'EMAIL'                => $data['email'],
645
646            'L_REG_COND'                => $l_reg_cond,
647            'L_USERNAME_EXPLAIN'        => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS_XY', (int) $config['min_name_chars']), $user->lang('CHARACTERS_XY', (int) $config['max_name_chars'])),
648            'L_PASSWORD_EXPLAIN'        => $user->lang($config['pass_complex'] . '_EXPLAIN', $user->lang('CHARACTERS_XY', (int) $config['min_pass_chars'])),
649
650            'LANG_OPTIONS'        => [
651                'id'        => 'lang',
652                'name'        => 'lang',
653                'options'    => $lang_options,
654            ],
655            'TIMEZONE_OPTIONS'    => [
656                'tag'        => 'select',
657                'name'        => 'tz',
658                'options'    => $timezone_select,
659            ],
660            'S_TZ_PRESELECT'    => !$submit,
661            'S_CONFIRM_REFRESH'    => ($config['enable_confirm'] && $config['confirm_refresh']) ? true : false,
662            'S_REGISTRATION'    => true,
663            'S_COPPA'            => $coppa,
664            'S_UCP_ACTION'        => append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=register'),
665
666            'COOKIE_NAME'        => $config['cookie_name'],
667            'COOKIE_PATH'        => $config['cookie_path'],
668        );
669
670        $tpl_name = 'ucp_register';
671
672        /**
673        * Modify template data on the registration page
674        *
675        * @event core.ucp_register_modify_template_data
676        * @var    array    template_vars        Array with template data
677        * @var    array    data                Array with user data, read only
678        * @var    array    error                Array with errors
679        * @var    array    s_hidden_fields        Array with hidden field elements
680        * @var    string    tpl_name            Template name
681        * @since 3.2.2-RC1
682        */
683        $vars = array(
684            'template_vars',
685            'data',
686            'error',
687            's_hidden_fields',
688            'tpl_name',
689        );
690        extract($phpbb_dispatcher->trigger_event('core.ucp_register_modify_template_data', compact($vars)));
691
692        $template_vars = array_merge($template_vars, array(
693            'ERROR'                => (count($error)) ? implode('<br />', $error) : '',
694            'S_HIDDEN_FIELDS'    => build_hidden_fields($s_hidden_fields),
695        ));
696
697        $template->assign_vars($template_vars);
698
699        //
700        $user->profile_fields = array();
701
702        // Generate profile fields -> Template Block Variable profile_fields
703        $cp->generate_profile_fields('register', $user->get_iso_lang_id());
704
705        //
706        $this->tpl_name = $tpl_name;
707    }
708
709    /**
710    * Creates the login_link data array
711    *
712    * @return    array    Returns an array of all POST paramaters whose names
713    *                    begin with 'login_link_'
714    */
715    protected function get_login_link_data_array()
716    {
717        global $request;
718
719        $var_names = $request->variable_names(\phpbb\request\request_interface::POST);
720        $login_link_data = array();
721        $string_start_length = strlen('login_link_');
722
723        foreach ($var_names as $var_name)
724        {
725            if (strpos($var_name, 'login_link_') === 0)
726            {
727                $key_name = substr($var_name, $string_start_length);
728                $login_link_data[$key_name] = $request->variable($var_name, '', false, \phpbb\request\request_interface::POST);
729            }
730        }
731
732        return $login_link_data;
733    }
734
735    /**
736    * Prepends they key names of an associative array with 'login_link_' for
737    * inclusion on the page as hidden fields.
738    *
739    * @param    array    $data    The array to be modified
740    * @return    array    The modified array
741    */
742    protected function get_login_link_data_for_hidden_fields($data)
743    {
744        $new_data = array();
745
746        foreach ($data as $key => $value)
747        {
748            $new_data['login_link_' . $key] = $value;
749        }
750
751        return $new_data;
752    }
753}