1<?php
2
3/**
4 * User Control Panel.
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at http://mozilla.org/MPL/2.0/.
9 *
10 * @package phpMyFAQ
11 * @author Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2012-2020 phpMyFAQ Team
13 * @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link https://www.phpmyfaq.de
15 * @since 2012-01-12
16 */
17
18use phpMyFAQ\Services\Gravatar;
19
20if (!defined('IS_VALID_PHPMYFAQ')) {
21    http_response_code(400);
22    exit();
23}
24
25if ($user->isLoggedIn()) {
26    try {
27        $faqSession->userTracking('user_control_panel', $user->getUserId());
28    } catch (Exception $e) {
29        // @todo handle the exception
30    }
31
32    if ($faqConfig->get('main.enableGravatarSupport')) {
33        $gravatar = new Gravatar($faqConfig);
34        $gravatarImg = sprintf(
35            '<a target="_blank" href="http://www.gravatar.com">%s</a>',
36            $gravatar->getImage(
37                $user->getUserData('email'),
38                ['class' => 'img-responsive rounded-circle', 'size' => 125]
39            )
40        );
41    } else {
42        $gravatarImg = '';
43    }
44
45    $template->parse(
46        'mainPageContent',
47        [
48            'headerUserControlPanel' => $PMF_LANG['headerUserControlPanel'],
49            'ucpGravatarImage' => $gravatarImg,
50            'userid' => $user->getUserId(),
51            'csrf' => $user->getCsrfTokenFromSession(),
52            'msgRealName' => $PMF_LANG['ad_user_name'],
53            'realname' => $user->getUserData('display_name'),
54            'msgEmail' => $PMF_LANG['msgNewContentMail'],
55            'email' => $user->getUserData('email'),
56            'msgPassword' => $PMF_LANG['ad_auth_passwd'],
57            'msgConfirm' => $PMF_LANG['ad_user_confirm'],
58            'msgSave' => $PMF_LANG['msgSave'],
59            'msgCancel' => $PMF_LANG['msgCancel'],
60        ]
61    );
62
63    $template->parseBlock(
64        'index',
65        'breadcrumb',
66        [
67            'breadcrumbHeadline' => $PMF_LANG['headerUserControlPanel']
68        ]
69    );
70} else {
71    // Redirect to login
72    header('Location: ' . $faqConfig->getDefaultUrl());
73    exit();
74}
75