diff options
author | Meik Sievertsen <acydburn@phpbb.com> | 2008-06-21 16:05:02 +0000 |
---|---|---|
committer | Meik Sievertsen <acydburn@phpbb.com> | 2008-06-21 16:05:02 +0000 |
commit | 11f27bee84447bf769e10fc7d099bb34209e9c2d (patch) | |
tree | 4218e19de59eec3c42f4202513abaddd3eb61c07 /phpBB/includes/functions_content.php | |
parent | b8647dc952b8992e3a09d31f27a5f3834fb4e8b5 (diff) | |
download | forums-11f27bee84447bf769e10fc7d099bb34209e9c2d.tar forums-11f27bee84447bf769e10fc7d099bb34209e9c2d.tar.gz forums-11f27bee84447bf769e10fc7d099bb34209e9c2d.tar.bz2 forums-11f27bee84447bf769e10fc7d099bb34209e9c2d.tar.xz forums-11f27bee84447bf769e10fc7d099bb34209e9c2d.zip |
further checks on maximum storage length
git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8667 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_content.php')
-rw-r--r-- | phpBB/includes/functions_content.php | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php index 97ec78abcc..ced5106c14 100644 --- a/phpBB/includes/functions_content.php +++ b/phpBB/includes/functions_content.php @@ -1066,8 +1066,16 @@ function extension_allowed($forum_id, $extension, &$extensions) /** * Truncates string while retaining special characters if going over the max length * The default max length is 60 at the moment +* The maximum storage length is there to fit the string within the given length. The string may be further truncated due to html entities. +* For example: string given is 'a "quote"' (length: 9), would be a stored as 'a "quote"' (length: 19) +* +* @param string $string The text to truncate to the given length. String is specialchared. +* @param int $max_length Maximum length of string (multibyte character count as 1 char / Html entity count as 1 char) +* @param int $max_store_length Maximum character length of string (multibyte character count as 1 char / Html entity count as entity chars). +* @param bool $allow_reply Allow Re: in front of string +* @param string $append String to be appended */ -function truncate_string($string, $max_length = 60, $allow_reply = true, $append = '') +function truncate_string($string, $max_length = 60, $max_store_length = 255, $allow_reply = true, $append = '') { $chars = array(); @@ -1090,6 +1098,21 @@ function truncate_string($string, $max_length = 60, $allow_reply = true, $append $stripped = true; } + // Due to specialchars, we may not be able to store the string... + if (utf8_strlen($string) > $max_store_length) + { + // let's split again, we do not want half-baked strings where entities are split + $_chars = utf8_str_split(htmlspecialchars_decode($string)); + $chars = array_map('utf8_htmlspecialchars', $_chars); + + do + { + array_pop($chars); + $string = implode('', $chars); + } + while (utf8_strlen($string) > $max_store_length || !sizeof($chars)); + } + if ($strip_reply) { $string = 'Re: ' . $string; |