aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions_content.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2008-06-23 18:22:44 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2008-06-23 18:22:44 +0000
commitad739a358ca7b593fc5f2bfc77e2058b4ea59163 (patch)
tree0190f40f45cf190dfc5a2a1e0053fa899c14ddce /phpBB/includes/functions_content.php
parent3892e7330adb2464293428e58f882f7d18fc8558 (diff)
downloadforums-ad739a358ca7b593fc5f2bfc77e2058b4ea59163.tar
forums-ad739a358ca7b593fc5f2bfc77e2058b4ea59163.tar.gz
forums-ad739a358ca7b593fc5f2bfc77e2058b4ea59163.tar.bz2
forums-ad739a358ca7b593fc5f2bfc77e2058b4ea59163.tar.xz
forums-ad739a358ca7b593fc5f2bfc77e2058b4ea59163.zip
merge? merge.
git-svn-id: file:///svn/phpbb/trunk@8672 89ea8834-ac86-4346-8a33-228a782c2dd0
Diffstat (limited to 'phpBB/includes/functions_content.php')
-rw-r--r--phpBB/includes/functions_content.php29
1 files changed, 26 insertions, 3 deletions
diff --git a/phpBB/includes/functions_content.php b/phpBB/includes/functions_content.php
index 73ab553cf0..bc31bf44d7 100644
--- a/phpBB/includes/functions_content.php
+++ b/phpBB/includes/functions_content.php
@@ -435,6 +435,7 @@ function generate_text_for_display($text, $uid, $bitfield, $flags)
function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bbcode = false, $allow_urls = false, $allow_smilies = false)
{
$uid = $bitfield = '';
+ $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
if (!$text)
{
@@ -458,7 +459,6 @@ function generate_text_for_storage(&$text, &$uid, &$bitfield, &$flags, $allow_bb
$uid = '';
}
- $flags = (($allow_bbcode) ? OPTION_FLAG_BBCODE : 0) + (($allow_smilies) ? OPTION_FLAG_SMILIES : 0) + (($allow_urls) ? OPTION_FLAG_LINKS : 0);
$bitfield = $message_parser->bbcode_bitfield;
return;
@@ -563,7 +563,7 @@ function make_clickable_callback($type, $whitespace, $url, $relative_url, $class
$relative_url = preg_replace('/[&?]sid=[0-9a-f]{32}$/', '', preg_replace('/([&?])sid=[0-9a-f]{32}&/', '$1', $relative_url));
$url = $url . '/' . $relative_url;
$text = $relative_url;
-
+
// this url goes to http://domain.tld/path/to/board/ which
// would result in an empty link if treated as local so
// don't touch it and let MAGIC_URL_FULL take care of it.
@@ -1062,8 +1062,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 &quot;quote&quot;' (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();
@@ -1086,6 +1094,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;