@@ -12,7 +12,7 @@ |
||
| 12 | 12 | public static function flatArray(array $input = [], $separator_elements = ', ', $separator = ': ') |
| 13 | 13 | { |
| 14 | 14 | return implode($separator_elements, array_map( |
| 15 | - function ($v, $k, $s) { |
|
| 15 | + function($v, $k, $s) { |
|
| 16 | 16 | return sprintf("%s{$s}\"%s\"", $k, $v); |
| 17 | 17 | }, |
| 18 | 18 | $input, |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | foreach ($matches[0] as $key => $match) { |
| 55 | 55 | |
| 56 | - $current = $matches[ 0 ][ $key ][ 0 ]; |
|
| 56 | + $current = $matches[0][$key][0]; |
|
| 57 | 57 | |
| 58 | - if(isset($matches[0][$key+1][0])){ |
|
| 59 | - $next = $matches[0][$key+1][0]; |
|
| 60 | - $nextOffset = $matches[0][$key+1][1]; |
|
| 58 | + if (isset($matches[0][$key + 1][0])) { |
|
| 59 | + $next = $matches[0][$key + 1][0]; |
|
| 60 | + $nextOffset = $matches[0][$key + 1][1]; |
|
| 61 | 61 | $realNextOffset = ($delta === 0) ? $nextOffset : ($nextOffset + $delta); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -65,13 +65,13 @@ discard block |
||
| 65 | 65 | $offset = $matches[0][$key][1]; |
| 66 | 66 | $realOffset = ($delta === 0) ? $offset : ($offset + $delta); |
| 67 | 67 | |
| 68 | - if( $current === '<' and isset($next)){ |
|
| 68 | + if ($current === '<' and isset($next)) { |
|
| 69 | 69 | |
| 70 | 70 | // 1. if next is > or |
| 71 | 71 | // 2. next is < and is not html tag (like < >) |
| 72 | - $insideAngularTags = substr($html, $realOffset, ($realNextOffset-$realOffset+1)); |
|
| 72 | + $insideAngularTags = substr($html, $realOffset, ($realNextOffset - $realOffset + 1)); |
|
| 73 | 73 | |
| 74 | - if($next !== '>' or !Strings::isHtmlString($insideAngularTags) ){ |
|
| 74 | + if ($next !== '>' or !Strings::isHtmlString($insideAngularTags)) { |
|
| 75 | 75 | $html = substr_replace($html, self::LT_PLACEHOLDER, $realOffset, $length); |
| 76 | 76 | $delta = $delta + strlen(self::LT_PLACEHOLDER) - $length; |
| 77 | 77 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * |
| 97 | 97 | * @return mixed |
| 98 | 98 | */ |
| 99 | - private static function protectNotClosedHtmlTags( $html) |
|
| 99 | + private static function protectNotClosedHtmlTags($html) |
|
| 100 | 100 | { |
| 101 | 101 | preg_match_all('/<|>/iu', $html, $matches, PREG_OFFSET_CAPTURE); |
| 102 | 102 | |
@@ -106,17 +106,17 @@ discard block |
||
| 106 | 106 | |
| 107 | 107 | // 1. Map all tags |
| 108 | 108 | foreach ($matches[0] as $key => $match) { |
| 109 | - $current = $matches[ 0 ][ $key ][ 0 ]; |
|
| 110 | - $currentOffset = $matches[ 0 ][ $key ][ 1 ]; |
|
| 109 | + $current = $matches[0][$key][0]; |
|
| 110 | + $currentOffset = $matches[0][$key][1]; |
|
| 111 | 111 | |
| 112 | 112 | // check every string inside angular brackets (< and >) |
| 113 | - if( $current === '<' and isset($matches[0][$key+1][0]) and $matches[0][$key+1][0] === '>' ){ |
|
| 114 | - $nextOffset = $matches[0][$key+1][1]; |
|
| 115 | - $tag = substr($html, ($currentOffset + 1), ( $nextOffset - $currentOffset - 1 )); |
|
| 113 | + if ($current === '<' and isset($matches[0][$key + 1][0]) and $matches[0][$key + 1][0] === '>') { |
|
| 114 | + $nextOffset = $matches[0][$key + 1][1]; |
|
| 115 | + $tag = substr($html, ($currentOffset + 1), ($nextOffset - $currentOffset - 1)); |
|
| 116 | 116 | $trimmedTag = trim($tag); |
| 117 | 117 | |
| 118 | 118 | // if the tag is self closed do nothing |
| 119 | - if(Strings::lastChar($tag) !== '/'){ |
|
| 119 | + if (Strings::lastChar($tag) !== '/') { |
|
| 120 | 120 | $tags[] = $trimmedTag; |
| 121 | 121 | $offsets[] = $currentOffset; |
| 122 | 122 | $originalLengths[] = strlen($tag) + 2; // add 2 to length because there are < and > |
@@ -127,18 +127,18 @@ discard block |
||
| 127 | 127 | // 2. Removing closed tags |
| 128 | 128 | $indexes = []; |
| 129 | 129 | |
| 130 | - if(count($tags) > 0){ |
|
| 131 | - foreach ($tags as $index => $tag){ |
|
| 130 | + if (count($tags) > 0) { |
|
| 131 | + foreach ($tags as $index => $tag) { |
|
| 132 | 132 | |
| 133 | - if(Strings::contains('/', $tag)){ |
|
| 133 | + if (Strings::contains('/', $tag)) { |
|
| 134 | 134 | $complementaryTag = $tag; |
| 135 | 135 | } else { |
| 136 | - $complementaryTag = '/'.explode(' ', $tag)[0]; |
|
| 136 | + $complementaryTag = '/' . explode(' ', $tag)[0]; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $complementaryTagIndex = array_search($complementaryTag, $tags); |
| 140 | 140 | |
| 141 | - if(false !== $complementaryTagIndex){ |
|
| 141 | + if (false !== $complementaryTagIndex) { |
|
| 142 | 142 | $indexes[] = $index; |
| 143 | 143 | $indexes[] = $complementaryTagIndex; |
| 144 | 144 | } |
@@ -146,15 +146,15 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | $indexes = array_unique($indexes); |
| 149 | - foreach ($indexes as $index){ |
|
| 149 | + foreach ($indexes as $index) { |
|
| 150 | 150 | unset($tags[$index]); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // 3. Loop not closed tags |
| 154 | 154 | $delta = 0; |
| 155 | 155 | |
| 156 | - if(count($tags)){ |
|
| 157 | - foreach ($tags as $index => $tag){ |
|
| 156 | + if (count($tags)) { |
|
| 157 | + foreach ($tags as $index => $tag) { |
|
| 158 | 158 | |
| 159 | 159 | $length = $originalLengths[$index]; |
| 160 | 160 | $offset = $offsets[$index]; |
@@ -176,9 +176,9 @@ discard block |
||
| 176 | 176 | * |
| 177 | 177 | * @return array |
| 178 | 178 | */ |
| 179 | - private static function extractHtmlNode( $html, $toBeEscaped = false) |
|
| 179 | + private static function extractHtmlNode($html, $toBeEscaped = false) |
|
| 180 | 180 | { |
| 181 | - $pattern = "/<([a-zA-Z0-9._-]+)([^>]|[^<]*?)(([\s]*\/>)|". |
|
| 181 | + $pattern = "/<([a-zA-Z0-9._-]+)([^>]|[^<]*?)(([\s]*\/>)|" . |
|
| 182 | 182 | "(>((([^<]*?|<\!\-\-.*?\-\->)|(?R))*)<\/\\1[\s]*>))/sm"; |
| 183 | 183 | preg_match_all($pattern, $html, $matches, PREG_OFFSET_CAPTURE); |
| 184 | 184 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | foreach ($matches[0] as $key => $match) { |
| 188 | 188 | |
| 189 | 189 | $attributes = isset($matches[2][$key][0]) ? self::getAttributes($matches[2][$key][0]) : []; |
| 190 | - $base64Decoded = (isset($attributes['equiv-text'])) ? base64_decode(str_replace("base64:", "", $attributes['equiv-text'])): null; |
|
| 190 | + $base64Decoded = (isset($attributes['equiv-text'])) ? base64_decode(str_replace("base64:", "", $attributes['equiv-text'])) : null; |
|
| 191 | 191 | $tagName = $matches[1][$key][0]; |
| 192 | 192 | $text = (isset($matches[6][$key][0]) and '' !== $matches[6][$key][0]) ? $matches[6][$key][0] : null; |
| 193 | 193 | $originalText = $text; |
@@ -237,9 +237,9 @@ discard block |
||
| 237 | 237 | * |
| 238 | 238 | * @return string|string[] |
| 239 | 239 | */ |
| 240 | - private static function restoreLessThanAndGreaterThanSymbols( $text) |
|
| 240 | + private static function restoreLessThanAndGreaterThanSymbols($text) |
|
| 241 | 241 | { |
| 242 | - return str_replace([self::LT_PLACEHOLDER, self::GT_PLACEHOLDER], ['<','>'], $text); |
|
| 242 | + return str_replace([self::LT_PLACEHOLDER, self::GT_PLACEHOLDER], ['<', '>'], $text); |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -254,13 +254,13 @@ discard block |
||
| 254 | 254 | { |
| 255 | 255 | $node = ''; |
| 256 | 256 | |
| 257 | - if($start !== null){ |
|
| 257 | + if ($start !== null) { |
|
| 258 | 258 | $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($start) : $start; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($originalText) : $originalText; |
| 262 | 262 | |
| 263 | - if($end !== null){ |
|
| 263 | + if ($end !== null) { |
|
| 264 | 264 | $node .= ($toBeEscaped) ? Strings::escapeOnlyHTMLTags($end) : $end; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -7404,7 +7404,7 @@ |
||
| 7404 | 7404 | ' |
@@ -7402,7 +7402,7 @@ |
||
| 7402 | 7402 | ' |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | if (($options & $i) > 0) { |
| 47 | 47 | //variable substitution: $field can be one between 'dirname', 'basename', 'extension', 'filename' |
| 48 | 48 | // $$field gets the value of the variable named $field |
| 49 | - $returnArray[ $field ] = $$field; |
|
| 49 | + $returnArray[$field] = $$field; |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | return false; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - return strtolower($pathInfo[ 'extension' ]); |
|
| 73 | + return strtolower($pathInfo['extension']); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | return false; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - switch (strtolower($pathInfo[ 'extension' ])) { |
|
| 115 | + switch (strtolower($pathInfo['extension'])) { |
|
| 116 | 116 | case 'tmx': |
| 117 | 117 | return 'tmx'; |
| 118 | 118 | break; |
@@ -65,22 +65,22 @@ discard block |
||
| 65 | 65 | * @throws Exception\NotValidFileException |
| 66 | 66 | * @throws Exception\XmlParsingException |
| 67 | 67 | */ |
| 68 | - public function xliffToArray( $xliffContent, $collapseEmptyTags = false) |
|
| 68 | + public function xliffToArray($xliffContent, $collapseEmptyTags = false) |
|
| 69 | 69 | { |
| 70 | 70 | $xliff = []; |
| 71 | 71 | $xliffContent = self::forceUft8Encoding($xliffContent, $xliff); |
| 72 | 72 | $xliffVersion = XliffVersionDetector::detect($xliffContent); |
| 73 | 73 | $info = XliffProprietaryDetect::getInfoFromXliffContent($xliffContent); |
| 74 | 74 | |
| 75 | - if($xliffVersion === 1){ |
|
| 75 | + if ($xliffVersion === 1) { |
|
| 76 | 76 | $xliffContent = self::removeInternalFileTagFromContent($xliffContent, $xliff); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - if($xliffVersion === 2){ |
|
| 79 | + if ($xliffVersion === 2) { |
|
| 80 | 80 | $xliffContent = self::escapeDataInOriginalMap($xliffContent); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if($collapseEmptyTags === false){ |
|
| 83 | + if ($collapseEmptyTags === false) { |
|
| 84 | 84 | $xliffContent = self::insertPlaceholderInEmptyTags($xliffContent); |
| 85 | 85 | } |
| 86 | 86 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | $enc = mb_detect_encoding($xliffContent); |
| 106 | 106 | |
| 107 | 107 | if ($enc !== 'UTF-8') { |
| 108 | - $xliff[ 'parser-warnings' ][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
| 108 | + $xliff['parser-warnings'][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only"; |
|
| 109 | 109 | |
| 110 | 110 | return iconv($enc, 'UTF-8', $xliffContent); |
| 111 | 111 | } |
@@ -126,22 +126,22 @@ discard block |
||
| 126 | 126 | private static function removeInternalFileTagFromContent($xliffContent, &$xliff) |
| 127 | 127 | { |
| 128 | 128 | $index = 1; |
| 129 | - $a = Strings::preg_split( '|<internal-file[\s>]|si', $xliffContent ); |
|
| 129 | + $a = Strings::preg_split('|<internal-file[\s>]|si', $xliffContent); |
|
| 130 | 130 | |
| 131 | 131 | // no match, return original string |
| 132 | - if(count($a) === 1){ |
|
| 132 | + if (count($a) === 1) { |
|
| 133 | 133 | return $a[0]; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - $b = Strings::preg_split( '|</internal-file>|si', $a[1] ); |
|
| 137 | - $strippedContent = $a[0].$b[1]; |
|
| 138 | - $xliff['files'][$index][ 'reference' ][] = self::extractBase64($b[0]); |
|
| 136 | + $b = Strings::preg_split('|</internal-file>|si', $a[1]); |
|
| 137 | + $strippedContent = $a[0] . $b[1]; |
|
| 138 | + $xliff['files'][$index]['reference'][] = self::extractBase64($b[0]); |
|
| 139 | 139 | $index++; |
| 140 | 140 | |
| 141 | - if(isset($a[2])){ |
|
| 142 | - $c = Strings::preg_split( '|</internal-file[\s>]|si', $a[2] ); |
|
| 141 | + if (isset($a[2])) { |
|
| 142 | + $c = Strings::preg_split('|</internal-file[\s>]|si', $a[2]); |
|
| 143 | 143 | $strippedContent .= $c[1]; |
| 144 | - $xliff['files'][$index][ 'reference' ][] = self::extractBase64($c[0]); |
|
| 144 | + $xliff['files'][$index]['reference'][] = self::extractBase64($c[0]); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $strippedContent; |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | private static function escapeDataInOriginalMap($xliffContent) |
| 180 | 180 | { |
| 181 | - $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceSpace' ], $xliffContent); |
|
| 182 | - $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceXliffTags' ], $xliffContent); |
|
| 181 | + $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceSpace'], $xliffContent); |
|
| 182 | + $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceXliffTags'], $xliffContent); |
|
| 183 | 183 | |
| 184 | 184 | return $xliffContent; |
| 185 | 185 | } |
@@ -202,11 +202,11 @@ discard block |
||
| 202 | 202 | { |
| 203 | 203 | preg_match_all('/<([a-zA-Z0-9._-]+)[^>]*><\/\1>/sm', $xliffContent, $emptyTagMatches); |
| 204 | 204 | |
| 205 | - if(!empty($emptyTagMatches[0])){ |
|
| 206 | - foreach ($emptyTagMatches[0] as $index => $emptyTagMatch){ |
|
| 205 | + if (!empty($emptyTagMatches[0])) { |
|
| 206 | + foreach ($emptyTagMatches[0] as $index => $emptyTagMatch) { |
|
| 207 | 207 | $matchedTag = $emptyTagMatches[1][$index]; |
| 208 | - $subst = Placeholder::EMPTY_TAG_PLACEHOLDER.'</'.$matchedTag.'>'; |
|
| 209 | - $replacedTag = str_replace('</'.$matchedTag.'>', $subst, $emptyTagMatch); |
|
| 208 | + $subst = Placeholder::EMPTY_TAG_PLACEHOLDER . '</' . $matchedTag . '>'; |
|
| 209 | + $replacedTag = str_replace('</' . $matchedTag . '>', $subst, $emptyTagMatch); |
|
| 210 | 210 | $xliffContent = str_replace($emptyTagMatch, $replacedTag, $xliffContent); |
| 211 | 211 | } |
| 212 | 212 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | $content = str_replace('\n', Placeholder::NEW_LINE_PLACEHOLDER, $content); |
| 228 | 228 | $content = str_replace('\t', Placeholder::TAB_PLACEHOLDER, $content); |
| 229 | 229 | |
| 230 | - return '<data'.$matches[1].'>'.$content.'</data>'; |
|
| 230 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | $xliffTags = XliffTags::$tags; |
| 241 | 241 | $content = $matches[2]; |
| 242 | 242 | |
| 243 | - foreach ($xliffTags as $xliffTag){ |
|
| 244 | - $content = preg_replace( '|<('.$xliffTag.'.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
| 245 | - $content = preg_replace( '|<(/'.$xliffTag.')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content ); |
|
| 243 | + foreach ($xliffTags as $xliffTag) { |
|
| 244 | + $content = preg_replace('|<(' . $xliffTag . '.*?)>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
| 245 | + $content = preg_replace('|<(/' . $xliffTag . ')>|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - return '<data'.$matches[1].'>'.$content.'</data>'; |
|
| 248 | + return '<data' . $matches[1] . '>' . $content . '</data>'; |
|
| 249 | 249 | } |
| 250 | 250 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * |
| 48 | 48 | * @return array |
| 49 | 49 | */ |
| 50 | - private static function getInfoFromTmp( $tmp) |
|
| 50 | + private static function getInfoFromTmp($tmp) |
|
| 51 | 51 | { |
| 52 | 52 | try { |
| 53 | 53 | self::checkVersion($tmp); |
@@ -59,10 +59,10 @@ discard block |
||
| 59 | 59 | // run CheckXliffProprietaryPipeline |
| 60 | 60 | $pipeline = self::runPipeline($tmp); |
| 61 | 61 | |
| 62 | - self::$fileType['proprietary' ] = $pipeline['proprietary' ]; |
|
| 63 | - self::$fileType[ 'proprietary_name' ] = $pipeline['proprietary_name' ]; |
|
| 64 | - self::$fileType[ 'proprietary_short_name' ] = $pipeline['proprietary_short_name' ]; |
|
| 65 | - self::$fileType[ 'converter_version' ] = $pipeline['converter_version' ]; |
|
| 62 | + self::$fileType['proprietary'] = $pipeline['proprietary']; |
|
| 63 | + self::$fileType['proprietary_name'] = $pipeline['proprietary_name']; |
|
| 64 | + self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name']; |
|
| 65 | + self::$fileType['converter_version'] = $pipeline['converter_version']; |
|
| 66 | 66 | |
| 67 | 67 | return self::$fileType; |
| 68 | 68 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | if (!empty($stringData)) { |
| 128 | - return array( $stringData ); |
|
| 128 | + return array($stringData); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | return false; |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected static function checkVersion($tmp) |
| 141 | 141 | { |
| 142 | - if (isset($tmp[ 0 ])) { |
|
| 143 | - self::$fileType[ 'version' ] = XliffVersionDetector::detect($tmp[ 0 ]); |
|
| 142 | + if (isset($tmp[0])) { |
|
| 143 | + self::$fileType['version'] = XliffVersionDetector::detect($tmp[0]); |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | // run CheckXliffProprietaryPipeline |
| 163 | 163 | $pipeline = self::runPipeline($tmp); |
| 164 | 164 | |
| 165 | - self::$fileType['proprietary' ] = $pipeline['proprietary' ]; |
|
| 166 | - self::$fileType[ 'proprietary_name' ] = $pipeline['proprietary_name' ]; |
|
| 167 | - self::$fileType[ 'proprietary_short_name' ] = $pipeline['proprietary_short_name' ]; |
|
| 168 | - self::$fileType[ 'converter_version' ] = $pipeline['converter_version' ]; |
|
| 165 | + self::$fileType['proprietary'] = $pipeline['proprietary']; |
|
| 166 | + self::$fileType['proprietary_name'] = $pipeline['proprietary_name']; |
|
| 167 | + self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name']; |
|
| 168 | + self::$fileType['converter_version'] = $pipeline['converter_version']; |
|
| 169 | 169 | |
| 170 | 170 | return self::$fileType; |
| 171 | 171 | } |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | |
| 195 | 195 | //if file is not proprietary AND Enforce is disabled |
| 196 | 196 | //we take it as is |
| 197 | - if (!$fileType[ 'proprietary' ] or $memoryFileType) { |
|
| 197 | + if (!$fileType['proprietary'] or $memoryFileType) { |
|
| 198 | 198 | $convert = false; |
| 199 | 199 | //ok don't convert a standard sdlxliff |
| 200 | 200 | } |
@@ -202,16 +202,16 @@ discard block |
||
| 202 | 202 | //if conversion enforce is active |
| 203 | 203 | //we force all xliff files but not files produced by SDL Studio because we can handle them |
| 204 | 204 | if ( |
| 205 | - $fileType[ 'proprietary_short_name' ] == 'matecat_converter' |
|
| 206 | - or $fileType[ 'proprietary_short_name' ] == 'trados' |
|
| 207 | - or $fileType[ 'proprietary_short_name' ] == 'xliff_v2' |
|
| 205 | + $fileType['proprietary_short_name'] == 'matecat_converter' |
|
| 206 | + or $fileType['proprietary_short_name'] == 'trados' |
|
| 207 | + or $fileType['proprietary_short_name'] == 'xliff_v2' |
|
| 208 | 208 | or $memoryFileType |
| 209 | 209 | ) { |
| 210 | 210 | $convert = false; |
| 211 | 211 | //ok don't convert a standard sdlxliff |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | - } elseif ($fileType[ 'proprietary' ]) { |
|
| 214 | + } elseif ($fileType['proprietary']) { |
|
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | 217 | * Application misconfiguration. |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | |
| 222 | 222 | $convert = -1; |
| 223 | 223 | //stop execution |
| 224 | - } elseif (!$fileType[ 'proprietary' ]) { |
|
| 224 | + } elseif (!$fileType['proprietary']) { |
|
| 225 | 225 | $convert = false; |
| 226 | 226 | //ok don't convert a standard sdlxliff |
| 227 | 227 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | { |
| 29 | 29 | preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($xliffContent, 0, 1000), $versionMatches); |
| 30 | 30 | |
| 31 | - if (empty($versionMatches) ) { |
|
| 31 | + if (empty($versionMatches)) { |
|
| 32 | 32 | throw new NotValidFileException('This is not a valid xliff file'); |
| 33 | 33 | } |
| 34 | 34 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | * |
| 18 | 18 | * @param array $map |
| 19 | 19 | */ |
| 20 | - public function __construct( array $map) |
|
| 20 | + public function __construct(array $map) |
|
| 21 | 21 | { |
| 22 | 22 | $this->map = $map; |
| 23 | 23 | } |
@@ -48,14 +48,14 @@ discard block |
||
| 48 | 48 | $html = HtmlParser::parse($string); |
| 49 | 49 | |
| 50 | 50 | // 1. Replace <ph>|<sc>|<ec> tags |
| 51 | - foreach ($html as $node){ |
|
| 51 | + foreach ($html as $node) { |
|
| 52 | 52 | $string = $this->recursiveAddEquivTextToPhTag($node, $string); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // 2. Replace <pc> tags |
| 56 | 56 | $toBeEscaped = Strings::isAnEscapedHTML($string); |
| 57 | 57 | |
| 58 | - if($this->stringContainsPcTags($string, $toBeEscaped)){ |
|
| 58 | + if ($this->stringContainsPcTags($string, $toBeEscaped)) { |
|
| 59 | 59 | |
| 60 | 60 | // replace self-closed <pc /> |
| 61 | 61 | $string = $this->replaceSelfClosedPcTags($string, $toBeEscaped); |
@@ -84,10 +84,10 @@ discard block |
||
| 84 | 84 | 'dataRefEnd', |
| 85 | 85 | ]; |
| 86 | 86 | |
| 87 | - foreach ($dataRefTags as $tag){ |
|
| 88 | - preg_match('/ '.$tag.'=[\\\\"](.*?)[\\\\"]/', $string, $matches); |
|
| 87 | + foreach ($dataRefTags as $tag) { |
|
| 88 | + preg_match('/ ' . $tag . '=[\\\\"](.*?)[\\\\"]/', $string, $matches); |
|
| 89 | 89 | |
| 90 | - if(count($matches) > 0){ |
|
| 90 | + if (count($matches) > 0) { |
|
| 91 | 91 | return true; |
| 92 | 92 | } |
| 93 | 93 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | { |
| 103 | 103 | $html = HtmlParser::parse($string); |
| 104 | 104 | |
| 105 | - foreach ($html as $node){ |
|
| 105 | + foreach ($html as $node) { |
|
| 106 | 106 | $string = $this->recursiveCleanFromEquivText($node, $string); |
| 107 | 107 | } |
| 108 | 108 | |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | * |
| 123 | 123 | * @return string |
| 124 | 124 | */ |
| 125 | - private function recursiveAddEquivTextToPhTag( $node, $string) |
|
| 125 | + private function recursiveAddEquivTextToPhTag($node, $string) |
|
| 126 | 126 | { |
| 127 | - if($node->has_children){ |
|
| 128 | - foreach ($node->inner_html as $childNode){ |
|
| 127 | + if ($node->has_children) { |
|
| 128 | + foreach ($node->inner_html as $childNode) { |
|
| 129 | 129 | $string = $this->recursiveAddEquivTextToPhTag($childNode, $string); |
| 130 | 130 | } |
| 131 | 131 | } else { |
@@ -134,18 +134,18 @@ discard block |
||
| 134 | 134 | return $string; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - $a = $node->node; // complete match. Eg: <ph id="source1" dataRef="source1"/> |
|
| 138 | - $b = $node->attributes['dataRef']; // map identifier. Eg: source1 |
|
| 137 | + $a = $node->node; // complete match. Eg: <ph id="source1" dataRef="source1"/> |
|
| 138 | + $b = $node->attributes['dataRef']; // map identifier. Eg: source1 |
|
| 139 | 139 | |
| 140 | 140 | |
| 141 | 141 | // if isset a value in the map calculate base64 encoded value |
| 142 | 142 | // otherwise skip |
| 143 | - if(!in_array($b, array_keys($this->map))){ |
|
| 143 | + if (!in_array($b, array_keys($this->map))) { |
|
| 144 | 144 | return $string; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // check if is null, in this case convert it to NULL string |
| 148 | - if(is_null($this->map[$b])){ |
|
| 148 | + if (is_null($this->map[$b])) { |
|
| 149 | 149 | $this->map[$b] = 'NULL'; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -157,19 +157,19 @@ discard block |
||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | // if there is no id copy it from dataRef |
| 160 | - $id = (!isset($node->attributes['id'])) ? ' id="'.$b.'" removeId="true"': ''; |
|
| 160 | + $id = (!isset($node->attributes['id'])) ? ' id="' . $b . '" removeId="true"' : ''; |
|
| 161 | 161 | |
| 162 | 162 | // introduce dataType for <ec>/<sc> tag handling |
| 163 | - $dataType = ($this->isAEcOrScTag($node)) ? ' dataType="'.$node->tagname.'"' : ''; |
|
| 163 | + $dataType = ($this->isAEcOrScTag($node)) ? ' dataType="' . $node->tagname . '"' : ''; |
|
| 164 | 164 | |
| 165 | 165 | // replacement |
| 166 | - $d = str_replace('/', $id.$dataType. ' equiv-text="base64:'.$base64EncodedValue.'"/', $a); |
|
| 167 | - $a = str_replace(['<','>','>', '<'], '', $a); |
|
| 168 | - $d = str_replace(['<','>','>', '<'], '', $d); |
|
| 166 | + $d = str_replace('/', $id . $dataType . ' equiv-text="base64:' . $base64EncodedValue . '"/', $a); |
|
| 167 | + $a = str_replace(['<', '>', '>', '<'], '', $a); |
|
| 168 | + $d = str_replace(['<', '>', '>', '<'], '', $d); |
|
| 169 | 169 | |
| 170 | 170 | // convert <ec>/<sc> into <ph> |
| 171 | - if($this->isAEcOrScTag($node)){ |
|
| 172 | - $d = 'ph'.substr($d, 2); |
|
| 171 | + if ($this->isAEcOrScTag($node)) { |
|
| 172 | + $d = 'ph' . substr($d, 2); |
|
| 173 | 173 | $d = trim($d); |
| 174 | 174 | } |
| 175 | 175 | |
@@ -191,7 +191,7 @@ discard block |
||
| 191 | 191 | $regex = ($toBeEscaped) ? '/<pc (.*?)>/iu' : '/<pc (.*?)>/iu'; |
| 192 | 192 | preg_match_all($regex, $string, $openingPcMatches); |
| 193 | 193 | |
| 194 | - return (isset($openingPcMatches[0]) and count($openingPcMatches[0])>0); |
|
| 194 | + return (isset($openingPcMatches[0]) and count($openingPcMatches[0]) > 0); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -202,27 +202,27 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | private function replaceSelfClosedPcTags($string, $toBeEscaped) |
| 204 | 204 | { |
| 205 | - if($toBeEscaped){ |
|
| 206 | - $string = str_replace(['<','>'],['<','>'],$string); |
|
| 205 | + if ($toBeEscaped) { |
|
| 206 | + $string = str_replace(['<', '>'], ['<', '>'], $string); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | $regex = '/<pc[^>]+?\/>/iu'; |
| 210 | 210 | preg_match_all($regex, $string, $selfClosedPcMatches); |
| 211 | 211 | |
| 212 | - foreach ($selfClosedPcMatches[0] as $match){ |
|
| 212 | + foreach ($selfClosedPcMatches[0] as $match) { |
|
| 213 | 213 | |
| 214 | 214 | $html = HtmlParser::parse($match); |
| 215 | 215 | $node = $html[0]; |
| 216 | 216 | $attributes = $node->attributes; |
| 217 | 217 | |
| 218 | - if(isset($attributes['dataRefStart']) and array_key_exists($node->attributes['dataRefStart'], $this->map)){ |
|
| 219 | - $replacement = '<ph id="'.$attributes['id'].'" dataType="pcSelf" originalData="'.base64_encode($match).'" dataRef="'.$attributes['dataRefStart'].'" equiv-text="base64:'.base64_encode($this->map[$node->attributes['dataRefStart']]).'"/>'; |
|
| 218 | + if (isset($attributes['dataRefStart']) and array_key_exists($node->attributes['dataRefStart'], $this->map)) { |
|
| 219 | + $replacement = '<ph id="' . $attributes['id'] . '" dataType="pcSelf" originalData="' . base64_encode($match) . '" dataRef="' . $attributes['dataRefStart'] . '" equiv-text="base64:' . base64_encode($this->map[$node->attributes['dataRefStart']]) . '"/>'; |
|
| 220 | 220 | $string = str_replace($match, $replacement, $string); |
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - if($toBeEscaped){ |
|
| 225 | - $string = str_replace(['<','>'],['<','>'],$string); |
|
| 224 | + if ($toBeEscaped) { |
|
| 225 | + $string = str_replace(['<', '>'], ['<', '>'], $string); |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | return $string; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | $dataRefEndMap = []; |
| 242 | 242 | |
| 243 | 243 | foreach ($html as $index => $node) { |
| 244 | - if ( $node->tagname === 'pc' ) { |
|
| 244 | + if ($node->tagname === 'pc') { |
|
| 245 | 245 | $this->extractDataRefMapRecursively($node, $dataRefEndMap); |
| 246 | 246 | } |
| 247 | 247 | } |
@@ -255,26 +255,26 @@ discard block |
||
| 255 | 255 | * @param object $node |
| 256 | 256 | * @param $dataRefEndMap |
| 257 | 257 | */ |
| 258 | - private function extractDataRefMapRecursively( $node, &$dataRefEndMap) |
|
| 258 | + private function extractDataRefMapRecursively($node, &$dataRefEndMap) |
|
| 259 | 259 | { |
| 260 | - if($this->nodeContainsNestedPcTags($node)) { |
|
| 261 | - foreach ( $node->inner_html as $nestedNode ) { |
|
| 260 | + if ($this->nodeContainsNestedPcTags($node)) { |
|
| 261 | + foreach ($node->inner_html as $nestedNode) { |
|
| 262 | 262 | $this->extractDataRefMapRecursively($nestedNode, $dataRefEndMap); |
| 263 | 263 | } |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | // EXCLUDE self closed <pc/> |
| 267 | - if($node->tagname === 'pc' and $node->self_closed === false){ |
|
| 268 | - if(isset($node->attributes['dataRefEnd'])){ |
|
| 267 | + if ($node->tagname === 'pc' and $node->self_closed === false) { |
|
| 268 | + if (isset($node->attributes['dataRefEnd'])) { |
|
| 269 | 269 | $dataRefEnd = $node->attributes['dataRefEnd']; |
| 270 | - } elseif(isset($node->attributes['dataRefStart'])) { |
|
| 270 | + } elseif (isset($node->attributes['dataRefStart'])) { |
|
| 271 | 271 | $dataRefEnd = $node->attributes['dataRefStart']; |
| 272 | 272 | } else { |
| 273 | 273 | $dataRefEnd = null; |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | $dataRefEndMap[] = [ |
| 277 | - 'id' => isset($node->attributes['id'] ) ? $node->attributes['id'] : null, |
|
| 277 | + 'id' => isset($node->attributes['id']) ? $node->attributes['id'] : null, |
|
| 278 | 278 | 'dataRefEnd' => $dataRefEnd, |
| 279 | 279 | ]; |
| 280 | 280 | } |
@@ -288,12 +288,12 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | private function recursiveCleanFromEquivText($node, $string) |
| 290 | 290 | { |
| 291 | - if($node->has_children){ |
|
| 292 | - foreach ($node->inner_html as $childNode){ |
|
| 291 | + if ($node->has_children) { |
|
| 292 | + foreach ($node->inner_html as $childNode) { |
|
| 293 | 293 | $string = $this->recursiveCleanFromEquivText($childNode, $string); |
| 294 | 294 | } |
| 295 | 295 | } else { |
| 296 | - if(isset($node->attributes['dataRef']) and array_key_exists($node->attributes['dataRef'], $this->map)){ |
|
| 296 | + if (isset($node->attributes['dataRef']) and array_key_exists($node->attributes['dataRef'], $this->map)) { |
|
| 297 | 297 | $cleaned = preg_replace('/ equiv-text="(.*?)"/', '', $node->node); |
| 298 | 298 | $string = str_replace($node->node, $cleaned, $string); |
| 299 | 299 | } |
@@ -315,29 +315,29 @@ discard block |
||
| 315 | 315 | $regex = ($toBeEscaped) ? '/<pc (.*?)>/iu' : '/<pc (.*?)>/iu'; |
| 316 | 316 | preg_match_all($regex, $string, $openingPcMatches); |
| 317 | 317 | |
| 318 | - foreach ($openingPcMatches[0] as $index => $match){ |
|
| 318 | + foreach ($openingPcMatches[0] as $index => $match) { |
|
| 319 | 319 | $attr = HtmlParser::getAttributes($openingPcMatches[1][$index]); |
| 320 | 320 | |
| 321 | 321 | // CASE 1 - Missing `dataRefStart` |
| 322 | - if( isset($attr['dataRefEnd']) and !isset($attr['dataRefStart']) ){ |
|
| 322 | + if (isset($attr['dataRefEnd']) and !isset($attr['dataRefStart'])) { |
|
| 323 | 323 | $attr['dataRefStart'] = $attr['dataRefEnd']; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | // CASE 2 - Missing `dataRefEnd` |
| 327 | - if( isset($attr['dataRefStart']) and !isset($attr['dataRefEnd']) ){ |
|
| 327 | + if (isset($attr['dataRefStart']) and !isset($attr['dataRefEnd'])) { |
|
| 328 | 328 | $attr['dataRefEnd'] = $attr['dataRefStart']; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - if(isset($attr['dataRefStart'])){ |
|
| 331 | + if (isset($attr['dataRefStart'])) { |
|
| 332 | 332 | $startOriginalData = $match; // opening <pc> |
| 333 | 333 | $startValue = $this->map[$attr['dataRefStart']] ? $this->map[$attr['dataRefStart']] : 'NULL'; //handling null values in original data map |
| 334 | 334 | $base64EncodedStartValue = base64_encode($startValue); |
| 335 | 335 | $base64StartOriginalData = base64_encode($startOriginalData); |
| 336 | 336 | |
| 337 | 337 | // conversion for opening <pc> tag |
| 338 | - $openingPcConverted = '<ph '. ((isset($attr['id'])) ? 'id="'.$attr['id'].'_1"' : '') .' dataType="pcStart" originalData="'.$base64StartOriginalData.'" dataRef="' |
|
| 339 | - .$attr['dataRefStart'].'" equiv-text="base64:' |
|
| 340 | - .$base64EncodedStartValue.'"/>'; |
|
| 338 | + $openingPcConverted = '<ph ' . ((isset($attr['id'])) ? 'id="' . $attr['id'] . '_1"' : '') . ' dataType="pcStart" originalData="' . $base64StartOriginalData . '" dataRef="' |
|
| 339 | + .$attr['dataRefStart'] . '" equiv-text="base64:' |
|
| 340 | + .$base64EncodedStartValue . '"/>'; |
|
| 341 | 341 | |
| 342 | 342 | $string = str_replace($startOriginalData, $openingPcConverted, $string); |
| 343 | 343 | } |
@@ -362,20 +362,20 @@ discard block |
||
| 362 | 362 | preg_match_all($regex, $string, $closingPcMatches, PREG_OFFSET_CAPTURE); |
| 363 | 363 | $delta = 0; |
| 364 | 364 | |
| 365 | - foreach ( $closingPcMatches[ 0 ] as $index => $match ) { |
|
| 365 | + foreach ($closingPcMatches[0] as $index => $match) { |
|
| 366 | 366 | $offset = $match[1]; |
| 367 | 367 | $length = strlen($match[0]); |
| 368 | 368 | $attr = $dataRefEndMap[$index]; |
| 369 | 369 | |
| 370 | - if(!empty($attr) and isset($attr['dataRefEnd'])){ |
|
| 370 | + if (!empty($attr) and isset($attr['dataRefEnd'])) { |
|
| 371 | 371 | $endOriginalData = $match[0]; // </pc> |
| 372 | 372 | $endValue = $this->map[$attr['dataRefEnd']] ? $this->map[$attr['dataRefEnd']] : 'NULL'; |
| 373 | 373 | $base64EncodedEndValue = base64_encode($endValue); |
| 374 | 374 | $base64EndOriginalData = base64_encode($endOriginalData); |
| 375 | 375 | |
| 376 | 376 | // conversion for closing <pc> tag |
| 377 | - $closingPcConverted = '<ph '. ((isset($attr['id'])) ? 'id="'.$attr['id'].'_2"': '') .' dataType="pcEnd" originalData="'.$base64EndOriginalData.'" dataRef="' |
|
| 378 | - .$attr['dataRefEnd'].'" equiv-text="base64:' .$base64EncodedEndValue.'"/>'; |
|
| 377 | + $closingPcConverted = '<ph ' . ((isset($attr['id'])) ? 'id="' . $attr['id'] . '_2"' : '') . ' dataType="pcEnd" originalData="' . $base64EndOriginalData . '" dataRef="' |
|
| 378 | + .$attr['dataRefEnd'] . '" equiv-text="base64:' . $base64EncodedEndValue . '"/>'; |
|
| 379 | 379 | |
| 380 | 380 | $realOffset = ($delta === 0) ? $offset : ($offset + $delta); |
| 381 | 381 | |
@@ -394,12 +394,12 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | private function nodeContainsNestedPcTags($node) |
| 396 | 396 | { |
| 397 | - if(!$node->has_children){ |
|
| 397 | + if (!$node->has_children) { |
|
| 398 | 398 | return false; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | 401 | foreach ($node->inner_html as $nestedNode) { |
| 402 | - if($nestedNode->tagname === 'pc' and (isset($node->attributes['dataRefEnd']) or isset($node->attributes['dataRefStart']))){ |
|
| 402 | + if ($nestedNode->tagname === 'pc' and (isset($node->attributes['dataRefEnd']) or isset($node->attributes['dataRefStart']))) { |
|
| 403 | 403 | return true; |
| 404 | 404 | } |
| 405 | 405 | } |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | $string = str_replace(' equiv-text=""', '', $string); |
| 424 | 424 | $html = HtmlParser::parse($string); |
| 425 | 425 | |
| 426 | - foreach ($html as $node){ |
|
| 426 | + foreach ($html as $node) { |
|
| 427 | 427 | $string = $this->recursiveRemoveOriginalData($node, $string); |
| 428 | 428 | } |
| 429 | 429 | |
@@ -438,43 +438,43 @@ discard block |
||
| 438 | 438 | */ |
| 439 | 439 | private function recursiveRemoveOriginalData($node, $string) |
| 440 | 440 | { |
| 441 | - if($node->has_children){ |
|
| 442 | - foreach ($node->inner_html as $childNode){ |
|
| 441 | + if ($node->has_children) { |
|
| 442 | + foreach ($node->inner_html as $childNode) { |
|
| 443 | 443 | $string = $this->recursiveRemoveOriginalData($childNode, $string); |
| 444 | 444 | } |
| 445 | 445 | } else { |
| 446 | 446 | |
| 447 | - if(!isset($node->attributes['dataRef'])){ |
|
| 447 | + if (!isset($node->attributes['dataRef'])) { |
|
| 448 | 448 | return $string; |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - $a = $node->node; // complete match. Eg: <ph id="source1" dataRef="source1"/> |
|
| 451 | + $a = $node->node; // complete match. Eg: <ph id="source1" dataRef="source1"/> |
|
| 452 | 452 | $b = $node->attributes['dataRef']; // map identifier. Eg: source1 |
| 453 | - $c = $node->terminator; // terminator: Eg: > |
|
| 453 | + $c = $node->terminator; // terminator: Eg: > |
|
| 454 | 454 | |
| 455 | 455 | // if isset a value in the map calculate base64 encoded value |
| 456 | 456 | // or it is an empty string |
| 457 | 457 | // otherwise skip |
| 458 | - if(!in_array($b, array_keys($this->map)) ){ |
|
| 458 | + if (!in_array($b, array_keys($this->map))) { |
|
| 459 | 459 | return $string; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | // check if is null, in this case convert it to NULL string |
| 463 | - if(is_null($this->map[$b])){ |
|
| 463 | + if (is_null($this->map[$b])) { |
|
| 464 | 464 | $this->map[$b] = 'NULL'; |
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | // remove id? |
| 468 | - $removeId = (isset($node->attributes['removeId']) and $node->attributes['removeId'] === "true") ? ' id="'.$b.'" removeId="true"' : ''; |
|
| 468 | + $removeId = (isset($node->attributes['removeId']) and $node->attributes['removeId'] === "true") ? ' id="' . $b . '" removeId="true"' : ''; |
|
| 469 | 469 | |
| 470 | 470 | // grab dataType attribute for <ec>/<sc> tag handling |
| 471 | - $dataType = ($this->wasAEcOrScTag($node)) ? ' dataType="'.$node->attributes['dataType'].'"' : ''; |
|
| 471 | + $dataType = ($this->wasAEcOrScTag($node)) ? ' dataType="' . $node->attributes['dataType'] . '"' : ''; |
|
| 472 | 472 | |
| 473 | - $d = str_replace($removeId.$dataType.' equiv-text="base64:'.base64_encode($this->map[$b]).'"/'.$c, '/'.$c, $a); |
|
| 473 | + $d = str_replace($removeId . $dataType . ' equiv-text="base64:' . base64_encode($this->map[$b]) . '"/' . $c, '/' . $c, $a); |
|
| 474 | 474 | |
| 475 | 475 | // replace original <ec>/<sc> tag |
| 476 | - if($this->wasAEcOrScTag($node)){ |
|
| 477 | - $d = $node->attributes['dataType'].substr($d, 3); |
|
| 476 | + if ($this->wasAEcOrScTag($node)) { |
|
| 477 | + $d = $node->attributes['dataType'] . substr($d, 3); |
|
| 478 | 478 | $d = trim($d); |
| 479 | 479 | } |
| 480 | 480 | |
@@ -487,7 +487,7 @@ discard block |
||
| 487 | 487 | $string = str_replace($a, $d, $string); |
| 488 | 488 | |
| 489 | 489 | // restoring <pc/> self-closed here |
| 490 | - if(Strings::contains('dataType="pcSelf"', $d)){ |
|
| 490 | + if (Strings::contains('dataType="pcSelf"', $d)) { |
|
| 491 | 491 | preg_match('/\s?originalData="(.*?)"\s?/', $d, $originalDataMatches); |
| 492 | 492 | |
| 493 | 493 | if (isset($originalDataMatches[1])) { |
@@ -546,6 +546,6 @@ discard block |
||
| 546 | 546 | */ |
| 547 | 547 | private function wasAEcOrScTag($node) |
| 548 | 548 | { |
| 549 | - return (isset($node->attributes['dataType']) and ( $node->attributes['dataType'] === 'ec' or $node->attributes['dataType'] === 'sc')); |
|
| 549 | + return (isset($node->attributes['dataType']) and ($node->attributes['dataType'] === 'ec' or $node->attributes['dataType'] === 'sc')); |
|
| 550 | 550 | } |
| 551 | 551 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | { |
| 14 | 14 | $fileType = []; |
| 15 | 15 | |
| 16 | - if (isset($tmp[ 0 ])) { |
|
| 16 | + if (isset($tmp[0])) { |
|
| 17 | 17 | preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($tmp[0], 0, 1000), $versionMatches); |
| 18 | 18 | preg_match('|<xliff.*?\sxmlns\s?=\s?["\']urn:oasis:names:tc:xliff:document:(.*?)["\']|si', substr($tmp[0], 0, 1000), $xmlnsMatches); |
| 19 | 19 | |
@@ -22,10 +22,10 @@ discard block |
||
| 22 | 22 | $xmlns = $xmlnsMatches[1]; |
| 23 | 23 | |
| 24 | 24 | if ($version === $xmlns and $version >= 2) { |
| 25 | - $fileType[ 'proprietary' ] = false; |
|
| 26 | - $fileType[ 'proprietary_name' ] = 'Xliff v'.$version.' File'; |
|
| 27 | - $fileType[ 'proprietary_short_name' ] = 'xliff_v2'; |
|
| 28 | - $fileType[ 'converter_version' ] = '2.0'; |
|
| 25 | + $fileType['proprietary'] = false; |
|
| 26 | + $fileType['proprietary_name'] = 'Xliff v' . $version . ' File'; |
|
| 27 | + $fileType['proprietary_short_name'] = 'xliff_v2'; |
|
| 28 | + $fileType['converter_version'] = '2.0'; |
|
| 29 | 29 | |
| 30 | 30 | return $fileType; |
| 31 | 31 | } |