From 9796ca38134ac7021ad8dd6019c124e0b2ebe3b9 Mon Sep 17 00:00:00 2001 From: oraricha Date: Sun, 12 Feb 2017 11:15:43 +0200 Subject: [PATCH 01/10] feat(compat): add support for Apester medias --- compat.php | 6 +++++ compat/apester-rules-configuration.json | 21 ++++++++++++++++++ compat/class-instant-articles-apester.php | 27 +++++++++++++++++++++++ 3 files changed, 54 insertions(+) create mode 100644 compat/apester-rules-configuration.json create mode 100644 compat/class-instant-articles-apester.php diff --git a/compat.php b/compat.php index 4ac3a422..21f0f6dd 100644 --- a/compat.php +++ b/compat.php @@ -46,3 +46,9 @@ include( dirname( __FILE__ ) . '/compat/class-instant-articles-playbuzz.php' ); $playbuzz = new Instant_Articles_Playbuzz; $playbuzz->init(); + + +// Load support for Apester's plugin Medias +include( dirname( __FILE__ ) . '/compat/class-instant-articles-apester.php' ); +$apester = new Instant_Articles_Apester; +$apester->init(); diff --git a/compat/apester-rules-configuration.json b/compat/apester-rules-configuration.json new file mode 100644 index 00000000..7a3346d4 --- /dev/null +++ b/compat/apester-rules-configuration.json @@ -0,0 +1,21 @@ +{ + "rules": [{ + "class": "IgnoreRule", + "selector": "//p/script[contains(@src,'apester')]" + }, { + "class": "InteractiveRule", + "selector": "div.apester-media", + "properties": { + "interactive.iframe": { + "type": "multiple", + "children": [{ + "type": "fragment", + "fragment": "" + }, { + "type": "element", + "selector": "div.apester-media" + }] + } + } + }] +} \ No newline at end of file diff --git a/compat/class-instant-articles-apester.php b/compat/class-instant-articles-apester.php new file mode 100644 index 00000000..11ac51f1 --- /dev/null +++ b/compat/class-instant-articles-apester.php @@ -0,0 +1,27 @@ +loadRules( $configuration ); + + return $transformer; + } +} From 9250fc675670a2cae9d79572fe125089a0049623 Mon Sep 17 00:00:00 2001 From: oraricha Date: Sun, 12 Feb 2017 11:22:04 +0200 Subject: [PATCH 02/10] remove blank line --- compat.php | 1 - 1 file changed, 1 deletion(-) diff --git a/compat.php b/compat.php index 21f0f6dd..a70d89b2 100644 --- a/compat.php +++ b/compat.php @@ -47,7 +47,6 @@ $playbuzz = new Instant_Articles_Playbuzz; $playbuzz->init(); - // Load support for Apester's plugin Medias include( dirname( __FILE__ ) . '/compat/class-instant-articles-apester.php' ); $apester = new Instant_Articles_Apester; From 0b02e90362c5f21bcf62501c8cd580e2b5ca1452 Mon Sep 17 00:00:00 2001 From: Diego Moreno Quinteiro Date: Mon, 13 Feb 2017 22:02:17 -0200 Subject: [PATCH 03/10] Add proper permission check on meta-box --- meta-box/class-instant-articles-meta-box.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/meta-box/class-instant-articles-meta-box.php b/meta-box/class-instant-articles-meta-box.php index 22d87534..71892a0a 100644 --- a/meta-box/class-instant-articles-meta-box.php +++ b/meta-box/class-instant-articles-meta-box.php @@ -56,6 +56,10 @@ public static function register_meta_box() { * @param Post $post the post request content. */ public static function render_meta_box_loader( $post ) { + if ( ! current_user_can( 'edit_post', $post->ID ) ) { + return; + } + include( dirname( __FILE__ ) . '/meta-box-loader-template.php' ); } @@ -63,8 +67,13 @@ public static function render_meta_box_loader( $post ) { * Renderer for the Metabox. */ public static function force_submit() { - check_ajax_referer( 'instant-articles-force-submit', 'security' ); $post_id = intval( $_POST[ 'post_ID' ] ); + + if ( ! current_user_can( 'edit_post', $post_id ) ) { + wp_die( -1, 403 ); + } + + check_ajax_referer( 'instant-articles-force-submit-' . $post_id, 'security' ); $force = sanitize_text_field( $_POST[ 'force' ] ) === 'true'; update_post_meta( $post_id, Instant_Articles_Publisher::FORCE_SUBMIT_KEY, $force ); Instant_Articles_Publisher::submit_article( $post_id, get_post( $post_id ) ); @@ -74,8 +83,13 @@ public static function force_submit() { * Renderer for the Metabox. */ public static function render_meta_box() { - $ajax_nonce = wp_create_nonce( "instant-articles-force-submit" ); $post_id = intval( $_POST[ 'post_ID' ] ); + + if ( ! current_user_can( 'edit_post', $post_id ) ) { + wp_die( -1, 403 ); + } + + $ajax_nonce = wp_create_nonce( "instant-articles-force-submit-" . $post_id ); $post = get_post( $post_id ); $adapter = new Instant_Articles_Post( $post ); $article = $adapter->to_instant_article(); From 3d3a4b413dfb42e97d9d4fbc91059e8069d4c809 Mon Sep 17 00:00:00 2001 From: Makoto Sakata Date: Mon, 13 Feb 2017 18:55:14 +0900 Subject: [PATCH 04/10] Add an option to set a copyright footer fixes #261 - [x] Set footer element during the construction of IA document - [x] Rename "Style" setting to "Appearance" - [x] Consolidate appearance settings logic into one function --- class-instant-articles-post.php | 36 +++++++++++++------ .../class-instant-articles-option-styles.php | 10 ++++-- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/class-instant-articles-post.php b/class-instant-articles-post.php index b05f112b..16273f4a 100644 --- a/class-instant-articles-post.php +++ b/class-instant-articles-post.php @@ -678,16 +678,7 @@ public function to_instant_article() { ->addMetaProperty( 'op:generator:application', 'facebook-instant-articles-wp' ) ->addMetaProperty( 'op:generator:application:version', IA_PLUGIN_VERSION ); - $settings_style = Instant_Articles_Option_Styles::get_option_decoded(); - if ( isset( $settings_style['article_style'] ) && ! empty( $settings_style['article_style'] ) ) { - $this->instant_article->withStyle( $settings_style['article_style'] ); - } else { - $this->instant_article->withStyle( 'default' ); - } - - if ( isset( $settings_style['rtl_enabled'] ) ) { - $this->instant_article->enableRTL(); - } + $this->set_appearance_from_settings(); $transformer->transformString( $this->instant_article, $this->get_the_content(), get_option( 'blog_charset' ) ); @@ -863,6 +854,31 @@ public function add_analytics_from_settings() { } } + /** + * Apply appearance settings for an InstantArticle. + * + * @since 3.3 + */ + public function set_appearance_from_settings() { + $settings = Instant_Articles_Option_Styles::get_option_decoded(); + + if ( isset( $settings['article_style'] ) && ! empty( $settings['article_style'] ) ) { + $this->instant_article->withStyle( $settings['article_style'] ); + } else { + $this->instant_article->withStyle( 'default' ); + } + + if ( isset( $settings['copyright'] ) && ! empty( $settings['copyright'] ) ) { + $this->instant_article->withFooter( + Footer::create()->withCopyright( $settings['copyright'] ) + ); + } + + if ( isset( $settings['rtl_enabled'] ) ) { + $this->instant_article->enableRTL(); + } + } + /** * Article style. * diff --git a/wizard/class-instant-articles-option-styles.php b/wizard/class-instant-articles-option-styles.php index d8ad734e..2eadb97a 100644 --- a/wizard/class-instant-articles-option-styles.php +++ b/wizard/class-instant-articles-option-styles.php @@ -17,8 +17,7 @@ class Instant_Articles_Option_Styles extends Instant_Articles_Option { const OPTION_KEY = 'instant-articles-option-styles'; public static $sections = array( - 'title' => 'Styles', - 'description' => '

