- Patch #13263 and #13265 by arnab: added word-based truncation and made the comment module use it to extract subjects.
parent
5f29fc9d0d
commit
b442fad027
|
@ -1722,14 +1722,19 @@ function drupal_xml_parser_create(&$data) {
|
||||||
* The string to truncate.
|
* The string to truncate.
|
||||||
* @param $len
|
* @param $len
|
||||||
* An upper limit on the returned string length.
|
* An upper limit on the returned string length.
|
||||||
|
* @param $wordsafe
|
||||||
|
* Flag to truncate at nearest word boundary. Defaults to FALSE.
|
||||||
* @return
|
* @return
|
||||||
* The truncated string.
|
* The truncated string.
|
||||||
*/
|
*/
|
||||||
function truncate_utf8($string, $len) {
|
function truncate_utf8($string, $len, $wordsafe = FALSE) {
|
||||||
$slen = strlen($string);
|
$slen = strlen($string);
|
||||||
if ($slen <= $len) {
|
if ($slen <= $len) {
|
||||||
return $string;
|
return $string;
|
||||||
}
|
}
|
||||||
|
if ($wordsafe) {
|
||||||
|
while (($string[--$len] != ' ') && ($len > 0)) {};
|
||||||
|
}
|
||||||
if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
|
if ((ord($string[$len]) < 0x80) || (ord($string[$len]) >= 0xC0)) {
|
||||||
return substr($string, 0, $len);
|
return substr($string, 0, $len);
|
||||||
}
|
}
|
||||||
|
|
|
@ -494,7 +494,7 @@ function comment_post($edit) {
|
||||||
$edit['subject'] = strip_tags($edit['subject']);
|
$edit['subject'] = strip_tags($edit['subject']);
|
||||||
|
|
||||||
if ($edit['subject'] == '') {
|
if ($edit['subject'] == '') {
|
||||||
$edit['subject'] = truncate_utf8(strip_tags($edit['comment']), 29);
|
$edit['subject'] = truncate_utf8(strip_tags($edit['comment']), 29, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!form_get_errors()) {
|
if (!form_get_errors()) {
|
||||||
|
|
|
@ -494,7 +494,7 @@ function comment_post($edit) {
|
||||||
$edit['subject'] = strip_tags($edit['subject']);
|
$edit['subject'] = strip_tags($edit['subject']);
|
||||||
|
|
||||||
if ($edit['subject'] == '') {
|
if ($edit['subject'] == '') {
|
||||||
$edit['subject'] = truncate_utf8(strip_tags($edit['comment']), 29);
|
$edit['subject'] = truncate_utf8(strip_tags($edit['comment']), 29, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!form_get_errors()) {
|
if (!form_get_errors()) {
|
||||||
|
|
Loading…
Reference in New Issue