|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace XoopsModules\Gbook; |
|
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
|
|
|
* Gbook\Utility Class |
|
18
|
|
|
* |
|
19
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
20
|
|
|
* @license http://www.fsf.org/copyleft/gpl.html GNU public license |
|
21
|
|
|
* @author XOOPS Development Team |
|
22
|
|
|
* @package GBook |
|
23
|
|
|
* @since 1.03 |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
//namespace GBook; |
|
27
|
|
|
|
|
28
|
|
|
use XoopsModules\Gbook; |
|
29
|
|
|
use XoopsModules\Gbook\Common; |
|
30
|
|
|
use XoopsModules\Gbook\Constants; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Class Utility |
|
34
|
|
|
*/ |
|
35
|
|
|
class Utility extends Common\SysUtility |
|
36
|
|
|
{ |
|
37
|
|
|
//--------------- Custom module methods ----------------------------- |
|
38
|
|
|
/** |
|
39
|
|
|
* @param \Xmf\Module\Helper $helper |
|
40
|
|
|
* @param array|null $options |
|
41
|
|
|
* @return \XoopsFormDhtmlTextArea|\XoopsFormEditor |
|
42
|
|
|
*/ |
|
43
|
|
|
public static function getEditor($helper = null, $options = null) |
|
44
|
|
|
{ |
|
45
|
|
|
/** @var Gbook\Helper $helper */ |
|
46
|
|
|
if (null === $options) { |
|
47
|
|
|
$options = []; |
|
48
|
|
|
$options['name'] = 'Editor'; |
|
49
|
|
|
$options['value'] = 'Editor'; |
|
50
|
|
|
$options['rows'] = 10; |
|
51
|
|
|
$options['cols'] = '100%'; |
|
52
|
|
|
$options['width'] = '100%'; |
|
53
|
|
|
$options['height'] = '400px'; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (null === $helper) { |
|
57
|
|
|
$helper = Helper::getInstance(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
$isAdmin = $helper->isUserAdmin(); |
|
61
|
|
|
|
|
62
|
|
|
if (\class_exists('XoopsFormEditor')) { |
|
63
|
|
|
if ($isAdmin) { |
|
64
|
|
|
$descEditor = new \XoopsFormEditor($options['name'], $helper->getConfig('editorAdmin'), $options, $nohtml = false, $onfailure = 'textarea'); |
|
65
|
|
|
} else { |
|
66
|
|
|
$descEditor = new \XoopsFormEditor($options['name'], $helper->getConfig('editorUser'), $options, $nohtml = false, $onfailure = 'textarea'); |
|
67
|
|
|
} |
|
68
|
|
|
} else { |
|
69
|
|
|
$descEditor = new \XoopsFormDhtmlTextArea($options['name'], $options['name'], $options['value'], '100%', '100%'); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
// $form->addElement($descEditor); |
|
73
|
|
|
|
|
74
|
|
|
return $descEditor; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param $nameTmp |
|
79
|
|
|
* @param $emailTmp |
|
80
|
|
|
* @param $urlTmp |
|
81
|
|
|
* @param $messageTmp |
|
82
|
|
|
* @return \XoopsThemeForm |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function getSignForm($nameTmp, $emailTmp, $urlTmp, $messageTmp): \XoopsThemeForm |
|
85
|
|
|
{ |
|
86
|
|
|
$name = new \XoopsFormText(_MD_GBOOK_NAME, 'Name', 43, 100, $nameTmp); |
|
87
|
|
|
$email = new \XoopsFormText(_MD_GBOOK_EMAIL, 'Email', 43, 100, $emailTmp); |
|
88
|
|
|
$url = new \XoopsFormText(_MD_GBOOK_URL, 'URL', 43, 100, $urlTmp); |
|
89
|
|
|
$message = new \XoopsFormTextArea(_MD_GBOOK_MESSAGE, 'Message', $messageTmp); |
|
90
|
|
|
$submit = new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'); |
|
91
|
|
|
$gbookform = new \XoopsThemeForm(_MD_GBOOK_SIGN, 'gbookform', 'sign.php'); |
|
92
|
|
|
|
|
93
|
|
|
$gbookform->addElement($name, true); |
|
94
|
|
|
$gbookform->addElement($email); |
|
95
|
|
|
$gbookform->addElement($url); |
|
96
|
|
|
$gbookform->addElement($message, true); |
|
97
|
|
|
$gbookform->addElement(new \XoopsFormCaptcha(), true); |
|
98
|
|
|
$gbookform->addElement($submit); |
|
99
|
|
|
|
|
100
|
|
|
return $gbookform; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @return string |
|
105
|
|
|
*/ |
|
106
|
|
|
public static function gbookIP(): string |
|
107
|
|
|
{ |
|
108
|
|
|
$ip = 'UNKNOWN'; |
|
109
|
|
|
if (\getenv('HTTP_CLIENT_IP')) { |
|
110
|
|
|
$ip = \getenv('HTTP_CLIENT_IP'); |
|
111
|
|
|
} elseif (\getenv('HTTP_X_FORWARDED_FOR')) { |
|
112
|
|
|
$ip = \getenv('HTTP_X_FORWARDED_FOR'); |
|
113
|
|
|
} elseif (\getenv('REMOTE_ADDR')) { |
|
114
|
|
|
$ip = \getenv('REMOTE_ADDR'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
return $ip; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|