Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
9.8KB

  1. <?php
  2. function savereplace($pattern, $replace, $text)
  3. {
  4. $save = $text;
  5. $text = preg_replace($pattern, $replace, $text);
  6. if ($text == '')
  7. $text = $save;
  8. return($text);
  9. }
  10. function unifyattributionline($message)
  11. {
  12. $quotestr = array('quote', 'spoiler');
  13. foreach ($quotestr as $quote) {
  14. $message = savereplace('/----- Original Message -----\s.*?From: "([^<"].*?)" <(.*?)>\s.*?To: (.*?)\s*?Cc: (.*?)\s*?Sent: (.*?)\s.*?Subject: ([^\n].*)\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  15. $message = savereplace('/----- Original Message -----\s.*?From: "([^<"].*?)" <(.*?)>\s.*?To: (.*?)\s*?Sent: (.*?)\s.*?Subject: ([^\n].*)\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  16. $message = savereplace('/-------- Original-Nachricht --------\s*\['.$quote.'\]\nDatum: (.*?)\nVon: (.*?) <(.*?)>\nAn: (.*?)\nBetreff: (.*?)\n/i', "[".$quote."='$2']\n", $message);
  17. $message = savereplace('/-------- Original-Nachricht --------\s*\['.$quote.'\]\sDatum: (.*?)\s.*Von: "([^<"].*?)" <(.*?)>\s.*An: (.*?)\n.*/i', "[".$quote."='$2']\n", $message);
  18. $message = savereplace('/-------- Original-Nachricht --------\s*\['.$quote.'\]\nDatum: (.*?)\nVon: (.*?)\nAn: (.*?)\nBetreff: (.*?)\n/i', "[".$quote."='$2']\n", $message);
  19. $message = savereplace('/-----Urspr.*?ngliche Nachricht-----\sVon: "([^<"].*?)" <(.*?)>\s.*Gesendet: (.*?)\s.*An: (.*?)\s.*Betreff: ([^\n].*?).*:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  20. $message = savereplace('/-----Urspr.*?ngliche Nachricht-----\sVon: "([^<"].*?)" <(.*?)>\s.*Gesendet: (.*?)\s.*An: (.*?)\s.*Betreff: ([^\n].*?)\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  21. $message = savereplace('/Am (.*?), schrieb (.*?):\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  22. $message = savereplace('/Am .*?, \d+ .*? \d+ \d+:\d+:\d+ \+\d+\sschrieb\s(.*?)\s<(.*?)>:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  23. $message = savereplace('/Am (.*?) schrieb (.*?) <(.*?)>:\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  24. $message = savereplace('/Am (.*?) schrieb <(.*?)>:\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  25. $message = savereplace('/Am (.*?) schrieb (.*?):\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  26. $message = savereplace('/Am (.*?) schrieb (.*?)\n(.*?):\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  27. $message = savereplace('/(\d+)\/(\d+)\/(\d+) ([^<"].*?) <(.*?)>\s*\['.$quote.'\]/i', "[".$quote."='$4']\n", $message);
  28. $message = savereplace('/On .*?, \d+ .*? \d+ \d+:\d+:\d+ \+\d+\s(.*?)\s<(.*?)>\swrote:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  29. $message = savereplace('/On (.*?) at (.*?), (.*?)\s<(.*?)>\swrote:\s*\['.$quote.'\]/i', "[".$quote."='$3']\n", $message);
  30. $message = savereplace('/On (.*?)\n([^<].*?)\s<(.*?)>\swrote:\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  31. $message = savereplace('/On (.*?), (.*?), (.*?)\s<(.*?)>\swrote:\s*\['.$quote.'\]/i', "[".$quote."='$3']\n", $message);
  32. $message = savereplace('/On ([^,].*?), (.*?)\swrote:\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  33. $message = savereplace('/On (.*?), (.*?)\swrote\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  34. // Der loescht manchmal den Body - was eigentlich unmoeglich ist
  35. $message = savereplace('/On (.*?),(.*?),(.*?),(.*?), (.*?) wrote:\s*\['.$quote.'\]/i', "[".$quote."='$5']\n", $message);
  36. $message = savereplace('/Zitat von ([^<].*?) <(.*?)>:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  37. $message = savereplace('/Quoting ([^<].*?) <(.*?)>:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  38. $message = savereplace('/From: "([^<"].*?)" <(.*?)>\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  39. $message = savereplace('/From: <(.*?)>\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  40. $message = savereplace('/Du \(([^)].*?)\) schreibst:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  41. $message = savereplace('/--- (.*?) <.*?> schrieb am (.*?):\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  42. $message = savereplace('/--- (.*?) schrieb am (.*?):\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  43. $message = savereplace('/\* (.*?) <(.*?)> hat geschrieben:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  44. $message = savereplace('/(.*?) <(.*?)> schrieb (.*?)\):\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  45. $message = savereplace('/(.*?) <(.*?)> schrieb am (.*?) um (.*):\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  46. $message = savereplace('/(.*?) schrieb am (.*?) um (.*):\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  47. $message = savereplace('/(.*?) \((.*?)\) schrieb:\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  48. $message = savereplace('/(.*?) schrieb:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  49. $message = savereplace('/(.*?) <(.*?)> writes:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  50. $message = savereplace('/(.*?) \((.*?)\) writes:\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  51. $message = savereplace('/(.*?) writes:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  52. $message = savereplace('/\* (.*?) wrote:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  53. $message = savereplace('/(.*?) wrote \(.*?\):\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  54. $message = savereplace('/(.*?) wrote:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  55. $message = savereplace('/([^<].*?) <.*?> hat am (.*?)\sum\s(.*)\sgeschrieben:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  56. $message = savereplace('/(\d+)\/(\d+)\/(\d+) ([^<"].*?) <(.*?)>:\s*\['.$quote.'\]/i', "[".$quote."='$4']\n", $message);
  57. $message = savereplace('/(\d+)\/(\d+)\/(\d+) (.*?) <(.*?)>\s*\['.$quote.'\]/i', "[".$quote."='$4']\n", $message);
  58. $message = savereplace('/(\d+)\/(\d+)\/(\d+) <(.*?)>:\s*\['.$quote.'\]/i', "[".$quote."='$4']\n", $message);
  59. $message = savereplace('/(\d+)\/(\d+)\/(\d+) <(.*?)>\s*\['.$quote.'\]/i', "[".$quote."='$4']\n", $message);
  60. $message = savereplace('/(.*?) <(.*?)> schrubselte:\s*\['.$quote.'\]/i', "[".$quote."='$1']\n", $message);
  61. $message = savereplace('/(.*?) \((.*?)\) schrubselte:\s*\['.$quote.'\]/i', "[".$quote."='$2']\n", $message);
  62. }
  63. return($message);
  64. }
  65. function removegpg($message)
  66. {
  67. $pattern = '/(.*)\s*-----BEGIN PGP SIGNED MESSAGE-----\s*[\r\n].*Hash:.*?[\r\n](.*)'.
  68. '[\r\n]\s*-----BEGIN PGP SIGNATURE-----\s*[\r\n].*'.
  69. '[\r\n]\s*-----END PGP SIGNATURE-----(.*)/is';
  70. preg_match($pattern, $message, $result);
  71. $cleaned = trim($result[1].$result[2].$result[3]);
  72. $cleaned = str_replace(array("\n- --\n", "\n- -"), array("\n-- \n", "\n-"), $cleaned);
  73. if ($cleaned == '')
  74. $cleaned = $message;
  75. return($cleaned);
  76. }
  77. function removesig($message)
  78. {
  79. $sigpos = strrpos($message, "\n-- \n");
  80. $quotepos = strrpos($message, "[/quote]");
  81. if ($sigpos == 0) {
  82. // Speziell fuer web.de, die das als Trenner verwenden
  83. $message = str_replace("\n___________________________________________________________\n", "\n-- \n", $message);
  84. $sigpos = strrpos($message, "\n-- \n");
  85. $quotepos = strrpos($message, "[/quote]");
  86. }
  87. // Sollte sich der Signaturtrenner innerhalb eines Quotes befinden
  88. // wird keine Signaturtrennung ausgefuehrt
  89. if (($sigpos < $quotepos) && ($sigpos != 0))
  90. return(array('body' => $message, 'sig' => ''));
  91. /// @TODO Regexp umstellen, so dass auf 1 oder kein Leerzeichen
  92. /// geprueft wird
  93. /// $message = str_replace("\n--\n", "\n-- \n", $message);
  94. $pattern = '/(.*)[\r\n]-- [\r\n](.*)/is';
  95. preg_match($pattern, $message, $result);
  96. if (($result[1] != '') && ($result[2] != '')) {
  97. $cleaned = trim($result[1])."\n";
  98. $sig = trim($result[2]);
  99. // '[hr][size=x-small][color=darkblue]'.trim($result[2]).'[/color][/size]';
  100. } else {
  101. $cleaned = $message;
  102. $sig = '';
  103. }
  104. return(array('body' => $cleaned, 'sig' => $sig));
  105. }
  106. function removelinebreak($message)
  107. {
  108. $arrbody = explode("\n", trim($message));
  109. $lines = array();
  110. $lineno = 0;
  111. foreach ($arrbody as $i => $line) {
  112. $currquotelevel = 0;
  113. $currline = $line;
  114. while ((strlen($currline)>0) && ((substr($currline, 0, 1) == '>')
  115. || (substr($currline, 0, 1) == ' '))) {
  116. if (substr($currline, 0, 1) == '>')
  117. $currquotelevel++;
  118. $currline = ltrim(substr($currline, 1));
  119. }
  120. $quotelevel = 0;
  121. $nextline = trim($arrbody[$i+1]);
  122. while ((strlen($nextline)>0) && ((substr($nextline, 0, 1) == '>')
  123. || (substr($nextline, 0, 1) == ' '))) {
  124. if (substr($nextline, 0, 1) == '>')
  125. $quotelevel++;
  126. $nextline = ltrim(substr($nextline, 1));
  127. }
  128. $len = strlen($line);
  129. $firstword = strpos($nextline.' ', ' ');
  130. $specialchars = ((substr(trim($nextline), 0, 1) == '-') ||
  131. (substr(trim($nextline), 0, 1) == '=') ||
  132. (substr(trim($nextline), 0, 1) == '*') ||
  133. (substr(trim($nextline), 0, 1) == '·') ||
  134. (substr(trim($nextline), 0, 4) == '[url') ||
  135. (substr(trim($nextline), 0, 5) == '[size') ||
  136. (substr(trim($nextline), 0, 7) == 'http://') ||
  137. (substr(trim($nextline), 0, 8) == 'https://'));
  138. if (!$specialchars)
  139. $specialchars = ((substr(rtrim($line), -1) == '-') ||
  140. (substr(rtrim($line), -1) == '=') ||
  141. (substr(rtrim($line), -1) == '*') ||
  142. (substr(rtrim($line), -1) == '·') ||
  143. (substr(rtrim($line), -6) == '[/url]') ||
  144. (substr(rtrim($line), -7) == '[/size]'));
  145. //if ($specialchars)
  146. // echo ("Special\n");
  147. if ($lines[$lineno] != '') {
  148. if (substr($lines[$lineno], -1) != ' ')
  149. $lines[$lineno] .= ' ';
  150. while ((strlen($line)>0) && ((substr($line, 0, 1) == '>')
  151. || (substr($line, 0, 1) == ' '))) {
  152. $line = ltrim(substr($line, 1));
  153. }
  154. }
  155. //else
  156. // $lines[$lineno] = $quotelevel.'-'.$len.'-'.$firstword.'-';
  157. $lines[$lineno] .= $line;
  158. //if ((($len + $firstword < 68) && (substr($line, -1, 1) != ' '))
  159. // || ($quotelevel != $currquotelevel) || $specialchars)
  160. if (((substr($line, -1, 1) != ' '))
  161. || ($quotelevel != $currquotelevel))
  162. $lineno++;
  163. }
  164. return(implode("\n", $lines));
  165. }