|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace XoopsModules\Xoopsfaq; |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
You may not change or alter any portion of this comment or credits of |
|
7
|
|
|
supporting developers from this source code or any supporting source code |
|
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit |
|
9
|
|
|
authors. |
|
10
|
|
|
|
|
11
|
|
|
This program is distributed in the hope that it will be useful, but |
|
12
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Contents (FAQ) and Handler Class Definitions |
|
18
|
|
|
* |
|
19
|
|
|
* @package module\xoopsfaq\class\contents |
|
20
|
|
|
* @author John Neill |
|
21
|
|
|
* @author XOOPS Module Development Team |
|
22
|
|
|
* @copyright Copyright (c) 2001-2017 {@link http://xoops.org XOOPS Project} |
|
23
|
|
|
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU Public License |
|
24
|
|
|
* @since :: 1.23 |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
use XoopsModules\Xoopsfaq; |
|
28
|
|
|
|
|
29
|
|
|
defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Contents handles CRUD operations for FAQs |
|
33
|
|
|
* |
|
34
|
|
|
* @author :: John Neill |
|
35
|
|
|
* @copyright:: Copyright (c) 2009 |
|
36
|
|
|
*/ |
|
37
|
|
|
class Contents extends \XoopsObject |
|
38
|
|
|
{ |
|
39
|
|
|
/** |
|
40
|
|
|
* @var string contains this modules directory name |
|
41
|
|
|
*/ |
|
42
|
|
|
protected $dirname; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Constructor |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __construct() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->dirname = basename(dirname(__DIR__)); |
|
50
|
|
|
xoops_load('constants', $this->dirname); |
|
51
|
|
|
|
|
52
|
|
|
parent::__construct(); |
|
53
|
|
|
$this->initVar('contents_id', XOBJ_DTYPE_INT, null, false); |
|
54
|
|
|
$this->initVar('contents_cid', XOBJ_DTYPE_INT, Xoopsfaq\Constants::DEFAULT_CATEGORY, false); |
|
55
|
|
|
$this->initVar('contents_title', XOBJ_DTYPE_TXTBOX, null, true, 255); |
|
56
|
|
|
$this->initVar('contents_contents', XOBJ_DTYPE_TXTAREA, null, false); |
|
57
|
|
|
$this->initVar('contents_publish', XOBJ_DTYPE_INT, time(), false); |
|
58
|
|
|
$this->initVar('contents_weight', XOBJ_DTYPE_INT, Xoopsfaq\Constants::DEFAULT_WEIGHT, false); |
|
59
|
|
|
$this->initVar('contents_active', XOBJ_DTYPE_INT, Xoopsfaq\Constants::ACTIVE, false); |
|
60
|
|
|
$this->initVar('dohtml', XOBJ_DTYPE_INT, Xoopsfaq\Constants::SET, false); |
|
61
|
|
|
$this->initVar('doxcode', XOBJ_DTYPE_INT, Xoopsfaq\Constants::SET, false); |
|
62
|
|
|
$this->initVar('dosmiley', XOBJ_DTYPE_INT, Xoopsfaq\Constants::SET, false); |
|
63
|
|
|
$this->initVar('doimage', XOBJ_DTYPE_INT, Xoopsfaq\Constants::SET, false); |
|
64
|
|
|
$this->initVar('dobr', XOBJ_DTYPE_INT, Xoopsfaq\Constants::SET, false); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Display Content (FAQ) |
|
69
|
|
|
* |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
|
|
public function __toString() |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->getVar('contents_title', 's'); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Display the Content (FAQ) Editor form for Admin |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
|
|
public function displayForm() |
|
83
|
|
|
{ |
|
84
|
|
|
echo $this->renderForm(); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Displays the Content (FAQ) Editor form for Admin |
|
89
|
|
|
*/ |
|
90
|
|
|
public function renderForm() |
|
91
|
|
|
{ |
|
92
|
|
|
/** @var CategoryHandler $categoryHandler */ |
|
93
|
|
|
/** @var Xoopsfaq\Helper $helper */ |
|
94
|
|
|
$helper = \XoopsModules\Xoopsfaq\Helper::getHelper($this->dirname); |
|
95
|
|
|
$categoryHandler = $helper->getHandler('Category'); |
|
96
|
|
|
$catCount = $categoryHandler->getCount(); |
|
97
|
|
|
if (empty($catCount)) { |
|
98
|
|
|
xoops_error(_AM_XOOPSFAQ_ERROR_NO_CATS_EXIST, ''); |
|
99
|
|
|
xoops_cp_footer(); |
|
100
|
|
|
exit(); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
require_once $GLOBALS['xoops']->path('/class/xoopsformloader.php'); |
|
104
|
|
|
|
|
105
|
|
|
$caption = ($this->isNew()) ? _AM_XOOPSFAQ_CREATE_NEW : sprintf(_AM_XOOPSFAQ_MODIFY_ITEM, $this->getVar('contents_title')); |
|
106
|
|
|
$form = new \XoopsThemeForm($caption, 'content', $_SERVER['REQUEST_URI'], 'post', true); |
|
107
|
|
|
// $form->addElement(new \XoopsFormHiddenToken()); |
|
108
|
|
|
$form->addElement(new \XoopsFormHidden('op', 'save')); |
|
109
|
|
|
$form->addElement(new \XoopsFormHidden('contents_id', $this->getVar('contents_id', 'e'))); |
|
110
|
|
|
|
|
111
|
|
|
// Active |
|
112
|
|
|
$contents_active = new \XoopsFormRadioYN(_AM_XOOPSFAQ_E_CONTENTS_ACTIVE, 'contents_active', $this->getVar('contents_active', 'e'), ' ' . _YES . '', ' ' . _NO . ''); |
|
113
|
|
|
$contents_active->setDescription(_AM_XOOPSFAQ_E_CONTENTS_ACTIVE_DESC); |
|
114
|
|
|
$form->addElement($contents_active, false); |
|
115
|
|
|
|
|
116
|
|
|
// Title |
|
117
|
|
|
$contents_title = new \XoopsFormText(_AM_XOOPSFAQ_E_CONTENTS_TITLE, 'contents_title', 50, 150, $this->getVar('contents_title', 'e')); |
|
118
|
|
|
$contents_title->setDescription(_AM_XOOPSFAQ_E_CONTENTS_TITLE_DESC); |
|
119
|
|
|
$form->addElement($contents_title, true); |
|
120
|
|
|
|
|
121
|
|
|
// Category |
|
122
|
|
|
$catCriteria = new \CriteriaCompo(); |
|
123
|
|
|
$catCriteria->order = 'ASC'; |
|
124
|
|
|
$catCriteria->setSort('category_order'); |
|
125
|
|
|
$objects = $categoryHandler->getList($catCriteria); |
|
126
|
|
|
$contents_cid = new \XoopsFormSelect(_AM_XOOPSFAQ_E_CONTENTS_CATEGORY, 'contents_cid', $this->getVar('contents_cid', 'e'), 1, false); |
|
127
|
|
|
$contents_cid->setDescription(_AM_XOOPSFAQ_E_CONTENTS_CATEGORY_DESC); |
|
128
|
|
|
$contents_cid->addOptionArray($objects); |
|
129
|
|
|
$form->addElement($contents_cid); |
|
130
|
|
|
|
|
131
|
|
|
// Weight |
|
132
|
|
|
$contents_weight = new \XoopsFormText(_AM_XOOPSFAQ_E_CONTENTS_WEIGHT, 'contents_weight', 5, 5, $this->getVar('contents_weight', 'e')); |
|
133
|
|
|
$contents_weight->setDescription(_AM_XOOPSFAQ_E_CONTENTS_WEIGHT_DESC); |
|
134
|
|
|
$form->addElement($contents_weight, false); |
|
135
|
|
|
|
|
136
|
|
|
// Editor |
|
137
|
|
|
$editorConfigs = []; |
|
138
|
|
|
$options_tray = new \XoopsFormElementTray(_AM_XOOPSFAQ_E_CONTENTS_CONTENT, '<br>'); |
|
139
|
|
|
if (class_exists('XoopsFormEditor')) { |
|
140
|
|
|
// $editorConfigs = array('editor' => $GLOBALS['xoopsConfig']['general_editor'], |
|
141
|
|
|
$editorConfigs = [ |
|
142
|
|
|
'editor' => $helper->getConfig('use_wysiwyg', 'dhtmltextarea'), |
|
143
|
|
|
'rows' => 25, |
|
144
|
|
|
'cols' => '100%', |
|
145
|
|
|
'width' => '100%', |
|
146
|
|
|
'height' => '600px', |
|
147
|
|
|
'name' => 'contents_contents', |
|
148
|
|
|
'value' => $this->getVar('contents_contents', 'e'), |
|
149
|
|
|
]; |
|
150
|
|
|
$contents_contents = new \XoopsFormEditor('', 'contents_contents', $editorConfigs); |
|
151
|
|
|
} else { |
|
152
|
|
|
$contents_contents = new \XoopsFormDhtmlTextArea('', 'contents_contents', $this->getVar('contents_contents', 'e'), '100%', '100%'); |
|
153
|
|
|
} |
|
154
|
|
|
$options_tray->addElement($contents_contents); |
|
155
|
|
|
$options_tray->setDescription(_AM_XOOPSFAQ_E_CONTENTS_CONTENT_DESC); |
|
156
|
|
|
|
|
157
|
|
|
xoops_load('XoopsEditorHandler'); |
|
158
|
|
|
$editorHandler = \XoopsEditorHandler::getInstance(); |
|
159
|
|
|
$editorList = $editorHandler->getList(true); |
|
160
|
|
|
if (isset($editorConfigs['editor']) && in_array($editorConfigs['editor'], array_flip($editorList))) { |
|
161
|
|
|
$form->addElement(new \XoopsFormHidden('dohtml', Xoopsfaq\Constants::NOTSET)); |
|
162
|
|
|
$form->addElement(new \XoopsFormHidden('dobr', Xoopsfaq\Constants::SET)); |
|
163
|
|
|
} else { |
|
164
|
|
|
$html_checkbox = new \XoopsFormCheckBox('', 'dohtml', $this->getVar('dohtml', 'e')); |
|
165
|
|
|
$html_checkbox->addOption(1, _AM_XOOPSFAQ_E_DOHTML); |
|
166
|
|
|
$options_tray->addElement($html_checkbox); |
|
167
|
|
|
|
|
168
|
|
|
$breaks_checkbox = new \XoopsFormCheckBox('', 'dobr', $this->getVar('dobr', 'e')); |
|
169
|
|
|
$breaks_checkbox->addOption(1, _AM_XOOPSFAQ_E_BREAKS); |
|
170
|
|
|
$options_tray->addElement($breaks_checkbox); |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
$doimage_checkbox = new \XoopsFormCheckBox('', 'doimage', $this->getVar('doimage', 'e')); |
|
174
|
|
|
$doimage_checkbox->addOption(1, _AM_XOOPSFAQ_E_DOIMAGE); |
|
175
|
|
|
$options_tray->addElement($doimage_checkbox); |
|
176
|
|
|
|
|
177
|
|
|
$xcodes_checkbox = new \XoopsFormCheckBox('', 'doxcode', $this->getVar('doxcode', 'e')); |
|
178
|
|
|
$xcodes_checkbox->addOption(1, _AM_XOOPSFAQ_E_DOXCODE); |
|
179
|
|
|
$options_tray->addElement($xcodes_checkbox); |
|
180
|
|
|
|
|
181
|
|
|
$smiley_checkbox = new \XoopsFormCheckBox('', 'dosmiley', $this->getVar('dosmiley', 'e')); |
|
182
|
|
|
$smiley_checkbox->addOption(1, _AM_XOOPSFAQ_E_DOSMILEY); |
|
183
|
|
|
$options_tray->addElement($smiley_checkbox); |
|
184
|
|
|
|
|
185
|
|
|
$form->addElement($options_tray); |
|
186
|
|
|
|
|
187
|
|
|
$contents_publish = new \XoopsFormTextDateSelect(_AM_XOOPSFAQ_E_CONTENTS_PUBLISH, 'contents_publish', 20, (int)$this->getVar('contents_publish'), $this->isNew()); |
|
188
|
|
|
$contents_publish->setDescription(_AM_XOOPSFAQ_E_CONTENTS_PUBLISH_DESC); |
|
189
|
|
|
$form->addElement($contents_publish); |
|
190
|
|
|
|
|
191
|
|
|
$form->addElement(new \XoopsFormButtonTray('contents_form', _SUBMIT, 'submit')); |
|
192
|
|
|
|
|
193
|
|
|
return $form->render(); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Get the FAQ Active/Inactive icon to display |
|
198
|
|
|
* |
|
199
|
|
|
* @return string HTML <img> tag representing current active status |
|
200
|
|
|
*/ |
|
201
|
|
|
public function getActiveIcon() |
|
202
|
|
|
{ |
|
203
|
|
|
if ($this->getVar('contents_active') > Xoopsfaq\Constants::INACTIVE) { |
|
204
|
|
|
$icon = '<img src="' . \Xmf\Module\Admin::iconUrl('green.gif', '16') . '" alt="' . _YES . '">'; |
|
205
|
|
|
} else { |
|
206
|
|
|
$icon = '<img src="' . \Xmf\Module\Admin::iconUrl('red.gif', '16') . '" alt="' . _NO . '">'; |
|
207
|
|
|
} |
|
208
|
|
|
return $icon; |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
/** |
|
212
|
|
|
* Get the timestamp for when Content (FAQ) was published |
|
213
|
|
|
* |
|
214
|
|
|
* @param int|string Unix timestamp |
|
215
|
|
|
* |
|
216
|
|
|
* @return string|bool formatted timestamp on success, false on failure |
|
217
|
|
|
*/ |
|
218
|
|
|
public function getPublished($timestamp = '') |
|
219
|
|
|
{ |
|
220
|
|
|
if (!$this->getVar('contents_publish')) { |
|
221
|
|
|
return ''; |
|
222
|
|
|
} |
|
223
|
|
|
return formatTimestamp($this->getVar('contents_publish'), $timestamp); |
|
224
|
|
|
} |
|
225
|
|
|
} |
|
226
|
|
|
|