Example #1
0
 public function transform()
 {
     $content = $this->original_content;
     $content = apply_filters('the_content', $content);
     // We run kses before AMP conversion due to a kses bug which doesn't allow hyphens (#34105-core).
     // Our custom kses handler strips out all not-allowed stuff and leaves in stuff that will be converted (like iframe, img, audio, video).
     // Technically, conversion should catch the tags so we shouldn't need to run it after anyway.
     $content = AMP_KSES::strip($content);
     // Convert HTML to AMP
     // see https://github.com/ampproject/amphtml/blob/master/spec/amp-html-format.md#html-tags)
     $img_converter = new AMP_Img_Converter();
     $content = $img_converter->convert($content, array('layout' => 'responsive'));
     return $content;
 }
    function test_multiple_different_images()
    {
        $content = '
<img src="http://placehold.it/350x150" />
<img src="http://placehold.it/360x160" />
<img src="http://placehold.it/370x170" />
<img src="http://placehold.it/380x180" />
			';
        $expected = '
<amp-img src="http://placehold.it/350x150"></amp-img>
<amp-img src="http://placehold.it/360x160"></amp-img>
<amp-img src="http://placehold.it/370x170"></amp-img>
<amp-img src="http://placehold.it/380x180"></amp-img>
			';
        $converter = new AMP_Img_Converter($content);
        $converted = $converter->convert();
        $this->assertEquals($expected, $converted);
    }
Example #3
0
 function get_author_avatar($size = 24)
 {
     $avatar_html = get_avatar($this->author->user_email, 24);
     $converter = new AMP_Img_Converter();
     return $converter->convert($avatar_html);
 }