Passed
Pull Request — master (#10)
by Michael
01:59
created

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
 *  You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *  This program is distributed in the hope that it will be useful,
7
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
8
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9
 *
10
 *--------------------------------------
11
 * Author: Raul Recio (AKA UNFOR)
12
 * Project: The XOOPS Project
13
 *--------------------------------------
14
 */
15
/**
16
 * XoopsPartners - a partner affiliation links module
17
 *
18
 * @package      module\xoopspartners\frontside
19
 * @author       Raul Recio (aka UNFOR)
20
 * @author       XOOPS Module Development Team
21
 * @copyright    {@link https://xoops.org 2001-2016 XOOPS Project}
22
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU Public License}
23
 * @link         https://xoops.org XOOPS
24
 */
25
use Xmf\Request;
26
use Xmf\Module\Helper;
27
28
require __DIR__ . '/header.php';
29
if (!isset($GLOBALS['xoopsUser']) || !$GLOBALS['xoopsUser'] instanceof XoopsUser) {
0 ignored issues
show
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
30
    $xpHelper->redirect('index.php', XoopspartnersConstants::REDIRECT_DELAY_MEDIUM, _NOPERM);
31
}
32
33
/** @var string $xoopsOption */
34
$xoopsOption['template_main'] = 'xoopspartners_join.tpl';
35
include $GLOBALS['xoops']->path('/header.php');
36
37
$op     = Request::getCmd('op', '', 'POST');
38
$myts   = MyTextSanitizer::getInstance();
39
$xpInfo = $xpHelper->getModule()->getInfo();
40
41
switch ($op) {
42
    case 'sendMail':
43 View Code Duplication
    if (!$GLOBALS['xoopsSecurity']->check()) {
0 ignored issues
show
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...
44
            $xpHelper->redirect('index.php',
45
                            XoopspartnersConstants::REDIRECT_DELAY_MEDIUM,
46
                            _MD_XOOPSPARTNERS_ERROR1 . '<br>' . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())
47
            );
48
    }
49
    extract($_POST, EXTR_PREFIX_ALL, 'unsafe');
50
    if (empty($unsafe_title) || empty($unsafe_description) || empty($unsafe_url) || $unsafe_url === 'http://') {
51
        $GLOBALS['xoopsTpl']->assign(array(
52
                                         'content4join'      => _MD_XOOPSPARTNERS_ERROR1,
53
                                         'lang_main_partner' => _MD_XOOPSPARTNERS_PARTNERS,
54
                                         'sitename'          => $GLOBALS['xoopsConfig']['sitename']
55
                                         )
56
            );
57
        } else {
58
    $url         = formatURL($myts->htmlSpecialChars($unsafe_url));
59
    $title       = $myts->htmlSpecialChars($unsafe_title);
60
    $description = $myts->htmlSpecialChars($unsafe_description);
61
    $image       = formatURL($myts->htmlSpecialChars($unsafe_image));
62
    $image       = xoops_trim($image);
63
    $image       = (('http://' === $image) || ('https://' === $image)) ? '' : $image;
64
    if (!empty($image)) {
65
        $allowed_mimetypes = array(
66
            'gif'  => 'image/gif',
67
            'jpg'  => 'image/jpeg',
68
            'pjpe' => 'image/pjpeg',  //IE7
69
            'png'  => 'image/png',
70
            'xpng' => 'image/x-png',  //IE7
71
            //                           'bmp' => 'image/bmp',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
72
            //                          'tiff' => 'image/tiff',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
73
            //                           'tif' => 'image/tif',
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
74
        );
75
                $maxFileSize   = (int)$xpInfo['maxuploadsize'] > 0
76
                               ? (int)$xpInfo['maxuploadsize']
77
                               : XoopspartnersConstants::DEFAULT_UPLOAD_SIZE;
78
/*                $maxFileWidth  = (int)$xpInfo['maxwidth'] > 0
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
79
                                 ? (int)$xpInfo['maxwidth']
80
                                 : XoopspartnersConstants::DEFAULT_MAX_WIDTH; */
81
/*                $maxFileHeight = (int)$xpInfo['maxheight'] > 0
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
82
                                 ? (int)$xpInfo('maxheight')
83
                                 : XoopspartnersConstants::DEFAULT_MAX_HEIGHT; */
84
                if (preg_match('^http[s]?:\/\/[^\s]', $image)) {
85
            // image is from external source
86
                    xoops_load('xoopsmediauploader');
87
                    $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH . "/{$moduleDirName}",
88
                                                       $allowed_mimetypes,
89
                                                       $maxFileSize
90
                    );
91
            if ($uploader->fetchMedia($image)) {
92
                if ($uploader->upload()) {
93
                    $image = $uploader->getSavedFileName();  // get file name to save in db
94
                }
95
            }
96
        }
97
98
        $imageInfo  = @getimagesize($image);
99
        $uploadErrs = ($uploader instanceof XoopsMediaUploader) ? $uploader->getErrors() : '';
0 ignored issues
show
The class XoopsMediaUploader does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
100
                if (false === $imageInfo || !empty($uploadErrs)) { // could not find image
101
            $GLOBALS['xoopsTpl']->assign(array(
102
                                                     'content4join'      => sprintf(_MD_XOOPSPARTNERS_ERROR3, $image)
103
                                                                            . '<br>' . $uploader->getErrors(),
104
                                             'lang_main_partner' => _MD_XOOPSPARTNERS_PARTNERS,
105
                                             'sitename'          => $GLOBALS['xoopsConfig']['sitename']
106
                                                 )
107
                    );
108
            include_once __DIR__ . '/footer.php';
109
            exit();
110
        }
111
    }
112
            $xoopsMailer = xoops_getMailer();
113
    $xoopsMailer->useMail();
114
            $tplPath = 'language/%s/mail_template/';
115
            if (file_exists($xpHelper->path(sprintf($tplPath, $GLOBALS['xoopsConfig']['language'])))) {
116
                $xoopsMailer->setTemplateDir($xpHelper->path(sprintf($tplPath, $GLOBALS['xoopsConfig']['language'])));
117
            } else {
118
                $xoopsMailer->setTemplateDir($xpHelper->path(sprintf($tplPath, 'english')));
119
            }
120
    $xoopsMailer->setTemplate('join.tpl');
121
    $xoopsMailer->assign(array(
122
                             'SITENAME'    => $GLOBALS['xoopsConfig']['sitename'],
123
                             'SITEURL'     => $GLOBALS['xoops']->url('www'),
124
                             'IP'          => $_SERVER['REMOTE_ADDR'],
125
                             'URL'         => $url,
126
                             'IMAGE'       => $image,
127
                             'TITLE'       => $title,
128
                             'DESCRIPTION' => $description,
129
                             'USER'        => $GLOBALS['xoopsUser']->getVar('uname'),
130
                                    'MODULENAME'  => $moduleDirName
131
                                 )
132
            );
133
    $xoopsMailer->setToEmails($GLOBALS['xoopsConfig']['adminmail']);
134
    $xoopsMailer->setFromEmail($GLOBALS['xoopsUser']->getVar('email'));
135
    $xoopsMailer->setFromName($GLOBALS['xoopsUser']->getVar('uname'));
136
    $xoopsMailer->setSubject(sprintf(_MD_XOOPSPARTNERS_NEWPARTNER, $GLOBALS['xoopsConfig']['sitename']));
137
    if (!$xoopsMailer->send()) {
138
        $GLOBALS['xoopsTpl']->assign(array(
139
                                                 'content4join'      => '<br>'
140
                                                                        . $xoopsMailer->getErrors()
141
                                                                        . _MD_XOOPSPARTNERS_GOBACK,
142
                                         'lang_main_partner' => _MD_XOOPSPARTNERS_PARTNERS,
143
                                         'lang_join'         => _MD_XOOPSPARTNERS_JOIN,
144
                                         'sitename'          => $GLOBALS['xoopsConfig']['sitename']
145
                                             )
146
                );
147
    } else {
148
        $GLOBALS['xoopsTpl']->assign(array(
149
                                                 'content4join'      => '<br>'
150
                                                                        . _MD_XOOPSPARTNERS_SENDMAIL,
151
                                         'lang_main_partner' => _MD_XOOPSPARTNERS_PARTNERS,
152
                                         'lang_join'         => _MD_XOOPSPARTNERS_JOIN,
153
                                         'sitename'          => $GLOBALS['xoopsConfig']['sitename']
154
                                             )
155
                );
156
    }
157
        }