Assign your Instant Articles a custom style. To begin, customize a template using the Style Editor. Next, input the name of the style below.

Note: If this field is left blank, the plugin will enable the “Default” style. Learn more about Instant Articles style options in the Design Guide.

', + 'title' => 'Appearance', ); public static $fields = array( @@ -26,6 +25,13 @@ class Instant_Articles_Option_Styles extends Instant_Articles_Option { 'article_style' => array( 'label' => 'Article Style', 'default' => 'default', + 'description' => '

Assign your Instant Articles a custom style. To begin, customize a template using the Style Editor. Next, input the name of the style below.

Note: If this field is left blank, the plugin will enable the “Default” style. Learn more about Instant Articles style options in the Design Guide.

', + ), + + 'copyright' => array( + 'label' => 'Copyright', + 'default' => '', + 'description' => 'The copyright details for your articles. Note: No markup tags can be used in this field. Learn more about Footer in Instant Articles.', ), 'rtl_enabled' => array( From 8fad39309b809d8b103dbd98702154a197e08ce0 Mon Sep 17 00:00:00 2001 From: oraricha Date: Tue, 14 Feb 2017 11:56:27 +0200 Subject: [PATCH 05/10] fix(apester transformer rule): fixed ignore rule to search any script tag --- compat/apester-rules-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compat/apester-rules-configuration.json b/compat/apester-rules-configuration.json index 7a3346d4..a689d39e 100644 --- a/compat/apester-rules-configuration.json +++ b/compat/apester-rules-configuration.json @@ -1,7 +1,7 @@ { "rules": [{ "class": "IgnoreRule", - "selector": "//p/script[contains(@src,'apester')]" + "selector": "//script[contains(@src,'apester')]" }, { "class": "InteractiveRule", "selector": "div.apester-media", From f6103789c6f15a9dca9520c4611dc2d4c5a44b6b Mon Sep 17 00:00:00 2001 From: Diego Moreno Quinteiro Date: Tue, 14 Feb 2017 15:45:37 -0200 Subject: [PATCH 06/10] Bump version to 3.3.3 --- facebook-instant-articles.php | 4 ++-- readme.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/facebook-instant-articles.php b/facebook-instant-articles.php index 62c71dc5..f33e39ca 100644 --- a/facebook-instant-articles.php +++ b/facebook-instant-articles.php @@ -4,7 +4,7 @@ * Description: Add support for Instant Articles for Facebook to your WordPress site. * Author: Automattic, Dekode, Facebook * Author URI: https://vip.wordpress.com/plugins/instant-articles/ - * Version: 3.3.2 + * Version: 3.3.3 * Text Domain: instant-articles * License: GPLv2 * License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -61,7 +61,7 @@ function () { defined( 'ABSPATH' ) || die( 'Shame on you' ); - define( 'IA_PLUGIN_VERSION', '3.3.2' ); + define( 'IA_PLUGIN_VERSION', '3.3.3' ); define( 'IA_PLUGIN_PATH_FULL', __FILE__ ); define( 'IA_PLUGIN_PATH', plugin_basename( __FILE__ ) ); define( 'IA_PLUGIN_FILE_BASENAME', pathinfo( __FILE__, PATHINFO_FILENAME ) ); diff --git a/readme.txt b/readme.txt index c6708ddb..50e95310 100644 --- a/readme.txt +++ b/readme.txt @@ -3,7 +3,7 @@ Contributors: trrine, olethomas, bjornjohansen, dekode, automattic, facebook Tags: instant articles, facebook, mobile Requires at least: 4.3 Tested up to: 4.6 -Stable tag: 3.3.2 +Stable tag: 3.3.3 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html From c9bc0b9e18b1f4b9bb70c03a82b3ee730ee6fda6 Mon Sep 17 00:00:00 2001 From: Everton Rosario Date: Wed, 15 Feb 2017 19:17:37 -0200 Subject: [PATCH 07/10] Extracted anonymous inline function to a declared one. Fixes #390 --- facebook-instant-articles.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/facebook-instant-articles.php b/facebook-instant-articles.php index f33e39ca..46277de4 100644 --- a/facebook-instant-articles.php +++ b/facebook-instant-articles.php @@ -12,13 +12,19 @@ * @package default */ +/** +* Prints error about incompatible version. Extracted as function issue: #390 +* +* @since 3.3.4 +*/ +function show_version_incompatible_warning() { + echo '

