public function apply($transformer, $instant_article, $node)
 {
     $image = Image::create();
     // Builds the image
     $url = $this->getProperty(self::PROPERTY_IMAGE_URL, $node);
     if ($url) {
         $image->withURL($url);
         $instant_article->addChild($image);
     } else {
         $transformer->addWarning(new InvalidSelector(self::PROPERTY_IMAGE_URL, $instant_article, $node, $this));
     }
     if ($this->getProperty(Image::ASPECT_FIT, $node)) {
         $image->withPresentation(Image::ASPECT_FIT);
     } elseif ($this->getProperty(Image::ASPECT_FIT_ONLY, $node)) {
         $image->withPresentation(Image::ASPECT_FIT_ONLY);
     } elseif ($this->getProperty(Image::FULLSCREEN, $node)) {
         $image->withPresentation(Image::FULLSCREEN);
     } elseif ($this->getProperty(Image::NON_INTERACTIVE, $node)) {
         $image->withPresentation(Image::NON_INTERACTIVE);
     }
     if ($this->getProperty(self::PROPERTY_LIKE, $node)) {
         $image->enableLike();
     }
     if ($this->getProperty(self::PROPERTY_COMMENTS, $node)) {
         $image->enableComments();
     }
     $suppress_warnings = $transformer->suppress_warnings;
     $transformer->suppress_warnings = true;
     $transformer->transform($image, $node);
     $transformer->suppress_warnings = $suppress_warnings;
     return $instant_article;
 }
 public function apply($transformer, $context, $node)
 {
     $image = Image::create();
     // Builds the image
     $url = $this->getProperty(self::PROPERTY_IMAGE_URL, $node);
     if ($url) {
         $image->withURL($url);
         $instant_article = $transformer->getInstantArticle();
         if ($instant_article) {
             $instant_article->addChild($image);
             $context->disableEmptyValidation();
             $context = Paragraph::create();
             $context->disableEmptyValidation();
             $instant_article->addChild($context);
         } else {
             $transformer->addWarning(new NoRootInstantArticleFoundWarning(null, $node));
         }
     } else {
         $transformer->addWarning(new InvalidSelector(self::PROPERTY_IMAGE_URL, $instant_article, $node, $this));
     }
     if ($this->getProperty(self::PROPERTY_LIKE, $node)) {
         $image->enableLike();
     }
     if ($this->getProperty(self::PROPERTY_COMMENTS, $node)) {
         $image->enableComments();
     }
     $suppress_warnings = $transformer->suppress_warnings;
     $transformer->suppress_warnings = true;
     $transformer->transform($image, $node);
     $transformer->suppress_warnings = $suppress_warnings;
     return $context;
 }
 public function apply($transformer, $instant_article, $node)
 {
     // Builds the slideshow
     $slideshow = Slideshow::create();
     $instant_article->addChild($slideshow);
     $gallery = $this->getProperty(self::PROPERTY_JETPACK_DATA_GALLERY, $node);
     if ($gallery && isset($gallery)) {
         foreach ($gallery as $gallery_image) {
             // Constructs Image if it contains URL
             if (!Type::isTextEmpty($gallery_image['src'])) {
                 $image = Image::create();
                 $image->withURL($gallery_image['src']);
                 // Constructs Caption element when present in the JSON
                 if (!Type::isTextEmpty($gallery_image['caption'])) {
                     $caption = Caption::create();
                     $caption->appendText($gallery_image['caption']);
                     $image->withCaption($caption);
                 }
                 $slideshow->addImage($image);
             }
         }
     }
     $transformer->transform($slideshow, $node);
     return $instant_article;
 }
 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));
 }
 public function apply($transformer, $header, $node)
 {
     $image = Image::create();
     // Builds the image
     $url = $this->getProperty(self::PROPERTY_IMAGE_URL, $node);
     if ($url) {
         $image->withURL($url);
         $header->withCover($image);
     } else {
         $transformer->addWarning(new InvalidSelector(self::PROPERTY_IMAGE_URL, $header, $node, $this));
     }
     $suppress_warnings = $transformer->suppress_warnings;
     $transformer->suppress_warnings = true;
     $transformer->transform($image, $node);
     $transformer->suppress_warnings = $suppress_warnings;
     return $header;
 }
 public function apply($transformer, $context, $node)
 {
     $image = Image::create();
     if (Type::is($context, InstantArticle::getClassName())) {
         $instant_article = $context;
     } elseif ($transformer->getInstantArticle()) {
         $instant_article = $transformer->getInstantArticle();
         $context->disableEmptyValidation();
         $context = Paragraph::create();
         $context->disableEmptyValidation();
     } else {
         $transformer->addWarning(new NoRootInstantArticleFoundWarning(null, $node));
         return $context;
     }
     // Builds the image
     $url = $this->getProperty(self::PROPERTY_IMAGE_URL, $node);
     if ($url) {
         $image->withURL($url);
         $instant_article->addChild($image);
         if ($instant_article !== $context) {
             $instant_article->addChild($context);
         }
     } else {
         $transformer->addWarning(new InvalidSelector(self::PROPERTY_IMAGE_URL, $instant_article, $node, $this));
     }
     if ($this->getProperty(Image::ASPECT_FIT, $node)) {
         $image->withPresentation(Image::ASPECT_FIT);
     } elseif ($this->getProperty(Image::ASPECT_FIT_ONLY, $node)) {
         $image->withPresentation(Image::ASPECT_FIT_ONLY);
     } elseif ($this->getProperty(Image::FULLSCREEN, $node)) {
         $image->withPresentation(Image::FULLSCREEN);
     } elseif ($this->getProperty(Image::NON_INTERACTIVE, $node)) {
         $image->withPresentation(Image::NON_INTERACTIVE);
     }
     if ($this->getProperty(self::PROPERTY_LIKE, $node)) {
         $image->enableLike();
     }
     if ($this->getProperty(self::PROPERTY_COMMENTS, $node)) {
         $image->enableComments();
     }
     $suppress_warnings = $transformer->suppress_warnings;
     $transformer->suppress_warnings = true;
     $transformer->transform($image, $node);
     $transformer->suppress_warnings = $suppress_warnings;
     return $context;
 }
 public function apply($transformer, $slideshow, $node)
 {
     $image = Image::create();
     // Builds the image
     $url = $this->getProperty(self::PROPERTY_IMAGE_URL, $node);
     if ($url) {
         $image->withURL($url);
         $slideshow->addImage($image);
     } else {
         $transformer->addWarning(new InvalidSelector(self::PROPERTY_IMAGE_URL, $slideshow, $node, $this));
     }
     $caption = Caption::create();
     $caption_title = $this->getProperty(self::PROPERTY_CAPTION_TITLE, $node);
     if ($caption_title) {
         $caption->withTitle($caption_title);
         $image->withCaption($caption);
     }
     $caption_credit = $this->getProperty(self::PROPERTY_CAPTION_CREDIT, $node);
     if ($caption_credit) {
         $caption->withCredit($caption_credit);
     }
     return $slideshow;
 }
 public function getContextClass()
 {
     return [Map::getClassName(), Image::getClassName(), Interactive::getClassName(), Slideshow::getClassName(), SocialEmbed::getClassName(), Video::getClassName()];
 }
 public function testIsWithinFalseObj()
 {
     $image = Image::create();
     $video = Video::create();
     $anotherImg = Image::create();
     $result = Type::isWithin($image, [$anotherImg, $video, 'z']);
     $this->assertFalse($result);
 }
