These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | You may not change or alter any portion of this comment or credits |
||
4 | of supporting developers from this source code or any supporting source code |
||
5 | which is considered copyrighted (c) material of the original comment or credit authors. |
||
6 | |||
7 | This program is distributed in the hope that it will be useful, |
||
8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
10 | */ |
||
11 | |||
12 | /** |
||
13 | * oledrion |
||
14 | * |
||
15 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
16 | * @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
||
17 | * @author Hervé Thouzard (http://www.herve-thouzard.com/) |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * Script chargé d'afficher un média d'un produit |
||
22 | */ |
||
23 | |||
24 | require_once __DIR__ . '/header.php'; |
||
25 | $type = isset($_GET['type']) ? strtolower($_GET['type']) : 'picture'; |
||
26 | $product_id = isset($_GET['product_id']) ? (int)$_GET['product_id'] : 0; |
||
27 | if ($product_id > 0) { |
||
28 | $product = null; |
||
29 | $product = $h_oledrion_products->get($product_id); |
||
30 | if (!is_object($product)) { |
||
31 | exit(_OLEDRION_ERROR1); |
||
32 | } |
||
33 | |||
34 | // Produit en ligne ? |
||
35 | if ($product->getVar('product_online') == 0) { |
||
36 | exit(_OLEDRION_ERROR2); |
||
37 | } |
||
38 | |||
39 | // Le produit est publié ? |
||
40 | View Code Duplication | if (OledrionUtility::getModuleOption('show_unpublished') == 0 && $product->getVar('product_submitted') > time()) { |
|
0 ignored issues
–
show
|
|||
41 | exit(_OLEDRION_ERROR3); |
||
42 | } |
||
43 | } else { |
||
44 | exit(_ERRORS); |
||
45 | } |
||
46 | |||
47 | switch ($type) { |
||
48 | case 'attachment': // Un fichier attaché à un produit |
||
49 | $file_id = isset($_GET['file_id']) ? (int)$_GET['file_id'] : 0; |
||
50 | if ($file_id == 0) { |
||
51 | exit(_OLEDRION_ERROR13); |
||
52 | } |
||
53 | $attachedFile = null; |
||
54 | $attachedFile = $h_oledrion_files->get($file_id); |
||
55 | if (!is_object($attachedFile)) { |
||
56 | exit(_OLEDRION_ERROR19); |
||
57 | } |
||
58 | header('Content-Type: ' . $attachedFile->getVar('file_mimetype')); |
||
59 | header('Content-disposition: inline; filename="' . $attachedFile->getVar('file_filename') . '"'); |
||
60 | readfile($attachedFile->getPath()); |
||
61 | break; |
||
62 | |||
63 | case 'picture': // L'image principale d'un produit |
||
64 | xoops_header(true); |
||
65 | echo "<div align='center' style='font-weight: bold;'><a href=\"javascript:self.close();\" title=\"" . _CLOSE . "\">"; |
||
66 | if ($product->pictureExists()) { |
||
67 | echo "<img src='" . $product->getPictureUrl() . "' alt=''>"; |
||
68 | } else { |
||
69 | echo _OLEDRION_SORRY_NOPICTURE; |
||
70 | } |
||
71 | ?> |
||
72 | </a></div><br> |
||
73 | <br> |
||
74 | <div align='center'><input value="<?php echo _CLOSE ?>" type="button" onclick="window.close();"> |
||
75 | </div> |
||
76 | <?php |
||
77 | xoops_footer(); |
||
78 | break; |
||
79 | } |
||
80 | ?> |
||
81 |
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.