index.php 3.0 KB

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