public function apply($transformer, $footer, $element)
 {
     $p = Paragraph::create();
     $footer->addCredit($p);
     $transformer->transform($p, $element);
     return $footer;
 }
 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, $context_element, $element)
 {
     $p = Paragraph::create();
     $context_element->addChild($p);
     $transformer->transform($p, $element);
     return $context_element;
 }
 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, $context, $node)
 {
     $interactive = Interactive::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 interactive
     $iframe = $this->getProperty(self::PROPERTY_IFRAME, $node);
     $url = $this->getProperty(self::PROPERTY_URL, $node);
     if ($iframe) {
         $interactive->withHTML($iframe);
     }
     if ($url) {
         $interactive->withSource($url);
     }
     if ($iframe || $url) {
         $instant_article->addChild($interactive);
         if ($instant_article !== $context) {
             $instant_article->addChild($context);
         }
     } else {
         $transformer->addWarning(new InvalidSelector(self::PROPERTY_IFRAME, $instant_article, $node, $this));
     }
     if ($this->getProperty(self::PROPERTY_WIDTH_COLUMN_WIDTH, $node)) {
         $interactive->withMargin(Interactive::COLUMN_WIDTH);
     } else {
         $interactive->withMargin(Interactive::NO_MARGIN);
     }
     $width = $this->getProperty(self::PROPERTY_WIDTH, $node);
     if ($width) {
         $interactive->withWidth($width);
     }
     $height = $this->getProperty(self::PROPERTY_HEIGHT, $node);
     if ($height) {
         $interactive->withHeight($height);
     }
     $suppress_warnings = $transformer->suppress_warnings;
     $transformer->suppress_warnings = true;
     $transformer->transform($interactive, $node);
     $transformer->suppress_warnings = $suppress_warnings;
     return $context;
 }
 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 getContextClass()
 {
     return Paragraph::getClassName();
 }
 protected function setUp()
 {
     $this->facebook = $this->getMockBuilder('Facebook\\Facebook')->disableOriginalConstructor()->getMock();
     $this->client = new Client($this->facebook, "PAGE_ID", false);
     $this->article = InstantArticle::create()->addChild(Paragraph::create()->appendText('Test'));
 }
 /**
  * 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;
 }
示例#10
0
 /**
  * Adds a new Paragraph to the credits
  *
  * @param Paragraph $credit - One Paragraph to be added as a credit.
  *
  * @return $this
  */
 public function addCredit($credit)
 {
     Type::enforce($credit, Paragraph::getClassName());
     $this->credits[] = $credit;
     return $this;
 }