diff options
author | David M <davidmj@users.sourceforge.net> | 2006-03-11 01:52:25 +0000 |
---|---|---|
committer | David M <davidmj@users.sourceforge.net> | 2006-03-11 01:52:25 +0000 |
commit | 1adfb39cbae433eccda37d50b7ed7a01bbabd4e3 (patch) | |
tree | 0d75a77cd1a41534039ea14b2ff9162b2842becc | |
parent | 2fb1507670ba4582a1170c0346ef735358545a53 (diff) | |
download | forums-1adfb39cbae433eccda37d50b7ed7a01bbabd4e3.tar forums-1adfb39cbae433eccda37d50b7ed7a01bbabd4e3.tar.gz forums-1adfb39cbae433eccda37d50b7ed7a01bbabd4e3.tar.bz2 forums-1adfb39cbae433eccda37d50b7ed7a01bbabd4e3.tar.xz forums-1adfb39cbae433eccda37d50b7ed7a01bbabd4e3.zip |
- Moved the image loading outside the big loop. This brings fewer comparisons and allows us to unload the image data sooner.
- Used a more appropriate method to break the images into chunks.
git-svn-id: file:///svn/phpbb/trunk@5619 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/includes/functions.php | 31 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_confirm.php | 24 |
2 files changed, 43 insertions, 12 deletions
diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index 092c527902..e75ba650f0 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -175,6 +175,37 @@ if (!function_exists('array_combine')) } } +if (!function_exists('str_split')) +{ + /** + * A wrapper for the PHP5 function str_split() + * @param array $string contains the string to be converted + * @param array $split_length contains the length of each chunk + * + * @return Converts a string to an array. If the optional split_length parameter is specified, + * the returned array will be broken down into chunks with each being split_length in length, + * otherwise each chunk will be one character in length. FALSE is returned if split_length is + * less than 1. If the split_length length exceeds the length of string, the entire string is + * returned as the first (and only) array element. + */ + function str_split($string, $split_length = 1) + { + if ($split_length < 1) + { + return false; + } + else if ($split_length >= strlen($string)) + { + return array($string); + } + else + { + preg_match_all('#.{1,' . $split_length . '}#s', $string, $matches); + return $matches[0]; + } + } +} + /** * Get userdata * @param mixed $user user id or username diff --git a/phpBB/includes/ucp/ucp_confirm.php b/phpBB/includes/ucp/ucp_confirm.php index 68e949799b..831ea92dcc 100644 --- a/phpBB/includes/ucp/ucp_confirm.php +++ b/phpBB/includes/ucp/ucp_confirm.php @@ -62,22 +62,30 @@ class ucp_confirm list($usec, $sec) = explode(' ', microtime()); mt_srand($sec * $usec); - $char_widths = array(); + $char_widths = $hold_chars = array(); $code_len = strlen($code); for ($i = 0; $i < $code_len; $i++) { $char = $code{$i}; $width = mt_rand(0, 4); + $raw_width = $_png[$char]['width']; $char_widths[$i] = $width; - $img_width += $_png[$char]['width'] - $width; + $img_width += $raw_width - $width; + + // Split the char into chunks of $raw_width + 1 length + if (empty($hold_chars[$char])) + { + $hold_chars[$char] = str_split(base64_decode($_png[$char]['data']), $raw_width + 1); + } } + unset($_png); + $offset_x = mt_rand(0, $total_width - $img_width); $offset_y = mt_rand(0, $total_height - $img_height); $image = ''; - $hold_chars = array(); for ($i = 0; $i < $total_height; $i++) { $image .= chr(0); @@ -91,13 +99,7 @@ class ucp_confirm for ($k = 0; $k < $code_len; $k++) { - $char = $code{$k}; - - if (empty($hold_chars[$char])) - { - $hold_chars[$char] = explode("\n", chunk_split(base64_decode($_png[$char]['data']), $_png[$char]['width'] + 1, "\n")); - } - $image .= $this->randomise(substr($hold_chars[$char][$i - $offset_y - 1], 1), $char_widths[$k]); + $image .= $this->randomise(substr($hold_chars[$code{$k}][$i - $offset_y - 1], 1), $char_widths[$k]); } for ($k = $offset_x + $img_width; $k < $total_width; $k++) @@ -124,7 +126,6 @@ class ucp_confirm echo $image; unset($image); - unset($_png); exit; } @@ -153,7 +154,6 @@ class ucp_confirm $new_line .= $scanline{$i}; } } - return $new_line; } |