PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/fileman/admin/fileman_common_js.php

https://gitlab.com/alexprowars/bitrix
PHP | 79 lines | 69 code | 9 blank | 1 comment | 13 complexity | eab11e2b22148c6921bb686664e79b8f MD5 | raw file
  1. <?
  2. session_cache_limiter("public");
  3. require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_before.php");
  4. $return304 = true;
  5. function GetFileContent($path)
  6. {
  7. clearstatcache();
  8. if(!file_exists($path) || !is_file($path))
  9. return false;
  10. if(filesize($path) <= 0)
  11. return "";
  12. $fd = fopen($path, "rb");
  13. $contents = fread($fd, filesize($path));
  14. fclose ($fd);
  15. return $contents;
  16. }
  17. $arr = Array(
  18. 'common.js',
  19. 'editor.js',
  20. 'parser.js',
  21. 'editor_php.js',
  22. 'controls.js',
  23. 'bars.js',
  24. 'toolbarbuttons.js',
  25. 'table_operations.js'
  26. );
  27. if (isset($_GET['s']) && $_GET['s'] <> '')
  28. {
  29. $s = $_GET['s'];
  30. if (mb_strpos($s, 'em') !== false)
  31. $arr[] = "bars_ex.js";
  32. if (mb_strpos($s, 'c2') !== false)
  33. $arr[] = "components2.js";
  34. if (mb_strpos($s, 's') !== false)
  35. $arr[] = "snippets.js";
  36. }
  37. $files_mod_str = 'bx_';
  38. $l = count($arr);
  39. for($i = 0; $i < $l; $i++)
  40. @$files_mod_str .= filemtime($_SERVER['DOCUMENT_ROOT'].'/bitrix/admin/htmleditor2/'.$arr[$i]);
  41. $files_mod_hash = md5($files_mod_str);
  42. if (!isset($_SERVER['HTTP_IF_NONE_MATCH']) || $_SERVER['HTTP_IF_NONE_MATCH'] != '"'.$files_mod_hash.'"')
  43. {
  44. header("Pragma: private");
  45. header("Cache-Control: public, max-age=2592000"); // 30 days
  46. header('ETag: "'.$files_mod_hash.'"');
  47. header("Content-Type: application/x-javascript; charset=".LANG_CHARSET);
  48. for($i = 0; $i < count($arr); $i++)
  49. {
  50. $script_filename = $arr[$i];
  51. $script_content = GetFileContent($_SERVER['DOCUMENT_ROOT'].'/bitrix/admin/htmleditor2/'.$script_filename);
  52. $script_content = preg_replace("/\t/", '', $script_content);
  53. //$script_content = preg_replace("/(.*)\/\/.*/", "\$1", $script_content);
  54. $script_content = preg_replace("/\r\n/", "\n", $script_content);
  55. echo "\n/*:::: $script_filename ::::*/\n";
  56. echo $script_content;
  57. }
  58. }
  59. else
  60. {
  61. CHTTP::SetStatus("304 Not Modified");
  62. header("Pragma: private");
  63. header("Cache-Control: public, max-age=2592000"); // 30 days
  64. header('ETag: "'.$files_mod_hash.'"');
  65. header("Content-Type: application/x-javascript; charset=".LANG_CHARSET);
  66. while(ob_get_level()) ob_end_clean();
  67. exit;
  68. }
  69. require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_admin_js.php");
  70. ?>