public function testInstantArticle()
 {
     $article = InstantArticle::create()->withCanonicalUrl('')->withHeader(Header::create())->addChild(Paragraph::create()->appendText('Some text to be within a paragraph for testing.'))->addChild(Paragraph::create())->addChild(Paragraph::create()->appendText(" \n \t "))->addChild(Image::create())->addChild(Image::create()->withURL(''))->addChild(SlideShow::create()->addImage(Image::create()->withURL('https://jpeg.org/images/jpegls-home.jpg'))->addImage(Image::create()))->addChild(Ad::create()->withSource('http://foo.com'))->addChild(Paragraph::create()->appendText('Other text to be within a second paragraph for testing.'))->addChild(Analytics::create())->withFooter(Footer::create());
     $expected = '<!doctype html>' . '<html>' . '<head>' . '<link rel="canonical" href=""/>' . '<meta charset="utf-8"/>' . '<meta property="op:generator" content="facebook-instant-articles-sdk-php"/>' . '<meta property="op:generator:version" content="' . InstantArticle::CURRENT_VERSION . '"/>' . '<meta property="op:markup_version" content="v1.0"/>' . '</head>' . '<body>' . '<article>' . '<p>Some text to be within a paragraph for testing.</p>' . '<figure class="op-slideshow">' . '<figure>' . '<img src="https://jpeg.org/images/jpegls-home.jpg"/>' . '</figure>' . '</figure>' . '<figure class="op-ad">' . '<iframe src="http://foo.com"></iframe>' . '</figure>' . '<p>Other text to be within a second paragraph for testing.</p>' . '</article>' . '</body>' . '</html>';
     $result = $article->render();
     $this->assertEquals($expected, $result);
     $warnings = InstantArticleValidator::check($article);
     $this->assertEquals(9, count($warnings));
 }
function wpcom_fbia_add_stats_pixel($ia_post)
{
    // Get the IA article.
    $instant_article = $ia_post->instant_article;
    // Create the wpcom stats code.
    $hostname = isset($_SERVER['HTTP_HOST']) ? sanitize_text_field(wp_unslash($_SERVER['HTTP_HOST'])) : '';
    // input var okay
    $url = 'https://pixel.wp.com/b.gif?host=' . $hostname . '&blog=' . $current_blog->blog_id . '&post=' . $post->ID . '&subd=' . str_replace('.wordpress.com', '', $current_blog->domain) . '&ref=&feed=1';
    $pixel_html = '<script>
		var x = new Image(); x.src = "' . esc_js($url) . '&rand=" +Math.random();
	</script>';
    // Create our FBIA markup
    $fbia_markup = Analytics::create();
    $fbia_markup->withHTML($pixel_html);
    // Add the FBIA-compatible stats markup to the IA content
    $instant_article->addChild($fbia_markup);
}
 public function apply($transformer, $instant_article, $node)
 {
     $analytics = Analytics::create();
     // Builds the analytics
     $url = $this->getProperty(self::PROPERTY_TRACKER_URL, $node);
     if ($url) {
         $analytics->withSource($url);
     }
     $embed_code = $this->getProperty(self::PROPERTY_TRACKER_EMBED_URL, $node);
     if ($embed_code) {
         $analytics->withHTML($embed_code);
     }
     if ($url || $embed_code) {
         $instant_article->addChild($analytics);
     } else {
         $transformer->addWarning(new InvalidSelector('embed code or url', $instant_article, $node, $this));
     }
     return $instant_article;
 }
 /**
  * Add all analytic tracking code(s) an InstantArticle.
  *
  * @since 0.3
  */
 public function add_analytics_from_settings()
 {
     $settings_analytics = Instant_Articles_Option_Analytics::get_option_decoded();
     if (isset($settings_analytics['embed_code_enabled']) && !empty($settings_analytics['embed_code'])) {
         $document = new DOMDocument();
         $fragment = $document->createDocumentFragment();
         $valid_html = @$fragment->appendXML($settings_analytics['embed_code']);
         if ($valid_html) {
             $this->instant_article->addChild(Analytics::create()->withHTML($fragment));
         }
     }
     if (!empty($settings_analytics['integrations'])) {
         $settings_analytics_compats = $settings_analytics['integrations'];
         $registered_compat_analytics = Instant_Articles_Option::get_registered_compat('instant_articles_compat_registry_analytics');
         foreach ($registered_compat_analytics as $compat_id => $compat_info) {
             if (in_array($compat_id, $settings_analytics_compats, true)) {
                 $document = new DOMDocument();
                 $fragment = $document->createDocumentFragment();
                 $valid_html = @$fragment->appendXML($compat_info['payload']);
                 if ($valid_html) {
                     $this->instant_article->addChild(Analytics::create()->withHTML($fragment));
                 }
             }
         }
     }
 }
 /**
  * Adds new child elements to the front of this InstantArticle
  *
  * @param Element to be added to this Article.
  *
  * @return $this
  */
 public function unshiftChild($child)
 {
     Type::enforce($child, [Ad::getClassName(), Analytics::getClassName(), AnimatedGIF::getClassName(), Audio::getClassName(), Blockquote::getClassName(), Image::getClassName(), H1::getClassName(), H2::getClassName(), Interactive::getClassName(), ListElement::getClassName(), Map::getClassName(), Paragraph::getClassName(), Pullquote::getClassName(), RelatedArticles::getClassName(), Slideshow::getClassName(), SocialEmbed::getClassName(), Video::getClassName()]);
     array_unshift($this->children, $child);
     return $this;
 }