From ced8624b8e86bc6aac143163e538f87376319079 Mon Sep 17 00:00:00 2001 From: Meik Sievertsen Date: Tue, 1 Aug 2006 15:29:47 +0000 Subject: - fixing some bugs - shortening some db columns to meet the requirements - correctly increase/decrease user post counts - fix the topic title length bug(s) git-svn-id: file:///svn/phpbb/trunk@6224 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions.php | 53 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 10 deletions(-) (limited to 'phpBB/includes/functions.php') diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index d5355ca600..320cee5bf5 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2276,6 +2276,41 @@ function get_preg_expression($mode) return ''; } +/** +* Truncates string while retaining special characters if going over the max length +* The default max length is 60 at the moment +*/ +function truncate_string($string, $max_length = 60) +{ + $chars = array(); + + // split the multibyte characters first + $string_ary = preg_split('#(&\#[0-9]+;)#', $string, -1, PREG_SPLIT_DELIM_CAPTURE); + + // Now go through the array and split the other characters + foreach ($string_ary as $key => $value) + { + if (strpos($value, '&#') === 0) + { + $chars[] = $value; + continue; + } + + // decode html entities and put them back later + $_chars = str_split(html_entity_decode($value)); + $chars = array_merge($chars, array_map('htmlspecialchars', $_chars)); + } + + // Now check the length ;) + if (sizeof($chars) <= $max_length) + { + return $string; + } + + // Cut off the last elements from the array + return implode('', array_slice($chars, 0, $max_length)); +} + // Handler, header and footer /** @@ -2863,6 +2898,8 @@ function garbage_collection() $db->sql_close(); } +/** +*/ class bitfield { var $data; @@ -2872,26 +2909,22 @@ class bitfield $this->data = $bitfield; } + /** + */ function get($n) { - /** - * Get the ($n / 8)th char - */ + // Get the ($n / 8)th char $byte = $n >> 3; if (!isset($this->data[$byte])) { - /** - * Of course, if it doesn't exist then the result if FALSE - */ - return FALSE; + // Of course, if it doesn't exist then the result if FALSE + return false; } $c = $this->data[$byte]; - /** - * Lookup the ($n % 8)th bit of the byte - */ + // Lookup the ($n % 8)th bit of the byte $bit = 7 - ($n & 7); return (bool) (ord($c) & (1 << $bit)); } -- cgit v1.2.1