index.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. $image_resize = V::get('resize', '', $_REQUEST);
  36. Lib::loadClass('DB_Image');
  37. // check remote id
  38. if ($remote_id <= 0) {
  39. header('HTTP/1.1 400: Bad Request');
  40. header('Warning: wrong ID L.' . __LINE__);
  41. exit;
  42. }
  43. // check remote table
  44. $remote_tables = DB_Image::conf_get('remote_tables');
  45. if (!in_array($remote_table, $remote_tables)) {
  46. header('HTTP/1.1 400: Bad Request');
  47. header('Warning: table not allowed L.' . __LINE__);
  48. exit;
  49. }
  50. $db = DB::getDB();
  51. $sql = "select `ID`, `TYPE`, `SIZE`, `IMAGE`, `WIDTH`, `HEIGHT`, UNIX_TIMESTAMP(`A_CREATE_DATE`) as A_CREATE_DATE
  52. from `".DB_Image::conf_get_table_name()."`
  53. where
  54. `REMOTE_ID`='".$remote_id."'
  55. and `REMOTE_TABLE`='".$remote_table."'
  56. order by `ID` asc
  57. limit 1 offset ".$number."
  58. ";
  59. $res = $db->query($sql);
  60. if (!$db->num_rows($res)) {
  61. header('HTTP/1.1 400: Bad Request');
  62. header('Warning: images not found in db L.' . __LINE__);
  63. exit;
  64. }
  65. if ($image_row = $db->fetch( $res )) {
  66. $etag = md5($image_row->ID . $image_row->A_CREATE_DATE);
  67. if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $image_row->A_CREATE_DATE
  68. || trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) {
  69. header("HTTP/1.1 304 Not Modified");
  70. exit;
  71. }
  72. $expire_date = mktime(0, 0, 0, date('m') + 3, date('d'), date('Y'));
  73. if ($image_resize) {
  74. list($resize_w, $resize_h) = explode('x', $image_resize, 2);
  75. $resize_w = intval($resize_w); $resize_h = intval($resize_h);
  76. if ($resize_w > 0 && $resize_h > 0) {
  77. $im = imagecreatefromstring( $image_row->IMAGE );
  78. $image_resized = DB_Image::resize_image_from_data($im, $resize_w, $resize_h);
  79. header("Content-type: ".$image_row->TYPE);
  80. //header("Cache-control: public");
  81. header("Cache-control: public");
  82. header("Pragma: public");// default 'no-cache'
  83. header("Etag: ".$etag);
  84. header("Expires: " . gmdate("D, d M Y H:i:s", $expire_date) . " GMT");
  85. header("Last-Modified: " . gmdate("D, d M Y H:i:s", $image_row->A_CREATE_DATE) . " GMT");
  86. if ($image_row->TYPE == 'image/png') {
  87. imagepng($image_resized);
  88. } else if ($image_row->TYPE == 'image/jpeg' || $image_row->TYPE == 'image/jpg') {
  89. imagejpeg($image_resized);
  90. } else if ($image_row->TYPE == 'image/gif') {
  91. imagegif($image_resized);
  92. }
  93. } else {
  94. echo'ERROR wrong param resize (WxH)';
  95. }
  96. exit;
  97. }
  98. //echo'<pre style="max-height:200px;overflow:auto;border:1px solid red;">';print_r($image_row);echo'</pre>';
  99. //header("Content-type: ".$image_row->TYPE);
  100. header("Content-type: ".$image_row->TYPE);
  101. header("Cache-control: public");
  102. header("Pragma: public");// default 'no-cache'
  103. header("Etag: ".$etag);
  104. header("Content-length: ".$image_row->SIZE);
  105. header("Expires: " . gmdate("D, d M Y H:i:s", $expire_date) . " GMT");
  106. header("Last-Modified: " . gmdate("D, d M Y H:i:s", $image_row->A_CREATE_DATE) . " GMT");
  107. //echo stripslashes($image_row->IMAGE);
  108. print $image_row->IMAGE;
  109. //file_put_contents('/home/pl/projekty/kyoritsu.pl/src/1.jpg', $image_row->IMAGE);
  110. } else {
  111. header('HTTP/1.1 400: Bad Request');
  112. header('Warning: image not found in db L.' . __LINE__);
  113. }
  114. exit;
  115. }