This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php namespace XoopsModules\Smartobject; |
||
2 | |||
3 | /** |
||
4 | * Contains the basis classes for managing any objects derived from SmartObjects |
||
5 | * |
||
6 | * @license GNU |
||
7 | * @author marcan <[email protected]> |
||
8 | * @link http://smartfactory.ca The SmartFactory |
||
9 | * @package SmartObject |
||
10 | * @subpackage SmartObjectCore |
||
11 | */ |
||
12 | |||
13 | use XoopsModules\Smartmedia; |
||
14 | /** @var Smartmedia\Helper $helper */ |
||
15 | $helper = Smartmedia\Helper::getInstance(); |
||
16 | |||
17 | |||
18 | // defined('XOOPS_ROOT_PATH') || die('Restricted access'); |
||
19 | |||
20 | require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php'; |
||
21 | |||
22 | if (!defined('XOBJ_DTYPE_SIMPLE_ARRAY')) { |
||
23 | define('XOBJ_DTYPE_SIMPLE_ARRAY', 101); |
||
24 | } |
||
25 | if (!defined('XOBJ_DTYPE_CURRENCY')) { |
||
26 | define('XOBJ_DTYPE_CURRENCY', 200); |
||
27 | } |
||
28 | if (!defined('XOBJ_DTYPE_FLOAT')) { |
||
29 | define('XOBJ_DTYPE_FLOAT', 201); |
||
30 | } |
||
31 | if (!defined('XOBJ_DTYPE_TIME_ONLY')) { |
||
32 | define('XOBJ_DTYPE_TIME_ONLY', 202); |
||
33 | } |
||
34 | if (!defined('XOBJ_DTYPE_URLLINK')) { |
||
35 | define('XOBJ_DTYPE_URLLINK', 203); |
||
36 | } |
||
37 | if (!defined('XOBJ_DTYPE_FILE')) { |
||
38 | define('XOBJ_DTYPE_FILE', 204); |
||
39 | } |
||
40 | if (!defined('XOBJ_DTYPE_IMAGE')) { |
||
41 | define('XOBJ_DTYPE_IMAGE', 205); |
||
42 | } |
||
43 | if (!defined('XOBJ_DTYPE_FORM_SECTION')) { |
||
44 | define('XOBJ_DTYPE_FORM_SECTION', 210); |
||
45 | } |
||
46 | if (!defined('XOBJ_DTYPE_FORM_SECTION_CLOSE')) { |
||
47 | define('XOBJ_DTYPE_FORM_SECTION_CLOSE', 211); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * SmartObject base class |
||
52 | * |
||
53 | * Base class representing a single SmartObject |
||
54 | * |
||
55 | * @package SmartObject |
||
56 | * @author marcan <[email protected]> |
||
57 | * @link http://smartfactory.ca The SmartFactory |
||
58 | */ |
||
59 | class BaseSmartObject extends \XoopsObject |
||
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 |
||
0 ignored issues
–
show
|
|||
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 | View Code Duplication | if ($this->handler && (!$form_caption || '' === $form_caption)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | if ($this->handler && (!$form_dsc || '' === $form_dsc)) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | public function initNonPersistableVar( |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | public function quickInitVar( |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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; |
||
0 ignored issues
–
show
|
|||
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 | View Code Duplication | case 'dohtml': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'dobr': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'doimage': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'dosmiley': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'doxcode': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'meta_keywords': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'meta_description': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'counter': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'weight': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | case 'custom_css': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | // 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 |
||
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; |
||
0 ignored issues
–
show
The return type of
return false; (false ) is incompatible with the return type documented by XoopsModules\Smartobject\BaseSmartObject::summary of type string .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
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(); |
||
0 ignored issues
–
show
$helper is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
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 | View Code Duplication | if ('default' === $form_editor) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | if (!$v['not_gpc']) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
844 | $cleanv = $ts->stripSlashesGPC($ts->censorString($cleanv)); |
||
845 | } else { |
||
846 | $cleanv = $ts->censorString($cleanv); |
||
847 | } |
||
848 | break; |
||
849 | case XOBJ_DTYPE_TXTAREA: |
||
850 | View Code Duplication | if ($v['required'] && '0' != $cleanv && '' == $cleanv) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
851 | $this->setErrors(sprintf(_XOBJ_ERR_REQUIRED, $k)); |
||
852 | continue 2; |
||
853 | } |
||
854 | View Code Duplication | if (!$v['not_gpc']) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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; |
||
0 ignored issues
–
show
|
|||
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 | View Code Duplication | if ($v['required'] && '' === $cleanv) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | if ($v['required'] && '' === $cleanv) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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; |
||
0 ignored issues
–
show
break 1; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
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; |
||
0 ignored issues
–
show
break 1; does not seem to be reachable.
This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed. Unreachable code is most often the result of function fx() {
try {
doSomething();
return true;
}
catch (\Exception $e) {
return false;
}
return false;
}
In the above example, the last ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
1002 | case 'n': |
||
1003 | case 'none': |
||
1004 | default: |
||
1005 | break 1; |
||
1006 | } |
||
1007 | break; |
||
1008 | View Code Duplication | case XOBJ_DTYPE_LTIME: |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
1020 | case 'n': |
||
1021 | case 'none': |
||
1022 | case 'e': |
||
1023 | case 'edit': |
||
1024 | break 1; |
||
1025 | default: |
||
1026 | break 1; |
||
1027 | } |
||
1028 | break; |
||
1029 | View Code Duplication | case XOBJ_DTYPE_STIME: |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
1041 | case 'n': |
||
1042 | case 'none': |
||
1043 | case 'e': |
||
1044 | case 'edit': |
||
1045 | break 1; |
||
1046 | default: |
||
1047 | break 1; |
||
1048 | } |
||
1049 | break; |
||
1050 | View Code Duplication | case XOBJ_DTYPE_TIME_ONLY: |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
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 | View Code Duplication | if ($decimal_section) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
1118 | case 'e': |
||
1119 | case 'edit': |
||
1120 | return htmlspecialchars($ret, ENT_QUOTES); |
||
1121 | break 1; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
1136 | case 'f': |
||
1137 | View Code Duplication | case 'formpreview': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
1138 | $ts = \MyTextSanitizer::getInstance(); |
||
1139 | |||
1140 | return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
||
1141 | break 1; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
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; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
1163 | case 'p': |
||
1164 | case 'preview': |
||
1165 | $ts = \MyTextSanitizer::getInstance(); |
||
1166 | |||
1167 | return $ts->stripSlashesGPC($ret); |
||
1168 | break 1; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
1169 | case 'f': |
||
1170 | View Code Duplication | case 'formpreview': |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
1171 | $ts = \MyTextSanitizer::getInstance(); |
||
1172 | |||
1173 | return htmlspecialchars($ts->stripSlashesGPC($ret), ENT_QUOTES); |
||
1174 | break 1; |
||
0 ignored issues
–
show
break is not strictly necessary here and could be removed.
The break statement is not necessary if it is preceded for example by a return statement: switch ($x) {
case 1:
return 'foo';
break; // This break is not necessary and can be left off.
}
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive. ![]() |
|||
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 | // 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 | View Code Duplication | public function getUrlLinkObj($key) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | View Code Duplication | public function getFileObj($key) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
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 | } |
||
1460 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.