@@ -344,7 +344,7 @@ protected function _applySpecialTagsFormat($tagHtml, $tagName, $trArr)
344
344
{
345
345
$ specialTags = $ tagHtml . '<span class="translate-inline- ' . $ tagName . '" ' . $ this ->_getHtmlAttribute (
346
346
self ::DATA_TRANSLATE ,
347
- '[ ' . join (', ' , $ trArr ) . '] '
347
+ '[ ' . htmlspecialchars ( join (', ' , $ trArr) ) . '] '
348
348
);
349
349
$ additionalAttr = $ this ->_getAdditionalHtmlAttribute ($ tagName );
350
350
if ($ additionalAttr !== null ) {
@@ -527,10 +527,12 @@ private function _specialTags()
527
527
private function _translateTags (&$ content , $ tagsList , $ formatCallback )
528
528
{
529
529
$ nextTag = 0 ;
530
+ $ tagRegExpBody = '#<(body)(/?>| \s*[^>]*+/?>)#iSU ' ;
530
531
531
532
$ tags = implode ('| ' , array_keys ($ tagsList ));
532
533
$ tagRegExp = '#<( ' . $ tags . ')(/?>| \s*[^>]*+/?>)#iSU ' ;
533
534
$ tagMatch = [];
535
+ $ headTranslateTags = '' ;
534
536
while (preg_match ($ tagRegExp , $ content , $ tagMatch , PREG_OFFSET_CAPTURE , $ nextTag )) {
535
537
$ tagName = strtolower ($ tagMatch [1 ][0 ]);
536
538
if (substr ($ tagMatch [0 ][0 ], -2 ) == '/> ' ) {
@@ -564,12 +566,36 @@ private function _translateTags(&$content, $tagsList, $formatCallback)
564
566
565
567
if (!empty ($ trArr )) {
566
568
$ trArr = array_unique ($ trArr );
567
- $ tagHtml = call_user_func ([$ this , $ formatCallback ], $ tagHtml , $ tagName , $ trArr );
569
+
570
+ $ tagBodyMatch = [];
571
+ preg_match ($ tagRegExpBody , $ content , $ tagBodyMatch , PREG_OFFSET_CAPTURE );
572
+ if (!empty ($ tagBodyMatch )) {
573
+ $ tagBodyOpenStartPosition = $ tagBodyMatch [0 ][1 ];
574
+
575
+ if (array_key_exists ($ tagName , $ this ->_allowedTagsGlobal )
576
+ && $ tagBodyOpenStartPosition > $ tagMatch [0 ][1 ]
577
+ ) {
578
+ $ tagHtmlHead = call_user_func ([$ this , $ formatCallback ], $ tagHtml , $ tagName , $ trArr );
579
+ $ headTranslateTags .= substr ($ tagHtmlHead , strlen ($ tagHtml ));
580
+ } else {
581
+ $ tagHtml = call_user_func ([$ this , $ formatCallback ], $ tagHtml , $ tagName , $ trArr );
582
+ }
583
+ }
584
+
568
585
$ tagClosurePos = $ tagMatch [0 ][1 ] + strlen ($ tagHtml );
569
586
$ content = substr_replace ($ content , $ tagHtml , $ tagMatch [0 ][1 ], $ tagLength );
570
587
}
571
588
$ nextTag = $ tagClosurePos ;
572
589
}
590
+ if ($ headTranslateTags ) {
591
+ $ tagBodyMatch = [];
592
+ preg_match ($ tagRegExpBody , $ content , $ tagBodyMatch , PREG_OFFSET_CAPTURE );
593
+ $ tagBodyOpenStartPosition = $ tagBodyMatch [0 ][1 ];
594
+ $ openTagBodyEndPosition = $ tagBodyOpenStartPosition + strlen ($ tagBodyMatch [0 ][0 ]);
595
+ $ content = substr ($ content , 0 , $ openTagBodyEndPosition )
596
+ . $ headTranslateTags
597
+ . substr ($ content , $ openTagBodyEndPosition );
598
+ }
573
599
}
574
600
575
601
/**
0 commit comments