Instant Articles for WP - Version 2.8

Version Description

Download this release

Release Info

Developer diegoquinteiro
Plugin Icon 128x128 Instant Articles for WP
Version 2.8
Comparing to
See all releases

Code changes from version 2.7 to 2.8

class-instant-articles-publisher.php CHANGED
@@ -37,6 +37,11 @@ class Instant_Articles_Publisher {
37
  return;
38
  }
39
 
 
 
 
 
 
40
  // Transform the post to an Instant Article.
41
  $adapter = new Instant_Articles_Post( $post );
42
  $article = $adapter->to_instant_article();
@@ -68,7 +73,7 @@ class Instant_Articles_Publisher {
68
  $take_live = false;
69
  } else {
70
  // Any publish status other than 'publish' means draft for the Instant Article.
71
- $take_live = 'publish' === $post->post_status;
72
  }
73
 
74
  try {
37
  return;
38
  }
39
 
40
+ // Don't process if this post is not published
41
+ if ('publish' !== $post->post_status) {
42
+ return;
43
+ }
44
+
45
  // Transform the post to an Instant Article.
46
  $adapter = new Instant_Articles_Post( $post );
47
  $article = $adapter->to_instant_article();
73
  $take_live = false;
74
  } else {
75
  // Any publish status other than 'publish' means draft for the Instant Article.
76
+ $take_live = true;
77
  }
78
 
