index.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. require_once dirname(__FILE__) . '/../se-lib/bootstrap.php';
  3. error_reporting(E_ALL & ~E_NOTICE);
  4. //session_save_path("../session") ;
  5. session_start();
  6. date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions
  7. if (file_exists(APP_PATH_ROOT . DS . 'config' . DS . '.config_'.$_SERVER['SERVER_NAME'].'.php')) {
  8. require APP_PATH_ROOT . DS . 'config' . DS . '.config_'.$_SERVER['SERVER_NAME'].'.php';
  9. }
  10. if (($function_init = V::get('function_init', '', $_GET))) {
  11. if (function_exists($function_init)) {
  12. $function_init();
  13. } else {
  14. header('HTTP/1.1 400: Bad Request');
  15. header('Warning: wrong ID L.' . __LINE__);
  16. }
  17. } else {
  18. header('HTTP/1.1 400: Bad Request');
  19. header('Warning: wrong ID L.' . __LINE__);
  20. }
  21. function fun_SHOW_EXTERNAL_IMAGE() {
  22. $remote_table = V::get('tbl', '', $_REQUEST);
  23. $remote_id = V::get('id', '', $_REQUEST, 'int');
  24. $number = V::get('number', '', $_REQUEST, 'int');
  25. $imageResize = V::get('resize', '', $_REQUEST);
  26. $DBG = (V::get('DBG', 0, $_REQUEST, 'int') > 0);
  27. Lib::loadClass('DB_Image');
  28. if ($remote_id <= 0) {
  29. header('HTTP/1.1 400: Bad Request');
  30. header('Warning: wrong ID L.' . __LINE__);
  31. exit;
  32. }
  33. if (!DB_Image::tableIsAllowed($remote_table)) {
  34. header('HTTP/1.1 400: Bad Request');
  35. header('Warning: table not allowed L.' . __LINE__);
  36. exit;
  37. }
  38. $image_row = DB_Image::getImage($remote_table, $remote_id, $number);
  39. if (!$image_row) {
  40. header('HTTP/1.1 400: Bad Request');
  41. header('Warning: image not found in db L.' . __LINE__);
  42. exit;
  43. }
  44. $etag = md5($image_row->ID . $image_row->A_CREATE_DATE_TS);
  45. if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $image_row->A_CREATE_DATE_TS
  46. || trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
  47. header("HTTP/1.1 304 Not Modified");
  48. exit;
  49. }
  50. $expire_date = mktime(0, 0, 0, date('m') + 3, date('d'), date('Y'));
  51. $maxWidth = 0;
  52. $maxHeight = 0;
  53. if ($imageResize) {
  54. list($maxWidth, $maxHeight) = explode('x', $imageResize, 2);
  55. $maxWidth = intval($maxWidth);
  56. $maxHeight = intval($maxHeight);
  57. if ($maxWidth <= 0 || $maxHeight <= 0) {
  58. header('HTTP/1.1 400: Bad Request');
  59. echo'ERROR wrong param resize (WxH)';
  60. exit;
  61. }
  62. }
  63. if (!$DBG) {
  64. header("Content-type: {$image_row->TYPE}");
  65. header("Cache-control: public");
  66. header("Pragma: public");// default 'no-cache'
  67. header("Etag: {$etag}");
  68. if (!$imageResize) {
  69. header("Content-length: {$image_row->SIZE}");
  70. }
  71. header("Expires: " . gmdate("D, d M Y H:i:s", $expire_date) . " GMT");
  72. header("Last-Modified: " . gmdate("D, d M Y H:i:s", $image_row->A_CREATE_DATE_TS) . " GMT");
  73. }
  74. if ($imageResize) {
  75. print DB_Image::resizeImageFromBlob($image_row->IMAGE, $image_row->TYPE, $maxWidth, $maxHeight);
  76. } else {
  77. print $image_row->IMAGE;
  78. }
  79. exit;
  80. }