Exemplo n.º 1
0
 private function sanitize($content)
 {
     list($sanitized_content, $scripts, $styles) = AMP_Content_Sanitizer::sanitize($content, $this->sanitizer_classes, $this->args);
     $this->add_scripts($scripts);
     $this->add_styles($styles);
     return $sanitized_content;
 }
 public function test__sanitize__append_with_scripts_and_styles()
 {
     $source_html = '<b>Hello</b>';
     $expected_return = array('<b>Hello</b><em>World</em>', array('scripts'), array('styles'));
     $actual_return = AMP_Content_Sanitizer::sanitize($source_html, array('AMP_Test_World_Sanitizer' => array()));
     $this->assertEquals($expected_return, $actual_return);
 }
Exemplo n.º 3
0
 private function build_post_featured_image()
 {
     $post_id = $this->ID;
     $featured_html = get_the_post_thumbnail($post_id, 'large');
     // Skip featured image if no featured image is available.
     if (!$featured_html) {
         return;
     }
     $featured_id = get_post_thumbnail_id($post_id);
     // If an image with the same ID as the featured image exists in the content, skip the featured image markup.
     // Prevents duplicate images, which is especially problematic for photo blogs.
     // A bit crude but it's fast and should cover most cases.
     $post_content = $this->post->post_content;
     if (false !== strpos($post_content, 'wp-image-' . $featured_id) || false !== strpos($post_content, 'attachment_' . $featured_id)) {
         return;
     }
     $featured_image = get_post($featured_id);
     list($sanitized_html, $featured_scripts, $featured_styles) = AMP_Content_Sanitizer::sanitize($featured_html, array('AMP_Img_Sanitizer' => array()), array('content_max_width' => $this->get('content_max_width')));
     $this->add_data_by_key('featured_image', array('amp_html' => $sanitized_html, 'caption' => $featured_image->post_excerpt));
     if ($featured_scripts) {
         $this->merge_data_for_key('amp_component_scripts', $featured_scripts);
     }
     if ($featured_styles) {
         $this->add_data_by_key('post_amp_styles', $featured_styles);
     }
 }