@@ -9,12 +9,12 @@ |
||
9 | 9 | |
10 | 10 | function smartobject_plugin_xcgal() |
11 | 11 | { |
12 | - global $xoopsConfig; |
|
12 | + global $xoopsConfig; |
|
13 | 13 | |
14 | - $pluginInfo = []; |
|
15 | - $pluginInfo['items']['album']['caption'] = 'Album'; |
|
16 | - $pluginInfo['items']['item']['url'] = 'thumbnails.php?album=%u'; |
|
17 | - $pluginInfo['items']['item']['request'] = 'album'; |
|
14 | + $pluginInfo = []; |
|
15 | + $pluginInfo['items']['album']['caption'] = 'Album'; |
|
16 | + $pluginInfo['items']['item']['url'] = 'thumbnails.php?album=%u'; |
|
17 | + $pluginInfo['items']['item']['request'] = 'album'; |
|
18 | 18 | |
19 | - return $pluginInfo; |
|
19 | + return $pluginInfo; |
|
20 | 20 | } |
@@ -9,15 +9,15 @@ |
||
9 | 9 | |
10 | 10 | function smartobject_plugin_smartsection() |
11 | 11 | { |
12 | - $pluginInfo = []; |
|
12 | + $pluginInfo = []; |
|
13 | 13 | |
14 | - $pluginInfo['items']['item']['caption'] = 'Article'; |
|
15 | - $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
16 | - $pluginInfo['items']['item']['request'] = 'itemid'; |
|
14 | + $pluginInfo['items']['item']['caption'] = 'Article'; |
|
15 | + $pluginInfo['items']['item']['url'] = 'item.php?itemid=%u'; |
|
16 | + $pluginInfo['items']['item']['request'] = 'itemid'; |
|
17 | 17 | |
18 | - $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | - $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
20 | - $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
18 | + $pluginInfo['items']['category']['caption'] = 'Category'; |
|
19 | + $pluginInfo['items']['category']['url'] = 'category.php?categoryid=%u'; |
|
20 | + $pluginInfo['items']['category']['request'] = 'categoryid'; |
|
21 | 21 | |
22 | - return $pluginInfo; |
|
22 | + return $pluginInfo; |
|
23 | 23 | } |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * @param $key |
|
179 | + * @param string $key |
|
180 | 180 | * @param $data_type |
181 | 181 | * @param bool $itemName |
182 | 182 | * @param string $form_caption |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
213 | 213 | * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
214 | 214 | * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
215 | - * @param mixed $value default value of this variable |
|
215 | + * @param string|false $value default value of this variable |
|
216 | 216 | */ |
217 | 217 | public function quickInitVar( |
218 | 218 | $key, |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | } |
228 | 228 | |
229 | 229 | /** |
230 | - * @param $varname |
|
230 | + * @param string $varname |
|
231 | 231 | * @param bool $displayOnForm |
232 | 232 | * @param string $default |
233 | 233 | */ |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | /** |
490 | 490 | * add an error |
491 | 491 | * |
492 | - * @param $err_str |
|
492 | + * @param string $err_str |
|
493 | 493 | * @param bool $prefix |
494 | 494 | * @internal param string $value error to add |
495 | 495 | * @access public |
@@ -751,8 +751,8 @@ discard block |
||
751 | 751 | |
752 | 752 | /** |
753 | 753 | * @param $key |
754 | - * @param $info |
|
755 | - * @param $value |
|
754 | + * @param string $info |
|
755 | + * @param boolean $value |
|
756 | 756 | */ |
757 | 757 | public function setVarInfo($key, $info, $value) |
758 | 758 | { |
@@ -760,7 +760,7 @@ discard block |
||
760 | 760 | } |
761 | 761 | |
762 | 762 | /** |
763 | - * @param $key |
|
763 | + * @param string $key |
|
764 | 764 | * @param bool $editor |
765 | 765 | * @return string |
766 | 766 | */ |
@@ -939,7 +939,7 @@ discard block |
||
939 | 939 | * @access public |
940 | 940 | * @param string $key key of the object's variable to be returned |
941 | 941 | * @param string $format format to use for the output |
942 | - * @return mixed formatted value of the variable |
|
942 | + * @return string formatted value of the variable |
|
943 | 943 | */ |
944 | 944 | public function getVar($key, $format = 's') |
945 | 945 | { |
@@ -1249,7 +1249,7 @@ discard block |
||
1249 | 1249 | } |
1250 | 1250 | |
1251 | 1251 | /** |
1252 | - * @param $key |
|
1252 | + * @param string $key |
|
1253 | 1253 | */ |
1254 | 1254 | public function hideFieldFromForm($key) |
1255 | 1255 | { |
@@ -20,31 +20,31 @@ discard block |
||
20 | 20 | require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
21 | 21 | |
22 | 22 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
23 | - define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
23 | + define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
|
24 | 24 | } |
25 | 25 | if (!defined('XOBJ_DTYPE_CURRENCY')) { |
26 | - define('XOBJ_DTYPE_CURRENCY', 200); |
|
26 | + define('XOBJ_DTYPE_CURRENCY', 200); |
|
27 | 27 | } |
28 | 28 | if (!defined('XOBJ_DTYPE_FLOAT')) { |
29 | - define('XOBJ_DTYPE_FLOAT', 201); |
|
29 | + define('XOBJ_DTYPE_FLOAT', 201); |
|
30 | 30 | } |
31 | 31 | if (!defined('XOBJ_DTYPE_TIME_ONLY')) { |
32 | - define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
32 | + define('XOBJ_DTYPE_TIME_ONLY', 202); |
|
33 | 33 | } |
34 | 34 | if (!defined('XOBJ_DTYPE_URLLINK')) { |
35 | - define('XOBJ_DTYPE_URLLINK', 203); |
|
35 | + define('XOBJ_DTYPE_URLLINK', 203); |
|
36 | 36 | } |
37 | 37 | if (!defined('XOBJ_DTYPE_FILE')) { |
38 | - define('XOBJ_DTYPE_FILE', 204); |
|
38 | + define('XOBJ_DTYPE_FILE', 204); |
|
39 | 39 | } |
40 | 40 | if (!defined('XOBJ_DTYPE_IMAGE')) { |
41 | - define('XOBJ_DTYPE_IMAGE', 205); |
|
41 | + define('XOBJ_DTYPE_IMAGE', 205); |
|
42 | 42 | } |
43 | 43 | if (!defined('XOBJ_DTYPE_FORM_SECTION')) { |
44 | - define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
44 | + define('XOBJ_DTYPE_FORM_SECTION', 210); |
|
45 | 45 | } |
46 | 46 | if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) { |
47 | - define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
47 | + define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -58,1402 +58,1402 @@ discard block |
||
58 | 58 | */ |
59 | 59 | class BaseSmartObject extends \XoopsObject |
60 | 60 | { |
61 | - public $_image_path; |
|
62 | - public $_image_url; |
|
63 | - |
|
64 | - public $seoEnabled = false; |
|
65 | - public $titleField; |
|
66 | - public $summaryField = false; |
|
67 | - |
|
68 | - /** |
|
69 | - * Reference to the handler managing this object |
|
70 | - * |
|
71 | - * @var PersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
72 | - */ |
|
73 | - public $handler; |
|
74 | - |
|
75 | - /** |
|
76 | - * References to control objects, managing the form fields of this object |
|
77 | - */ |
|
78 | - public $controls = []; |
|
79 | - |
|
80 | - /** |
|
81 | - * SmartObject constructor. |
|
82 | - * @param $handler |
|
83 | - */ |
|
84 | - public function __construct($handler) |
|
85 | - { |
|
86 | - $this->handler = $handler; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Checks if the user has a specific access on this object |
|
91 | - * |
|
92 | - * @param $perm_name |
|
93 | - * @return bool: TRUE if user has access, false if not |
|
94 | - * @internal param string $gperm_name name of the permission to test |
|
95 | - */ |
|
96 | - public function accessGranted($perm_name) |
|
97 | - { |
|
98 | - $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
99 | - |
|
100 | - return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * @param $section_name |
|
105 | - * @param bool $value |
|
106 | - * @param bool $hide |
|
107 | - */ |
|
108 | - public function addFormSection($section_name, $value = false, $hide = false) |
|
109 | - { |
|
110 | - $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
111 | - $this->vars[$section_name]['hide'] = $hide; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @param $section_name |
|
116 | - */ |
|
117 | - public function closeSection($section_name) |
|
118 | - { |
|
119 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * |
|
124 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
125 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
126 | - * @param mixed $value default value of this variable |
|
127 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
128 | - * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
129 | - * @param string $options does this data have any select options? |
|
130 | - * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
131 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
132 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
133 | - * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
134 | - * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
135 | - * @param bool $displayOnForm |
|
136 | - */ |
|
137 | - public function initVar( |
|
138 | - $key, |
|
139 | - $data_type, |
|
140 | - $value = null, |
|
141 | - $required = false, |
|
142 | - $maxlength = null, |
|
143 | - $options = '', |
|
144 | - $multilingual = false, |
|
145 | - $form_caption = '', |
|
146 | - $form_dsc = '', |
|
147 | - $sortby = false, |
|
148 | - $persistent = true, |
|
149 | - $displayOnForm = true |
|
150 | - ) { |
|
151 | - //url_ is reserved for files. |
|
152 | - if (0 === strpos($key, 'url_')) { |
|
153 | - trigger_error("Cannot use variable starting with 'url_'."); |
|
154 | - } |
|
155 | - parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
156 | - if ($this->handler && (!$form_caption || '' === $form_caption)) { |
|
157 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
158 | - if (defined($dyn_form_caption)) { |
|
159 | - $form_caption = constant($dyn_form_caption); |
|
160 | - } |
|
161 | - } |
|
162 | - if ($this->handler && (!$form_dsc || '' === $form_dsc)) { |
|
163 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
164 | - if (defined($dyn_form_dsc)) { |
|
165 | - $form_dsc = constant($dyn_form_dsc); |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - $this->vars[$key] = array_merge($this->vars[$key], [ |
|
170 | - 'multilingual' => $multilingual, |
|
171 | - 'form_caption' => $form_caption, |
|
172 | - 'form_dsc' => $form_dsc, |
|
173 | - 'sortby' => $sortby, |
|
174 | - 'persistent' => $persistent, |
|
175 | - 'displayOnForm' => $displayOnForm, |
|
176 | - 'displayOnSingleView' => true, |
|
177 | - 'readonly' => false |
|
178 | - ]); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param $key |
|
183 | - * @param $data_type |
|
184 | - * @param bool $itemName |
|
185 | - * @param string $form_caption |
|
186 | - * @param bool $sortby |
|
187 | - * @param string $value |
|
188 | - * @param bool $displayOnForm |
|
189 | - * @param bool $required |
|
190 | - */ |
|
191 | - public function initNonPersistableVar( |
|
192 | - $key, |
|
193 | - $data_type, |
|
194 | - $itemName = false, |
|
195 | - $form_caption = '', |
|
196 | - $sortby = false, |
|
197 | - $value = '', |
|
198 | - $displayOnForm = false, |
|
199 | - $required = false |
|
200 | - ) { |
|
201 | - $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
202 | - $this->vars[$key]['itemName'] = $itemName; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Quickly initiate a var |
|
207 | - * |
|
208 | - * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
209 | - * |
|
210 | - * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
211 | - * - all other vars are NULL or '' depending of the parameter |
|
212 | - * |
|
213 | - * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
214 | - * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
215 | - * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
216 | - * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
217 | - * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
218 | - * @param mixed $value default value of this variable |
|
219 | - */ |
|
220 | - public function quickInitVar( |
|
221 | - $key, |
|
222 | - $data_type, |
|
223 | - $required = false, |
|
224 | - $form_caption = '', |
|
225 | - $form_dsc = '', |
|
226 | - $value = null |
|
227 | - ) { |
|
228 | - $maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null; |
|
229 | - $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * @param $varname |
|
234 | - * @param bool $displayOnForm |
|
235 | - * @param string $default |
|
236 | - */ |
|
237 | - public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
238 | - { |
|
239 | - switch ($varname) { |
|
240 | - case 'dohtml': |
|
241 | - $value = 'notdefined' !== $default ? $default : true; |
|
242 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
243 | - $this->setControl($varname, 'yesno'); |
|
244 | - break; |
|
245 | - |
|
246 | - case 'dobr': |
|
247 | - $value = ('notdefined' === $default) ? true : $default; |
|
248 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
249 | - $this->setControl($varname, 'yesno'); |
|
250 | - break; |
|
251 | - |
|
252 | - case 'doimage': |
|
253 | - $value = 'notdefined' !== $default ? $default : true; |
|
254 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
255 | - $this->setControl($varname, 'yesno'); |
|
256 | - break; |
|
257 | - |
|
258 | - case 'dosmiley': |
|
259 | - $value = 'notdefined' !== $default ? $default : true; |
|
260 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
261 | - $this->setControl($varname, 'yesno'); |
|
262 | - break; |
|
263 | - |
|
264 | - case 'doxcode': |
|
265 | - $value = 'notdefined' !== $default ? $default : true; |
|
266 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
267 | - $this->setControl($varname, 'yesno'); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'meta_keywords': |
|
271 | - $value = 'notdefined' !== $default ? $default : ''; |
|
272 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
273 | - $this->setControl('meta_keywords', [ |
|
274 | - 'name' => 'textarea', |
|
275 | - 'form_editor' => 'textarea' |
|
276 | - ]); |
|
277 | - break; |
|
278 | - |
|
279 | - case 'meta_description': |
|
280 | - $value = 'notdefined' !== $default ? $default : ''; |
|
281 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
282 | - $this->setControl('meta_description', [ |
|
283 | - 'name' => 'textarea', |
|
284 | - 'form_editor' => 'textarea' |
|
285 | - ]); |
|
286 | - break; |
|
287 | - |
|
288 | - case 'short_url': |
|
289 | - $value = 'notdefined' !== $default ? $default : ''; |
|
290 | - $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
291 | - break; |
|
292 | - |
|
293 | - case 'hierarchy_path': |
|
294 | - $value = 'notdefined' !== $default ? $default : ''; |
|
295 | - $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
296 | - break; |
|
297 | - |
|
298 | - case 'counter': |
|
299 | - $value = 'notdefined' !== $default ? $default : 0; |
|
300 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
301 | - break; |
|
302 | - |
|
303 | - case 'weight': |
|
304 | - $value = 'notdefined' !== $default ? $default : 0; |
|
305 | - $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
306 | - break; |
|
307 | - case 'custom_css': |
|
308 | - $value = 'notdefined' !== $default ? $default : ''; |
|
309 | - $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
310 | - $this->setControl('custom_css', [ |
|
311 | - 'name' => 'textarea', |
|
312 | - 'form_editor' => 'textarea' |
|
313 | - ]); |
|
314 | - break; |
|
315 | - } |
|
316 | - $this->hideFieldFromSingleView($varname); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Set control information for an instance variable |
|
321 | - * |
|
322 | - * The $options parameter can be a string or an array. Using a string |
|
323 | - * is the quickest way: |
|
324 | - * |
|
325 | - * $this->setControl('date', 'date_time'); |
|
326 | - * |
|
327 | - * This will create a date and time selectbox for the 'date' var on the |
|
328 | - * form to edit or create this item. |
|
329 | - * |
|
330 | - * Here are the currently supported controls: |
|
331 | - * |
|
332 | - * - color |
|
333 | - * - country |
|
334 | - * - date_time |
|
335 | - * - date |
|
336 | ||
337 | - * - group |
|
338 | - * - group_multi |
|
339 | - * - image |
|
340 | - * - imageupload |
|
341 | - * - label |
|
342 | - * - language |
|
343 | - * - parentcategory |
|
344 | - * - password |
|
345 | - * - select_multi |
|
346 | - * - select |
|
347 | - * - text |
|
348 | - * - textarea |
|
349 | - * - theme |
|
350 | - * - theme_multi |
|
351 | - * - timezone |
|
352 | - * - user |
|
353 | - * - user_multi |
|
354 | - * - yesno |
|
355 | - * |
|
356 | - * Now, using an array as $options, you can customize what information to |
|
357 | - * use in the control. For example, if one needs to display a select box for |
|
358 | - * the user to choose the status of an item. We only need to tell SmartObject |
|
359 | - * what method to execute within what handler to retreive the options of the |
|
360 | - * selectbox. |
|
361 | - * |
|
362 | - * $this->setControl('status', array('name' => false, |
|
363 | - * 'itemHandler' => 'item', |
|
364 | - * 'method' => 'getStatus', |
|
365 | - * 'module' => 'smartshop')); |
|
366 | - * |
|
367 | - * In this example, the array elements are the following: |
|
368 | - * - name: false, as we don't need to set a special control here. |
|
369 | - * we will use the default control related to the object type (defined in initVar) |
|
370 | - * - itemHandler: name of the object for which we will use the handler |
|
371 | - * - method: name of the method of this handler that we will execute |
|
372 | - * - module: name of the module from wich the handler is |
|
373 | - * |
|
374 | - * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
375 | - * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
376 | - * |
|
377 | - * Another example of the use of $options as an array is for TextArea: |
|
378 | - * |
|
379 | - * $this->setControl('body', array('name' => 'textarea', |
|
380 | - * 'form_editor' => 'default')); |
|
381 | - * |
|
382 | - * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
383 | - * the 'default' editor, providing it is defined in the module |
|
384 | - * preferences: $helper->getConfig('default_editor') |
|
385 | - * |
|
386 | - * Of course, you can force the use of a specific editor: |
|
387 | - * |
|
388 | - * $this->setControl('body', array('name' => 'textarea', |
|
389 | - * 'form_editor' => 'koivi')); |
|
390 | - * |
|
391 | - * Here is a list of supported editor: |
|
392 | - * - tiny: TinyEditor |
|
393 | - * - dhtmltextarea: XOOPS DHTML Area |
|
394 | - * - fckeditor: FCKEditor |
|
395 | - * - inbetween: InBetween |
|
396 | - * - koivi: Koivi |
|
397 | - * - spaw: Spaw WYSIWYG Editor |
|
398 | - * - htmlarea: HTMLArea |
|
399 | - * - textarea: basic textarea with no options |
|
400 | - * |
|
401 | - * @param string $var name of the variable for which we want to set a control |
|
402 | - * @param array $options |
|
403 | - */ |
|
404 | - public function setControl($var, $options = []) |
|
405 | - { |
|
406 | - if (isset($this->controls[$var])) { |
|
407 | - unset($this->controls[$var]); |
|
408 | - } |
|
409 | - if (is_string($options)) { |
|
410 | - $options = ['name' => $options]; |
|
411 | - } |
|
412 | - $this->controls[$var] = $options; |
|
413 | - } |
|
414 | - |
|
415 | - /** |
|
416 | - * Get control information for an instance variable |
|
417 | - * |
|
418 | - * @param string $var |
|
419 | - * @return bool|mixed |
|
420 | - */ |
|
421 | - public function getControl($var) |
|
422 | - { |
|
423 | - return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
427 | - * Create the form for this object |
|
428 | - * |
|
429 | - * @param $form_caption |
|
430 | - * @param $form_name |
|
431 | - * @param bool $form_action |
|
432 | - * @param string $submit_button_caption |
|
433 | - * @param bool $cancel_js_action |
|
434 | - * @param bool $captcha |
|
435 | - * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
436 | - * object for this object |
|
437 | - * @see SmartObjectForm::SmartObjectForm() |
|
438 | - */ |
|
439 | - public function getForm( |
|
440 | - $form_caption, |
|
441 | - $form_name, |
|
442 | - $form_action = false, |
|
443 | - $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
444 | - $cancel_js_action = false, |
|
445 | - $captcha = false |
|
446 | - ) { |
|
61 | + public $_image_path; |
|
62 | + public $_image_url; |
|
63 | + |
|
64 | + public $seoEnabled = false; |
|
65 | + public $titleField; |
|
66 | + public $summaryField = false; |
|
67 | + |
|
68 | + /** |
|
69 | + * Reference to the handler managing this object |
|
70 | + * |
|
71 | + * @var PersistableObjectHandler reference to {@link SmartPersistableObjectHandler} |
|
72 | + */ |
|
73 | + public $handler; |
|
74 | + |
|
75 | + /** |
|
76 | + * References to control objects, managing the form fields of this object |
|
77 | + */ |
|
78 | + public $controls = []; |
|
79 | + |
|
80 | + /** |
|
81 | + * SmartObject constructor. |
|
82 | + * @param $handler |
|
83 | + */ |
|
84 | + public function __construct($handler) |
|
85 | + { |
|
86 | + $this->handler = $handler; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Checks if the user has a specific access on this object |
|
91 | + * |
|
92 | + * @param $perm_name |
|
93 | + * @return bool: TRUE if user has access, false if not |
|
94 | + * @internal param string $gperm_name name of the permission to test |
|
95 | + */ |
|
96 | + public function accessGranted($perm_name) |
|
97 | + { |
|
98 | + $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
99 | + |
|
100 | + return $smartPermissionsHandler->accessGranted($perm_name, $this->id()); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * @param $section_name |
|
105 | + * @param bool $value |
|
106 | + * @param bool $hide |
|
107 | + */ |
|
108 | + public function addFormSection($section_name, $value = false, $hide = false) |
|
109 | + { |
|
110 | + $this->initVar($section_name, XOBJ_DTYPE_FORM_SECTION, $value, false, null, '', false, '', '', false, false, true); |
|
111 | + $this->vars[$section_name]['hide'] = $hide; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @param $section_name |
|
116 | + */ |
|
117 | + public function closeSection($section_name) |
|
118 | + { |
|
119 | + $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * |
|
124 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
125 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
126 | + * @param mixed $value default value of this variable |
|
127 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
128 | + * @param int $maxlength maximum length of this variable, for XOBJ_DTYPE_TXTBOX type only |
|
129 | + * @param string $options does this data have any select options? |
|
130 | + * @param bool $multilingual is this field needs to support multilingual features (NOT YET IMPLEMENTED...) |
|
131 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
132 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
133 | + * @param bool $sortby set to TRUE to make this field used to sort objects in SmartObjectTable |
|
134 | + * @param bool $persistent set to FALSE if this field is not to be saved in the database |
|
135 | + * @param bool $displayOnForm |
|
136 | + */ |
|
137 | + public function initVar( |
|
138 | + $key, |
|
139 | + $data_type, |
|
140 | + $value = null, |
|
141 | + $required = false, |
|
142 | + $maxlength = null, |
|
143 | + $options = '', |
|
144 | + $multilingual = false, |
|
145 | + $form_caption = '', |
|
146 | + $form_dsc = '', |
|
147 | + $sortby = false, |
|
148 | + $persistent = true, |
|
149 | + $displayOnForm = true |
|
150 | + ) { |
|
151 | + //url_ is reserved for files. |
|
152 | + if (0 === strpos($key, 'url_')) { |
|
153 | + trigger_error("Cannot use variable starting with 'url_'."); |
|
154 | + } |
|
155 | + parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
|
156 | + if ($this->handler && (!$form_caption || '' === $form_caption)) { |
|
157 | + $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
158 | + if (defined($dyn_form_caption)) { |
|
159 | + $form_caption = constant($dyn_form_caption); |
|
160 | + } |
|
161 | + } |
|
162 | + if ($this->handler && (!$form_dsc || '' === $form_dsc)) { |
|
163 | + $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
164 | + if (defined($dyn_form_dsc)) { |
|
165 | + $form_dsc = constant($dyn_form_dsc); |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + $this->vars[$key] = array_merge($this->vars[$key], [ |
|
170 | + 'multilingual' => $multilingual, |
|
171 | + 'form_caption' => $form_caption, |
|
172 | + 'form_dsc' => $form_dsc, |
|
173 | + 'sortby' => $sortby, |
|
174 | + 'persistent' => $persistent, |
|
175 | + 'displayOnForm' => $displayOnForm, |
|
176 | + 'displayOnSingleView' => true, |
|
177 | + 'readonly' => false |
|
178 | + ]); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param $key |
|
183 | + * @param $data_type |
|
184 | + * @param bool $itemName |
|
185 | + * @param string $form_caption |
|
186 | + * @param bool $sortby |
|
187 | + * @param string $value |
|
188 | + * @param bool $displayOnForm |
|
189 | + * @param bool $required |
|
190 | + */ |
|
191 | + public function initNonPersistableVar( |
|
192 | + $key, |
|
193 | + $data_type, |
|
194 | + $itemName = false, |
|
195 | + $form_caption = '', |
|
196 | + $sortby = false, |
|
197 | + $value = '', |
|
198 | + $displayOnForm = false, |
|
199 | + $required = false |
|
200 | + ) { |
|
201 | + $this->initVar($key, $data_type, $value, $required, null, '', false, $form_caption, '', $sortby, false, $displayOnForm); |
|
202 | + $this->vars[$key]['itemName'] = $itemName; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Quickly initiate a var |
|
207 | + * |
|
208 | + * Since many vars do have the same config, let's use this method with some of these configuration as a convention ;-) |
|
209 | + * |
|
210 | + * - $maxlength = 0 unless $data_type is a TEXTBOX, then $maxlength will be 255 |
|
211 | + * - all other vars are NULL or '' depending of the parameter |
|
212 | + * |
|
213 | + * @param string $key key of this field. This needs to be the name of the field in the related database table |
|
214 | + * @param int $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type ckecking nor text sanitizing is required) |
|
215 | + * @param bool $required set to TRUE if this variable needs to have a value set before storing the object in the table |
|
216 | + * @param string $form_caption caption of this variable in a {@link SmartobjectForm} and title of a column in a {@link SmartObjectTable} |
|
217 | + * @param string $form_dsc description of this variable in a {@link SmartobjectForm} |
|
218 | + * @param mixed $value default value of this variable |
|
219 | + */ |
|
220 | + public function quickInitVar( |
|
221 | + $key, |
|
222 | + $data_type, |
|
223 | + $required = false, |
|
224 | + $form_caption = '', |
|
225 | + $form_dsc = '', |
|
226 | + $value = null |
|
227 | + ) { |
|
228 | + $maxlength = 'XOBJ_DTYPE_TXTBOX' === $data_type ? 255 : null; |
|
229 | + $this->initVar($key, $data_type, $value, $required, $maxlength, '', false, $form_caption, $form_dsc, false, true, true); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * @param $varname |
|
234 | + * @param bool $displayOnForm |
|
235 | + * @param string $default |
|
236 | + */ |
|
237 | + public function initCommonVar($varname, $displayOnForm = true, $default = 'notdefined') |
|
238 | + { |
|
239 | + switch ($varname) { |
|
240 | + case 'dohtml': |
|
241 | + $value = 'notdefined' !== $default ? $default : true; |
|
242 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOHTML_FORM_CAPTION, '', false, true, $displayOnForm); |
|
243 | + $this->setControl($varname, 'yesno'); |
|
244 | + break; |
|
245 | + |
|
246 | + case 'dobr': |
|
247 | + $value = ('notdefined' === $default) ? true : $default; |
|
248 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOBR_FORM_CAPTION, '', false, true, $displayOnForm); |
|
249 | + $this->setControl($varname, 'yesno'); |
|
250 | + break; |
|
251 | + |
|
252 | + case 'doimage': |
|
253 | + $value = 'notdefined' !== $default ? $default : true; |
|
254 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOIMAGE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
255 | + $this->setControl($varname, 'yesno'); |
|
256 | + break; |
|
257 | + |
|
258 | + case 'dosmiley': |
|
259 | + $value = 'notdefined' !== $default ? $default : true; |
|
260 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOSMILEY_FORM_CAPTION, '', false, true, $displayOnForm); |
|
261 | + $this->setControl($varname, 'yesno'); |
|
262 | + break; |
|
263 | + |
|
264 | + case 'doxcode': |
|
265 | + $value = 'notdefined' !== $default ? $default : true; |
|
266 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_DOXCODE_FORM_CAPTION, '', false, true, $displayOnForm); |
|
267 | + $this->setControl($varname, 'yesno'); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'meta_keywords': |
|
271 | + $value = 'notdefined' !== $default ? $default : ''; |
|
272 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_KEYWORDS, _CO_SOBJECT_META_KEYWORDS_DSC, false, true, $displayOnForm); |
|
273 | + $this->setControl('meta_keywords', [ |
|
274 | + 'name' => 'textarea', |
|
275 | + 'form_editor' => 'textarea' |
|
276 | + ]); |
|
277 | + break; |
|
278 | + |
|
279 | + case 'meta_description': |
|
280 | + $value = 'notdefined' !== $default ? $default : ''; |
|
281 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_META_DESCRIPTION, _CO_SOBJECT_META_DESCRIPTION_DSC, false, true, $displayOnForm); |
|
282 | + $this->setControl('meta_description', [ |
|
283 | + 'name' => 'textarea', |
|
284 | + 'form_editor' => 'textarea' |
|
285 | + ]); |
|
286 | + break; |
|
287 | + |
|
288 | + case 'short_url': |
|
289 | + $value = 'notdefined' !== $default ? $default : ''; |
|
290 | + $this->initVar($varname, XOBJ_DTYPE_TXTBOX, $value, false, null, '', false, _CO_SOBJECT_SHORT_URL, _CO_SOBJECT_SHORT_URL_DSC, false, true, $displayOnForm); |
|
291 | + break; |
|
292 | + |
|
293 | + case 'hierarchy_path': |
|
294 | + $value = 'notdefined' !== $default ? $default : ''; |
|
295 | + $this->initVar($varname, XOBJ_DTYPE_ARRAY, $value, false, null, '', false, _CO_SOBJECT_HIERARCHY_PATH, _CO_SOBJECT_HIERARCHY_PATH_DSC, false, true, $displayOnForm); |
|
296 | + break; |
|
297 | + |
|
298 | + case 'counter': |
|
299 | + $value = 'notdefined' !== $default ? $default : 0; |
|
300 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_COUNTER_FORM_CAPTION, '', false, true, $displayOnForm); |
|
301 | + break; |
|
302 | + |
|
303 | + case 'weight': |
|
304 | + $value = 'notdefined' !== $default ? $default : 0; |
|
305 | + $this->initVar($varname, XOBJ_DTYPE_INT, $value, false, null, '', false, _CO_SOBJECT_WEIGHT_FORM_CAPTION, '', true, true, $displayOnForm); |
|
306 | + break; |
|
307 | + case 'custom_css': |
|
308 | + $value = 'notdefined' !== $default ? $default : ''; |
|
309 | + $this->initVar($varname, XOBJ_DTYPE_TXTAREA, $value, false, null, '', false, _CO_SOBJECT_CUSTOM_CSS, _CO_SOBJECT_CUSTOM_CSS_DSC, false, true, $displayOnForm); |
|
310 | + $this->setControl('custom_css', [ |
|
311 | + 'name' => 'textarea', |
|
312 | + 'form_editor' => 'textarea' |
|
313 | + ]); |
|
314 | + break; |
|
315 | + } |
|
316 | + $this->hideFieldFromSingleView($varname); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Set control information for an instance variable |
|
321 | + * |
|
322 | + * The $options parameter can be a string or an array. Using a string |
|
323 | + * is the quickest way: |
|
324 | + * |
|
325 | + * $this->setControl('date', 'date_time'); |
|
326 | + * |
|
327 | + * This will create a date and time selectbox for the 'date' var on the |
|
328 | + * form to edit or create this item. |
|
329 | + * |
|
330 | + * Here are the currently supported controls: |
|
331 | + * |
|
332 | + * - color |
|
333 | + * - country |
|
334 | + * - date_time |
|
335 | + * - date |
|
336 | ||
337 | + * - group |
|
338 | + * - group_multi |
|
339 | + * - image |
|
340 | + * - imageupload |
|
341 | + * - label |
|
342 | + * - language |
|
343 | + * - parentcategory |
|
344 | + * - password |
|
345 | + * - select_multi |
|
346 | + * - select |
|
347 | + * - text |
|
348 | + * - textarea |
|
349 | + * - theme |
|
350 | + * - theme_multi |
|
351 | + * - timezone |
|
352 | + * - user |
|
353 | + * - user_multi |
|
354 | + * - yesno |
|
355 | + * |
|
356 | + * Now, using an array as $options, you can customize what information to |
|
357 | + * use in the control. For example, if one needs to display a select box for |
|
358 | + * the user to choose the status of an item. We only need to tell SmartObject |
|
359 | + * what method to execute within what handler to retreive the options of the |
|
360 | + * selectbox. |
|
361 | + * |
|
362 | + * $this->setControl('status', array('name' => false, |
|
363 | + * 'itemHandler' => 'item', |
|
364 | + * 'method' => 'getStatus', |
|
365 | + * 'module' => 'smartshop')); |
|
366 | + * |
|
367 | + * In this example, the array elements are the following: |
|
368 | + * - name: false, as we don't need to set a special control here. |
|
369 | + * we will use the default control related to the object type (defined in initVar) |
|
370 | + * - itemHandler: name of the object for which we will use the handler |
|
371 | + * - method: name of the method of this handler that we will execute |
|
372 | + * - module: name of the module from wich the handler is |
|
373 | + * |
|
374 | + * So in this example, SmartObject will create a selectbox for the variable 'status' and it will |
|
375 | + * populate this selectbox with the result from SmartshopItemHandler::getStatus() |
|
376 | + * |
|
377 | + * Another example of the use of $options as an array is for TextArea: |
|
378 | + * |
|
379 | + * $this->setControl('body', array('name' => 'textarea', |
|
380 | + * 'form_editor' => 'default')); |
|
381 | + * |
|
382 | + * In this example, SmartObject will create a TextArea for the variable 'body'. And it will use |
|
383 | + * the 'default' editor, providing it is defined in the module |
|
384 | + * preferences: $helper->getConfig('default_editor') |
|
385 | + * |
|
386 | + * Of course, you can force the use of a specific editor: |
|
387 | + * |
|
388 | + * $this->setControl('body', array('name' => 'textarea', |
|
389 | + * 'form_editor' => 'koivi')); |
|
390 | + * |
|
391 | + * Here is a list of supported editor: |
|
392 | + * - tiny: TinyEditor |
|
393 | + * - dhtmltextarea: XOOPS DHTML Area |
|
394 | + * - fckeditor: FCKEditor |
|
395 | + * - inbetween: InBetween |
|
396 | + * - koivi: Koivi |
|
397 | + * - spaw: Spaw WYSIWYG Editor |
|
398 | + * - htmlarea: HTMLArea |
|
399 | + * - textarea: basic textarea with no options |
|
400 | + * |
|
401 | + * @param string $var name of the variable for which we want to set a control |
|
402 | + * @param array $options |
|
403 | + */ |
|
404 | + public function setControl($var, $options = []) |
|
405 | + { |
|
406 | + if (isset($this->controls[$var])) { |
|
407 | + unset($this->controls[$var]); |
|
408 | + } |
|
409 | + if (is_string($options)) { |
|
410 | + $options = ['name' => $options]; |
|
411 | + } |
|
412 | + $this->controls[$var] = $options; |
|
413 | + } |
|
414 | + |
|
415 | + /** |
|
416 | + * Get control information for an instance variable |
|
417 | + * |
|
418 | + * @param string $var |
|
419 | + * @return bool|mixed |
|
420 | + */ |
|
421 | + public function getControl($var) |
|
422 | + { |
|
423 | + return isset($this->controls[$var]) ? $this->controls[$var] : false; |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | + * Create the form for this object |
|
428 | + * |
|
429 | + * @param $form_caption |
|
430 | + * @param $form_name |
|
431 | + * @param bool $form_action |
|
432 | + * @param string $submit_button_caption |
|
433 | + * @param bool $cancel_js_action |
|
434 | + * @param bool $captcha |
|
435 | + * @return \XoopsModules\Smartobject\Form\SmartobjectForm <a href='psi_element://SmartobjectForm'>SmartobjectForm</a> object for this object |
|
436 | + * object for this object |
|
437 | + * @see SmartObjectForm::SmartObjectForm() |
|
438 | + */ |
|
439 | + public function getForm( |
|
440 | + $form_caption, |
|
441 | + $form_name, |
|
442 | + $form_action = false, |
|
443 | + $submit_button_caption = _CO_SOBJECT_SUBMIT, |
|
444 | + $cancel_js_action = false, |
|
445 | + $captcha = false |
|
446 | + ) { |
|
447 | 447 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/smartobjectform.php'; |
448 | - $form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
449 | - |
|
450 | - return $form; |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * @return array |
|
455 | - */ |
|
456 | - public function toArray() |
|
457 | - { |
|
458 | - $ret = []; |
|
459 | - $vars =& $this->getVars(); |
|
460 | - foreach ($vars as $key => $var) { |
|
461 | - $value = $this->getVar($key); |
|
462 | - $ret[$key] = $value; |
|
463 | - } |
|
464 | - if ('' !== $this->handler->identifierName) { |
|
465 | - $controller = new ObjectController($this->handler); |
|
466 | - /** |
|
467 | - * Addition of some automatic value |
|
468 | - */ |
|
469 | - $ret['itemLink'] = $controller->getItemLink($this); |
|
470 | - $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
471 | - $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
472 | - $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
473 | - $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
474 | - } |
|
475 | - |
|
476 | - // Hightlighting searched words |
|
448 | + $form = new Smartobject\Form\SmartobjectForm($this, $form_name, $form_caption, $form_action, null, $submit_button_caption, $cancel_js_action, $captcha); |
|
449 | + |
|
450 | + return $form; |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * @return array |
|
455 | + */ |
|
456 | + public function toArray() |
|
457 | + { |
|
458 | + $ret = []; |
|
459 | + $vars =& $this->getVars(); |
|
460 | + foreach ($vars as $key => $var) { |
|
461 | + $value = $this->getVar($key); |
|
462 | + $ret[$key] = $value; |
|
463 | + } |
|
464 | + if ('' !== $this->handler->identifierName) { |
|
465 | + $controller = new ObjectController($this->handler); |
|
466 | + /** |
|
467 | + * Addition of some automatic value |
|
468 | + */ |
|
469 | + $ret['itemLink'] = $controller->getItemLink($this); |
|
470 | + $ret['itemUrl'] = $controller->getItemLink($this, true); |
|
471 | + $ret['editItemLink'] = $controller->getEditItemLink($this, false, true); |
|
472 | + $ret['deleteItemLink'] = $controller->getDeleteItemLink($this, false, true); |
|
473 | + $ret['printAndMailLink'] = $controller->getPrintAndMailLink($this); |
|
474 | + } |
|
475 | + |
|
476 | + // Hightlighting searched words |
|
477 | 477 | // require_once SMARTOBJECT_ROOT_PATH . 'class/smarthighlighter.php'; |
478 | - $highlight = Smartobject\Utility::getConfig('module_search_highlighter', false, true); |
|
479 | - |
|
480 | - if ($highlight && isset($_GET['keywords'])) { |
|
481 | - $myts = \MyTextSanitizer::getInstance(); |
|
482 | - $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
483 | - $h = new Highlighter($keywords, true, 'smart_highlighter'); |
|
484 | - foreach ($this->handler->highlightFields as $field) { |
|
485 | - $ret[$field] = $h->highlight($ret[$field]); |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - return $ret; |
|
490 | - } |
|
491 | - |
|
492 | - /** |
|
493 | - * add an error |
|
494 | - * |
|
495 | - * @param $err_str |
|
496 | - * @param bool $prefix |
|
497 | - * @internal param string $value error to add |
|
498 | - * @access public |
|
499 | - */ |
|
500 | - public function setErrors($err_str, $prefix = false) |
|
501 | - { |
|
502 | - if (is_array($err_str)) { |
|
503 | - foreach ($err_str as $str) { |
|
504 | - $this->setErrors($str, $prefix); |
|
505 | - } |
|
506 | - } else { |
|
507 | - if ($prefix) { |
|
508 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
509 | - } |
|
510 | - parent::setErrors($err_str); |
|
511 | - } |
|
512 | - } |
|
513 | - |
|
514 | - /** |
|
515 | - * @param $field |
|
516 | - * @param bool $required |
|
517 | - */ |
|
518 | - public function setFieldAsRequired($field, $required = true) |
|
519 | - { |
|
520 | - if (is_array($field)) { |
|
521 | - foreach ($field as $v) { |
|
522 | - $this->doSetFieldAsRequired($v, $required); |
|
523 | - } |
|
524 | - } else { |
|
525 | - $this->doSetFieldAsRequired($field, $required); |
|
526 | - } |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * @param $field |
|
531 | - */ |
|
532 | - public function setFieldForSorting($field) |
|
533 | - { |
|
534 | - if (is_array($field)) { |
|
535 | - foreach ($field as $v) { |
|
536 | - $this->doSetFieldForSorting($v); |
|
537 | - } |
|
538 | - } else { |
|
539 | - $this->doSetFieldForSorting($field); |
|
540 | - } |
|
541 | - } |
|
542 | - |
|
543 | - /** |
|
544 | - * @return bool |
|
545 | - */ |
|
546 | - public function hasError() |
|
547 | - { |
|
548 | - return count($this->_errors) > 0; |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * @param $url |
|
553 | - * @param $path |
|
554 | - */ |
|
555 | - public function setImageDir($url, $path) |
|
556 | - { |
|
557 | - $this->_image_url = $url; |
|
558 | - $this->_image_path = $path; |
|
559 | - } |
|
560 | - |
|
561 | - /** |
|
562 | - * Retreive the group that have been granted access to a specific permission for this object |
|
563 | - * |
|
564 | - * @param $group_perm |
|
565 | - * @return string $group_perm name of the permission |
|
566 | - */ |
|
567 | - public function getGroupPerm($group_perm) |
|
568 | - { |
|
569 | - if (!$this->handler->getPermissions()) { |
|
570 | - $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
571 | - |
|
572 | - return false; |
|
573 | - } |
|
574 | - |
|
575 | - $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
576 | - $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
577 | - |
|
578 | - if (0 == count($ret)) { |
|
579 | - return false; |
|
580 | - } else { |
|
581 | - return $ret; |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - /** |
|
586 | - * @param bool $path |
|
587 | - * @return mixed |
|
588 | - */ |
|
589 | - public function getImageDir($path = false) |
|
590 | - { |
|
591 | - if ($path) { |
|
592 | - return $this->_image_path; |
|
593 | - } else { |
|
594 | - return $this->_image_url; |
|
595 | - } |
|
596 | - } |
|
597 | - |
|
598 | - /** |
|
599 | - * @param bool $path |
|
600 | - * @return mixed |
|
601 | - */ |
|
602 | - public function getUploadDir($path = false) |
|
603 | - { |
|
604 | - if ($path) { |
|
605 | - return $this->_image_path; |
|
606 | - } else { |
|
607 | - return $this->_image_url; |
|
608 | - } |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * @param string $key |
|
613 | - * @param string $info |
|
614 | - * @return array |
|
615 | - */ |
|
616 | - public function getVarInfo($key = '', $info = '') |
|
617 | - { |
|
618 | - if (isset($this->vars[$key][$info])) { |
|
619 | - return $this->vars[$key][$info]; |
|
620 | - } elseif ('' === $info && isset($this->vars[$key])) { |
|
621 | - return $this->vars[$key]; |
|
622 | - } else { |
|
623 | - return $this->vars; |
|
624 | - } |
|
625 | - } |
|
626 | - |
|
627 | - /** |
|
628 | - * Get the id of the object |
|
629 | - * |
|
630 | - * @return int id of this object |
|
631 | - */ |
|
632 | - public function id() |
|
633 | - { |
|
634 | - return $this->getVar($this->handler->keyName, 'e'); |
|
635 | - } |
|
636 | - |
|
637 | - /** |
|
638 | - * Return the value of the title field of this object |
|
639 | - * |
|
640 | - * @param string $format |
|
641 | - * @return string |
|
642 | - */ |
|
643 | - public function title($format = 's') |
|
644 | - { |
|
645 | - return $this->getVar($this->handler->identifierName, $format); |
|
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * Return the value of the title field of this object |
|
650 | - * |
|
651 | - * @return string |
|
652 | - */ |
|
653 | - public function summary() |
|
654 | - { |
|
655 | - if ($this->handler->summaryName) { |
|
656 | - return $this->getVar($this->handler->summaryName); |
|
657 | - } else { |
|
658 | - return false; |
|
659 | - } |
|
660 | - } |
|
661 | - |
|
662 | - /** |
|
663 | - * Retreive the object admin side link, displayijng a SingleView page |
|
664 | - * |
|
665 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
666 | - * @return string user side link to the object |
|
667 | - */ |
|
668 | - public function getAdminViewItemLink($onlyUrl = false) |
|
669 | - { |
|
670 | - $controller = new ObjectController($this->handler); |
|
671 | - |
|
672 | - return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Retreive the object user side link |
|
677 | - * |
|
678 | - * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
679 | - * @return string user side link to the object |
|
680 | - */ |
|
681 | - public function getItemLink($onlyUrl = false) |
|
682 | - { |
|
683 | - $controller = new ObjectController($this->handler); |
|
684 | - |
|
685 | - return $controller->getItemLink($this, $onlyUrl); |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * @param bool $onlyUrl |
|
690 | - * @param bool $withimage |
|
691 | - * @param bool $userSide |
|
692 | - * @return string |
|
693 | - */ |
|
694 | - public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
695 | - { |
|
696 | - $controller = new ObjectController($this->handler); |
|
697 | - |
|
698 | - return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
699 | - } |
|
700 | - |
|
701 | - /** |
|
702 | - * @param bool $onlyUrl |
|
703 | - * @param bool $withimage |
|
704 | - * @param bool $userSide |
|
705 | - * @return string |
|
706 | - */ |
|
707 | - public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
708 | - { |
|
709 | - $controller = new ObjectController($this->handler); |
|
710 | - |
|
711 | - return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
712 | - } |
|
713 | - |
|
714 | - /** |
|
715 | - * @return string |
|
716 | - */ |
|
717 | - public function getPrintAndMailLink() |
|
718 | - { |
|
719 | - $controller = new ObjectController($this->handler); |
|
720 | - |
|
721 | - return $controller->getPrintAndMailLink($this); |
|
722 | - } |
|
723 | - |
|
724 | - /** |
|
725 | - * @param $sortsel |
|
726 | - * @return array|bool |
|
727 | - */ |
|
728 | - public function getFieldsForSorting($sortsel) |
|
729 | - { |
|
730 | - $ret = []; |
|
731 | - |
|
732 | - foreach ($this->vars as $key => $field_info) { |
|
733 | - if ($field_info['sortby']) { |
|
734 | - $ret[$key]['caption'] = $field_info['form_caption']; |
|
735 | - $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
736 | - } |
|
737 | - } |
|
738 | - |
|
739 | - if (count($ret) > 0) { |
|
740 | - return $ret; |
|
741 | - } else { |
|
742 | - return false; |
|
743 | - } |
|
744 | - } |
|
745 | - |
|
746 | - /** |
|
747 | - * @param $key |
|
748 | - * @param $newType |
|
749 | - */ |
|
750 | - public function setType($key, $newType) |
|
751 | - { |
|
752 | - $this->vars[$key]['data_type'] = $newType; |
|
753 | - } |
|
754 | - |
|
755 | - /** |
|
756 | - * @param $key |
|
757 | - * @param $info |
|
758 | - * @param $value |
|
759 | - */ |
|
760 | - public function setVarInfo($key, $info, $value) |
|
761 | - { |
|
762 | - $this->vars[$key][$info] = $value; |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * @param $key |
|
767 | - * @param bool $editor |
|
768 | - * @return string |
|
769 | - */ |
|
770 | - public function getValueFor($key, $editor = true) |
|
771 | - { |
|
772 | - /** @var Smartmedia\Helper $helper */ |
|
773 | - $helper = Smartmedia\Helper::getInstance(); |
|
774 | - |
|
775 | - $ret = $this->getVar($key, 'n'); |
|
776 | - $myts = \MyTextSanitizer::getInstance(); |
|
777 | - |
|
778 | - $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
779 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
780 | - |
|
781 | - $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
782 | - $smiley = true; |
|
783 | - $xcode = true; |
|
784 | - $image = true; |
|
785 | - $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
786 | - $formatML = true; |
|
787 | - |
|
788 | - if ('default' === $form_editor) { |
|
789 | - /** @var Smartmedia\Helper $helper */ |
|
790 | - $helper = Smartmedia\Helper::getInstance(); |
|
791 | - |
|
792 | - $form_editor = null !==($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea'; |
|
793 | - } |
|
794 | - |
|
795 | - if ($editor) { |
|
796 | - if (defined('XOOPS_EDITOR_IS_HTML') |
|
797 | - && !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) { |
|
798 | - $br = false; |
|
799 | - $formatML = !$editor; |
|
800 | - } else { |
|
801 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
802 | - } |
|
803 | - } |
|
804 | - |
|
805 | - if (method_exists($myts, 'formatForML')) { |
|
806 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
807 | - } else { |
|
808 | - return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
809 | - } |
|
810 | - } |
|
811 | - |
|
812 | - /** |
|
813 | - * clean values of all variables of the object for storage. |
|
814 | - * also add slashes whereever needed |
|
815 | - * |
|
816 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
817 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
818 | - * as a string separated by | |
|
819 | - * |
|
820 | - * @return bool true if successful |
|
821 | - * @access public |
|
822 | - */ |
|
823 | - public function cleanVars() |
|
824 | - { |
|
825 | - $ts = \MyTextSanitizer::getInstance(); |
|
826 | - $existing_errors = $this->getErrors(); |
|
827 | - $this->_errors = []; |
|
828 | - foreach ($this->vars as $k => $v) { |
|
829 | - $cleanv = $v['value']; |
|
830 | - if (!$v['changed']) { |
|
831 | - } else { |
|
832 | - $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
833 | - switch ($v['data_type']) { |
|
834 | - case XOBJ_DTYPE_TXTBOX: |
|
835 | - if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
836 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
837 | - continue 2; |
|
838 | - } |
|
839 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
840 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
841 | - continue 2; |
|
842 | - } |
|
843 | - if (!$v['not_gpc']) { |
|
844 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
845 | - } else { |
|
846 | - $cleanv = $ts->censorString($cleanv); |
|
847 | - } |
|
848 | - break; |
|
849 | - case XOBJ_DTYPE_TXTAREA: |
|
850 | - if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
851 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
852 | - continue 2; |
|
853 | - } |
|
854 | - if (!$v['not_gpc']) { |
|
855 | - $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
856 | - } else { |
|
857 | - $cleanv = $ts->censorString($cleanv); |
|
858 | - } |
|
859 | - break; |
|
860 | - case XOBJ_DTYPE_SOURCE: |
|
861 | - if (!$v['not_gpc']) { |
|
862 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
863 | - } else { |
|
864 | - $cleanv = $cleanv; |
|
865 | - } |
|
866 | - break; |
|
867 | - case XOBJ_DTYPE_INT: |
|
868 | - case XOBJ_DTYPE_TIME_ONLY: |
|
869 | - $cleanv = (int)$cleanv; |
|
870 | - break; |
|
871 | - |
|
872 | - case XOBJ_DTYPE_CURRENCY: |
|
873 | - $cleanv = Smartobject\Utility::getCurrency($cleanv); |
|
874 | - break; |
|
875 | - |
|
876 | - case XOBJ_DTYPE_FLOAT: |
|
877 | - $cleanv = Smartobject\Utility::float($cleanv); |
|
878 | - break; |
|
879 | - |
|
880 | - case XOBJ_DTYPE_EMAIL: |
|
881 | - if ($v['required'] && '' === $cleanv) { |
|
882 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
883 | - continue 2; |
|
884 | - } |
|
885 | - if ('' !== $cleanv |
|
886 | - && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
887 | - $this->setErrors('Invalid Email'); |
|
888 | - continue 2; |
|
889 | - } |
|
890 | - if (!$v['not_gpc']) { |
|
891 | - $cleanv = $ts->stripSlashesGPC($cleanv); |
|
892 | - } |
|
893 | - break; |
|
894 | - case XOBJ_DTYPE_URL: |
|
895 | - if ($v['required'] && '' === $cleanv) { |
|
896 | - $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
897 | - continue 2; |
|
898 | - } |
|
899 | - if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
900 | - $cleanv = 'http://' . $cleanv; |
|
901 | - } |
|
902 | - if (!$v['not_gpc']) { |
|
903 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
904 | - } |
|
905 | - break; |
|
906 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
907 | - $cleanv = implode('|', $cleanv); |
|
908 | - break; |
|
909 | - case XOBJ_DTYPE_ARRAY: |
|
910 | - $cleanv = serialize($cleanv); |
|
911 | - break; |
|
912 | - case XOBJ_DTYPE_STIME: |
|
913 | - case XOBJ_DTYPE_MTIME: |
|
914 | - case XOBJ_DTYPE_LTIME: |
|
915 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
916 | - if (!($cleanv > 0)) { |
|
917 | - $cleanv = strtotime($cleanv); |
|
918 | - } |
|
919 | - break; |
|
920 | - default: |
|
921 | - break; |
|
922 | - } |
|
923 | - } |
|
924 | - $this->cleanVars[$k] =& $cleanv; |
|
925 | - unset($cleanv); |
|
926 | - } |
|
927 | - if (count($this->_errors) > 0) { |
|
928 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
929 | - |
|
930 | - return false; |
|
931 | - } |
|
932 | - $this->_errors = array_merge($existing_errors, $this->_errors); |
|
933 | - $this->unsetDirty(); |
|
934 | - |
|
935 | - return true; |
|
936 | - } |
|
937 | - |
|
938 | - /** |
|
939 | - * returns a specific variable for the object in a proper format |
|
940 | - * |
|
941 | - * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
942 | - * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
943 | - * as a string separated by | |
|
944 | - * |
|
945 | - * @access public |
|
946 | - * @param string $key key of the object's variable to be returned |
|
947 | - * @param string $format format to use for the output |
|
948 | - * @return mixed formatted value of the variable |
|
949 | - */ |
|
950 | - public function getVar($key, $format = 's') |
|
951 | - { |
|
952 | - global $myts; |
|
953 | - |
|
954 | - $ret = $this->vars[$key]['value']; |
|
955 | - |
|
956 | - switch ($this->vars[$key]['data_type']) { |
|
957 | - |
|
958 | - case XOBJ_DTYPE_TXTBOX: |
|
959 | - switch (strtolower($format)) { |
|
960 | - case 's': |
|
961 | - case 'show': |
|
962 | - // ML Hack by marcan |
|
963 | - $ts = \MyTextSanitizer::getInstance(); |
|
964 | - $ret = $ts->htmlSpecialChars($ret); |
|
965 | - |
|
966 | - if (method_exists($myts, 'formatForML')) { |
|
967 | - return $ts->formatForML($ret); |
|
968 | - } else { |
|
969 | - return $ret; |
|
970 | - } |
|
971 | - break 1; |
|
972 | - // End of ML Hack by marcan |
|
973 | - |
|
974 | - case 'clean': |
|
975 | - $ts = \MyTextSanitizer::getInstance(); |
|
976 | - |
|
977 | - $ret = Smartobject\Utility::getHtml2text($ret); |
|
978 | - $ret = Smartobject\Utility::purifyText($ret); |
|
979 | - |
|
980 | - if (method_exists($myts, 'formatForML')) { |
|
981 | - return $ts->formatForML($ret); |
|
982 | - } else { |
|
983 | - return $ret; |
|
984 | - } |
|
985 | - break 1; |
|
986 | - // End of ML Hack by marcan |
|
987 | - |
|
988 | - case 'e': |
|
989 | - case 'edit': |
|
990 | - $ts = \MyTextSanitizer::getInstance(); |
|
991 | - |
|
992 | - return $ts->htmlSpecialChars($ret); |
|
993 | - break 1; |
|
994 | - case 'p': |
|
995 | - case 'preview': |
|
996 | - case 'f': |
|
997 | - case 'formpreview': |
|
998 | - $ts = \MyTextSanitizer::getInstance(); |
|
999 | - |
|
1000 | - return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
1001 | - break 1; |
|
1002 | - case 'n': |
|
1003 | - case 'none': |
|
1004 | - default: |
|
1005 | - break 1; |
|
1006 | - } |
|
1007 | - break; |
|
1008 | - case XOBJ_DTYPE_LTIME: |
|
1009 | - switch (strtolower($format)) { |
|
1010 | - case 's': |
|
1011 | - case 'show': |
|
1012 | - case 'p': |
|
1013 | - case 'preview': |
|
1014 | - case 'f': |
|
1015 | - case 'formpreview': |
|
1016 | - $ret = formatTimestamp($ret, _DATESTRING); |
|
1017 | - |
|
1018 | - return $ret; |
|
1019 | - break 1; |
|
1020 | - case 'n': |
|
1021 | - case 'none': |
|
1022 | - case 'e': |
|
1023 | - case 'edit': |
|
1024 | - break 1; |
|
1025 | - default: |
|
1026 | - break 1; |
|
1027 | - } |
|
1028 | - break; |
|
1029 | - case XOBJ_DTYPE_STIME: |
|
1030 | - switch (strtolower($format)) { |
|
1031 | - case 's': |
|
1032 | - case 'show': |
|
1033 | - case 'p': |
|
1034 | - case 'preview': |
|
1035 | - case 'f': |
|
1036 | - case 'formpreview': |
|
1037 | - $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
1038 | - |
|
1039 | - return $ret; |
|
1040 | - break 1; |
|
1041 | - case 'n': |
|
1042 | - case 'none': |
|
1043 | - case 'e': |
|
1044 | - case 'edit': |
|
1045 | - break 1; |
|
1046 | - default: |
|
1047 | - break 1; |
|
1048 | - } |
|
1049 | - break; |
|
1050 | - case XOBJ_DTYPE_TIME_ONLY: |
|
1051 | - switch (strtolower($format)) { |
|
1052 | - case 's': |
|
1053 | - case 'show': |
|
1054 | - case 'p': |
|
1055 | - case 'preview': |
|
1056 | - case 'f': |
|
1057 | - case 'formpreview': |
|
1058 | - $ret = formatTimestamp($ret, 'G:i'); |
|
1059 | - |
|
1060 | - return $ret; |
|
1061 | - break 1; |
|
1062 | - case 'n': |
|
1063 | - case 'none': |
|
1064 | - case 'e': |
|
1065 | - case 'edit': |
|
1066 | - break 1; |
|
1067 | - default: |
|
1068 | - break 1; |
|
1069 | - } |
|
1070 | - break; |
|
1071 | - |
|
1072 | - case XOBJ_DTYPE_CURRENCY: |
|
1073 | - $decimal_section_original = strstr($ret, '.'); |
|
1074 | - $decimal_section = $decimal_section_original; |
|
1075 | - if ($decimal_section) { |
|
1076 | - if (1 == strlen($decimal_section)) { |
|
1077 | - $decimal_section = '.00'; |
|
1078 | - } elseif (2 == strlen($decimal_section)) { |
|
1079 | - $decimal_section .= '0'; |
|
1080 | - } |
|
1081 | - $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1082 | - } else { |
|
1083 | - $ret .= '.00'; |
|
1084 | - } |
|
1085 | - break; |
|
1086 | - |
|
1087 | - case XOBJ_DTYPE_TXTAREA: |
|
1088 | - switch (strtolower($format)) { |
|
1089 | - case 's': |
|
1090 | - case 'show': |
|
1091 | - $ts = \MyTextSanitizer::getInstance(); |
|
1092 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1093 | - |
|
1094 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
1095 | - || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
1096 | - |
|
1097 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1098 | - || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
1099 | - $image = (!isset($this->vars['doimage']['value']) |
|
1100 | - || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
1101 | - $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * Hack by marcan <INBOX> for SCSPRO |
|
1105 | - * Setting mastop as the main editor |
|
1106 | - */ |
|
1107 | - if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1108 | - $br = false; |
|
1109 | - } |
|
1110 | - |
|
1111 | - /** |
|
1112 | - * Hack by marcan <INBOX> for SCSPRO |
|
1113 | - * Setting mastop as the main editor |
|
1114 | - */ |
|
1115 | - |
|
1116 | - return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1117 | - break 1; |
|
1118 | - case 'e': |
|
1119 | - case 'edit': |
|
1120 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1121 | - break 1; |
|
1122 | - case 'p': |
|
1123 | - case 'preview': |
|
1124 | - $ts = \MyTextSanitizer::getInstance(); |
|
1125 | - $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1126 | - $xcode = (!isset($this->vars['doxcode']['value']) |
|
1127 | - || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
1128 | - $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1129 | - || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
1130 | - $image = (!isset($this->vars['doimage']['value']) |
|
1131 | - || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
1132 | - $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
1133 | - |
|
1134 | - return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1135 | - break 1; |
|
1136 | - case 'f': |
|
1137 | - case 'formpreview': |
|
1138 | - $ts = \MyTextSanitizer::getInstance(); |
|
1139 | - |
|
1140 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1141 | - break 1; |
|
1142 | - case 'n': |
|
1143 | - case 'none': |
|
1144 | - default: |
|
1145 | - break 1; |
|
1146 | - } |
|
1147 | - break; |
|
1148 | - case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1149 | - $ret =& explode('|', $ret); |
|
1150 | - break; |
|
1151 | - case XOBJ_DTYPE_ARRAY: |
|
1152 | - $ret =& unserialize($ret); |
|
1153 | - break; |
|
1154 | - case XOBJ_DTYPE_SOURCE: |
|
1155 | - switch (strtolower($format)) { |
|
1156 | - case 's': |
|
1157 | - case 'show': |
|
1158 | - break 1; |
|
1159 | - case 'e': |
|
1160 | - case 'edit': |
|
1161 | - return htmlspecialchars($ret, ENT_QUOTES); |
|
1162 | - break 1; |
|
1163 | - case 'p': |
|
1164 | - case 'preview': |
|
1165 | - $ts = \MyTextSanitizer::getInstance(); |
|
1166 | - |
|
1167 | - return $ts->stripSlashesGPC($ret); |
|
1168 | - break 1; |
|
1169 | - case 'f': |
|
1170 | - case 'formpreview': |
|
1171 | - $ts = \MyTextSanitizer::getInstance(); |
|
1172 | - |
|
1173 | - return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1174 | - break 1; |
|
1175 | - case 'n': |
|
1176 | - case 'none': |
|
1177 | - default: |
|
1178 | - break 1; |
|
1179 | - } |
|
1180 | - break; |
|
1181 | - default: |
|
1182 | - if ('' !== $this->vars[$key]['options'] && '' != $ret) { |
|
1183 | - switch (strtolower($format)) { |
|
1184 | - case 's': |
|
1185 | - case 'show': |
|
1186 | - $selected = explode('|', $ret); |
|
1187 | - $options = explode('|', $this->vars[$key]['options']); |
|
1188 | - $i = 1; |
|
1189 | - $ret = []; |
|
1190 | - foreach ($options as $op) { |
|
1191 | - if (in_array($i, $selected)) { |
|
1192 | - $ret[] = $op; |
|
1193 | - } |
|
1194 | - ++$i; |
|
1195 | - } |
|
1196 | - |
|
1197 | - return implode(', ', $ret); |
|
1198 | - case 'e': |
|
1199 | - case 'edit': |
|
1200 | - $ret = explode('|', $ret); |
|
1201 | - break 1; |
|
1202 | - default: |
|
1203 | - break 1; |
|
1204 | - } |
|
1205 | - } |
|
1206 | - break; |
|
1207 | - } |
|
1208 | - |
|
1209 | - return $ret; |
|
1210 | - } |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * @param $key |
|
1214 | - */ |
|
1215 | - public function doMakeFieldreadOnly($key) |
|
1216 | - { |
|
1217 | - if (isset($this->vars[$key])) { |
|
1218 | - $this->vars[$key]['readonly'] = true; |
|
1219 | - $this->vars[$key]['displayOnForm'] = true; |
|
1220 | - } |
|
1221 | - } |
|
1222 | - |
|
1223 | - /** |
|
1224 | - * @param $key |
|
1225 | - */ |
|
1226 | - public function makeFieldReadOnly($key) |
|
1227 | - { |
|
1228 | - if (is_array($key)) { |
|
1229 | - foreach ($key as $v) { |
|
1230 | - $this->doMakeFieldreadOnly($v); |
|
1231 | - } |
|
1232 | - } else { |
|
1233 | - $this->doMakeFieldreadOnly($key); |
|
1234 | - } |
|
1235 | - } |
|
1236 | - |
|
1237 | - /** |
|
1238 | - * @param $key |
|
1239 | - */ |
|
1240 | - public function doHideFieldFromForm($key) |
|
1241 | - { |
|
1242 | - if (isset($this->vars[$key])) { |
|
1243 | - $this->vars[$key]['displayOnForm'] = false; |
|
1244 | - } |
|
1245 | - } |
|
1246 | - |
|
1247 | - /** |
|
1248 | - * @param $key |
|
1249 | - */ |
|
1250 | - public function doHideFieldFromSingleView($key) |
|
1251 | - { |
|
1252 | - if (isset($this->vars[$key])) { |
|
1253 | - $this->vars[$key]['displayOnSingleView'] = false; |
|
1254 | - } |
|
1255 | - } |
|
1256 | - |
|
1257 | - /** |
|
1258 | - * @param $key |
|
1259 | - */ |
|
1260 | - public function hideFieldFromForm($key) |
|
1261 | - { |
|
1262 | - if (is_array($key)) { |
|
1263 | - foreach ($key as $v) { |
|
1264 | - $this->doHideFieldFromForm($v); |
|
1265 | - } |
|
1266 | - } else { |
|
1267 | - $this->doHideFieldFromForm($key); |
|
1268 | - } |
|
1269 | - } |
|
1270 | - |
|
1271 | - /** |
|
1272 | - * @param $key |
|
1273 | - */ |
|
1274 | - public function hideFieldFromSingleView($key) |
|
1275 | - { |
|
1276 | - if (is_array($key)) { |
|
1277 | - foreach ($key as $v) { |
|
1278 | - $this->doHideFieldFromSingleView($v); |
|
1279 | - } |
|
1280 | - } else { |
|
1281 | - $this->doHideFieldFromSingleView($key); |
|
1282 | - } |
|
1283 | - } |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * @param $key |
|
1287 | - */ |
|
1288 | - public function doShowFieldOnForm($key) |
|
1289 | - { |
|
1290 | - if (isset($this->vars[$key])) { |
|
1291 | - $this->vars[$key]['displayOnForm'] = true; |
|
1292 | - } |
|
1293 | - } |
|
1294 | - |
|
1295 | - /** |
|
1296 | - * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1297 | - * |
|
1298 | - * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1299 | - * @param bool $userSide for futur use, to do something different on the user side |
|
1300 | - * @param array $actions |
|
1301 | - * @param bool $headerAsRow |
|
1302 | - * @return string content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1303 | - */ |
|
1304 | - public function displaySingleObject( |
|
1305 | - $fetchOnly = false, |
|
1306 | - $userSide = false, |
|
1307 | - $actions = [], |
|
1308 | - $headerAsRow = true |
|
1309 | - ) { |
|
478 | + $highlight = Smartobject\Utility::getConfig('module_search_highlighter', false, true); |
|
479 | + |
|
480 | + if ($highlight && isset($_GET['keywords'])) { |
|
481 | + $myts = \MyTextSanitizer::getInstance(); |
|
482 | + $keywords = $myts->htmlSpecialChars(trim(urldecode($_GET['keywords']))); |
|
483 | + $h = new Highlighter($keywords, true, 'smart_highlighter'); |
|
484 | + foreach ($this->handler->highlightFields as $field) { |
|
485 | + $ret[$field] = $h->highlight($ret[$field]); |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + return $ret; |
|
490 | + } |
|
491 | + |
|
492 | + /** |
|
493 | + * add an error |
|
494 | + * |
|
495 | + * @param $err_str |
|
496 | + * @param bool $prefix |
|
497 | + * @internal param string $value error to add |
|
498 | + * @access public |
|
499 | + */ |
|
500 | + public function setErrors($err_str, $prefix = false) |
|
501 | + { |
|
502 | + if (is_array($err_str)) { |
|
503 | + foreach ($err_str as $str) { |
|
504 | + $this->setErrors($str, $prefix); |
|
505 | + } |
|
506 | + } else { |
|
507 | + if ($prefix) { |
|
508 | + $err_str = '[' . $prefix . '] ' . $err_str; |
|
509 | + } |
|
510 | + parent::setErrors($err_str); |
|
511 | + } |
|
512 | + } |
|
513 | + |
|
514 | + /** |
|
515 | + * @param $field |
|
516 | + * @param bool $required |
|
517 | + */ |
|
518 | + public function setFieldAsRequired($field, $required = true) |
|
519 | + { |
|
520 | + if (is_array($field)) { |
|
521 | + foreach ($field as $v) { |
|
522 | + $this->doSetFieldAsRequired($v, $required); |
|
523 | + } |
|
524 | + } else { |
|
525 | + $this->doSetFieldAsRequired($field, $required); |
|
526 | + } |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * @param $field |
|
531 | + */ |
|
532 | + public function setFieldForSorting($field) |
|
533 | + { |
|
534 | + if (is_array($field)) { |
|
535 | + foreach ($field as $v) { |
|
536 | + $this->doSetFieldForSorting($v); |
|
537 | + } |
|
538 | + } else { |
|
539 | + $this->doSetFieldForSorting($field); |
|
540 | + } |
|
541 | + } |
|
542 | + |
|
543 | + /** |
|
544 | + * @return bool |
|
545 | + */ |
|
546 | + public function hasError() |
|
547 | + { |
|
548 | + return count($this->_errors) > 0; |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * @param $url |
|
553 | + * @param $path |
|
554 | + */ |
|
555 | + public function setImageDir($url, $path) |
|
556 | + { |
|
557 | + $this->_image_url = $url; |
|
558 | + $this->_image_path = $path; |
|
559 | + } |
|
560 | + |
|
561 | + /** |
|
562 | + * Retreive the group that have been granted access to a specific permission for this object |
|
563 | + * |
|
564 | + * @param $group_perm |
|
565 | + * @return string $group_perm name of the permission |
|
566 | + */ |
|
567 | + public function getGroupPerm($group_perm) |
|
568 | + { |
|
569 | + if (!$this->handler->getPermissions()) { |
|
570 | + $this->setError("Trying to access a permission that does not exists for thisobject's handler"); |
|
571 | + |
|
572 | + return false; |
|
573 | + } |
|
574 | + |
|
575 | + $smartPermissionsHandler = new PermissionHandler($this->handler); |
|
576 | + $ret = $smartPermissionsHandler->getGrantedGroups($group_perm, $this->id()); |
|
577 | + |
|
578 | + if (0 == count($ret)) { |
|
579 | + return false; |
|
580 | + } else { |
|
581 | + return $ret; |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + /** |
|
586 | + * @param bool $path |
|
587 | + * @return mixed |
|
588 | + */ |
|
589 | + public function getImageDir($path = false) |
|
590 | + { |
|
591 | + if ($path) { |
|
592 | + return $this->_image_path; |
|
593 | + } else { |
|
594 | + return $this->_image_url; |
|
595 | + } |
|
596 | + } |
|
597 | + |
|
598 | + /** |
|
599 | + * @param bool $path |
|
600 | + * @return mixed |
|
601 | + */ |
|
602 | + public function getUploadDir($path = false) |
|
603 | + { |
|
604 | + if ($path) { |
|
605 | + return $this->_image_path; |
|
606 | + } else { |
|
607 | + return $this->_image_url; |
|
608 | + } |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * @param string $key |
|
613 | + * @param string $info |
|
614 | + * @return array |
|
615 | + */ |
|
616 | + public function getVarInfo($key = '', $info = '') |
|
617 | + { |
|
618 | + if (isset($this->vars[$key][$info])) { |
|
619 | + return $this->vars[$key][$info]; |
|
620 | + } elseif ('' === $info && isset($this->vars[$key])) { |
|
621 | + return $this->vars[$key]; |
|
622 | + } else { |
|
623 | + return $this->vars; |
|
624 | + } |
|
625 | + } |
|
626 | + |
|
627 | + /** |
|
628 | + * Get the id of the object |
|
629 | + * |
|
630 | + * @return int id of this object |
|
631 | + */ |
|
632 | + public function id() |
|
633 | + { |
|
634 | + return $this->getVar($this->handler->keyName, 'e'); |
|
635 | + } |
|
636 | + |
|
637 | + /** |
|
638 | + * Return the value of the title field of this object |
|
639 | + * |
|
640 | + * @param string $format |
|
641 | + * @return string |
|
642 | + */ |
|
643 | + public function title($format = 's') |
|
644 | + { |
|
645 | + return $this->getVar($this->handler->identifierName, $format); |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * Return the value of the title field of this object |
|
650 | + * |
|
651 | + * @return string |
|
652 | + */ |
|
653 | + public function summary() |
|
654 | + { |
|
655 | + if ($this->handler->summaryName) { |
|
656 | + return $this->getVar($this->handler->summaryName); |
|
657 | + } else { |
|
658 | + return false; |
|
659 | + } |
|
660 | + } |
|
661 | + |
|
662 | + /** |
|
663 | + * Retreive the object admin side link, displayijng a SingleView page |
|
664 | + * |
|
665 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
666 | + * @return string user side link to the object |
|
667 | + */ |
|
668 | + public function getAdminViewItemLink($onlyUrl = false) |
|
669 | + { |
|
670 | + $controller = new ObjectController($this->handler); |
|
671 | + |
|
672 | + return $controller->getAdminViewItemLink($this, $onlyUrl); |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Retreive the object user side link |
|
677 | + * |
|
678 | + * @param bool $onlyUrl wether or not to return a simple URL or a full <a> link |
|
679 | + * @return string user side link to the object |
|
680 | + */ |
|
681 | + public function getItemLink($onlyUrl = false) |
|
682 | + { |
|
683 | + $controller = new ObjectController($this->handler); |
|
684 | + |
|
685 | + return $controller->getItemLink($this, $onlyUrl); |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * @param bool $onlyUrl |
|
690 | + * @param bool $withimage |
|
691 | + * @param bool $userSide |
|
692 | + * @return string |
|
693 | + */ |
|
694 | + public function getEditItemLink($onlyUrl = false, $withimage = true, $userSide = false) |
|
695 | + { |
|
696 | + $controller = new ObjectController($this->handler); |
|
697 | + |
|
698 | + return $controller->getEditItemLink($this, $onlyUrl, $withimage, $userSide); |
|
699 | + } |
|
700 | + |
|
701 | + /** |
|
702 | + * @param bool $onlyUrl |
|
703 | + * @param bool $withimage |
|
704 | + * @param bool $userSide |
|
705 | + * @return string |
|
706 | + */ |
|
707 | + public function getDeleteItemLink($onlyUrl = false, $withimage = false, $userSide = false) |
|
708 | + { |
|
709 | + $controller = new ObjectController($this->handler); |
|
710 | + |
|
711 | + return $controller->getDeleteItemLink($this, $onlyUrl, $withimage, $userSide); |
|
712 | + } |
|
713 | + |
|
714 | + /** |
|
715 | + * @return string |
|
716 | + */ |
|
717 | + public function getPrintAndMailLink() |
|
718 | + { |
|
719 | + $controller = new ObjectController($this->handler); |
|
720 | + |
|
721 | + return $controller->getPrintAndMailLink($this); |
|
722 | + } |
|
723 | + |
|
724 | + /** |
|
725 | + * @param $sortsel |
|
726 | + * @return array|bool |
|
727 | + */ |
|
728 | + public function getFieldsForSorting($sortsel) |
|
729 | + { |
|
730 | + $ret = []; |
|
731 | + |
|
732 | + foreach ($this->vars as $key => $field_info) { |
|
733 | + if ($field_info['sortby']) { |
|
734 | + $ret[$key]['caption'] = $field_info['form_caption']; |
|
735 | + $ret[$key]['selected'] = $key == $sortsel ? 'selected' : ''; |
|
736 | + } |
|
737 | + } |
|
738 | + |
|
739 | + if (count($ret) > 0) { |
|
740 | + return $ret; |
|
741 | + } else { |
|
742 | + return false; |
|
743 | + } |
|
744 | + } |
|
745 | + |
|
746 | + /** |
|
747 | + * @param $key |
|
748 | + * @param $newType |
|
749 | + */ |
|
750 | + public function setType($key, $newType) |
|
751 | + { |
|
752 | + $this->vars[$key]['data_type'] = $newType; |
|
753 | + } |
|
754 | + |
|
755 | + /** |
|
756 | + * @param $key |
|
757 | + * @param $info |
|
758 | + * @param $value |
|
759 | + */ |
|
760 | + public function setVarInfo($key, $info, $value) |
|
761 | + { |
|
762 | + $this->vars[$key][$info] = $value; |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * @param $key |
|
767 | + * @param bool $editor |
|
768 | + * @return string |
|
769 | + */ |
|
770 | + public function getValueFor($key, $editor = true) |
|
771 | + { |
|
772 | + /** @var Smartmedia\Helper $helper */ |
|
773 | + $helper = Smartmedia\Helper::getInstance(); |
|
774 | + |
|
775 | + $ret = $this->getVar($key, 'n'); |
|
776 | + $myts = \MyTextSanitizer::getInstance(); |
|
777 | + |
|
778 | + $control = isset($this->controls[$key]) ? $this->controls[$key] : false; |
|
779 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
780 | + |
|
781 | + $html = isset($this->vars['dohtml']) ? $this->getVar('dohtml') : true; |
|
782 | + $smiley = true; |
|
783 | + $xcode = true; |
|
784 | + $image = true; |
|
785 | + $br = isset($this->vars['dobr']) ? $this->getVar('dobr') : true; |
|
786 | + $formatML = true; |
|
787 | + |
|
788 | + if ('default' === $form_editor) { |
|
789 | + /** @var Smartmedia\Helper $helper */ |
|
790 | + $helper = Smartmedia\Helper::getInstance(); |
|
791 | + |
|
792 | + $form_editor = null !==($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea'; |
|
793 | + } |
|
794 | + |
|
795 | + if ($editor) { |
|
796 | + if (defined('XOOPS_EDITOR_IS_HTML') |
|
797 | + && !in_array($form_editor, ['formtextarea', 'textarea', 'dhtmltextarea'])) { |
|
798 | + $br = false; |
|
799 | + $formatML = !$editor; |
|
800 | + } else { |
|
801 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
802 | + } |
|
803 | + } |
|
804 | + |
|
805 | + if (method_exists($myts, 'formatForML')) { |
|
806 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br, $formatML); |
|
807 | + } else { |
|
808 | + return $myts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
809 | + } |
|
810 | + } |
|
811 | + |
|
812 | + /** |
|
813 | + * clean values of all variables of the object for storage. |
|
814 | + * also add slashes whereever needed |
|
815 | + * |
|
816 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
817 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
818 | + * as a string separated by | |
|
819 | + * |
|
820 | + * @return bool true if successful |
|
821 | + * @access public |
|
822 | + */ |
|
823 | + public function cleanVars() |
|
824 | + { |
|
825 | + $ts = \MyTextSanitizer::getInstance(); |
|
826 | + $existing_errors = $this->getErrors(); |
|
827 | + $this->_errors = []; |
|
828 | + foreach ($this->vars as $k => $v) { |
|
829 | + $cleanv = $v['value']; |
|
830 | + if (!$v['changed']) { |
|
831 | + } else { |
|
832 | + $cleanv = is_string($cleanv) ? trim($cleanv) : $cleanv; |
|
833 | + switch ($v['data_type']) { |
|
834 | + case XOBJ_DTYPE_TXTBOX: |
|
835 | + if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
836 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
837 | + continue 2; |
|
838 | + } |
|
839 | + if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
840 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
841 | + continue 2; |
|
842 | + } |
|
843 | + if (!$v['not_gpc']) { |
|
844 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
845 | + } else { |
|
846 | + $cleanv = $ts->censorString($cleanv); |
|
847 | + } |
|
848 | + break; |
|
849 | + case XOBJ_DTYPE_TXTAREA: |
|
850 | + if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
851 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
852 | + continue 2; |
|
853 | + } |
|
854 | + if (!$v['not_gpc']) { |
|
855 | + $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
|
856 | + } else { |
|
857 | + $cleanv = $ts->censorString($cleanv); |
|
858 | + } |
|
859 | + break; |
|
860 | + case XOBJ_DTYPE_SOURCE: |
|
861 | + if (!$v['not_gpc']) { |
|
862 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
863 | + } else { |
|
864 | + $cleanv = $cleanv; |
|
865 | + } |
|
866 | + break; |
|
867 | + case XOBJ_DTYPE_INT: |
|
868 | + case XOBJ_DTYPE_TIME_ONLY: |
|
869 | + $cleanv = (int)$cleanv; |
|
870 | + break; |
|
871 | + |
|
872 | + case XOBJ_DTYPE_CURRENCY: |
|
873 | + $cleanv = Smartobject\Utility::getCurrency($cleanv); |
|
874 | + break; |
|
875 | + |
|
876 | + case XOBJ_DTYPE_FLOAT: |
|
877 | + $cleanv = Smartobject\Utility::float($cleanv); |
|
878 | + break; |
|
879 | + |
|
880 | + case XOBJ_DTYPE_EMAIL: |
|
881 | + if ($v['required'] && '' === $cleanv) { |
|
882 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
883 | + continue 2; |
|
884 | + } |
|
885 | + if ('' !== $cleanv |
|
886 | + && !preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$/i", $cleanv)) { |
|
887 | + $this->setErrors('Invalid Email'); |
|
888 | + continue 2; |
|
889 | + } |
|
890 | + if (!$v['not_gpc']) { |
|
891 | + $cleanv = $ts->stripSlashesGPC($cleanv); |
|
892 | + } |
|
893 | + break; |
|
894 | + case XOBJ_DTYPE_URL: |
|
895 | + if ($v['required'] && '' === $cleanv) { |
|
896 | + $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
|
897 | + continue 2; |
|
898 | + } |
|
899 | + if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
|
900 | + $cleanv = 'http://' . $cleanv; |
|
901 | + } |
|
902 | + if (!$v['not_gpc']) { |
|
903 | + $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
904 | + } |
|
905 | + break; |
|
906 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
907 | + $cleanv = implode('|', $cleanv); |
|
908 | + break; |
|
909 | + case XOBJ_DTYPE_ARRAY: |
|
910 | + $cleanv = serialize($cleanv); |
|
911 | + break; |
|
912 | + case XOBJ_DTYPE_STIME: |
|
913 | + case XOBJ_DTYPE_MTIME: |
|
914 | + case XOBJ_DTYPE_LTIME: |
|
915 | + $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
916 | + if (!($cleanv > 0)) { |
|
917 | + $cleanv = strtotime($cleanv); |
|
918 | + } |
|
919 | + break; |
|
920 | + default: |
|
921 | + break; |
|
922 | + } |
|
923 | + } |
|
924 | + $this->cleanVars[$k] =& $cleanv; |
|
925 | + unset($cleanv); |
|
926 | + } |
|
927 | + if (count($this->_errors) > 0) { |
|
928 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
929 | + |
|
930 | + return false; |
|
931 | + } |
|
932 | + $this->_errors = array_merge($existing_errors, $this->_errors); |
|
933 | + $this->unsetDirty(); |
|
934 | + |
|
935 | + return true; |
|
936 | + } |
|
937 | + |
|
938 | + /** |
|
939 | + * returns a specific variable for the object in a proper format |
|
940 | + * |
|
941 | + * We had to put this method in the SmartObject because the XOBJ_DTYPE_ARRAY does not work properly |
|
942 | + * at least on PHP 5.1. So we have created a new type XOBJ_DTYPE_SIMPLE_ARRAY to handle 1 level array |
|
943 | + * as a string separated by | |
|
944 | + * |
|
945 | + * @access public |
|
946 | + * @param string $key key of the object's variable to be returned |
|
947 | + * @param string $format format to use for the output |
|
948 | + * @return mixed formatted value of the variable |
|
949 | + */ |
|
950 | + public function getVar($key, $format = 's') |
|
951 | + { |
|
952 | + global $myts; |
|
953 | + |
|
954 | + $ret = $this->vars[$key]['value']; |
|
955 | + |
|
956 | + switch ($this->vars[$key]['data_type']) { |
|
957 | + |
|
958 | + case XOBJ_DTYPE_TXTBOX: |
|
959 | + switch (strtolower($format)) { |
|
960 | + case 's': |
|
961 | + case 'show': |
|
962 | + // ML Hack by marcan |
|
963 | + $ts = \MyTextSanitizer::getInstance(); |
|
964 | + $ret = $ts->htmlSpecialChars($ret); |
|
965 | + |
|
966 | + if (method_exists($myts, 'formatForML')) { |
|
967 | + return $ts->formatForML($ret); |
|
968 | + } else { |
|
969 | + return $ret; |
|
970 | + } |
|
971 | + break 1; |
|
972 | + // End of ML Hack by marcan |
|
973 | + |
|
974 | + case 'clean': |
|
975 | + $ts = \MyTextSanitizer::getInstance(); |
|
976 | + |
|
977 | + $ret = Smartobject\Utility::getHtml2text($ret); |
|
978 | + $ret = Smartobject\Utility::purifyText($ret); |
|
979 | + |
|
980 | + if (method_exists($myts, 'formatForML')) { |
|
981 | + return $ts->formatForML($ret); |
|
982 | + } else { |
|
983 | + return $ret; |
|
984 | + } |
|
985 | + break 1; |
|
986 | + // End of ML Hack by marcan |
|
987 | + |
|
988 | + case 'e': |
|
989 | + case 'edit': |
|
990 | + $ts = \MyTextSanitizer::getInstance(); |
|
991 | + |
|
992 | + return $ts->htmlSpecialChars($ret); |
|
993 | + break 1; |
|
994 | + case 'p': |
|
995 | + case 'preview': |
|
996 | + case 'f': |
|
997 | + case 'formpreview': |
|
998 | + $ts = \MyTextSanitizer::getInstance(); |
|
999 | + |
|
1000 | + return $ts->htmlSpecialChars($ts->stripSlashesGPC($ret)); |
|
1001 | + break 1; |
|
1002 | + case 'n': |
|
1003 | + case 'none': |
|
1004 | + default: |
|
1005 | + break 1; |
|
1006 | + } |
|
1007 | + break; |
|
1008 | + case XOBJ_DTYPE_LTIME: |
|
1009 | + switch (strtolower($format)) { |
|
1010 | + case 's': |
|
1011 | + case 'show': |
|
1012 | + case 'p': |
|
1013 | + case 'preview': |
|
1014 | + case 'f': |
|
1015 | + case 'formpreview': |
|
1016 | + $ret = formatTimestamp($ret, _DATESTRING); |
|
1017 | + |
|
1018 | + return $ret; |
|
1019 | + break 1; |
|
1020 | + case 'n': |
|
1021 | + case 'none': |
|
1022 | + case 'e': |
|
1023 | + case 'edit': |
|
1024 | + break 1; |
|
1025 | + default: |
|
1026 | + break 1; |
|
1027 | + } |
|
1028 | + break; |
|
1029 | + case XOBJ_DTYPE_STIME: |
|
1030 | + switch (strtolower($format)) { |
|
1031 | + case 's': |
|
1032 | + case 'show': |
|
1033 | + case 'p': |
|
1034 | + case 'preview': |
|
1035 | + case 'f': |
|
1036 | + case 'formpreview': |
|
1037 | + $ret = formatTimestamp($ret, _SHORTDATESTRING); |
|
1038 | + |
|
1039 | + return $ret; |
|
1040 | + break 1; |
|
1041 | + case 'n': |
|
1042 | + case 'none': |
|
1043 | + case 'e': |
|
1044 | + case 'edit': |
|
1045 | + break 1; |
|
1046 | + default: |
|
1047 | + break 1; |
|
1048 | + } |
|
1049 | + break; |
|
1050 | + case XOBJ_DTYPE_TIME_ONLY: |
|
1051 | + switch (strtolower($format)) { |
|
1052 | + case 's': |
|
1053 | + case 'show': |
|
1054 | + case 'p': |
|
1055 | + case 'preview': |
|
1056 | + case 'f': |
|
1057 | + case 'formpreview': |
|
1058 | + $ret = formatTimestamp($ret, 'G:i'); |
|
1059 | + |
|
1060 | + return $ret; |
|
1061 | + break 1; |
|
1062 | + case 'n': |
|
1063 | + case 'none': |
|
1064 | + case 'e': |
|
1065 | + case 'edit': |
|
1066 | + break 1; |
|
1067 | + default: |
|
1068 | + break 1; |
|
1069 | + } |
|
1070 | + break; |
|
1071 | + |
|
1072 | + case XOBJ_DTYPE_CURRENCY: |
|
1073 | + $decimal_section_original = strstr($ret, '.'); |
|
1074 | + $decimal_section = $decimal_section_original; |
|
1075 | + if ($decimal_section) { |
|
1076 | + if (1 == strlen($decimal_section)) { |
|
1077 | + $decimal_section = '.00'; |
|
1078 | + } elseif (2 == strlen($decimal_section)) { |
|
1079 | + $decimal_section .= '0'; |
|
1080 | + } |
|
1081 | + $ret = str_replace($decimal_section_original, $decimal_section, $ret); |
|
1082 | + } else { |
|
1083 | + $ret .= '.00'; |
|
1084 | + } |
|
1085 | + break; |
|
1086 | + |
|
1087 | + case XOBJ_DTYPE_TXTAREA: |
|
1088 | + switch (strtolower($format)) { |
|
1089 | + case 's': |
|
1090 | + case 'show': |
|
1091 | + $ts = \MyTextSanitizer::getInstance(); |
|
1092 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1093 | + |
|
1094 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
1095 | + || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
1096 | + |
|
1097 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1098 | + || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
1099 | + $image = (!isset($this->vars['doimage']['value']) |
|
1100 | + || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
1101 | + $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * Hack by marcan <INBOX> for SCSPRO |
|
1105 | + * Setting mastop as the main editor |
|
1106 | + */ |
|
1107 | + if (defined('XOOPS_EDITOR_IS_HTML')) { |
|
1108 | + $br = false; |
|
1109 | + } |
|
1110 | + |
|
1111 | + /** |
|
1112 | + * Hack by marcan <INBOX> for SCSPRO |
|
1113 | + * Setting mastop as the main editor |
|
1114 | + */ |
|
1115 | + |
|
1116 | + return $ts->displayTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1117 | + break 1; |
|
1118 | + case 'e': |
|
1119 | + case 'edit': |
|
1120 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1121 | + break 1; |
|
1122 | + case 'p': |
|
1123 | + case 'preview': |
|
1124 | + $ts = \MyTextSanitizer::getInstance(); |
|
1125 | + $html = !empty($this->vars['dohtml']['value']) ? 1 : 0; |
|
1126 | + $xcode = (!isset($this->vars['doxcode']['value']) |
|
1127 | + || 1 == $this->vars['doxcode']['value']) ? 1 : 0; |
|
1128 | + $smiley = (!isset($this->vars['dosmiley']['value']) |
|
1129 | + || 1 == $this->vars['dosmiley']['value']) ? 1 : 0; |
|
1130 | + $image = (!isset($this->vars['doimage']['value']) |
|
1131 | + || 1 == $this->vars['doimage']['value']) ? 1 : 0; |
|
1132 | + $br = (!isset($this->vars['dobr']['value']) || 1 == $this->vars['dobr']['value']) ? 1 : 0; |
|
1133 | + |
|
1134 | + return $ts->previewTarea($ret, $html, $smiley, $xcode, $image, $br); |
|
1135 | + break 1; |
|
1136 | + case 'f': |
|
1137 | + case 'formpreview': |
|
1138 | + $ts = \MyTextSanitizer::getInstance(); |
|
1139 | + |
|
1140 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1141 | + break 1; |
|
1142 | + case 'n': |
|
1143 | + case 'none': |
|
1144 | + default: |
|
1145 | + break 1; |
|
1146 | + } |
|
1147 | + break; |
|
1148 | + case XOBJ_DTYPE_SIMPLE_ARRAY: |
|
1149 | + $ret =& explode('|', $ret); |
|
1150 | + break; |
|
1151 | + case XOBJ_DTYPE_ARRAY: |
|
1152 | + $ret =& unserialize($ret); |
|
1153 | + break; |
|
1154 | + case XOBJ_DTYPE_SOURCE: |
|
1155 | + switch (strtolower($format)) { |
|
1156 | + case 's': |
|
1157 | + case 'show': |
|
1158 | + break 1; |
|
1159 | + case 'e': |
|
1160 | + case 'edit': |
|
1161 | + return htmlspecialchars($ret, ENT_QUOTES); |
|
1162 | + break 1; |
|
1163 | + case 'p': |
|
1164 | + case 'preview': |
|
1165 | + $ts = \MyTextSanitizer::getInstance(); |
|
1166 | + |
|
1167 | + return $ts->stripSlashesGPC($ret); |
|
1168 | + break 1; |
|
1169 | + case 'f': |
|
1170 | + case 'formpreview': |
|
1171 | + $ts = \MyTextSanitizer::getInstance(); |
|
1172 | + |
|
1173 | + return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
|
1174 | + break 1; |
|
1175 | + case 'n': |
|
1176 | + case 'none': |
|
1177 | + default: |
|
1178 | + break 1; |
|
1179 | + } |
|
1180 | + break; |
|
1181 | + default: |
|
1182 | + if ('' !== $this->vars[$key]['options'] && '' != $ret) { |
|
1183 | + switch (strtolower($format)) { |
|
1184 | + case 's': |
|
1185 | + case 'show': |
|
1186 | + $selected = explode('|', $ret); |
|
1187 | + $options = explode('|', $this->vars[$key]['options']); |
|
1188 | + $i = 1; |
|
1189 | + $ret = []; |
|
1190 | + foreach ($options as $op) { |
|
1191 | + if (in_array($i, $selected)) { |
|
1192 | + $ret[] = $op; |
|
1193 | + } |
|
1194 | + ++$i; |
|
1195 | + } |
|
1196 | + |
|
1197 | + return implode(', ', $ret); |
|
1198 | + case 'e': |
|
1199 | + case 'edit': |
|
1200 | + $ret = explode('|', $ret); |
|
1201 | + break 1; |
|
1202 | + default: |
|
1203 | + break 1; |
|
1204 | + } |
|
1205 | + } |
|
1206 | + break; |
|
1207 | + } |
|
1208 | + |
|
1209 | + return $ret; |
|
1210 | + } |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * @param $key |
|
1214 | + */ |
|
1215 | + public function doMakeFieldreadOnly($key) |
|
1216 | + { |
|
1217 | + if (isset($this->vars[$key])) { |
|
1218 | + $this->vars[$key]['readonly'] = true; |
|
1219 | + $this->vars[$key]['displayOnForm'] = true; |
|
1220 | + } |
|
1221 | + } |
|
1222 | + |
|
1223 | + /** |
|
1224 | + * @param $key |
|
1225 | + */ |
|
1226 | + public function makeFieldReadOnly($key) |
|
1227 | + { |
|
1228 | + if (is_array($key)) { |
|
1229 | + foreach ($key as $v) { |
|
1230 | + $this->doMakeFieldreadOnly($v); |
|
1231 | + } |
|
1232 | + } else { |
|
1233 | + $this->doMakeFieldreadOnly($key); |
|
1234 | + } |
|
1235 | + } |
|
1236 | + |
|
1237 | + /** |
|
1238 | + * @param $key |
|
1239 | + */ |
|
1240 | + public function doHideFieldFromForm($key) |
|
1241 | + { |
|
1242 | + if (isset($this->vars[$key])) { |
|
1243 | + $this->vars[$key]['displayOnForm'] = false; |
|
1244 | + } |
|
1245 | + } |
|
1246 | + |
|
1247 | + /** |
|
1248 | + * @param $key |
|
1249 | + */ |
|
1250 | + public function doHideFieldFromSingleView($key) |
|
1251 | + { |
|
1252 | + if (isset($this->vars[$key])) { |
|
1253 | + $this->vars[$key]['displayOnSingleView'] = false; |
|
1254 | + } |
|
1255 | + } |
|
1256 | + |
|
1257 | + /** |
|
1258 | + * @param $key |
|
1259 | + */ |
|
1260 | + public function hideFieldFromForm($key) |
|
1261 | + { |
|
1262 | + if (is_array($key)) { |
|
1263 | + foreach ($key as $v) { |
|
1264 | + $this->doHideFieldFromForm($v); |
|
1265 | + } |
|
1266 | + } else { |
|
1267 | + $this->doHideFieldFromForm($key); |
|
1268 | + } |
|
1269 | + } |
|
1270 | + |
|
1271 | + /** |
|
1272 | + * @param $key |
|
1273 | + */ |
|
1274 | + public function hideFieldFromSingleView($key) |
|
1275 | + { |
|
1276 | + if (is_array($key)) { |
|
1277 | + foreach ($key as $v) { |
|
1278 | + $this->doHideFieldFromSingleView($v); |
|
1279 | + } |
|
1280 | + } else { |
|
1281 | + $this->doHideFieldFromSingleView($key); |
|
1282 | + } |
|
1283 | + } |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * @param $key |
|
1287 | + */ |
|
1288 | + public function doShowFieldOnForm($key) |
|
1289 | + { |
|
1290 | + if (isset($this->vars[$key])) { |
|
1291 | + $this->vars[$key]['displayOnForm'] = true; |
|
1292 | + } |
|
1293 | + } |
|
1294 | + |
|
1295 | + /** |
|
1296 | + * Display an automatic SingleView of the object, based on the displayOnSingleView param of each vars |
|
1297 | + * |
|
1298 | + * @param bool $fetchOnly if set to TRUE, then the content will be return, if set to FALSE, the content will be outputed |
|
1299 | + * @param bool $userSide for futur use, to do something different on the user side |
|
1300 | + * @param array $actions |
|
1301 | + * @param bool $headerAsRow |
|
1302 | + * @return string content of the template if $fetchOnly or nothing if !$fetchOnly |
|
1303 | + */ |
|
1304 | + public function displaySingleObject( |
|
1305 | + $fetchOnly = false, |
|
1306 | + $userSide = false, |
|
1307 | + $actions = [], |
|
1308 | + $headerAsRow = true |
|
1309 | + ) { |
|
1310 | 1310 | // require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectsingleview.php'; |
1311 | - $singleview = new SingleView($this, $userSide, $actions, $headerAsRow); |
|
1312 | - // add all fields mark as displayOnSingleView except the keyid |
|
1313 | - foreach ($this->vars as $key => $var) { |
|
1314 | - if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1315 | - $is_header = ($key == $this->handler->identifierName); |
|
1316 | - $singleview->addRow(new ObjectRow($key, false, $is_header)); |
|
1317 | - } |
|
1318 | - } |
|
1319 | - |
|
1320 | - if ($fetchOnly) { |
|
1321 | - $ret = $singleview->render($fetchOnly); |
|
1322 | - |
|
1323 | - return $ret; |
|
1324 | - } else { |
|
1325 | - $singleview->render($fetchOnly); |
|
1326 | - } |
|
1327 | - } |
|
1328 | - |
|
1329 | - /** |
|
1330 | - * @param $key |
|
1331 | - */ |
|
1332 | - public function doDisplayFieldOnSingleView($key) |
|
1333 | - { |
|
1334 | - if (isset($this->vars[$key])) { |
|
1335 | - $this->vars[$key]['displayOnSingleView'] = true; |
|
1336 | - } |
|
1337 | - } |
|
1338 | - |
|
1339 | - /** |
|
1340 | - * @param $field |
|
1341 | - * @param bool $required |
|
1342 | - */ |
|
1343 | - public function doSetFieldAsRequired($field, $required = true) |
|
1344 | - { |
|
1345 | - $this->setVarInfo($field, 'required', $required); |
|
1346 | - } |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * @param $field |
|
1350 | - */ |
|
1351 | - public function doSetFieldForSorting($field) |
|
1352 | - { |
|
1353 | - $this->setVarInfo($field, 'sortby', true); |
|
1354 | - } |
|
1355 | - |
|
1356 | - /** |
|
1357 | - * @param $key |
|
1358 | - */ |
|
1359 | - public function showFieldOnForm($key) |
|
1360 | - { |
|
1361 | - if (is_array($key)) { |
|
1362 | - foreach ($key as $v) { |
|
1363 | - $this->doShowFieldOnForm($v); |
|
1364 | - } |
|
1365 | - } else { |
|
1366 | - $this->doShowFieldOnForm($key); |
|
1367 | - } |
|
1368 | - } |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * @param $key |
|
1372 | - */ |
|
1373 | - public function displayFieldOnSingleView($key) |
|
1374 | - { |
|
1375 | - if (is_array($key)) { |
|
1376 | - foreach ($key as $v) { |
|
1377 | - $this->doDisplayFieldOnSingleView($v); |
|
1378 | - } |
|
1379 | - } else { |
|
1380 | - $this->doDisplayFieldOnSingleView($key); |
|
1381 | - } |
|
1382 | - } |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * @param $key |
|
1386 | - */ |
|
1387 | - public function doSetAdvancedFormFields($key) |
|
1388 | - { |
|
1389 | - if (isset($this->vars[$key])) { |
|
1390 | - $this->vars[$key]['advancedform'] = true; |
|
1391 | - } |
|
1392 | - } |
|
1393 | - |
|
1394 | - /** |
|
1395 | - * @param $key |
|
1396 | - */ |
|
1397 | - public function setAdvancedFormFields($key) |
|
1398 | - { |
|
1399 | - if (is_array($key)) { |
|
1400 | - foreach ($key as $v) { |
|
1401 | - $this->doSetAdvancedFormFields($v); |
|
1402 | - } |
|
1403 | - } else { |
|
1404 | - $this->doSetAdvancedFormFields($key); |
|
1405 | - } |
|
1406 | - } |
|
1407 | - |
|
1408 | - /** |
|
1409 | - * @param $key |
|
1410 | - * @return mixed |
|
1411 | - */ |
|
1412 | - public function getUrlLinkObj($key) |
|
1413 | - { |
|
1414 | - $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink'); |
|
1415 | - $urllinkid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
1416 | - if (0 != $urllinkid) { |
|
1417 | - return $smartobjectLinkurlHandler->get($urllinkid); |
|
1418 | - } else { |
|
1419 | - return $smartobjectLinkurlHandler->create(); |
|
1420 | - } |
|
1421 | - } |
|
1422 | - |
|
1423 | - /** |
|
1424 | - * @param $urlLinkObj |
|
1425 | - * @return mixed |
|
1426 | - */ |
|
1427 | - public function &storeUrlLinkObj($urlLinkObj) |
|
1428 | - { |
|
1429 | - $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink'); |
|
1430 | - |
|
1431 | - return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1432 | - } |
|
1433 | - |
|
1434 | - /** |
|
1435 | - * @param $key |
|
1436 | - * @return mixed |
|
1437 | - */ |
|
1438 | - public function getFileObj($key) |
|
1439 | - { |
|
1440 | - $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File'); |
|
1441 | - $fileid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
1442 | - if (0 != $fileid) { |
|
1443 | - return $smartobjectFileHandler->get($fileid); |
|
1444 | - } else { |
|
1445 | - return $smartobjectFileHandler->create(); |
|
1446 | - } |
|
1447 | - } |
|
1448 | - |
|
1449 | - /** |
|
1450 | - * @param $fileObj |
|
1451 | - * @return mixed |
|
1452 | - */ |
|
1453 | - public function &storeFileObj($fileObj) |
|
1454 | - { |
|
1455 | - $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File'); |
|
1456 | - |
|
1457 | - return $smartobjectFileHandler->insert($fileObj); |
|
1458 | - } |
|
1311 | + $singleview = new SingleView($this, $userSide, $actions, $headerAsRow); |
|
1312 | + // add all fields mark as displayOnSingleView except the keyid |
|
1313 | + foreach ($this->vars as $key => $var) { |
|
1314 | + if ($key != $this->handler->keyName && $var['displayOnSingleView']) { |
|
1315 | + $is_header = ($key == $this->handler->identifierName); |
|
1316 | + $singleview->addRow(new ObjectRow($key, false, $is_header)); |
|
1317 | + } |
|
1318 | + } |
|
1319 | + |
|
1320 | + if ($fetchOnly) { |
|
1321 | + $ret = $singleview->render($fetchOnly); |
|
1322 | + |
|
1323 | + return $ret; |
|
1324 | + } else { |
|
1325 | + $singleview->render($fetchOnly); |
|
1326 | + } |
|
1327 | + } |
|
1328 | + |
|
1329 | + /** |
|
1330 | + * @param $key |
|
1331 | + */ |
|
1332 | + public function doDisplayFieldOnSingleView($key) |
|
1333 | + { |
|
1334 | + if (isset($this->vars[$key])) { |
|
1335 | + $this->vars[$key]['displayOnSingleView'] = true; |
|
1336 | + } |
|
1337 | + } |
|
1338 | + |
|
1339 | + /** |
|
1340 | + * @param $field |
|
1341 | + * @param bool $required |
|
1342 | + */ |
|
1343 | + public function doSetFieldAsRequired($field, $required = true) |
|
1344 | + { |
|
1345 | + $this->setVarInfo($field, 'required', $required); |
|
1346 | + } |
|
1347 | + |
|
1348 | + /** |
|
1349 | + * @param $field |
|
1350 | + */ |
|
1351 | + public function doSetFieldForSorting($field) |
|
1352 | + { |
|
1353 | + $this->setVarInfo($field, 'sortby', true); |
|
1354 | + } |
|
1355 | + |
|
1356 | + /** |
|
1357 | + * @param $key |
|
1358 | + */ |
|
1359 | + public function showFieldOnForm($key) |
|
1360 | + { |
|
1361 | + if (is_array($key)) { |
|
1362 | + foreach ($key as $v) { |
|
1363 | + $this->doShowFieldOnForm($v); |
|
1364 | + } |
|
1365 | + } else { |
|
1366 | + $this->doShowFieldOnForm($key); |
|
1367 | + } |
|
1368 | + } |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * @param $key |
|
1372 | + */ |
|
1373 | + public function displayFieldOnSingleView($key) |
|
1374 | + { |
|
1375 | + if (is_array($key)) { |
|
1376 | + foreach ($key as $v) { |
|
1377 | + $this->doDisplayFieldOnSingleView($v); |
|
1378 | + } |
|
1379 | + } else { |
|
1380 | + $this->doDisplayFieldOnSingleView($key); |
|
1381 | + } |
|
1382 | + } |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * @param $key |
|
1386 | + */ |
|
1387 | + public function doSetAdvancedFormFields($key) |
|
1388 | + { |
|
1389 | + if (isset($this->vars[$key])) { |
|
1390 | + $this->vars[$key]['advancedform'] = true; |
|
1391 | + } |
|
1392 | + } |
|
1393 | + |
|
1394 | + /** |
|
1395 | + * @param $key |
|
1396 | + */ |
|
1397 | + public function setAdvancedFormFields($key) |
|
1398 | + { |
|
1399 | + if (is_array($key)) { |
|
1400 | + foreach ($key as $v) { |
|
1401 | + $this->doSetAdvancedFormFields($v); |
|
1402 | + } |
|
1403 | + } else { |
|
1404 | + $this->doSetAdvancedFormFields($key); |
|
1405 | + } |
|
1406 | + } |
|
1407 | + |
|
1408 | + /** |
|
1409 | + * @param $key |
|
1410 | + * @return mixed |
|
1411 | + */ |
|
1412 | + public function getUrlLinkObj($key) |
|
1413 | + { |
|
1414 | + $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink'); |
|
1415 | + $urllinkid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
1416 | + if (0 != $urllinkid) { |
|
1417 | + return $smartobjectLinkurlHandler->get($urllinkid); |
|
1418 | + } else { |
|
1419 | + return $smartobjectLinkurlHandler->create(); |
|
1420 | + } |
|
1421 | + } |
|
1422 | + |
|
1423 | + /** |
|
1424 | + * @param $urlLinkObj |
|
1425 | + * @return mixed |
|
1426 | + */ |
|
1427 | + public function &storeUrlLinkObj($urlLinkObj) |
|
1428 | + { |
|
1429 | + $smartobjectLinkurlHandler = Smartobject\Helper::getInstance()->getHandler('Urllink'); |
|
1430 | + |
|
1431 | + return $smartobjectLinkurlHandler->insert($urlLinkObj); |
|
1432 | + } |
|
1433 | + |
|
1434 | + /** |
|
1435 | + * @param $key |
|
1436 | + * @return mixed |
|
1437 | + */ |
|
1438 | + public function getFileObj($key) |
|
1439 | + { |
|
1440 | + $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File'); |
|
1441 | + $fileid = null !== $this->getVar($key) ? $this->getVar($key) : 0; |
|
1442 | + if (0 != $fileid) { |
|
1443 | + return $smartobjectFileHandler->get($fileid); |
|
1444 | + } else { |
|
1445 | + return $smartobjectFileHandler->create(); |
|
1446 | + } |
|
1447 | + } |
|
1448 | + |
|
1449 | + /** |
|
1450 | + * @param $fileObj |
|
1451 | + * @return mixed |
|
1452 | + */ |
|
1453 | + public function &storeFileObj($fileObj) |
|
1454 | + { |
|
1455 | + $smartobjectFileHandler = Smartobject\Helper::getInstance()->getHandler('File'); |
|
1456 | + |
|
1457 | + return $smartobjectFileHandler->insert($fileObj); |
|
1458 | + } |
|
1459 | 1459 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | |
18 | 18 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
19 | 19 | |
20 | -require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
|
20 | +require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php'; |
|
21 | 21 | |
22 | 22 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
23 | 23 | define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | */ |
117 | 117 | public function closeSection($section_name) |
118 | 118 | { |
119 | - $this->initVar('close_section_' . $section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
119 | + $this->initVar('close_section_'.$section_name, XOBJ_DTYPE_FORM_SECTION_CLOSE, '', false, null, '', false, '', '', false, false, true); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -154,13 +154,13 @@ discard block |
||
154 | 154 | } |
155 | 155 | parent::initVar($key, $data_type, $value, $required, $maxlength, $options); |
156 | 156 | if ($this->handler && (!$form_caption || '' === $form_caption)) { |
157 | - $dyn_form_caption = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key); |
|
157 | + $dyn_form_caption = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key); |
|
158 | 158 | if (defined($dyn_form_caption)) { |
159 | 159 | $form_caption = constant($dyn_form_caption); |
160 | 160 | } |
161 | 161 | } |
162 | 162 | if ($this->handler && (!$form_dsc || '' === $form_dsc)) { |
163 | - $dyn_form_dsc = strtoupper('_CO_' . $this->handler->_moduleName . '_' . $this->handler->_itemname . '_' . $key . '_DSC'); |
|
163 | + $dyn_form_dsc = strtoupper('_CO_'.$this->handler->_moduleName.'_'.$this->handler->_itemname.'_'.$key.'_DSC'); |
|
164 | 164 | if (defined($dyn_form_dsc)) { |
165 | 165 | $form_dsc = constant($dyn_form_dsc); |
166 | 166 | } |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | public function toArray() |
457 | 457 | { |
458 | 458 | $ret = []; |
459 | - $vars =& $this->getVars(); |
|
459 | + $vars = & $this->getVars(); |
|
460 | 460 | foreach ($vars as $key => $var) { |
461 | 461 | $value = $this->getVar($key); |
462 | 462 | $ret[$key] = $value; |
@@ -505,7 +505,7 @@ discard block |
||
505 | 505 | } |
506 | 506 | } else { |
507 | 507 | if ($prefix) { |
508 | - $err_str = '[' . $prefix . '] ' . $err_str; |
|
508 | + $err_str = '['.$prefix.'] '.$err_str; |
|
509 | 509 | } |
510 | 510 | parent::setErrors($err_str); |
511 | 511 | } |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | /** @var Smartmedia\Helper $helper */ |
790 | 790 | $helper = Smartmedia\Helper::getInstance(); |
791 | 791 | |
792 | - $form_editor = null !==($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea'; |
|
792 | + $form_editor = null !== ($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea'; |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | if ($editor) { |
@@ -836,8 +836,8 @@ discard block |
||
836 | 836 | $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
837 | 837 | continue 2; |
838 | 838 | } |
839 | - if (isset($v['maxlength']) && strlen($cleanv) > (int)$v['maxlength']) { |
|
840 | - $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int)$v['maxlength'])); |
|
839 | + if (isset($v['maxlength']) && strlen($cleanv) > (int) $v['maxlength']) { |
|
840 | + $this->setErrors(sprintf(_XOBJ_ERR_SHORTERTHAN, $k, (int) $v['maxlength'])); |
|
841 | 841 | continue 2; |
842 | 842 | } |
843 | 843 | if (!$v['not_gpc']) { |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | break; |
867 | 867 | case XOBJ_DTYPE_INT: |
868 | 868 | case XOBJ_DTYPE_TIME_ONLY: |
869 | - $cleanv = (int)$cleanv; |
|
869 | + $cleanv = (int) $cleanv; |
|
870 | 870 | break; |
871 | 871 | |
872 | 872 | case XOBJ_DTYPE_CURRENCY: |
@@ -897,10 +897,10 @@ discard block |
||
897 | 897 | continue 2; |
898 | 898 | } |
899 | 899 | if ('' !== $cleanv && !preg_match("/^http[s]*:\/\//i", $cleanv)) { |
900 | - $cleanv = 'http://' . $cleanv; |
|
900 | + $cleanv = 'http://'.$cleanv; |
|
901 | 901 | } |
902 | 902 | if (!$v['not_gpc']) { |
903 | - $cleanv =& $ts->stripSlashesGPC($cleanv); |
|
903 | + $cleanv = & $ts->stripSlashesGPC($cleanv); |
|
904 | 904 | } |
905 | 905 | break; |
906 | 906 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | case XOBJ_DTYPE_STIME: |
913 | 913 | case XOBJ_DTYPE_MTIME: |
914 | 914 | case XOBJ_DTYPE_LTIME: |
915 | - $cleanv = !is_string($cleanv) ? (int)$cleanv : strtotime($cleanv); |
|
915 | + $cleanv = !is_string($cleanv) ? (int) $cleanv : strtotime($cleanv); |
|
916 | 916 | if (!($cleanv > 0)) { |
917 | 917 | $cleanv = strtotime($cleanv); |
918 | 918 | } |
@@ -921,7 +921,7 @@ discard block |
||
921 | 921 | break; |
922 | 922 | } |
923 | 923 | } |
924 | - $this->cleanVars[$k] =& $cleanv; |
|
924 | + $this->cleanVars[$k] = & $cleanv; |
|
925 | 925 | unset($cleanv); |
926 | 926 | } |
927 | 927 | if (count($this->_errors) > 0) { |
@@ -1146,10 +1146,10 @@ discard block |
||
1146 | 1146 | } |
1147 | 1147 | break; |
1148 | 1148 | case XOBJ_DTYPE_SIMPLE_ARRAY: |
1149 | - $ret =& explode('|', $ret); |
|
1149 | + $ret = & explode('|', $ret); |
|
1150 | 1150 | break; |
1151 | 1151 | case XOBJ_DTYPE_ARRAY: |
1152 | - $ret =& unserialize($ret); |
|
1152 | + $ret = & unserialize($ret); |
|
1153 | 1153 | break; |
1154 | 1154 | case XOBJ_DTYPE_SOURCE: |
1155 | 1155 | switch (strtolower($format)) { |
@@ -19,8 +19,8 @@ |
||
19 | 19 | class SmartFormUploadElement extends \XoopsFormFile |
20 | 20 | { |
21 | 21 | /** |
22 | - * @param $object |
|
23 | - * @param $key |
|
22 | + * @param string $object |
|
23 | + * @param string $key |
|
24 | 24 | */ |
25 | 25 | public function SmartFormFileElement($object, $key) |
26 | 26 | { |
@@ -18,25 +18,25 @@ |
||
18 | 18 | */ |
19 | 19 | class SmartFormUploadElement extends \XoopsFormFile |
20 | 20 | { |
21 | - /** |
|
22 | - * @param $object |
|
23 | - * @param $key |
|
24 | - */ |
|
25 | - public function SmartFormFileElement($object, $key) |
|
26 | - { |
|
27 | - parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
28 | - $this->setExtra(' size=50'); |
|
29 | - } |
|
21 | + /** |
|
22 | + * @param $object |
|
23 | + * @param $key |
|
24 | + */ |
|
25 | + public function SmartFormFileElement($object, $key) |
|
26 | + { |
|
27 | + parent::__construct(_CO_SOBJECT_UPLOAD, $key, isset($object->vars[$key]['form_maxfilesize']) ? $object->vars[$key]['form_maxfilesize'] : 0); |
|
28 | + $this->setExtra(' size=50'); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * prepare HTML for output |
|
33 | - * |
|
34 | - * @return string HTML |
|
35 | - */ |
|
36 | - public function render() |
|
37 | - { |
|
38 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
31 | + /** |
|
32 | + * prepare HTML for output |
|
33 | + * |
|
34 | + * @return string HTML |
|
35 | + */ |
|
36 | + public function render() |
|
37 | + { |
|
38 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
39 | 39 | <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
40 | 40 | <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
41 | - } |
|
41 | + } |
|
42 | 42 | } |
@@ -28,8 +28,8 @@ |
||
28 | 28 | */ |
29 | 29 | public function render() |
30 | 30 | { |
31 | - return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'> |
|
32 | - <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . "> |
|
33 | - <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>"; |
|
31 | + return "<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."'> |
|
32 | + <input type='file' name='" . $this->getName()."' id='".$this->getName()."'".$this->getExtra()."> |
|
33 | + <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName()."'>"; |
|
34 | 34 | } |
35 | 35 | } |
@@ -306,8 +306,8 @@ |
||
306 | 306 | } |
307 | 307 | |
308 | 308 | /** |
309 | - * @param $form_name |
|
310 | - * @param $form_caption |
|
309 | + * @param string $form_name |
|
310 | + * @param string $form_caption |
|
311 | 311 | * @param bool $submit_button_caption |
312 | 312 | */ |
313 | 313 | public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | use XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
26 | 26 | use XoopsModules\Smartobject\Form\Elements\SmartFormUrlLinkElement; |
27 | 27 | |
28 | -require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
|
28 | +require_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php'; |
|
29 | 29 | //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
30 | 30 | //require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsectionclose.php'; |
31 | 31 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $cancel_js_action = false, |
71 | 71 | $captcha = false |
72 | 72 | ) { |
73 | - $this->targetObject =& $target; |
|
73 | + $this->targetObject = & $target; |
|
74 | 74 | $this->form_fields = $form_fields; |
75 | 75 | $this->_cancel_js_action = $cancel_js_action; |
76 | 76 | $this->_captcha = $captcha; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | public function addCaptcha() |
100 | 100 | { |
101 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
101 | + require_once SMARTOBJECT_ROOT_PATH.'include/captcha/formcaptcha.php'; |
|
102 | 102 | $this->addElement(new \XoopsFormCaptcha(), true); |
103 | 103 | } |
104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function addCustomButton($name, $caption, $onclick = false) |
111 | 111 | { |
112 | - $custom_button_array = [ |
|
112 | + $custom_button_array = [ |
|
113 | 113 | 'name' => $name, |
114 | 114 | 'caption' => $caption, |
115 | 115 | 'onclick' => $onclick |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | if ($key) { |
131 | 131 | if ($this->targetObject->vars[$key]['readonly']) { |
132 | 132 | $formElement->setExtra('disabled="disabled"'); |
133 | - $formElement->setName($key . '-readonly'); |
|
133 | + $formElement->setName($key.'-readonly'); |
|
134 | 134 | // Since this element is disable, we still want to pass it's value in the form |
135 | 135 | $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
136 | 136 | $this->addElement($hidden); |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | $this->addElement($hidden); |
142 | 142 | $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
143 | 143 | $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
144 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
144 | + $formElement->setExtra('onchange="'.$onchangedString.'"'.' '.$otherExtra); |
|
145 | 145 | } else { |
146 | 146 | if (isset($var['form_extra'])) { |
147 | 147 | $formElement->setExtra($var['form_extra']); |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | asort($group_list); |
309 | 309 | foreach ($permissions as $permission) { |
310 | 310 | if ($this->targetObject->isNew()) { |
311 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
312 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
311 | + if (isset($smartModuleConfig['def_perm_'.$permission['perm_name']])) { |
|
312 | + $groups_value = $smartModuleConfig['def_perm_'.$permission['perm_name']]; |
|
313 | 313 | } |
314 | 314 | } else { |
315 | 315 | $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
@@ -341,7 +341,7 @@ discard block |
||
341 | 341 | } else { |
342 | 342 | $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
343 | 343 | } |
344 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
344 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\''.$form_name.'\'"'); |
|
345 | 345 | $button_tray->addElement($butt_create); |
346 | 346 | |
347 | 347 | //creating custom buttons |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | foreach ($this->_custom_button as $custom_button) { |
350 | 350 | $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
351 | 351 | if ($custom_button['onclick']) { |
352 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
352 | + $butt_custom->setExtra('onclick="'.$custom_button['onclick'].'"'); |
|
353 | 353 | } |
354 | 354 | $button_tray->addElement($butt_custom); |
355 | 355 | unset($butt_custom); |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | // creating the "cancel" button |
360 | 360 | $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
361 | 361 | if ($this->_cancel_js_action) { |
362 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
362 | + $butt_cancel->setExtra('onclick="'.$this->_cancel_js_action.'"'); |
|
363 | 363 | } else { |
364 | 364 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
365 | 365 | } |
@@ -461,21 +461,21 @@ discard block |
||
461 | 461 | break; |
462 | 462 | |
463 | 463 | default: |
464 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
464 | + $classname = 'SmartForm'.ucfirst($controlName).'Element'; |
|
465 | 465 | if (!class_exists($classname)) { |
466 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
466 | + if (file_exists(SMARTOBJECT_ROOT_PATH.'class/form/elements/'.strtolower($classname).'.php')) { |
|
467 | 467 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
468 | 468 | } else { |
469 | 469 | // perhaps this is a control created by the module |
470 | 470 | $moduleName = $this->targetObject->handler->_moduleName; |
471 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
472 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
473 | - $classFileName = strtolower($classname) . '.php'; |
|
471 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath.'class/form/elements/'; |
|
472 | + $classname = ucfirst($moduleName).ucfirst($controlName).'Element'; |
|
473 | + $classFileName = strtolower($classname).'.php'; |
|
474 | 474 | |
475 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
475 | + if (file_exists($moduleFormElementsPath.$classFileName)) { |
|
476 | 476 | // require_once $moduleFormElementsPath . $classFileName; |
477 | 477 | } else { |
478 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
478 | + trigger_error($classname.' Not found', E_USER_WARNING); |
|
479 | 479 | |
480 | 480 | return new \XoopsFormLabel(); //Empty object |
481 | 481 | } |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | $editor_configs['height'] = '400px'; |
545 | 545 | |
546 | 546 | $dhtml = true; |
547 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
547 | + $xoopseditorclass = XOOPS_ROOT_PATH.'/class/xoopsform/formeditor.php'; |
|
548 | 548 | |
549 | 549 | if (file_exists($xoopseditorclass)) { |
550 | 550 | require_once $xoopseditorclass; |
@@ -554,8 +554,8 @@ discard block |
||
554 | 554 | |
555 | 555 | case 'tiny': |
556 | 556 | if (!$xoops22) { |
557 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
558 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
557 | + if (is_readable(XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
558 | + require_once XOOPS_ROOT_PATH.'/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
559 | 559 | $editor = new \XoopsFormTinymce([ |
560 | 560 | 'caption' => $caption, |
561 | 561 | 'name' => $name, |
@@ -662,10 +662,10 @@ discard block |
||
662 | 662 | $size = $multiple ? 5 : 1; |
663 | 663 | $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
664 | 664 | |
665 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
665 | + $handle = opendir(XOOPS_THEME_PATH.'/'); |
|
666 | 666 | $dirlist = []; |
667 | 667 | while (false !== ($file = readdir($handle))) { |
668 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
668 | + if (is_dir(XOOPS_THEME_PATH.'/'.$file) && !preg_match('/^[.]{1,2}$/', $file) |
|
669 | 669 | && 'cvs' !== strtolower($file)) { |
670 | 670 | $dirlist[$file] = $file; |
671 | 671 | } |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | { |
688 | 688 | foreach ($this->_elements as $eleObj) { |
689 | 689 | if ($eleObj->getName() == $keyname) { |
690 | - $ret =& $eleObj; |
|
690 | + $ret = & $eleObj; |
|
691 | 691 | break; |
692 | 692 | } |
693 | 693 | } |
@@ -704,9 +704,9 @@ discard block |
||
704 | 704 | { |
705 | 705 | $required = $this->getRequired(); |
706 | 706 | $ret = " |
707 | - <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
|
707 | + <form name='" . $this->getName()."' id='".$this->getName()."' action='".$this->getAction()."' method='".$this->getMethod()."' onsubmit='return xoopsFormValidate_".$this->getName()."(this);'".$this->getExtra()."> |
|
708 | 708 | <table width='100%' class='outer' cellspacing='1'> |
709 | - <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
|
709 | + <tr><th colspan='2'>" . $this->getTitle().'</th></tr> |
|
710 | 710 | '; |
711 | 711 | $hidden = ''; |
712 | 712 | $class = 'even'; |
@@ -715,11 +715,11 @@ discard block |
||
715 | 715 | $ret .= $ele; |
716 | 716 | } elseif (!$ele->isHidden()) { |
717 | 717 | //$class = ( $class == 'even' ) ? 'odd': 'even'; |
718 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
718 | + $ret .= "<tr id='".$ele->getName()."' valign='top' align='left'><td class='head'>".$ele->getCaption(); |
|
719 | 719 | if ('' !== $ele->getDescription()) { |
720 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
720 | + $ret .= '<br><br><span style="font-weight: normal;">'.$ele->getDescription().'</span>'; |
|
721 | 721 | } |
722 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
722 | + $ret .= "</td><td class='$class'>".$ele->render()."</td></tr>\n"; |
|
723 | 723 | } else { |
724 | 724 | $hidden .= $ele->render(); |
725 | 725 | } |
@@ -767,7 +767,7 @@ discard block |
||
767 | 767 | 'name' => $this->getName(), |
768 | 768 | 'action' => $this->getAction(), |
769 | 769 | 'method' => $this->getMethod(), |
770 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
770 | + 'extra' => 'onsubmit="return xoopsFormValidate_'.$this->getName().'(this);"'.$this->getExtra(), |
|
771 | 771 | 'javascript' => $js, |
772 | 772 | 'elements' => $elements |
773 | 773 | ]); |
@@ -785,7 +785,7 @@ discard block |
||
785 | 785 | } |
786 | 786 | $myts = \MyTextSanitizer::getInstance(); |
787 | 787 | $formname = $this->getName(); |
788 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
788 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
789 | 789 | // First, output code to check required elements |
790 | 790 | $elements = $this->getRequired(); |
791 | 791 | foreach ($elements as $elt) { |
@@ -836,15 +836,15 @@ discard block |
||
836 | 836 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
837 | 837 | } |
838 | 838 | } else { |
839 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
839 | + $js .= "if ( myform.{$eltname}.value == \"\" ) "."{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
840 | 840 | } |
841 | 841 | } |
842 | 842 | // Now, handle custom validation code |
843 | - $elements =& $this->getElements(true); |
|
843 | + $elements = & $this->getElements(true); |
|
844 | 844 | foreach ($elements as $elt) { |
845 | 845 | if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
846 | 846 | if ($eltjs = $elt->renderValidationJS()) { |
847 | - $js .= $eltjs . "\n"; |
|
847 | + $js .= $eltjs."\n"; |
|
848 | 848 | } |
849 | 849 | } |
850 | 850 | } |
@@ -44,549 +44,549 @@ discard block |
||
44 | 44 | */ |
45 | 45 | class SmartObjectForm extends \XoopsThemeForm |
46 | 46 | { |
47 | - public $targetObject = null; |
|
48 | - public $form_fields = null; |
|
49 | - public $_cancel_js_action = false; |
|
50 | - public $_custom_button = false; |
|
51 | - public $_captcha = false; |
|
52 | - public $_form_name = false; |
|
53 | - public $_form_caption = false; |
|
54 | - public $_submit_button_caption = false; |
|
55 | - |
|
56 | - /** |
|
57 | - * SmartobjectForm constructor. |
|
58 | - * @param string $target |
|
59 | - * @param string $form_name |
|
60 | - * @param string $form_caption |
|
61 | - * @param string $form_action |
|
62 | - * @param null $form_fields |
|
63 | - * @param bool $submit_button_caption |
|
64 | - * @param bool $cancel_js_action |
|
65 | - * @param bool $captcha |
|
66 | - */ |
|
67 | - public function __construct( |
|
68 | - &$target, |
|
69 | - $form_name, |
|
70 | - $form_caption, |
|
71 | - $form_action, |
|
72 | - $form_fields = null, |
|
73 | - $submit_button_caption = false, |
|
74 | - $cancel_js_action = false, |
|
75 | - $captcha = false |
|
76 | - ) { |
|
77 | - $this->targetObject =& $target; |
|
78 | - $this->form_fields = $form_fields; |
|
79 | - $this->_cancel_js_action = $cancel_js_action; |
|
80 | - $this->_captcha = $captcha; |
|
81 | - $this->_form_name = $form_name; |
|
82 | - $this->_form_caption = $form_caption; |
|
83 | - $this->_submit_button_caption = $submit_button_caption; |
|
84 | - |
|
85 | - if (!isset($form_action)) { |
|
86 | - $form_action = xoops_getenv('PHP_SELF'); |
|
87 | - } |
|
88 | - |
|
89 | - parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
90 | - $this->setExtra('enctype="multipart/form-data"'); |
|
91 | - |
|
92 | - $this->createElements(); |
|
93 | - |
|
94 | - if ($captcha) { |
|
95 | - $this->addCaptcha(); |
|
96 | - } |
|
97 | - |
|
98 | - $this->createPermissionControls(); |
|
99 | - |
|
100 | - $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
101 | - } |
|
102 | - |
|
103 | - public function addCaptcha() |
|
104 | - { |
|
105 | - require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
106 | - $this->addElement(new \XoopsFormCaptcha(), true); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * @param $name |
|
111 | - * @param $caption |
|
112 | - * @param bool $onclick |
|
113 | - */ |
|
114 | - public function addCustomButton($name, $caption, $onclick = false) |
|
115 | - { |
|
116 | - $custom_button_array = [ |
|
117 | - 'name' => $name, |
|
118 | - 'caption' => $caption, |
|
119 | - 'onclick' => $onclick |
|
120 | - ]; |
|
121 | - $this->_custom_button[] = $custom_button_array; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Add an element to the form |
|
126 | - * |
|
127 | - * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
128 | - * @param bool $key |
|
129 | - * @param bool $var |
|
130 | - * @param bool|string $required is this a "required" element? |
|
131 | - */ |
|
132 | - public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
133 | - { |
|
134 | - if ($key) { |
|
135 | - if ($this->targetObject->vars[$key]['readonly']) { |
|
136 | - $formElement->setExtra('disabled="disabled"'); |
|
137 | - $formElement->setName($key . '-readonly'); |
|
138 | - // Since this element is disable, we still want to pass it's value in the form |
|
139 | - $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
140 | - $this->addElement($hidden); |
|
141 | - } |
|
142 | - $formElement->setDescription($var['form_dsc']); |
|
143 | - if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
144 | - $hidden = new \XoopsFormHidden('changedField', false); |
|
145 | - $this->addElement($hidden); |
|
146 | - $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
147 | - $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
148 | - $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
149 | - } else { |
|
150 | - if (isset($var['form_extra'])) { |
|
151 | - $formElement->setExtra($var['form_extra']); |
|
152 | - } |
|
153 | - } |
|
154 | - $controls = $this->targetObject->controls; |
|
155 | - if (isset($controls[$key]['js'])) { |
|
156 | - $formElement->customValidationCode[] = $controls[$key]['js']; |
|
157 | - } |
|
158 | - parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
159 | - } else { |
|
160 | - parent::addElement($formElement, 'notset' === $required ? false : true); |
|
161 | - } |
|
162 | - unset($formElement); |
|
163 | - } |
|
164 | - |
|
165 | - public function createElements() |
|
166 | - { |
|
167 | - $controls = $this->targetObject->controls; |
|
168 | - $vars = $this->targetObject->vars; |
|
169 | - foreach ($vars as $key => $var) { |
|
170 | - |
|
171 | - // If $displayOnForm is false OR this is the primary key, it doesn't |
|
172 | - // need to be displayed, then we only create an hidden field |
|
173 | - if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
174 | - $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
175 | - $this->addElement($elementToAdd, $key, $var, false); |
|
176 | - unset($elementToAdd); |
|
177 | - // If not, the we need to create the proper form control for this fields |
|
178 | - } else { |
|
179 | - // If this field has a specific control, we will use it |
|
180 | - |
|
181 | - if ('parentid' === $key) { |
|
182 | - /** |
|
183 | - * Why this ? |
|
184 | - */ |
|
185 | - } |
|
186 | - if (isset($controls[$key])) { |
|
187 | - /* If the control has name, it's because it's an object already present in the script |
|
47 | + public $targetObject = null; |
|
48 | + public $form_fields = null; |
|
49 | + public $_cancel_js_action = false; |
|
50 | + public $_custom_button = false; |
|
51 | + public $_captcha = false; |
|
52 | + public $_form_name = false; |
|
53 | + public $_form_caption = false; |
|
54 | + public $_submit_button_caption = false; |
|
55 | + |
|
56 | + /** |
|
57 | + * SmartobjectForm constructor. |
|
58 | + * @param string $target |
|
59 | + * @param string $form_name |
|
60 | + * @param string $form_caption |
|
61 | + * @param string $form_action |
|
62 | + * @param null $form_fields |
|
63 | + * @param bool $submit_button_caption |
|
64 | + * @param bool $cancel_js_action |
|
65 | + * @param bool $captcha |
|
66 | + */ |
|
67 | + public function __construct( |
|
68 | + &$target, |
|
69 | + $form_name, |
|
70 | + $form_caption, |
|
71 | + $form_action, |
|
72 | + $form_fields = null, |
|
73 | + $submit_button_caption = false, |
|
74 | + $cancel_js_action = false, |
|
75 | + $captcha = false |
|
76 | + ) { |
|
77 | + $this->targetObject =& $target; |
|
78 | + $this->form_fields = $form_fields; |
|
79 | + $this->_cancel_js_action = $cancel_js_action; |
|
80 | + $this->_captcha = $captcha; |
|
81 | + $this->_form_name = $form_name; |
|
82 | + $this->_form_caption = $form_caption; |
|
83 | + $this->_submit_button_caption = $submit_button_caption; |
|
84 | + |
|
85 | + if (!isset($form_action)) { |
|
86 | + $form_action = xoops_getenv('PHP_SELF'); |
|
87 | + } |
|
88 | + |
|
89 | + parent::__construct($form_caption, $form_name, $form_action, 'post', true); |
|
90 | + $this->setExtra('enctype="multipart/form-data"'); |
|
91 | + |
|
92 | + $this->createElements(); |
|
93 | + |
|
94 | + if ($captcha) { |
|
95 | + $this->addCaptcha(); |
|
96 | + } |
|
97 | + |
|
98 | + $this->createPermissionControls(); |
|
99 | + |
|
100 | + $this->createButtons($form_name, $form_caption, $submit_button_caption); |
|
101 | + } |
|
102 | + |
|
103 | + public function addCaptcha() |
|
104 | + { |
|
105 | + require_once SMARTOBJECT_ROOT_PATH . 'include/captcha/formcaptcha.php'; |
|
106 | + $this->addElement(new \XoopsFormCaptcha(), true); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * @param $name |
|
111 | + * @param $caption |
|
112 | + * @param bool $onclick |
|
113 | + */ |
|
114 | + public function addCustomButton($name, $caption, $onclick = false) |
|
115 | + { |
|
116 | + $custom_button_array = [ |
|
117 | + 'name' => $name, |
|
118 | + 'caption' => $caption, |
|
119 | + 'onclick' => $onclick |
|
120 | + ]; |
|
121 | + $this->_custom_button[] = $custom_button_array; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Add an element to the form |
|
126 | + * |
|
127 | + * @param string|XoopsFormElement &$formElement reference to a {@link XoopsFormElement} |
|
128 | + * @param bool $key |
|
129 | + * @param bool $var |
|
130 | + * @param bool|string $required is this a "required" element? |
|
131 | + */ |
|
132 | + public function addElement($formElement, $key = false, $var = false, $required = 'notset') |
|
133 | + { |
|
134 | + if ($key) { |
|
135 | + if ($this->targetObject->vars[$key]['readonly']) { |
|
136 | + $formElement->setExtra('disabled="disabled"'); |
|
137 | + $formElement->setName($key . '-readonly'); |
|
138 | + // Since this element is disable, we still want to pass it's value in the form |
|
139 | + $hidden = new \XoopsFormHidden($key, $this->targetObject->vars[$key]['value']); |
|
140 | + $this->addElement($hidden); |
|
141 | + } |
|
142 | + $formElement->setDescription($var['form_dsc']); |
|
143 | + if (isset($this->targetObject->controls[$key]['onSelect'])) { |
|
144 | + $hidden = new \XoopsFormHidden('changedField', false); |
|
145 | + $this->addElement($hidden); |
|
146 | + $otherExtra = isset($var['form_extra']) ? $var['form_extra'] : ''; |
|
147 | + $onchangedString = "this.form.elements.changedField.value='$key'; this.form.elements.op.value='changedField'; submit()"; |
|
148 | + $formElement->setExtra('onchange="' . $onchangedString . '"' . ' ' . $otherExtra); |
|
149 | + } else { |
|
150 | + if (isset($var['form_extra'])) { |
|
151 | + $formElement->setExtra($var['form_extra']); |
|
152 | + } |
|
153 | + } |
|
154 | + $controls = $this->targetObject->controls; |
|
155 | + if (isset($controls[$key]['js'])) { |
|
156 | + $formElement->customValidationCode[] = $controls[$key]['js']; |
|
157 | + } |
|
158 | + parent::addElement($formElement, 'notset' === $required ? $var['required'] : $required); |
|
159 | + } else { |
|
160 | + parent::addElement($formElement, 'notset' === $required ? false : true); |
|
161 | + } |
|
162 | + unset($formElement); |
|
163 | + } |
|
164 | + |
|
165 | + public function createElements() |
|
166 | + { |
|
167 | + $controls = $this->targetObject->controls; |
|
168 | + $vars = $this->targetObject->vars; |
|
169 | + foreach ($vars as $key => $var) { |
|
170 | + |
|
171 | + // If $displayOnForm is false OR this is the primary key, it doesn't |
|
172 | + // need to be displayed, then we only create an hidden field |
|
173 | + if ($key == $this->targetObject->handler->keyName || !$var['displayOnForm']) { |
|
174 | + $elementToAdd = new \XoopsFormHidden($key, $var['value']); |
|
175 | + $this->addElement($elementToAdd, $key, $var, false); |
|
176 | + unset($elementToAdd); |
|
177 | + // If not, the we need to create the proper form control for this fields |
|
178 | + } else { |
|
179 | + // If this field has a specific control, we will use it |
|
180 | + |
|
181 | + if ('parentid' === $key) { |
|
182 | + /** |
|
183 | + * Why this ? |
|
184 | + */ |
|
185 | + } |
|
186 | + if (isset($controls[$key])) { |
|
187 | + /* If the control has name, it's because it's an object already present in the script |
|
188 | 188 | * for example, "user" |
189 | 189 | * If the field does not have a name, than we will use a "select" (ie XoopsFormSelect) |
190 | 190 | */ |
191 | - if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
192 | - $controls[$key]['name'] = 'select'; |
|
193 | - } |
|
194 | - |
|
195 | - $form_select = $this->getControl($controls[$key]['name'], $key); |
|
196 | - |
|
197 | - // Adding on the form, the control for this field |
|
198 | - $this->addElement($form_select, $key, $var); |
|
199 | - unset($form_select); |
|
200 | - |
|
201 | - // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
202 | - } else { |
|
203 | - switch ($var['data_type']) { |
|
204 | - |
|
205 | - case XOBJ_DTYPE_TXTBOX: |
|
206 | - |
|
207 | - $form_text = $this->getControl('text', $key); |
|
208 | - $this->addElement($form_text, $key, $var); |
|
209 | - unset($form_text); |
|
210 | - break; |
|
211 | - |
|
212 | - case XOBJ_DTYPE_INT: |
|
213 | - $this->targetObject->setControl($key, [ |
|
214 | - 'name' => 'text', |
|
215 | - 'size' => '5' |
|
216 | - ]); |
|
217 | - $form_text = $this->getControl('text', $key); |
|
218 | - $this->addElement($form_text, $key, $var); |
|
219 | - unset($form_text); |
|
220 | - break; |
|
221 | - |
|
222 | - case XOBJ_DTYPE_FLOAT: |
|
223 | - $this->targetObject->setControl($key, [ |
|
224 | - 'name' => 'text', |
|
225 | - 'size' => '5' |
|
226 | - ]); |
|
227 | - $form_text = $this->getControl('text', $key); |
|
228 | - $this->addElement($form_text, $key, $var); |
|
229 | - unset($form_text); |
|
230 | - break; |
|
231 | - |
|
232 | - case XOBJ_DTYPE_LTIME: |
|
233 | - $form_date_time = $this->getControl('date_time', $key); |
|
234 | - $this->addElement($form_date_time, $key, $var); |
|
235 | - unset($form_date_time); |
|
236 | - break; |
|
237 | - |
|
238 | - case XOBJ_DTYPE_STIME: |
|
239 | - $form_date_time = $this->getControl('date', $key); |
|
240 | - $this->addElement($form_date_time, $key, $var); |
|
241 | - unset($form_date_time); |
|
242 | - break; |
|
243 | - |
|
244 | - case XOBJ_DTYPE_TIME_ONLY: |
|
245 | - $form_time = $this->getControl('time', $key); |
|
246 | - $this->addElement($form_time, $key, $var); |
|
247 | - unset($form_time); |
|
248 | - break; |
|
249 | - |
|
250 | - case XOBJ_DTYPE_CURRENCY: |
|
251 | - $this->targetObject->setControl($key, [ |
|
252 | - 'name' => 'text', |
|
253 | - 'size' => '15' |
|
254 | - ]); |
|
255 | - $form_currency = $this->getControl('text', $key); |
|
256 | - $this->addElement($form_currency, $key, $var); |
|
257 | - unset($form_currency); |
|
258 | - break; |
|
259 | - |
|
260 | - case XOBJ_DTYPE_URLLINK: |
|
261 | - $form_urllink = $this->getControl('urllink', $key); |
|
262 | - $this->addElement($form_urllink, $key, $var); |
|
263 | - unset($form_urllink); |
|
264 | - break; |
|
265 | - |
|
266 | - case XOBJ_DTYPE_FILE: |
|
267 | - $form_file = $this->getControl('richfile', $key); |
|
268 | - $this->addElement($form_file, $key, $var); |
|
269 | - unset($form_file); |
|
270 | - break; |
|
271 | - |
|
272 | - case XOBJ_DTYPE_TXTAREA: |
|
273 | - |
|
274 | - $form_text_area = $this->getTextArea($key, $var); |
|
275 | - $this->addElement($form_text_area, $key, $var); |
|
276 | - unset($form_text_area); |
|
277 | - break; |
|
278 | - |
|
279 | - case XOBJ_DTYPE_ARRAY: |
|
280 | - // TODO: To come... |
|
281 | - break; |
|
282 | - case XOBJ_DTYPE_SOURCE: |
|
283 | - // TODO: To come... |
|
284 | - break; |
|
285 | - case XOBJ_DTYPE_FORM_SECTION: |
|
286 | - $section_control = new SmartFormSection($key, $var['value']); |
|
287 | - $this->addElement($section_control, $key, $var); |
|
288 | - unset($section_control); |
|
289 | - break; |
|
290 | - case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
291 | - $section_control = new SmartFormSectionClose($key, $var['value']); |
|
292 | - $this->addElement($section_control, $key, $var); |
|
293 | - unset($section_control); |
|
294 | - break; |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
298 | - } |
|
299 | - // Add an hidden field to store the URL of the page before this form |
|
300 | - $this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm())); |
|
301 | - } |
|
302 | - |
|
303 | - public function createPermissionControls() |
|
304 | - { |
|
305 | - $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
306 | - |
|
307 | - $permissions = $this->targetObject->handler->getPermissions(); |
|
308 | - |
|
309 | - if ($permissions) { |
|
310 | - $memberHandler = xoops_getHandler('member'); |
|
311 | - $group_list = $memberHandler->getGroupList(); |
|
312 | - asort($group_list); |
|
313 | - foreach ($permissions as $permission) { |
|
314 | - if ($this->targetObject->isNew()) { |
|
315 | - if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
316 | - $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
317 | - } |
|
318 | - } else { |
|
319 | - $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
320 | - } |
|
321 | - $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
322 | - $groups_select->setDescription($permission['description']); |
|
323 | - $groups_select->addOptionArray($group_list); |
|
324 | - $this->addElement($groups_select); |
|
325 | - unset($groups_select); |
|
326 | - } |
|
327 | - } |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param $form_name |
|
332 | - * @param $form_caption |
|
333 | - * @param bool $submit_button_caption |
|
334 | - */ |
|
335 | - public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
336 | - { |
|
337 | - $button_tray = new \XoopsFormElementTray('', ''); |
|
338 | - $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
339 | - if (!$submit_button_caption) { |
|
340 | - if ($this->targetObject->isNew()) { |
|
341 | - $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
342 | - } else { |
|
343 | - $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
344 | - } |
|
345 | - } else { |
|
346 | - $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
347 | - } |
|
348 | - $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
349 | - $button_tray->addElement($butt_create); |
|
350 | - |
|
351 | - //creating custom buttons |
|
352 | - if ($this->_custom_button) { |
|
353 | - foreach ($this->_custom_button as $custom_button) { |
|
354 | - $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
355 | - if ($custom_button['onclick']) { |
|
356 | - $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
357 | - } |
|
358 | - $button_tray->addElement($butt_custom); |
|
359 | - unset($butt_custom); |
|
360 | - } |
|
361 | - } |
|
362 | - |
|
363 | - // creating the "cancel" button |
|
364 | - $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
365 | - if ($this->_cancel_js_action) { |
|
366 | - $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
367 | - } else { |
|
368 | - $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
369 | - } |
|
370 | - $button_tray->addElement($butt_cancel); |
|
371 | - |
|
372 | - $this->addElement($button_tray); |
|
373 | - } |
|
374 | - |
|
375 | - /** |
|
376 | - * @param $controlName |
|
377 | - * @param $key |
|
378 | - * @return \XoopsFormLabel |
|
379 | - */ |
|
380 | - public function getControl($controlName, $key) |
|
381 | - { |
|
382 | - switch ($controlName) { |
|
383 | - case 'check': |
|
191 | + if (!isset($controls[$key]['name']) || !$controls[$key]['name']) { |
|
192 | + $controls[$key]['name'] = 'select'; |
|
193 | + } |
|
194 | + |
|
195 | + $form_select = $this->getControl($controls[$key]['name'], $key); |
|
196 | + |
|
197 | + // Adding on the form, the control for this field |
|
198 | + $this->addElement($form_select, $key, $var); |
|
199 | + unset($form_select); |
|
200 | + |
|
201 | + // If this field don't have a specific control, we will use the standard one, depending on its data type |
|
202 | + } else { |
|
203 | + switch ($var['data_type']) { |
|
204 | + |
|
205 | + case XOBJ_DTYPE_TXTBOX: |
|
206 | + |
|
207 | + $form_text = $this->getControl('text', $key); |
|
208 | + $this->addElement($form_text, $key, $var); |
|
209 | + unset($form_text); |
|
210 | + break; |
|
211 | + |
|
212 | + case XOBJ_DTYPE_INT: |
|
213 | + $this->targetObject->setControl($key, [ |
|
214 | + 'name' => 'text', |
|
215 | + 'size' => '5' |
|
216 | + ]); |
|
217 | + $form_text = $this->getControl('text', $key); |
|
218 | + $this->addElement($form_text, $key, $var); |
|
219 | + unset($form_text); |
|
220 | + break; |
|
221 | + |
|
222 | + case XOBJ_DTYPE_FLOAT: |
|
223 | + $this->targetObject->setControl($key, [ |
|
224 | + 'name' => 'text', |
|
225 | + 'size' => '5' |
|
226 | + ]); |
|
227 | + $form_text = $this->getControl('text', $key); |
|
228 | + $this->addElement($form_text, $key, $var); |
|
229 | + unset($form_text); |
|
230 | + break; |
|
231 | + |
|
232 | + case XOBJ_DTYPE_LTIME: |
|
233 | + $form_date_time = $this->getControl('date_time', $key); |
|
234 | + $this->addElement($form_date_time, $key, $var); |
|
235 | + unset($form_date_time); |
|
236 | + break; |
|
237 | + |
|
238 | + case XOBJ_DTYPE_STIME: |
|
239 | + $form_date_time = $this->getControl('date', $key); |
|
240 | + $this->addElement($form_date_time, $key, $var); |
|
241 | + unset($form_date_time); |
|
242 | + break; |
|
243 | + |
|
244 | + case XOBJ_DTYPE_TIME_ONLY: |
|
245 | + $form_time = $this->getControl('time', $key); |
|
246 | + $this->addElement($form_time, $key, $var); |
|
247 | + unset($form_time); |
|
248 | + break; |
|
249 | + |
|
250 | + case XOBJ_DTYPE_CURRENCY: |
|
251 | + $this->targetObject->setControl($key, [ |
|
252 | + 'name' => 'text', |
|
253 | + 'size' => '15' |
|
254 | + ]); |
|
255 | + $form_currency = $this->getControl('text', $key); |
|
256 | + $this->addElement($form_currency, $key, $var); |
|
257 | + unset($form_currency); |
|
258 | + break; |
|
259 | + |
|
260 | + case XOBJ_DTYPE_URLLINK: |
|
261 | + $form_urllink = $this->getControl('urllink', $key); |
|
262 | + $this->addElement($form_urllink, $key, $var); |
|
263 | + unset($form_urllink); |
|
264 | + break; |
|
265 | + |
|
266 | + case XOBJ_DTYPE_FILE: |
|
267 | + $form_file = $this->getControl('richfile', $key); |
|
268 | + $this->addElement($form_file, $key, $var); |
|
269 | + unset($form_file); |
|
270 | + break; |
|
271 | + |
|
272 | + case XOBJ_DTYPE_TXTAREA: |
|
273 | + |
|
274 | + $form_text_area = $this->getTextArea($key, $var); |
|
275 | + $this->addElement($form_text_area, $key, $var); |
|
276 | + unset($form_text_area); |
|
277 | + break; |
|
278 | + |
|
279 | + case XOBJ_DTYPE_ARRAY: |
|
280 | + // TODO: To come... |
|
281 | + break; |
|
282 | + case XOBJ_DTYPE_SOURCE: |
|
283 | + // TODO: To come... |
|
284 | + break; |
|
285 | + case XOBJ_DTYPE_FORM_SECTION: |
|
286 | + $section_control = new SmartFormSection($key, $var['value']); |
|
287 | + $this->addElement($section_control, $key, $var); |
|
288 | + unset($section_control); |
|
289 | + break; |
|
290 | + case XOBJ_DTYPE_FORM_SECTION_CLOSE: |
|
291 | + $section_control = new SmartFormSectionClose($key, $var['value']); |
|
292 | + $this->addElement($section_control, $key, $var); |
|
293 | + unset($section_control); |
|
294 | + break; |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | + } |
|
299 | + // Add an hidden field to store the URL of the page before this form |
|
300 | + $this->addElement(new \XoopsFormHidden('smart_page_before_form', Smartobject\Utility::getPageBeforeForm())); |
|
301 | + } |
|
302 | + |
|
303 | + public function createPermissionControls() |
|
304 | + { |
|
305 | + $smartModuleConfig = $this->targetObject->handler->getModuleConfig(); |
|
306 | + |
|
307 | + $permissions = $this->targetObject->handler->getPermissions(); |
|
308 | + |
|
309 | + if ($permissions) { |
|
310 | + $memberHandler = xoops_getHandler('member'); |
|
311 | + $group_list = $memberHandler->getGroupList(); |
|
312 | + asort($group_list); |
|
313 | + foreach ($permissions as $permission) { |
|
314 | + if ($this->targetObject->isNew()) { |
|
315 | + if (isset($smartModuleConfig['def_perm_' . $permission['perm_name']])) { |
|
316 | + $groups_value = $smartModuleConfig['def_perm_' . $permission['perm_name']]; |
|
317 | + } |
|
318 | + } else { |
|
319 | + $groups_value = $this->targetObject->getGroupPerm($permission['perm_name']); |
|
320 | + } |
|
321 | + $groups_select = new \XoopsFormSelect($permission['caption'], $permission['perm_name'], $groups_value, 4, true); |
|
322 | + $groups_select->setDescription($permission['description']); |
|
323 | + $groups_select->addOptionArray($group_list); |
|
324 | + $this->addElement($groups_select); |
|
325 | + unset($groups_select); |
|
326 | + } |
|
327 | + } |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param $form_name |
|
332 | + * @param $form_caption |
|
333 | + * @param bool $submit_button_caption |
|
334 | + */ |
|
335 | + public function createButtons($form_name, $form_caption, $submit_button_caption = false) |
|
336 | + { |
|
337 | + $button_tray = new \XoopsFormElementTray('', ''); |
|
338 | + $button_tray->addElement(new \XoopsFormHidden('op', $form_name)); |
|
339 | + if (!$submit_button_caption) { |
|
340 | + if ($this->targetObject->isNew()) { |
|
341 | + $butt_create = new \XoopsFormButton('', 'create_button', _CO_SOBJECT_CREATE, 'submit'); |
|
342 | + } else { |
|
343 | + $butt_create = new \XoopsFormButton('', 'modify_button', _CO_SOBJECT_MODIFY, 'submit'); |
|
344 | + } |
|
345 | + } else { |
|
346 | + $butt_create = new \XoopsFormButton('', 'modify_button', $submit_button_caption, 'submit'); |
|
347 | + } |
|
348 | + $butt_create->setExtra('onclick="this.form.elements.op.value=\'' . $form_name . '\'"'); |
|
349 | + $button_tray->addElement($butt_create); |
|
350 | + |
|
351 | + //creating custom buttons |
|
352 | + if ($this->_custom_button) { |
|
353 | + foreach ($this->_custom_button as $custom_button) { |
|
354 | + $butt_custom = new \XoopsFormButton('', $custom_button['name'], $custom_button['caption'], 'submit'); |
|
355 | + if ($custom_button['onclick']) { |
|
356 | + $butt_custom->setExtra('onclick="' . $custom_button['onclick'] . '"'); |
|
357 | + } |
|
358 | + $button_tray->addElement($butt_custom); |
|
359 | + unset($butt_custom); |
|
360 | + } |
|
361 | + } |
|
362 | + |
|
363 | + // creating the "cancel" button |
|
364 | + $butt_cancel = new \XoopsFormButton('', 'cancel_button', _CO_SOBJECT_CANCEL, 'button'); |
|
365 | + if ($this->_cancel_js_action) { |
|
366 | + $butt_cancel->setExtra('onclick="' . $this->_cancel_js_action . '"'); |
|
367 | + } else { |
|
368 | + $butt_cancel->setExtra('onclick="history.go(-1)"'); |
|
369 | + } |
|
370 | + $button_tray->addElement($butt_cancel); |
|
371 | + |
|
372 | + $this->addElement($button_tray); |
|
373 | + } |
|
374 | + |
|
375 | + /** |
|
376 | + * @param $controlName |
|
377 | + * @param $key |
|
378 | + * @return \XoopsFormLabel |
|
379 | + */ |
|
380 | + public function getControl($controlName, $key) |
|
381 | + { |
|
382 | + switch ($controlName) { |
|
383 | + case 'check': |
|
384 | 384 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformcheckelement.php'; |
385 | - $control = $this->targetObject->getControl($key); |
|
386 | - $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
387 | - $controlObj->addOptionArray($control['options']); |
|
385 | + $control = $this->targetObject->getControl($key); |
|
386 | + $controlObj = new SmartFormCheckElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
387 | + $controlObj->addOptionArray($control['options']); |
|
388 | 388 | |
389 | - return $controlObj; |
|
390 | - break; |
|
389 | + return $controlObj; |
|
390 | + break; |
|
391 | 391 | |
392 | - case 'color': |
|
393 | - $control = $this->targetObject->getControl($key); |
|
394 | - $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
392 | + case 'color': |
|
393 | + $control = $this->targetObject->getControl($key); |
|
394 | + $controlObj = new \XoopsFormColorPicker($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
395 | 395 | |
396 | - return $controlObj; |
|
397 | - break; |
|
396 | + return $controlObj; |
|
397 | + break; |
|
398 | 398 | |
399 | - case 'radio': |
|
400 | - $control = $this->targetObject->getControl($key); |
|
399 | + case 'radio': |
|
400 | + $control = $this->targetObject->getControl($key); |
|
401 | 401 | |
402 | - $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
403 | - $controlObj->addOptionArray($control['options']); |
|
402 | + $controlObj = new \XoopsFormRadio($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
403 | + $controlObj->addOptionArray($control['options']); |
|
404 | 404 | |
405 | - return $controlObj; |
|
406 | - break; |
|
405 | + return $controlObj; |
|
406 | + break; |
|
407 | 407 | |
408 | - case 'label': |
|
409 | - return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
410 | - break; |
|
408 | + case 'label': |
|
409 | + return new \XoopsFormLabel($this->targetObject->vars[$key]['form_caption'], $this->targetObject->getVar($key)); |
|
410 | + break; |
|
411 | 411 | |
412 | - case 'textarea': |
|
413 | - return $this->getTextArea($key); |
|
412 | + case 'textarea': |
|
413 | + return $this->getTextArea($key); |
|
414 | 414 | |
415 | - case 'theme': |
|
416 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
415 | + case 'theme': |
|
416 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key]); |
|
417 | 417 | |
418 | - case 'theme_multi': |
|
419 | - return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
420 | - break; |
|
418 | + case 'theme_multi': |
|
419 | + return $this->getThemeSelect($key, $this->targetObject->vars[$key], true); |
|
420 | + break; |
|
421 | 421 | |
422 | - case 'timezone': |
|
423 | - return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
424 | - break; |
|
422 | + case 'timezone': |
|
423 | + return new \XoopsFormSelectTimezone($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key)); |
|
424 | + break; |
|
425 | 425 | |
426 | - case 'group': |
|
427 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
428 | - break; |
|
426 | + case 'group': |
|
427 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
|
428 | + break; |
|
429 | 429 | |
430 | - case 'group_multi': |
|
431 | - return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
432 | - break; |
|
430 | + case 'group_multi': |
|
431 | + return new \XoopsFormSelectGroup($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
432 | + break; |
|
433 | 433 | |
434 | - /*case 'user': |
|
434 | + /*case 'user': |
|
435 | 435 | return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 1, false); |
436 | 436 | break;*/ |
437 | 437 | |
438 | - case 'user_multi': |
|
439 | - return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
440 | - break; |
|
438 | + case 'user_multi': |
|
439 | + return new \XoopsFormSelectUser($this->targetObject->vars[$key]['form_caption'], $key, false, $this->targetObject->getVar($key, 'e'), 5, true); |
|
440 | + break; |
|
441 | 441 | |
442 | - case 'password': |
|
443 | - return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
444 | - break; |
|
442 | + case 'password': |
|
443 | + return new \XoopsFormPassword($this->targetObject->vars[$key]['form_caption'], $key, 50, 255, $this->targetObject->getVar($key, 'e')); |
|
444 | + break; |
|
445 | 445 | |
446 | - case 'country': |
|
447 | - return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
448 | - break; |
|
446 | + case 'country': |
|
447 | + return new \XoopsFormSelectCountry($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getVar($key, 'e')); |
|
448 | + break; |
|
449 | 449 | |
450 | - case 'urllink': |
|
450 | + case 'urllink': |
|
451 | 451 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformurllinkelement.php'; |
452 | 452 | |
453 | - return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
454 | - break; |
|
453 | + return new SmartFormUrlLinkElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getUrlLinkObj($key)); |
|
454 | + break; |
|
455 | 455 | |
456 | - case 'richfile': |
|
456 | + case 'richfile': |
|
457 | 457 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformrichfileelement.php'; |
458 | 458 | |
459 | - return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
460 | - break; |
|
461 | - case 'section': |
|
459 | + return new SmartFormRichFileElement($this->targetObject->vars[$key]['form_caption'], $key, $this->targetObject->getFileObj($key)); |
|
460 | + break; |
|
461 | + case 'section': |
|
462 | 462 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformsection.php'; |
463 | 463 | |
464 | - return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
465 | - break; |
|
464 | + return new SmartFormSection($key, $this->targetObject->vars[$key]['form_caption']); |
|
465 | + break; |
|
466 | 466 | |
467 | - default: |
|
468 | - $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
469 | - if (!class_exists($classname)) { |
|
470 | - if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
467 | + default: |
|
468 | + $classname = 'SmartForm' . ucfirst($controlName) . 'Element'; |
|
469 | + if (!class_exists($classname)) { |
|
470 | + if (file_exists(SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php')) { |
|
471 | 471 | // require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/' . strtolower($classname) . '.php'; |
472 | - } else { |
|
473 | - // perhaps this is a control created by the module |
|
474 | - $moduleName = $this->targetObject->handler->_moduleName; |
|
475 | - $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
476 | - $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
477 | - $classFileName = strtolower($classname) . '.php'; |
|
478 | - |
|
479 | - if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
472 | + } else { |
|
473 | + // perhaps this is a control created by the module |
|
474 | + $moduleName = $this->targetObject->handler->_moduleName; |
|
475 | + $moduleFormElementsPath = $this->targetObject->handler->_modulePath . 'class/form/elements/'; |
|
476 | + $classname = ucfirst($moduleName) . ucfirst($controlName) . 'Element'; |
|
477 | + $classFileName = strtolower($classname) . '.php'; |
|
478 | + |
|
479 | + if (file_exists($moduleFormElementsPath . $classFileName)) { |
|
480 | 480 | // require_once $moduleFormElementsPath . $classFileName; |
481 | - } else { |
|
482 | - trigger_error($classname . ' Not found', E_USER_WARNING); |
|
483 | - |
|
484 | - return new \XoopsFormLabel(); //Empty object |
|
485 | - } |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - return new $classname($this->targetObject, $key); |
|
490 | - break; |
|
491 | - } |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * @param $key |
|
496 | - * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
497 | - */ |
|
498 | - public function getTextArea($key) |
|
499 | - { |
|
500 | - $var = $this->targetObject->vars[$key]; |
|
501 | - |
|
502 | - // if no control has been created, let's create a default one |
|
503 | - if (!isset($this->targetObject->controls[$key])) { |
|
504 | - $control = [ |
|
505 | - 'name' => 'textarea', |
|
506 | - 'itemHandler' => false, |
|
507 | - 'method' => false, |
|
508 | - 'module' => false, |
|
509 | - 'form_editor' => 'default' |
|
510 | - ]; |
|
511 | - } else { |
|
512 | - $control = $this->targetObject->controls[$key]; |
|
513 | - } |
|
514 | - $xoops22 = Smartobject\Utility::isXoops22(); |
|
515 | - |
|
516 | - $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
517 | - /** |
|
518 | - * If the editor is 'default', retreive the default editor of this module |
|
519 | - */ |
|
520 | - if ('default' === $form_editor) { |
|
521 | - /** @var Smartobject\Helper $helper */ |
|
522 | - $helper = Smartobject\Helper::getInstance(); |
|
523 | - $form_editor = null !== ($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea'; |
|
524 | - } |
|
525 | - |
|
526 | - $caption = $var['form_caption']; |
|
527 | - $name = $key; |
|
528 | - |
|
529 | - $value = $this->targetObject->getVar($key); |
|
530 | - |
|
531 | - $value = $this->targetObject->getValueFor($key, true); |
|
532 | - |
|
533 | - $editor_configs = []; |
|
534 | - $editor_configs['name'] = $name; |
|
535 | - $editor_configs['value'] = $value; |
|
536 | - if ('textarea' !== $form_editor) { |
|
537 | - $editor_configs['rows'] = 35; |
|
538 | - $editor_configs['cols'] = 60; |
|
539 | - } |
|
540 | - |
|
541 | - if (isset($control['rows'])) { |
|
542 | - $editor_configs['rows'] = $control['rows']; |
|
543 | - } |
|
544 | - if (isset($control['cols'])) { |
|
545 | - $editor_configs['cols'] = $control['cols']; |
|
546 | - } |
|
547 | - |
|
548 | - $editor_configs['width'] = '100%'; |
|
549 | - $editor_configs['height'] = '400px'; |
|
550 | - |
|
551 | - $dhtml = true; |
|
552 | - $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
553 | - |
|
554 | - if (file_exists($xoopseditorclass)) { |
|
555 | - require_once $xoopseditorclass; |
|
556 | - $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
557 | - } else { |
|
558 | - switch ($form_editor) { |
|
559 | - |
|
560 | - case 'tiny': |
|
561 | - if (!$xoops22) { |
|
562 | - if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
563 | - require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
564 | - $editor = new \XoopsFormTinymce([ |
|
565 | - 'caption' => $caption, |
|
566 | - 'name' => $name, |
|
567 | - 'value' => $value, |
|
568 | - 'width' => '100%', |
|
569 | - 'height' => '300px' |
|
570 | - ], true); |
|
571 | - } else { |
|
572 | - if ($dhtml) { |
|
573 | - $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
574 | - } else { |
|
575 | - $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
576 | - } |
|
577 | - } |
|
578 | - } else { |
|
579 | - $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
580 | - } |
|
581 | - break; |
|
582 | - |
|
583 | - case 'dhtmltextarea': |
|
584 | - case 'dhtmltext': |
|
585 | - $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
586 | - if ($var['form_dsc']) { |
|
587 | - $editor->setDescription($var['form_dsc']); |
|
588 | - } |
|
589 | - break; |
|
481 | + } else { |
|
482 | + trigger_error($classname . ' Not found', E_USER_WARNING); |
|
483 | + |
|
484 | + return new \XoopsFormLabel(); //Empty object |
|
485 | + } |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + return new $classname($this->targetObject, $key); |
|
490 | + break; |
|
491 | + } |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * @param $key |
|
496 | + * @return \XoopsFormDhtmlTextArea|\XoopsFormEditor|\XoopsFormTextArea|\XoopsFormTinymce|\XoopsFormTinymce4 |
|
497 | + */ |
|
498 | + public function getTextArea($key) |
|
499 | + { |
|
500 | + $var = $this->targetObject->vars[$key]; |
|
501 | + |
|
502 | + // if no control has been created, let's create a default one |
|
503 | + if (!isset($this->targetObject->controls[$key])) { |
|
504 | + $control = [ |
|
505 | + 'name' => 'textarea', |
|
506 | + 'itemHandler' => false, |
|
507 | + 'method' => false, |
|
508 | + 'module' => false, |
|
509 | + 'form_editor' => 'default' |
|
510 | + ]; |
|
511 | + } else { |
|
512 | + $control = $this->targetObject->controls[$key]; |
|
513 | + } |
|
514 | + $xoops22 = Smartobject\Utility::isXoops22(); |
|
515 | + |
|
516 | + $form_editor = isset($control['form_editor']) ? $control['form_editor'] : 'textarea'; |
|
517 | + /** |
|
518 | + * If the editor is 'default', retreive the default editor of this module |
|
519 | + */ |
|
520 | + if ('default' === $form_editor) { |
|
521 | + /** @var Smartobject\Helper $helper */ |
|
522 | + $helper = Smartobject\Helper::getInstance(); |
|
523 | + $form_editor = null !== ($helper->getConfig('default_editor')) ? $helper->getConfig('default_editor') : 'textarea'; |
|
524 | + } |
|
525 | + |
|
526 | + $caption = $var['form_caption']; |
|
527 | + $name = $key; |
|
528 | + |
|
529 | + $value = $this->targetObject->getVar($key); |
|
530 | + |
|
531 | + $value = $this->targetObject->getValueFor($key, true); |
|
532 | + |
|
533 | + $editor_configs = []; |
|
534 | + $editor_configs['name'] = $name; |
|
535 | + $editor_configs['value'] = $value; |
|
536 | + if ('textarea' !== $form_editor) { |
|
537 | + $editor_configs['rows'] = 35; |
|
538 | + $editor_configs['cols'] = 60; |
|
539 | + } |
|
540 | + |
|
541 | + if (isset($control['rows'])) { |
|
542 | + $editor_configs['rows'] = $control['rows']; |
|
543 | + } |
|
544 | + if (isset($control['cols'])) { |
|
545 | + $editor_configs['cols'] = $control['cols']; |
|
546 | + } |
|
547 | + |
|
548 | + $editor_configs['width'] = '100%'; |
|
549 | + $editor_configs['height'] = '400px'; |
|
550 | + |
|
551 | + $dhtml = true; |
|
552 | + $xoopseditorclass = XOOPS_ROOT_PATH . '/class/xoopsform/formeditor.php'; |
|
553 | + |
|
554 | + if (file_exists($xoopseditorclass)) { |
|
555 | + require_once $xoopseditorclass; |
|
556 | + $editor = new \XoopsFormEditor($caption, $form_editor, $editor_configs, $nohtml = false, $onfailure = 'textarea'); |
|
557 | + } else { |
|
558 | + switch ($form_editor) { |
|
559 | + |
|
560 | + case 'tiny': |
|
561 | + if (!$xoops22) { |
|
562 | + if (is_readable(XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php')) { |
|
563 | + require_once XOOPS_ROOT_PATH . '/class/xoopseditor/tinyeditor/formtinytextarea.php'; |
|
564 | + $editor = new \XoopsFormTinymce([ |
|
565 | + 'caption' => $caption, |
|
566 | + 'name' => $name, |
|
567 | + 'value' => $value, |
|
568 | + 'width' => '100%', |
|
569 | + 'height' => '300px' |
|
570 | + ], true); |
|
571 | + } else { |
|
572 | + if ($dhtml) { |
|
573 | + $editor = new \XoopsFormDhtmlTextArea($caption, $name, $value, 20, 60); |
|
574 | + } else { |
|
575 | + $editor = new \XoopsFormTextArea($caption, $name, $value, 7, 60); |
|
576 | + } |
|
577 | + } |
|
578 | + } else { |
|
579 | + $editor = new \XoopsFormEditor($caption, 'tinyeditor', $editor_configs); |
|
580 | + } |
|
581 | + break; |
|
582 | + |
|
583 | + case 'dhtmltextarea': |
|
584 | + case 'dhtmltext': |
|
585 | + $editor = new \XoopsFormDhtmlTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), 20, 60); |
|
586 | + if ($var['form_dsc']) { |
|
587 | + $editor->setDescription($var['form_dsc']); |
|
588 | + } |
|
589 | + break; |
|
590 | 590 | |
591 | 591 | // case 'inbetween': |
592 | 592 | // if (!$xoops22) { |
@@ -639,177 +639,177 @@ discard block |
||
639 | 639 | // } |
640 | 640 | // break; |
641 | 641 | |
642 | - default: |
|
643 | - case 'textarea': |
|
644 | - $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
645 | - $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
646 | - |
|
647 | - $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
648 | - if ($var['form_dsc']) { |
|
649 | - $editor->setDescription($var['form_dsc']); |
|
650 | - } |
|
651 | - break; |
|
652 | - |
|
653 | - } |
|
654 | - } |
|
655 | - |
|
656 | - return $editor; |
|
657 | - } |
|
658 | - |
|
659 | - /** |
|
660 | - * @param $key |
|
661 | - * @param $var |
|
662 | - * @param bool $multiple |
|
663 | - * @return \XoopsFormSelect |
|
664 | - */ |
|
665 | - public function getThemeSelect($key, $var, $multiple = false) |
|
666 | - { |
|
667 | - $size = $multiple ? 5 : 1; |
|
668 | - $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
669 | - |
|
670 | - $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
671 | - $dirlist = []; |
|
672 | - while (false !== ($file = readdir($handle))) { |
|
673 | - if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
674 | - && 'cvs' !== strtolower($file)) { |
|
675 | - $dirlist[$file] = $file; |
|
676 | - } |
|
677 | - } |
|
678 | - closedir($handle); |
|
679 | - if (!empty($dirlist)) { |
|
680 | - asort($dirlist); |
|
681 | - $theme_select->addOptionArray($dirlist); |
|
682 | - } |
|
683 | - |
|
684 | - return $theme_select; |
|
685 | - } |
|
686 | - |
|
687 | - /** |
|
688 | - * @param $keyname |
|
689 | - * @return bool |
|
690 | - */ |
|
691 | - public function &getElementById($keyname) |
|
692 | - { |
|
693 | - foreach ($this->_elements as $eleObj) { |
|
694 | - if ($eleObj->getName() == $keyname) { |
|
695 | - $ret =& $eleObj; |
|
696 | - break; |
|
697 | - } |
|
698 | - } |
|
699 | - |
|
700 | - return isset($ret) ? $ret : false; |
|
701 | - } |
|
702 | - |
|
703 | - /** |
|
704 | - * create HTML to output the form as a theme-enabled table with validation. |
|
705 | - * |
|
706 | - * @return string |
|
707 | - */ |
|
708 | - public function render() |
|
709 | - { |
|
710 | - $required = $this->getRequired(); |
|
711 | - $ret = " |
|
642 | + default: |
|
643 | + case 'textarea': |
|
644 | + $form_rows = isset($control['rows']) ? $control['rows'] : 5; |
|
645 | + $form_cols = isset($control['cols']) ? $control['cols'] : 60; |
|
646 | + |
|
647 | + $editor = new \XoopsFormTextArea($var['form_caption'], $key, $this->targetObject->getVar($key, 'e'), $form_rows, $form_cols); |
|
648 | + if ($var['form_dsc']) { |
|
649 | + $editor->setDescription($var['form_dsc']); |
|
650 | + } |
|
651 | + break; |
|
652 | + |
|
653 | + } |
|
654 | + } |
|
655 | + |
|
656 | + return $editor; |
|
657 | + } |
|
658 | + |
|
659 | + /** |
|
660 | + * @param $key |
|
661 | + * @param $var |
|
662 | + * @param bool $multiple |
|
663 | + * @return \XoopsFormSelect |
|
664 | + */ |
|
665 | + public function getThemeSelect($key, $var, $multiple = false) |
|
666 | + { |
|
667 | + $size = $multiple ? 5 : 1; |
|
668 | + $theme_select = new \XoopsFormSelect($var['form_caption'], $key, $this->targetObject->getVar($key), $size, $multiple); |
|
669 | + |
|
670 | + $handle = opendir(XOOPS_THEME_PATH . '/'); |
|
671 | + $dirlist = []; |
|
672 | + while (false !== ($file = readdir($handle))) { |
|
673 | + if (is_dir(XOOPS_THEME_PATH . '/' . $file) && !preg_match('/^[.]{1,2}$/', $file) |
|
674 | + && 'cvs' !== strtolower($file)) { |
|
675 | + $dirlist[$file] = $file; |
|
676 | + } |
|
677 | + } |
|
678 | + closedir($handle); |
|
679 | + if (!empty($dirlist)) { |
|
680 | + asort($dirlist); |
|
681 | + $theme_select->addOptionArray($dirlist); |
|
682 | + } |
|
683 | + |
|
684 | + return $theme_select; |
|
685 | + } |
|
686 | + |
|
687 | + /** |
|
688 | + * @param $keyname |
|
689 | + * @return bool |
|
690 | + */ |
|
691 | + public function &getElementById($keyname) |
|
692 | + { |
|
693 | + foreach ($this->_elements as $eleObj) { |
|
694 | + if ($eleObj->getName() == $keyname) { |
|
695 | + $ret =& $eleObj; |
|
696 | + break; |
|
697 | + } |
|
698 | + } |
|
699 | + |
|
700 | + return isset($ret) ? $ret : false; |
|
701 | + } |
|
702 | + |
|
703 | + /** |
|
704 | + * create HTML to output the form as a theme-enabled table with validation. |
|
705 | + * |
|
706 | + * @return string |
|
707 | + */ |
|
708 | + public function render() |
|
709 | + { |
|
710 | + $required = $this->getRequired(); |
|
711 | + $ret = " |
|
712 | 712 | <form name='" . $this->getName() . "' id='" . $this->getName() . "' action='" . $this->getAction() . "' method='" . $this->getMethod() . "' onsubmit='return xoopsFormValidate_" . $this->getName() . "(this);'" . $this->getExtra() . "> |
713 | 713 | <table width='100%' class='outer' cellspacing='1'> |
714 | 714 | <tr><th colspan='2'>" . $this->getTitle() . '</th></tr> |
715 | 715 | '; |
716 | - $hidden = ''; |
|
717 | - $class = 'even'; |
|
718 | - foreach ($this->getElements() as $ele) { |
|
719 | - if (!is_object($ele)) { |
|
720 | - $ret .= $ele; |
|
721 | - } elseif (!$ele->isHidden()) { |
|
722 | - //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
723 | - $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
724 | - if ('' !== $ele->getDescription()) { |
|
725 | - $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
726 | - } |
|
727 | - $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
728 | - } else { |
|
729 | - $hidden .= $ele->render(); |
|
730 | - } |
|
731 | - } |
|
732 | - $ret .= "</table>\n$hidden\n</form>\n"; |
|
733 | - $ret .= $this->renderValidationJS(true); |
|
734 | - |
|
735 | - return $ret; |
|
736 | - } |
|
737 | - |
|
738 | - /** |
|
739 | - * assign to smarty form template instead of displaying directly |
|
740 | - * |
|
741 | - * @param \XoopsTpl $tpl |
|
742 | - * |
|
743 | - * object |
|
744 | - * @param bool $smartyName |
|
745 | - * @see Smarty |
|
746 | - */ |
|
747 | - public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
748 | - { |
|
749 | - $i = 0; |
|
750 | - $elements = []; |
|
751 | - foreach ($this->getElements() as $ele) { |
|
752 | - $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
753 | - $elements[$n]['name'] = $ele->getName(); |
|
754 | - $elements[$n]['caption'] = $ele->getCaption(); |
|
755 | - $elements[$n]['body'] = $ele->render(); |
|
756 | - $elements[$n]['hidden'] = $ele->isHidden(); |
|
757 | - $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
758 | - $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
759 | - $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
760 | - if ('' !== $ele->getDescription()) { |
|
761 | - $elements[$n]['description'] = $ele->getDescription(); |
|
762 | - } |
|
763 | - ++$i; |
|
764 | - } |
|
765 | - $js = $this->renderValidationJS(); |
|
766 | - if (!$smartyName) { |
|
767 | - $smartyName = $this->getName(); |
|
768 | - } |
|
769 | - |
|
770 | - $tpl->assign($smartyName, [ |
|
771 | - 'title' => $this->getTitle(), |
|
772 | - 'name' => $this->getName(), |
|
773 | - 'action' => $this->getAction(), |
|
774 | - 'method' => $this->getMethod(), |
|
775 | - 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
776 | - 'javascript' => $js, |
|
777 | - 'elements' => $elements |
|
778 | - ]); |
|
779 | - } |
|
780 | - |
|
781 | - /** |
|
782 | - * @param bool $withtags |
|
783 | - * @return string |
|
784 | - */ |
|
785 | - public function renderValidationJS($withtags = true) |
|
786 | - { |
|
787 | - $js = ''; |
|
788 | - if ($withtags) { |
|
789 | - $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
790 | - } |
|
791 | - $myts = \MyTextSanitizer::getInstance(); |
|
792 | - $formname = $this->getName(); |
|
793 | - $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
794 | - // First, output code to check required elements |
|
795 | - $elements = $this->getRequired(); |
|
796 | - foreach ($elements as $elt) { |
|
797 | - $eltname = $elt->getName(); |
|
798 | - $eltcaption = trim($elt->getCaption()); |
|
799 | - $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
800 | - $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
801 | - if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
802 | - $js .= 'var myOption = -1;'; |
|
803 | - $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
716 | + $hidden = ''; |
|
717 | + $class = 'even'; |
|
718 | + foreach ($this->getElements() as $ele) { |
|
719 | + if (!is_object($ele)) { |
|
720 | + $ret .= $ele; |
|
721 | + } elseif (!$ele->isHidden()) { |
|
722 | + //$class = ( $class == 'even' ) ? 'odd': 'even'; |
|
723 | + $ret .= "<tr id='" . $ele->getName() . "' valign='top' align='left'><td class='head'>" . $ele->getCaption(); |
|
724 | + if ('' !== $ele->getDescription()) { |
|
725 | + $ret .= '<br><br><span style="font-weight: normal;">' . $ele->getDescription() . '</span>'; |
|
726 | + } |
|
727 | + $ret .= "</td><td class='$class'>" . $ele->render() . "</td></tr>\n"; |
|
728 | + } else { |
|
729 | + $hidden .= $ele->render(); |
|
730 | + } |
|
731 | + } |
|
732 | + $ret .= "</table>\n$hidden\n</form>\n"; |
|
733 | + $ret .= $this->renderValidationJS(true); |
|
734 | + |
|
735 | + return $ret; |
|
736 | + } |
|
737 | + |
|
738 | + /** |
|
739 | + * assign to smarty form template instead of displaying directly |
|
740 | + * |
|
741 | + * @param \XoopsTpl $tpl |
|
742 | + * |
|
743 | + * object |
|
744 | + * @param bool $smartyName |
|
745 | + * @see Smarty |
|
746 | + */ |
|
747 | + public function assign(\XoopsTpl $tpl, $smartyName = false) |
|
748 | + { |
|
749 | + $i = 0; |
|
750 | + $elements = []; |
|
751 | + foreach ($this->getElements() as $ele) { |
|
752 | + $n = ('' !== $ele->getName()) ? $ele->getName() : $i; |
|
753 | + $elements[$n]['name'] = $ele->getName(); |
|
754 | + $elements[$n]['caption'] = $ele->getCaption(); |
|
755 | + $elements[$n]['body'] = $ele->render(); |
|
756 | + $elements[$n]['hidden'] = $ele->isHidden(); |
|
757 | + $elements[$n]['section'] = strtolower(get_class($ele)) == strtolower('SmartFormSection'); |
|
758 | + $elements[$n]['section_close'] = $ele instanceof \XoopsModules\Smartobject\Form\Elements\SmartFormSectionClose; |
|
759 | + $elements[$n]['hide'] = isset($this->targetObject->vars[$n]['hide']) ? $this->targetObject->vars[$n]['hide'] : false; |
|
760 | + if ('' !== $ele->getDescription()) { |
|
761 | + $elements[$n]['description'] = $ele->getDescription(); |
|
762 | + } |
|
763 | + ++$i; |
|
764 | + } |
|
765 | + $js = $this->renderValidationJS(); |
|
766 | + if (!$smartyName) { |
|
767 | + $smartyName = $this->getName(); |
|
768 | + } |
|
769 | + |
|
770 | + $tpl->assign($smartyName, [ |
|
771 | + 'title' => $this->getTitle(), |
|
772 | + 'name' => $this->getName(), |
|
773 | + 'action' => $this->getAction(), |
|
774 | + 'method' => $this->getMethod(), |
|
775 | + 'extra' => 'onsubmit="return xoopsFormValidate_' . $this->getName() . '(this);"' . $this->getExtra(), |
|
776 | + 'javascript' => $js, |
|
777 | + 'elements' => $elements |
|
778 | + ]); |
|
779 | + } |
|
780 | + |
|
781 | + /** |
|
782 | + * @param bool $withtags |
|
783 | + * @return string |
|
784 | + */ |
|
785 | + public function renderValidationJS($withtags = true) |
|
786 | + { |
|
787 | + $js = ''; |
|
788 | + if ($withtags) { |
|
789 | + $js .= "\n<!-- Start Form Validation JavaScript //-->\n<script type='text/javascript'>\n<!--//\n"; |
|
790 | + } |
|
791 | + $myts = \MyTextSanitizer::getInstance(); |
|
792 | + $formname = $this->getName(); |
|
793 | + $js .= "function xoopsFormValidate_{$formname}(myform) {"; |
|
794 | + // First, output code to check required elements |
|
795 | + $elements = $this->getRequired(); |
|
796 | + foreach ($elements as $elt) { |
|
797 | + $eltname = $elt->getName(); |
|
798 | + $eltcaption = trim($elt->getCaption()); |
|
799 | + $eltmsg = empty($eltcaption) ? sprintf(_FORM_ENTER, $eltname) : sprintf(_FORM_ENTER, $eltcaption); |
|
800 | + $eltmsg = str_replace('"', '\"', stripslashes($eltmsg)); |
|
801 | + if ('xoopsformradio' === strtolower(get_class($elt))) { |
|
802 | + $js .= 'var myOption = -1;'; |
|
803 | + $js .= "for (i=myform.{$eltname}.length-1; i > -1; i--) { |
|
804 | 804 | if (myform.{$eltname}[i].checked) { |
805 | 805 | myOption = i; i = -1; |
806 | 806 | } |
807 | 807 | } |
808 | 808 | if (myOption == -1) { |
809 | 809 | window.alert(\"{$eltmsg}\"); myform.{$eltname}[0].focus(); return false; }\n"; |
810 | - } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
811 | - $js .= 'var hasSelections = false;'; |
|
812 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
810 | + } elseif ('smartformselect_multielement' === strtolower(get_class($elt))) { |
|
811 | + $js .= 'var hasSelections = false;'; |
|
812 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
813 | 813 | if (myform['{$eltname}[]'].options[i].selected) { |
814 | 814 | hasSelections = true; |
815 | 815 | } |
@@ -817,12 +817,12 @@ discard block |
||
817 | 817 | } |
818 | 818 | if (hasSelections === false) { |
819 | 819 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'].options[0].focus(); return false; }\n"; |
820 | - } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
821 | - || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
822 | - $js .= 'var hasSelections = false;'; |
|
823 | - //sometimes, there is an implicit '[]', sometimes not |
|
824 | - if (false === strpos($eltname, '[')) { |
|
825 | - $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
820 | + } elseif ('xoopsformcheckbox' === strtolower(get_class($elt)) |
|
821 | + || 'smartformcheckelement' === strtolower(get_class($elt))) { |
|
822 | + $js .= 'var hasSelections = false;'; |
|
823 | + //sometimes, there is an implicit '[]', sometimes not |
|
824 | + if (false === strpos($eltname, '[')) { |
|
825 | + $js .= "for (var i = 0; i < myform['{$eltname}[]'].length; i++) { |
|
826 | 826 | if (myform['{$eltname}[]'][i].checked) { |
827 | 827 | hasSelections = true; |
828 | 828 | } |
@@ -830,8 +830,8 @@ discard block |
||
830 | 830 | } |
831 | 831 | if (hasSelections === false) { |
832 | 832 | window.alert(\"{$eltmsg}\"); myform['{$eltname}[]'][0].focus(); return false; }\n"; |
833 | - } else { |
|
834 | - $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
833 | + } else { |
|
834 | + $js .= "for (var i = 0; i < myform['{$eltname}'].length; i++) { |
|
835 | 835 | if (myform['{$eltname}'][i].checked) { |
836 | 836 | hasSelections = true; |
837 | 837 | } |
@@ -839,25 +839,25 @@ discard block |
||
839 | 839 | } |
840 | 840 | if (hasSelections === false) { |
841 | 841 | window.alert(\"{$eltmsg}\"); myform['{$eltname}'][0].focus(); return false; }\n"; |
842 | - } |
|
843 | - } else { |
|
844 | - $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
845 | - } |
|
846 | - } |
|
847 | - // Now, handle custom validation code |
|
848 | - $elements =& $this->getElements(true); |
|
849 | - foreach ($elements as $elt) { |
|
850 | - if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
851 | - if ($eltjs = $elt->renderValidationJS()) { |
|
852 | - $js .= $eltjs . "\n"; |
|
853 | - } |
|
854 | - } |
|
855 | - } |
|
856 | - $js .= "return true;\n}\n"; |
|
857 | - if ($withtags) { |
|
858 | - $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
859 | - } |
|
860 | - |
|
861 | - return $js; |
|
862 | - } |
|
842 | + } |
|
843 | + } else { |
|
844 | + $js .= "if ( myform.{$eltname}.value == \"\" ) " . "{ window.alert(\"{$eltmsg}\"); myform.{$eltname}.focus(); return false; }\n"; |
|
845 | + } |
|
846 | + } |
|
847 | + // Now, handle custom validation code |
|
848 | + $elements =& $this->getElements(true); |
|
849 | + foreach ($elements as $elt) { |
|
850 | + if (method_exists($elt, 'renderValidationJS') && 'xoopsformcheckbox' !== strtolower(get_class($elt))) { |
|
851 | + if ($eltjs = $elt->renderValidationJS()) { |
|
852 | + $js .= $eltjs . "\n"; |
|
853 | + } |
|
854 | + } |
|
855 | + } |
|
856 | + $js .= "return true;\n}\n"; |
|
857 | + if ($withtags) { |
|
858 | + $js .= "//--></script>\n<!-- 'End Form Validation JavaScript' //-->\n"; |
|
859 | + } |
|
860 | + |
|
861 | + return $js; |
|
862 | + } |
|
863 | 863 | } |
@@ -196,7 +196,7 @@ |
||
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
199 | - * @param $name |
|
199 | + * @param string $name |
|
200 | 200 | * @param string $extension |
201 | 201 | * @return array |
202 | 202 | */ |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | $xoopsLogger->activated = false; |
11 | 11 | |
12 | 12 | if (empty(Request::getString('HTTP_REFERER', '', 'SERVER')) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', Request::getString('HTTP_REFERER', '', 'SERVER'))) { |
13 | - exit(); |
|
13 | + exit(); |
|
14 | 14 | } |
15 | 15 | |
16 | 16 | /** |
@@ -18,192 +18,192 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class XoopsCaptchaImageHandler |
20 | 20 | { |
21 | - public $config = []; |
|
22 | - //var $mode = "gd"; // GD or bmp |
|
23 | - public $code; |
|
24 | - public $invalid = false; |
|
25 | - |
|
26 | - public $font; |
|
27 | - public $spacing; |
|
28 | - public $width; |
|
29 | - public $height; |
|
30 | - |
|
31 | - /** |
|
32 | - * XoopsCaptchaImageHandler constructor. |
|
33 | - */ |
|
34 | - public function __construct() |
|
35 | - { |
|
36 | - if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
37 | - $this->invalid = true; |
|
38 | - } |
|
39 | - |
|
40 | - if (!extension_loaded('gd')) { |
|
41 | - $this->mode = 'bmp'; |
|
42 | - } else { |
|
43 | - $required_functions = [ |
|
44 | - 'imagecreatetruecolor', |
|
45 | - 'imagecolorallocate', |
|
46 | - 'imagefilledrectangle', |
|
47 | - 'imagejpeg', |
|
48 | - 'imagedestroy', |
|
49 | - 'imageftbbox' |
|
50 | - ]; |
|
51 | - foreach ($required_functions as $func) { |
|
52 | - if (!function_exists($func)) { |
|
53 | - $this->mode = 'bmp'; |
|
54 | - break; |
|
55 | - } |
|
56 | - } |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Loading configs from CAPTCHA class |
|
62 | - * @param array $config |
|
63 | - */ |
|
64 | - public function setConfig($config = []) |
|
65 | - { |
|
66 | - // Loading default preferences |
|
67 | - $this->config = $config; |
|
68 | - } |
|
69 | - |
|
70 | - public function loadImage() |
|
71 | - { |
|
72 | - $this->createCode(); |
|
73 | - $this->setCode(); |
|
74 | - $this->createImage(); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Create Code |
|
79 | - */ |
|
80 | - public function createCode() |
|
81 | - { |
|
82 | - if ($this->invalid) { |
|
83 | - return; |
|
84 | - } |
|
85 | - |
|
86 | - if ('bmp' === $this->mode) { |
|
87 | - $this->config['num_chars'] = 4; |
|
88 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
89 | - } else { |
|
90 | - $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
91 | - if (!$this->config['casesensitive']) { |
|
92 | - $this->code = strtoupper($this->code); |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - public function setCode() |
|
98 | - { |
|
99 | - if ($this->invalid) { |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
104 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
105 | - |
|
106 | - // Increase the attempt records on refresh |
|
107 | - if (!empty($maxAttempts)) { |
|
108 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
109 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
110 | - $this->invalid = true; |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $file |
|
117 | - * @return string|void |
|
118 | - */ |
|
119 | - public function createImage($file = '') |
|
120 | - { |
|
121 | - if ($this->invalid) { |
|
122 | - header('Content-type: image/gif'); |
|
123 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
124 | - |
|
125 | - return; |
|
126 | - } |
|
127 | - |
|
128 | - if ('bmp' === $this->mode) { |
|
129 | - return $this->createImageBmp(); |
|
130 | - } else { |
|
131 | - return $this->createImageGd(); |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Create CAPTCHA iamge with GD |
|
137 | - * Originated from DuGris' SecurityImage |
|
138 | - * @param string $file |
|
139 | - */ |
|
140 | - // --------------------------------------------------------------------------- // |
|
141 | - // Class: SecurityImage 1.5 // |
|
142 | - // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
143 | - // Email: [email protected] // |
|
144 | - // Licence: GNU // |
|
145 | - // Project: XOOPS Project // |
|
146 | - // --------------------------------------------------------------------------- // |
|
147 | - public function createImageGd($file = '') |
|
148 | - { |
|
149 | - $this->loadFont(); |
|
150 | - $this->setImageSize(); |
|
151 | - |
|
152 | - $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
153 | - $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
154 | - imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
155 | - |
|
156 | - switch ($this->config['background_type']) { |
|
157 | - default: |
|
158 | - case 0: |
|
159 | - $this->drawBars(); |
|
160 | - break; |
|
161 | - |
|
162 | - case 1: |
|
163 | - $this->drawCircles(); |
|
164 | - break; |
|
165 | - |
|
166 | - case 2: |
|
167 | - $this->drawLines(); |
|
168 | - break; |
|
169 | - |
|
170 | - case 3: |
|
171 | - $this->drawRectangles(); |
|
172 | - break; |
|
173 | - |
|
174 | - case 4: |
|
175 | - $this->drawEllipses(); |
|
176 | - break; |
|
177 | - |
|
178 | - case 5: |
|
179 | - $this->drawPolygons(); |
|
180 | - break; |
|
181 | - |
|
182 | - case 100: |
|
183 | - $this->createFromFile(); |
|
184 | - break; |
|
185 | - } |
|
186 | - $this->drawBorder(); |
|
187 | - $this->drawCode(); |
|
188 | - |
|
189 | - if (empty($file)) { |
|
190 | - header('Content-type: image/jpeg'); |
|
191 | - imagejpeg($this->oImage); |
|
192 | - } else { |
|
193 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
194 | - } |
|
195 | - imagedestroy($this->oImage); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * @param $name |
|
200 | - * @param string $extension |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public function _getList($name, $extension = '') |
|
204 | - { |
|
205 | - $items = []; |
|
206 | - /* |
|
21 | + public $config = []; |
|
22 | + //var $mode = "gd"; // GD or bmp |
|
23 | + public $code; |
|
24 | + public $invalid = false; |
|
25 | + |
|
26 | + public $font; |
|
27 | + public $spacing; |
|
28 | + public $width; |
|
29 | + public $height; |
|
30 | + |
|
31 | + /** |
|
32 | + * XoopsCaptchaImageHandler constructor. |
|
33 | + */ |
|
34 | + public function __construct() |
|
35 | + { |
|
36 | + if (empty($_SESSION['XoopsCaptcha_name'])) { |
|
37 | + $this->invalid = true; |
|
38 | + } |
|
39 | + |
|
40 | + if (!extension_loaded('gd')) { |
|
41 | + $this->mode = 'bmp'; |
|
42 | + } else { |
|
43 | + $required_functions = [ |
|
44 | + 'imagecreatetruecolor', |
|
45 | + 'imagecolorallocate', |
|
46 | + 'imagefilledrectangle', |
|
47 | + 'imagejpeg', |
|
48 | + 'imagedestroy', |
|
49 | + 'imageftbbox' |
|
50 | + ]; |
|
51 | + foreach ($required_functions as $func) { |
|
52 | + if (!function_exists($func)) { |
|
53 | + $this->mode = 'bmp'; |
|
54 | + break; |
|
55 | + } |
|
56 | + } |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Loading configs from CAPTCHA class |
|
62 | + * @param array $config |
|
63 | + */ |
|
64 | + public function setConfig($config = []) |
|
65 | + { |
|
66 | + // Loading default preferences |
|
67 | + $this->config = $config; |
|
68 | + } |
|
69 | + |
|
70 | + public function loadImage() |
|
71 | + { |
|
72 | + $this->createCode(); |
|
73 | + $this->setCode(); |
|
74 | + $this->createImage(); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Create Code |
|
79 | + */ |
|
80 | + public function createCode() |
|
81 | + { |
|
82 | + if ($this->invalid) { |
|
83 | + return; |
|
84 | + } |
|
85 | + |
|
86 | + if ('bmp' === $this->mode) { |
|
87 | + $this->config['num_chars'] = 4; |
|
88 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
89 | + } else { |
|
90 | + $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
|
91 | + if (!$this->config['casesensitive']) { |
|
92 | + $this->code = strtoupper($this->code); |
|
93 | + } |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + public function setCode() |
|
98 | + { |
|
99 | + if ($this->invalid) { |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
104 | + $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
105 | + |
|
106 | + // Increase the attempt records on refresh |
|
107 | + if (!empty($maxAttempts)) { |
|
108 | + $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
109 | + if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
110 | + $this->invalid = true; |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $file |
|
117 | + * @return string|void |
|
118 | + */ |
|
119 | + public function createImage($file = '') |
|
120 | + { |
|
121 | + if ($this->invalid) { |
|
122 | + header('Content-type: image/gif'); |
|
123 | + readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
124 | + |
|
125 | + return; |
|
126 | + } |
|
127 | + |
|
128 | + if ('bmp' === $this->mode) { |
|
129 | + return $this->createImageBmp(); |
|
130 | + } else { |
|
131 | + return $this->createImageGd(); |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Create CAPTCHA iamge with GD |
|
137 | + * Originated from DuGris' SecurityImage |
|
138 | + * @param string $file |
|
139 | + */ |
|
140 | + // --------------------------------------------------------------------------- // |
|
141 | + // Class: SecurityImage 1.5 // |
|
142 | + // Author: DuGris aka L. Jen <http://www.dugris.info> // |
|
143 | + // Email: [email protected] // |
|
144 | + // Licence: GNU // |
|
145 | + // Project: XOOPS Project // |
|
146 | + // --------------------------------------------------------------------------- // |
|
147 | + public function createImageGd($file = '') |
|
148 | + { |
|
149 | + $this->loadFont(); |
|
150 | + $this->setImageSize(); |
|
151 | + |
|
152 | + $this->oImage = imagecreatetruecolor($this->width, $this->height); |
|
153 | + $background = imagecolorallocate($this->oImage, 255, 255, 255); |
|
154 | + imagefilledrectangle($this->oImage, 0, 0, $this->width, $this->height, $background); |
|
155 | + |
|
156 | + switch ($this->config['background_type']) { |
|
157 | + default: |
|
158 | + case 0: |
|
159 | + $this->drawBars(); |
|
160 | + break; |
|
161 | + |
|
162 | + case 1: |
|
163 | + $this->drawCircles(); |
|
164 | + break; |
|
165 | + |
|
166 | + case 2: |
|
167 | + $this->drawLines(); |
|
168 | + break; |
|
169 | + |
|
170 | + case 3: |
|
171 | + $this->drawRectangles(); |
|
172 | + break; |
|
173 | + |
|
174 | + case 4: |
|
175 | + $this->drawEllipses(); |
|
176 | + break; |
|
177 | + |
|
178 | + case 5: |
|
179 | + $this->drawPolygons(); |
|
180 | + break; |
|
181 | + |
|
182 | + case 100: |
|
183 | + $this->createFromFile(); |
|
184 | + break; |
|
185 | + } |
|
186 | + $this->drawBorder(); |
|
187 | + $this->drawCode(); |
|
188 | + |
|
189 | + if (empty($file)) { |
|
190 | + header('Content-type: image/jpeg'); |
|
191 | + imagejpeg($this->oImage); |
|
192 | + } else { |
|
193 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
194 | + } |
|
195 | + imagedestroy($this->oImage); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * @param $name |
|
200 | + * @param string $extension |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public function _getList($name, $extension = '') |
|
204 | + { |
|
205 | + $items = []; |
|
206 | + /* |
|
207 | 207 | if (@ require_once XOOPS_ROOT_PATH."/Frameworks/art/functions.ini.php") { |
208 | 208 | load_functions("cache"); |
209 | 209 | if ($items = mod_loadCacheFile("captcha_{$name}", "captcha")) { |
@@ -211,231 +211,231 @@ discard block |
||
211 | 211 | } |
212 | 212 | } |
213 | 213 | */ |
214 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
215 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
216 | - $files = XoopsLists::getFileListAsArray($file_path); |
|
217 | - foreach ($files as $item) { |
|
218 | - if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
219 | - $items[] = $item; |
|
220 | - } |
|
221 | - } |
|
222 | - if (function_exists('mod_createCacheFile')) { |
|
223 | - mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
224 | - } |
|
225 | - |
|
226 | - return $items; |
|
227 | - } |
|
228 | - |
|
229 | - public function loadFont() |
|
230 | - { |
|
231 | - $fonts = $this->_getList('fonts', 'ttf'); |
|
232 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
233 | - } |
|
234 | - |
|
235 | - public function setImageSize() |
|
236 | - { |
|
237 | - $MaxCharWidth = 0; |
|
238 | - $MaxCharHeight = 0; |
|
239 | - $oImage = imagecreatetruecolor(100, 100); |
|
240 | - $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
241 | - $FontSize = $this->config['fontsize_max']; |
|
242 | - for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
243 | - for ($i = 65; $i <= 90; ++$i) { |
|
244 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), []); |
|
245 | - $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
246 | - if ($_MaxCharWidth > $MaxCharWidth) { |
|
247 | - $MaxCharWidth = $_MaxCharWidth; |
|
248 | - } |
|
249 | - $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
250 | - if ($_MaxCharHeight > $MaxCharHeight) { |
|
251 | - $MaxCharHeight = $_MaxCharHeight; |
|
252 | - } |
|
253 | - } |
|
254 | - } |
|
255 | - imagedestroy($oImage); |
|
256 | - |
|
257 | - $this->height = $MaxCharHeight + 2; |
|
258 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
259 | - $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Return random background |
|
264 | - * |
|
265 | - * @return null|string |
|
266 | - */ |
|
267 | - public function loadBackground() |
|
268 | - { |
|
269 | - $RandBackground = null; |
|
270 | - if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
271 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
272 | - } |
|
273 | - |
|
274 | - return $RandBackground; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Draw Image background |
|
279 | - */ |
|
280 | - public function createFromFile() |
|
281 | - { |
|
282 | - if ($RandImage = $this->loadBackground()) { |
|
283 | - $ImageType = @getimagesize($RandImage); |
|
284 | - switch (@$ImageType[2]) { |
|
285 | - case 1: |
|
286 | - $BackgroundImage = imagecreatefromgif($RandImage); |
|
287 | - break; |
|
288 | - |
|
289 | - case 2: |
|
290 | - $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
291 | - break; |
|
292 | - |
|
293 | - case 3: |
|
294 | - $BackgroundImage = imagecreatefrompng($RandImage); |
|
295 | - break; |
|
296 | - } |
|
297 | - } |
|
298 | - if (!empty($BackgroundImage)) { |
|
299 | - imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
300 | - imagedestroy($BackgroundImage); |
|
301 | - } else { |
|
302 | - $this->drawBars(); |
|
303 | - } |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Draw Code |
|
308 | - */ |
|
309 | - public function drawCode() |
|
310 | - { |
|
311 | - for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
312 | - // select random greyscale colour |
|
313 | - $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
314 | - |
|
315 | - // write text to image |
|
316 | - $Angle = mt_rand(10, 30); |
|
317 | - if ($i % 2) { |
|
318 | - $Angle = mt_rand(-10, -30); |
|
319 | - } |
|
320 | - |
|
321 | - // select random font size |
|
322 | - $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
323 | - |
|
324 | - $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []); |
|
325 | - $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
326 | - |
|
327 | - // calculate character starting coordinates |
|
328 | - $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
329 | - $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
330 | - |
|
331 | - imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Draw Border |
|
337 | - */ |
|
338 | - public function drawBorder() |
|
339 | - { |
|
340 | - $rgb = mt_rand(50, 150); |
|
341 | - $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
342 | - imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Draw Circles background |
|
347 | - */ |
|
348 | - public function drawCircles() |
|
349 | - { |
|
350 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
351 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
352 | - imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
353 | - } |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * Draw Lines background |
|
358 | - */ |
|
359 | - public function drawLines() |
|
360 | - { |
|
361 | - for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
362 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
363 | - imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Draw Rectangles background |
|
369 | - */ |
|
370 | - public function drawRectangles() |
|
371 | - { |
|
372 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
373 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
374 | - imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
375 | - } |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Draw Bars background |
|
380 | - */ |
|
381 | - public function drawBars() |
|
382 | - { |
|
383 | - for ($i = 0; $i <= $this->height;) { |
|
384 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
385 | - imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
386 | - $i += 2.5; |
|
387 | - } |
|
388 | - for ($i = 0; $i <= $this->width;) { |
|
389 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
390 | - imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
391 | - $i += 2.5; |
|
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Draw Ellipses background |
|
397 | - */ |
|
398 | - public function drawEllipses() |
|
399 | - { |
|
400 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
401 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
402 | - imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
403 | - } |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Draw polygons background |
|
408 | - */ |
|
409 | - public function drawPolygons() |
|
410 | - { |
|
411 | - for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
412 | - $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
413 | - $coords = []; |
|
414 | - for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
415 | - $coords[] = mt_rand(0, $this->width); |
|
416 | - $coords[] = mt_rand(0, $this->height); |
|
417 | - } |
|
418 | - imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
419 | - } |
|
420 | - } |
|
421 | - |
|
422 | - /** |
|
423 | - * Create CAPTCHA iamge with BMP |
|
424 | - * TODO |
|
425 | - * @param string $file |
|
426 | - * @return string |
|
427 | - */ |
|
428 | - public function createImageBmp($file = '') |
|
429 | - { |
|
430 | - $image = ''; |
|
431 | - |
|
432 | - if (empty($file)) { |
|
433 | - header('Content-type: image/bmp'); |
|
434 | - echo $image; |
|
435 | - } else { |
|
436 | - return $image; |
|
437 | - } |
|
438 | - } |
|
214 | + require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
215 | + $file_path = $this->config['rootpath'] . "/{$name}"; |
|
216 | + $files = XoopsLists::getFileListAsArray($file_path); |
|
217 | + foreach ($files as $item) { |
|
218 | + if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
|
219 | + $items[] = $item; |
|
220 | + } |
|
221 | + } |
|
222 | + if (function_exists('mod_createCacheFile')) { |
|
223 | + mod_createCacheFile($items, "captcha_{$name}", 'captcha'); |
|
224 | + } |
|
225 | + |
|
226 | + return $items; |
|
227 | + } |
|
228 | + |
|
229 | + public function loadFont() |
|
230 | + { |
|
231 | + $fonts = $this->_getList('fonts', 'ttf'); |
|
232 | + $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
233 | + } |
|
234 | + |
|
235 | + public function setImageSize() |
|
236 | + { |
|
237 | + $MaxCharWidth = 0; |
|
238 | + $MaxCharHeight = 0; |
|
239 | + $oImage = imagecreatetruecolor(100, 100); |
|
240 | + $text_color = imagecolorallocate($oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
241 | + $FontSize = $this->config['fontsize_max']; |
|
242 | + for ($Angle = -30; $Angle <= 30; ++$Angle) { |
|
243 | + for ($i = 65; $i <= 90; ++$i) { |
|
244 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, chr($i), []); |
|
245 | + $_MaxCharWidth = abs($CharDetails[0] + $CharDetails[2]); |
|
246 | + if ($_MaxCharWidth > $MaxCharWidth) { |
|
247 | + $MaxCharWidth = $_MaxCharWidth; |
|
248 | + } |
|
249 | + $_MaxCharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
250 | + if ($_MaxCharHeight > $MaxCharHeight) { |
|
251 | + $MaxCharHeight = $_MaxCharHeight; |
|
252 | + } |
|
253 | + } |
|
254 | + } |
|
255 | + imagedestroy($oImage); |
|
256 | + |
|
257 | + $this->height = $MaxCharHeight + 2; |
|
258 | + $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
259 | + $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Return random background |
|
264 | + * |
|
265 | + * @return null|string |
|
266 | + */ |
|
267 | + public function loadBackground() |
|
268 | + { |
|
269 | + $RandBackground = null; |
|
270 | + if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
|
271 | + $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
272 | + } |
|
273 | + |
|
274 | + return $RandBackground; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Draw Image background |
|
279 | + */ |
|
280 | + public function createFromFile() |
|
281 | + { |
|
282 | + if ($RandImage = $this->loadBackground()) { |
|
283 | + $ImageType = @getimagesize($RandImage); |
|
284 | + switch (@$ImageType[2]) { |
|
285 | + case 1: |
|
286 | + $BackgroundImage = imagecreatefromgif($RandImage); |
|
287 | + break; |
|
288 | + |
|
289 | + case 2: |
|
290 | + $BackgroundImage = imagecreatefromjpeg($RandImage); |
|
291 | + break; |
|
292 | + |
|
293 | + case 3: |
|
294 | + $BackgroundImage = imagecreatefrompng($RandImage); |
|
295 | + break; |
|
296 | + } |
|
297 | + } |
|
298 | + if (!empty($BackgroundImage)) { |
|
299 | + imagecopyresized($this->oImage, $BackgroundImage, 0, 0, 0, 0, imagesx($this->oImage), imagesy($this->oImage), imagesx($BackgroundImage), imagesy($BackgroundImage)); |
|
300 | + imagedestroy($BackgroundImage); |
|
301 | + } else { |
|
302 | + $this->drawBars(); |
|
303 | + } |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Draw Code |
|
308 | + */ |
|
309 | + public function drawCode() |
|
310 | + { |
|
311 | + for ($i = 0; $i < $this->config['num_chars']; ++$i) { |
|
312 | + // select random greyscale colour |
|
313 | + $text_color = imagecolorallocate($this->oImage, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); |
|
314 | + |
|
315 | + // write text to image |
|
316 | + $Angle = mt_rand(10, 30); |
|
317 | + if ($i % 2) { |
|
318 | + $Angle = mt_rand(-10, -30); |
|
319 | + } |
|
320 | + |
|
321 | + // select random font size |
|
322 | + $FontSize = mt_rand($this->config['fontsize_min'], $this->config['fontsize_max']); |
|
323 | + |
|
324 | + $CharDetails = imageftbbox($FontSize, $Angle, $this->font, $this->code[$i], []); |
|
325 | + $CharHeight = abs($CharDetails[1] + $CharDetails[5]); |
|
326 | + |
|
327 | + // calculate character starting coordinates |
|
328 | + $posX = ($this->spacing / 2) + ($i * $this->spacing); |
|
329 | + $posY = 2 + ($this->height / 2) + ($CharHeight / 4); |
|
330 | + |
|
331 | + imagefttext($this->oImage, $FontSize, $Angle, $posX, $posY, $text_color, $this->font, $this->code[$i], []); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Draw Border |
|
337 | + */ |
|
338 | + public function drawBorder() |
|
339 | + { |
|
340 | + $rgb = mt_rand(50, 150); |
|
341 | + $border_color = imagecolorallocate($this->oImage, $rgb, $rgb, $rgb); |
|
342 | + imagerectangle($this->oImage, 0, 0, $this->width - 1, $this->height - 1, $border_color); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Draw Circles background |
|
347 | + */ |
|
348 | + public function drawCircles() |
|
349 | + { |
|
350 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
351 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
352 | + imagefilledellipse($this->oImage, mt_rand(0, $this->width - 10), mt_rand(0, $this->height - 3), mt_rand(10, 20), mt_rand(20, 30), $randomcolor); |
|
353 | + } |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * Draw Lines background |
|
358 | + */ |
|
359 | + public function drawLines() |
|
360 | + { |
|
361 | + for ($i = 0; $i < $this->config['background_num']; ++$i) { |
|
362 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
363 | + imageline($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Draw Rectangles background |
|
369 | + */ |
|
370 | + public function drawRectangles() |
|
371 | + { |
|
372 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
373 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
374 | + imagefilledrectangle($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
375 | + } |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Draw Bars background |
|
380 | + */ |
|
381 | + public function drawBars() |
|
382 | + { |
|
383 | + for ($i = 0; $i <= $this->height;) { |
|
384 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
385 | + imageline($this->oImage, 0, $i, $this->width, $i, $randomcolor); |
|
386 | + $i += 2.5; |
|
387 | + } |
|
388 | + for ($i = 0; $i <= $this->width;) { |
|
389 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
390 | + imageline($this->oImage, $i, 0, $i, $this->height, $randomcolor); |
|
391 | + $i += 2.5; |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Draw Ellipses background |
|
397 | + */ |
|
398 | + public function drawEllipses() |
|
399 | + { |
|
400 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
401 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
402 | + imageellipse($this->oImage, mt_rand(0, $this->width), mt_rand(0, $this->height), mt_rand(0, $this->width), mt_rand(0, $this->height), $randomcolor); |
|
403 | + } |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Draw polygons background |
|
408 | + */ |
|
409 | + public function drawPolygons() |
|
410 | + { |
|
411 | + for ($i = 1; $i <= $this->config['background_num']; ++$i) { |
|
412 | + $randomcolor = imagecolorallocate($this->oImage, mt_rand(190, 255), mt_rand(190, 255), mt_rand(190, 255)); |
|
413 | + $coords = []; |
|
414 | + for ($j = 1; $j <= $this->config['polygon_point']; ++$j) { |
|
415 | + $coords[] = mt_rand(0, $this->width); |
|
416 | + $coords[] = mt_rand(0, $this->height); |
|
417 | + } |
|
418 | + imagefilledpolygon($this->oImage, $coords, $this->config['polygon_point'], $randomcolor); |
|
419 | + } |
|
420 | + } |
|
421 | + |
|
422 | + /** |
|
423 | + * Create CAPTCHA iamge with BMP |
|
424 | + * TODO |
|
425 | + * @param string $file |
|
426 | + * @return string |
|
427 | + */ |
|
428 | + public function createImageBmp($file = '') |
|
429 | + { |
|
430 | + $image = ''; |
|
431 | + |
|
432 | + if (empty($file)) { |
|
433 | + header('Content-type: image/bmp'); |
|
434 | + echo $image; |
|
435 | + } else { |
|
436 | + return $image; |
|
437 | + } |
|
438 | + } |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | $config = @include __DIR__ . '/../config.php'; |
@@ -5,11 +5,11 @@ discard block |
||
5 | 5 | * D.J. |
6 | 6 | */ |
7 | 7 | |
8 | -include dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/mainfile.php'; |
|
8 | +include dirname(dirname(dirname(dirname(dirname(__DIR__))))).'/mainfile.php'; |
|
9 | 9 | error_reporting(0); |
10 | 10 | $xoopsLogger->activated = false; |
11 | 11 | |
12 | -if (empty(Request::getString('HTTP_REFERER', '', 'SERVER')) || !preg_match('/^' . preg_quote(XOOPS_URL, '/') . '/', Request::getString('HTTP_REFERER', '', 'SERVER'))) { |
|
12 | +if (empty(Request::getString('HTTP_REFERER', '', 'SERVER')) || !preg_match('/^'.preg_quote(XOOPS_URL, '/').'/', Request::getString('HTTP_REFERER', '', 'SERVER'))) { |
|
13 | 13 | exit(); |
14 | 14 | } |
15 | 15 | |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | if ('bmp' === $this->mode) { |
87 | 87 | $this->config['num_chars'] = 4; |
88 | - $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int)str_pad('9', $this->config['num_chars'], '9')); |
|
88 | + $this->code = mt_rand(pow(10, $this->config['num_chars'] - 1), (int) str_pad('9', $this->config['num_chars'], '9')); |
|
89 | 89 | } else { |
90 | 90 | $this->code = substr(md5(uniqid(mt_rand(), 1)), 0, $this->config['num_chars']); |
91 | 91 | if (!$this->config['casesensitive']) { |
@@ -100,13 +100,13 @@ discard block |
||
100 | 100 | return; |
101 | 101 | } |
102 | 102 | |
103 | - $_SESSION['XoopsCaptcha_sessioncode'] = (string)$this->code; |
|
104 | - $maxAttempts = (int)(@$_SESSION['XoopsCaptcha_maxattempts']); |
|
103 | + $_SESSION['XoopsCaptcha_sessioncode'] = (string) $this->code; |
|
104 | + $maxAttempts = (int) (@$_SESSION['XoopsCaptcha_maxattempts']); |
|
105 | 105 | |
106 | 106 | // Increase the attempt records on refresh |
107 | 107 | if (!empty($maxAttempts)) { |
108 | - $_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']]++; |
|
109 | - if ($_SESSION['XoopsCaptcha_attempt_' . $_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
108 | + $_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']]++; |
|
109 | + if ($_SESSION['XoopsCaptcha_attempt_'.$_SESSION['XoopsCaptcha_name']] > $maxAttempts) { |
|
110 | 110 | $this->invalid = true; |
111 | 111 | } |
112 | 112 | } |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | { |
121 | 121 | if ($this->invalid) { |
122 | 122 | header('Content-type: image/gif'); |
123 | - readfile(XOOPS_ROOT_PATH . '/images/subject/icon2.gif'); |
|
123 | + readfile(XOOPS_ROOT_PATH.'/images/subject/icon2.gif'); |
|
124 | 124 | |
125 | 125 | return; |
126 | 126 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | header('Content-type: image/jpeg'); |
191 | 191 | imagejpeg($this->oImage); |
192 | 192 | } else { |
193 | - imagejpeg($this->oImage, XOOPS_ROOT_PATH . '/' . $this->config['imagepath'] . '/' . $file . '.jpg'); |
|
193 | + imagejpeg($this->oImage, XOOPS_ROOT_PATH.'/'.$this->config['imagepath'].'/'.$file.'.jpg'); |
|
194 | 194 | } |
195 | 195 | imagedestroy($this->oImage); |
196 | 196 | } |
@@ -211,8 +211,8 @@ discard block |
||
211 | 211 | } |
212 | 212 | } |
213 | 213 | */ |
214 | - require_once XOOPS_ROOT_PATH . '/class/xoopslists.php'; |
|
215 | - $file_path = $this->config['rootpath'] . "/{$name}"; |
|
214 | + require_once XOOPS_ROOT_PATH.'/class/xoopslists.php'; |
|
215 | + $file_path = $this->config['rootpath']."/{$name}"; |
|
216 | 216 | $files = XoopsLists::getFileListAsArray($file_path); |
217 | 217 | foreach ($files as $item) { |
218 | 218 | if (empty($extension) || preg_match("/(\.{$extension})$/i", $item)) { |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | public function loadFont() |
230 | 230 | { |
231 | 231 | $fonts = $this->_getList('fonts', 'ttf'); |
232 | - $this->font = $this->config['rootpath'] . '/fonts/' . $fonts[array_rand($fonts)]; |
|
232 | + $this->font = $this->config['rootpath'].'/fonts/'.$fonts[array_rand($fonts)]; |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | public function setImageSize() |
@@ -255,7 +255,7 @@ discard block |
||
255 | 255 | imagedestroy($oImage); |
256 | 256 | |
257 | 257 | $this->height = $MaxCharHeight + 2; |
258 | - $this->spacing = (int)(($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
258 | + $this->spacing = (int) (($this->config['num_chars'] * $MaxCharWidth) / $this->config['num_chars']); |
|
259 | 259 | $this->width = ($this->config['num_chars'] * $MaxCharWidth) + ($this->spacing / 2); |
260 | 260 | } |
261 | 261 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | { |
269 | 269 | $RandBackground = null; |
270 | 270 | if ($backgrounds = $this->_getList('backgrounds', '(gif|jpg|png)')) { |
271 | - $RandBackground = $this->config['rootpath'] . '/backgrounds/' . $backgrounds[array_rand($backgrounds)]; |
|
271 | + $RandBackground = $this->config['rootpath'].'/backgrounds/'.$backgrounds[array_rand($backgrounds)]; |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | return $RandBackground; |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } |
439 | 439 | } |
440 | 440 | |
441 | -$config = @include __DIR__ . '/../config.php'; |
|
441 | +$config = @include __DIR__.'/../config.php'; |
|
442 | 442 | $imageHandler = new \XoopsCaptchaImageHandler(); |
443 | 443 | $imageHandler->setConfig($config); |
444 | 444 | $imageHandler->loadImage(); |
@@ -41,6 +41,6 @@ |
||
41 | 41 | $myts = \MyTextSanitizer::getInstance(); |
42 | 42 | |
43 | 43 | if (!isset($GLOBALS['xoopsTpl']) || !($GLOBALS['xoopsTpl'] instanceof XoopsTpl)) { |
44 | - require_once $GLOBALS['xoops']->path('class/template.php'); |
|
45 | - $xoopsTpl = new \XoopsTpl(); |
|
44 | + require_once $GLOBALS['xoops']->path('class/template.php'); |
|
45 | + $xoopsTpl = new \XoopsTpl(); |
|
46 | 46 | } |
@@ -19,11 +19,11 @@ |
||
19 | 19 | |
20 | 20 | use XoopsModules\Smartobject; |
21 | 21 | |
22 | -require_once __DIR__ . '/../../../include/cp_header.php'; |
|
22 | +require_once __DIR__.'/../../../include/cp_header.php'; |
|
23 | 23 | //require_once $GLOBALS['xoops']->path('www/class/xoopsformloader.php'); |
24 | 24 | |
25 | 25 | //require_once __DIR__ . '/../class/Utility.php'; |
26 | -require_once __DIR__ . '/../include/common.php'; |
|
26 | +require_once __DIR__.'/../include/common.php'; |
|
27 | 27 | |
28 | 28 | $moduleDirName = basename(dirname(__DIR__)); |
29 | 29 | $helper = Smartobject\Helper::getInstance(); |
@@ -17,11 +17,11 @@ |
||
17 | 17 | * @author XOOPS Development Team |
18 | 18 | */ |
19 | 19 | |
20 | -require_once __DIR__ . '/admin_header.php'; |
|
20 | +require_once __DIR__.'/admin_header.php'; |
|
21 | 21 | xoops_cp_header(); |
22 | 22 | |
23 | 23 | $adminObject->displayNavigation(basename(__FILE__)); |
24 | 24 | $adminObject::setPaypal('[email protected]'); |
25 | 25 | $adminObject->displayAbout(false); |
26 | 26 | |
27 | -require_once __DIR__ . '/admin_footer.php'; |
|
27 | +require_once __DIR__.'/admin_footer.php'; |
@@ -4,29 +4,29 @@ |
||
4 | 4 | * @see http://www.php-fig.org/psr/psr-4/examples/ |
5 | 5 | */ |
6 | 6 | spl_autoload_register(function ($class) { |
7 | - // project-specific namespace prefix |
|
8 | - $prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__))); |
|
7 | + // project-specific namespace prefix |
|
8 | + $prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__))); |
|
9 | 9 | |
10 | - // base directory for the namespace prefix |
|
11 | - $base_dir = __DIR__ . '/../class/'; |
|
10 | + // base directory for the namespace prefix |
|
11 | + $base_dir = __DIR__ . '/../class/'; |
|
12 | 12 | |
13 | - // does the class use the namespace prefix? |
|
14 | - $len = strlen($prefix); |
|
13 | + // does the class use the namespace prefix? |
|
14 | + $len = strlen($prefix); |
|
15 | 15 | |
16 | - if (0 !== strncmp($prefix, $class, $len)) { |
|
17 | - return; |
|
18 | - } |
|
16 | + if (0 !== strncmp($prefix, $class, $len)) { |
|
17 | + return; |
|
18 | + } |
|
19 | 19 | |
20 | - // get the relative class name |
|
21 | - $relative_class = substr($class, $len); |
|
20 | + // get the relative class name |
|
21 | + $relative_class = substr($class, $len); |
|
22 | 22 | |
23 | - // replace the namespace prefix with the base directory, replace namespace |
|
24 | - // separators with directory separators in the relative class name, append |
|
25 | - // with .php |
|
26 | - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
23 | + // replace the namespace prefix with the base directory, replace namespace |
|
24 | + // separators with directory separators in the relative class name, append |
|
25 | + // with .php |
|
26 | + $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
27 | 27 | |
28 | - // if the file exists, require it |
|
29 | - if (file_exists($file)) { |
|
30 | - require $file; |
|
31 | - } |
|
28 | + // if the file exists, require it |
|
29 | + if (file_exists($file)) { |
|
30 | + require $file; |
|
31 | + } |
|
32 | 32 | }); |
@@ -3,12 +3,12 @@ discard block |
||
3 | 3 | /** |
4 | 4 | * @see http://www.php-fig.org/psr/psr-4/examples/ |
5 | 5 | */ |
6 | -spl_autoload_register(function ($class) { |
|
6 | +spl_autoload_register(function($class) { |
|
7 | 7 | // project-specific namespace prefix |
8 | - $prefix = 'XoopsModules\\' . ucfirst(basename(dirname(__DIR__))); |
|
8 | + $prefix = 'XoopsModules\\'.ucfirst(basename(dirname(__DIR__))); |
|
9 | 9 | |
10 | 10 | // base directory for the namespace prefix |
11 | - $base_dir = __DIR__ . '/../class/'; |
|
11 | + $base_dir = __DIR__.'/../class/'; |
|
12 | 12 | |
13 | 13 | // does the class use the namespace prefix? |
14 | 14 | $len = strlen($prefix); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | // replace the namespace prefix with the base directory, replace namespace |
24 | 24 | // separators with directory separators in the relative class name, append |
25 | 25 | // with .php |
26 | - $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; |
|
26 | + $file = $base_dir.str_replace('\\', '/', $relative_class).'.php'; |
|
27 | 27 | |
28 | 28 | // if the file exists, require it |
29 | 29 | if (file_exists($file)) { |