Passed
Pull Request — master (#81)
by Michael
02:53
created

class/Common/ModuleFeedback.php (7 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Yogurt\Common;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
/**
18
 * Feedback plugin for XOOPS modules
19
 *
20
 * @copyright      XOOPS Project  (https://xoops.org)
21
 * @license        GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
22
 * @author         Michael Beck <[email protected]>
23
 * @author         Wedega - Email:<[email protected]>
24
 * @author         Fernando Santos (topet05) <[email protected]>
25
 */
26
27
/**
28
 * Class Object ModuleFeedback
29
 */
30
class ModuleFeedback extends XoopsObject
0 ignored issues
show
The type XoopsModules\Yogurt\Common\XoopsObject was not found. Did you mean XoopsObject? If so, make sure to prefix the type with \.
Loading history...
31
{
32
    public $name    = '';
33
    public $email   = '';
34
    public $site    = '';
35
    public $type    = '';
36
    public $content = '';
37
38
    /**
39
     * Constructor
40
     *
41
     * @param null
42
     */
43
    public function __construct()
44
    {
45
    }
46
47
    /**
48
     * @static function &getInstance
49
     *
50
     * @param null
51
     */
52
    public static function getInstance()
53
    {
54
        static $instance = false;
55
        if (!$instance) {
56
            $instance = new self();
57
        }
58
    }
59
60
    /**
61
     * @public function getFormFeedback:
62
     * provide form for sending a feedback to module author
63
     * @param bool $action
64
     * @return \XoopsThemeForm
65
     */
66
    public function getFormFeedback(
67
        $action = false
68
    ) {
69
        if (!$action) {
70
            $action = $_SERVER['REQUEST_URI'];
71
        }
72
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
73
        $moduleDirNameUpper = mb_strtoupper($moduleDirName);
74
        // Get Theme Form
75
        \xoops_load('XoopsFormLoader');
76
        $form = new XoopsThemeForm(
0 ignored issues
show
The type XoopsModules\Yogurt\Common\XoopsThemeForm was not found. Did you mean XoopsThemeForm? If so, make sure to prefix the type with \.
Loading history...
77
            \constant(
78
                'CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'
79
            ), 'formfeedback', 'feedback.php', 'post', true
80
        );
81
        $form->setExtra('enctype="multipart/form-data"');
82
83
        $recipient = new XoopsFormText(
0 ignored issues
show
The type XoopsModules\Yogurt\Common\XoopsFormText was not found. Did you mean XoopsFormText? If so, make sure to prefix the type with \.
Loading history...
84
            \constant(
85
                'CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'
86
            ), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo(
87
            'author_mail'
88
        )
89
        );
90
        $recipient->setExtra('disabled="disabled"');
91
        $form->addElement($recipient);
92
        $your_name = new XoopsFormText(
93
            \constant(
94
                'CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'
95
            ), 'your_name', 50, 255, $this->name
96
        );
97
        $your_name->setExtra(
98
            'placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME_PLACEHOLER') . '"'
99
        );
100
        $form->addElement($your_name);
101
        $your_site = new XoopsFormText(
102
            \constant(
103
                'CO_' . $moduleDirNameUpper . '_' . 'FB_SITE'
104
            ), 'your_site', 50, 255, $this->site
105
        );
106
        $your_site->setExtra(
107
            'placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE_PLACEHOLER') . '"'
108
        );
109
        $form->addElement($your_site);
110
        $your_mail = new XoopsFormText(
111
            \constant(
112
                'CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL'
113
            ), 'your_mail', 50, 255, $this->email
114
        );
115
        $your_mail->setExtra(
116
            'placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL_PLACEHOLER') . '"'
117
        );
118
        $form->addElement($your_mail);
119
120
        $fbtypeSelect = new XoopsFormSelect(
0 ignored issues
show
The type XoopsModules\Yogurt\Common\XoopsFormSelect was not found. Did you mean XoopsFormSelect? If so, make sure to prefix the type with \.
Loading history...
121
            \constant(
122
                'CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE'
123
            ), 'fb_type', $this->type
124
        );
125
        $fbtypeSelect->addOption('', '');
126
        $fbtypeSelect->addOption(
127
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'),
128
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION')
129
        );
130
        $fbtypeSelect->addOption(
131
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'),
132
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS')
133
        );
134
        $fbtypeSelect->addOption(
135
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'),
136
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL')
137
        );
138
        $fbtypeSelect->addOption(
139
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'),
140
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES')
141
        );
142
        $fbtypeSelect->addOption(
143
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'),
144
            \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS')
145
        );
146
        $form->addElement($fbtypeSelect, true);
147
148
        $editorConfigs           = [];
149
        $editorConfigs['name']   = 'fb_content';
150
        $editorConfigs['value']  = $this->content;
151
        $editorConfigs['rows']   = 5;
152
        $editorConfigs['cols']   = 40;
153
        $editorConfigs['width']  = '100%';
154
        $editorConfigs['height'] = '400px';
155
        /** @var \XoopsModuleHandler $moduleHandler */
156
        $moduleHandler = \xoops_getHandler('module');
157
        $module        = $moduleHandler->getByDirname('system');
158
        /** @var \XoopsConfigHandler $configHandler */
159
        $configHandler           = \xoops_getHandler('config');
160
        $config                  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
161
        $editorConfigs['editor'] = $config['general_editor'];
162
        $editor                  = new XoopsFormEditor(
0 ignored issues
show
The type XoopsModules\Yogurt\Common\XoopsFormEditor was not found. Did you mean XoopsFormEditor? If so, make sure to prefix the type with \.
Loading history...
163
            \constant(
164
                'CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_CONTENT'
165
            ), 'fb_content', $editorConfigs
166
        );
167
        $form->addElement($editor, true);
168
169
        $form->addElement(new XoopsFormHidden('op', 'send'));
0 ignored issues
show
The type XoopsModules\Yogurt\Common\XoopsFormHidden was not found. Did you mean XoopsFormHidden? If so, make sure to prefix the type with \.
Loading history...
170
        $form->addElement(new XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
0 ignored issues
show
The type XoopsModules\Yogurt\Common\XoopsFormButtonTray was not found. Did you mean XoopsFormButtonTray? If so, make sure to prefix the type with \.
Loading history...
171
172
        return $form;
173
    }
174
}
175