|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Xooghost\Form; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Xooghost module |
|
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
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
14
|
|
|
* |
|
15
|
|
|
* @copyright XOOPS Project (https://xoops.org) |
|
16
|
|
|
* @license GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html) |
|
17
|
|
|
* @package Xooghost |
|
18
|
|
|
* @since 2.6.0 |
|
19
|
|
|
* @author Laurent JEN (Aka DuGris) |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class PagesForm |
|
24
|
|
|
*/ |
|
25
|
|
|
class PagesForm extends \Xoops\Form\ThemeForm |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @param \XoopsModules\Xooghost\Page|\XoopsObject|null $obj |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(\XoopsModules\Xooghost\Page $obj = null) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->xoopsObject = $obj; |
|
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
/** @var \XoopsModules\Xooghost\Helper $helper */ |
|
35
|
|
|
$helper = \XoopsModules\Xooghost\Helper::getInstance(); |
|
36
|
|
|
$ghostConfig = $helper->loadConfig(); |
|
37
|
|
|
$pageHandler = $helper->getHandler('Page'); |
|
38
|
|
|
$xoops = \Xoops::getInstance(); |
|
39
|
|
|
|
|
40
|
|
|
if ($this->xoopsObject->isNew()) { |
|
|
|
|
|
|
41
|
|
|
parent::__construct(_AM_XOO_GHOST_ADD, 'form_pages', 'pages.php', 'post', true); |
|
42
|
|
|
} else { |
|
43
|
|
|
parent::__construct(_AM_XOO_GHOST_EDIT . ' : ' . $this->xoopsObject->getVar('xooghost_title'), 'form_pages', 'pages.php', 'post', true); |
|
44
|
|
|
} |
|
45
|
|
|
$this->setExtra('enctype="multipart/form-data"'); |
|
46
|
|
|
|
|
47
|
|
|
$tabTray = new \Xoops\Form\TabTray('', 'uniqueid'); |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Main |
|
51
|
|
|
*/ |
|
52
|
|
|
$tab1 = new \Xoops\Form\Tab(_AM_XOO_TABFORM_MAIN, 'tabid-1'); |
|
53
|
|
|
// Url |
|
54
|
|
|
if ($this->xoopsObject->isNew()) { |
|
55
|
|
|
$dirlist = $pageHandler->getPhpListAsArray(); |
|
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
if (count($dirlist) > 0) { |
|
58
|
|
|
$ele = new \Xoops\Form\Select('', 'xooghost_url'); |
|
59
|
|
|
$ele->addOption(0, _AM_XOO_GHOST_CHOOSE); |
|
60
|
|
|
$ele->addOptionArray($dirlist); |
|
61
|
|
|
$tab1->addElement($ele); |
|
62
|
|
|
} else { |
|
63
|
|
|
$tab1->addElement(new \Xoops\Form\Text(_XOO_GHOST_URL, 'xooghost_url', 12, 100, $this->xoopsObject->getVar('xooghost_url')), true); |
|
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
} else { |
|
66
|
|
|
$tab1->addElement(new \Xoops\Form\Hidden('xooghost_url', $this->xoopsObject->getVar('xooghost_url'))); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
// Title |
|
70
|
|
|
$tab1->addElement(new \Xoops\Form\Text(_XOO_GHOST_TITLE, 'xooghost_title', 12, 100, $this->xoopsObject->getVar('xooghost_title')), true); |
|
71
|
|
|
|
|
72
|
|
|
// submitter |
|
73
|
|
|
if ($helper->isUserAdmin()) { |
|
74
|
|
|
$xooghost_uid = $this->xoopsObject->isNew() ? $xoops->user->getVar('uid') : $this->xoopsObject->getVar('xooghost_uid'); |
|
75
|
|
|
$tab1->addElement(new \Xoops\Form\SelectUser(_XOO_GHOST_AUTHOR, 'xooghost_uid', true, $xooghost_uid, 1, false)); |
|
76
|
|
|
} else { |
|
77
|
|
|
$xooghost_uid = $xoops->isUser() ? $xoops->user->getVar('uid') : 0; |
|
78
|
|
|
$tab1->addElement(new \Xoops\Form\Hidden('xooghost_uid', $xooghost_uid)); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
// Content |
|
82
|
|
|
$tab1->addElement(new \Xoops\Form\TextArea(_XOO_GHOST_CONTENT, 'xooghost_content', $this->xoopsObject->getVar('xooghost_content'), 7, 12), true); |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
// image |
|
85
|
|
|
$upload_msg[] = _XOO_GHOST_CONFIG_IMAGE_SIZE . ' : ' . $ghostConfig['xooghost_image_size']; |
|
|
|
|
|
|
86
|
|
|
$upload_msg[] = _XOO_GHOST_CONFIG_IMAGE_WIDTH . ' : ' . $ghostConfig['xooghost_image_width']; |
|
87
|
|
|
$upload_msg[] = _XOO_GHOST_CONFIG_IMAGE_HEIGHT . ' : ' . $ghostConfig['xooghost_image_height']; |
|
88
|
|
|
|
|
89
|
|
|
$warning_tray = new \Xoops\Form\ElementTray($this->message($upload_msg, '')); |
|
90
|
|
|
$image_tray = new \Xoops\Form\ElementTray(_XOO_GHOST_IMAGE, ''); |
|
91
|
|
|
|
|
92
|
|
|
$image_box = new \Xoops\Form\File('', 'xooghost_image', 5000000); |
|
|
|
|
|
|
93
|
|
|
$image_box->setExtra("size ='70%'"); |
|
|
|
|
|
|
94
|
|
|
$image_tray->addElement($image_box); |
|
95
|
|
|
$image_tray->addElement($warning_tray); |
|
96
|
|
|
|
|
97
|
|
|
$image_array = \XoopsLists:: getImgListAsArray(\XoopsBaseConfig::get('uploads-path') . '/xooghost/images'); |
|
98
|
|
|
$image_select = new \Xoops\Form\Select('<br>', 'image_list', $this->xoopsObject->getVar('xooghost_image')); |
|
99
|
|
|
$image_select->addOptionArray($image_array); |
|
100
|
|
|
$image_select->setExtra("onchange='showImgSelected(\"select_image\", \"image_list\", \"" . '/xooghost/images/' . '", "", "' . \XoopsBaseConfig::get('uploads-url') . "\")'"); |
|
|
|
|
|
|
101
|
|
|
$image_tray->addElement($image_select); |
|
102
|
|
|
$image_tray->addElement(new \Xoops\Form\Label('', "<br><img src='" . \XoopsBaseConfig::get('uploads-url') . '/xooghost/images/' . $this->xoopsObject->getVar('xooghost_image') . "' name='select_image' id='select_image' alt=''>")); |
|
103
|
|
|
$tab1->addElement($image_tray); |
|
104
|
|
|
|
|
105
|
|
|
$tabTray->addElement($tab1); |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Metas |
|
109
|
|
|
*/ |
|
110
|
|
|
$tab2 = new \Xoops\Form\Tab(_AM_XOO_TABFORM_METAS, 'tabid-2'); |
|
111
|
|
|
// Meta description |
|
112
|
|
|
$tab2->addElement(new \Xoops\Form\TextArea(_XOO_GHOST_DESCRIPTION, 'xooghost_description', $this->xoopsObject->getVar('xooghost_description'), 7, 12)); |
|
113
|
|
|
|
|
114
|
|
|
// Meta Keywords |
|
115
|
|
|
$tab2->addElement(new \Xoops\Form\TextArea(_XOO_GHOST_KEYWORDS, 'xooghost_keywords', $this->xoopsObject->getVar('xooghost_keywords'), 7, 12, _XOO_GHOST_KEYWORDS_DESC)); |
|
116
|
|
|
$tabTray->addElement($tab2); |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Options |
|
120
|
|
|
*/ |
|
121
|
|
|
// Published date |
|
122
|
|
|
$tab3 = new \Xoops\Form\Tab(_AM_XOO_TABFORM_OPTIONS, 'tabid-3'); |
|
123
|
|
|
$published = (0 == $this->xoopsObject->getVar('xooghost_published')) ? time() : $this->xoopsObject->getVar('xooghost_published'); |
|
124
|
|
|
$tab3->addElement(new \Xoops\Form\DateTimeSelect(_XOO_GHOST_PUBLISHED, 'xooghost_published', 15, $published, false)); |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
// display |
|
127
|
|
|
$tab3->addElement(new \Xoops\Form\RadioYesNo(_XOO_GHOST_DISPLAY, 'xooghost_online', $this->xoopsObject->getVar('xooghost_online'))); |
|
|
|
|
|
|
128
|
|
|
$tabTray->addElement($tab3); |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Tags |
|
132
|
|
|
*/ |
|
133
|
|
|
if ($xoops->registry()->offsetExists('XOOTAGS') && $xoops->registry()->get('XOOTAGS')) { |
|
134
|
|
|
$tagsTray = new \Xoops\Form\Tab(_AM_XOO_TABFORM_TAGS, 'tabid-tags'); |
|
135
|
|
|
// $tagsFormHandler = $xoops->getModuleForm(0, 'tags', 'xootags'); |
|
136
|
|
|
// $tagform = $tagsFormHandler->tagForm('tags', $this->xoopsObject->getVar('xooghost_id')); |
|
137
|
|
|
|
|
138
|
|
|
$tagsForm = new \XoopsModules\Xootags\Form\TagsForm(); |
|
|
|
|
|
|
139
|
|
|
$tagform = $tagsForm->tagForm('tags', $this->xoopsObject->getVar('xooghost_id')); |
|
140
|
|
|
|
|
141
|
|
|
$tagsTray->addElement($tagform); |
|
142
|
|
|
$tabTray->addElement($tagsTray); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
// hidden |
|
146
|
|
|
$this->addElement(new \Xoops\Form\Hidden('xooghost_id', $this->xoopsObject->getVar('xooghost_id'))); |
|
147
|
|
|
$this->addElement(new \Xoops\Form\Hidden('xooghost_hits', $this->xoopsObject->getVar('xooghost_hits'))); |
|
148
|
|
|
$this->addElement(new \Xoops\Form\Hidden('xooghost_rates', $this->xoopsObject->getVar('xooghost_rates'))); |
|
149
|
|
|
$this->addElement(new \Xoops\Form\Hidden('xooghost_like', $this->xoopsObject->getVar('xooghost_like'))); |
|
150
|
|
|
$this->addElement(new \Xoops\Form\Hidden('xooghost_dislike', $this->xoopsObject->getVar('xooghost_dislike'))); |
|
151
|
|
|
$this->addElement(new \Xoops\Form\Hidden('xooghost_comments', $this->xoopsObject->getVar('xooghost_comments'))); |
|
152
|
|
|
|
|
153
|
|
|
$this->addElement($tabTray); |
|
154
|
|
|
|
|
155
|
|
|
/** |
|
156
|
|
|
* Buttons |
|
157
|
|
|
*/ |
|
158
|
|
|
$buttonTray = new \Xoops\Form\ElementTray('', ''); |
|
159
|
|
|
$buttonTray->addElement(new \Xoops\Form\Hidden('op', 'save')); |
|
160
|
|
|
|
|
161
|
|
|
$buttonSubmit = new \Xoops\Form\Button('', 'submit', \XoopsLocale::A_SUBMIT, 'submit'); |
|
162
|
|
|
$buttonSubmit->setClass('btn btn-success'); |
|
163
|
|
|
$buttonTray->addElement($buttonSubmit); |
|
164
|
|
|
|
|
165
|
|
|
$buttonReset = new \Xoops\Form\Button('', 'reset', \XoopsLocale::A_RESET, 'reset'); |
|
166
|
|
|
$buttonReset->setClass('btn btn-warning'); |
|
167
|
|
|
$buttonTray->addElement($buttonReset); |
|
168
|
|
|
|
|
169
|
|
|
$buttonCancel = new \Xoops\Form\Button('', 'cancel', \XoopsLocale::A_CANCEL, 'button'); |
|
170
|
|
|
$buttonCancel->setExtra("onclick='javascript:history.go(-1);'"); |
|
|
|
|
|
|
171
|
|
|
$buttonCancel->setClass('btn btn-danger'); |
|
172
|
|
|
$buttonTray->addElement($buttonCancel); |
|
173
|
|
|
|
|
174
|
|
|
$this->addElement($buttonTray); |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
/** |
|
178
|
|
|
* @param $msg |
|
179
|
|
|
* @param string $title |
|
180
|
|
|
* @param string $class |
|
181
|
|
|
* |
|
182
|
|
|
* @return string |
|
183
|
|
|
*/ |
|
184
|
|
|
public function message($msg, $title = '', $class = 'errorMsg') |
|
185
|
|
|
{ |
|
186
|
|
|
$ret = "<div class='" . $class . "'>"; |
|
187
|
|
|
if ('' != $title) { |
|
188
|
|
|
$ret .= '<strong>' . $title . '</strong>'; |
|
189
|
|
|
} |
|
190
|
|
|
if (is_array($msg) || is_object($msg)) { |
|
191
|
|
|
$ret .= implode('<br>', $msg); |
|
|
|
|
|
|
192
|
|
|
} else { |
|
193
|
|
|
$ret .= $msg; |
|
194
|
|
|
} |
|
195
|
|
|
$ret .= '</div>'; |
|
196
|
|
|
|
|
197
|
|
|
return $ret; |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|