Apply wordrap in post to hopefully work properly with multibyte characters.
This commit is contained in:
parent
beae111da8
commit
087e26ca6a
|
@ -2050,6 +2050,63 @@ function verify_gpg_signature($res, $signed_text)
|
|||
}
|
||||
}
|
||||
|
||||
function mb_wordwrap($string, $width = 75, $break = "\n", $cut = false) {
|
||||
$string = (string) $string;
|
||||
if ($string === '') {
|
||||
return '';
|
||||
}
|
||||
$break = (string) $break;
|
||||
if ($break === '') {
|
||||
trigger_error('Break string cannot be empty', E_USER_ERROR);
|
||||
}
|
||||
$width = (int) $width;
|
||||
if ($width === 0 && $cut) {
|
||||
trigger_error('Cannot force cut when width is zero', E_USER_ERROR);
|
||||
}
|
||||
if (strlen($string) === mb_strlen($string)) {
|
||||
return wordwrap($string, $width, $break, $cut);
|
||||
}
|
||||
$stringWidth = mb_strlen($string);
|
||||
$breakWidth = mb_strlen($break);
|
||||
$result = '';
|
||||
$lastStart = $lastSpace = 0;
|
||||
for ($current = 0; $current < $stringWidth; $current++) {
|
||||
$char = mb_substr($string, $current, 1);
|
||||
$possibleBreak = $char;
|
||||
if ($breakWidth !== 1) {
|
||||
$possibleBreak = mb_substr($string, $current, $breakWidth);
|
||||
}
|
||||
if ($possibleBreak === $break) {
|
||||
$result .= mb_substr($string, $lastStart, $current - $lastStart + $breakWidth);
|
||||
$current += $breakWidth - 1;
|
||||
$lastStart = $lastSpace = $current + 1;
|
||||
continue;
|
||||
}
|
||||
if ($char === ' ') {
|
||||
if ($current - $lastStart >= $width) {
|
||||
$result .= mb_substr($string, $lastStart, $current - $lastStart) . $break;
|
||||
$lastStart = $current + 1;
|
||||
}
|
||||
$lastSpace = $current;
|
||||
continue;
|
||||
}
|
||||
if ($current - $lastStart >= $width && $cut && $lastStart >= $lastSpace) {
|
||||
$result .= mb_substr($string, $lastStart, $current - $lastStart) . $break;
|
||||
$lastStart = $lastSpace = $current;
|
||||
continue;
|
||||
}
|
||||
if ($current - $lastStart >= $width && $lastStart < $lastSpace) {
|
||||
$result .= mb_substr($string, $lastStart, $lastSpace - $lastStart) . $break;
|
||||
$lastStart = $lastSpace = $lastSpace + 1;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if ($lastStart !== $current) {
|
||||
$result .= mb_substr($string, $lastStart, $current - $lastStart);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function is_moderated($newsgroups)
|
||||
{
|
||||
global $CONFIG, $OVERRIDES, $spooldir;
|
||||
|
|
|
@ -254,9 +254,9 @@ if ($type == "post") {
|
|||
if (isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0) {
|
||||
$_FILES['photo']['name'] = preg_replace('/[^a-zA-Z0-9\.]/', '_', $_FILES['photo']['name']);
|
||||
// There is an attachment to handle
|
||||
$message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname'], null, true);
|
||||
$message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(mb_wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname'], null, true);
|
||||
} else {
|
||||
$message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname']);
|
||||
$message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(mb_wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname']);
|
||||
}
|
||||
// Article sent without errors, or duplicate?
|
||||
if ((substr($message, 0, 3) == "240") || (substr($message, 0, 7) == "441 435")) {
|
||||
|
|
Loading…
Reference in New Issue