Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EZP-27360: Make Template Operators utf8 friendly #1298

Merged
merged 1 commit into from May 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 33 additions & 33 deletions lib/eztemplate/classes/eztemplatearrayoperator.php
Expand Up @@ -434,7 +434,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
{
if ( $isString )
{
$result = ( strpos( $inParam, $matchParam ) !== false );
$result = ( mb_strpos( $inParam, $matchParam ) !== false );
}
else if( $isArray )
{
Expand All @@ -453,7 +453,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,

if ( $isString )
{
$code = '%output% = ( strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );';
$code = '%output% = ( mb_strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );';
}
else if ( $isArray )
{
Expand All @@ -463,7 +463,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
{
$code = 'if( is_string( ' . $inParamCode . ' ) )' . "\n" .
'{' . "\n" .
' %output% = ( strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );' . "\n" .
' %output% = ( mb_strpos( ' . $inParamCode . ', ' . $matchParamCode . ' ) !== false );' . "\n" .
'}' . "\n" .
'else if ( is_array( ' . $inParamCode . ' ) )' . "\n" .
'{' . "\n" .
Expand Down Expand Up @@ -731,7 +731,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
{
if ( $isString )
{
return array( eZTemplateNodeTool::createStringElement( substr( $inputArray, $offset, $length ) ) );
return array( eZTemplateNodeTool::createStringElement( mb_substr( $inputArray, $offset, $length ) ) );
}
else if ( $isArray )
{
Expand All @@ -747,7 +747,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,

if ( $isString )
{
$code = '%output% = substr( ' . $inputArrayCode . ', ' . $offsetCode;
$code = '%output% = mb_substr( ' . $inputArrayCode . ', ' . $offsetCode;
if ( $lengthCode )
$code .= ', ' . $lengthCode;
$code .= ' );';
Expand All @@ -764,13 +764,13 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
$code = ( '%tmp1% = ' . $inputArrayCode . ';' . "\n" .
'if ( is_string( %tmp1% ) )' . "\n" .
'{' . "\n" .
' %output% = ( substr( %tmp1%, 0, ' . $offsetCode . ' )' );
' %output% = ( mb_substr( %tmp1%, 0, ' . $offsetCode . ' )' );

$lengthCode = !$lengthCode ? 1 : $lengthCode;

if ( $lengthCode )
{
$code .= ' . substr( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )';
$code .= ' . mb_substr( %tmp1%, ' . $offsetCode . ' + ' . $lengthCode . ' )';
}
$code .= ( ' );' . "\n" .
'}' . "\n" .
Expand Down Expand Up @@ -845,7 +845,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
{
if ( $isString )
{
return array( eZTemplateNodeTool::createStringElement( substr( $inputArray, 0, $offset ) . $insertText . substr( $inputArray, $offset ) ) );
return array( eZTemplateNodeTool::createStringElement( mb_substr( $inputArray, 0, $offset ) . $insertText . mb_substr( $inputArray, $offset ) ) );
}
else if ( $isArray )
{
Expand All @@ -865,7 +865,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
$tmpCount = 0;
if ( $isString )
{
$code = '%output% = substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );';
$code = '%output% = mb_substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . mb_substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );';
}
else if ( $isArray )
{
Expand All @@ -890,7 +890,7 @@ function arrayTrans( $operatorName, &$node, $tpl, &$resourceData,
$code = '%tmp1% = ' . $inputArrayCode . ';' . "\n" .
'if ( is_string( %tmp1% ) )' . "\n" .
'{' . "\n" .
' %output% = substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );' . "\n" .
' %output% = mb_substr( ' . $inputArrayCode . ', 0, ' . $offsetCode . ' ) . ' . $insertElemCode[0] . ' . mb_substr( ' . $inputArrayCode . ', ' . $offsetCode . ' );' . "\n" .
'}' . "\n" .
'else if ( is_array( %tmp1% ) )' . "\n" .
'{' . "\n" .
Expand Down Expand Up @@ -1076,7 +1076,7 @@ function compareTrans( $operatorName, &$node, $tpl, &$resourceData,
{
if ( $isString )
{
$result = ( strrpos( $inParam, $compareParams[0] ) === ( strlen( $inParam ) - strlen ( $compareParams[0] ) ) );
$result = ( mb_strrpos( $inParam, $compareParams[0] ) === ( mb_strlen( $inParam ) - mb_strlen ( $compareParams[0] ) ) );
}
else if ( $isArray )
{
Expand All @@ -1100,7 +1100,7 @@ function compareTrans( $operatorName, &$node, $tpl, &$resourceData,

if ( $isString )
{
$code = '%output% = ( strrpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === ( strlen( ' . $inParamCode . ' ) - strlen( ' . $compareParamsCode[0] . ' ) ) );';
$code = '%output% = ( mb_strrpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === ( mb_strlen( ' . $inParamCode . ' ) - mb_strlen( ' . $compareParamsCode[0] . ' ) ) );';
}
else if ( $isArray )
{
Expand All @@ -1124,7 +1124,7 @@ function compareTrans( $operatorName, &$node, $tpl, &$resourceData,
$code = '%tmp4% = ' . $inParamCode . ';' . "\n" .
'if ( is_string( %tmp4% ) )' . "\n" .
'{' . "\n" .
' %output% = ( strrpos( %tmp4%, ' . $compareParamsCode[0] . ' ) === ( strlen( %tmp4% ) - strlen( ' . $compareParamsCode[0] . ' ) ) );' . "\n" .
' %output% = ( mb_strrpos( %tmp4%, ' . $compareParamsCode[0] . ' ) === ( mb_strlen( %tmp4% ) - mb_strlen( ' . $compareParamsCode[0] . ' ) ) );' . "\n" .
'}' . "\n" .
'else if( is_array( %tmp4% ) )' . "\n" .
'{' . "\n" .
Expand Down Expand Up @@ -1153,7 +1153,7 @@ function compareTrans( $operatorName, &$node, $tpl, &$resourceData,
{
if ( $isString )
{
$result = ( strpos ( $inParam, $compareParams[0] ) === 0 );
$result = ( mb_strpos ( $inParam, $compareParams[0] ) === 0 );
}
else if ( $isArray )
{
Expand All @@ -1173,7 +1173,7 @@ function compareTrans( $operatorName, &$node, $tpl, &$resourceData,

if ( $isString )
{
$code = '%output% = ( ' . $compareParamsCode[0] . ' && strpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === 0 );';
$code = '%output% = ( ' . $compareParamsCode[0] . ' && mb_strpos( ' . $inParamCode . ', ' . $compareParamsCode[0] . ' ) === 0 );';
}
else if ( $isArray )
{
Expand All @@ -1197,7 +1197,7 @@ function compareTrans( $operatorName, &$node, $tpl, &$resourceData,
" if ( {$compareParamsCode[0]} == '' )\n" .
" %output% = false;\n" .
" else\n" .
' %output% = ( strpos( %tmp1%, ' . $compareParamsCode[0] . ' ) === 0 );' . "\n" .
' %output% = ( mb_strpos( %tmp1%, ' . $compareParamsCode[0] . ' ) === 0 );' . "\n" .
'}' . "\n" .
'else if( is_array( %tmp1% ) )' . "\n" .
'{' . "\n" .
Expand Down Expand Up @@ -1292,14 +1292,14 @@ function extractTrans( $operatorName, &$node, $tpl, &$resourceData,
if ( $operatorName == $this->ExtractRightName or !$length )
{
if ( is_string( $input ) )
$output = substr( $input, $offset );
$output = mb_substr( $input, $offset );
else
$output = array_slice( $input, $offset );
}
else
{
if ( is_string( $input ) )
$output = substr( $input, $offset, $length );
$output = mb_substr( $input, $offset, $length );
else
$output = array_slice( $input, $offset, $length );
}
Expand All @@ -1314,7 +1314,7 @@ function extractTrans( $operatorName, &$node, $tpl, &$resourceData,
{
$values[] = $parameters[0];
$code = ( "if ( is_string( %" . count( $values ) . "% ) )\n" .
" %output% = substr( %" . count( $values ) . "%, " . $code . " );\n" .
" %output% = mb_substr( %" . count( $values ) . "%, " . $code . " );\n" .
"else\n" .
" %output% = array_slice( %" . count( $values ) . "%, " . $code . " );" );
}
Expand Down Expand Up @@ -1947,7 +1947,7 @@ function modify( $tpl, $operatorName, $operatorParameters,
// Check if the string contains a specified sequence of chars/string.
case $this->ContainsName:
{
$operatorValue = ( strpos( $operatorValue, $namedParameters['match'] ) !== false );
$operatorValue = ( mb_strpos( $operatorValue, $namedParameters['match'] ) !== false );
}
break;

Expand All @@ -1969,29 +1969,29 @@ function modify( $tpl, $operatorName, $operatorParameters,
case $this->ExtractName:
{
if ( $namedParameters['extract_length'] === false )
$operatorValue = substr( $operatorValue, $namedParameters['extract_start'] );
$operatorValue = mb_substr( $operatorValue, $namedParameters['extract_start'] );
else
$operatorValue = substr( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] );
$operatorValue = mb_substr( $operatorValue, $namedParameters['extract_start'], $namedParameters['extract_length'] );
}
break;

// Extract string/portion from the start of the string.
case $this->ExtractLeftName:
{
$operatorValue = substr( $operatorValue, 0, $namedParameters['length'] );
$operatorValue = mb_substr( $operatorValue, 0, $namedParameters['length'] );
}break;

// Extract string/portion from the end of the string.
case $this->ExtractRightName:
{
$offset = strlen( $operatorValue ) - $namedParameters['length'];
$operatorValue = substr( $operatorValue, $offset );
$offset = mb_strlen( $operatorValue ) - $namedParameters['length'];
$operatorValue = mb_substr( $operatorValue, $offset );
}break;

// Check if string begins with specified sequence:
case $this->BeginsWithName:
{
if ( strpos( $operatorValue, $namedParameters['match'] ) === 0 )
if ( mb_strpos( $operatorValue, $namedParameters['match'] ) === 0 )
{
$operatorValue = true;
}
Expand All @@ -2004,7 +2004,7 @@ function modify( $tpl, $operatorName, $operatorParameters,
// Check if string ends with specified sequence:
case $this->EndsWithName:
{
if ( strrpos( $operatorValue, $namedParameters['match'] ) === ( strlen( $operatorValue ) - strlen ($namedParameters['match'] ) ) )
if ( mb_strrpos( $operatorValue, $namedParameters['match'] ) === ( mb_strlen( $operatorValue ) - mb_strlen ($namedParameters['match'] ) ) )
{
$operatorValue = true;
}
Expand Down Expand Up @@ -2041,24 +2041,24 @@ function modify( $tpl, $operatorName, $operatorParameters,
// Insert a given string at a specified position:
case $this->InsertName:
{
$first = substr( $operatorValue, 0, $namedParameters['insert_position'] );
$second = substr( $operatorValue, $namedParameters['insert_position'] );
$first = mb_substr( $operatorValue, 0, $namedParameters['insert_position'] );
$second = mb_substr( $operatorValue, $namedParameters['insert_position'] );
$operatorValue = $first . $namedParameters['insert_string'] . $second;
}break;

// Remove a portion from a string:
case $this->RemoveName:
{
$first = substr( $operatorValue, 0, $namedParameters['offset'] );
$second = substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
$first = mb_substr( $operatorValue, 0, $namedParameters['offset'] );
$second = mb_substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
$operatorValue = $first . $second;
}break;

// Replace a portion of a string:
case $this->ReplaceName:
{
$first = substr( $operatorValue, 0, $namedParameters['offset'] );
$second = substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
$first = mb_substr( $operatorValue, 0, $namedParameters['offset'] );
$second = mb_substr( $operatorValue, $namedParameters['offset'] + $namedParameters['length'] );
$mid = '';

for ( $i = 2; $i < count( $operatorParameters ); ++ $i )
Expand Down