ModuleFeedback::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xoopspoll\Common;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
use XoopsFormButtonTray;
16
use XoopsFormEditor;
17
use XoopsFormHidden;
18
use XoopsFormSelect;
19
use XoopsFormText;
20
use XoopsObject;
21
use XoopsThemeForm;
22
23
/**
24
 * Feedback plugin for xoops modules
25
 *
26
 * @copyright      XOOPS Project  (https://xoops.org)
27
 * @license        GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
28
 * @author         Michael Beck <[email protected]>
29
 * @author         Wedega - Email:<[email protected]>
30
 * @author         Fernando Santos (topet05) <[email protected]>
31
 */
32
\defined('XOOPS_ROOT_PATH') || die('Restricted access');
33
34
/**
35
 * Class Object ModuleFeedback
36
 */
37
class ModuleFeedback extends XoopsObject
38
{
39
    public string $name    = '';
40
    public string $email   = '';
41
    public string $site    = '';
42
    public string $type    = '';
43
    public string $content = '';
44
45
    /**
46
     * Constructor
47
     *
48
     * @param null
49
     */
50
    public function __construct()
51
    {
52
    }
53
54
    /**
55
     * @static function &getInstance
56
     *
57
     * @param null
58
     */
59
    public static function getInstance(): void
60
    {
61
        static $instance = false;
62
        if (!$instance) {
63
            $instance = new self();
64
        }
65
    }
66
67
    /**
68
     * @public function getFormFeedback:
69
     * provide form for sending a feedback to module author
70
     * @param bool|string $action
71
     */
72
    public function getFormFeedback($action = false): XoopsThemeForm
73
    {
74
        if (!$action) {
75
            $action = $_SERVER['REQUEST_URI'];
0 ignored issues
show
Unused Code introduced by
The assignment to $action is dead and can be removed.
Loading history...
76
        }
77
        $moduleDirName      = \basename(\dirname(__DIR__, 2));
78
        $moduleDirNameUpper = \mb_strtoupper($moduleDirName);
79
        // Get Theme Form
80
        \xoops_load('XoopsFormLoader');
81
        $form = new XoopsThemeForm(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_FORM_TITLE'), 'formfeedback', 'feedback.php', 'post', true);
82
        $form->setExtra('enctype="multipart/form-data"');
83
84
        $recipient = new XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_RECIPIENT'), 'recipient', 50, 255, $GLOBALS['xoopsModule']->getInfo('author_mail'));
85
        $recipient->setExtra('disabled="disabled"');
86
        $form->addElement($recipient);
87
        $your_name = new XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME'), 'your_name', 50, 255, $this->name);
88
        $your_name->setExtra('placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_NAME_PLACEHOLER') . '"');
89
        $form->addElement($your_name);
90
        $your_site = new XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE'), 'your_site', 50, 255, $this->site);
91
        $your_site->setExtra('placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_SITE_PLACEHOLER') . '"');
92
        $form->addElement($your_site);
93
        $your_mail = new XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL'), 'your_mail', 50, 255, $this->email);
94
        $your_mail->setExtra('placeholder="' . \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_MAIL_PLACEHOLER') . '"');
95
        $form->addElement($your_mail);
96
97
        $fbtypeSelect = new XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE'), 'fb_type', $this->type);
98
        $fbtypeSelect->addOption('', '');
99
        $fbtypeSelect->addOption(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'), \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_SUGGESTION'));
100
        $fbtypeSelect->addOption(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'), \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_BUGS'));
101
        $fbtypeSelect->addOption(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'), \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_TESTIMONIAL'));
102
        $fbtypeSelect->addOption(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'), \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_FEATURES'));
103
        $fbtypeSelect->addOption(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'), \constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_OTHERS'));
104
        $form->addElement($fbtypeSelect, true);
105
106
        $editorConfigs           = [];
107
        $editorConfigs['name']   = 'fb_content';
108
        $editorConfigs['value']  = $this->content;
109
        $editorConfigs['rows']   = 5;
110
        $editorConfigs['cols']   = 40;
111
        $editorConfigs['width']  = '100%';
112
        $editorConfigs['height'] = '400px';
113
        /** @var \XoopsModuleHandler $moduleHandler */
114
        $moduleHandler = \xoops_getHandler('module');
115
        $module        = $moduleHandler->getByDirname('system');
116
        /** @var \XoopsConfigHandler $configHandler */
117
        $configHandler           = \xoops_getHandler('config');
118
        $config                  = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
119
        $editorConfigs['editor'] = $config['general_editor'];
120
        $editor                  = new XoopsFormEditor(\constant('CO_' . $moduleDirNameUpper . '_' . 'FB_TYPE_CONTENT'), 'fb_content', $editorConfigs);
121
        $form->addElement($editor, true);
122
123
        $form->addElement(new XoopsFormHidden('op', 'send'));
124
        $form->addElement(new XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
125
126
        return $form;
127
    }
128
}
129