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

/admin/loader.php

http://lazycms.googlecode.com/
PHP | 114 lines | 62 code | 4 blank | 48 comment | 11 complexity | cc3db801cb913f4146e46a2c30e4fc3b MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1
  1. <?php
  2. /**
  3. * +---------------------------------------------------------------------------+
  4. * | LL LLLL LL L LLLL LLLL |
  5. * | LL LL L LLL LL LL L LL LL |
  6. * | LL LLLL LLLLL LL LL LL LLLL LLL LL LL LL LL |
  7. * | LL LL LL LL LL LL L LLL LL LLLLL LL LL LL |
  8. * | LL LLLLL LL LLLL LL L L LL LLLLL LL LL LL |
  9. * | LL LL LL LL LLLL LL L LL LL LLLL LL |
  10. * | LL LL LL LL LL LL L L LL L LL LLLL LL |
  11. * | LLLLLL LLLLL LLLLL LL LLLL L LL LLLL LL LLLLLL |
  12. * | LL |
  13. * | LL |
  14. * +---------------------------------------------------------------------------+
  15. * | Copyright (C) 2007-2010 LazyCMS.com All rights reserved. |
  16. * +---------------------------------------------------------------------------+
  17. * | LazyCMS is free software. See LICENSE for copyright notices and details. |
  18. * +---------------------------------------------------------------------------+
  19. */
  20. /**
  21. * ??????
  22. *
  23. * Set this to error_reporting( E_ALL ) or error_reporting( E_ALL | E_STRICT ) for debugging
  24. */
  25. // ????????
  26. defined('ADMIN_PATH') or define('ADMIN_PATH',dirname(__FILE__));
  27. // ????
  28. define('NO_REDIRECT', true);
  29. // ??????
  30. include ADMIN_PATH.'/admin.php'; error_reporting(0);
  31. // ??????
  32. $type = isset($_GET['type']) ? $_GET['type'] : null;
  33. $ver = isset($_GET['ver']) ? $_GET['ver'] : 0;
  34. $load = isset($_GET['load']) ? $_GET['load'] : null;
  35. $load = preg_replace('/[^a-z0-9,_\-\.]+/i', '', $load);
  36. $ckey = sprintf('loader.%s.%s.%s', $type, $load, $ver);
  37. $load = explode(',', $load);
  38. if (empty($load)) exit;
  39. // ???????365?
  40. $expire = 31536000;
  41. // ????header
  42. header('Expires: ' . gmdate( "D, d M Y H:i:s", time() + $expire ) . ' GMT');
  43. header("Cache-Control: public, max-age={$expire}");
  44. // ?????
  45. /*$out = fcache_get($ckey);
  46. if (fcache_not_null($out)) {
  47. if ($type == 'css') {
  48. header('Content-Type: text/css; charset=utf-8');
  49. } elseif ($type == 'js') {
  50. header('Content-Type: application/x-javascript; charset=utf-8');
  51. }
  52. echo $out; exit();
  53. }*/
  54. // ????
  55. $out = '';
  56. switch ($type) {
  57. case 'css':
  58. header('Content-Type: text/css; charset=utf-8');
  59. $loads = loader_get_files($type, $load);
  60. foreach ($load as $css) {
  61. if (isset($loads[$css])) {
  62. foreach ($loads[$css] as $src) {
  63. $content = file_get_contents($src) . "\n";
  64. if (!strncasecmp($src,COM_PATH,strlen(COM_PATH))) {
  65. $content = str_replace('../images/',ROOT.'common/images/',$content);
  66. $content = str_replace('../editor/',ROOT.'common/editor/',$content);
  67. } else {
  68. $content = str_replace('../images/',ADMIN.'images/',$content);
  69. }
  70. $out.= $content;
  71. }
  72. }
  73. }
  74. // ???????
  75. $out = preg_replace('@(\/\*(.+)\*\/)|(\r\n|\n|\t)@sU', '', $out);
  76. break;
  77. case 'js':
  78. header('Content-Type: application/x-javascript; charset=utf-8');
  79. $loads = loader_get_files($type, $load);
  80. foreach ($load as $js) {
  81. if (isset($loads[$js])) {
  82. foreach ($loads[$js] as $src) {
  83. $index = strrpos($src, '.');
  84. $src_min = substr($src, 0, $index).'.min'.substr($src, $index);
  85. // min??????
  86. $is_file = is_file($src_min);
  87. // ????
  88. $content = file_get_contents($is_file ? $src_min : $src);
  89. // ??????
  90. if (substr($src,-10) == 'lazycms.js') {
  91. $content = preg_replace('/^(\\s*ADMIN).+$/m',"\$1: '".ADMIN."',",$content);
  92. $content = preg_replace('/^(\\s*ROOT).+$/m',"\$1: '".ROOT."',",$content);
  93. }
  94. // ?????????
  95. elseif (substr($src,-9) == 'common.js') {
  96. $content = preg_replace('/^(\\s*LazyCMS\.UpLinkExt\\s*).+$/m', "\$1= '".C('UPFILE-Exts')."';", $content);
  97. $content = preg_replace('/^(\\s*LazyCMS\.UpImgExt\\s*).+$/m', "\$1= '".C('UPIMG-Exts')."';", $content);
  98. }
  99. // jsmin
  100. if (!$is_file && filesize($src) <= 50*1024) $content = jsmin($content);
  101. $out.= "/* file:".rel_root($src)." */\n". $content . "\n\n";
  102. }
  103. }
  104. }
  105. break;
  106. }
  107. // ???????
  108. fcache_set($ckey, $out, $expire);
  109. // ????
  110. echo $out;