' . + esc_html__( 'Instant Articles for WP requires PHP 5.4 to function properly. Please upgrade PHP or deactivate Instant Articles for WP.', 'instant-articles' ) . '

'; +} if ( version_compare( PHP_VERSION, '5.4', '<' ) ) { add_action( 'admin_notices', - function () { - echo '

' . - esc_html__( 'Instant Articles for WP requires PHP 5.4 to function properly. Please upgrade PHP or deactivate Instant Articles for WP.', 'instant-articles' ) . '

'; - } + 'show_version_incompatible_warning' ); return; } else { From 21a7bb8b926bd8e3fec562cd3d52ba02e75a216a Mon Sep 17 00:00:00 2001 From: Everton Rosario Date: Thu, 16 Feb 2017 10:17:27 -0200 Subject: [PATCH 08/10] - [x] Adds configuration for likes and comments - [x] Makes easier to enable likes + comments without any coding Relates to https://github.com/facebook/facebook-instant-articles-sdk-php/pull/195 Fixes #36 and #340 --- class-instant-articles-post.php | 13 +++++++++++++ .../class-instant-articles-option-publishing.php | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/class-instant-articles-post.php b/class-instant-articles-post.php index 16273f4a..8270fe76 100644 --- a/class-instant-articles-post.php +++ b/class-instant-articles-post.php @@ -680,6 +680,19 @@ public function to_instant_article() { $this->set_appearance_from_settings(); + // This block sets as default likes and/or comments based on the configuration setup, + // and call $transformer->transform will consider the defaults before building the Elements + // + // Warning: if you are using pthreads or any other multithreaded engine, consider replicating this to all processes. + if ( isset( $settings_publishing[ 'likes_on_media' ] ) ) { + Image::setDefaultLikeEnabled( $settings_publishing[ 'likes_on_media' ] ); + Video::setDefaultLikeEnabled( $settings_publishing[ 'likes_on_media' ] ); + } + if ( isset( $settings_publishing[ 'comments_on_media' ] ) ) { + Image::setDefaultCommentEnabled( $settings_publishing[ 'comments_on_media' ] ); + Video::setDefaultCommentEnabled( $settings_publishing[ 'comments_on_media' ] ); + } + $transformer->transformString( $this->instant_article, $this->get_the_content(), get_option( 'blog_charset' ) ); $this->add_ads_from_settings(); diff --git a/wizard/class-instant-articles-option-publishing.php b/wizard/class-instant-articles-option-publishing.php index 46dcfe98..05711348 100644 --- a/wizard/class-instant-articles-option-publishing.php +++ b/wizard/class-instant-articles-option-publishing.php @@ -54,6 +54,22 @@ class Instant_Articles_Option_Publishing extends Instant_Articles_Option { 'default' => false, 'checkbox_label' => 'Publish articles containing warnings', ), + + 'likes_on_media' => array( + 'label' => 'Likes', + 'description' => 'With this option enabled, any image or video will have the like action enabled by default.', + 'render' => 'checkbox', + 'default' => false, + 'checkbox_label' => 'Enable like action on images and videos by default', + ), + + 'comments_on_media' => array( + 'label' => 'Comments', + 'description' => 'With this option enabled, any image or video will have the comments enabled by default.', + 'render' => 'checkbox', + 'default' => false, + 'checkbox_label' => 'Enable comments on images and videos by default', + ), ); /** From 6fc258c7a325e8688917812e76b8c5abe381f661 Mon Sep 17 00:00:00 2001 From: Makoto Sakata Date: Fri, 24 Feb 2017 12:39:17 +0900 Subject: [PATCH 09/10] fix merge damage - as @yssk22 commented in #428, the refactored code has been reverted back by mistake, and it result in garbled MB characters in title. --- class-instant-articles-post.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/class-instant-articles-post.php b/class-instant-articles-post.php index 8270fe76..3dc1b590 100644 --- a/class-instant-articles-post.php +++ b/class-instant-articles-post.php @@ -636,11 +636,7 @@ public function to_instant_article() { $title = $this->get_the_title(); if ( $title ) { - $document = new DOMDocument(); - libxml_use_internal_errors(true); - $document->loadHTML( '

