PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/include/javascript/getYUIComboFile.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 97 lines | 48 code | 11 blank | 38 comment | 8 complexity | 79212b9800ede659ec34081b99ad0517 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM Community Edition is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. if (empty($_REQUEST)) die();
  38. $yui_path = array(
  39. "2.9.0" => "include/javascript/yui",
  40. "2_9_0" => "include/javascript/yui",
  41. "3.3.0" => "include/javascript/yui3",
  42. "3_3_0" => "include/javascript/yui3"
  43. );
  44. $types = array(
  45. "js" => "application/x-javascript",
  46. "css" => "text/css",
  47. );
  48. $out = "";
  49. $contentType = "";
  50. $allpath = "";
  51. foreach ($_REQUEST as $param => $val)
  52. {
  53. //No backtracking in the path
  54. if (strpos($param, "..") !== false)
  55. continue;
  56. $version = explode("/", $param);
  57. $version = $version[0];
  58. if (empty($yui_path[$version])) continue;
  59. $path = $yui_path[$version] . substr($param, strlen($version));
  60. $extension = substr($path, strrpos($path, "_") + 1);
  61. //Only allowed file extensions
  62. if (empty($types[$extension]))
  63. continue;
  64. if (empty($contentType))
  65. {
  66. $contentType = $types[$extension];
  67. }
  68. //Put together the final filepath
  69. $path = substr($path, 0, strrpos($path, "_")) . "." . $extension;
  70. $contents = '';
  71. if (is_file($path)) {
  72. $out .= "/*" . $path . "*/\n";
  73. $contents = file_get_contents($path);
  74. $out .= $contents . "\n";
  75. }
  76. $path = empty($contents) ? $path : $contents;
  77. $allpath .= md5($path);
  78. }
  79. $etag = '"'.md5($allpath).'"';
  80. // try to use the content cached locally if it's the same as we have here.
  81. header("Cache-Control: private");
  82. header("Pragma: dummy=bogus");
  83. header("Etag: $etag");
  84. header('Expires: ' . gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
  85. header("Content-Type: $contentType");
  86. echo ($out);