rollback r11168, r11171. issue 2159.

git-svn-id: http://xe-core.googlecode.com/svn/branches/luminous@11188 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
flyskyko 2012-09-10 06:16:34 +00:00
parent de9492a1c0
commit e03e365ff0
4 changed files with 16 additions and 108 deletions

View file

@ -140,7 +140,13 @@ class HTMLDisplayHandler {
if(is_array(Context::get('INPUT_ERROR')))
{
$output = preg_replace_callback('@<form[^<>]* id="' . $_SESSION['INPUT_ERROR_ID'] . '"[^<>]*/?>.*?</form>@is', array(&$this, '_inputError'), $output);
$INPUT_ERROR = Context::get('INPUT_ERROR');
$keys = array_keys($INPUT_ERROR);
$keys = '('.implode('|', $keys).')';
$output = preg_replace_callback('@(<input)([^>]*?)\sname="'.$keys.'"([^>]*?)/?>@is', array(&$this, '_preserveValue'), $output);
$output = preg_replace_callback('@<select[^>]*\sname="'.$keys.'".+</select>@isU', array(&$this, '_preserveSelectValue'), $output);
$output = preg_replace_callback('@<textarea[^>]*\sname="'.$keys.'".+</textarea>@isU', array(&$this, '_preserveTextAreaValue'), $output);
}
if(__DEBUG__==3) $GLOBALS['__trans_content_elapsed__'] = getMicroTime()-$start;
@ -173,61 +179,6 @@ class HTMLDisplayHandler {
$oModuleController->replaceDefinedLangCode($output);
}
/**
* Display prev values that inputted by user
* @param array $matches
* @return string
*/
function _inputError($matches)
{
$INPUT_ERROR = Context::get('INPUT_ERROR');
$keys = array();
foreach($INPUT_ERROR as $key => $value)
{
if(is_array($value))
{
$keys[] = $key . '\[[^\]]*\]';
}
else
{
$keys[] = $key;
}
}
$keys = '('.implode('|', $keys).')';
$matches[0] = preg_replace_callback('@(<input)([^>]*?)\sname="'.$keys.'"([^>]*?)/?>@is', array(&$this, '_preserveValue'), $matches[0]);
$matches[0] = preg_replace_callback('@<select[^>]*\sname="'.$keys.'".+</select>@isU', array(&$this, '_preserveSelectValue'), $matches[0]);
$matches[0] = preg_replace_callback('@<textarea[^>]*\sname="'.$keys.'".+</textarea>@isU', array(&$this, '_preserveTextAreaValue'), $matches[0]);
return $matches[0];
}
function _getInputErrorValue($ogName, &$value)
{
$INPUT_ERROR = Context::get('INPUT_ERROR');
if(preg_match('/^([^\[]+)\[([^\]]+)\]$/', $ogName, $m))
{
$name = $m[1];
$key = $m[2];
}
else
{
$name = $ogName;
}
if(isset($key))
{
$value = $INPUT_ERROR[$name][$key];
}
else
{
$value = $INPUT_ERROR[$name];
}
}
/**
* when display mode is HTML, prepare code before print about <input> tag value.
* @param array $match input value.
@ -235,7 +186,7 @@ class HTMLDisplayHandler {
**/
function _preserveValue($match)
{
$this->_getInputErrorValue($match[3], $value);
$INPUT_ERROR = Context::get('INPUT_ERROR');
$str = $match[1].$match[2].' name="'.$match[3].'"'.$match[4];
@ -246,7 +197,7 @@ class HTMLDisplayHandler {
switch($type){
case 'text':
case 'hidden':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.@htmlspecialchars($value).'"';
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str).' value="'.@htmlspecialchars($INPUT_ERROR[$match[3]]).'"';
break;
case 'password':
$str = preg_replace('@\svalue="[^"]*?"@', ' ', $str);
@ -254,7 +205,7 @@ class HTMLDisplayHandler {
case 'radio':
case 'checkbox':
$str = preg_replace('@\schecked(="[^"]*?")?@', ' ', $str);
if(@preg_match('@\s(?i:value)="'.$value.'"@', $str)) {
if(@preg_match('@\s(?i:value)="'.$INPUT_ERROR[$match[3]].'"@', $str)) {
$str .= ' checked="checked"';
}
break;
@ -270,14 +221,13 @@ class HTMLDisplayHandler {
**/
function _preserveSelectValue($matches)
{
$this->_getInputErrorValue($matches[1], $value);
$INPUT_ERROR = Context::get('INPUT_ERROR');
preg_replace('@\sselected(="[^"]*?")?@', ' ', $matches[0]);
preg_match('@<select.*?>@is', $matches[0], $mm);
preg_match_all('@<option[^>]*\svalue="([^"]*)".+</option>@isU', $matches[0], $m);
$key = array_search($value, $m[1]);
$key = array_search($INPUT_ERROR[$matches[1]], $m[1]);
if($key === FALSE)
{
return $matches[0];
@ -295,10 +245,9 @@ class HTMLDisplayHandler {
**/
function _preserveTextAreaValue($matches)
{
$this->_getInputErrorValue($matches[1], $value);
$INPUT_ERROR = Context::get('INPUT_ERROR');
preg_match('@<textarea.*?>@is', $matches[0], $mm);
return $mm[0].$value.'</textarea>';
return $mm[0].$INPUT_ERROR[$matches[1]].'</textarea>';
}
/**