index.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /* Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. // This page return an image of a photo
  18. //if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER','1'); // Not disabled cause need to load personalized language
  19. //if (! defined('NOREQUIREDB')) define('NOREQUIREDB','1'); // Not disabled cause need to load personalized language
  20. if (!defined('NOREQUIRESOC')) {
  21. define('NOREQUIRESOC', '1');
  22. }
  23. //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
  24. if (!defined('NOCSRFCHECK')) {
  25. define('NOCSRFCHECK', '1');
  26. }
  27. if (!defined('NOTOKENRENEWAL')) {
  28. define('NOTOKENRENEWAL', '1');
  29. }
  30. if (!defined('NOREQUIREMENU')) {
  31. define('NOREQUIREMENU', '1');
  32. }
  33. if (!defined('NOREQUIREHTML')) {
  34. define('NOREQUIREHTML', '1');
  35. }
  36. if (!defined('NOREQUIREAJAX')) {
  37. define('NOREQUIREAJAX', '1');
  38. }
  39. if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  40. require '../../main.inc.php'; // Load $user and permissions
  41. }
  42. $id = GETPOST('id', 'int');
  43. $w = GETPOST('w', 'int');
  44. $h = GETPOST('h', 'int');
  45. $query = GETPOST('query', 'alpha');
  46. /*
  47. * View
  48. */
  49. if ($query == "cat") {
  50. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  51. require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
  52. $object = new Categorie($db);
  53. $result = $object->fetch($id);
  54. $upload_dir = $conf->categorie->multidir_output[$object->entity];
  55. $pdir = get_exdir($object->id, 2, 0, 0, $object, 'category').$object->id."/photos/";
  56. $dir = $upload_dir.'/'.$pdir;
  57. foreach ($object->liste_photos($dir) as $key => $obj) {
  58. if ($obj['photo_vignette']) {
  59. $filename = $obj['photo_vignette'];
  60. } else {
  61. $filename = $obj['photo'];
  62. }
  63. $file = DOL_URL_ROOT.'/viewimage.php?cache=1&publictakepos=1&modulepart=category&entity='.$object->entity.'&file='.urlencode($pdir.$filename);
  64. header('Location: '.$file);
  65. exit;
  66. }
  67. header('Location: ../../public/theme/common/nophoto.png');
  68. exit;
  69. } elseif ($query == "pro") {
  70. require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
  71. $objProd = new Product($db);
  72. $objProd->fetch($id);
  73. $image = $objProd->show_photos('product', $conf->product->multidir_output[$objProd->entity], 'small', 1);
  74. $match = array();
  75. preg_match('@src="([^"]+)"@', $image, $match);
  76. $file = array_pop($match);
  77. if ($file == "") {
  78. header('Location: ../../public/theme/common/nophoto.png');
  79. exit;
  80. } else {
  81. if (!defined('INCLUDE_PHONEPAGE_FROM_PUBLIC_PAGE')) {
  82. header('Location: '.$file.'&cache=1');
  83. exit;
  84. } else {
  85. header('Location: '.$file.'&cache=1&publictakepos=1&modulepart=product');
  86. exit;
  87. }
  88. }
  89. } else {
  90. // TODO We don't need this. Size of image must be defined on HTML page, image must NOT be resized when downloaded.
  91. // The file
  92. $filename = $query.".jpg";
  93. // Dimensions
  94. list($width, $height) = getimagesize($filename);
  95. $new_width = $w;
  96. $new_height = $h;
  97. // Resample
  98. $image_p = imagecreatetruecolor($new_width, $new_height);
  99. $image = imagecreatefromjpeg($filename);
  100. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  101. // Output
  102. imagejpeg($image_p, null, 100);
  103. }