Просмотр исходного кода

pun_strlen() and utf8_strlen() replaced to mb_strlen(). Fix PUN_MAX_POSTSIZE

Visman 8 лет назад
Родитель
Сommit
dea119336c

+ 1 - 1
admin_options.php

@@ -734,7 +734,7 @@ generate_admin_menu('options');
 									<th scope="row"><?php echo $lang_admin_options['SMTP password label'] ?></th>
 									<td>
 										<label><input type="checkbox" name="form[smtp_change_pass]" value="1" />&#160;<?php echo $lang_admin_options['SMTP change password help'] ?></label>
-<?php $smtp_pass = !empty($pun_config['o_smtp_pass']) ? random_key(pun_strlen($pun_config['o_smtp_pass']), true) : ''; ?>
+<?php $smtp_pass = !empty($pun_config['o_smtp_pass']) ? random_key(mb_strlen($pun_config['o_smtp_pass']), true) : ''; ?>
 										<input type="password" name="form[smtp_pass1]" size="25" maxlength="50" value="<?php echo $smtp_pass ?>" />
 										<input type="password" name="form[smtp_pass2]" size="25" maxlength="50" value="<?php echo $smtp_pass ?>" />
 										<span><?php echo $lang_admin_options['SMTP password help'] ?></span>

+ 3 - 3
app/Core/Install.php

@@ -151,9 +151,9 @@ class Install implements ContainerAwareInterface
                 $base_url = substr($base_url, 0, -1);
 
             // Validate username and passwords
-            if (pun_strlen($username) < 2)
+            if (mb_strlen($username) < 2)
                 $alerts[] = $lang_install['Username 1'];
-            else if (pun_strlen($username) > 25) // This usually doesn't happen since the form element only accepts 25 characters
+            else if (mb_strlen($username) > 25) // This usually doesn't happen since the form element only accepts 25 characters
                 $alerts[] = $lang_install['Username 2'];
             else if (! strcasecmp($username, 'Guest'))
                 $alerts[] = $lang_install['Username 3'];
@@ -164,7 +164,7 @@ class Install implements ContainerAwareInterface
             else if (preg_match('%(?:\[/?(?:b|u|i|h|colou?r|quote|code|img|url|email|list)\]|\[(?:code|quote|list)=)%i', $username))
                 $alerts[] = $lang_install['Username 6'];
 
-            if (pun_strlen($password1) < 6)
+            if (mb_strlen($password1) < 6)
                 $alerts[] = $lang_install['Short password'];
             else if ($password1 != $password2)
                 $alerts[] = $lang_install['Passwords not match'];

+ 2 - 2
app/bootstrap.php

@@ -21,9 +21,9 @@ mb_language('uni');
 mb_internal_encoding('UTF-8');
 mb_substitute_character(0xFFFD);
 
-// The maximum size of a post, in bytes, since the field is now MEDIUMTEXT this allows ~16MB but lets cap at 1MB...
+// The maximum size of a post, in characters, not bytes
 if (!defined('PUN_MAX_POSTSIZE'))
-	define('PUN_MAX_POSTSIZE', 1048576);
+	define('PUN_MAX_POSTSIZE', 65000);
 
 if (!defined('PUN_SEARCH_MIN_WORD'))
 	define('PUN_SEARCH_MIN_WORD', 3);

+ 2 - 2
db_update.php

@@ -1028,9 +1028,9 @@ switch ($stage)
 
 				$username = trim($_POST['dupe_users'][$id]);
 
-				if (pun_strlen($username) < 2)
+				if (mb_strlen($username) < 2)
 					$errors[$id][] = $lang_update['Username too short error'];
-				else if (pun_strlen($username) > 25) // This usually doesn't happen since the form element only accepts 25 characters
+				else if (mb_strlen($username) > 25) // This usually doesn't happen since the form element only accepts 25 characters
 					$errors[$id][] = $lang_update['Username too long error'];
 				else if (!strcasecmp($username, 'Guest'))
 					$errors[$id][] = $lang_update['Username Guest reserved error'];

+ 2 - 3
edit.php

@@ -81,7 +81,7 @@ if ($request->isPost('form_sent'))
 			$errors[] = $lang_post['No subject'];
 		else if ($pun_config['o_censoring'] == '1' && $censored_subject == '')
 			$errors[] = $lang_post['No subject after censoring'];
