From 3c49d6832e046cdc47662dc4c46dcd86696b01c1 Mon Sep 17 00:00:00 2001 From: chrisamico Date: Sat, 14 Jun 2014 18:23:50 -0400 Subject: [PATCH 01/99] Clean up quoting and spacing a bit --- navis-documentcloud.php | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/navis-documentcloud.php b/navis-documentcloud.php index c1c7aad..9fc3b26 100644 --- a/navis-documentcloud.php +++ b/navis-documentcloud.php @@ -26,24 +26,23 @@ class Navis_DocumentCloud { function __construct() { - // shortcode - // mce plugins - // mce buttons - add_shortcode( 'documentcloud', array(&$this, 'embed_shortcode')); + + add_shortcode('documentcloud', array(&$this, 'embed_shortcode')); - add_action( 'init', array(&$this, 'register_tinymce_filters')); + add_action('init', array(&$this, 'register_tinymce_filters')); - add_action( 'save_post', array(&$this, 'save')); + add_action('save_post', array(&$this, 'save')); - add_action( 'admin_menu', array(&$this, 'add_options_page')); + add_action('admin_menu', array(&$this, 'add_options_page')); - add_action( 'admin_init', array(&$this, 'settings_init')); + add_action('admin_init', array(&$this, 'settings_init')); } function register_tinymce_filters() { add_filter('mce_external_plugins', array(&$this, 'add_tinymce_plugin') ); + add_filter('mce_buttons', array(&$this, 'register_button') ); @@ -57,7 +56,7 @@ function add_tinymce_plugin($plugin_array) { } function register_button($buttons) { - array_push($buttons, '|', "documentcloud"); + array_push($buttons, '|', 'documentcloud'); return $buttons; } @@ -94,7 +93,7 @@ function render_options_page() { ?> } function settings_init() { - add_settings_section( 'documentcloud', '', + add_settings_section('documentcloud', '', array(&$this, 'settings_section'), 'documentcloud'); add_settings_field('documentcloud_default_height', 'Default embed height (px)', @@ -112,17 +111,17 @@ function settings_init() { } function default_height_field() { - $option = intval(get_option( 'documentcloud_default_height', 600 )); + $option = intval(get_option('documentcloud_default_height', 600)); echo ""; } function default_width_field() { - $option = intval(get_option( 'documentcloud_default_width', 620 )); + $option = intval(get_option('documentcloud_default_width', 620)); echo ""; } function full_width_field() { - $option = intval(get_option( 'documentcloud_full_width', 620 )); + $option = intval(get_option('documentcloud_full_width', 620)); echo ""; } @@ -134,7 +133,7 @@ function save($post_id) { $post = get_post($post_id); // avoid autosave - if ( !in_array( $post->post_status, array( + if (!in_array($post->post_status, array( 'publish', 'draft', 'private', 'future', 'pending' )) ) { return; } @@ -153,13 +152,13 @@ function save($post_id) { $atts = shortcode_atts($defaults, $atts); // get a doc id to keep array keys consistent - if ( isset($atts['url']) && !isset($atts['id']) ) { + if (isset($atts['url']) && !isset($atts['id']) ) { $atts['id'] = $this->parse_id_from_url($atts['url']); } // if no id, don't bother storing because it's wrong if ($atts['id'] != null) { - if ( $atts['format'] == "wide" || $atts['width'] > $defaults['width']) { + if ($atts['format'] == "wide" || $atts['width'] > $defaults['width']) { $wide_assets[$atts['id']] = true; } else { $wide_assets[$atts['id']] = false; @@ -188,7 +187,7 @@ function parse_id_from_url($url) { function embed_shortcode($atts, $content, $code) { global $post; $defaults = $this->get_defaults(); - extract( shortcode_atts($defaults, $atts)); + extract(shortcode_atts($defaults, $atts)); // we need a document ID or URL, or it's a no op if ($url && !$id) { @@ -199,10 +198,10 @@ function embed_shortcode($atts, $content, $code) { // still no id? nothin doing if (!$id) return; - # we only deal with integers + // we only deal with integers $height = intval($height); $width = intval($width); - if ($format == "wide") { + if ($format == 'wide') { $width = get_option('documentcloud_full_width', 940); } From af35181bc879c4265d098a96abbe18c64f5c9f45 Mon Sep 17 00:00:00 2001 From: chrisamico Date: Sat, 14 Jun 2014 18:40:19 -0400 Subject: [PATCH 02/99] Heredocs are more trouble than they're worth. Closes #6. --- navis-documentcloud.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/navis-documentcloud.php b/navis-documentcloud.php index 9fc3b26..e768048 100644 --- a/navis-documentcloud.php +++ b/navis-documentcloud.php @@ -210,7 +210,7 @@ function embed_shortcode($atts, $content, $code) { // full control in single templates if (is_single() || is_page()) { return " -
+
- "; + "; + } else { // index view is always normal width, no sidebar return " @@ -237,8 +237,7 @@ function embed_shortcode($atts, $content, $code) { pdf: $pdf, container: '#DV-viewer-$id' }); - - "; + "; } } } From 7b0f40be7b5e673bd07b1684d80fe025e4f945d9 Mon Sep 17 00:00:00 2001 From: Chris Amico Date: Thu, 3 Jul 2014 22:26:10 -0400 Subject: [PATCH 03/99] Fix an unbalanced quote in embed code. Oops. --- navis-documentcloud.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/navis-documentcloud.php b/navis-documentcloud.php index e768048..63b6a48 100644 --- a/navis-documentcloud.php +++ b/navis-documentcloud.php @@ -210,7 +210,7 @@ function embed_shortcode($atts, $content, $code) { // full control in single templates if (is_single() || is_page()) { return " -
+
- + - - -
-

- - -

-

- - -

-

- - -

-
-
- -
-
- -
-
-
- - - - - diff --git a/readme.txt b/readme.txt index 70484c3..0b9fac3 100644 --- a/readme.txt +++ b/readme.txt @@ -75,6 +75,9 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == += 0.3.3 = +* Remove unused TinyMCE components + = 0.3.2 = * Implement a few best practice security measures From e21f53b5196d6b80268fdbae3e7908a988d83ad6 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Tue, 18 Aug 2015 11:11:50 -0500 Subject: [PATCH 45/99] Update "Tested up to" version number --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 0b9fac3..380d8cb 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: chrisamico, reefdog Tags: documentcloud, documents, journalism, reporting, research Requires at least: 3.2 -Tested up to: 4.2.1 +Tested up to: 4.2.4 Stable tag: trunk License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html From 7b2327cdc44eca156e74bd7ab17da5cf5bd81965 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Tue, 18 Aug 2015 11:33:29 -0500 Subject: [PATCH 46/99] Update tested-up-to to 4.3 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 380d8cb..003bd01 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: chrisamico, reefdog Tags: documentcloud, documents, journalism, reporting, research Requires at least: 3.2 -Tested up to: 4.2.4 +Tested up to: 4.3 Stable tag: trunk License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html From 2f7b56e93acae6722d6044b73c96168c2135f193 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Tue, 18 Aug 2015 11:33:35 -0500 Subject: [PATCH 47/99] Fix readme typo --- README.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8b17390..7d61a3c 100644 --- a/README.md +++ b/README.md @@ -105,4 +105,4 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## License and History -The DocumentCloud WordPress plugin is [GPLv2](http://www.gnu.org/licenses/gpl-2.0.html). Initial development of this plugin by Chris Amico (@eyeseast) supported by [NPR](http://www.npr.org) as part of [StateImpact](http://stateimpact.npr.org) project. Development continued by Justin Reese (@reefdog) at [DocumentCloud](https://www.documentcloud.org/). +The DocumentCloud WordPress plugin is [GPLv2](http://www.gnu.org/licenses/gpl-2.0.html). Initial development of this plugin by Chris Amico (@eyeseast) supported by [NPR](http://www.npr.org) as part of the [StateImpact](http://stateimpact.npr.org) project. Development continued by Justin Reese (@reefdog) at [DocumentCloud](https://www.documentcloud.org/). diff --git a/readme.txt b/readme.txt index 003bd01..052d34d 100644 --- a/readme.txt +++ b/readme.txt @@ -11,7 +11,7 @@ Embed DocumentCloud resources in WordPress content. == Description == -[DocumentCloud](https://www.documentcloud.org/) is a service that allows journalists to analyze, annotate and publish documents, hosted by Investigative Reporters & Editors. Initial development of this plugin supported by [NPR](http://www.npr.org) as part of [StateImpact](http://stateimpact.npr.org) project. +[DocumentCloud](https://www.documentcloud.org/) is a service that allows journalists to analyze, annotate and publish documents, hosted by Investigative Reporters & Editors. Initial development of this plugin supported by [NPR](http://www.npr.org) as part of the [StateImpact](http://stateimpact.npr.org) project. This plugin allows you to embed DocumentCloud resources using either the raw URL on its own line: From b73a8d110e05fa49d7e05b4d7f34aac030a24b96 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Aug 2015 13:27:18 -0500 Subject: [PATCH 48/99] Add note about security vulnerability to changelog --- README.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7d61a3c..0c397fd 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog ### 0.3.3 -* Remove unused TinyMCE components +* Remove unused TinyMCE components (resolves CVE-2015-2807 reported by dxw Security: https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/) ### 0.3.2 * Implement a few best practice security measures diff --git a/readme.txt b/readme.txt index 052d34d..a9acbf0 100644 --- a/readme.txt +++ b/readme.txt @@ -76,7 +76,7 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == = 0.3.3 = -* Remove unused TinyMCE components +* Remove unused TinyMCE components (resolves CVE-2015-2807 reported by dxw Security: https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/) = 0.3.2 = * Implement a few best practice security measures From ae040a8fe377bdd0a2d464903895ee6f07637170 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Aug 2015 13:38:32 -0500 Subject: [PATCH 49/99] Tweak changelog style to unbreak link WordPress's readme text parser included the closing paren in the link HREF. Gah. --- README.md | 3 ++- readme.txt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0c397fd..8eb745a 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,8 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog ### 0.3.3 -* Remove unused TinyMCE components (resolves CVE-2015-2807 reported by dxw Security: https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/) +* Remove unused TinyMCE components +* Resolve CVE-2015-2807 reported by dxw Security at https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/ ### 0.3.2 * Implement a few best practice security measures diff --git a/readme.txt b/readme.txt index a9acbf0..27e4427 100644 --- a/readme.txt +++ b/readme.txt @@ -76,7 +76,8 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == = 0.3.3 = -* Remove unused TinyMCE components (resolves CVE-2015-2807 reported by dxw Security: https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/) +* Remove unused TinyMCE components +* Resolve CVE-2015-2807 reported by dxw Security at https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/ = 0.3.2 = * Implement a few best practice security measures From 9c88628c087ef9e6be500bf98fe53182e22e9136 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Fri, 11 Sep 2015 15:06:10 -0500 Subject: [PATCH 50/99] Add logo --- README.md | 3 +++ assets/icon-128x128.png | Bin 0 -> 3912 bytes assets/icon-256x256.png | Bin 0 -> 6833 bytes readme.txt | 3 +++ 4 files changed, 6 insertions(+) create mode 100644 assets/icon-128x128.png create mode 100644 assets/icon-256x256.png diff --git a/README.md b/README.md index 8eb745a..58fe47d 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,9 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog +### 0.3.4 +* Add DocumentCloud logo for plugin (#26) + ### 0.3.3 * Remove unused TinyMCE components * Resolve CVE-2015-2807 reported by dxw Security at https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/ diff --git a/assets/icon-128x128.png b/assets/icon-128x128.png new file mode 100644 index 0000000000000000000000000000000000000000..84979055b2eb3862122a0fbe0ab35c5ccb06a8fd GIT binary patch literal 3912 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 literal 0 HcmV?d00001 diff --git a/assets/icon-256x256.png b/assets/icon-256x256.png new file mode 100644 index 0000000000000000000000000000000000000000..37352a6c85ed23588089b89a02f62b4b7f5bd1da GIT binary patch literal 6833 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 literal 0 HcmV?d00001 diff --git a/readme.txt b/readme.txt index 27e4427..80543ba 100644 --- a/readme.txt +++ b/readme.txt @@ -75,6 +75,9 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == += 0.3.4 = +* Add DocumentCloud logo for plugin (#26) + = 0.3.3 = * Remove unused TinyMCE components * Resolve CVE-2015-2807 reported by dxw Security at https://security.dxw.com/advisories/publicly-exploitable-xss-in-wordpress-plugin-navis-documentcloud/ From 1f6b791658723d9b7b65536956ad29a949295ea5 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Fri, 11 Sep 2015 15:06:43 -0500 Subject: [PATCH 51/99] Don't trigger PHP notice when checking array key --- README.md | 1 + documentcloud.php | 2 +- readme.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 58fe47d..85e0329 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog ### 0.3.4 +* Check for existence of `note_id` without triggering PHP notice (#27) * Add DocumentCloud logo for plugin (#26) ### 0.3.3 diff --git a/documentcloud.php b/documentcloud.php index 41eaff0..d8d4293 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -232,7 +232,7 @@ function clean_dc_url($url) { $elements = $this->parse_dc_url($url); if ($elements['document_slug']) { $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}" . - ($elements['note_id'] ? "/annotations/{$elements['note_id']}" : '') . '.html'; + (isset($elements['note_id']) ? "/annotations/{$elements['note_id']}" : '') . '.html'; } return $url; } diff --git a/readme.txt b/readme.txt index 80543ba..8d7e4c7 100644 --- a/readme.txt +++ b/readme.txt @@ -76,6 +76,7 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == = 0.3.4 = +* Check for existence of `note_id` without triggering PHP notice (#27) * Add DocumentCloud logo for plugin (#26) = 0.3.3 = From 5dee6aa547e492c1b83e83d51961a0e19485d619 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Fri, 11 Sep 2015 15:08:23 -0500 Subject: [PATCH 52/99] Bump version number Should do this *before* starting to commit to it, but oh well. --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index d8d4293..d5b7ec0 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -3,7 +3,7 @@ * Plugin Name: DocumentCloud * Plugin URI: https://www.documentcloud.org/ * Description: Embed DocumentCloud resources in WordPress content. - * Version: 0.3.3 + * Version: 0.3.4 * Authors: Chris Amico, Justin Reese * License: GPLv2 ***/ From 27bed0abff7c4fd9a78b3b58f5fe465f60482fd9 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Mon, 23 Nov 2015 11:11:38 -0600 Subject: [PATCH 53/99] Add note that v0.3.4 is still in development --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 85e0329..68fc701 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog -### 0.3.4 +### 0.3.4 (IN DEVELOPMENT) * Check for existence of `note_id` without triggering PHP notice (#27) * Add DocumentCloud logo for plugin (#26) From e26dccae6ab6b4ebbf507268cca98c9201b852ac Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Tue, 24 Nov 2015 13:57:10 -0600 Subject: [PATCH 54/99] Detail oEmbed discoverability in README/comments --- README.md | 4 ++++ documentcloud.php | 3 +++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index 68fc701..99de889 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,10 @@ Here's the full list of embed options you can pass via shortcode attributes; som You can read more about publishing and embedding DocumentCloud resources on https://www.documentcloud.org/help/publishing. +## How the oEmbed endpoint is discovered + +To make a resource [discoverable](http://oembed.com/#section4) by oEmbed consumers, you can include a `` tag that specifies the oEmbed endpoint URL. So in one version of reality, once you tell WordPress "this resource is oEmbeddable", WordPress would cURL the resource URL, look for the oEmbed link tag in its header, pluck out the oEmbed endpoint from the `` tag's `href`, and then hit that endpoint for the embed code. In our actual reality, that's considered a waste of a cURL, so we have to actually describe the format of our oEmbed endpoint within WordPress itself. + ## Caching Ideally, when WordPress hits our oEmbed service to fetch the embed code, it would obey the `cache_age` we return. Despite [conversation](https://core.trac.wordpress.org/ticket/14759) around this, it doesn't seem to. diff --git a/documentcloud.php b/documentcloud.php index d5b7ec0..e9ae2a1 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -66,6 +66,9 @@ function dc_conflict_admin_notice() { Date: Tue, 24 Nov 2015 13:57:51 -0600 Subject: [PATCH 55/99] Add note that v0.3.4 is still in development --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 8d7e4c7..5ffd4cd 100644 --- a/readme.txt +++ b/readme.txt @@ -75,7 +75,7 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == -= 0.3.4 = += 0.3.4 (IN DEVELOPMENT) = * Check for existence of `note_id` without triggering PHP notice (#27) * Add DocumentCloud logo for plugin (#26) From d3ea846eb970d8549b1b4b52b7b830ab1ec678c3 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Mon, 7 Dec 2015 14:53:16 -0600 Subject: [PATCH 56/99] Support page embed Affects #28 --- documentcloud.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index e9ae2a1..1883453 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -215,6 +215,9 @@ function parse_dc_url($url) { $patterns = array( // Document '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\.html$}', + // Pages and page variants + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document/p(?P[0-9]+)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . 'pages/(?P[0-9]+)\.(html|js)$}', // Notes and note variants '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '/annotations/(?P[0-9]+)\.(html|js)$}', '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document/p([0-9]+)/a(?P[0-9]+)$}', @@ -234,8 +237,14 @@ function parse_dc_url($url) { function clean_dc_url($url) { $elements = $this->parse_dc_url($url); if ($elements['document_slug']) { - $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}" . - (isset($elements['note_id']) ? "/annotations/{$elements['note_id']}" : '') . '.html'; + $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}"; + if (isset($elements['page_number']) { + $url .= "/pages/{$elements['page_number']}"; + } + else if (isset($elements['note_id']) { + $url .= "/annotations/{$elements['note_id']}"; + } + $url .= '.html'; } return $url; } @@ -327,8 +336,11 @@ function save($post_id) { if (isset($atts['url'])) { $elements = $this->parse_dc_url($atts['url']); $meta_key = $elements['document_slug']; - if ($elements['note_id']) { - $meta_key .= "-{$elements['note_id']}"; + if ($elements['page_number']) { + $meta_key .= "-p{$elements['page_number']}"; + } + else if ($elements['note_id']) { + $meta_key .= "-a{$elements['note_id']}"; } } else if (isset($atts['id'])) { $meta_key = $atts['id']; From 14b816012676b911b7a20a98262a47c83d41e580 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Mon, 7 Dec 2015 15:02:57 -0600 Subject: [PATCH 57/99] Update READMEs with page embed info --- README.md | 11 ++++++++--- readme.txt | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 99de889..5cb4623 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The DocumentCloud WordPress plugin lets you embed [DocumentCloud](https://www.do 1. Upload the contents of the plugin to `wp-content/plugins/documentcloud` 2. Activate the plugin through the "Plugins" menu -3. In your posts, embed documents or notes using the DocumentCloud button or the `[documentcloud]` shortcode +3. In your posts, embed documents, pages, or notes using the DocumentCloud button or the `[documentcloud]` shortcode 4. Optional: Set a default width/height for all DocumentCloud embeds (which can be overridden on a per-embed basis with the `height/width` attributes) at Settings > DocumentCloud. (This default width will only be used if you set `responsive="false"` on an embed.) **Upgrading from Navis DocumentCloud:** If you're currently using the Navis DocumentCloud plugin (from which this plugin was built), you'll want to deactivate or delete it before installing this plugin. @@ -37,13 +37,17 @@ You can set your own defaults in Settings > DocumentCloud, but default widths wi [documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html" responsive="false"] -To embed a note, just use any note-specific URL. Notes ignore `width/height` and always act responsively: +To embed a single page, use any page-specific URL. Pages ignore `width/height` and always act responsively: + + [documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html#document/p1"] + +To embed a note, use any note-specific URL. Notes ignore `width/height` and always act responsively: [documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html#document/p1/a53674"] Here's the full list of embed options you can pass via shortcode attributes; some are specific to the type of resource you're embedding. -### All resources (documents and notes): +### All resources: - `url` (**required**, string): Full URL of the DocumentCloud resource. - `container` (string): ID of element to insert the embed into; if excluded, embedder will create its own container. @@ -84,6 +88,7 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog ### 0.3.4 (IN DEVELOPMENT) +* Support embedding pages (#28) * Check for existence of `note_id` without triggering PHP notice (#27) * Add DocumentCloud logo for plugin (#26) diff --git a/readme.txt b/readme.txt index 5ffd4cd..dc8fd0e 100644 --- a/readme.txt +++ b/readme.txt @@ -35,13 +35,17 @@ You can set your own defaults in Settings > DocumentCloud, but default widths wi [documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html" responsive="false"] -To embed a note, just use any note-specific URL. Notes ignore `width/height` and always act responsively: +To embed a single page, use any page-specific URL. Pages ignore `width/height` and always act responsively: + + [documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html#document/p1"] + +To embed a note, use any note-specific URL. Notes ignore `width/height` and always act responsively: [documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html#document/p1/a53674"] Here's the full list of embed options you can pass via shortcode attributes; some are specific to the type of resource you're embedding. -**All resources (documents and notes):** +**All resources:** - `url` (**required**, string): Full URL of the DocumentCloud resource. - `container` (string): ID of element to insert the embed into; if excluded, embedder will create its own container. @@ -68,7 +72,7 @@ You can read more about publishing and embedding DocumentCloud resources on http 1. Upload the contents of the plugin to `wp-content/plugins/documentcloud` 2. Activate the plugin through the "Plugins" menu -3. In your posts, embed documents or notes using the DocumentCloud button or the `[documentcloud]` shortcode +3. In your posts, embed documents, pages, or notes using the DocumentCloud button or the `[documentcloud]` shortcode 4. Optional: Set a default width/height for all DocumentCloud embeds (which can be overridden on a per-embed basis with the `height/width` attributes) at Settings > DocumentCloud. (This default width will only be used if you set `responsive="false"` on an embed.) **Upgrading from Navis DocumentCloud:** If you're currently using the Navis DocumentCloud plugin (from which this plugin was built), you'll want to deactivate or delete it before installing this plugin. @@ -76,6 +80,7 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == = 0.3.4 (IN DEVELOPMENT) = +* Support embedding pages (#28) * Check for existence of `note_id` without triggering PHP notice (#27) * Add DocumentCloud logo for plugin (#26) From 89576f5c38d52127254405fa51132f81fe8c7f6f Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Mon, 7 Dec 2015 16:49:31 -0600 Subject: [PATCH 58/99] Fix syntax error --- documentcloud.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index 1883453..70722eb 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -238,10 +238,10 @@ function clean_dc_url($url) { $elements = $this->parse_dc_url($url); if ($elements['document_slug']) { $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}"; - if (isset($elements['page_number']) { + if (isset($elements['page_number'])) { $url .= "/pages/{$elements['page_number']}"; } - else if (isset($elements['note_id']) { + else if (isset($elements['note_id'])) { $url .= "/annotations/{$elements['note_id']}"; } $url .= '.html'; From ac2b5133c306c4f2f25b72e9e6ecc9d3d05b8161 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 9 Dec 2015 18:03:39 -0600 Subject: [PATCH 59/99] Reduce notices with existence checks --- documentcloud.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index 70722eb..be54ec2 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -236,7 +236,7 @@ function parse_dc_url($url) { function clean_dc_url($url) { $elements = $this->parse_dc_url($url); - if ($elements['document_slug']) { + if (isset($elements['document_slug'])) { $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}"; if (isset($elements['page_number'])) { $url .= "/pages/{$elements['page_number']}"; @@ -335,19 +335,21 @@ function save($post_id) { // get a doc id to keep array keys consistent if (isset($atts['url'])) { $elements = $this->parse_dc_url($atts['url']); - $meta_key = $elements['document_slug']; - if ($elements['page_number']) { - $meta_key .= "-p{$elements['page_number']}"; - } - else if ($elements['note_id']) { - $meta_key .= "-a{$elements['note_id']}"; + if (isset($elements['document_slug'])) { + $meta_key = $elements['document_slug']; + if (isset($elements['page_number'])) { + $meta_key .= "-p{$elements['page_number']}"; + } + else if (isset($elements['note_id'])) { + $meta_key .= "-a{$elements['note_id']}"; + } } } else if (isset($atts['id'])) { $meta_key = $atts['id']; } // if no id, don't bother storing because it's wrong - if ($meta_key) { + if (isset($meta_key)) { $width = intval(isset($parsed_atts['width']) ? $parsed_atts['width'] : $atts['maxwidth']); if ($atts['format'] == "wide" || $width > $default_sizes['width']) { $wide_assets[$meta_key] = true; From 40b0c864286afff414fb417207d650a9c73290db Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 9 Dec 2015 18:05:20 -0600 Subject: [PATCH 60/99] Fix patterns for URL recognition --- documentcloud.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index be54ec2..53289df 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -34,7 +34,7 @@ class WP_DocumentCloud { DEFAULT_EMBED_FULL_WIDTH = 940, OEMBED_RESOURCE_DOMAIN = 'www.documentcloud.org', OEMBED_PROVIDER = 'https://www.documentcloud.org/api/oembed.{format}', - DOCUMENT_PATTERN = '^(?Phttps?)://www\.documentcloud\.org/documents/(?P[0-9]+-[a-z0-9-]+)'; + DOCUMENT_PATTERN = '^(?Phttps?)://www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-z0-9-]+)'; function __construct() { @@ -216,12 +216,12 @@ function parse_dc_url($url) { // Document '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\.html$}', // Pages and page variants - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document/p(?P[0-9]+)$}', - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . 'pages/(?P[0-9]+)\.(html|js)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document\/p(?P[0-9]+)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\/pages\/(?P[0-9]+)\.(html|js)$}', // Notes and note variants - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '/annotations/(?P[0-9]+)\.(html|js)$}', - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document/p([0-9]+)/a(?P[0-9]+)$}', - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#annotation/a(?P[0-9]+)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\/annotations\/(?P[0-9]+)\.(html|js)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document\/p([0-9]+)/a(?P[0-9]+)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#annotation\/a(?P[0-9]+)$}', ); $elements = array(); From 7ec8b715320b5dcc3df4e9367ad192a805e9ce02 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 9 Dec 2015 18:06:56 -0600 Subject: [PATCH 61/99] Handle shortcode params that start with `#` Previously, shortcode params that started with `#` (like `container="#foo"`) were borked when `add_query_arg()` mistook `#foo` for a URL fragment (page anchor) and threw it at the end of the URL. --- documentcloud.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/documentcloud.php b/documentcloud.php index 53289df..bff5c69 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -140,6 +140,12 @@ function add_dc_arguments($provider, $url, $args) { // Don't pass these attributes to the provider break; default: + // Without this check, `add_query_arg()` will treat values + // that are actually ID selectors, like `container=#foo`, + // as URL fragments and throw them at the end of the URL. + if (strpos($value, '#') === 0) { + $value = urlencode($value); + } $provider = add_query_arg( $key, $value, $provider ); break; } From 58eb44b8d5a8da974a7eea9f1c4a790fd159beb2 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 9 Dec 2015 18:20:44 -0600 Subject: [PATCH 62/99] Support contextual URLs outside of shortcodes Adds ability to embed pages and notes with this syntax: ``` This is something you should look at: https://www.documentcloud.org/documents/282753-lefler-thesis.html#document/p57 Wasn't that great? ``` Previously, those contextual URLs (using page anchors) could only be used in shortcodes. Using them on their own line would just embed the document viewer. --- documentcloud.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index bff5c69..a75976f 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -41,8 +41,10 @@ function __construct() { add_action('admin_init', array(&$this, 'check_dc_plugin_conflict')); add_action('init', array(&$this, 'register_dc_oembed_provider')); - add_shortcode('documentcloud', array(&$this, 'handle_dc_shortcode')); - add_filter('oembed_fetch_url', array(&$this, 'add_dc_arguments'), 10, 3); + // Only called when `[documentcloud]` shortcode is used + add_shortcode('documentcloud', array(&$this, 'process_dc_shortcode')); + // Called just before oEmbed endpoint is hit + add_filter('oembed_fetch_url', array(&$this, 'prepare_oembed_fetch'), 10, 3); // Setup admin settings add_action('admin_menu', array(&$this, 'add_options_page')); @@ -130,7 +132,8 @@ function get_default_atts() { ); } - function add_dc_arguments($provider, $url, $args) { + function prepare_oembed_fetch($provider, $url, $args) { + // Clean and prepare arguments foreach ($args as $key => $value) { switch ($key) { case 'format': @@ -150,10 +153,16 @@ function add_dc_arguments($provider, $url, $args) { break; } } + + // Some resources (like notes) have multiple possible + // user-facing URLs. We recompose them into a single form. + $url = $this->clean_dc_url($url); + $provider = add_query_arg( 'url', urlencode($url), $provider ); + return $provider; } - function handle_dc_shortcode($atts) { + function process_dc_shortcode($atts) { $default_sizes = $this->get_default_sizes(); $default_atts = $this->get_default_atts(); @@ -172,10 +181,6 @@ function handle_dc_shortcode($atts) { else { $url = $filtered_atts['url'] = "https://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$atts['id']}.html"; } - } else { - // Some resources (like notes) have multiple possible - // user-facing URLs. We recompose them into a single form. - $url = $filtered_atts['url'] = $this->clean_dc_url($atts['url']); } // `height/width` beat `maxheight/maxwidth`; see full precedence list in `get_default_atts()`. @@ -210,9 +215,10 @@ function handle_dc_shortcode($atts) { // This lets WordPress cache the result of the oEmbed call. // Thanks to http://bit.ly/1HykA0U for this pattern. global $wp_embed; + $url = $filtered_atts['url'] = $this->clean_dc_url($atts['url']); return $wp_embed->shortcode($filtered_atts, $url); } else { - return wp_oembed_get($url, $filtered_atts); + return wp_oembed_get($atts['url'], $filtered_atts); } } @@ -237,6 +243,7 @@ function parse_dc_url($url) { break; } } + return $elements; } From 062a8d649ef3f6f55f9da4dd8ec7d091aad26006 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 9 Dec 2015 18:28:47 -0600 Subject: [PATCH 63/99] Tweak document pattern --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index a75976f..0a3eeed 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -34,7 +34,7 @@ class WP_DocumentCloud { DEFAULT_EMBED_FULL_WIDTH = 940, OEMBED_RESOURCE_DOMAIN = 'www.documentcloud.org', OEMBED_PROVIDER = 'https://www.documentcloud.org/api/oembed.{format}', - DOCUMENT_PATTERN = '^(?Phttps?)://www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-z0-9-]+)'; + DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-z0-9-]+)'; function __construct() { From c23fa28fa6ca0d93b0da6c7f1f04917aa05cb657 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 9 Dec 2015 18:29:19 -0600 Subject: [PATCH 64/99] Update README and bump version number to 0.4.0 --- README.md | 7 +++++-- documentcloud.php | 2 +- readme.txt | 7 +++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 5cb4623..7bd7110 100644 --- a/README.md +++ b/README.md @@ -87,10 +87,13 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog -### 0.3.4 (IN DEVELOPMENT) +### 0.4.0 * Support embedding pages (#28) -* Check for existence of `note_id` without triggering PHP notice (#27) +* Support embedding raw contextual page/note URLs (#29) +* Check for existence of things to stop triggering PHP notices (#27) * Add DocumentCloud logo for plugin (#26) +* Fix ability to specificy a container in the shortcode +* Improve embeddable resource pattern recognition ### 0.3.3 * Remove unused TinyMCE components diff --git a/documentcloud.php b/documentcloud.php index 0a3eeed..9d391a1 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -3,7 +3,7 @@ * Plugin Name: DocumentCloud * Plugin URI: https://www.documentcloud.org/ * Description: Embed DocumentCloud resources in WordPress content. - * Version: 0.3.4 + * Version: 0.4.0 * Authors: Chris Amico, Justin Reese * License: GPLv2 ***/ diff --git a/readme.txt b/readme.txt index dc8fd0e..f000d4e 100644 --- a/readme.txt +++ b/readme.txt @@ -79,10 +79,13 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == -= 0.3.4 (IN DEVELOPMENT) = += 0.4.0 = * Support embedding pages (#28) -* Check for existence of `note_id` without triggering PHP notice (#27) +* Support embedding raw contextual page/note URLs (#29) +* Check for existence of things to stop triggering PHP notices (#27) * Add DocumentCloud logo for plugin (#26) +* Fix ability to specificy a container in the shortcode +* Improve embeddable resource pattern recognition = 0.3.3 = * Remove unused TinyMCE components From b0420007a3c70f2ebc78defb775f3550a8e43ec1 Mon Sep 17 00:00:00 2001 From: anthonydb Date: Wed, 9 Dec 2015 23:17:36 -0500 Subject: [PATCH 65/99] Pedantry. --- README.md | 6 +++--- readme.txt | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7bd7110..53b2f07 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ The DocumentCloud WordPress plugin lets you embed [DocumentCloud](https://www.do This plugin allows you to embed DocumentCloud resources using either the raw URL on its own line: Here's something you should really take a look at: - + https://www.documentcloud.org/documents/282753-lefler-thesis.html - + Isn't that interesting? Or a custom shortcode: @@ -92,7 +92,7 @@ If you find yourself absolutely needing to expire the cache, though, you have tw * Support embedding raw contextual page/note URLs (#29) * Check for existence of things to stop triggering PHP notices (#27) * Add DocumentCloud logo for plugin (#26) -* Fix ability to specificy a container in the shortcode +* Fix ability to specify a container in the shortcode * Improve embeddable resource pattern recognition ### 0.3.3 diff --git a/readme.txt b/readme.txt index f000d4e..b4ae07d 100644 --- a/readme.txt +++ b/readme.txt @@ -16,9 +16,9 @@ Embed DocumentCloud resources in WordPress content. This plugin allows you to embed DocumentCloud resources using either the raw URL on its own line: Here's something you should really take a look at: - + https://www.documentcloud.org/documents/282753-lefler-thesis.html - + Isn't that interesting? Or a custom shortcode: @@ -84,7 +84,7 @@ You can read more about publishing and embedding DocumentCloud resources on http * Support embedding raw contextual page/note URLs (#29) * Check for existence of things to stop triggering PHP notices (#27) * Add DocumentCloud logo for plugin (#26) -* Fix ability to specificy a container in the shortcode +* Fix ability to specify a container in the shortcode * Improve embeddable resource pattern recognition = 0.3.3 = From 6e728746b372725caf56c37267fc1765e969b1b0 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 10 Dec 2015 11:03:17 -0600 Subject: [PATCH 66/99] Show that we tested up to 4.4 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index b4ae07d..141f5b4 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: chrisamico, reefdog Tags: documentcloud, documents, journalism, reporting, research Requires at least: 3.2 -Tested up to: 4.3 +Tested up to: 4.4 Stable tag: trunk License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html From 7e054402c1abaac39c7d74c5253fd1b5de659e9a Mon Sep 17 00:00:00 2001 From: bcampeau Date: Mon, 15 Feb 2016 17:55:09 -0500 Subject: [PATCH 67/99] Updated plugin source for VIP compatibility. Fixed comments, escaping, translation and code formatting. Incremented plugin version. --- documentcloud.php | 405 ++++++++++++++++++++++++++++------------------ 1 file changed, 251 insertions(+), 154 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index 9d391a1..c44baea 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -3,7 +3,7 @@ * Plugin Name: DocumentCloud * Plugin URI: https://www.documentcloud.org/ * Description: Embed DocumentCloud resources in WordPress content. - * Version: 0.4.0 + * Version: 0.4.1 * Authors: Chris Amico, Justin Reese * License: GPLv2 ***/ @@ -12,7 +12,7 @@ Copyright 2015 DocumentCloud, Investigative Reporters & Editors This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2, as + it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, @@ -25,73 +25,104 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -// Die if this isn't being called from within WordPress. -defined( 'ABSPATH' ) or die(); - class WP_DocumentCloud { + // Plugin constants const CACHING_ENABLED = true, DEFAULT_EMBED_FULL_WIDTH = 940, OEMBED_RESOURCE_DOMAIN = 'www.documentcloud.org', OEMBED_PROVIDER = 'https://www.documentcloud.org/api/oembed.{format}', DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-z0-9-]+)'; - + /** + * Constructor. + */ function __construct() { + // Check for conflicts with other Documentcloud plugins. + // Not needed on WordPress VIP since no other Documentcloud plugins exist. + if ( ! defined( 'WPCOM_IS_VIP_ENV' ) || ! WPCOM_IS_VIP_ENV ) { + add_action( 'admin_init', array( $this, 'check_dc_plugin_conflict') ); + add_action( 'init', array( $this, 'register_dc_oembed_provider' ) ); + } - add_action('admin_init', array(&$this, 'check_dc_plugin_conflict')); + // Set the textdomain for the plugin so it is translation compatible + add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) ); - add_action('init', array(&$this, 'register_dc_oembed_provider')); // Only called when `[documentcloud]` shortcode is used - add_shortcode('documentcloud', array(&$this, 'process_dc_shortcode')); + add_shortcode( 'documentcloud', array( $this, 'process_dc_shortcode' ) ); + // Called just before oEmbed endpoint is hit - add_filter('oembed_fetch_url', array(&$this, 'prepare_oembed_fetch'), 10, 3); + add_filter( 'oembed_fetch_url', array( $this, 'prepare_oembed_fetch' ), 10, 3 ); - // Setup admin settings - add_action('admin_menu', array(&$this, 'add_options_page')); - add_action('admin_init', array(&$this, 'settings_init')); + // Setup the settings page + add_action( 'admin_menu', array( $this, 'add_options_page' ) ); + add_action( 'admin_init', array( $this, 'settings_init' ) ); - // Store metadata upon post save - add_action('save_post', array(&$this, 'save')); + // Store Documentcloud metadata upon post save + add_action( 'save_post', array( $this, 'save' ), 10, 2 ); } - + + /** + * Load plugin textdomain. + */ + function load_plugin_textdomain() { + load_plugin_textdomain( 'documentcloud' ); + } + + /** + * Check for conflicts with the Navis Documentcloud plugin. + */ function check_dc_plugin_conflict() { - if (is_plugin_active('navis-documentcloud/navis-documentcloud.php')) { - add_action( 'admin_notices', array(&$this, 'dc_conflict_admin_notice')); + if ( is_plugin_active( 'navis-documentcloud/navis-documentcloud.php' ) ) { + add_action( 'admin_notices', array( $this, 'dc_conflict_admin_notice' ) ); } } + /** + * Create an admin notice when conflicts exist with Navis Documentcloud. + */ function dc_conflict_admin_notice() { ?>
-

Warning! You have two conflicting DocumentCloud plugins activated. Please deactivate Navis DocumentCloud, which has been replaced by DocumentCloud.', 'documentcloud-plugin-conflict' ); ?>

+

Warning! You have two conflicting DocumentCloud plugins activated. Please deactivate Navis DocumentCloud, which has been replaced by DocumentCloud.', 'documentcloud' ) ); ?>

$height, @@ -100,7 +131,11 @@ function get_default_sizes() { ); } - // TODO: Add admin options to adjust all defaults. + /** + * Get the attribute defaults for the shortcode. + * + * @return array + */ function get_default_atts() { $default_sizes = $this->get_default_sizes(); @@ -114,7 +149,7 @@ function get_default_atts() { 'zoom' => null, 'search' => null, 'responsive' => 'true', - // The following defaults match the existing plugin, except + // The following defaults match the existing plugin, except // `height/width` are prefixed `max*` per the oEmbed spec. // You can still use `height/width` for backwards // compatibility, but they'll be mapped to `max*`. @@ -132,10 +167,18 @@ function get_default_atts() { ); } - function prepare_oembed_fetch($provider, $url, $args) { + /** + * Prepare the oEmbed fetch URL. + * + * @param string $provider + * @param string $url + * @param array $args + * @return string + */ + function prepare_oembed_fetch( $provider, $url, $args ) { // Clean and prepare arguments - foreach ($args as $key => $value) { - switch ($key) { + foreach ( $args as $key => $value ) { + switch ( $key ) { case 'format': case 'height': case 'width': @@ -143,11 +186,11 @@ function prepare_oembed_fetch($provider, $url, $args) { // Don't pass these attributes to the provider break; default: - // Without this check, `add_query_arg()` will treat values - // that are actually ID selectors, like `container=#foo`, + // Without this check, `add_query_arg()` will treat values + // that are actually ID selectors, like `container=#foo`, // as URL fragments and throw them at the end of the URL. - if (strpos($value, '#') === 0) { - $value = urlencode($value); + if ( 0 === strpos( $value, '#' ) ) { + $value = urlencode( $value ); } $provider = add_query_arg( $key, $value, $provider ); break; @@ -156,26 +199,32 @@ function prepare_oembed_fetch($provider, $url, $args) { // Some resources (like notes) have multiple possible // user-facing URLs. We recompose them into a single form. - $url = $this->clean_dc_url($url); - $provider = add_query_arg( 'url', urlencode($url), $provider ); + $url = $this->clean_dc_url( $url ); + $provider = add_query_arg( 'url', urlencode( $url ), $provider ); return $provider; } - function process_dc_shortcode($atts) { + /** + * Create the Documentcloud embed output from the shortcode. + * + * @param array $atts + * @return string + */ + function process_dc_shortcode( $atts ) { $default_sizes = $this->get_default_sizes(); $default_atts = $this->get_default_atts(); // Smooshes together passed-in shortcode attrs with defaults // and filters to only those we accept. - $filtered_atts = shortcode_atts($default_atts, $atts); + $filtered_atts = shortcode_atts( $default_atts, $atts ); - // Either the `url` or `id` attributes are required, but `id` + // Either the `url` or `id` attributes are required, but `id` // is only supported for backwards compatibility. If it's used, - // we force this to embed a document. I.e., `id` can't be used + // we force this to embed a document. I.e., `id` can't be used // for embedding notes, pages, or other non-document resources. - if (!$atts['url']) { - if (!$atts['id']) { + if ( empty( $atts['url'] ) ) { + if ( empty( $atts['id'] ) ) { return ''; } else { @@ -184,46 +233,52 @@ function process_dc_shortcode($atts) { } // `height/width` beat `maxheight/maxwidth`; see full precedence list in `get_default_atts()`. - if (isset($atts['height'])) { + if ( isset( $atts['height'] ) ) { $filtered_atts['maxheight'] = $atts['height']; } - if (isset($atts['width'])) { + if ( isset( $atts['width'] ) ) { $filtered_atts['maxwidth'] = $atts['width']; } - - // `responsive` defaults true, but our responsive layout - // ignores width declarations. If a user indicates a width and - // hasn't otherwise specifically indicated `responsive='true'`, - // it's safe to assume they expect us to respect the width, so + + // `responsive` defaults true, but our responsive layout + // ignores width declarations. If a user indicates a width and + // hasn't otherwise specifically indicated `responsive='true'`, + // it's safe to assume they expect us to respect the width, so // we disable the responsive flag. - if ((isset($atts['width']) || isset($atts['maxwidth'])) && (string) $atts['responsive'] != 'true') { + if ( ( isset( $atts['width'] ) || isset( $atts['maxwidth'] ) ) && 'true' !== $atts['responsive'] ) { $filtered_atts['responsive'] = 'false'; } - // If the format is set to wide, it blows away all other width + // If the format is set to wide, it blows away all other width // settings. - if ($filtered_atts['format'] == 'wide') { + if ( 'wide' == $filtered_atts['format'] ) { $filtered_atts['maxwidth'] = $default_sizes['full_width']; } - - // For the benefit of some templates, notify template that + + // For the benefit of some templates, notify template that // we're requesting an asset wider than the default size. global $post; - $is_wide = intval($filtered_atts['maxwidth']) > $default_sizes['width']; + $is_wide = intval( $filtered_atts['maxwidth'] ) > $default_sizes['width']; - if (WP_DocumentCloud::CACHING_ENABLED) { + if ( apply_filters( 'documentcloud_caching_enabled', WP_DocumentCloud::CACHING_ENABLED ) ) { // This lets WordPress cache the result of the oEmbed call. // Thanks to http://bit.ly/1HykA0U for this pattern. global $wp_embed; - $url = $filtered_atts['url'] = $this->clean_dc_url($atts['url']); - return $wp_embed->shortcode($filtered_atts, $url); + $url = $filtered_atts['url'] = $this->clean_dc_url( $atts['url'] ); + return $wp_embed->shortcode( $filtered_atts, $url ); } else { - return wp_oembed_get($atts['url'], $filtered_atts); + return wp_oembed_get( $atts['url'], $filtered_atts ); } } - function parse_dc_url($url) { + /** + * Parse the Documentcloud URL into its components. + * + * @param string $url + * @return array + */ + function parse_dc_url( $url ) { $patterns = array( // Document '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\.html$}', @@ -237,9 +292,9 @@ function parse_dc_url($url) { ); $elements = array(); - foreach ($patterns as $pattern) { - $perfect_match = preg_match($pattern, $url, $elements); - if ($perfect_match) { + foreach ( $patterns as $pattern ) { + $perfect_match = preg_match( $pattern, $url, $elements ); + if ( $perfect_match ) { break; } } @@ -247,14 +302,20 @@ function parse_dc_url($url) { return $elements; } - function clean_dc_url($url) { - $elements = $this->parse_dc_url($url); - if (isset($elements['document_slug'])) { + /** + * Clean the Documentcloud URL. + * + * @param string $url + * @return string + */ + function clean_dc_url( $url ) { + $elements = $this->parse_dc_url( $url ); + if ( isset( $elements['document_slug'] ) ) { $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}"; - if (isset($elements['page_number'])) { + if ( isset( $elements['page_number'] ) ) { $url .= "/pages/{$elements['page_number']}"; } - else if (isset($elements['note_id'])) { + else if ( isset( $elements['note_id'] ) ) { $url .= "/annotations/{$elements['note_id']}"; } $url .= '.html'; @@ -262,120 +323,156 @@ function clean_dc_url($url) { return $url; } - // Setup settings for plugin - + /** + * Add the Documentcloud options page. + */ function add_options_page() { - if (current_user_can('manage_options')) { - add_options_page('DocumentCloud', 'DocumentCloud', 'manage_options', - 'documentcloud', array(&$this, 'render_options_page')); + if ( current_user_can( 'manage_options' ) ) { + add_options_page( 'DocumentCloud', 'DocumentCloud', 'manage_options', 'documentcloud', array( $this, 'render_options_page' ) ); } } - - function render_options_page() { ?> -

DocumentCloud Options

+ + /** + * Render the Documentcloud options page. + */ + function render_options_page() { + ?> +

-

Any widths set here will only take effect if you set responsive="false" on an embed.

- - - - -

+

responsive="false" on an embed.', 'documentcloud' ) ) ?>

+ + + + +

get_default_sizes(); - echo ''; + echo ''; } - + + /** + * Render the default width field. + */ function default_width_field() { $default_sizes = $this->get_default_sizes(); - echo ''; + echo ''; } - + + /** + * Render the full width field. + */ function full_width_field() { $default_sizes = $this->get_default_sizes(); - echo ''; + echo ''; } - - function settings_section() {} - - function save($post_id) { - // tell the post if we're carrying a wide load - if (current_user_can('edit_posts')) { - $post = get_post($post_id); - - // avoid autosave - if (!in_array($post->post_status, array( - 'publish', 'draft', 'private', 'future', 'pending' - )) - ) { return; } - + + /** + * Save Documentcloud postmeta required by the shortcode on post save. + * + * @param int $post_id + * @param WP_Post $post + */ + function save( $post_id, $post ) { + // Avoid autosave + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + return; + } + + // Tell the post if we're carrying a wide load + if ( current_user_can( 'edit_posts' ) ) { $default_sizes = $this->get_default_sizes(); $default_atts = $this->get_default_atts(); - $wide_assets = get_post_meta($post_id, 'wide_assets', true); + $wide_assets = get_post_meta( $post_id, 'wide_assets', true ); $matches = array(); - - preg_match_all('/'.get_shortcode_regex().'/', $post->post_content, $matches); + + preg_match_all( '/'.get_shortcode_regex().'/', $post->post_content, $matches ); $tags = $matches[2]; $args = $matches[3]; - foreach($tags as $i => $tag) { - if ($tag == "documentcloud") { - $parsed_atts = shortcode_parse_atts($args[$i]); - $atts = shortcode_atts($default_atts, $parsed_atts); - - // get a doc id to keep array keys consistent - if (isset($atts['url'])) { - $elements = $this->parse_dc_url($atts['url']); - if (isset($elements['document_slug'])) { + foreach( $tags as $i => $tag ) { + if ( 'documentcloud' == $tag ) { + $parsed_atts = shortcode_parse_atts( $args[$i] ); + $atts = shortcode_atts( $default_atts, $parsed_atts ); + + // Get a doc id to keep array keys consistent + if ( isset( $atts['url'] ) ) { + $elements = $this->parse_dc_url( $atts['url'] ); + if ( isset( $elements['document_slug'] ) ) { $meta_key = $elements['document_slug']; - if (isset($elements['page_number'])) { + if ( isset( $elements['page_number'] ) ) { $meta_key .= "-p{$elements['page_number']}"; } - else if (isset($elements['note_id'])) { + else if ( isset( $elements['note_id'] ) ) { $meta_key .= "-a{$elements['note_id']}"; } } - } else if (isset($atts['id'])) { + } else if ( isset( $atts['id'] ) ) { $meta_key = $atts['id']; } - - // if no id, don't bother storing because it's wrong - if (isset($meta_key)) { - $width = intval(isset($parsed_atts['width']) ? $parsed_atts['width'] : $atts['maxwidth']); - if ($atts['format'] == "wide" || $width > $default_sizes['width']) { - $wide_assets[$meta_key] = true; + + // If no id, don't bother storing because it's wrong + if ( isset( $meta_key ) ) { + $width = intval( isset( $parsed_atts['width'] ) ? $parsed_atts['width'] : $atts['maxwidth'] ); + if ( 'wide' == $atts['format'] || $width > $default_sizes['width'] ) { + $wide_assets[ $meta_key ] = true; } else { - $wide_assets[$meta_key] = false; + $wide_assets[ $meta_key ] = false; } } } } - update_post_meta($post_id, 'wide_assets', $wide_assets); + update_post_meta( $post_id, 'wide_assets', $wide_assets ); } } - + } new WP_DocumentCloud; From c6230298e764eaa809f0f664b6e9547a22f7ae90 Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:33:02 -0500 Subject: [PATCH 68/99] Adjusted capitalization of DocumentCloud --- documentcloud.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index c44baea..3059899 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -37,8 +37,8 @@ class WP_DocumentCloud { * Constructor. */ function __construct() { - // Check for conflicts with other Documentcloud plugins. - // Not needed on WordPress VIP since no other Documentcloud plugins exist. + // Check for conflicts with other DocumentCloud plugins. + // Not needed on WordPress VIP since no other DocumentCloud plugins exist. if ( ! defined( 'WPCOM_IS_VIP_ENV' ) || ! WPCOM_IS_VIP_ENV ) { add_action( 'admin_init', array( $this, 'check_dc_plugin_conflict') ); add_action( 'init', array( $this, 'register_dc_oembed_provider' ) ); @@ -57,7 +57,7 @@ function __construct() { add_action( 'admin_menu', array( $this, 'add_options_page' ) ); add_action( 'admin_init', array( $this, 'settings_init' ) ); - // Store Documentcloud metadata upon post save + // Store DocumentCloud metadata upon post save add_action( 'save_post', array( $this, 'save' ), 10, 2 ); } @@ -69,7 +69,7 @@ function load_plugin_textdomain() { } /** - * Check for conflicts with the Navis Documentcloud plugin. + * Check for conflicts with the Navis DocumentCloud plugin. */ function check_dc_plugin_conflict() { if ( is_plugin_active( 'navis-documentcloud/navis-documentcloud.php' ) ) { @@ -78,7 +78,7 @@ function check_dc_plugin_conflict() { } /** - * Create an admin notice when conflicts exist with Navis Documentcloud. + * Create an admin notice when conflicts exist with Navis DocumentCloud. */ function dc_conflict_admin_notice() { ?> @@ -113,7 +113,7 @@ function register_dc_oembed_provider() { } /** - * Get the default sizes for Documentcloud. + * Get the default sizes for DocumentCloud. * * @return array */ @@ -206,7 +206,7 @@ function prepare_oembed_fetch( $provider, $url, $args ) { } /** - * Create the Documentcloud embed output from the shortcode. + * Create the DocumentCloud embed output from the shortcode. * * @param array $atts * @return string @@ -273,7 +273,7 @@ function process_dc_shortcode( $atts ) { } /** - * Parse the Documentcloud URL into its components. + * Parse the DocumentCloud URL into its components. * * @param string $url * @return array @@ -303,7 +303,7 @@ function parse_dc_url( $url ) { } /** - * Clean the Documentcloud URL. + * Clean the DocumentCloud URL. * * @param string $url * @return string @@ -324,7 +324,7 @@ function clean_dc_url( $url ) { } /** - * Add the Documentcloud options page. + * Add the DocumentCloud options page. */ function add_options_page() { if ( current_user_can( 'manage_options' ) ) { @@ -333,7 +333,7 @@ function add_options_page() { } /** - * Render the Documentcloud options page. + * Render the DocumentCloud options page. */ function render_options_page() { ?> @@ -351,7 +351,7 @@ function render_options_page() { } /** - * Initialize settings for the Documentcloud options page. + * Initialize settings for the DocumentCloud options page. */ function settings_init() { if ( current_user_can( 'manage_options' ) ) { @@ -416,7 +416,7 @@ function full_width_field() { } /** - * Save Documentcloud postmeta required by the shortcode on post save. + * Save DocumentCloud postmeta required by the shortcode on post save. * * @param int $post_id * @param WP_Post $post From 18a0349f04dcfedf9503670985b588e3ae7a709d Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:34:06 -0500 Subject: [PATCH 69/99] Updated wp_kses usage --- documentcloud.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index 3059899..b888b73 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -83,7 +83,7 @@ function check_dc_plugin_conflict() { function dc_conflict_admin_notice() { ?>
-

Warning! You have two conflicting DocumentCloud plugins activated. Please deactivate Navis DocumentCloud, which has been replaced by DocumentCloud.', 'documentcloud' ) ); ?>

+

Warning! You have two conflicting DocumentCloud plugins activated. Please deactivate Navis DocumentCloud, which has been replaced by DocumentCloud.', 'documentcloud' ) ); ?>

-

responsive="false" on an embed.', 'documentcloud' ) ) ?>

+

responsive="false" on an embed.', 'documentcloud' ) ) ?>

From fcb03f5879eb4a8598ef868b7f83ac52413236af Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:35:21 -0500 Subject: [PATCH 70/99] Fix indentation --- documentcloud.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index b888b73..b6e4d3d 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -356,10 +356,10 @@ function render_options_page() { function settings_init() { if ( current_user_can( 'manage_options' ) ) { add_settings_section( - 'documentcloud', - '', - '__return_null', - 'documentcloud' + 'documentcloud', + '', + '__return_null', + 'documentcloud' ); add_settings_field( From 8512f7212817da327dd8d15136c21fa1284c06f9 Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:35:51 -0500 Subject: [PATCH 71/99] Fix indentation --- documentcloud.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index b6e4d3d..8d45185 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -355,12 +355,12 @@ function render_options_page() { */ function settings_init() { if ( current_user_can( 'manage_options' ) ) { - add_settings_section( + add_settings_section( 'documentcloud', '', '__return_null', 'documentcloud' - ); + ); add_settings_field( 'documentcloud_default_height', From c7cb210148fa9d39a4bfc707f18df2589c79d754 Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:36:42 -0500 Subject: [PATCH 72/99] Fix indentation --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index 8d45185..b8186c5 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -423,7 +423,7 @@ function full_width_field() { */ function save( $post_id, $post ) { // Avoid autosave - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } From eb25b1c05e1ce7f92f259e6231c1bc12e753d44a Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:37:30 -0500 Subject: [PATCH 73/99] Fix indentation --- documentcloud.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index b8186c5..eaa3f96 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -355,12 +355,12 @@ function render_options_page() { */ function settings_init() { if ( current_user_can( 'manage_options' ) ) { - add_settings_section( - 'documentcloud', - '', - '__return_null', - 'documentcloud' - ); + add_settings_section( + 'documentcloud', + '', + '__return_null', + 'documentcloud' + ); add_settings_field( 'documentcloud_default_height', @@ -424,8 +424,8 @@ function full_width_field() { function save( $post_id, $post ) { // Avoid autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { - return; - } + return; + } // Tell the post if we're carrying a wide load if ( current_user_can( 'edit_posts' ) ) { From b02f024ab06bdbb388ede8b853ddbafaab19d9f7 Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:38:25 -0500 Subject: [PATCH 74/99] Fix indentation --- documentcloud.php | 758 +++++++++++++++++++++++----------------------- 1 file changed, 379 insertions(+), 379 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index eaa3f96..12a8109 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -8,58 +8,58 @@ * License: GPLv2 ***/ /* - Copyright 2011 National Public Radio, Inc. - Copyright 2015 DocumentCloud, Investigative Reporters & Editors + Copyright 2011 National Public Radio, Inc. + Copyright 2015 DocumentCloud, Investigative Reporters & Editors - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License, version 2, as - published by the Free Software Foundation. + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License, version 2, as + published by the Free Software Foundation. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class WP_DocumentCloud { // Plugin constants - const CACHING_ENABLED = true, - DEFAULT_EMBED_FULL_WIDTH = 940, - OEMBED_RESOURCE_DOMAIN = 'www.documentcloud.org', - OEMBED_PROVIDER = 'https://www.documentcloud.org/api/oembed.{format}', - DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-z0-9-]+)'; + const CACHING_ENABLED = true, + DEFAULT_EMBED_FULL_WIDTH = 940, + OEMBED_RESOURCE_DOMAIN = 'www.documentcloud.org', + OEMBED_PROVIDER = 'https://www.documentcloud.org/api/oembed.{format}', + DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-z0-9-]+)'; /** * Constructor. */ - function __construct() { + function __construct() { // Check for conflicts with other DocumentCloud plugins. // Not needed on WordPress VIP since no other DocumentCloud plugins exist. if ( ! defined( 'WPCOM_IS_VIP_ENV' ) || ! WPCOM_IS_VIP_ENV ) { add_action( 'admin_init', array( $this, 'check_dc_plugin_conflict') ); - add_action( 'init', array( $this, 'register_dc_oembed_provider' ) ); - } + add_action( 'init', array( $this, 'register_dc_oembed_provider' ) ); + } - // Set the textdomain for the plugin so it is translation compatible + // Set the textdomain for the plugin so it is translation compatible add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) ); - // Only called when `[documentcloud]` shortcode is used - add_shortcode( 'documentcloud', array( $this, 'process_dc_shortcode' ) ); + // Only called when `[documentcloud]` shortcode is used + add_shortcode( 'documentcloud', array( $this, 'process_dc_shortcode' ) ); - // Called just before oEmbed endpoint is hit - add_filter( 'oembed_fetch_url', array( $this, 'prepare_oembed_fetch' ), 10, 3 ); + // Called just before oEmbed endpoint is hit + add_filter( 'oembed_fetch_url', array( $this, 'prepare_oembed_fetch' ), 10, 3 ); - // Setup the settings page - add_action( 'admin_menu', array( $this, 'add_options_page' ) ); - add_action( 'admin_init', array( $this, 'settings_init' ) ); + // Setup the settings page + add_action( 'admin_menu', array( $this, 'add_options_page' ) ); + add_action( 'admin_init', array( $this, 'settings_init' ) ); - // Store DocumentCloud metadata upon post save - add_action( 'save_post', array( $this, 'save' ), 10, 2 ); - } + // Store DocumentCloud metadata upon post save + add_action( 'save_post', array( $this, 'save' ), 10, 2 ); + } /** * Load plugin textdomain. @@ -71,29 +71,29 @@ function load_plugin_textdomain() { /** * Check for conflicts with the Navis DocumentCloud plugin. */ - function check_dc_plugin_conflict() { - if ( is_plugin_active( 'navis-documentcloud/navis-documentcloud.php' ) ) { - add_action( 'admin_notices', array( $this, 'dc_conflict_admin_notice' ) ); - } - } + function check_dc_plugin_conflict() { + if ( is_plugin_active( 'navis-documentcloud/navis-documentcloud.php' ) ) { + add_action( 'admin_notices', array( $this, 'dc_conflict_admin_notice' ) ); + } + } /** * Create an admin notice when conflicts exist with Navis DocumentCloud. */ - function dc_conflict_admin_notice() { - ?> -
-

Warning! You have two conflicting DocumentCloud plugins activated. Please deactivate Navis DocumentCloud, which has been replaced by DocumentCloud.', 'documentcloud' ) ); ?>

-
- +
+

Warning! You have two conflicting DocumentCloud plugins activated. Please deactivate Navis DocumentCloud, which has been replaced by DocumentCloud.', 'documentcloud' ) ); ?>

+
+ $height, - 'width' => $width, - 'full_width' => $full_width, - ); - } - - /** - * Get the attribute defaults for the shortcode. - * - * @return array - */ - function get_default_atts() { - $default_sizes = $this->get_default_sizes(); - - return array( - 'url' => null, - 'container' => null, - 'notes' => null, - 'responsive_offset' => null, - 'default_page' => null, - 'default_note' => null, - 'zoom' => null, - 'search' => null, - 'responsive' => 'true', - // The following defaults match the existing plugin, except - // `height/width` are prefixed `max*` per the oEmbed spec. - // You can still use `height/width` for backwards - // compatibility, but they'll be mapped to `max*`. - // Precedence (lower number == higher priority): - // 1. `width` on shortcode - // 2. `maxwidth` on shortcode - // 3. Settings > DocumentCloud > "Default embed width" - // 4. `wp_embed_defaults()['width']` - 'maxheight' => $default_sizes['height'], - 'maxwidth' => $default_sizes['width'], - 'format' => 'normal', - 'sidebar' => 'false', - 'text' => 'true', - 'pdf' => 'true', - ); - } + function get_default_sizes() { + $wp_embed_defaults = wp_embed_defaults(); + + $height = intval( get_option( 'documentcloud_default_height', $wp_embed_defaults['height'] ) ); + $width = intval( get_option( 'documentcloud_default_width', $wp_embed_defaults['width'] ) ); + $full_width = intval( get_option( 'documentcloud_full_width', WP_DocumentCloud::DEFAULT_EMBED_FULL_WIDTH ) ); + + return array ( + 'height' => $height, + 'width' => $width, + 'full_width' => $full_width, + ); + } + + /** + * Get the attribute defaults for the shortcode. + * + * @return array + */ + function get_default_atts() { + $default_sizes = $this->get_default_sizes(); + + return array( + 'url' => null, + 'container' => null, + 'notes' => null, + 'responsive_offset' => null, + 'default_page' => null, + 'default_note' => null, + 'zoom' => null, + 'search' => null, + 'responsive' => 'true', + // The following defaults match the existing plugin, except + // `height/width` are prefixed `max*` per the oEmbed spec. + // You can still use `height/width` for backwards + // compatibility, but they'll be mapped to `max*`. + // Precedence (lower number == higher priority): + // 1. `width` on shortcode + // 2. `maxwidth` on shortcode + // 3. Settings > DocumentCloud > "Default embed width" + // 4. `wp_embed_defaults()['width']` + 'maxheight' => $default_sizes['height'], + 'maxwidth' => $default_sizes['width'], + 'format' => 'normal', + 'sidebar' => 'false', + 'text' => 'true', + 'pdf' => 'true', + ); + } /** - * Prepare the oEmbed fetch URL. - * - * @param string $provider - * @param string $url - * @param array $args - * @return string - */ - function prepare_oembed_fetch( $provider, $url, $args ) { - // Clean and prepare arguments - foreach ( $args as $key => $value ) { - switch ( $key ) { - case 'format': - case 'height': - case 'width': - case 'discover': - // Don't pass these attributes to the provider - break; - default: - // Without this check, `add_query_arg()` will treat values - // that are actually ID selectors, like `container=#foo`, - // as URL fragments and throw them at the end of the URL. - if ( 0 === strpos( $value, '#' ) ) { - $value = urlencode( $value ); - } - $provider = add_query_arg( $key, $value, $provider ); - break; - } - } - - // Some resources (like notes) have multiple possible - // user-facing URLs. We recompose them into a single form. - $url = $this->clean_dc_url( $url ); - $provider = add_query_arg( 'url', urlencode( $url ), $provider ); - - return $provider; - } + * Prepare the oEmbed fetch URL. + * + * @param string $provider + * @param string $url + * @param array $args + * @return string + */ + function prepare_oembed_fetch( $provider, $url, $args ) { + // Clean and prepare arguments + foreach ( $args as $key => $value ) { + switch ( $key ) { + case 'format': + case 'height': + case 'width': + case 'discover': + // Don't pass these attributes to the provider + break; + default: + // Without this check, `add_query_arg()` will treat values + // that are actually ID selectors, like `container=#foo`, + // as URL fragments and throw them at the end of the URL. + if ( 0 === strpos( $value, '#' ) ) { + $value = urlencode( $value ); + } + $provider = add_query_arg( $key, $value, $provider ); + break; + } + } + + // Some resources (like notes) have multiple possible + // user-facing URLs. We recompose them into a single form. + $url = $this->clean_dc_url( $url ); + $provider = add_query_arg( 'url', urlencode( $url ), $provider ); + + return $provider; + } /** - * Create the DocumentCloud embed output from the shortcode. - * - * @param array $atts - * @return string - */ - function process_dc_shortcode( $atts ) { - $default_sizes = $this->get_default_sizes(); - $default_atts = $this->get_default_atts(); - - // Smooshes together passed-in shortcode attrs with defaults - // and filters to only those we accept. - $filtered_atts = shortcode_atts( $default_atts, $atts ); - - // Either the `url` or `id` attributes are required, but `id` - // is only supported for backwards compatibility. If it's used, - // we force this to embed a document. I.e., `id` can't be used - // for embedding notes, pages, or other non-document resources. - if ( empty( $atts['url'] ) ) { - if ( empty( $atts['id'] ) ) { - return ''; - } - else { - $url = $filtered_atts['url'] = "https://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$atts['id']}.html"; - } - } - - // `height/width` beat `maxheight/maxwidth`; see full precedence list in `get_default_atts()`. - if ( isset( $atts['height'] ) ) { - $filtered_atts['maxheight'] = $atts['height']; - } - if ( isset( $atts['width'] ) ) { - $filtered_atts['maxwidth'] = $atts['width']; - } - - // `responsive` defaults true, but our responsive layout - // ignores width declarations. If a user indicates a width and - // hasn't otherwise specifically indicated `responsive='true'`, - // it's safe to assume they expect us to respect the width, so - // we disable the responsive flag. - if ( ( isset( $atts['width'] ) || isset( $atts['maxwidth'] ) ) && 'true' !== $atts['responsive'] ) { - $filtered_atts['responsive'] = 'false'; - } - - // If the format is set to wide, it blows away all other width - // settings. - if ( 'wide' == $filtered_atts['format'] ) { - $filtered_atts['maxwidth'] = $default_sizes['full_width']; - } - - // For the benefit of some templates, notify template that - // we're requesting an asset wider than the default size. - global $post; - $is_wide = intval( $filtered_atts['maxwidth'] ) > $default_sizes['width']; - - if ( apply_filters( 'documentcloud_caching_enabled', WP_DocumentCloud::CACHING_ENABLED ) ) { - // This lets WordPress cache the result of the oEmbed call. - // Thanks to http://bit.ly/1HykA0U for this pattern. - global $wp_embed; - $url = $filtered_atts['url'] = $this->clean_dc_url( $atts['url'] ); - return $wp_embed->shortcode( $filtered_atts, $url ); - } else { - return wp_oembed_get( $atts['url'], $filtered_atts ); - } - - } + * Create the DocumentCloud embed output from the shortcode. + * + * @param array $atts + * @return string + */ + function process_dc_shortcode( $atts ) { + $default_sizes = $this->get_default_sizes(); + $default_atts = $this->get_default_atts(); + + // Smooshes together passed-in shortcode attrs with defaults + // and filters to only those we accept. + $filtered_atts = shortcode_atts( $default_atts, $atts ); + + // Either the `url` or `id` attributes are required, but `id` + // is only supported for backwards compatibility. If it's used, + // we force this to embed a document. I.e., `id` can't be used + // for embedding notes, pages, or other non-document resources. + if ( empty( $atts['url'] ) ) { + if ( empty( $atts['id'] ) ) { + return ''; + } + else { + $url = $filtered_atts['url'] = "https://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$atts['id']}.html"; + } + } + + // `height/width` beat `maxheight/maxwidth`; see full precedence list in `get_default_atts()`. + if ( isset( $atts['height'] ) ) { + $filtered_atts['maxheight'] = $atts['height']; + } + if ( isset( $atts['width'] ) ) { + $filtered_atts['maxwidth'] = $atts['width']; + } + + // `responsive` defaults true, but our responsive layout + // ignores width declarations. If a user indicates a width and + // hasn't otherwise specifically indicated `responsive='true'`, + // it's safe to assume they expect us to respect the width, so + // we disable the responsive flag. + if ( ( isset( $atts['width'] ) || isset( $atts['maxwidth'] ) ) && 'true' !== $atts['responsive'] ) { + $filtered_atts['responsive'] = 'false'; + } + + // If the format is set to wide, it blows away all other width + // settings. + if ( 'wide' == $filtered_atts['format'] ) { + $filtered_atts['maxwidth'] = $default_sizes['full_width']; + } + + // For the benefit of some templates, notify template that + // we're requesting an asset wider than the default size. + global $post; + $is_wide = intval( $filtered_atts['maxwidth'] ) > $default_sizes['width']; + + if ( apply_filters( 'documentcloud_caching_enabled', WP_DocumentCloud::CACHING_ENABLED ) ) { + // This lets WordPress cache the result of the oEmbed call. + // Thanks to http://bit.ly/1HykA0U for this pattern. + global $wp_embed; + $url = $filtered_atts['url'] = $this->clean_dc_url( $atts['url'] ); + return $wp_embed->shortcode( $filtered_atts, $url ); + } else { + return wp_oembed_get( $atts['url'], $filtered_atts ); + } + + } /** - * Parse the DocumentCloud URL into its components. - * - * @param string $url - * @return array - */ - function parse_dc_url( $url ) { - $patterns = array( - // Document - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\.html$}', - // Pages and page variants - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document\/p(?P[0-9]+)$}', - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\/pages\/(?P[0-9]+)\.(html|js)$}', - // Notes and note variants - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\/annotations\/(?P[0-9]+)\.(html|js)$}', - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document\/p([0-9]+)/a(?P[0-9]+)$}', - '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#annotation\/a(?P[0-9]+)$}', - ); - - $elements = array(); - foreach ( $patterns as $pattern ) { - $perfect_match = preg_match( $pattern, $url, $elements ); - if ( $perfect_match ) { - break; - } - } - - return $elements; - } + * Parse the DocumentCloud URL into its components. + * + * @param string $url + * @return array + */ + function parse_dc_url( $url ) { + $patterns = array( + // Document + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\.html$}', + // Pages and page variants + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document\/p(?P[0-9]+)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\/pages\/(?P[0-9]+)\.(html|js)$}', + // Notes and note variants + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '\/annotations\/(?P[0-9]+)\.(html|js)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#document\/p([0-9]+)/a(?P[0-9]+)$}', + '{' . WP_DocumentCloud::DOCUMENT_PATTERN . '.html#annotation\/a(?P[0-9]+)$}', + ); + + $elements = array(); + foreach ( $patterns as $pattern ) { + $perfect_match = preg_match( $pattern, $url, $elements ); + if ( $perfect_match ) { + break; + } + } + + return $elements; + } /** - * Clean the DocumentCloud URL. - * - * @param string $url - * @return string - */ - function clean_dc_url( $url ) { - $elements = $this->parse_dc_url( $url ); - if ( isset( $elements['document_slug'] ) ) { - $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}"; - if ( isset( $elements['page_number'] ) ) { - $url .= "/pages/{$elements['page_number']}"; - } - else if ( isset( $elements['note_id'] ) ) { - $url .= "/annotations/{$elements['note_id']}"; - } - $url .= '.html'; - } - return $url; - } + * Clean the DocumentCloud URL. + * + * @param string $url + * @return string + */ + function clean_dc_url( $url ) { + $elements = $this->parse_dc_url( $url ); + if ( isset( $elements['document_slug'] ) ) { + $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}"; + if ( isset( $elements['page_number'] ) ) { + $url .= "/pages/{$elements['page_number']}"; + } + else if ( isset( $elements['note_id'] ) ) { + $url .= "/annotations/{$elements['note_id']}"; + } + $url .= '.html'; + } + return $url; + } /** - * Add the DocumentCloud options page. - */ - function add_options_page() { - if ( current_user_can( 'manage_options' ) ) { - add_options_page( 'DocumentCloud', 'DocumentCloud', 'manage_options', 'documentcloud', array( $this, 'render_options_page' ) ); - } - } + * Add the DocumentCloud options page. + */ + function add_options_page() { + if ( current_user_can( 'manage_options' ) ) { + add_options_page( 'DocumentCloud', 'DocumentCloud', 'manage_options', 'documentcloud', array( $this, 'render_options_page' ) ); + } + } /** - * Render the DocumentCloud options page. - */ - function render_options_page() { - ?> -

- + * Render the DocumentCloud options page. + */ + function render_options_page() { + ?> +

+ -

responsive="false" on an embed.', 'documentcloud' ) ) ?>

+

responsive="false" on an embed.', 'documentcloud' ) ) ?>

- - + + -

- -

+ + get_default_sizes(); - echo ''; - } + * Render the default height field. + */ + function default_height_field() { + $default_sizes = $this->get_default_sizes(); + echo ''; + } /** - * Render the default width field. - */ - function default_width_field() { - $default_sizes = $this->get_default_sizes(); - echo ''; - } + * Render the default width field. + */ + function default_width_field() { + $default_sizes = $this->get_default_sizes(); + echo ''; + } /** - * Render the full width field. - */ - function full_width_field() { - $default_sizes = $this->get_default_sizes(); - echo ''; - } + * Render the full width field. + */ + function full_width_field() { + $default_sizes = $this->get_default_sizes(); + echo ''; + } /** - * Save DocumentCloud postmeta required by the shortcode on post save. - * - * @param int $post_id - * @param WP_Post $post - */ - function save( $post_id, $post ) { - // Avoid autosave - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { - return; - } - - // Tell the post if we're carrying a wide load - if ( current_user_can( 'edit_posts' ) ) { - $default_sizes = $this->get_default_sizes(); - $default_atts = $this->get_default_atts(); - $wide_assets = get_post_meta( $post_id, 'wide_assets', true ); - $matches = array(); - - preg_match_all( '/'.get_shortcode_regex().'/', $post->post_content, $matches ); - $tags = $matches[2]; - $args = $matches[3]; - foreach( $tags as $i => $tag ) { - if ( 'documentcloud' == $tag ) { - $parsed_atts = shortcode_parse_atts( $args[$i] ); - $atts = shortcode_atts( $default_atts, $parsed_atts ); - - // Get a doc id to keep array keys consistent - if ( isset( $atts['url'] ) ) { - $elements = $this->parse_dc_url( $atts['url'] ); - if ( isset( $elements['document_slug'] ) ) { - $meta_key = $elements['document_slug']; - if ( isset( $elements['page_number'] ) ) { - $meta_key .= "-p{$elements['page_number']}"; - } - else if ( isset( $elements['note_id'] ) ) { - $meta_key .= "-a{$elements['note_id']}"; - } - } - } else if ( isset( $atts['id'] ) ) { - $meta_key = $atts['id']; - } - - // If no id, don't bother storing because it's wrong - if ( isset( $meta_key ) ) { - $width = intval( isset( $parsed_atts['width'] ) ? $parsed_atts['width'] : $atts['maxwidth'] ); - if ( 'wide' == $atts['format'] || $width > $default_sizes['width'] ) { - $wide_assets[ $meta_key ] = true; - } else { - $wide_assets[ $meta_key ] = false; - } - } - } - } - update_post_meta( $post_id, 'wide_assets', $wide_assets ); - } - } + * Save DocumentCloud postmeta required by the shortcode on post save. + * + * @param int $post_id + * @param WP_Post $post + */ + function save( $post_id, $post ) { + // Avoid autosave + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { + return; + } + + // Tell the post if we're carrying a wide load + if ( current_user_can( 'edit_posts' ) ) { + $default_sizes = $this->get_default_sizes(); + $default_atts = $this->get_default_atts(); + $wide_assets = get_post_meta( $post_id, 'wide_assets', true ); + $matches = array(); + + preg_match_all( '/'.get_shortcode_regex().'/', $post->post_content, $matches ); + $tags = $matches[2]; + $args = $matches[3]; + foreach( $tags as $i => $tag ) { + if ( 'documentcloud' == $tag ) { + $parsed_atts = shortcode_parse_atts( $args[$i] ); + $atts = shortcode_atts( $default_atts, $parsed_atts ); + + // Get a doc id to keep array keys consistent + if ( isset( $atts['url'] ) ) { + $elements = $this->parse_dc_url( $atts['url'] ); + if ( isset( $elements['document_slug'] ) ) { + $meta_key = $elements['document_slug']; + if ( isset( $elements['page_number'] ) ) { + $meta_key .= "-p{$elements['page_number']}"; + } + else if ( isset( $elements['note_id'] ) ) { + $meta_key .= "-a{$elements['note_id']}"; + } + } + } else if ( isset( $atts['id'] ) ) { + $meta_key = $atts['id']; + } + + // If no id, don't bother storing because it's wrong + if ( isset( $meta_key ) ) { + $width = intval( isset( $parsed_atts['width'] ) ? $parsed_atts['width'] : $atts['maxwidth'] ); + if ( 'wide' == $atts['format'] || $width > $default_sizes['width'] ) { + $wide_assets[ $meta_key ] = true; + } else { + $wide_assets[ $meta_key ] = false; + } + } + } + } + update_post_meta( $post_id, 'wide_assets', $wide_assets ); + } + } } From 7ccd21b20b8247a66026314920dc2bda65a19a11 Mon Sep 17 00:00:00 2001 From: bcampeau Date: Wed, 17 Feb 2016 20:39:55 -0500 Subject: [PATCH 75/99] Fix indentation --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index 12a8109..bb7c137 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -362,7 +362,7 @@ function settings_init() { 'documentcloud' ); - add_settings_field( + add_settings_field( 'documentcloud_default_height', __( 'Default embed height (px)', 'documentcloud' ), array( $this, 'default_height_field' ), From b53d2f60a793b9fc07c7a5eabb0aa8973f39fd8f Mon Sep 17 00:00:00 2001 From: bcampeau Date: Mon, 22 Feb 2016 16:35:18 -0500 Subject: [PATCH 76/99] Moved oEmbed registration out of incorrect logic --- documentcloud.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index bb7c137..a2045b6 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -41,9 +41,11 @@ function __construct() { // Not needed on WordPress VIP since no other DocumentCloud plugins exist. if ( ! defined( 'WPCOM_IS_VIP_ENV' ) || ! WPCOM_IS_VIP_ENV ) { add_action( 'admin_init', array( $this, 'check_dc_plugin_conflict') ); - add_action( 'init', array( $this, 'register_dc_oembed_provider' ) ); } + // Register the oEmbed provider + add_action( 'init', array( $this, 'register_dc_oembed_provider' ) ); + // Set the textdomain for the plugin so it is translation compatible add_action( 'plugins_loaded', array( $this, 'load_plugin_textdomain' ) ); From 9f682529eef5aff13350b8990ac7b52e4d14ec09 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 25 Feb 2016 13:59:43 -0600 Subject: [PATCH 77/99] Always send default attributes to oEmbed endpoint Previously, only the shortcode send default attributes to the oEmbed endpoint. Bare URLs (i.e., just putting a document URL on its own line in the post body) didn't. This resolves that inconsistency. --- documentcloud.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index a2045b6..5977cb2 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -178,8 +178,13 @@ function get_default_atts() { * @return string */ function prepare_oembed_fetch( $provider, $url, $args ) { + // Merge actual args with default attributes so that defaults are always + // sent to oEmbed endpoint + $default_atts = $this->get_default_atts(); + $atts = array_merge( $default_atts, $args ); + // Clean and prepare arguments - foreach ( $args as $key => $value ) { + foreach ( $atts as $key => $value ) { switch ( $key ) { case 'format': case 'height': From 183f7023b77fd45078fd28da41ceaf8b6fdc4989 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 25 Feb 2016 14:24:07 -0600 Subject: [PATCH 78/99] Fix some indentation --- documentcloud.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index 5977cb2..e0a8d42 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -124,12 +124,12 @@ function get_default_sizes() { $height = intval( get_option( 'documentcloud_default_height', $wp_embed_defaults['height'] ) ); $width = intval( get_option( 'documentcloud_default_width', $wp_embed_defaults['width'] ) ); - $full_width = intval( get_option( 'documentcloud_full_width', WP_DocumentCloud::DEFAULT_EMBED_FULL_WIDTH ) ); + $full_width = intval( get_option( 'documentcloud_full_width', WP_DocumentCloud::DEFAULT_EMBED_FULL_WIDTH ) ); return array ( - 'height' => $height, - 'width' => $width, - 'full_width' => $full_width, + 'height' => $height, + 'width' => $width, + 'full_width' => $full_width, ); } @@ -145,7 +145,7 @@ function get_default_atts() { 'url' => null, 'container' => null, 'notes' => null, - 'responsive_offset' => null, + 'responsive_offset' => null, 'default_page' => null, 'default_note' => null, 'zoom' => null, From 4de1d222b4ce517b71083a8d4c62a5c3401760f3 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 25 Feb 2016 16:09:27 -0600 Subject: [PATCH 79/99] Recognize resources with uppercase doc slugs Fixes #36 --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index e0a8d42..f41bfa2 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -32,7 +32,7 @@ class WP_DocumentCloud { DEFAULT_EMBED_FULL_WIDTH = 940, OEMBED_RESOURCE_DOMAIN = 'www.documentcloud.org', OEMBED_PROVIDER = 'https://www.documentcloud.org/api/oembed.{format}', - DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-z0-9-]+)'; + DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-zA-Z0-9-]+)'; /** * Constructor. */ From 0694811ff6103a7ff5271995d1b8e31bf86826ac Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 25 Feb 2016 16:14:07 -0600 Subject: [PATCH 80/99] Add v0.4.1 items to changelog --- README.md | 5 +++++ readme.txt | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 53b2f07..4d7490a 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,11 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog +### 0.4.1 +* Conform syntax to WordPress VIP plugin requirements (#30) (@bcampeau) +* Fixed: Bare URLs now get default parameters (#35) +* Fixed: Pages/notes on docs with uppercase slugs now embeddable (#36) + ### 0.4.0 * Support embedding pages (#28) * Support embedding raw contextual page/note URLs (#29) diff --git a/readme.txt b/readme.txt index 141f5b4..e24d22a 100644 --- a/readme.txt +++ b/readme.txt @@ -79,6 +79,11 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == += 0.4.1 = +* Conform syntax to WordPress VIP plugin requirements (#30) (@bcampeau) +* Fixed: Bare URLs now get default parameters (#35) +* Fixed: Pages/notes on docs with uppercase slugs now embeddable (#36) + = 0.4.0 = * Support embedding pages (#28) * Support embedding raw contextual page/note URLs (#29) From acb4bf9dc3f8f4aeb22a5fe30028aa3059762b5f Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 25 Feb 2016 17:42:53 -0600 Subject: [PATCH 81/99] Bump version to 0.4.2 --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index f41bfa2..82abbb9 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -3,7 +3,7 @@ * Plugin Name: DocumentCloud * Plugin URI: https://www.documentcloud.org/ * Description: Embed DocumentCloud resources in WordPress content. - * Version: 0.4.1 + * Version: 0.4.2 * Authors: Chris Amico, Justin Reese * License: GPLv2 ***/ From 54a6e7166f11442b573e55aaaa2eb23145353869 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 25 Feb 2016 17:43:14 -0600 Subject: [PATCH 82/99] Recognize full Unicode alphanumerics in doc slugs Fixes #37 --- README.md | 3 +++ documentcloud.php | 2 +- readme.txt | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4d7490a..8e325bf 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,9 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog +### 0.4.2 +* Recognize Unicode document slugs (#37) + ### 0.4.1 * Conform syntax to WordPress VIP plugin requirements (#30) (@bcampeau) * Fixed: Bare URLs now get default parameters (#35) diff --git a/documentcloud.php b/documentcloud.php index 82abbb9..2b3e414 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -32,7 +32,7 @@ class WP_DocumentCloud { DEFAULT_EMBED_FULL_WIDTH = 940, OEMBED_RESOURCE_DOMAIN = 'www.documentcloud.org', OEMBED_PROVIDER = 'https://www.documentcloud.org/api/oembed.{format}', - DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[a-zA-Z0-9-]+)'; + DOCUMENT_PATTERN = '^(?Phttps?):\/\/www\.documentcloud\.org\/documents\/(?P[0-9]+-[\p{L}\p{N}%-]+)'; /** * Constructor. */ diff --git a/readme.txt b/readme.txt index e24d22a..c35a117 100644 --- a/readme.txt +++ b/readme.txt @@ -79,6 +79,9 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == += 0.4.2 = +* Recognize Unicode document slugs (#37) + = 0.4.1 = * Conform syntax to WordPress VIP plugin requirements (#30) (@bcampeau) * Fixed: Bare URLs now get default parameters (#35) From 1c4e98a2250ce2a25a848eac4270a2a126e6596d Mon Sep 17 00:00:00 2001 From: bcampeau Date: Mon, 14 Mar 2016 11:06:41 -0400 Subject: [PATCH 83/99] Handling VIP code review feedback --- documentcloud.php | 56 ++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index 2b3e414..a1df5d0 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -442,36 +442,38 @@ function save( $post_id, $post ) { $matches = array(); preg_match_all( '/'.get_shortcode_regex().'/', $post->post_content, $matches ); - $tags = $matches[2]; - $args = $matches[3]; - foreach( $tags as $i => $tag ) { - if ( 'documentcloud' == $tag ) { - $parsed_atts = shortcode_parse_atts( $args[$i] ); - $atts = shortcode_atts( $default_atts, $parsed_atts ); - - // Get a doc id to keep array keys consistent - if ( isset( $atts['url'] ) ) { - $elements = $this->parse_dc_url( $atts['url'] ); - if ( isset( $elements['document_slug'] ) ) { - $meta_key = $elements['document_slug']; - if ( isset( $elements['page_number'] ) ) { - $meta_key .= "-p{$elements['page_number']}"; - } - else if ( isset( $elements['note_id'] ) ) { - $meta_key .= "-a{$elements['note_id']}"; + $tags = isset( $matches[2] ) ? $matches[2] : array(); + $args = isset( $matches[3] ) ? $matches[3] : array(); + if ( ! empty( $tags ) && is_array( $tags ) ) { + foreach( $tags as $i => $tag ) { + if ( 'documentcloud' == $tag ) { + $parsed_atts = shortcode_parse_atts( $args[$i] ); + $atts = shortcode_atts( $default_atts, $parsed_atts ); + + // Get a doc id to keep array keys consistent + if ( isset( $atts['url'] ) ) { + $elements = $this->parse_dc_url( $atts['url'] ); + if ( isset( $elements['document_slug'] ) ) { + $meta_key = $elements['document_slug']; + if ( isset( $elements['page_number'] ) ) { + $meta_key .= "-p{$elements['page_number']}"; + } + else if ( isset( $elements['note_id'] ) ) { + $meta_key .= "-a{$elements['note_id']}"; + } } + } else if ( isset( $atts['id'] ) ) { + $meta_key = $atts['id']; } - } else if ( isset( $atts['id'] ) ) { - $meta_key = $atts['id']; - } - // If no id, don't bother storing because it's wrong - if ( isset( $meta_key ) ) { - $width = intval( isset( $parsed_atts['width'] ) ? $parsed_atts['width'] : $atts['maxwidth'] ); - if ( 'wide' == $atts['format'] || $width > $default_sizes['width'] ) { - $wide_assets[ $meta_key ] = true; - } else { - $wide_assets[ $meta_key ] = false; + // If no id, don't bother storing because it's wrong + if ( isset( $meta_key ) ) { + $width = intval( isset( $parsed_atts['width'] ) ? $parsed_atts['width'] : $atts['maxwidth'] ); + if ( 'wide' == $atts['format'] || $width > $default_sizes['width'] ) { + $wide_assets[ $meta_key ] = true; + } else { + $wide_assets[ $meta_key ] = false; + } } } } From 31806d1d6a1f6f0f48212bd149557ed7b0f4845b Mon Sep 17 00:00:00 2001 From: Paul Schreiber Date: Wed, 16 Mar 2016 14:07:45 -0400 Subject: [PATCH 84/99] PHPCS fixes --- documentcloud.php | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index a1df5d0..e132ad4 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -40,7 +40,7 @@ function __construct() { // Check for conflicts with other DocumentCloud plugins. // Not needed on WordPress VIP since no other DocumentCloud plugins exist. if ( ! defined( 'WPCOM_IS_VIP_ENV' ) || ! WPCOM_IS_VIP_ENV ) { - add_action( 'admin_init', array( $this, 'check_dc_plugin_conflict') ); + add_action( 'admin_init', array( $this, 'check_dc_plugin_conflict' ) ); } // Register the oEmbed provider @@ -126,7 +126,7 @@ function get_default_sizes() { $width = intval( get_option( 'documentcloud_default_width', $wp_embed_defaults['width'] ) ); $full_width = intval( get_option( 'documentcloud_full_width', WP_DocumentCloud::DEFAULT_EMBED_FULL_WIDTH ) ); - return array ( + return array( 'height' => $height, 'width' => $width, 'full_width' => $full_width, @@ -178,10 +178,10 @@ function get_default_atts() { * @return string */ function prepare_oembed_fetch( $provider, $url, $args ) { - // Merge actual args with default attributes so that defaults are always - // sent to oEmbed endpoint - $default_atts = $this->get_default_atts(); - $atts = array_merge( $default_atts, $args ); + // Merge actual args with default attributes so that defaults are always + // sent to oEmbed endpoint + $default_atts = $this->get_default_atts(); + $atts = array_merge( $default_atts, $args ); // Clean and prepare arguments foreach ( $atts as $key => $value ) { @@ -233,9 +233,8 @@ function process_dc_shortcode( $atts ) { if ( empty( $atts['url'] ) ) { if ( empty( $atts['id'] ) ) { return ''; - } - else { - $url = $filtered_atts['url'] = "https://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$atts['id']}.html"; + } else { + $url = $filtered_atts['url'] = 'https://' . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$atts['id']}.html"; } } @@ -258,7 +257,7 @@ function process_dc_shortcode( $atts ) { // If the format is set to wide, it blows away all other width // settings. - if ( 'wide' == $filtered_atts['format'] ) { + if ( 'wide' === $filtered_atts['format'] ) { $filtered_atts['maxwidth'] = $default_sizes['full_width']; } @@ -321,8 +320,7 @@ function clean_dc_url( $url ) { $url = "{$elements['protocol']}://" . WP_DocumentCloud::OEMBED_RESOURCE_DOMAIN . "/documents/{$elements['document_slug']}"; if ( isset( $elements['page_number'] ) ) { $url .= "/pages/{$elements['page_number']}"; - } - else if ( isset( $elements['note_id'] ) ) { + } else if ( isset( $elements['note_id'] ) ) { $url .= "/annotations/{$elements['note_id']}"; } $url .= '.html'; @@ -445,9 +443,9 @@ function save( $post_id, $post ) { $tags = isset( $matches[2] ) ? $matches[2] : array(); $args = isset( $matches[3] ) ? $matches[3] : array(); if ( ! empty( $tags ) && is_array( $tags ) ) { - foreach( $tags as $i => $tag ) { - if ( 'documentcloud' == $tag ) { - $parsed_atts = shortcode_parse_atts( $args[$i] ); + foreach ( $tags as $i => $tag ) { + if ( 'documentcloud' === $tag ) { + $parsed_atts = shortcode_parse_atts( $args[ $i ] ); $atts = shortcode_atts( $default_atts, $parsed_atts ); // Get a doc id to keep array keys consistent @@ -457,8 +455,7 @@ function save( $post_id, $post ) { $meta_key = $elements['document_slug']; if ( isset( $elements['page_number'] ) ) { $meta_key .= "-p{$elements['page_number']}"; - } - else if ( isset( $elements['note_id'] ) ) { + } else if ( isset( $elements['note_id'] ) ) { $meta_key .= "-a{$elements['note_id']}"; } } @@ -469,7 +466,7 @@ function save( $post_id, $post ) { // If no id, don't bother storing because it's wrong if ( isset( $meta_key ) ) { $width = intval( isset( $parsed_atts['width'] ) ? $parsed_atts['width'] : $atts['maxwidth'] ); - if ( 'wide' == $atts['format'] || $width > $default_sizes['width'] ) { + if ( 'wide' === $atts['format'] || $width > $default_sizes['width'] ) { $wide_assets[ $meta_key ] = true; } else { $wide_assets[ $meta_key ] = false; @@ -481,7 +478,6 @@ function save( $post_id, $post ) { update_post_meta( $post_id, 'wide_assets', $wide_assets ); } } - } new WP_DocumentCloud; From e7364a2f81f10b80278accd0607cfc1c403e8300 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 13 Apr 2016 12:54:01 -0500 Subject: [PATCH 85/99] Version `0.4.3-dev` --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index e132ad4..9723f5c 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -3,7 +3,7 @@ * Plugin Name: DocumentCloud * Plugin URI: https://www.documentcloud.org/ * Description: Embed DocumentCloud resources in WordPress content. - * Version: 0.4.2 + * Version: 0.4.3-dev * Authors: Chris Amico, Justin Reese * License: GPLv2 ***/ From 39edbef02eebc29ddc3d3f8aa17f02e04ea23e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Here=C3=B1=C3=BA?= Date: Fri, 30 Sep 2016 20:49:09 -0300 Subject: [PATCH 86/99] Minor fix (proposal) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8e325bf..d431422 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Here's the full list of embed options you can pass via shortcode attributes; som - `responsive_offset` (integer): Distance (in pixels) to vertically offset the viewer for some responsive embeds. - `default_page` (integer): Page number to have the document scroll to by default. - `default_note` (integer): ID of the note that the document should highlight by default. -- `notes` (boolean): Show/hide notes: +- `notes` (boolean): Show/hide notes - `search` (boolean): Hide or show search form. - `sidebar` (boolean): Hide or show sidebar. Defaults `false`. - `pdf` (boolean): Hide or show link to download original PDF. Defaults `true`. From 703ae5cd2d80471295ce219139978b51b4c8a682 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Oct 2016 13:47:28 -0500 Subject: [PATCH 87/99] Expect `page`/`note` without `default_` prefix #47 --- README.md | 7 +++++-- documentcloud.php | 4 ++-- readme.txt | 7 +++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8e325bf..a204251 100644 --- a/README.md +++ b/README.md @@ -58,8 +58,8 @@ Here's the full list of embed options you can pass via shortcode attributes; som - `width` (integer): Width (in pixels) of the embed. If used, will implicitly set `responsive="false"`. - `responsive` (boolean): Use responsive layout, which dynamically adjusts width to fill content area. Defaults `true`. - `responsive_offset` (integer): Distance (in pixels) to vertically offset the viewer for some responsive embeds. -- `default_page` (integer): Page number to have the document scroll to by default. -- `default_note` (integer): ID of the note that the document should highlight by default. +- `page` (integer): Page number to have the document scroll to by default. +- `note` (integer): ID of the note that the document should highlight by default. - `notes` (boolean): Show/hide notes: - `search` (boolean): Hide or show search form. - `sidebar` (boolean): Hide or show sidebar. Defaults `false`. @@ -87,6 +87,9 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog +### 0.4.3 +* Rename `default_page` and `default_note` options back to `page` and `note` + ### 0.4.2 * Recognize Unicode document slugs (#37) diff --git a/documentcloud.php b/documentcloud.php index 9723f5c..2d4c44e 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -146,11 +146,11 @@ function get_default_atts() { 'container' => null, 'notes' => null, 'responsive_offset' => null, - 'default_page' => null, - 'default_note' => null, 'zoom' => null, 'search' => null, 'responsive' => 'true', + 'page' => null, + 'note' => null, // The following defaults match the existing plugin, except // `height/width` are prefixed `max*` per the oEmbed spec. // You can still use `height/width` for backwards diff --git a/readme.txt b/readme.txt index c35a117..f986110 100644 --- a/readme.txt +++ b/readme.txt @@ -56,8 +56,8 @@ Here's the full list of embed options you can pass via shortcode attributes; som - `width` (integer): Width (in pixels) of the embed. If used, will implicitly set `responsive="false"`. - `responsive` (boolean): Use responsive layout, which dynamically adjusts width to fill content area. Defaults `true`. - `responsive_offset` (integer): Distance (in pixels) to vertically offset the viewer for some responsive embeds. -- `default_page` (integer): Page number to have the document scroll to by default. -- `default_note` (integer): ID of the note that the document should highlight by default. +- `page` (integer): Page number to have the document scroll to by default. +- `note` (integer): ID of the note that the document should highlight by default. - `notes` (boolean): Show/hide notes: - `search` (boolean): Hide or show search form. - `sidebar` (boolean): Hide or show sidebar. Defaults `false`. @@ -79,6 +79,9 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == += 0.4.3 = +* Rename `default_page` and `default_note` options back to `page` and `note` + = 0.4.2 = * Recognize Unicode document slugs (#37) From acf9690d81350029202e2e47e9525d63c8fb6240 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Oct 2016 13:48:19 -0500 Subject: [PATCH 88/99] Separate oEmbed config from embed config #48 --- README.md | 1 + documentcloud.php | 42 ++++++++++++++++++++++-------------------- readme.txt | 1 + 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index a204251..84d3ffb 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,7 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog ### 0.4.3 +* Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) * Rename `default_page` and `default_note` options back to `page` and `note` ### 0.4.2 diff --git a/documentcloud.php b/documentcloud.php index 2d4c44e..fabbcbf 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -148,9 +148,9 @@ function get_default_atts() { 'responsive_offset' => null, 'zoom' => null, 'search' => null, - 'responsive' => 'true', 'page' => null, 'note' => null, + 'responsive' => null, // The following defaults match the existing plugin, except // `height/width` are prefixed `max*` per the oEmbed spec. // You can still use `height/width` for backwards @@ -183,30 +183,32 @@ function prepare_oembed_fetch( $provider, $url, $args ) { $default_atts = $this->get_default_atts(); $atts = array_merge( $default_atts, $args ); + // Some resources (like notes) have multiple possible + // user-facing URLs. We recompose them into a single form. + $url = $this->clean_dc_url( $url ); + + // Send these to the oEmbed endpoint itself + $oembed_config_keys = array( 'maxheight', 'maxwidth' ); + + // Specifically *don't* include these on the embed config itself + $excluded_embed_config_keys = array( 'url', 'format', 'height', 'width', 'maxheight', 'maxwidth', 'discover' ); + // Clean and prepare arguments foreach ( $atts as $key => $value ) { - switch ( $key ) { - case 'format': - case 'height': - case 'width': - case 'discover': - // Don't pass these attributes to the provider - break; - default: - // Without this check, `add_query_arg()` will treat values - // that are actually ID selectors, like `container=#foo`, - // as URL fragments and throw them at the end of the URL. - if ( 0 === strpos( $value, '#' ) ) { - $value = urlencode( $value ); - } - $provider = add_query_arg( $key, $value, $provider ); - break; + if ( in_array( $key, $oembed_config_keys ) ) { + $provider = add_query_arg( $key, $value, $provider ); + } + if ( ! in_array( $key, $excluded_embed_config_keys ) ) { + // Without this check, `add_query_arg()` will treat values + // that are actually ID selectors, like `container=#foo`, + // as URL fragments and throw them at the end of the URL. + if ( 0 === strpos( $value, '#' ) ) { + $value = urlencode( $value ); + } + $url = add_query_arg( $key, $value, $url ); } } - // Some resources (like notes) have multiple possible - // user-facing URLs. We recompose them into a single form. - $url = $this->clean_dc_url( $url ); $provider = add_query_arg( 'url', urlencode( $url ), $provider ); return $provider; diff --git a/readme.txt b/readme.txt index f986110..122481b 100644 --- a/readme.txt +++ b/readme.txt @@ -80,6 +80,7 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == = 0.4.3 = +* Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) * Rename `default_page` and `default_note` options back to `page` and `note` = 0.4.2 = From c32677a5300e593fa0408b1270f1e06cf03bb17a Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Oct 2016 13:48:35 -0500 Subject: [PATCH 89/99] Align some assignments --- documentcloud.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index fabbcbf..0d55373 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -142,14 +142,14 @@ function get_default_atts() { $default_sizes = $this->get_default_sizes(); return array( - 'url' => null, - 'container' => null, - 'notes' => null, - 'responsive_offset' => null, - 'zoom' => null, - 'search' => null, + 'url' => null, + 'container' => null, + 'notes' => null, + 'responsive_offset' => null, 'page' => null, 'note' => null, + 'zoom' => null, + 'search' => null, 'responsive' => null, // The following defaults match the existing plugin, except // `height/width` are prefixed `max*` per the oEmbed spec. @@ -160,12 +160,12 @@ function get_default_atts() { // 2. `maxwidth` on shortcode // 3. Settings > DocumentCloud > "Default embed width" // 4. `wp_embed_defaults()['width']` - 'maxheight' => $default_sizes['height'], - 'maxwidth' => $default_sizes['width'], - 'format' => 'normal', - 'sidebar' => 'false', - 'text' => 'true', - 'pdf' => 'true', + 'maxheight' => $default_sizes['height'], + 'maxwidth' => $default_sizes['width'], + 'format' => 'normal', + 'sidebar' => 'false', + 'text' => 'true', + 'pdf' => 'true', ); } From a452bca3978d3ecdc651636cce18c79460a8f1c4 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Oct 2016 14:02:17 -0500 Subject: [PATCH 90/99] Remove unnecessary defaults The `sidebar`, `text`, and `pdf` defaults match what we send anyway, and the `text` in particular was problematic with page embeds (which also take a `text` boolean, but which we expect to be false), so remove them. --- README.md | 7 ++++--- documentcloud.php | 6 +++--- readme.txt | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 84d3ffb..2b292fa 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ Here's the full list of embed options you can pass via shortcode attributes; som - `note` (integer): ID of the note that the document should highlight by default. - `notes` (boolean): Show/hide notes: - `search` (boolean): Hide or show search form. -- `sidebar` (boolean): Hide or show sidebar. Defaults `false`. -- `pdf` (boolean): Hide or show link to download original PDF. Defaults `true`. -- `text` (boolean): Hide or show text tab. Defaults `true`. +- `sidebar` (boolean): Hide or show sidebar. +- `pdf` (boolean): Hide or show link to download original PDF. +- `text` (boolean): Hide or show text tab. - `zoom` (boolean): Hide or show zoom slider. - `format` (string): Indicate to the theme that this is a wide asset by setting this to `wide`. Defaults `normal`. @@ -90,6 +90,7 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ### 0.4.3 * Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) * Rename `default_page` and `default_note` options back to `page` and `note` +* Remove `sidebar`, `text`, and `pdf` default values ### 0.4.2 * Recognize Unicode document slugs (#37) diff --git a/documentcloud.php b/documentcloud.php index 0d55373..8323348 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -151,6 +151,9 @@ function get_default_atts() { 'zoom' => null, 'search' => null, 'responsive' => null, + 'sidebar' => null, + 'text' => null, + 'pdf' => null, // The following defaults match the existing plugin, except // `height/width` are prefixed `max*` per the oEmbed spec. // You can still use `height/width` for backwards @@ -163,9 +166,6 @@ function get_default_atts() { 'maxheight' => $default_sizes['height'], 'maxwidth' => $default_sizes['width'], 'format' => 'normal', - 'sidebar' => 'false', - 'text' => 'true', - 'pdf' => 'true', ); } diff --git a/readme.txt b/readme.txt index 122481b..a806ef5 100644 --- a/readme.txt +++ b/readme.txt @@ -60,9 +60,9 @@ Here's the full list of embed options you can pass via shortcode attributes; som - `note` (integer): ID of the note that the document should highlight by default. - `notes` (boolean): Show/hide notes: - `search` (boolean): Hide or show search form. -- `sidebar` (boolean): Hide or show sidebar. Defaults `false`. -- `pdf` (boolean): Hide or show link to download original PDF. Defaults `true`. -- `text` (boolean): Hide or show text tab. Defaults `true`. +- `sidebar` (boolean): Hide or show sidebar. +- `pdf` (boolean): Hide or show link to download original PDF. +- `text` (boolean): Hide or show text tab. - `zoom` (boolean): Hide or show zoom slider. - `format` (string): Indicate to the theme that this is a wide asset by setting this to `wide`. Defaults `normal`. @@ -82,6 +82,7 @@ You can read more about publishing and embedding DocumentCloud resources on http = 0.4.3 = * Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) * Rename `default_page` and `default_note` options back to `page` and `note` +* Remove `sidebar`, `text`, and `pdf` default values = 0.4.2 = * Recognize Unicode document slugs (#37) From 38be75c75bb54811baac24fdbb184b202cc03174 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Oct 2016 14:05:19 -0500 Subject: [PATCH 91/99] =?UTF-8?q?Update=20=E2=80=9Ctested=20up=20to?= =?UTF-8?q?=E2=80=9D=20to=204.6.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit #45 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index a806ef5..3dff93c 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: chrisamico, reefdog Tags: documentcloud, documents, journalism, reporting, research Requires at least: 3.2 -Tested up to: 4.4 +Tested up to: 4.6.1 Stable tag: trunk License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html From fefb797d694f5526156b9145627719f5b4336d73 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Wed, 26 Oct 2016 15:23:11 -0500 Subject: [PATCH 92/99] Require at least WP 3.5 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index 3dff93c..6f2e1a8 100644 --- a/readme.txt +++ b/readme.txt @@ -1,7 +1,7 @@ === DocumentCloud === Contributors: chrisamico, reefdog Tags: documentcloud, documents, journalism, reporting, research -Requires at least: 3.2 +Requires at least: 3.5 Tested up to: 4.6.1 Stable tag: trunk License: GPLv2 From 1ffa2607a899a4da7634250fb1921c8e1b6f7956 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 27 Oct 2016 09:48:21 -0500 Subject: [PATCH 93/99] Update version to 0.4.3 --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index 8323348..b2c54ea 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -3,7 +3,7 @@ * Plugin Name: DocumentCloud * Plugin URI: https://www.documentcloud.org/ * Description: Embed DocumentCloud resources in WordPress content. - * Version: 0.4.3-dev + * Version: 0.4.3 * Authors: Chris Amico, Justin Reese * License: GPLv2 ***/ From ae2d74cf6b501e31d9836874e73f5d05b2f333cb Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 27 Oct 2016 09:54:40 -0500 Subject: [PATCH 94/99] Queue up version 0.4.4 --- documentcloud.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentcloud.php b/documentcloud.php index b2c54ea..acee6f7 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -3,7 +3,7 @@ * Plugin Name: DocumentCloud * Plugin URI: https://www.documentcloud.org/ * Description: Embed DocumentCloud resources in WordPress content. - * Version: 0.4.3 + * Version: 0.4.4-dev * Authors: Chris Amico, Justin Reese * License: GPLv2 ***/ From 2e190809702de743c79336680570bf5c522b748a Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Thu, 27 Oct 2016 09:57:24 -0500 Subject: [PATCH 95/99] Add issue numbers to changelog items --- README.md | 4 ++-- readme.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2b292fa..2d8c8c9 100644 --- a/README.md +++ b/README.md @@ -88,8 +88,8 @@ If you find yourself absolutely needing to expire the cache, though, you have tw ## Changelog ### 0.4.3 -* Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) -* Rename `default_page` and `default_note` options back to `page` and `note` +* Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) (#48) +* Rename `default_page` and `default_note` options back to `page` and `note` (#47) * Remove `sidebar`, `text`, and `pdf` default values ### 0.4.2 diff --git a/readme.txt b/readme.txt index 6f2e1a8..b3a8026 100644 --- a/readme.txt +++ b/readme.txt @@ -80,8 +80,8 @@ You can read more about publishing and embedding DocumentCloud resources on http == Changelog == = 0.4.3 = -* Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) -* Rename `default_page` and `default_note` options back to `page` and `note` +* Separate the oEmbed config options (provided as params to the endpoint) from the embed config options (encoded as params on the `url`) (#48) +* Rename `default_page` and `default_note` options back to `page` and `note` (#47) * Remove `sidebar`, `text`, and `pdf` default values = 0.4.2 = From a1a3d93ae1e71672562e45b34b8dfc2304dec1c6 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Mon, 5 Dec 2016 14:17:14 -0600 Subject: [PATCH 96/99] Tweak `notes` description in readme After @kant called attention to it in #44 --- README.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 568a32e..2160d55 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Here's the full list of embed options you can pass via shortcode attributes; som - `responsive_offset` (integer): Distance (in pixels) to vertically offset the viewer for some responsive embeds. - `page` (integer): Page number to have the document scroll to by default. - `note` (integer): ID of the note that the document should highlight by default. -- `notes` (boolean): Show/hide notes +- `notes` (boolean): Hide or show notes. - `search` (boolean): Hide or show search form. - `sidebar` (boolean): Hide or show sidebar. - `pdf` (boolean): Hide or show link to download original PDF. diff --git a/readme.txt b/readme.txt index b3a8026..b757670 100644 --- a/readme.txt +++ b/readme.txt @@ -58,7 +58,7 @@ Here's the full list of embed options you can pass via shortcode attributes; som - `responsive_offset` (integer): Distance (in pixels) to vertically offset the viewer for some responsive embeds. - `page` (integer): Page number to have the document scroll to by default. - `note` (integer): ID of the note that the document should highlight by default. -- `notes` (boolean): Show/hide notes: +- `notes` (boolean): Hide or show notes. - `search` (boolean): Hide or show search form. - `sidebar` (boolean): Hide or show sidebar. - `pdf` (boolean): Hide or show link to download original PDF. From 859d6c86d3513bfdb2ad37537306d62d89bcecc1 Mon Sep 17 00:00:00 2001 From: Justin Reese Date: Tue, 20 Dec 2016 17:33:46 -0600 Subject: [PATCH 97/99] Tested up to 4.7 --- readme.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.txt b/readme.txt index b757670..312c46d 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: chrisamico, reefdog Tags: documentcloud, documents, journalism, reporting, research Requires at least: 3.5 -Tested up to: 4.6.1 +Tested up to: 4.7 Stable tag: trunk License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html From 08965112d8633c7c70a90c6ae7f322d79aa7553f Mon Sep 17 00:00:00 2001 From: aschweigert Date: Fri, 16 Jun 2017 11:23:28 -0400 Subject: [PATCH 98/99] remove wide_assets postmeta since this should be a theme-specific thing, fixes #51 --- documentcloud.php | 59 ----------------------------------------------- 1 file changed, 59 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index acee6f7..e2e1a95 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -421,65 +421,6 @@ function full_width_field() { $default_sizes = $this->get_default_sizes(); echo ''; } - - /** - * Save DocumentCloud postmeta required by the shortcode on post save. - * - * @param int $post_id - * @param WP_Post $post - */ - function save( $post_id, $post ) { - // Avoid autosave - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { - return; - } - - // Tell the post if we're carrying a wide load - if ( current_user_can( 'edit_posts' ) ) { - $default_sizes = $this->get_default_sizes(); - $default_atts = $this->get_default_atts(); - $wide_assets = get_post_meta( $post_id, 'wide_assets', true ); - $matches = array(); - - preg_match_all( '/'.get_shortcode_regex().'/', $post->post_content, $matches ); - $tags = isset( $matches[2] ) ? $matches[2] : array(); - $args = isset( $matches[3] ) ? $matches[3] : array(); - if ( ! empty( $tags ) && is_array( $tags ) ) { - foreach ( $tags as $i => $tag ) { - if ( 'documentcloud' === $tag ) { - $parsed_atts = shortcode_parse_atts( $args[ $i ] ); - $atts = shortcode_atts( $default_atts, $parsed_atts ); - - // Get a doc id to keep array keys consistent - if ( isset( $atts['url'] ) ) { - $elements = $this->parse_dc_url( $atts['url'] ); - if ( isset( $elements['document_slug'] ) ) { - $meta_key = $elements['document_slug']; - if ( isset( $elements['page_number'] ) ) { - $meta_key .= "-p{$elements['page_number']}"; - } else if ( isset( $elements['note_id'] ) ) { - $meta_key .= "-a{$elements['note_id']}"; - } - } - } else if ( isset( $atts['id'] ) ) { - $meta_key = $atts['id']; - } - - // If no id, don't bother storing because it's wrong - if ( isset( $meta_key ) ) { - $width = intval( isset( $parsed_atts['width'] ) ? $parsed_atts['width'] : $atts['maxwidth'] ); - if ( 'wide' === $atts['format'] || $width > $default_sizes['width'] ) { - $wide_assets[ $meta_key ] = true; - } else { - $wide_assets[ $meta_key ] = false; - } - } - } - } - } - update_post_meta( $post_id, 'wide_assets', $wide_assets ); - } - } } new WP_DocumentCloud; From f20b7c3332964921b83e2b5231532fdcfdf41020 Mon Sep 17 00:00:00 2001 From: aschweigert Date: Fri, 16 Jun 2017 11:31:23 -0400 Subject: [PATCH 99/99] remove save post action --- documentcloud.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/documentcloud.php b/documentcloud.php index e2e1a95..538a539 100644 --- a/documentcloud.php +++ b/documentcloud.php @@ -58,9 +58,6 @@ function __construct() { // Setup the settings page add_action( 'admin_menu', array( $this, 'add_options_page' ) ); add_action( 'admin_init', array( $this, 'settings_init' ) ); - - // Store DocumentCloud metadata upon post save - add_action( 'save_post', array( $this, 'save' ), 10, 2 ); } /**