' . $title . '

' ); - libxml_use_internal_errors(false); - $transformer->transform( $header, $document ); + $transformer->transformString( $header, '

' . $title . '

', $blog_charset ); } if ( $this->has_subtitle() ) { From 95541fc9a1704381d18c2f3c00544f345830ab2d Mon Sep 17 00:00:00 2001 From: Everton Rosario Date: Thu, 9 Mar 2017 11:30:04 -0300 Subject: [PATCH 10/10] Adds parameter to format article before ingestion [x] Depends on PR: https://github.com/facebook/facebook-instant-articles-sdk-php/pull/199 [x] Creates a new checkbox configuration to allow user to activate/deactivate formatting [x] Uses the configuration to apply the formatting style chosen on setup Depends on https://github.com/facebook/facebook-instant-articles-sdk-php/pull/199 Fixes #625 --- class-instant-articles-publisher.php | 7 +++++-- meta-box/meta-box-template.php | 2 +- wizard/class-instant-articles-option-publishing.php | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/class-instant-articles-publisher.php b/class-instant-articles-publisher.php index d9d565b4..97cb680c 100644 --- a/class-instant-articles-publisher.php +++ b/class-instant-articles-publisher.php @@ -125,13 +125,16 @@ public static function submit_article( $post_id, $post ) { $published = apply_filters( 'instant_articles_post_published', true, $post_id ); } + // Checks if it will render article formatted - With spaces and tabs. + $publishArticleFormatted = isset( $publishing_settings[ 'publish_formatted' ] ) ? (bool) $publishing_settings[ 'publish_formatted' ] : false; + try { // Import the article. - $submission_id = $client->importArticle( $article, $published ); + $submission_id = $client->importArticle( $article, $published, true, $publishArticleFormatted ); update_post_meta( $post_id, self::SUBMISSION_ID_KEY, $submission_id ); } catch ( Exception $e ) { // Try without taking live for pages not yet reviewed. - $submission_id = $client->importArticle( $article, false ); + $submission_id = $client->importArticle( $article, false, true, $publishArticleFormatted ); update_post_meta( $post_id, self::SUBMISSION_ID_KEY, $submission_id ); } } diff --git a/meta-box/meta-box-template.php b/meta-box/meta-box-template.php index 116dc706..d456de0e 100644 --- a/meta-box/meta-box-template.php +++ b/meta-box/meta-box-template.php @@ -200,7 +200,7 @@
- +

diff --git a/wizard/class-instant-articles-option-publishing.php b/wizard/class-instant-articles-option-publishing.php index 05711348..8d0d5e8c 100644 --- a/wizard/class-instant-articles-option-publishing.php +++ b/wizard/class-instant-articles-option-publishing.php @@ -55,6 +55,14 @@ class Instant_Articles_Option_Publishing extends Instant_Articles_Option { 'checkbox_label' => 'Publish articles containing warnings', ), + 'publish_formatted' => array( + 'label' => 'Format articles', + 'description' => 'With this option enabled, articles will be formatted before ingestion. This helps finding errors and understand the final markup Instant Article document.', + 'render' => 'checkbox', + 'default' => false, + 'checkbox_label' => 'Publish articles formatted', + ), + 'likes_on_media' => array( 'label' => 'Likes', 'description' => 'With this option enabled, any image or video will have the like action enabled by default.',