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;
 }
示例#2
0
 public function apply($transformer, $context_element, $node)
 {
     $h2 = H2::create();
     if (Type::is($context_element, array(Header::getClassName(), Caption::getClassName()))) {
         $context_element->withSubTitle($h2);
     } elseif (Type::is($context_element, InstantArticle::getClassName())) {
         $context_element->addChild($h2);
     }
     if ($this->getProperty(Caption::POSITION_BELOW, $node)) {
         $h2->withPosition(Caption::POSITION_BELOW);
     }
     if ($this->getProperty(Caption::POSITION_CENTER, $node)) {
         $h2->withPosition(Caption::POSITION_CENTER);
     }
     if ($this->getProperty(Caption::POSITION_ABOVE, $node)) {
         $h2->withPosition(Caption::POSITION_ABOVE);
     }
     if ($this->getProperty(Caption::ALIGN_LEFT, $node)) {
         $h2->withTextAlignment(Caption::ALIGN_LEFT);
     }
     if ($this->getProperty(Caption::ALIGN_CENTER, $node)) {
         $h2->withTextAlignment(Caption::ALIGN_CENTER);
     }
     if ($this->getProperty(Caption::ALIGN_RIGHT, $node)) {
         $h2->withTextAlignment(Caption::ALIGN_RIGHT);
     }
     $transformer->transform($h2, $node);
     return $context_element;
 }
 public function testRenderBasicWithCaption()
 {
     $social_embed = interactive::create()->withSource('http://foo.com/interactive-graphic')->withWidth(640)->withHeight(300)->withCaption(Caption::create()->appendText('Some caption to the interactive graphic'));
     $expected = '<figure class="op-interactive">' . '<iframe src="http://foo.com/interactive-graphic" width="640" height="300"></iframe>' . '<figcaption>Some caption to the interactive graphic</figcaption>' . '</figure>';
     $rendered = $social_embed->render();
     $this->assertEquals($expected, $rendered);
 }
 public function apply($transformer, $container_of_caption, $node)
 {
     $caption = Caption::create();
     $container_of_caption->withCaption($caption);
     if ($this->getProperty(Caption::POSITION_BELOW, $node)) {
         $caption->withPosition(Caption::POSITION_BELOW);
     }
     if ($this->getProperty(Caption::POSITION_CENTER, $node)) {
         $caption->withPosition(Caption::POSITION_CENTER);
     }
     if ($this->getProperty(Caption::POSITION_ABOVE, $node)) {
         $caption->withPosition(Caption::POSITION_ABOVE);
     }
     if ($this->getProperty(Caption::ALIGN_LEFT, $node)) {
         $caption->withTextAlignment(Caption::ALIGN_LEFT);
     }
     if ($this->getProperty(Caption::ALIGN_CENTER, $node)) {
         $caption->withTextAlignment(Caption::ALIGN_CENTER);
     }
     if ($this->getProperty(Caption::ALIGN_RIGHT, $node)) {
         $caption->withTextAlignment(Caption::ALIGN_RIGHT);
     }
     if ($this->getProperty(Caption::SIZE_MEDIUM, $node)) {
         $caption->withFontsize(Caption::SIZE_MEDIUM);
     }
     if ($this->getProperty(Caption::SIZE_LARGE, $node)) {
         $caption->withFontsize(Caption::SIZE_LARGE);
     }
     if ($this->getProperty(Caption::SIZE_XLARGE, $node)) {
         $caption->withFontsize(Caption::SIZE_XLARGE);
     }
     $text_default = $this->getProperty(self::PROPERTY_DEFAULT, $node);
     if ($text_default) {
         $caption->withTitle($text_default);
     } else {
         $transformer->transform($caption, $node);
     }
     return $container_of_caption;
 }
 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 testIsNotInSetException()
 {
     $this->setExpectedException('InvalidArgumentException');
     Type::enforce(Caption::create(), [InstantArticle::getClassName(), Video::getClassName(), Image::getClassName()]);
 }
示例#7
0
 /**
  * This sets figcaption tag as documentation. It overrides all sets
  * made with Caption.
  *
  * @param Caption $caption the caption the video will have
  * @see Caption.
  * @return $this
  */
 public function withCaption($caption)
 {
     Type::enforce($caption, Caption::getClassName());
     $this->caption = $caption;
     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;
 }
 public function getContextClass()
 {
     return Caption::getClassName();
 }