Example #10
0
 /**
  * Sets the cover of InstantArticle with Image or Video
  *
  * @param Image|Video|Slideshow $cover The cover for the header of the InstantArticle
  *
  * @return $this
  */
 public function withCover($cover)
 {
     Type::enforce($cover, [Image::getClassName(), Slideshow::getClassName(), Video::getClassName()]);
     $this->cover = $cover;
     return $this;
 }
 /**
  * Get the cover media.
  *
  * @since 0.1
  * @return Image|Video
  */
 public function get_cover_media()
 {
     $cover_media = Image::create();
     // If someone else is handling this, let them. Otherwise fall back to us trying to use the featured image.
     if (has_filter('instant_articles_cover_media')) {
         /**
          * Filter the cover media.
          *
          * @since 0.1
          * @param Image     $cover_media  The cover media object.
          * @param int       $post_id      The current post ID.
          */
         $cover_media = apply_filters('instant_articles_cover_media', $cover_media, $this->_post->ID);
     } else {
         $featured_image_data = $this->get_the_featured_image();
         if (isset($featured_image_data['src']) && strlen($featured_image_data['src'])) {
             $cover_media = Image::create()->withURL($featured_image_data['src']);
             if (isset($featured_image_data['caption']) && strlen($featured_image_data['caption'])) {
                 $cover_media->withCaption(Caption::create()->withTitle($featured_image_data['caption']));
             }
         }
     }
     return $cover_media;
 }
 /**
  * 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;
 }
 /**
  * Adds a new image to the slideshow. It is REQUIRED.
  *
  * @param Image $article_image The image.
  *
  * @return $this
  */
 public function addImage($article_image)
 {
     Type::enforce($article_image, Image::getClassName());
     $this->article_images[] = $article_image;
     return $this;
 }
 public function getContextClass()
 {
     return [Image::getClassName(), Video::getClassName(), Map::getClassName()];
 }