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

/source code/includes/mxi/MXI_functions.inc.php

http://quan-li-cua-hang-bang-dia.googlecode.com/
PHP | 163 lines | 126 code | 13 blank | 24 comment | 31 complexity | 336c9576d4756f30c0aa267c0125f6f2 MD5 | raw file
  1. <?php
  2. /*
  3. * ADOBE SYSTEMS INCORPORATED
  4. * Copyright 2007 Adobe Systems Incorporated
  5. * All Rights Reserved
  6. *
  7. * NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the
  8. * terms of the Adobe license agreement accompanying it. If you have received this file from a
  9. * source other than Adobe, then your use, modification, or distribution of it requires the prior
  10. * written permission of Adobe.
  11. */
  12. /*
  13. Copyright (c) InterAKT Online 2000-2006. All rights reserved.
  14. */
  15. /**
  16. include a PHP page (containing HTML/HEAD/BODY and strips away the outer HTML
  17. then eval the code
  18. - overcome the SBs can't be applied on a separate page thing
  19. **/
  20. ob_start();
  21. $GLOBALS['KT_MXI_parse_css'] = true;
  22. $GLOBALS['KT_dir_depth'] = array();
  23. $GLOBALS['KT_dir_depth'][] = array(
  24. 'relpath'=> '', 'dir'=>getcwd().DIRECTORY_SEPARATOR, 'dirrelpath'=>''
  25. );
  26. function mxi_getBaseURL() {
  27. return KT_getUriFolder();
  28. }
  29. function mxi_includes_start($fName) {
  30. if (!isset($GLOBALS['KT_REL_PATH'])) {
  31. $GLOBALS['KT_REL_PATH'] = "";
  32. }
  33. $tmpArr = array();
  34. $tmpArr['dirRelPath'] = dirname($fName)."/";
  35. if ($tmpArr['dirRelPath'] == "./") {
  36. $tmpArr['dirRelPath'] = "";
  37. }
  38. $tmpArr['relpath'] = KT_CanonizeRelPath($GLOBALS['KT_REL_PATH'].$tmpArr['dirRelPath']);
  39. $tmpArr['relpath'] = ($GLOBALS['KT_REL_PATH'].$tmpArr['dirRelPath']);
  40. $tmpArr['dir'] = getcwd().DIRECTORY_SEPARATOR;
  41. $GLOBALS['KT_dir_depth'][] = $tmpArr;
  42. $GLOBALS['KT_REL_PATH'] = $tmpArr['relpath'];
  43. if ($tmpArr['dirRelPath'] != "") {
  44. $chk = @chdir($tmpArr['dirRelPath']);
  45. if ($chk === false) {
  46. die(KT_getResource('PHP_CHDIR_FAILED', 'MXI', array($tmpArr['dirRelPath'])));
  47. }
  48. }
  49. ob_start();
  50. if (isset($GLOBALS['tNGs'])) {
  51. if (!isset($GLOBALS['arrTNGs'])) {
  52. $GLOBALS['arrTNGs'] = array();
  53. }
  54. $GLOBALS['arrTNGs'][] = $GLOBALS['tNGs'];
  55. }
  56. }
  57. function mxi_includes_end() {
  58. $content = ob_get_contents();
  59. ob_end_clean();
  60. $tmpArr = array_pop($GLOBALS['KT_dir_depth']);
  61. $GLOBALS['KT_REL_PATH'] = $tmpArr['relpath'];
  62. // dirty hack IIS
  63. $chk = true;
  64. if (substr($tmpArr['dir'],0,strlen($tmpArr['dir'])-1) !== realpath(dirname(__FILE__).'/../../')){
  65. $chk = chdir($tmpArr['dir']);
  66. } elseif (getcwd() !== realpath(dirname(__FILE__).'/../../')){
  67. chdir (realpath(dirname(__FILE__)));
  68. $chk = chdir ('../../');
  69. }
  70. if ($chk === false) {
  71. die(KT_getResource('PHP_CHDIR_FAILED', 'MXI', array($tmpArr['dirRelPath'])));
  72. }
  73. $content = mxi_ParseHtml($content, $tmpArr['relpath']);
  74. $GLOBALS['KT_REL_PATH'] = $GLOBALS['KT_dir_depth'][count($GLOBALS['KT_dir_depth'])-1]['relpath'];
  75. echo $content;
  76. if (isset($GLOBALS['arrTNGs']) && count($GLOBALS['arrTNGs']) > 0) {
  77. $GLOBALS['tNGs'] = array_pop($GLOBALS['arrTNGs']);
  78. }
  79. }
  80. function mxi_ParseHtml($text, $relPath) {
  81. if (!isset($GLOBALS['mxi_scripts_hash'])) {
  82. $GLOBALS['mxi_scripts_hash'] = array();
  83. }
  84. if (!isset($GLOBALS['mxi_links_hash'])) {
  85. $GLOBALS['mxi_links_hash'] = array();
  86. }
  87. if (!isset($GLOBALS['mxi_styles_hash'])) {
  88. $GLOBALS['mxi_styles_hash'] = array();
  89. }
  90. $ret = KT_transformsPaths($relPath, $text, false);
  91. // get the <body>
  92. $body = $ret;
  93. $body = preg_replace("/^[\w\W]*<body[^>]*>/i", "", $body);
  94. $body = preg_replace("/<\/body>[\w\W]*$/i", "", $body);
  95. // get the <head>
  96. $head = $ret;
  97. $head = preg_replace("/^[\w\W]*<head[^>]*>/i", "", $head);
  98. $head = preg_replace("/<\/head>[\w\W]*$/i", "", $head);
  99. $links = "";
  100. $styles = "";
  101. if (isset($GLOBALS['KT_MXI_parse_css']) && $GLOBALS['KT_MXI_parse_css'] == true) {
  102. // get the external CSS
  103. preg_match_all("/<link[^>]*>[\n\r]*/i", $head, $links);
  104. if (sizeof($links) == 1) {
  105. $links = $links[0];
  106. foreach ($links as $k => $link) {
  107. $md5_link = md5($link);
  108. if (in_array($md5_link, $GLOBALS['mxi_links_hash'])) {
  109. unset($links[$k]);
  110. } else {
  111. array_push($GLOBALS['mxi_links_hash'], $md5_link);
  112. }
  113. }
  114. $links = implode("", $links);
  115. }
  116. // get the inline CSS
  117. preg_match_all("/<style[^>]*>[\w\W]*?<\/style>[\n\r]*/i", $head, $styles);
  118. if (sizeof($styles) == 1) {
  119. $styles = $styles[0];
  120. foreach ($styles as $k => $style) {
  121. $md5_style = md5($style);
  122. if (in_array($md5_style, $GLOBALS['mxi_styles_hash'])) {
  123. unset($styles[$k]);
  124. } else {
  125. array_push($GLOBALS['mxi_styles_hash'], $md5_style);
  126. }
  127. }
  128. $styles = implode("", $styles);
  129. }
  130. }
  131. // get the JavaScripts
  132. preg_match_all("/<script[^>]*>[\w\W]*?<\/script>[\n\r]*/i", $head, $scripts);
  133. if (sizeof($scripts) == 1) {
  134. $scripts = $scripts[0];
  135. foreach ($scripts as $k => $script) {
  136. $md5_script = md5($script);
  137. if (in_array($md5_script, $GLOBALS['mxi_scripts_hash'])) {
  138. unset($scripts[$k]);
  139. } else {
  140. array_push($GLOBALS['mxi_scripts_hash'], $md5_script);
  141. }
  142. }
  143. $scripts = implode("", $scripts);
  144. } else {
  145. $scripts = "";
  146. }
  147. $ret = $links.$styles.$scripts.$body;
  148. return $ret;
  149. }
  150. ?>