strings.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. // Searches for the next position in a string minus white space
  30. function next_pos_minus_white ($haystack, $pos) {
  31. while (substr($haystack, $pos, 1) == " " ||
  32. substr($haystack, $pos, 1) == "\t" ||
  33. substr($haystack, $pos, 1) == "\n" ||
  34. substr($haystack, $pos, 1) == "\r") {
  35. if ($pos >= strlen($haystack))
  36. return -1;
  37. $pos++;
  38. }
  39. return $pos;
  40. }
  41. // Wraps text at $wrap characters
  42. function sqWordWrap($passed, $wrap) {
  43. $passed = str_replace("&gt;", ">", $passed);
  44. $passed = str_replace("&lt;", "<", $passed);
  45. $words = explode(" ", trim($passed));
  46. $i = 0;
  47. $line_len = strlen($words[$i])+1;
  48. $line = "";
  49. if (count($words) > 1) {
  50. while ($i < count($words)) {
  51. while ($line_len < $wrap) {
  52. $line = "$line$words[$i] ";
  53. $i++;
  54. $line_len = $line_len + strlen($words[$i])+1;
  55. }
  56. $line_len = strlen($words[$i])+1;
  57. if ($line_len < $wrap) {
  58. if ($i < count($words)) // don't <BR> the last line
  59. $line = "$line\n";
  60. } else {
  61. $endline = $words[$i];
  62. while ($line_len >= $wrap) {
  63. $bigline = substr($endline, 0, $wrap);
  64. $endline = substr($endline, $wrap, strlen($endline));
  65. $line_len = strlen($endline);
  66. $line = "$line$bigline<BR>";
  67. }
  68. $line = "$line$endline<BR>";
  69. $i++;
  70. }
  71. }
  72. } else {
  73. $line = $words[0];
  74. }
  75. $line = str_replace(">", "&gt;", $line);
  76. $line = str_replace("<", "&lt;", $line);
  77. return $line;
  78. }
  79. /** Returns an array of email addresses **/
  80. function parseAddrs($text) {
  81. if (trim($text) == "") {
  82. return;
  83. }
  84. $text = str_replace(" ", "", $text);
  85. $text = ereg_replace( '"[^"]*"', "", $text);
  86. $text = str_replace(",", ";", $text);
  87. $array = explode(";", $text);
  88. for ($i = 0; $i < count ($array); $i++) {
  89. $array[$i] = eregi_replace ("^.*\<", "", $array[$i]);
  90. $array[$i] = eregi_replace ("\>.*$", "", $array[$i]);
  91. }
  92. return $array;
  93. }
  94. /** Returns a line of comma separated email addresses from an array **/
  95. function getLineOfAddrs($array) {
  96. if (is_array($array)) {
  97. $to_line = implode(", ", $array);
  98. $to_line = trim(ereg_replace(",,+", ",", $to_line));
  99. } else {
  100. $to_line = "";
  101. }
  102. return $to_line;
  103. }
  104. function translateText($body, $wrap_at, $charset) {
  105. global $where, $what; // from searching
  106. if (!isset($url_parser_php)) {
  107. include "../functions/url_parser.php";
  108. }
  109. $body_ary = explode("\n", $body);
  110. for ($i=0; $i < count($body_ary); $i++) {
  111. $line = $body_ary[$i];
  112. $line = charset_decode($charset, $line);
  113. if (strlen($line) - 2 >= $wrap_at) {
  114. $line = sqWordWrap($line, $wrap_at);
  115. }
  116. $line = str_replace(" ", "&nbsp;", $line);
  117. $line = str_replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $line);
  118. $line = nl2br($line);
  119. $line = parseEmail ($line);
  120. $line = parseUrl ($line);
  121. $line = "^^$line"; // gotta do this because if not, strpos() returns 0
  122. // which in PHP is the same as false. Now it returns 2
  123. if (strpos(trim(str_replace("&nbsp;", "", $line)), "&gt;&gt;") == 2) {
  124. $line = substr($line, 2);
  125. $line = "<FONT COLOR=FF0000>$line</FONT>\n";
  126. } else if (strpos(trim(str_replace("&nbsp;", "", $line)), "&gt;") == 2) {
  127. $line = substr($line, 2);
  128. $line = "<FONT COLOR=800000>$line</FONT>\n";
  129. } else {
  130. $line = substr($line, 2);
  131. }
  132. $body_ary[$i] = "<tt>$line</tt><br>";
  133. }
  134. $body = implode("\n", $body_ary);
  135. return $body;
  136. }
  137. /* SquirrelMail version number -- DO NOT CHANGE */
  138. $version = "0.5pre1";
  139. function find_mailbox_name ($mailbox) {
  140. $mailbox = trim($mailbox);
  141. if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") {
  142. $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
  143. $pos = strrpos ($mailbox, "\"")+1;
  144. $box = substr($mailbox, $pos);
  145. } else {
  146. $box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox));
  147. }
  148. return $box;
  149. }
  150. function replace_spaces ($string) {
  151. return str_replace(" ", "&nbsp;", $string);
  152. }
  153. function replace_escaped_spaces ($string) {
  154. return str_replace("&nbsp;", " ", $string);
  155. }
  156. function get_location () {
  157. # This determines the location to forward to relative
  158. # to your server. If this doesnt work correctly for
  159. # you (although it should), you can remove all this
  160. # code except the last two lines, and change the header()
  161. # function to look something like this, customized to
  162. # the location of SquirrelMail on your server:
  163. #
  164. # http://www.myhost.com/squirrelmail/src/login.php
  165. global $PHP_SELF, $SERVER_NAME, $HTTPS, $HTTP_HOST;
  166. // Get the path
  167. $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'));
  168. // Check if this is a HTTPS or regular HTTP request
  169. $proto = "http://";
  170. if(isset($HTTPS) && $HTTPS == 'on' ) {
  171. $proto = "https://";
  172. }
  173. // Get the hostname from the Host header or server config.
  174. // Fallback is to omit the server name and use a relative URI,
  175. // although this is not RFC 2616 compliant.
  176. if(isset($HTTP_HOST) && !empty($HTTP_HOST)) {
  177. $location = $proto . $HTTP_HOST . $path;
  178. } else if(isset($SERVER_NAME) && !empty($SERVER_NAME)) {
  179. $location = $proto . $SERVER_NAME . $path;
  180. } else {
  181. $location = $path;
  182. }
  183. return $location;
  184. }
  185. ?>