158
        break;
159
    default:
160
    include $GLOBALS['xoops']->path('/class/xoopsformloader.php');
161
    $form = new XoopsThemeForm('', 'joinform', 'join.php', 'post', true);
162
    $form->setExtra('enctype="multipart/form-data"');
163
        $titlePartner = new XoopsFormText(_MD_XOOPSPARTNERS_TITLE, 'title', 50, 50);
164
        $imagePartner = new XoopsFormText(_MD_XOOPSPARTNERS_IMAGE, 'image', 50, 150, 'http://');
165
        $urlPartner   = new XoopsFormText(_MD_XOOPSPARTNERS_URL, 'url', 50, 150, 'http://');
166
        $descrPartner = new XoopsFormTextArea(_MD_XOOPSPARTNERS_DESCRIPTION, 'description', '', 5, 51);
167
        $opHidden     = new XoopsFormHidden('op', 'sendMail');
168
    $submitButton       = new XoopsFormButton('', 'dbsubmit', _MD_XOOPSPARTNERS_SEND, 'submit');
169
    $form->addElement($titlePartner, true);
170
    $form->addElement($imagePartner);
171
    $form->addElement($urlPartner, true);
172
        $form->addElement($descrPartner, true);
173
        /* @todo add captcha to join form */
174
//        $form->addElement(new XoopsFormCaptcha());
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
175
        $form->addElement($opHidden);
176
    $form->addElement($submitButton);
177
    $content = $form->render();
178
    $GLOBALS['xoopsTpl']->assign(array(
179
                                     'content4join'      => $content,
180
                                     'lang_main_partner' => _MD_XOOPSPARTNERS_PARTNERS,
181
                                     'lang_join'         => _MD_XOOPSPARTNERS_JOIN,
182
                                     'sitename'          => $GLOBALS['xoopsConfig']['sitename']
183
                                     )
184
        );
185
}
186
187
include_once __DIR__ . '/footer.php';
188