-		else if (pun_strlen($subject) > 70)
+		else if (mb_strlen($subject) > 70)
 			$errors[] = $lang_post['Too long subject'];
 		else if ($pun_config['p_subject_all_caps'] == '0' && is_all_uppercase($subject) && !$pun_user['is_admmod'])
 			$errors[] = $lang_post['All caps subject'];
@@ -95,8 +95,7 @@ if ($request->isPost('form_sent'))
 	// Clean up message from POST
 	$message = pun_linebreaks(trim($request->postStr('req_message')));
 
-	// Here we use strlen() not pun_strlen() as we want to limit the post to PUN_MAX_POSTSIZE bytes, not characters
-	if (pun_strlen($message) > PUN_MAX_POSTSIZE)
+	if (mb_strlen($message) > PUN_MAX_POSTSIZE)
 		$errors[] = sprintf($lang_post['Too long message'], forum_number_format(PUN_MAX_POSTSIZE));
 	else if ($pun_config['p_message_all_caps'] == '0' && is_all_uppercase($message) && !$pun_user['is_admmod'])
 		$errors[] = $lang_post['All caps message'];

+ 1 - 1
extern.php

@@ -267,7 +267,7 @@ function output_html($feed)
 
 	foreach ($feed['items'] as $item)
 	{
-		if (utf8_strlen($item['title']) > FORUM_EXTERN_MAX_SUBJECT_LENGTH)
+		if (mb_strlen($item['title']) > FORUM_EXTERN_MAX_SUBJECT_LENGTH)
 			$subject_truncated = pun_htmlspecialchars(trim(utf8_substr($item['title'], 0, (FORUM_EXTERN_MAX_SUBJECT_LENGTH - 5)))).' …';
 		else
 			$subject_truncated = pun_htmlspecialchars($item['title']);

+ 2 - 2
include/common.php

@@ -152,9 +152,9 @@ if (!defined('WITT_ENABLE')) // Кто в этой теме - Visman
 if ($pun_user['is_guest'] && $container->get('Request')->isGet('login'))
 	message($lang_common['No cookie']);
 
-// The maximum size of a post, in bytes, since the field is now MEDIUMTEXT this allows ~16MB but lets cap at 1MB...
+// The maximum size of a post, in characters, not bytes
 if (!defined('PUN_MAX_POSTSIZE'))
-	define('PUN_MAX_POSTSIZE', 1048576);
+	define('PUN_MAX_POSTSIZE', 65000);
 
 if (!defined('PUN_SEARCH_MIN_WORD'))
 	define('PUN_SEARCH_MIN_WORD', 3);

+ 3 - 12
include/functions.php

@@ -506,9 +506,9 @@ function check_username($username, $exclude_id = null)
 	$username = preg_replace('%\s+%s', ' ', $username);
 
 	// Validate username
-	if (pun_strlen($username) < 2)
+	if (mb_strlen($username) < 2)
 		$errors[] = $lang_prof_reg['Username too short'];
-	else if (pun_strlen($username) > 25) // This usually doesn't happen since the form element only accepts 25 characters
+	else if (mb_strlen($username) > 25) // This usually doesn't happen since the form element only accepts 25 characters
 		$errors[] = $lang_prof_reg['Username too long'];
 	else if (!preg_match('%^\p{L}[\p{L}\p{N}_ ]+$%uD', $username)) // строгая проверка имени пользователя - Visman
 		$errors[] = $lang_prof_reg['Username Error'];
@@ -1384,15 +1384,6 @@ function pun_htmlspecialchars_decode($str)
 }
 
 
-//
-// A wrapper for utf8_strlen for compatibility
-//
-function pun_strlen($str)
-{
-	return utf8_strlen($str);
-}
-
-
 //
 // Convert \r\n and \r to \n
 //
@@ -1828,7 +1819,7 @@ function forum_remove_bad_characters() //????
 // Removes any "bad" characters (characters which mess with the display of a page, are invisible, etc) from the given string
 // See: http://kb.mozillazine.org/Network.IDN.blacklist_chars
 //
