From 5724b49a972aeadfc31a9394142cc330512c94c0 Mon Sep 17 00:00:00 2001
From: Jeff Ong This is a test text with HTML.get_attribute( 'style' ) . '" )?>" src="' . CBT_Theme_Media::make_relative_media_url( $p->get_attribute( 'src' ) ) . '" alt="get_attribute( 'alt' ) . '" );?>">';
+ break;
+ default:
+ $text .= '<' . strtolower( $p->get_token_name() ) . '>';
+ break;
+ }
+ }
+ break;
+ case '#text':
+ $text .= 'get_modifiable_text() . '", wp_get_theme()->get( \'TextDomain\' ) ); ?>';
+ break;
+ }
+ }
+
+ return $text;
}
/**
From 723a88feebe69a7820e1abb97c7259e0fd6855cd Mon Sep 17 00:00:00 2001
From: Jeff Ong
get_attribute( 'style' ) . '" )?>" src="' . CBT_Theme_Media::make_relative_media_url( $p->get_attribute( 'src' ) ) . '" alt="get_attribute( 'alt' ) . '" );?>">';
break;
default:
From a9ca35aa88728d5b1ca40dd7d5725d7c2d10840c Mon Sep 17 00:00:00 2001
From: Jeff Ong
get_attribute( 'style' ) . '" )?>" src="' . CBT_Theme_Media::make_relative_media_url( $p->get_attribute( 'src' ) ) . '" alt="get_attribute( 'alt' ) . '" );?>">';
- break;
- default:
- $text .= '<' . strtolower( $p->get_token_name() ) . '>';
- break;
- }
+ $token_type = $p->get_token_type();
+ $token_name = strtolower( $p->get_token_name() );
+ $is_tag_closer = $p->is_tag_closer();
+
+ if ( '#tag' === $token_type ) {
+ // Add a placeholder for the token.
+ $text .= '%s';
+ if ( $is_tag_closer ) {
+ $tokens[] = "{$token_name}>";
+ } else {
+ // Depending on the HTML tag, we may need to process attributes so they are correctly added to the placeholder.
+ switch ( $token_name ) {
+ // Handle links.
+ case 'a':
+ $href = esc_url( $p->get_attribute( 'href' ) );
+ $target = empty( esc_attr( $p->get_attribute( 'target' ) ) ) ? '' : ' target="_blank"';
+ $rel = empty( esc_attr( $p->get_attribute( 'rel' ) ) ) ? '' : ' rel="nofollow noopener noreferrer"';
+ $tokens[] = "";
+ break;
+ // Handle inline images.
+ case 'img':
+ $src = esc_url( $p->get_attribute( 'src' ) );
+ $style = esc_attr( $p->get_attribute( 'style' ) );
+ $alt = esc_attr( $p->get_attribute( 'alt' ) );
+
+ CBT_Theme_Media::add_media_to_local( array( $src ) );
+ $relative_src = CBT_Theme_Media::get_media_folder_path_from_url( $src ) . basename( $src );
+ $tokens[] = "
";
+ break;
+ // Handle highlights.
+ case 'mark':
+ $style = esc_attr( $p->get_attribute( 'style' ) );
+ $class = esc_attr( $p->get_attribute( 'class' ) );
+ $tokens[] = "";
+ break;
+ // Otherwise, just add the tag opener.
+ default:
+ $tokens[] = "<{$token_name}>";
+ break;
}
- break;
- case '#text':
- $text .= 'get_modifiable_text() . '", wp_get_theme()->get( \'TextDomain\' ) ); ?>';
- break;
+ }
+ } else {
+ // If it's not a tag, just add the text content.
+ $text .= esc_html( $p->get_modifiable_text() );
}
}
- return $text;
+ // Format the string, replacing the placeholders with the formatted tokens.
+ $mystring = "get( 'TextDomain' ) . "' ), " . implode(
+ ', ',
+ array_map(
+ function( $token ) {
+ return "'$token'";
+ },
+ $tokens
+ )
+ ) . '); ?>';
+
+ return $mystring;
}
/**
From 0460dc52fa709a1f263a9f535beb24fc2dfadf57 Mon Sep 17 00:00:00 2001
From: Jeff Ong
This is a test text with HTML.
'; + $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); + $expected_output = "', '' ); ?>"; + $this->assertEquals( $expected_output, $escaped_string ); } public function test_escape_text_content_with_already_escaped_string() { diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 2fee4adf..34d705c6 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -108,7 +108,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -El polvo elemental que nos ignora+
y que fue el rojo Adán y que es ahora
todos los hombres, y que no veremos.\', \'test-locale-theme\');?>
\', \'', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index e2842800..f3aec6e6 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -159,12 +159,12 @@ public function test_properly_encode_lessthan_and_greaterthan() { public function test_properly_encode_html_markup() { $template = new stdClass(); - $template->content = ' -
\', \'
\' ); ?>
Bold text has feelings <> TOO
- '; + $template->content = 'Bold text has feelings <> TOO
'; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "Bold text has feelings <> TOO', '');?>", $escaped_template->content ); + $expected_output = '\', \'\' ); ?>
'; + + $this->assertStringContainsString( $expected_output, $escaped_template->content ); } public function test_empty_alt_text_is_not_localized() { @@ -262,7 +262,12 @@ public function test_localize_verse() {Here is some verse to localize'; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( "verse to localize', '');?>", $new_template->content ); + + $expected_output = ' +
\', \'\' ); ?>+ '; + + $this->assertStringContainsString( $expected_output, $new_template->content ); } public function test_localize_table() { From 45c312c5cb42d0fc694d845e4a874e8a920d317d Mon Sep 17 00:00:00 2001 From: Jeff Ong
This is a test text with HTML.
'; $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); - $expected_output = "', '' ); ?>"; + $expected_output = '\', \'\' ); ?>'; $this->assertEquals( $expected_output, $escaped_string ); } diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 34d705c6..fe897867 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -108,7 +108,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -\', \'+
\', \'
\' ); ?>
\', \'', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index f3aec6e6..7007f39e 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -162,7 +162,7 @@ public function test_properly_encode_html_markup() { $template->content = '
\', \'
\' ); ?>
Bold text has feelings <> TOO
'; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $expected_output = '\', \'\' ); ?>
'; + $expected_output = '\', \'\' ); ?>
'; $this->assertStringContainsString( $expected_output, $escaped_template->content ); } @@ -264,7 +264,7 @@ public function test_localize_verse() { $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); $expected_output = ' -\', \'\' ); ?>+
\', \'\' ); ?>'; $this->assertStringContainsString( $expected_output, $new_template->content ); From 3f0adfac69e3a240e58257b1bbe40d1db8bef9a4 Mon Sep 17 00:00:00 2001 From: Jeff Ong
Bold text has feelings <> TOO
'; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $expected_output = '\', \'\' ); ?>
'; + $expected_output = 'TOO\', \'\' ), \'\', \'\' ); ?>
'; $this->assertStringContainsString( $expected_output, $escaped_template->content ); } @@ -270,6 +270,15 @@ public function test_localize_verse() { $this->assertStringContainsString( $expected_output, $new_template->content ); } + public function test_localize_text_with_placeholders() { + $template = new stdClass(); + $template->content = ' +This is bold text with a %s placeholder
+ '; + $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); + $this->assertStringContainsString( '\', \'\' ); ?>', $new_template->content ); + } + public function test_localize_table() { $template = new stdClass(); $template->content = ' From 7a75758984c2238c464afcd9bec7942f7b6ce66c Mon Sep 17 00:00:00 2001 From: Sarah NorrisThis is a test text with HTML.
'; $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); - $expected_output = '\', \'\' ); ?>'; + $expected_output = '\', \'\' ); ?>'; $this->assertEquals( $expected_output, $escaped_string ); } From bf603a97213fea85c913144a41a160db916c9927 Mon Sep 17 00:00:00 2001 From: Sarah Norris\', \'+
\', \'
\' ); ?>
\', \'', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index ced18c7b..7beb9a1c 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -162,7 +162,7 @@ public function test_properly_encode_html_markup() { $template->content = '
\', \'
\' ); ?>
Bold text has feelings <> TOO
'; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $expected_output = 'TOO\', \'\' ), \'\', \'\' ); ?>
'; + $expected_output = 'TOO\', \'\' ), \'\', \'\' ); ?>
'; $this->assertStringContainsString( $expected_output, $escaped_template->content ); } @@ -264,7 +264,7 @@ public function test_localize_verse() { $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); $expected_output = ' -\', \'\' ); ?>+
\', \'\' ); ?>'; $this->assertStringContainsString( $expected_output, $new_template->content ); @@ -276,7 +276,7 @@ public function test_localize_text_with_placeholders() {
This is bold text with a %s placeholder
'; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( '\', \'\' ); ?>', $new_template->content ); + $this->assertStringContainsString( '\', \'\' ); ?>', $new_template->content ); } public function test_localize_table() { From e3497d3dab581f40f9b02c0bb73fa49c62cd7bd8 Mon Sep 17 00:00:00 2001 From: Sarah NorrisThis is a test text with HTML.
'; $escaped_string = $this->call_private_method( 'escape_text_content', array( $string ) ); - $expected_output = '\', \'\' ); ?>'; + $expected_output = '\', \'\' ); ?>'; $this->assertEquals( $expected_output, $escaped_string ); } diff --git a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php index 07f4097c..50e85891 100644 --- a/tests/CbtThemeLocale/escapeTextContentOfBlocks.php +++ b/tests/CbtThemeLocale/escapeTextContentOfBlocks.php @@ -108,8 +108,7 @@ public function data_test_escape_text_content_of_blocks() { ', 'expected_markup' => ' -\', \'+
\', \'
\' ); ?>
\', \'', ), diff --git a/tests/test-theme-templates.php b/tests/test-theme-templates.php index 7beb9a1c..15bdc8f0 100644 --- a/tests/test-theme-templates.php +++ b/tests/test-theme-templates.php @@ -162,7 +162,7 @@ public function test_properly_encode_html_markup() { $template->content = '
\', \'
\' ); ?>
Bold text has feelings <> TOO
'; $escaped_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $expected_output = 'TOO\', \'\' ), \'\', \'\' ); ?>
'; + $expected_output = 'TOO\', \'\' ), \'\', \'\' ); ?>
'; $this->assertStringContainsString( $expected_output, $escaped_template->content ); } @@ -264,7 +264,7 @@ public function test_localize_verse() { $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); $expected_output = ' -\', \'\' ); ?>+
\', \'\' ); ?>'; $this->assertStringContainsString( $expected_output, $new_template->content ); @@ -276,7 +276,7 @@ public function test_localize_text_with_placeholders() {
This is bold text with a %s placeholder
'; $new_template = CBT_Theme_Templates::escape_text_in_template( $template ); - $this->assertStringContainsString( '\', \'\' ); ?>', $new_template->content ); + $this->assertStringContainsString( '\', \'\' ); ?>', $new_template->content ); } public function test_localize_table() {