Completed
Push — master ( 89db23...db7223 )
by Michael
02:46
created

sign.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
 * ****************************************************************************
4
 *  GBOOK - MODULE FOR XOOPS
5
 *  Copyright (c) 2007 - 2012
6
 *  Ingo H. de Boer (http://www.winshell.org)
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  (at your option) any later version.
12
 *
13
 *  You may not change or alter any portion of this comment or credits
14
 *  of supporting developers from this source code or any supporting
15
 *  source code which is considered copyrighted (c) material of the
16
 *  original comment or credit authors.
17
 *
18
 *  This program is distributed in the hope that it will be useful,
19
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 *  GNU General Public License for more details.
22
 *  ---------------------------------------------------------------------------
23
 *
24
 * @copyright       Ingo H. de Boer (http://www.winshell.org)
25
 * @license         GNU General Public License (GPL)
26
 * @package         GBook
27
 * @author          Ingo H. de Boer ([email protected])
28
 *
29
 * ****************************************************************************
30
 */
31
use Xmf\Request;
32
33
include_once __DIR__ . '/header.php';
34
include_once __DIR__ . '/class/utilities.php';
35
global $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
36
//Assign info
37
$myts = MyTextSanitizer::getInstance();
38
$nameTmp    = Request::getString('Name', '', 'POST') ?: ('' !== $xoopsUser ? $xoopsUser->getVar('uname', 'E') : '');
39
$emailTmp   = Request::getString('Email', '', 'POST') ?: ('' !== $xoopsUser ? $xoopsUser->getVar('email', 'E') : '');
40
$urlTmp     = Request::getString('URL', '', 'POST') ?: ('' !== $xoopsUser ? $xoopsUser->getVar('url', 'E') : '');
41
$messageTmp = Request::getString('Message', '', 'POST') ?: '';
42
$timeTmp    = time();
43
$ipTmp      = GBookUtilities::gbookIP();
44
45
$GLOBALS['xoopsOption']['template_main']       = 'gbook_sign.tpl';
46
$GLOBALS['xoopsOption']['xoops_module_header'] = '<link rel="stylesheet" type="text/css" href="assets/css/gbook.css" />';
47
include XOOPS_ROOT_PATH . '/header.php';
48
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
49
50
//Assign data to smarty tpl
51
$xoopsTpl->assign('lang_back', _MD_GBOOK_BACK);
52
$xoopsTpl->assign('lang_desc', _MD_GBOOK_DESC);
53
54
if (empty($_POST['submit'])) {
55
    $gbookform = GBookUtilities::getSignForm($nameTmp, $emailTmp, $urlTmp, $messageTmp);
56
    $gbookform->assign($xoopsTpl);
57
} else {
58
    $stop = '';
59
    xoops_load('XoopsCaptcha');
60
    $xoopsCaptcha = xoopsCaptcha::getInstance();
61
    if (!$xoopsCaptcha->verify()) {
62
        $stop .= $xoopsCaptcha->getMessage();
63
    }
64
    if (!empty($emailTmp) && !checkEmail($emailTmp)) {
65
        $stop .= _MD_GBOOK_EMAIL_INVALID;
66
    }
67
    if ('' !== $stop) {
68
        $stop .= '<br />';
69
        $GLOBALS['xoopsTpl']->assign('stop', $stop);
70
        $gbookform = GBookUtilities::getSignForm($nameTmp, $emailTmp, $urlTmp, $messageTmp);
71
        $gbookform->assign($xoopsTpl);
72
    } else {
73
        /** @var GbookEntriesHandler $entriesHandler */
74
        $entriesHandler = xoops_getModuleHandler('entries');
75
        $obj     = $entriesHandler->create();
76
        $obj->setVar('name', $nameTmp);
77
        $obj->setVar('email', $emailTmp);
78
        $obj->setVar('url', formatURL($urlTmp));
79
        $obj->setVar('message', $messageTmp);
80
        $obj->setVar('time', $timeTmp);
81
        $obj->setVar('ip', $ipTmp);
82
        if ($entriesHandler->insert($obj)) {
83
            redirect_header('index.php', 3, _MD_GBOOK_SIGNED);
84
        }
85
//        include_once dirname(__DIR__) . '/include/forms.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% 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...
86
        echo $obj->getHtmlErrors();
87
        $form = $obj->getForm();
88
        $form->display();
89
    }
90
}
91
92
include_once __DIR__ . '/footer.php';
93