aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/functions.php
diff options
context:
space:
mode:
authorMeik Sievertsen <acydburn@phpbb.com>2006-08-01 15:29:47 +0000
committerMeik Sievertsen <acydburn@phpbb.com>2006-08-01 15:29:47 +0000
commitced8624b8e86bc6aac143163e538f87376319079 (patch)
tree7479c2699efb9bd9c6785e0f5ecd4f792d8ca59e /phpBB/includes/functions.php
parent541dbf8af07874e9507249a7e62cc3c32475d475 (diff)
downloadforums-ced8624b8e86bc6aac143163e538f87376319079.tar
forums-ced8624b8e86bc6aac143163e538f87376319079.tar.gz
forums-ced8624b8e86bc6aac143163e538f87376319079.tar.bz2
forums-ced8624b8e86bc6aac143163e538f87376319079.tar.xz
forums-ced8624b8e86bc6aac143163e538f87376319079.zip
- 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
Diffstat (limited to 'phpBB/includes/functions.php')
-rw-r--r--phpBB/includes/functions.php53
1 files changed, 43 insertions, 10 deletions
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));
}