79
  try {
facebook-instant-articles.php CHANGED
@@ -4,7 +4,7 @@
4
  * Description: Add support for Instant Articles for Facebook to your WordPress site.
5
  * Author: Automattic, Dekode, Facebook
6
  * Author URI: https://vip.wordpress.com/plugins/instant-articles/
7
- * Version: 2.7
8
  * Text Domain: instant-articles
9
  * License: GPLv2
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -67,7 +67,7 @@ if ( version_compare( PHP_VERSION, '5.4', '<' ) ) {
67
 
68
  defined( 'ABSPATH' ) || die( 'Shame on you' );
69
 
70
- define( 'IA_PLUGIN_VERSION', '2.7' );
71
  define( 'IA_PLUGIN_PATH_FULL', __FILE__ );
72
  define( 'IA_PLUGIN_PATH', plugin_basename( __FILE__ ) );
73
  define( 'IA_PLUGIN_FILE_BASENAME', pathinfo( __FILE__, PATHINFO_FILENAME ) );
4
  * Description: Add support for Instant Articles for Facebook to your WordPress site.
5
  * Author: Automattic, Dekode, Facebook
6
  * Author URI: https://vip.wordpress.com/plugins/instant-articles/
7
+ * Version: 2.8
8
  * Text Domain: instant-articles
9
  * License: GPLv2
10
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
67
 
68
  defined( 'ABSPATH' ) || die( 'Shame on you' );
69
 
70
+ define( 'IA_PLUGIN_VERSION', '2.8' );
71
  define( 'IA_PLUGIN_PATH_FULL', __FILE__ );
72
  define( 'IA_PLUGIN_PATH', plugin_basename( __FILE__ ) );
73
  define( 'IA_PLUGIN_FILE_BASENAME', pathinfo( __FILE__, PATHINFO_FILENAME ) );
meta-box/class-instant-articles-meta-box.php CHANGED
@@ -62,6 +62,7 @@ class Instant_Articles_Meta_Box {
62
  $article = $adapter->to_instant_article();
63
  $canonical_url = $adapter->get_canonical_url();
64
  $submission_status = null;
 
65
 
66
  Instant_Articles_Settings::menu_items();
67
  $settings_page_href = Instant_Articles_Settings::get_href_to_settings_page();
62
  $article = $adapter->to_instant_article();
63
  $canonical_url = $adapter->get_canonical_url();
64
  $submission_status = null;
65
+ $published = 'publish' === $post->post_status;
66
 
67
  Instant_Articles_Settings::menu_items();
68
  $settings_page_href = Instant_Articles_Settings::get_href_to_settings_page();
meta-box/meta-box-template.php CHANGED
@@ -11,8 +11,15 @@ use Facebook\InstantArticles\Client\InstantArticleStatus;
11
  use Facebook\InstantArticles\Client\ServerMessage;
12
  ?>
13
 
14
- <!-- Submission status -->
15
- <?php if ( $submission_status ) : ?>
 
 
 
 
 
 
 
16
 
17
  <!-- Display the last submission status -->
18
  <?php switch ( $submission_status->getStatus() ) :
11
  use Facebook\InstantArticles\Client\ServerMessage;
12
  ?>
13
 
14
+ <?php if ( ! $published ) : ?>
15
+ <p>
16
+ <b>
17
+ <span class="dashicons dashicons-media-document"></span>
18
+ Your post will be submitted to Instant Articles once you publish it.
19
+ </b>
20
+ </p>
21
+
22
+ <?php elseif ( $submission_status ) : ?>
23
 
24
  <!-- Display the last submission status -->
25
  <?php switch ( $submission_status->getStatus() ) :
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: trrine, olethomas, bjornjohansen, dekode, automattic, facebook
3
  Tags: instant articles, facebook, mobile
4
  Requires at least: 4.3
5
  Tested up to: 4.5
6
- Stable tag: 2.7
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
3
  Tags: instant articles, facebook, mobile
4
  Requires at least: 4.3
5
  Tested up to: 4.5
6
+ Stable tag: 2.8
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
vendor/composer/installed.json CHANGED
@@ -145,17 +145,17 @@
145
  },
146
  {
147
  "name": "facebook/facebook-instant-articles-sdk-php",
148
- "version": "v1.0.3",
149
- "version_normalized": "1.0.3.0",
150
  "source": {
151
  "type": "git",
152
  "url": "https://github.com/facebook/facebook-instant-articles-sdk-php.git",
153
- "reference": "736aba9bba141cbb4e45bd045969afce023ad926"
154
  },
155
  "dist": {
156
  "type": "zip",
157
- "url": "https://api.github.com/repos/facebook/facebook-instant-articles-sdk-php/zipball/736aba9bba141cbb4e45bd045969afce023ad926",
158
- "reference": "736aba9bba141cbb4e45bd045969afce023ad926",
159
  "shasum": ""
160
  },
161
  "require": {
@@ -167,7 +167,7 @@
167
  "require-dev": {
168
  "phpunit/phpunit": "^4.8"
169
  },
170
- "time": "2016-04-13 16:07:02",
171
  "type": "library",
172
  "installation-source": "dist",
173
  "autoload": {
145
  },
146
  {
147
  "name": "facebook/facebook-instant-articles-sdk-php",
148
+ "version": "v1.0.5",
149
+ "version_normalized": "1.0.5.0",
150
  "source": {
151
  "type": "git",
152
  "url": "https://github.com/facebook/facebook-instant-articles-sdk-php.git",
153
+ "reference": "0ef500ab82a54dbc8e13faed107ee6beed017107"
154
  },
155
  "dist": {
156
  "type": "zip",
157
+ "url": "https://api.github.com/repos/facebook/facebook-instant-articles-sdk-php/zipball/0ef500ab82a54dbc8e13faed107ee6beed017107",
158
+ "reference": "0ef500ab82a54dbc8e13faed107ee6beed017107",
159
  "shasum": ""
160
  },
161
  "require": {
167
  "require-dev": {
168
  "phpunit/phpunit": "^4.8"
169
  },
170
+ "time": "2016-04-14 22:49:19",
171
  "type": "library",
172
  "installation-source": "dist",
173
  "autoload": {
vendor/facebook/facebook-instant-articles-sdk-php/docs/QuickStart.md CHANGED
@@ -9,6 +9,11 @@ This SDK contains three primary components:
9
  `Elements` is the object tree class that represents the structure of an Instant Article. This object tree structure ensures that no invalid Instant Article HTML markup is generated. Here is a simple and complete object tree structure, starting with the `InstantArticle` class that holds the full Instant Article.
10
 
11
  ```php
 
 
 
 
 
12
  $article =
13
  InstantArticle::create()
14
  ->withCanonicalUrl('http://foo.com/article.html')
@@ -99,10 +104,7 @@ $article =
99
  // Analytics
100
  ->addChild(
101
  Analytics::create()
102
- ->withHTML(
103
- <h1>Some custom code</h1>
104
- <script>alert("test");</script>
105
- )
106
  )
107
  // Footer
108
  ->withFooter(
9
  `Elements` is the object tree class that represents the structure of an Instant Article. This object tree structure ensures that no invalid Instant Article HTML markup is generated. Here is a simple and complete object tree structure, starting with the `InstantArticle` class that holds the full Instant Article.
10
 
11
  ```php
12
+ $fragment = $document->createDocumentFragment();
13
+ $fragment->appendXML(
14
+ '<h1>Some custom code</h1>'.
15
+ '<script>alert("test");</script>'
16
+ );
17
  $article =
18
  InstantArticle::create()
19
  ->withCanonicalUrl('http://foo.com/article.html')
104
  // Analytics
105
  ->addChild(
106
  Analytics::create()
107
+ ->withHTML($fragment)
 
 
 
108
  )
109
  // Footer
110
  ->withFooter(
vendor/facebook/facebook-instant-articles-sdk-php/src/Facebook/InstantArticles/Elements/InstantArticle.php CHANGED
@@ -33,7 +33,7 @@ use Facebook\InstantArticles\Validators\Type;
33
  */
34
  class InstantArticle extends Element
35
  {
36
- const CURRENT_VERSION = '1.0.3';
37
 
38
  /**
39
  * The meta properties that are used on <head>
@@ -277,10 +277,12 @@ class InstantArticle extends Element
277
  $head->appendChild($charset);
278
 
279
  $this->addMetaProperty('op:markup_version', $this->markupVersion);
280
- $this->addMetaProperty(
281
- 'fb:use_automatic_ad_placement',
282
- $this->isAutomaticAdPlaced ? 'true' : 'false'
283
- );
 
 
284
 
285
  if ($this->style) {
286
  $this->addMetaProperty('fb:article_style', $this->style);
@@ -307,6 +309,17 @@ class InstantArticle extends Element
307
  }
308
  if ($this->children) {
309
  foreach ($this->children as $child) {
 
 
 
 
 
 
 
 
 
 
 
310
  $article->appendChild($child->toDOMElement($document));
311
  }
312
  if ($this->footer) {
33
  */
34
  class InstantArticle extends Element
35
  {
36
+ const CURRENT_VERSION = '1.0.5';
37
 
38
  /**
39
  * The meta properties that are used on <head>
277
  $head->appendChild($charset);
278
 
279
  $this->addMetaProperty('op:markup_version', $this->markupVersion);
280
+ if ($this->header && count($this->header->getAds()) > 0) {
281
+ $this->addMetaProperty(
282
+ 'fb:use_automatic_ad_placement',
283
+ $this->isAutomaticAdPlaced ? 'true' : 'false'
284
+ );
285
+ }
286
 
287
  if ($this->style) {
288
  $this->addMetaProperty('fb:article_style', $this->style);
309
  }
310
  if ($this->children) {
311
  foreach ($this->children as $child) {
312
+ if (Type::is($child, TextContainer::getClassName())) {
313
+ if (count($child->getTextChildren()) === 0) {
314
+ continue;
315
+ }
316
+ elseif (count($child->getTextChildren()) === 1) {
317
+ if (Type::is($child->getTextChildren()[0], Type::STRING) &&
318
+ trim($child->getTextChildren()[0]) === '') {
319
+ continue;
320
+ }
321
+ }
322
+ }
323
  $article->appendChild($child->toDOMElement($document));
324
  }
325
  if ($this->footer) {
vendor/facebook/facebook-instant-articles-sdk-php/src/Facebook/InstantArticles/Elements/ListElement.php CHANGED
@@ -80,7 +80,7 @@ class ListElement extends Element
80
  {
81
  Type::enforce($new_item, array(ListItem::getClassName(), Type::STRING));
82
  if (Type::is($new_item, Type::STRING)) {
83
- $new_item = ListItem::create()->withText($new_item);
84
  }
85
  $this->items[] = $new_item;
86
 
80
  {
81
  Type::enforce($new_item, array(ListItem::getClassName(), Type::STRING));
82
  if (Type::is($new_item, Type::STRING)) {
83
+ $new_item = ListItem::create()->appendText($new_item);
84
  }
85
  $this->items[] = $new_item;
86
 
vendor/facebook/facebook-instant-articles-sdk-php/src/Facebook/InstantArticles/Elements/ListItem.php CHANGED
@@ -33,39 +33,7 @@ class ListItem extends TextContainer
33
  }
34
 
35
  /**
36
- * @param string|TextContainer $text the text that will be added to <li>
37
- */
38
- public function withText($text)
39
- {
40
- Type::enforce($text, array(TextContainer::getClassName(), Type::STRING));
41
- $this->text = $text;
42
-
43
- return $this;
44
- }
45
-
46
- /**
47
- * Overrides the appendText to make sure only one child will be setted on this ListItem.
48
- * If appendText is called multiple times, it will store only the last one.
49
- * @see ListItem::withText()
50
- *
51
- * @param string|TextContainer The content can be a string or a TextContainer.
52
- */
53
- public function appendText($child)
54
- {
55
- return $this->withText($child);
56
- }
57
-
58
-
59
- /**
60
- * @return string|TextContainer The text that was added thru @see ListItem::withText()
61
- */
62
- public function getText()
63
- {
64
- return $this->text;
65
- }
66
-
67
- /**
68
- * Structure and create the full ListItem in a DOMElement.
69
  *
70
  * @param DOMDocument $document - The document where this element will be appended (optional).
71
  */
@@ -76,13 +44,7 @@ class ListItem extends TextContainer
76
  }
77
  $list_item = $document->createElement('li');
78
 
79
- if ($this->text) {
80
- if (Type::is($this->text, Type::STRING)) {
81
- $list_item->appendChild($document->createTextNode($this->text));
82
- } else {
83
- $list_item->appendChild($this->text->toDOMElement($document));
84
- }
85
- }
86
 
87
  return $list_item;
88
  }
33
  }
34
 
35
  /**
36
+ * Structure and create the full ListItem <li> in a DOMElement.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  *
38
  * @param DOMDocument $document - The document where this element will be appended (optional).
39
  */
44
  }
45
  $list_item = $document->createElement('li');
46
 
47
+ $list_item->appendChild($this->textToDOMDocumentFragment($document));
 
 
 
 
 
 
48
 
49
  return $list_item;
50
  }
vendor/facebook/facebook-instant-articles-sdk-php/src/Facebook/InstantArticles/Elements/TextContainer.php CHANGED
@@ -32,7 +32,7 @@ abstract class TextContainer extends Element
32
  */
33
  public function appendText($child)
34
  {
35
- Type::enforce($child, array(Type::STRING, FormattedText::getClassName()));
36
  $this->textChildren[] = $child;
37
 
38
  return $this;
32
  */
33
  public function appendText($child)
34
  {
35
+ Type::enforce($child, array(Type::STRING, FormattedText::getClassName(), TextContainer::getClassName()));
36
  $this->textChildren[] = $child;
37
 
38
  return $this;
vendor/facebook/facebook-instant-articles-sdk-php/tests/Facebook/InstantArticles/Elements/InstantArticleTest.php CHANGED
@@ -97,6 +97,17 @@ class InstantArticleTest extends \PHPUnit_Framework_TestCase
97
  ->appendText('Other text to be within a second paragraph for testing.')
98
  )
99
 
 
 
 
 
 
 
 
 
 
 
 
100
  // Slideshow
101
  ->addChild(
102
  SlideShow::create()
@@ -146,6 +157,75 @@ class InstantArticleTest extends \PHPUnit_Framework_TestCase
146
  }
147
 
148
  public function testRender()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  {
150
 
151
  $expected =
@@ -180,6 +260,7 @@ class InstantArticleTest extends \PHPUnit_Framework_TestCase
180
  'Author user in facebook'.
181
  '</address>'.
182
  '<h3 class="op-kicker">Some kicker of this article</h3>'.
 
183
  '</header>'.
184
  '<p>Some text to be within a paragraph for testing.</p>'.
185
  '<p>Other text to be within a second paragraph for testing.</p>'.
@@ -212,6 +293,8 @@ class InstantArticleTest extends \PHPUnit_Framework_TestCase
212
  '</body>'.
213
  '</html>';
214
 
 
 
215
  $this->assertEquals($expected, $this->article->render());
216
  }
217
  }
97
  ->appendText('Other text to be within a second paragraph for testing.')
98
  )
99
 
100
+ // Empty paragraph
101
+ ->addChild(
102
+ Paragraph::create()
103
+ )
104
+
105
+ // Paragraph with only whitespace
106
+ ->addChild(
107
+ Paragraph::create()
108
+ ->appendText(" \n \t ")
109
+ )
110
+
111
  // Slideshow
112
  ->addChild(
113
  SlideShow::create()
157
  }
158
 
159
  public function testRender()
160
+ {
161
+
162
+ $expected =
163
+ '<!doctype html>'.
164
+ '<html>'.
165
+ '<head>'.
166
+ '<link rel="canonical" href="http://foo.com/article.html"/>'.
167
+ '<meta charset="utf-8"/>'.
168
+ '<meta property="op:generator" content="facebook-instant-articles-sdk-php"/>'.
169
+ '<meta property="op:generator:version" content="'.InstantArticle::CURRENT_VERSION.'"/>'.
170
+ '<meta property="op:markup_version" content="v1.0"/>'.
171
+ '<meta property="fb:article_style" content="myarticlestyle"/>'.
172
+ '</head>'.
173
+ '<body>'.
174
+ '<article>'.
175
+ '<header>'.
176
+ '<figure>'.
177
+ '<img src="https://jpeg.org/images/jpegls-home.jpg"/>'.
178
+ '<figcaption>Some caption to the image</figcaption>'.
179
+ '</figure>'.
180
+ '<h1>Big Top Title</h1>'.
181
+ '<h2>Smaller SubTitle</h2>'.
182
+ '<time class="op-published" datetime="1984-08-14T19:30:00+00:00">August 14th, 7:30pm</time>'.
183
+ '<time class="op-modified" datetime="2016-02-10T10:00:00+00:00">February 10th, 10:00am</time>'.
184
+ '<address>'.
185
+ '<a>Author Name</a>'.
186
+ 'Author more detailed description'.
187
+ '</address>'.
188
+ '<address>'.
189
+ '<a href="http://facebook.com/author" rel="facebook">Author in FB</a>'.
190
+ 'Author user in facebook'.
191
+ '</address>'.
192
+ '<h3 class="op-kicker">Some kicker of this article</h3>'.
193
+ '</header>'.
194
+ '<p>Some text to be within a paragraph for testing.</p>'.
195
+ '<p>Other text to be within a second paragraph for testing.</p>'.
196
+ '<figure class="op-slideshow">'.
197
+ '<figure>'.
198
+ '<img src="https://jpeg.org/images/jpegls-home.jpg"/>'.
199
+ '</figure>'.
200
+ '<figure>'.
201
+ '<img src="https://jpeg.org/images/jpegls-home2.jpg"/>'.
202
+ '</figure>'.
203
+ '<figure>'.
204
+ '<img src="https://jpeg.org/images/jpegls-home3.jpg"/>'.
205
+ '</figure>'.
206
+ '</figure>'.
207
+ '<p>Some text to be within a paragraph for testing.</p>'.
208
+ '<figure class="op-ad">'.
209
+ '<iframe src="http://foo.com"></iframe>'.
210
+ '</figure>'.
211
+ '<p>Other text to be within a second paragraph for testing.</p>'.
212
+ '<figure class="op-tracker">'.
213
+ '<iframe>'.
214
+ '<h1>Some custom code</h1>'.
215
+ '<script>alert("test");</script>'.
216
+ '</iframe>'.
217
+ '</figure>'.
218
+ '<footer>'.
219
+ '<aside>Some plaintext credits.</aside>'.
220
+ '</footer>'.
221
+ '</article>'.
222
+ '</body>'.
223
+ '</html>';
224
+
225
+ $this->assertEquals($expected, $this->article->render());
226
+ }
227
+
228
+ public function testRenderWithAds()
229
  {
230
 
231
  $expected =
260
  'Author user in facebook'.
261
  '</address>'.
262
  '<h3 class="op-kicker">Some kicker of this article</h3>'.
263
+ '<figure class="op-ad"><iframe src="http://foo.com"></iframe></figure>'.
264
  '</header>'.
265
  '<p>Some text to be within a paragraph for testing.</p>'.
266
  '<p>Other text to be within a second paragraph for testing.</p>'.
293
  '</body>'.
294
  '</html>';
295
 
296
+ $this->article->getHeader()->addAd(Ad::create()->withSource('http://foo.com'));
297
+
298
  $this->assertEquals($expected, $this->article->render());
299
  }
300
  }
vendor/facebook/facebook-instant-articles-sdk-php/tests/Facebook/InstantArticles/Elements/ListElementTest.php CHANGED
@@ -92,9 +92,9 @@ class ListElementTest extends \PHPUnit_Framework_TestCase
92
  {
93
  $list =
94
  ListElement::createUnordered()
95
- ->addItem(ListItem::create()->withText(Paragraph::create()->appendText('Item 1')))
96
- ->addItem(ListItem::create()->withText(Div::create()->appendText('Item 2')))
97
- ->addItem(ListItem::create()->withText(Span::create()->appendText('Item 3')));
98
 
99
  $expected =
100
  '<ul>'.
92
  {
93
  $list =
94
  ListElement::createUnordered()
95
+ ->addItem(ListItem::create()->appendText(Paragraph::create()->appendText('Item 1')))
96
+ ->addItem(ListItem::create()->appendText(Div::create()->appendText('Item 2')))
97
+ ->addItem(ListItem::create()->appendText(Span::create()->appendText('Item 3')));
98
 
99
  $expected =
100
  '<ul>'.
vendor/facebook/facebook-instant-articles-sdk-php/tests/Facebook/InstantArticles/Transformer/Example/simple-ia.xml CHANGED
@@ -7,7 +7,6 @@
7
  <meta property="op:transformer" content="facebook-instant-articles-sdk-php"/>
8
  <meta property="op:transformer:version" content="1.0.0"/>
9
  <meta property="op:markup_version" content="v1.0"/>
10
- <meta property="fb:use_automatic_ad_placement" content="true"/>
11
  </head>
12
  <body>
13
  <article>
7
  <meta property="op:transformer" content="facebook-instant-articles-sdk-php"/>
8
  <meta property="op:transformer:version" content="1.0.0"/>
9
  <meta property="op:markup_version" content="v1.0"/>
 
10
  </head>
11
  <body>
12
  <article>
vendor/facebook/facebook-instant-articles-sdk-php/tests/Facebook/InstantArticles/Transformer/instant-article-example.html CHANGED
@@ -7,7 +7,6 @@
7
  <meta property="op:transformer" content="facebook-instant-articles-sdk-php"/>
8
  <meta property="op:transformer:version" content="1.0.0"/>
9
  <meta property="op:markup_version" content="v1.0"/>
10
- <meta property="fb:use_automatic_ad_placement" content="true"/>
11
  </head>
12
  <body>
13
  <article>
@@ -84,7 +83,7 @@
84
  <li>One paragraph on the list</li>
85
  <li>On the span</li>
86
  <li>Text inside div?</li>
87
- <li>Other paragraph on the li</li>
88
  <li>Last list item</li>
89
  </ol>
90
  <p>Some text to be within a paragraph for testing.</p>
7
  <meta property="op:transformer" content="facebook-instant-articles-sdk-php"/>
8
  <meta property="op:transformer:version" content="1.0.0"/>
9
  <meta property="op:markup_version" content="v1.0"/>
 
10
  </head>
11
  <body>
12
  <article>
83
  <li>One paragraph on the list</li>
84
  <li>On the span</li>
85
  <li>Text inside div?</li>
86
+ <li>Other <a href="#">paragraph</a> on the li</li>
87
  <li>Last list item</li>
88
  </ol>
89
  <p>Some text to be within a paragraph for testing.</p>