-function remove_bad_characters($array)
+function remove_bad_characters($array) //????
 {
 	static $bad_utf8_chars;
 

+ 1 - 1
include/parser.php

@@ -697,7 +697,7 @@ function handle_url_tag($url, $link = '', $bbcode = false)
 		if ($link == '' || $link == $url)
 		{
 			$url = pun_htmlspecialchars_decode($url);
-			$link = utf8_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
+			$link = mb_strlen($url) > 55 ? utf8_substr($url, 0 , 39).' … '.utf8_substr($url, -10) : $url;
 			$link = pun_htmlspecialchars($link);
 		}
 		else

+ 1 - 1
include/pms_new/mdl/post.php

@@ -145,7 +145,7 @@ if ($request->isPost('csrf_hash'))
 
 		if ($subject == '')
 			$errors[] = $lang_pmsn['No subject'];
-		else if (pun_strlen($subject) > 70)
+		else if (mb_strlen($subject) > 70)
 			$errors[] = $lang_post['Too long subject'];
 		else if ($pun_config['p_subject_all_caps'] == '0' && is_all_uppercase($subject) && !$pun_user['is_admmod'])
 			$errors[] = $lang_post['All caps subject'];

+ 2 - 2
include/poll.php

@@ -378,7 +378,7 @@ function poll_form_validate($tid, &$errors)
 			else
 			{
 				$kol++;
-				if (pun_strlen($question) > 250)
+				if (mb_strlen($question) > 250)
 					$errors[] = sprintf($lang_poll['Question too long'], $k);
 
 				$koc = 0;
@@ -391,7 +391,7 @@ function poll_form_validate($tid, &$errors)
 					else
 					{
 						$koc++;
-						if (pun_strlen($choice) > 250)
+						if (mb_strlen($choice) > 250)
 							$errors[] = sprintf($lang_poll['Choice too long'], $k, $i);
 					}
 				}

+ 1 - 1
include/search_idx.php

@@ -193,7 +193,7 @@ function validate_search_word($word, $idx)
 	$word = str_replace(array('%', '*'), '', $word);
 
 	// Check the word is within the min/max length
-	$num_chars = pun_strlen($word);
+	$num_chars = mb_strlen($word);
 	return $num_chars >= PUN_SEARCH_MIN_WORD && $num_chars <= PUN_SEARCH_MAX_WORD;
 }
 

+ 1 - 1
include/security.php

@@ -59,7 +59,7 @@ function security_show_random_value($val)
 		$arr = security_lang('Idx'.$val);
 		$new = $arr[array_rand($arr)];
 
-		if (pun_strlen($new) > pun_strlen($val))
+		if (mb_strlen($new) > mb_strlen($val))
 			$random++;
 
 		return $new;

+ 1 - 1
include/subforums_view.php

@@ -181,7 +181,7 @@ foreach ($sf_array[$sf_cur_forum] as $cur_subforum)
 
 	// If there is a last_post/last_poster
 	if ($cur_subforum['last_post'] != '')
-		$last_post = '<a href="viewtopic.php?pid='.$cur_subforum['last_post_id'].'#p'.$cur_subforum['last_post_id'].'">'.pun_htmlspecialchars(pun_strlen($cur_subforum['last_topic']) > 30 ? utf8_substr($cur_subforum['last_topic'], 0, 30).'…' : $cur_subforum['last_topic']).'</a> <span class="byuser">'.format_time($cur_subforum['last_post']).' '.$lang_common['by'].' '.pun_htmlspecialchars($cur_subforum['last_poster']).'</span>'; // last topic on index - Visman
+		$last_post = '<a href="viewtopic.php?pid='.$cur_subforum['last_post_id'].'#p'.$cur_subforum['last_post_id'].'">'.pun_htmlspecialchars(mb_strlen($cur_subforum['last_topic']) > 30 ? utf8_substr($cur_subforum['last_topic'], 0, 30).'…' : $cur_subforum['last_topic']).'</a> <span class="byuser">'.format_time($cur_subforum['last_post']).' '.$lang_common['by'].' '.pun_htmlspecialchars($cur_subforum['last_poster']).'</span>'; // last topic on index - Visman
 	else if ($cur_subforum['redirect_url'] != '')
 		$last_post = '- - -';
 	else

+ 1 - 2
misc.php

@@ -143,8 +143,7 @@ else if ($request->isGet('email'))
 			message($lang_misc['No email subject']);
 		else if ($message == '')
 			message($lang_misc['No email message']);
