PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/oscommerce-2.2rc2/includes/functions/sts.php

http://myopensources.googlecode.com/
PHP | 152 lines | 78 code | 33 blank | 41 comment | 13 complexity | 1331873359b6de93a746f17c4598b21c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /*
  3. $Id: sts.php,v 4.5.5 2006/03/06 22:30:54 Rigadin Exp $
  4. osCommerce, Open Source E-Commerce Solutions
  5. http://www.oscommerce.com
  6. Released under the GNU General Public License
  7. STS v4.5.1 by Rigadin2 (rigadin@osc-help.net)
  8. Based on: Simple Template System (STS) - Copyright (c) 2004 Brian Gallagher - brian@diamondsea.com
  9. */
  10. // STRIP_UNWANTED_TAGS() - Remove leading and trailing <tr><td> from strings
  11. // Modified in v4.5.1 to not check <table> tags but <td>
  12. // Modified in v4.5.5 to work with <td class="xxx"> and not only with <td>
  13. function sts_strip_unwanted_tags($tmpstr, $commentlabel) {
  14. // Now lets remove the <tr><td> that the require puts in front of the tableBox
  15. $tablestart = strpos($tmpstr, "<td"); // v4.5.5
  16. // If empty, return nothing
  17. if ($tablestart < 1) {
  18. return "\n<!-- start $commentlabel //-->\n$tmpstr\n<!-- end $commentlabel //-->\n";
  19. }
  20. $tmpstr = substr($tmpstr, strpos ($tmpstr,">",$tablestart)+1); // strip off stuff before (and including <td>, v4.5.5
  21. // Now lets remove the </td></tr> at the end of the tableBox output
  22. // strrpos only works for chars, not strings, so we'll cheat and reverse the string and then use strpos
  23. $tmpstr = strrev($tmpstr);
  24. $tableend = strpos($tmpstr, strrev("</td>"), 1);
  25. $tmpstr = substr($tmpstr, $tableend+5); // strip off stuff after </table>
  26. // Now let's un-reverse it
  27. $tmpstr = strrev($tmpstr);
  28. // print "<hr>After cleaning tmpstr:" . strlen($tmpstr) . ": FULL=[". htmlspecialchars($tmpstr) . "]<hr>\n";
  29. return "\n<!-- start $commentlabel //-->\n$tmpstr\n<!-- end $commentlabel //-->\n";
  30. }
  31. // STRIP_CONTENT_TAGS() - Remove text before "body_text" and after "body_text_eof"
  32. function sts_strip_content_tags($tmpstr, $commentlabel) {
  33. // Now lets remove the <tr><td> that the require puts in front of the tableBox
  34. $tablestart = strpos($tmpstr, "<table");
  35. $formstart = strpos($tmpstr, "<form");
  36. // If there is a <form> tag before the <table> tag, keep it
  37. if ($formstart !== false and $formstart < $tablestart) {
  38. $tablestart = $formstart;
  39. $formfirst = true;
  40. }
  41. // If empty, return nothing
  42. if ($tablestart < 1) {
  43. return "\n<!-- start $commentlabel //-->\n$tmpstr\n<!-- end $commentlabel //-->\n";
  44. }
  45. $tmpstr = substr($tmpstr, $tablestart); // strip off stuff before <table>
  46. // Now lets remove the </td></tr> at the end of the tableBox output
  47. // strrpos only works for chars, not strings, so we'll cheat and reverse the string and then use strpos
  48. $tmpstr = strrev($tmpstr);
  49. if ($formfirst == true) {
  50. $tableend = strpos($tmpstr, strrev("</form>"), 1);
  51. } else {
  52. $tableend = strpos($tmpstr, strrev("</table>"), 1);
  53. }
  54. $tmpstr = substr($tmpstr, $tableend); // strip off stuff after <!-- body_text_eof //-->
  55. // Now let's un-reverse it
  56. $tmpstr = strrev($tmpstr);
  57. // print "<hr>After cleaning tmpstr:" . strlen($tmpstr) . ": FULL=[". htmlspecialchars($tmpstr) . "]<hr>\n";
  58. return "\n<!-- start $commentlabel //-->\n$tmpstr\n<!-- end $commentlabel //-->\n";
  59. }
  60. function sts_read_template_file ($template_file){
  61. // Open Template file and read into a variable
  62. if (! file_exists($template_file)) {
  63. print 'Template file does not exist: ['.$template_file.']';
  64. return '';
  65. }
  66. ob_start(); // Start capture to buffer
  67. require $template_file; // Includes the template, this way php code can be used in templates
  68. $template_html = ob_get_contents(); // Get content of buffer
  69. ob_end_clean(); // Clear out the capture buffer
  70. return $template_html;
  71. }
  72. function get_javascript($tmpstr, $commentlabel) {
  73. // Now lets remove the <tr><td> that the require puts in front of the tableBox
  74. $tablestart = strpos($tmpstr, "<script");
  75. // If empty, return nothing
  76. if ($tablestart === false) {
  77. return "\n<!-- start $commentlabel //-->\n\n<!-- end $commentlabel //-->\n";
  78. }
  79. $tmpstr = substr($tmpstr, $tablestart); // strip off stuff before <table>
  80. // Now lets remove the </td></tr> at the end of the tableBox output
  81. // strrpos only works for chars, not strings, so we'll cheat and reverse the string and then use strpos
  82. $tmpstr = strrev($tmpstr);
  83. $tableend = strpos($tmpstr, strrev("</script>"), 1);
  84. $tmpstr = substr($tmpstr, $tableend); // strip off stuff after </table>
  85. // Now let's un-reverse it
  86. $tmpstr = strrev($tmpstr);
  87. // print "<hr>After cleaning tmpstr:" . strlen($tmpstr) . ": FULL=[". htmlspecialchars($tmpstr) . "]<hr>\n";
  88. return "\n<!-- start $commentlabel //-->\n$tmpstr\n<!-- end $commentlabel //-->\n";
  89. }
  90. // Return the value between $startstr and $endstr in $tmpstr
  91. function str_between($tmpstr, $startstr, $endstr) {
  92. $startpos = strpos($tmpstr, $startstr);
  93. // If empty, return nothing
  94. if ($startpos === false) {
  95. return "";
  96. }
  97. $tmpstr = substr($tmpstr, $startpos + strlen($startstr)); // strip off stuff before $start
  98. // Now lets remove the </td></tr> at the end of the tableBox output
  99. // strrpos only works for chars, not strings, so we'll cheat and reverse the string and then use strpos
  100. $tmpstr = strrev($tmpstr);
  101. $endpos = strpos($tmpstr, strrev($endstr), 1);
  102. $tmpstr = substr($tmpstr, $endpos + strlen($endstr)); // strip off stuff after </table>
  103. // Now let's un-reverse it
  104. $tmpstr = strrev($tmpstr);
  105. return $tmpstr;
  106. }
  107. function sortbykeylength($a,$b) {
  108. $alen = strlen($a);
  109. $blen = strlen($b);
  110. if ($alen == $blen) $r = 0;
  111. if ($alen < $blen) $r = 1;
  112. if ($alen > $blen) $r = -1;
  113. return $r;
  114. }
  115. ?>