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 |
||
2 | /** |
||
3 | * **************************************************************************** |
||
4 | * references - MODULE FOR XOOPS |
||
5 | * Copyright (c) Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
||
6 | * |
||
7 | * You may not change or alter any portion of this comment or credits |
||
8 | * of supporting developers from this source code or any supporting source code |
||
9 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
10 | * This program is distributed in the hope that it will be useful, |
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
13 | * |
||
14 | * @copyright Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
||
15 | * @license http://www.fsf.org/copyleft/gpl.html GNU public license |
||
16 | * @package references |
||
17 | * @author Hervé Thouzard of Instant Zero (http://www.instant-zero.com) |
||
18 | * |
||
19 | * **************************************************************************** |
||
20 | */ |
||
21 | defined('XOOPS_ROOT_PATH') || exit('XOOPS root path not defined'); |
||
22 | |||
23 | require_once XOOPS_ROOT_PATH . '/kernel/object.php'; |
||
24 | if (!class_exists('references_XoopsPersistableObjectHandler')) { |
||
25 | require_once XOOPS_ROOT_PATH . '/modules/references/class/PersistableObjectHandler.php'; |
||
26 | } |
||
27 | |||
28 | define('REFERENCES_STATUS_ONLINE', 1); // Articles en ligne |
||
29 | define('REFERENCES_STATUS_OFFLINE', 0); // Articles hors ligne |
||
30 | |||
31 | class references_articles extends references_Object |
||
32 | { |
||
33 | public function __construct() |
||
34 | { |
||
35 | $this->initVar('article_id', XOBJ_DTYPE_INT, null, false); |
||
36 | $this->initVar('article_category_id', XOBJ_DTYPE_INT, null, false); |
||
37 | $this->initVar('article_timestamp', XOBJ_DTYPE_INT, null, false); |
||
38 | $this->initVar('article_weight', XOBJ_DTYPE_INT, null, false); |
||
39 | $this->initVar('article_date', XOBJ_DTYPE_TXTBOX, null, false); |
||
40 | $this->initVar('article_title', XOBJ_DTYPE_TXTBOX, null, false); |
||
41 | $this->initVar('article_text', XOBJ_DTYPE_TXTAREA, null, false); |
||
42 | $this->initVar('article_externalurl', XOBJ_DTYPE_TXTBOX, null, false); |
||
43 | $this->initVar('article_picture1', XOBJ_DTYPE_TXTBOX, null, false); |
||
44 | $this->initVar('article_picture1_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
45 | $this->initVar('article_picture2', XOBJ_DTYPE_TXTBOX, null, false); |
||
46 | $this->initVar('article_picture2_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
47 | $this->initVar('article_picture3', XOBJ_DTYPE_TXTBOX, null, false); |
||
48 | $this->initVar('article_picture3_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
49 | $this->initVar('article_picture4', XOBJ_DTYPE_TXTBOX, null, false); |
||
50 | $this->initVar('article_picture4_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
51 | $this->initVar('article_picture5', XOBJ_DTYPE_TXTBOX, null, false); |
||
52 | $this->initVar('article_picture5_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
53 | $this->initVar('article_picture6', XOBJ_DTYPE_TXTBOX, null, false); |
||
54 | $this->initVar('article_picture6_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
55 | $this->initVar('article_picture7', XOBJ_DTYPE_TXTBOX, null, false); |
||
56 | $this->initVar('article_picture7_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
57 | $this->initVar('article_picture8', XOBJ_DTYPE_TXTBOX, null, false); |
||
58 | $this->initVar('article_picture8_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
59 | $this->initVar('article_picture9', XOBJ_DTYPE_TXTBOX, null, false); |
||
60 | $this->initVar('article_picture9_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
61 | $this->initVar('article_picture10', XOBJ_DTYPE_TXTBOX, null, false); |
||
62 | $this->initVar('article_picture10_text', XOBJ_DTYPE_TXTBOX, null, false); |
||
63 | $this->initVar('article_author', XOBJ_DTYPE_INT, null, false); |
||
64 | $this->initVar('article_online', XOBJ_DTYPE_INT, null, false); |
||
65 | $this->initVar('article_attached_file', XOBJ_DTYPE_TXTBOX, null, false); |
||
66 | $this->initVar('article_readmore', XOBJ_DTYPE_TXTAREA, null, false); |
||
67 | |||
68 | // Pour autoriser le html |
||
69 | $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * Indique si l'article en cours est visible |
||
74 | * |
||
75 | * @return boolean |
||
76 | */ |
||
77 | public function isArticleOnline() |
||
78 | { |
||
79 | return $this->getVar('article_online') == REFERENCES_STATUS_ONLINE ? true : false; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Retourne une image qui indique si l'article est en ligne ou pas |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getOnlinePicture() |
||
88 | { |
||
89 | if ($this->isArticleOnline()) { |
||
90 | return REFERENCES_IMAGES_URL . 'status_online.png'; |
||
91 | } else { |
||
92 | return REFERENCES_IMAGES_URL . 'status_offline.png'; |
||
93 | } |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * Retourne la chaine de caractères qui peut être utilisée dans l'attribut href d'une balise html A. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getHrefTitle() |
||
102 | { |
||
103 | return references_utils::makeHrefTitle($this->getVar('article_title')); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * Indique si une image de l'article existe |
||
108 | * |
||
109 | * @param integer $indice L'indice de l'image recherchée |
||
110 | * @return boolean Vrai si l'image existe sinon faux |
||
111 | */ |
||
112 | View Code Duplication | public function pictureExists($indice) |
|
0 ignored issues
–
show
|
|||
113 | { |
||
114 | $return = false; |
||
115 | $fieldName = 'article_picture' . $indice; |
||
116 | if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName))) { |
||
117 | $return = true; |
||
118 | } |
||
119 | |||
120 | return $return; |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * Supprime l'image associée à un article |
||
125 | * |
||
126 | * @param integer $indice L'indice de l'image recherchée |
||
127 | * @return void |
||
128 | */ |
||
129 | public function deletePicture($indice) |
||
130 | { |
||
131 | $fieldName = 'article_picture' . $indice; |
||
132 | if ($this->pictureExists($indice)) { |
||
133 | @unlink(references_utils::getModuleOption('images_path') . references_utils::getModuleOption('images_path') . $this->getVar($fieldName)); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
134 | } |
||
135 | $this->setVar($fieldName, ''); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Retourne l'URL de l'image de l'article courant |
||
140 | * |
||
141 | * @param integer $indice L'indice de l'image recherchée |
||
142 | * @return string L'URL |
||
143 | */ |
||
144 | View Code Duplication | public function getPictureUrl($indice) |
|
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. ![]() |
|||
145 | { |
||
146 | $fieldName = 'article_picture' . $indice; |
||
147 | if (xoops_trim($this->getVar($fieldName)) != '' && $this->pictureExists($indice)) { |
||
148 | return references_utils::getModuleOption('images_url') . '/' . $this->getVar($fieldName); |
||
149 | } else { |
||
150 | return REFERENCES_IMAGES_URL . 'blank.gif'; |
||
151 | } |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Retourne le chemin de l'image de l'article courante |
||
156 | * |
||
157 | * @param integer $indice L'indice de l'image recherchée |
||
158 | * @return string Le chemin |
||
159 | */ |
||
160 | public function getPicturePath($indice) |
||
161 | { |
||
162 | $fieldName = 'article_picture' . $indice; |
||
163 | if (xoops_trim($this->getVar($fieldName)) != '') { |
||
164 | return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . $this->getVar($fieldName); |
||
165 | } else { |
||
166 | return ''; |
||
167 | } |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Indique si la vignette de l'image de l'article existe |
||
172 | * |
||
173 | * @param integer $indice L'indice de l'image recherchée |
||
174 | * @return boolean Vrai si l'image existe sinon faux |
||
175 | */ |
||
176 | View Code Duplication | public function thumbExists($indice) |
|
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. ![]() |
|||
177 | { |
||
178 | $fieldName = 'article_picture' . $indice; |
||
179 | $return = false; |
||
180 | if (xoops_trim($this->getVar($fieldName)) != '' && file_exists(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName))) { |
||
181 | $return = true; |
||
182 | } |
||
183 | |||
184 | return $return; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * Retourne l'URL de la vignette de l'article |
||
189 | * |
||
190 | * @param integer $indice L'indice de l'image recherchée |
||
191 | * @return string L'URL |
||
192 | */ |
||
193 | View Code Duplication | public function getThumbUrl($indice) |
|
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. ![]() |
|||
194 | { |
||
195 | $fieldName = 'article_picture' . $indice; |
||
196 | if (xoops_trim($this->getVar($fieldName)) != '') { |
||
197 | return references_utils::getModuleOption('images_url') . '/' . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
||
198 | } else { |
||
199 | return REFERENCES_IMAGES_URL . 'blank.gif'; |
||
200 | } |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Retourne le chemin de la vignette de l'annonce |
||
205 | * |
||
206 | * @param integer $indice L'indice de l'image recherchée |
||
207 | * @return string L'URL |
||
208 | */ |
||
209 | public function getThumbPath($indice) |
||
210 | { |
||
211 | $fieldName = 'article_picture' . $indice; |
||
212 | if (xoops_trim($this->getVar($fieldName)) != '') { |
||
213 | return references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName); |
||
214 | } else { |
||
215 | return ''; |
||
216 | } |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Indique si le fichier attaché à un article existe |
||
221 | * |
||
222 | * @return boolean |
||
223 | */ |
||
224 | public function attachmentExists() |
||
225 | { |
||
226 | $return = false; |
||
227 | if (xoops_trim($this->getVar('article_attached_file')) != '' && file_exists(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'))) { |
||
228 | $return = true; |
||
229 | } |
||
230 | |||
231 | return $return; |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * Retourne l'URL du fichier attaché |
||
236 | * |
||
237 | * @return string L'url du fichier attaché sinon une chaine vide |
||
238 | */ |
||
239 | View Code Duplication | public function getAttachmentUrl() |
|
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. ![]() |
|||
240 | { |
||
241 | if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
||
242 | return references_utils::getModuleOption('attached_url') . '/' . $this->getVar('article_attached_file'); |
||
243 | } else { |
||
244 | return ''; |
||
245 | } |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * Retourne le chemin du fichier attaché |
||
250 | * |
||
251 | * @return string Le chemin du fichier attaché sinon une chaine vide |
||
252 | */ |
||
253 | View Code Duplication | public function getAttachmentPath() |
|
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. ![]() |
|||
254 | { |
||
255 | if (xoops_trim($this->getVar('article_attached_file')) != '' && $this->attachmentExists()) { |
||
256 | return references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file'); |
||
257 | } else { |
||
258 | return ''; |
||
259 | } |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * Supprime le fichier attaché à un article |
||
264 | */ |
||
265 | public function deleteAttachment() |
||
266 | { |
||
267 | if ($this->attachmentExists()) { |
||
268 | @unlink(references_utils::getModuleOption('attached_path') . DIRECTORY_SEPARATOR . $this->getVar('article_attached_file')); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
269 | } |
||
270 | $this->setVar('article_attached_file', ''); |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * Supprime la miniature associée à l'article |
||
275 | * |
||
276 | * @param integer $indice L'indice de l'image recherchée |
||
277 | * @return void |
||
278 | */ |
||
279 | public function deleteThumb($indice) |
||
280 | { |
||
281 | $fieldName = 'article_picture' . $indice; |
||
282 | if ($this->thumbExists($indice)) { |
||
283 | @unlink(references_utils::getModuleOption('images_path') . DIRECTORY_SEPARATOR . REFERENCES_THUMBS_PREFIX . $this->getVar($fieldName)); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
284 | } |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * Supprime l'image (et vignette) d'un article (raccourcis) |
||
289 | * |
||
290 | * @return void |
||
291 | */ |
||
292 | public function deletePicturesAndThumbs() |
||
293 | { |
||
294 | for ($i = 1; $i <= 10; ++$i) { |
||
295 | $this->deleteThumb($i); |
||
296 | $this->deletePicture($i); |
||
297 | } |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * Retourne le timestamp de création formaté |
||
302 | * |
||
303 | * @return string |
||
304 | */ |
||
305 | public function getFormatedTimeStamp() |
||
306 | { |
||
307 | return formatTimestamp($this->getVar('article_timestamp'), 's'); |
||
308 | } |
||
309 | |||
310 | /** |
||
311 | * Indique s'il existe au moins une image pour l'article |
||
312 | * |
||
313 | * @return boolean |
||
314 | */ |
||
315 | public function isThereAPicture() |
||
316 | { |
||
317 | for ($i = 1; $i <= 10; ++$i) { |
||
318 | if ($this->pictureExists($i)) { |
||
319 | return true; |
||
320 | } |
||
321 | } |
||
322 | |||
323 | return false; |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * Inidique s'il existe au moins une vignette pour l'article |
||
328 | * |
||
329 | * @return boolean |
||
330 | */ |
||
331 | public function isThereAThumb() |
||
332 | { |
||
333 | for ($i = 1; $i <= 10; ++$i) { |
||
334 | if ($this->thumbExists($i)) { |
||
335 | return true; |
||
336 | } |
||
337 | } |
||
338 | |||
339 | return false; |
||
340 | } |
||
341 | |||
342 | /** |
||
343 | * Retourne l'url pour atteindre l'élément |
||
344 | * |
||
345 | * @param bool $shortVersion |
||
346 | * @return string |
||
347 | */ |
||
348 | View Code Duplication | public function getUrl($shortVersion = false) |
|
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. ![]() |
|||
349 | { |
||
350 | if (!$shortVersion) { |
||
351 | return REFERENCES_URL . 'reference.php?article_id=' . $this->getVar('article_id'); |
||
352 | } else { |
||
353 | return 'reference.php?article_id=' . $this->getVar('article_id'); |
||
354 | } |
||
355 | } |
||
356 | |||
357 | /** |
||
358 | * Retourne les éléments de l'annnonce formatés pour affichage |
||
359 | * |
||
360 | * @param string $format Format à utiliser |
||
361 | * @return array |
||
362 | */ |
||
363 | public function toArray($format = 's') |
||
364 | { |
||
365 | $ret = array(); |
||
0 ignored issues
–
show
$ret 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 ![]() |
|||
366 | $ret = parent::toArray($format); |
||
367 | $hrefTitle = $this->getHrefTitle(); |
||
368 | $ret['article_href_title'] = $hrefTitle; |
||
369 | $ret['article_url'] = $this->getUrl(); |
||
370 | // Indique si une annonce est expirée |
||
371 | $ret['article_is_online'] = $this->isArticleOnline(); |
||
372 | if ($this->isThereAPicture()) { |
||
373 | $ret['article_picture_exists'] = true; |
||
374 | for ($i = 1; $i <= 10; ++$i) { |
||
375 | if ($this->pictureExists($i)) { |
||
376 | $ret['article_picture_url' . $i] = $this->getPictureUrl($i); |
||
377 | $ret['article_picture_path' . $i] = $this->getPicturePath($i); |
||
378 | $ret['article_pictures_urls'][] = $this->getPictureUrl($i); |
||
379 | $ret['article_pictures_paths'][] = $this->getPicturePath($i); |
||
380 | $fieldName = 'article_picture' . $i . '_text'; |
||
381 | if (xoops_trim($this->getVar($fieldName)) != '') { |
||
382 | $ret['article_pictures_texts'][] = references_utils::makeHrefTitle($this->getVar($fieldName)); |
||
383 | } else { |
||
384 | $ret['article_pictures_texts'][] = $hrefTitle; |
||
385 | } |
||
386 | } |
||
387 | } |
||
388 | } else { |
||
389 | $ret['article_picture_exists'] = false; |
||
390 | } |
||
391 | $ret['article_short_text'] = references_utils::truncate_tagsafe($this->getVar('article_text'), REFERENCES_SHORTEN_TEXT); |
||
392 | |||
393 | if ($this->attachmentExists()) { |
||
394 | $ret['article_attachment_exists'] = true; |
||
395 | $ret['article_attachment_url'] = $this->getAttachmentUrl(); |
||
396 | $ret['article_attachment_path'] = $this->getAttachmentPath(); |
||
397 | } else { |
||
398 | $ret['attachment_exists'] = false; |
||
399 | } |
||
400 | |||
401 | if ($this->isThereAThumb()) { |
||
402 | $ret['article_thumb_exists'] = true; |
||
403 | for ($i = 1; $i <= 10; ++$i) { |
||
404 | if ($this->thumbExists($i)) { |
||
405 | $ret['article_thumb_url' . $i] = $this->getThumbUrl($i); |
||
406 | $ret['article_thumb_path' . $i] = $this->getThumbPath($i); |
||
407 | $ret['article_thumbs_urls'][] = $this->getThumbUrl($i); |
||
408 | $ret['article_thumbs_paths'][] = $this->getThumbPath($i); |
||
409 | } |
||
410 | } |
||
411 | } else { |
||
412 | $ret['article_thumb_exists'] = false; |
||
413 | } |
||
414 | |||
415 | $ret['article_timestamp_formated'] = $this->getFormatedTimeStamp(); |
||
416 | |||
417 | return $ret; |
||
418 | } |
||
419 | } |
||
420 | |||
421 | class ReferencesReferences_articlesHandler extends references_XoopsPersistableObjectHandler |
||
422 | { |
||
423 | public function __construct($db) |
||
424 | { // Table Classe Id Descr. |
||
425 | parent::__construct($db, 'references_articles', 'references_articles', 'article_id', 'article_title'); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Retourne le critère à utiliser pour voir les catégories en respectant les permissions |
||
430 | * |
||
431 | * @param string $permissionsType Type de permission (pour l'instant permission de voir) |
||
432 | * @return obejct de type Criteria |
||
433 | */ |
||
434 | public function getPermissionsCategoriesCriteria($permissionsType = REFERENCES_PERM_READ) |
||
435 | { |
||
436 | global $xoopsUser; |
||
437 | static $permissions = array(); |
||
438 | if (is_array($permissions) && array_key_exists($permissionsType, $permissions)) { |
||
439 | return $permissions[$permissionsType]; |
||
440 | } |
||
441 | $categories = array(); |
||
0 ignored issues
–
show
$categories 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 ![]() |
|||
442 | $currentModule = references_utils::getModule(); |
||
443 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
444 | $gperm_handler = xoops_getHandler('groupperm'); |
||
445 | $categories = $gperm_handler->getItemIds($permissionsType, $groups, $currentModule->getVar('mid')); |
||
446 | View Code Duplication | if (is_array($categories) && count($categories) > 0) { |
|
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. ![]() |
|||
447 | $permissions[$permissionsType] = new Criteria('article_category_id', '(' . implode(',', $categories) . ')', 'IN'); |
||
448 | } else { // Ne peut rien voir |
||
449 | $permissions[$permissionsType] = new Criteria('article_category_id', '0', '='); |
||
450 | } |
||
451 | |||
452 | return $permissions[$permissionsType]; |
||
0 ignored issues
–
show
The return type of
return $permissions[$permissionsType]; (Criteria ) is incompatible with the return type documented by ReferencesReferences_art...sionsCategoriesCriteria of type obejct .
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 ![]() |
|||
453 | } |
||
454 | |||
455 | /** |
||
456 | * Retourne les articles récents en tenant compte des permissions de consultation sur les catégories |
||
457 | * |
||
458 | * @param integer $start Indice de début |
||
459 | * @param integer $limit Nombre d'objets à renvoyer |
||
460 | * @param string $sort Zone de tri |
||
461 | * @param string $order Sens du tri |
||
462 | * @param boolean $onlyOnline Uniquement les articles en ligne ? |
||
463 | * @param integer $categoryId Identifiant d'une catégorie à laquelle se limiter |
||
464 | * @return array Objets de type references_articles |
||
0 ignored issues
–
show
|
|||
465 | */ |
||
466 | public function getRecentArticles($start = 0, $limit = 0, $sort = 'article_timestamp', $order = 'DESC', $onlyOnline = true, $categoryId = 0) |
||
467 | { |
||
468 | $criteria = new CriteriaCompo(); |
||
469 | $criteria->add(new Criteria('article_id', 0, '<>')); |
||
470 | $criteria->add($this->getPermissionsCategoriesCriteria()); |
||
471 | if ($onlyOnline) { |
||
472 | $criteria->add(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
||
473 | } |
||
474 | if (is_array($categoryId) && count($categoryId) > 0) { |
||
475 | $criteria->add(new Criteria('article_category_id', '(' . implode(',', $categoryId) . ')', 'IN')); |
||
476 | } elseif ($categoryId > 0) { |
||
477 | $criteria->add(new Criteria('article_category_id', $categoryId, '=')); |
||
478 | } |
||
479 | $criteria->setStart($start); |
||
480 | $criteria->setSort($sort); |
||
481 | $criteria->setOrder($order); |
||
482 | $criteria->setLimit($limit); |
||
483 | |||
484 | return $this->getObjects($criteria); |
||
485 | } |
||
486 | |||
487 | /** |
||
488 | * Retourne le nombre total d'articles en ligne |
||
489 | * |
||
490 | * @return integer |
||
491 | */ |
||
492 | public function getOnlineArticlesCount() |
||
493 | { |
||
494 | return $this->getCount(new Criteria('article_online', REFERENCES_STATUS_ONLINE, '=')); |
||
495 | } |
||
496 | |||
497 | /** |
||
498 | * Notification de la publication d'une nouvelle référence |
||
499 | * |
||
500 | * @param object|references_articles $article L'annonce pour laquelle on fait la notification |
||
501 | * @return bool |
||
502 | */ |
||
503 | View Code Duplication | public function notifyNewArticle(references_articles $article) |
|
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. ![]() |
|||
504 | { |
||
505 | $plugins = references_plugins::getInstance(); |
||
506 | $plugins->fireAction(references_plugins::EVENT_ON_REFERENCE_CREATE, new references_parameters(array('reference' => $article))); |
||
507 | |||
508 | return true; |
||
509 | } |
||
510 | |||
511 | /** |
||
512 | * Effectue la suppression d'un article (et de ses images et fichier attaché) |
||
513 | * |
||
514 | * @param references_articles $article L'article à supprimer |
||
515 | * @return boolean Le résultat de la suppression |
||
516 | */ |
||
517 | public function deleteArticle(references_articles $article) |
||
518 | { |
||
519 | $article->deletePicturesAndThumbs(); |
||
520 | $article->deleteAttachment(); |
||
521 | |||
522 | return $this->delete($article, true); |
||
523 | } |
||
524 | |||
525 | /** |
||
526 | * Retourne la liste des catégories uniques utilisées par les références |
||
527 | * |
||
528 | */ |
||
529 | public function getDistinctCategoriesIds() |
||
530 | { |
||
531 | $ret = array(); |
||
532 | $sql = 'SELECT distinct(article_category_id) FROM ' . $this->table; |
||
533 | $sql .= ' ' . $this->getPermissionsCategoriesCriteria()->renderWhere(); // Permissions |
||
534 | $sql .= ' GROUP BY article_category_id ORDER BY article_category_id'; |
||
535 | $result = $this->db->query($sql); |
||
536 | if (!$result) { |
||
537 | return $ret; |
||
538 | } |
||
539 | while ($row = $this->db->fetchArray($result)) { |
||
540 | $ret[$row['article_category_id']] = $row['article_category_id']; |
||
541 | } |
||
542 | |||
543 | return $ret; |
||
544 | } |
||
545 | |||
546 | /** |
||
547 | * Passe un article en ligne |
||
548 | * |
||
549 | * @param references_articles $article |
||
550 | * @return boolean |
||
551 | */ |
||
552 | public function onlineArticle(references_articles $article) |
||
553 | { |
||
554 | $article->setVar('article_online', REFERENCES_STATUS_ONLINE); |
||
555 | |||
556 | return $this->insert($article, true); |
||
557 | } |
||
558 | |||
559 | /** |
||
560 | * Passe un article hors ligne |
||
561 | * |
||
562 | * @param references_articles $article |
||
563 | * @return boolean |
||
564 | */ |
||
565 | public function offlineArticle(references_articles $article) |
||
566 | { |
||
567 | $article->setVar('article_online', REFERENCES_STATUS_OFFLINE); |
||
568 | |||
569 | return $this->insert($article, true); |
||
570 | } |
||
571 | |||
572 | /** |
||
573 | * Indique si une référence est visible d'un utilisateur |
||
574 | * |
||
575 | * @param object|references_articles $article L'article à controler |
||
576 | * @param integer $uid L'id de l'utilisateur à controler |
||
577 | * @return bool |
||
578 | */ |
||
579 | View Code Duplication | public function userCanSeeReference(references_articles $article, $uid = 0) |
|
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. ![]() |
|||
580 | { |
||
581 | global $xoopsUser; |
||
582 | if ($uid == 0) { |
||
583 | $uid = references_utils::getCurrentUserID(); |
||
584 | } |
||
585 | $currentModule = references_utils::getModule(); |
||
586 | $groups = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
0 ignored issues
–
show
$groups 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 ![]() |
|||
587 | $gperm_handler = xoops_getHandler('groupperm'); |
||
588 | |||
589 | return $gperm_handler->checkRight(REFERENCES_PERM_READ, $article->article_category_id, references_utils::getMemberGroups($uid), $currentModule->getVar('mid')); |
||
590 | } |
||
591 | |||
592 | /** |
||
593 | * Remonte un article d'un cran dans l'ordre global des articles |
||
594 | * |
||
595 | * @param integer $currentId L'ID de l'article courant dont on souhaite remonter l'ordre |
||
596 | * @param integer $currentOrder L'ordre de l'élément courant à remonter |
||
597 | * @return void |
||
598 | */ |
||
599 | View Code Duplication | public function moveUp($currentId, $currentOrder) |
|
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. ![]() |
|||
600 | { |
||
601 | $sql_plus = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder - 1); |
||
602 | $res_plus = $this->db->query($sql_plus); |
||
603 | if ($this->db->getRowsNum($res_plus) == 0) { |
||
604 | return; |
||
605 | } |
||
606 | $row_plus = $this->db->fetchArray($res_plus); |
||
607 | |||
608 | $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight + 1) WHERE article_id = ' . $row_plus['article_id']; |
||
609 | $this->db->queryF($upd1); |
||
610 | |||
611 | $upd2 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . (int)$currentId; |
||
612 | $this->db->queryF($upd2); |
||
613 | $this->forceCacheClean(); |
||
614 | } |
||
615 | |||
616 | /** |
||
617 | * Descend un article d'un cran dans l'ordre global des articles |
||
618 | * |
||
619 | * @param integer $currentId L'Id de l'article courant dont on souhaite descendre l'ordre |
||
620 | * @param integer $currentOrder L'orde de l'élément courant à remonter |
||
621 | * @return void |
||
622 | */ |
||
623 | View Code Duplication | public function moveDown($currentId, $currentOrder) |
|
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. ![]() |
|||
624 | { |
||
625 | $sql_moins = 'SELECT article_id FROM ' . $this->table . ' WHERE article_weight = ' . ((int)$currentOrder + 1); |
||
626 | $res_moins = $this->db->query($sql_moins); |
||
627 | if ($this->db->getRowsNum($res_moins) == 0) { |
||
628 | return; |
||
629 | } |
||
630 | |||
631 | $row_moins = $this->db->fetchArray($res_moins); |
||
632 | $upd1 = 'UPDATE ' . $this->table . ' SET article_weight = (article_weight - 1) WHERE article_id = ' . $row_moins['article_id']; |
||
633 | $this->db->queryF($upd1); |
||
634 | |||
635 | $upd2 = 'UPDATE ' . $this->table . ' SET article_weight =( article_weight + 1) WHERE article_id = ' . (int)$currentId; |
||
636 | $this->db->queryF($upd2); |
||
637 | $this->forceCacheClean(); |
||
638 | } |
||
639 | } |
||
640 |
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.