strings.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. $strings_php = true;
  3. //*************************************************************************
  4. // Count the number of occurances of $needle are in $haystack.
  5. //*************************************************************************
  6. function countCharInString($haystack, $needle) {
  7. $len = strlen($haystack);
  8. for ($i = 0; $i < $len; $i++) {
  9. if ($haystack[$i] == $needle)
  10. $count++;
  11. }
  12. return $count;
  13. }
  14. //*************************************************************************
  15. // Read from the back of $haystack until $needle is found, or the begining
  16. // of the $haystack is reached.
  17. //*************************************************************************
  18. function readShortMailboxName($haystack, $needle) {
  19. if (substr($haystack, -1) == $needle)
  20. $haystack = substr($haystack, 0, strlen($haystack) - 1);
  21. if (strrpos($haystack, $needle)) {
  22. $pos = strrpos($haystack, $needle) + 1;
  23. $data = substr($haystack, $pos, strlen($haystack));
  24. } else {
  25. $data = $haystack;
  26. }
  27. return $data;
  28. }
  29. // Wraps text at $wrap characters
  30. function wordWrap($passed, $wrap) {
  31. $passed = str_replace("&gt;", ">", $passed);
  32. $passed = str_replace("&lt;", "<", $passed);
  33. $words = explode(" ", trim($passed));
  34. $i = 0;
  35. $line_len = strlen($words[$i])+1;
  36. $line = "";
  37. while ($i < count($words)) {
  38. while ($line_len < $wrap) {
  39. $line = "$line$words[$i] ";
  40. $i++;
  41. $line_len = $line_len + strlen($words[$i])+1;
  42. }
  43. $line_len = strlen($words[$i])+1;
  44. if ($line_len < $wrap) {
  45. if ($i < count($words)) // don't <BR> the last line
  46. $line = "$line\n";
  47. } else {
  48. $endline = $words[$i];
  49. while ($line_len >= $wrap) {
  50. $bigline = substr($endline, 0, $wrap);
  51. $endline = substr($endline, $wrap, strlen($endline));
  52. $line_len = strlen($endline);
  53. $line = "$line$bigline<BR>";
  54. }
  55. $line = "$line$endline<BR>";
  56. $i++;
  57. }
  58. }
  59. $line = str_replace(">", "&gt;", $line);
  60. $line = str_replace("<", "&lt;", $line);
  61. return $line;
  62. }
  63. /** Returns an array of email addresses **/
  64. function parseAddrs($text) {
  65. if (trim($text) == "") {
  66. return;
  67. }
  68. $text = str_replace(" ", "", $text);
  69. $text = str_replace(",", ";", $text);
  70. $array = explode(";", $text);
  71. return $array;
  72. }
  73. /** Returns a line of comma separated email addresses from an array **/
  74. function getLineOfAddrs($array) {
  75. $to_line = "";
  76. for ($i = 0; $i < count($array); $i++) {
  77. if ($to_line)
  78. $to_line = "$to_line, $array[$i]";
  79. else
  80. $to_line = "$array[$i]";
  81. }
  82. return $to_line;
  83. }
  84. function translateText($body, $wrap_at, $charset) {
  85. include ("../functions/url_parser.php");
  86. /** Add any parsing you want to in here */
  87. $body = trim($body);
  88. $body_ary = explode("\n", $body);
  89. for ($i = 0; $i < count($body_ary); $i++) {
  90. $line = $body_ary[$i];
  91. $line = "^^$line";
  92. //$line = str_replace(">", "&gt;", $line);
  93. //$line = str_replace("<", "&lt;", $line);
  94. //$line = htmlspecialchars($line);
  95. if (strlen($line) >= $wrap_at) // -2 because of the ^^ at the beginning
  96. $line = wordWrap($line, $wrap_at);
  97. $line = charset_decode($charset, $line);
  98. $line = str_replace(" ", "&nbsp;", $line);
  99. $line = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $line);
  100. $line = nl2br($line);
  101. if (strpos(trim(str_replace("&nbsp;", "", $line)), "&gt;&gt;") == 2) {
  102. $line = substr($line, 2, strlen($line));
  103. $line = "<TT><FONT COLOR=FF0000>$line</FONT></TT><BR>\n";
  104. } else if (strpos(trim(str_replace("&nbsp;", "", $line)), "&gt;") == 2) {
  105. $line = substr($line, 2, strlen($line));
  106. $line = "<TT><FONT COLOR=800000>$line</FONT></TT><BR>\n";
  107. } else {
  108. $line = substr($line, 2, strlen($line));
  109. $line = "<TT><FONT COLOR=000000>$line</FONT></TT><BR>\n";
  110. }
  111. $line = parseEmail ($line);
  112. $line = parseUrl ($line);
  113. $new_body[$i] = "$line";
  114. }
  115. $bdy = implode("\n", $new_body);
  116. return $bdy;
  117. }
  118. /* SquirrelMail version number -- DO NOT CHANGE */
  119. $version = "0.4pre1";
  120. function find_mailbox_name ($mailbox) {
  121. $mailbox = trim($mailbox);
  122. if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") {
  123. $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
  124. $pos = strrpos ($mailbox, "\"")+1;
  125. $box = substr($mailbox, $pos);
  126. } else {
  127. $box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox));
  128. }
  129. return $box;
  130. }
  131. function replace_spaces ($string) {
  132. return str_replace(" ", "&nbsp;", $string);
  133. }
  134. function replace_escaped_spaces ($string) {
  135. return str_replace("&nbsp;", " ", $string);
  136. }
  137. ?>