1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-05 08:17:47 +02:00

- compress is nicer (fixed a bug :P)

- UTF-8 code is nicer (fixed a bug :P)
- new CAPTCHA. Replaced the old one for size and usability issues. The old CAPTCHA will most likely be released as a separate package


git-svn-id: file:///svn/phpbb/trunk@6549 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
David M
2006-11-03 23:09:16 +00:00
parent 7ab232a455
commit 8b0ec6e02d
12 changed files with 1423 additions and 4974 deletions

View File

@@ -21,91 +21,37 @@ class acp_captcha
$user->add_lang('acp/board');
$config_vars = array('enable_confirm' => 'REG_ENABLE',
'enable_post_confirm' => 'POST_ENABLE',
'policy_overlap' => 'OVERLAP_ENABLE',
'policy_overlap_noise_pixel' => 'OVERLAP_NOISE_PIXEL',
'policy_overlap_noise_line' => 'OVERLAP_NOISE_LINE_ENABLE',
'policy_entropy' => 'ENTROPY_ENABLE',
'policy_entropy_noise_pixel' => 'ENTROPY_NOISE_PIXEL',
'policy_entropy_noise_line' => 'ENTROPY_NOISE_LINE_ENABLE',
'policy_shape' => 'SHAPE_ENABLE',
'policy_shape_noise_pixel' => 'SHAPE_NOISE_PIXEL',
'policy_shape_noise_line' => 'SHAPE_NOISE_LINE_ENABLE',
'policy_3dbitmap' => 'THREEDBITMAP_ENABLE',
'policy_cells' => 'CELLS_ENABLE',
'policy_stencil' => 'STENCIL_ENABLE',
'policy_composite' => 'COMPOSITE_ENABLE'
);
$config_vars = array(
'enable_confirm' => 'REG_ENABLE',
'enable_post_confirm' => 'POST_ENABLE',
'captcha_gd' => 'CAPTCHA_GD',
'captcha_gd_noise' => 'CAPTCHA_GD_NOISE',
);
$policy_modules = array('policy_entropy', 'policy_3dbitmap', 'policy_overlap', 'policy_shape', 'policy_cells', 'policy_stencil', 'policy_composite');
switch ($mode)
$this->tpl_name = 'acp_captcha';
$this->page_title = 'ACP_VC_SETTINGS';
$submit = request_var('submit', '');
if ($submit)
{
case 'visual':
$this->tpl_name = 'acp_captcha';
$this->page_title = 'ACP_VC_SETTINGS';
$submit = request_var('submit', '');
if ($submit)
{
$config_vars = array_keys($config_vars);
foreach ($config_vars as $config_var)
{
set_config($config_var, request_var($config_var, ''));
}
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
}
else
{
$array = array();
$config_vars = array_keys($config_vars);
foreach ($config_vars as $config_var)
{
set_config($config_var, request_var($config_var, ''));
}
trigger_error($user->lang['CONFIG_UPDATED'] . adm_back_link($this->u_action));
}
else
{
$array = array();
foreach ($config_vars as $config_var => $template_var)
{
$array[$template_var] = $config[$config_var];
}
$template->assign_vars($array);
if (@extension_loaded('gd'))
{
$template->assign_var('GD', true);
foreach ($policy_modules as $module_name)
{
$template->assign_var('U_' . strtoupper($module_name), sprintf($user->lang['CAPTCHA_EXPLAIN'], '<a href="' . append_sid("{$phpbb_root_path}adm/index.$phpEx", 'i=captcha&amp;mode=img&amp;policy=' . $module_name) . '">', '</a>'));
}
if (function_exists('imagettfbbox') && function_exists('imagettftext'))
{
$template->assign_var('TTF', true);
}
}
}
break;
case 'img':
$policy = request_var('policy', '');
if (!@extension_loaded('gd'))
{
trigger_error($user->lang['NO_GD'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if (!($policy === 'policy_entropy' || $policy === 'policy_3dbitmap') && (!function_exists('imagettfbbox') || !function_exists('imagettftext')))
{
trigger_error($user->lang['NO_TTF'] . adm_back_link($this->u_action), E_USER_WARNING);
}
if (!in_array($policy, $policy_modules))
{
trigger_error($user->lang['BAD_POLICY'] . adm_back_link($this->u_action), E_USER_WARNING);
}
$user->add_lang('ucp');
include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
$captcha = new captcha();
$captcha->execute(gen_rand_string(), $policy);
break;
if (@extension_loaded('gd') && function_exists('imagettfbbox') && function_exists('imagettftext'))
{
$template->assign_var('GD', true);
}
foreach ($config_vars as $config_var => $template_var)
{
$template->assign_var($template_var, $config[$config_var]);
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -612,6 +612,14 @@ else
}
}
if (!function_exists('htmlspecialchars_decode'))
{
function htmlspecialchars_decode($string, $quote_style = ENT_COMPAT)
{
return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
}
}
// functions used for building option fields
/**

View File

@@ -2430,7 +2430,7 @@ function get_database_size()
{
if ($table_prefix != '')
{
if (strstr($row['Name'], $table_prefix))
if (strpos($row['Name'], $table_prefix) !== false)
{
$database_size += $row['Data_length'] + $row['Index_length'];
}

View File

@@ -478,17 +478,17 @@ class compress_tar extends compress
// Run through the file and grab directory entries
while ($buffer = $fzread($this->fp, 512))
{
$tmp = unpack("A6magic", substr($buffer, 257, 6));
$tmp = unpack('A6magic', substr($buffer, 257, 6));
if (trim($tmp['magic']) == 'ustar')
{
$tmp = unpack("A100name", $buffer);
$tmp = unpack('A100name', $buffer);
$filename = trim($tmp['name']);
$tmp = unpack("Atype", substr($buffer, 156, 1));
$tmp = unpack('Atype', substr($buffer, 156, 1));
$filetype = (int) trim($tmp['type']);
$tmp = unpack("A12size", substr($buffer, 124, 12));
$tmp = unpack('A12size', substr($buffer, 124, 12));
$filesize = octdec((int) trim($tmp['size']));
if ($filetype == 5)
@@ -508,12 +508,12 @@ class compress_tar extends compress
{
trigger_error("Could not create directory $folder");
}
@chmod("$str", 0777);
@chmod($str, 0777);
}
}
}
}
else if($filesize != 0 && ($filetype == 0 || $filetype == "\0"))
else if ($filesize != 0 && ($filetype == 0 || $filetype == "\0"))
{
// Write out the files
if (!($fp = fopen("$dst$filename", 'wb')))
@@ -523,7 +523,7 @@ class compress_tar extends compress
@chmod("$dst$filename", 0777);
// Grab the file contents
fwrite($fp, $fzread($this->fp, $filesize + 512 - $filesize % 512), $filesize);
fwrite($fp, $fzread($this->fp, ($filesize + 511) &~ 511), $filesize);
fclose($fp);
}
}
@@ -542,7 +542,7 @@ class compress_tar extends compress
$fzwrite = ($this->isbz && function_exists('bzwrite')) ? 'bzwrite' : (($this->isgz && @extension_loaded('zlib')) ? 'gzwrite' : 'fwrite');
// Symbolizes that there are no more files
$fzwrite($this->fp, pack("a512", ""));
$fzwrite($this->fp, str_repeat("\0", 512));
}
$fzclose($this->fp);
@@ -560,37 +560,37 @@ class compress_tar extends compress
// This is the header data, it contains all the info we know about the file or folder that we are about to archive
$header = '';
$header .= pack("a100", $name); // file name
$header .= pack("a8", sprintf("%07o", $stat[2])); // file mode
$header .= pack("a8", sprintf("%07o", $stat[4])); // owner id
$header .= pack("a8", sprintf("%07o", $stat[5])); // group id
$header .= pack("a12", sprintf("%011o", $stat[7])); // file size
$header .= pack("a12", sprintf("%011o", $stat[9])); // last mod time
$header .= pack('a100', $name); // file name
$header .= pack('a8', sprintf("%07o", $stat[2])); // file mode
$header .= pack('a8', sprintf("%07o", $stat[4])); // owner id
$header .= pack('a8', sprintf("%07o", $stat[5])); // group id
$header .= pack('a12', sprintf("%011o", $stat[7])); // file size
$header .= pack('a12', sprintf("%011o", $stat[9])); // last mod time
// Checksum
$checksum = 0;
for ($i = 0; $i < 148; $i++)
{
$checksum += ord(substr($header, $i, 1));
$checksum += ord($header[$i]);
}
// We precompute the rest of the hash, this saves us time in the loop and allows us to insert our hash without resorting to string functions
$checksum += 2415 + (($is_dir) ? 53 : 0);
$header .= pack("a8", sprintf("%07o", $checksum)); // checksum
$header .= pack("a1", $typeflag); // link indicator
$header .= pack("a100", ''); // name of linked file
$header .= pack("a6", 'ustar'); // ustar indicator
$header .= pack("a2", '00'); // ustar version
$header .= pack("a32", 'Unknown'); // owner name
$header .= pack("a32", 'Unknown'); // group name
$header .= pack("a8", ''); // device major number
$header .= pack("a8", ''); // device minor number
$header .= pack("a155", ''); // filename prefix
$header .= pack("a12", ''); // end
$header .= pack('a8', sprintf("%07o", $checksum)); // checksum
$header .= pack('a1', $typeflag); // link indicator
$header .= pack('a100', ''); // name of linked file
$header .= pack('a6', 'ustar'); // ustar indicator
$header .= pack('a2', '00'); // ustar version
$header .= pack('a32', 'Unknown'); // owner name
$header .= pack('a32', 'Unknown'); // group name
$header .= pack('a8', ''); // device major number
$header .= pack('a8', ''); // device minor number
$header .= pack('a155', ''); // filename prefix
$header .= pack('a12', ''); // end
// This writes the entire file in one shot. Header, followed by data and then null padded to a multiple of 512
$fzwrite($this->fp, $header . (($stat[7] !== 0 && !$is_dir) ? $data . (($stat[7] % 512 > 0) ? str_repeat("\0", 512 - $stat[7] % 512) : '') : ''));
$fzwrite($this->fp, $header . (($stat[7] !== 0 && !$is_dir) ? $data . str_repeat("\0", (($stat[7] + 511) &~ 511) - $stat[7]) : ''));
unset($data);
}

View File

@@ -54,46 +54,9 @@ class ucp_confirm
exit;
}
// Some people might want the olde style CAPTCHA even if they have GD enabled, this also saves us from people who have GD but no TTF
$policy_modules = array('policy_entropy', 'policy_3dbitmap');
if (function_exists('imagettfbbox') && function_exists('imagettftext'))
if ($config['captcha_gd'])
{
$policy_modules = array_merge($policy_modules, array('policy_overlap', 'policy_shape', 'policy_cells', 'policy_stencil', 'policy_composite'));
}
foreach ($policy_modules as $key => $name)
{
if ($config[$name] === '0')
{
unset($policy_modules[$key]);
}
}
$policy = '';
if (@extension_loaded('gd') && sizeof($policy_modules))
{
$change_lang = request_var('change_lang', '');
if ($change_lang)
{
$change_lang = basename($change_lang);
if (file_exists($phpbb_root_path . 'language/' . $change_lang . '/'))
{
$user->lang_name = $lang = $change_lang;
$user->lang_path = $phpbb_root_path . 'language/' . $lang . '/';
$user->lang = array();
$user->add_lang(array('common', 'ucp'));
}
else
{
$change_lang = '';
}
}
include($phpbb_root_path . 'includes/captcha/captcha_gd.' . $phpEx);
$policy = $policy_modules[array_rand($policy_modules)];
}
else
{
@@ -101,7 +64,7 @@ class ucp_confirm
}
$captcha = new captcha();
$captcha->execute($row['code'], $policy);
$captcha->execute($row['code']);
exit;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -781,7 +781,7 @@ function utf8_recode($string, $encoding)
*/
function utf8_encode_ncr($text)
{
return preg_replace_callback('#[\\xC2-\\xF4][\\x80-\\xBF]?[\\x80-\\xBF]?[\\x80-\\xBF]+#', 'utf8_encode_ncr_callback', $text);
return preg_replace_callback('#[\\xC2-\\xF4][\\x80-\\xBF]{1,3}#', 'utf8_encode_ncr_callback', $text);
}
/**
@@ -824,7 +824,7 @@ function utf8_ord($chr)
break;
default:
return $m;
return $chr;
}
}