-		// Here we use strlen() not pun_strlen() as we want to limit the post to PUN_MAX_POSTSIZE bytes, not characters
-		else if (strlen($message) > PUN_MAX_POSTSIZE)
+		else if (mb_strlen($message) > PUN_MAX_POSTSIZE)
 			message($lang_misc['Too long email message']);
 
 		if ($pun_user['last_email_sent'] != '' && (time() - $pun_user['last_email_sent']) < $pun_user['g_email_flood'] && (time() - $pun_user['last_email_sent']) >= 0)

+ 1 - 1
moderate.php

@@ -198,7 +198,7 @@ if ($request->isGet('tid'))
 
 			if ($new_subject == '')
 				message($lang_post['No subject']);
-			else if (pun_strlen($new_subject) > 70)
+			else if (mb_strlen($new_subject) > 70)
 				message($lang_post['Too long subject']);
 
 			// Get data from the new first post

+ 3 - 4
post.php

@@ -93,7 +93,7 @@ if ($request->isPost('form_sent'))
 			$errors[] = $lang_post['No subject'];
 		else if ($pun_config['o_censoring'] == '1' && $censored_subject == '')
 			$errors[] = $lang_post['No subject after censoring'];
-		else if (pun_strlen($subject) > 70)
+		else if (mb_strlen($subject) > 70)
 			$errors[] = $lang_post['Too long subject'];
 		else if ($pun_config['p_subject_all_caps'] == '0' && is_all_uppercase($subject) && !$pun_user['is_admmod'])
 			$errors[] = $lang_post['All caps subject'];
@@ -140,8 +140,7 @@ if ($request->isPost('form_sent'))
 	// Clean up message from POST
 	$orig_message = $message = pun_linebreaks(trim($request->postStr('req_message')));
 
-	// Here we use strlen() not pun_strlen() as we want to limit the post to PUN_MAX_POSTSIZE bytes, not characters
-	if (pun_strlen($message) > PUN_MAX_POSTSIZE)
+	if (mb_strlen($message) > PUN_MAX_POSTSIZE)
 		$errors[] = sprintf($lang_post['Too long message'], forum_number_format(PUN_MAX_POSTSIZE));
 	else if ($pun_config['p_message_all_caps'] == '0' && is_all_uppercase($message) && !$pun_user['is_admmod'])
 		$errors[] = $lang_post['All caps message'];
@@ -188,7 +187,7 @@ if ($request->isPost('form_sent'))
 		require PUN_ROOT.'include/search_idx.php';
 
 // START Merge Post
