import.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. require_once 'config.php';
  3. //加入一个调试开关
  4. if(array_key_exists('debug', $_GET))
  5. Config::$DEBUG = true;
  6. if(!Config::$DEBUG){
  7. header("Content-type: text/javascript; charset=utf-8");
  8. header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
  9. }
  10. /*
  11. * Tangram
  12. * Copyright 2009 Baidu Inc. All rights reserved.
  13. *
  14. * path: import.php
  15. * author: berg
  16. * version: 1.0
  17. * date: 2010/07/18 23:57:52
  18. *
  19. * @fileoverview * import.js的php版本
  20. * 接受一个f参数,格式和import.js相同,自动合并js并输出
  21. * 此外,本脚本支持引入一个包所有文件(其实也就是一个目录下的所有js文件,**不递归**)
  22. * IE下,get请求不能超过2083字节,请注意。
  23. */
  24. $cov = array_key_exists('cov', $_GET) ? true : false;
  25. $import = 'import.js';
  26. function importSrc($cov){
  27. global $import;
  28. $source = '';
  29. require_once 'config.php';
  30. if(file_exists(Config::$test_PATH.$import)){
  31. $cnt = file_get_contents(Config::$test_PATH.$import);
  32. }
  33. if($cnt == ''){
  34. if(Config::$DEBUG)
  35. print "fail read file : ".Config::$test_PATH.$import;
  36. return '';
  37. }
  38. $is = array();
  39. //正则匹配,提取所有(///import xxx;)中的xxx
  40. preg_match_all('/\/\/\/import\s+([^;]+);?/ies', $cnt, $is, PREG_PATTERN_ORDER);
  41. foreach($is[1] as $i) {
  42. // $dd = $i;
  43. //$path = join('/', explode('.', $i)).'.js';
  44. $path = $i.'.js'; //为了支持xx.xx.js类型的文件名而修改 田丽丽
  45. if($cov){
  46. $covpath = Config::$COVERAGE_PATH.$path;
  47. if(file_exists($covpath)){
  48. if(Config::$DEBUG) var_dump($covpath);
  49. $_source=file_get_contents($covpath);
  50. $source.= $_source;
  51. }
  52. else if(Config::$DEBUG)print "fail read file : ".Config::$COVERAGE_PATH.$path;
  53. }
  54. else {
  55. foreach(Config::$SOURCE_PATH as $i=>$d){
  56. // if(preg_match("/editorui/",$dd)){
  57. // echo "*************".file_get_contents($d.$path)."************";
  58. // }
  59. if(file_exists($d.$path)){
  60. $source.= file_get_contents($d.$path);
  61. $source.="\n";//读取文件内容必须加个回车
  62. break;
  63. }
  64. }
  65. }
  66. }
  67. return $source;
  68. }
  69. //update by bell 2011-03-25, 更新覆盖率相关逻辑
  70. echo importSrc($cov);
  71. ?>