Completed
Push — master ( 72613d...069c91 )
by Michael
02:16
created

public-sendecard.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * ExtGallery User area
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   {@link https://xoops.org/ XOOPS Project}
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Zoullou (http://www.zoullou.net)
15
 * @package     ExtGallery
16
 */
17
18
include __DIR__ . '/header.php';
19
require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/publicPerm.php';
20
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
21
22
if (isset($_GET['id'])) {
23
    $photoId = (int)$_GET['id'];
24
} elseif (isset($_POST['photo_id'])) {
25
    $photoId = (int)$_POST['photo_id'];
26
} else {
27
    $photoId = 0;
28
}
29
if (isset($_POST['step'])) {
30
    $step = $_POST['step'];
31
} else {
32
    $step = 'default';
33
}
34
/** @var ExtgalleryPublicPhotoHandler $photoHandler */
35
$photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
36
$photo        = $photoHandler->getPhoto($photoId);
37
38
$permHandler = ExtgalleryPublicPermHandler::getInstance();
39
40 View Code Duplication
if (!$permHandler->isAllowed($GLOBALS['xoopsUser'], 'public_ecard', $photo->getVar('cat_id'))) {
41
    redirect_header('index.php', 3, _MD_EXTGALLERY_NOPERM);
42
}
43
/** @var xos_opal_Theme $xoTheme */
44
switch ($step) {
45
46
    case 'send':
47
48
        require_once XOOPS_ROOT_PATH . '/modules/extgallery/class/php-captcha.inc.php';
49
50
        // Enable captcha only if GD is Used
51
        if ('gd' === $xoopsModuleConfig['graphic_lib']) {
52
            if (!PhpCaptcha::Validate($_POST['captcha'])) {
53
                redirect_header('public-photo.php?photoId=' . $photoId . '#photoNav', 3, _MD_EXTGALLERY_CAPTCHA_ERROR);
54
            }
55
        }
56
        /** @var ExtgalleryPublicEcardHandler $ecardHandler */
57
        $ecardHandler = xoops_getModuleHandler('publicecard', 'extgallery');
58
        /** @var ExtgalleryPublicPhotoHandler $photoHandler */
59
        $photoHandler = xoops_getModuleHandler('publicphoto', 'extgallery');
60
61
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
62
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
63
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
64
            $ip = $_SERVER['HTTP_CLIENT_IP'];
65
        } else {
66
            $ip = $_SERVER['REMOTE_ADDR'];
67
        }
68
69
        $data = [
70
            'ecard_fromname'  => $_POST['ecard_fromname'],
71
            'ecard_fromemail' => $_POST['ecard_fromemail'],
72
            'ecard_toname'    => $_POST['ecard_toname'],
73
            'ecard_toemail'   => $_POST['ecard_toemail'],
74
            'ecard_greetings' => $_POST['ecard_greetings'],
75
            'ecard_desc'      => $_POST['ecard_desc'],
76
            'ecard_ip'        => $ip,
77
            'photo_id'        => $photoId
78
        ];
79
80
        $ecardHandler->createEcard($data);
81
        $photoHandler->updateEcard($photoId);
82
83
        redirect_header('public-photo.php?photoId=' . $photoId . '#photoNav', 3, _MD_EXTGALLERY_ECARD_SENT);
84
85
        break;
86
87
    case 'default':
88
    default:
89
90
        $GLOBALS['xoopsOption']['template_main'] = 'extgallery_public-sendecard.tpl';
91
        include XOOPS_ROOT_PATH . '/header.php';
92
93 View Code Duplication
        if ('' != $photo->getVar('photo_serveur')) {
0 ignored issues
show
The method getVar cannot be called on $photo (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
            $photoUrl = $photo->getVar('photo_serveur') . 'thumb_' . $photo->getVar('photo_name');
95
        } else {
96
            $photoUrl = XOOPS_URL . '/uploads/extgallery/public-photo/thumb/thumb_' . $photo->getVar('photo_name');
97
        }
98
99
        $fromName  = is_a($GLOBALS['xoopsUser'], 'XoopsUser') ? $GLOBALS['xoopsUser']->getVar('uname') : '';
100
        $fromEmail = is_a($GLOBALS['xoopsUser'], 'XoopsUser') ? $GLOBALS['xoopsUser']->getVar('email') : '';
101
102
        $form = new XoopsThemeForm(_MD_EXTGALLERY_SEND_ECARD, 'send_ecard', 'public-sendecard.php', 'post', true);
103
        $form->addElement(new XoopsFormText(_MD_EXTGALLERY_FROM_NAME, 'ecard_fromname', '70', '255', $fromName), false);
104
        $form->addElement(new XoopsFormText(_MD_EXTGALLERY_FROM_EMAIL, 'ecard_fromemail', '70', '255', $fromEmail), false);
105
        $form->addElement(new XoopsFormText(_MD_EXTGALLERY_TO_NAME, 'ecard_toname', '70', '255', ''), false);
106
        $form->addElement(new XoopsFormText(_MD_EXTGALLERY_TO_EMAIL, 'ecard_toemail', '70', '255', ''), false);
107
        $form->addElement(new XoopsFormText(_MD_EXTGALLERY_GREETINGS, 'ecard_greetings', '110', '255', ''), false);
108
        $form->addElement(new XoopsFormTextArea(_MD_EXTGALLERY_DESC, 'ecard_desc', ''), false);
109
        // Enable captcha only if GD is Used
110
        if ('gd' === $xoopsModuleConfig['graphic_lib']) {
111
            $form->addElement(new XoopsFormText(_MD_EXTGALLERY_SECURITY, 'captcha', '10', '5', ''), false);
112
        }
113
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
114
        $form->addElement(new XoopsFormHidden('photo_id', $photoId));
115
        $form->addElement(new XoopsFormHidden('step', 'send'));
116
        $form->assign($xoopsTpl);
117
118
        $xoopsTpl->assign('photo', $photoUrl);
119
        $xoopsTpl->assign('xoops_pagetitle', 'Send ' . $photo->getVar('photo_desc') . ' to eCard');
120
        $xoTheme->addMeta('meta', 'description', $photo->getVar('photo_desc'));
121
122
        $rel                 = 'alternate';
123
        $attributes['rel']   = $rel;
124
        $attributes['type']  = 'application/rss+xml';
125
        $attributes['title'] = _MD_EXTGALLERY_RSS;
126
        $attributes['href']  = XOOPS_URL . '/modules/extgallery/public-rss.php';
127
        $xoTheme->addMeta('link', $rel, $attributes);
128
        $xoTheme->addStylesheet('modules/extgallery/assets/css/style.css');
129
130
        $lang = [
131
            'to'   => _MD_EXTGALLERY_TO,
132
            'from' => _MD_EXTGALLERY_FROM
133
        ];
134
        $xoopsTpl->assign('lang', $lang);
135
136
        include XOOPS_ROOT_PATH . '/footer.php';
137
138
        break;
139
140
}
141