-		if (isset($pun_config['o_merge_timeout']) && !$pun_user['is_guest'] && !$fid && (($is_admmod && $request->isPost('merge')) || !$is_admmod) && $cur_posting['poster_id']!=NULL && $cur_posting['message']!=NULL && ($now - $cur_posting['posted'])<$pun_config['o_merge_timeout'] && (pun_strlen($cur_posting['message'].$message) + 100 < PUN_MAX_POSTSIZE))
+		if (isset($pun_config['o_merge_timeout']) && !$pun_user['is_guest'] && !$fid && (($is_admmod && $request->isPost('merge')) || !$is_admmod) && $cur_posting['poster_id']!=NULL && $cur_posting['message']!=NULL && ($now - $cur_posting['posted'])<$pun_config['o_merge_timeout'] && (mb_strlen($cur_posting['message'].$message) + 100 < PUN_MAX_POSTSIZE))
 		{
 			$message= '[after='.($now - $cur_posting['posted']).']'."\n".$message;
 			$merged = true;

+ 3 - 3
profile.php

@@ -95,7 +95,7 @@ if ($action === 'change_pass')
 
 		if ($new_password1 != $new_password2)
 			message($lang_prof_reg['Pass not match']);
-		if (pun_strlen($new_password1) < 6)
+		if (mb_strlen($new_password1) < 6)
 			message($lang_prof_reg['Pass too short']);
 
 		$result = $db->query('SELECT * FROM '.$db->prefix.'users WHERE id='.$id) or error('Unable to fetch password', __FILE__, __LINE__, $db->error());
@@ -908,8 +908,8 @@ else if ($request->isPost('form_sent'))
 				$form['signature'] = pun_linebreaks(trim($request->postStr('signature')));
 
 				// Validate signature
-				if (pun_strlen($form['signature']) > $pun_config['p_sig_length'])
-					message(sprintf($lang_prof_reg['Sig too long'], $pun_config['p_sig_length'], pun_strlen($form['signature']) - $pun_config['p_sig_length']));
+				if (mb_strlen($form['signature']) > $pun_config['p_sig_length'])
+					message(sprintf($lang_prof_reg['Sig too long'], $pun_config['p_sig_length'], mb_strlen($form['signature']) - $pun_config['p_sig_length']));
 				else if (substr_count($form['signature'], "\n") > ($pun_config['p_sig_lines']-1))
 					message(sprintf($lang_prof_reg['Sig too many lines'], $pun_config['p_sig_lines']));
 				else if ($form['signature'] && $pun_config['p_sig_all_caps'] == '0' && is_all_uppercase($form['signature']) && !$pun_user['is_admmod'])

+ 1 - 1
register.php

@@ -94,7 +94,7 @@ if ($request->isPost('form_sent'))
 	// Validate username and passwords
 	check_username($username);
 
-	if (pun_strlen($password1) < 6)
+	if (mb_strlen($password1) < 6)
 		$errors[] = $lang_prof_reg['Pass too short'];
 	else if ($password1 != $password2)
 		$errors[] = $lang_prof_reg['Pass not match'];

+ 2 - 2
search.php

@@ -61,10 +61,10 @@ if (! empty($action) || $request->isGet('search_id'))
 		$keywords = utf8_strtolower(trim($request->getStr('keywords')));
 		$author = utf8_strtolower(trim($request->getStr('author')));
 
-		if (preg_match('%^[\*\%]+$%', $keywords) || (pun_strlen(str_replace(array('*', '%'), '', $keywords)) < PUN_SEARCH_MIN_WORD && !is_cjk($keywords)))
+		if (preg_match('%^[\*\%]+$%', $keywords) || (mb_strlen(str_replace(array('*', '%'), '', $keywords)) < PUN_SEARCH_MIN_WORD && !is_cjk($keywords)))
 			$keywords = '';
 
-		if (preg_match('%^[\*\%]+$%', $author) || pun_strlen(str_replace(array('*', '%'), '', $author)) < 2)
+		if (preg_match('%^[\*\%]+$%', $author) || mb_strlen(str_replace(array('*', '%'), '', $author)) < 2)
 			$author = '';
 
 		if (!$keywords && !$author)

+ 3 - 3
upfiles.php

@@ -394,11 +394,11 @@ else
 
 ?>
 						<li>
-							<div class="upf-name" title="<?php echo pun_htmlspecialchars($f) ?>"><span><?php echo pun_htmlspecialchars(pun_strlen($f) > 20 ? utf8_substr($f, 0, 18).'…' : $f) ?></span></div>
+							<div class="upf-name" title="<?php echo pun_htmlspecialchars($f) ?>"><span><?php echo pun_htmlspecialchars(mb_strlen($f) > 20 ? utf8_substr($f, 0, 18).'…' : $f) ?></span></div>
 							<div class="upf-file" style="height:<?php echo $height ?>px;">
 								<a href="<?php echo pun_htmlspecialchars(get_base_url(true).'/'.$file).$fb ?>">
-<?php if ($fmini || $fb): ?>									<img src="<?php echo pun_htmlspecialchars($fmini ? get_base_url(true).'/'.$mini : get_base_url(true).'/'.$file) ?>" alt="<?php echo pun_htmlspecialchars((pun_strlen($fi[1]) > 15 ? utf8_substr($fi[1], 0, 10).'… ' : $fi[1]).'.'.$fi[2]) ?>" />
-<?php else: ?>									<span><?php echo pun_htmlspecialchars((pun_strlen($fi[1]) > 15 ? utf8_substr($fi[1], 0, 10).'… ' : $fi[1]).'.'.$fi[2]) ?></span>
+<?php if ($fmini || $fb): ?>									<img src="<?php echo pun_htmlspecialchars($fmini ? get_base_url(true).'/'.$mini : get_base_url(true).'/'.$file) ?>" alt="<?php echo pun_htmlspecialchars((mb_strlen($fi[1]) > 15 ? utf8_substr($fi[1], 0, 10).'… ' : $fi[1]).'.'.$fi[2]) ?>" />
+<?php else: ?>									<span><?php echo pun_htmlspecialchars((mb_strlen($fi[1]) > 15 ? utf8_substr($fi[1], 0, 10).'… ' : $fi[1]).'.'.$fi[2]) ?></span>
 <?php endif; ?>
 								</a>
 							</div>