From 2bcc4993a7080c3bd60326e7c3faf03cd7ef3fa6 Mon Sep 17 00:00:00 2001 From: "Anthony G. Basile" Date: Mon, 6 Jan 2020 14:35:30 -0500 Subject: Update public-post-preview 2.9.0 Signed-off-by: Anthony G. Basile --- plugins/public-post-preview/CHANGELOG.md | 74 +++++++++++++ plugins/public-post-preview/composer.json | 25 +++++ .../js/gutenberg-integration.deps.json | 1 + .../js/gutenberg-integration.js | 2 +- .../public-post-preview/js/public-post-preview.js | 5 +- .../js/public-post-preview.min.js | 2 +- .../js/src/components/preview-toggle/index.js | 80 +++++++++++---- .../languages/public-post-preview.php | 19 ---- .../languages/public-post-preview.pot | 24 ----- .../public-post-preview/public-post-preview.php | 114 ++++++++++----------- plugins/public-post-preview/readme.txt | 84 ++++----------- 11 files changed, 234 insertions(+), 196 deletions(-) create mode 100755 plugins/public-post-preview/CHANGELOG.md create mode 100755 plugins/public-post-preview/composer.json create mode 100755 plugins/public-post-preview/js/gutenberg-integration.deps.json delete mode 100644 plugins/public-post-preview/languages/public-post-preview.php delete mode 100644 plugins/public-post-preview/languages/public-post-preview.pot diff --git a/plugins/public-post-preview/CHANGELOG.md b/plugins/public-post-preview/CHANGELOG.md new file mode 100755 index 00000000..4f2bf1d4 --- /dev/null +++ b/plugins/public-post-preview/CHANGELOG.md @@ -0,0 +1,74 @@ +# Changelog + +## 2.9.0 (2019-07-20): +* Requires WordPress 5.0 +* Requires PHP 5.6 +* Adds notice (as Snackbar if supported) when changing preview status in block editor. +* Fixes incorrect status message in classic editor. +* Fixes grammar in expired link notice. Props [@garrett-eclipse](https://github.com/garrett-eclipse). +* Improves internal checks to be more strict. Props [@PatelUtkarsh](https://github.com/PatelUtkarsh). +* Removes deprecated i18n compatibility layer from Gutenberg plugin. + +## 2.8.0 (2018-11-27): +* Add support for WordPress 5.0 and the new block editor. + +## 2.7.0 (2018-09-14): +* Initial support for Gutenberg. +* Block robots for public post previews. Props [@westonruter](https://github.com/westonruter). + +## 2.6.0 (2017-04-27): +* Make `DS_Public_Post_Preview::get_preview_link()` public. Props [@rcstr](https://github.com/rcstr). +* Send no-cache headers for public post previews. + +## 2.5.0 (2016-04-05): +* Auto select preview link on focus. Props [@JeroenSormani](https://github.com/JeroenSormani). +* Remove preview status from posts which are trashed or after scheduled posts are published. +* Add support for paged posts. + +## 2.4.1 (2015-10-13): +* Update text domain to support language packs. Translations are now managed via http://translate.wordpress.org/projects/wp-plugins/public-post-preview. + +## 2.4 (2014-08-21): +* Supports EditFlow and custom statuses +* Disables comments and pings during public post preview +* Adds __Public Preview__ to the list of display states used in the Posts list table +* Prevents flickering of link box on Post edit while loading + +## 2.3 (2013-11-18): +* Introduces a filter `ppp_preview_link`. With the filter you can adjust the preview link. +* If a post has gone live, redirect to it's proper permalink. +* Adds the query var `_ppp` to WordPress SEO by Yoast whitelist. + +## 2.2 (2013-03-15): +* Based on user feedback: Removed the extra meta box and added preview link to the main Publish meta box. +* Only show the checkbox if the post status/post type is good. +* Requires WordPress 3.5 + +## 2.1.1 (2012-09-19): +* Sorry for the new update. Through a change in 2.1 a filter was applied to each query. The misplaced "The link has been expired!" message is now gone. Props Aki Björklund and Jonathan Channon. + +## 2.1 (2012-09-16): +* Introduces a filter `ppp_nonce_life`. With the filter you can adjust the expiration of a link. By default a link has a lifetime of 48 hours. +* In some situations (still not sure when) the preview link is rewritten as a permalink which results in an error. The plugin now works in this situations too. + +## 2.0.1 (2012-07-25): +* Makes the preview link copyable again + +## 2.0 (2012-07-23): +* Support for all public post types +* Saves public preview status via an AJAX request +* I18n +* Requires at least WordPress 3.3 + +## 1.3 (2009-06-30): +* Hook in earlier in the post selection process to fix PHP notices +* Add uninstall functionality to remove options from the options table + +## 1.2 (2009-03-30): +* Fix preview URL for scheduled posts on sites with a permalink other than default activated. + +## 1.1 (2009-03-11): +* Don't limit public previews to posts in draft or pending status. Just exclude posts in publish status. + +## 1.0 (2009-02-20): +* Initial Public Release diff --git a/plugins/public-post-preview/composer.json b/plugins/public-post-preview/composer.json new file mode 100755 index 00000000..86865c4e --- /dev/null +++ b/plugins/public-post-preview/composer.json @@ -0,0 +1,25 @@ +{ + "name": "ocean90/public-post-preview", + "description": "WordPress plugin to allow anonymous users to preview a post before it is published.", + "homepage": "https://wordpress.org/plugins/public-post-preview/", + "type": "wordpress-plugin", + "license": "GPL-2.0-or-later", + "authors": [ + { + "name": "Dominik Schilling", + "homepage": "https://dominikschilling.de/" + } + ], + "support": { + "issues": "https://github.com/ocean90/public-post-preview/issues", + "forum": "https://wordpress.org/support/plugin/public-post-preview", + "source": "https://github.com/ocean90/public-post-preview" + }, + "config": { + "sort-packages": true, + "preferred-install": "dist" + }, + "require": { + "php": ">=5.6" + } +} diff --git a/plugins/public-post-preview/js/gutenberg-integration.deps.json b/plugins/public-post-preview/js/gutenberg-integration.deps.json new file mode 100755 index 00000000..56f563b3 --- /dev/null +++ b/plugins/public-post-preview/js/gutenberg-integration.deps.json @@ -0,0 +1 @@ +["lodash","wp-components","wp-compose","wp-data","wp-edit-post","wp-element","wp-i18n","wp-plugins","wp-polyfill"] \ No newline at end of file diff --git a/plugins/public-post-preview/js/gutenberg-integration.js b/plugins/public-post-preview/js/gutenberg-integration.js index 6bf327c1..8388a80f 100644 --- a/plugins/public-post-preview/js/gutenberg-integration.js +++ b/plugins/public-post-preview/js/gutenberg-integration.js @@ -1 +1 @@ -this.publicPostPreview=this.publicPostPreview||{},this.publicPostPreview.main=function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=22)}([function(e,t){!function(){e.exports=this.wp.element}()},function(e,t){e.exports=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}},function(e,t){!function(){e.exports=this.wp.i18n}()},function(e,t,r){"use strict";(function(e){r.d(t,"a",function(){return c});var n=r(17),i=void 0!==e?e:{},a=Object(n.a)(i),c=(a.flush,a.hydrate,a.cx,a.merge,a.getRegisteredStyles,a.injectGlobal,a.keyframes,a.css);a.sheet,a.caches}).call(this,r(21))},function(e,t){!function(){e.exports=this.wp.components}()},function(e,t){!function(){e.exports=this.wp.compose}()},function(e,t){!function(){e.exports=this.wp.editPost}()},function(e,t){!function(){e.exports=this.wp.plugins}()},function(e,t,r){var n=r(18);e.exports=function(e){for(var t=1;t=4;)t=1540483477*(65535&(t=255&e.charCodeAt(i)|(255&e.charCodeAt(++i))<<8|(255&e.charCodeAt(++i))<<16|(255&e.charCodeAt(++i))<<24))+((1540483477*(t>>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++i;switch(r){case 3:n^=(255&e.charCodeAt(i+2))<<16;case 2:n^=(255&e.charCodeAt(i+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(i)))+((1540483477*(n>>>16)&65535)<<16)}return n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16),((n^=n>>>15)>>>0).toString(36)};var c=function(e){function t(e,t,n){var i=t.trim().split(d);t=i;var a=i.length,c=e.length;switch(c){case 0:case 1:var o=0;for(e=0===c?"":e[0]+" ";on&&(n=(t=t.trim()).charCodeAt(0)),n){case 38:return t.replace(b,"$1"+e.trim());case 58:return e.trim()+t.replace(b,"$1"+e.trim());default:if(0<1*r&&0s.charCodeAt(8))break;case 115:c=c.replace(s,"-webkit-"+s)+";"+c;break;case 207:case 102:c=c.replace(s,"-webkit-"+(102o.charCodeAt(0)&&(o=o.trim()),o=[o],0p)&&(F=(D=D.replace(" ",":")).length),01?i-1:0),o=1;on&&(n=(t=t.trim()).charCodeAt(0)),n){case 38:return t.replace(b,"$1"+e.trim());case 58:return e.trim()+t.replace(b,"$1"+e.trim());default:if(0<1*r&&0s.charCodeAt(8))break;case 115:c=c.replace(s,"-webkit-"+s)+";"+c;break;case 207:case 102:c=c.replace(s,"-webkit-"+(102o.charCodeAt(0)&&(o=o.trim()),o=[o],0h)&&(G=(T=T.replace(" ",":")).length),0=4;)t=1540483477*(65535&(t=255&e.charCodeAt(i)|(255&e.charCodeAt(++i))<<8|(255&e.charCodeAt(++i))<<16|(255&e.charCodeAt(++i))<<24))+((1540483477*(t>>>16)&65535)<<16),n=1540483477*(65535&n)+((1540483477*(n>>>16)&65535)<<16)^(t=1540483477*(65535&(t^=t>>>24))+((1540483477*(t>>>16)&65535)<<16)),r-=4,++i;switch(r){case 3:n^=(255&e.charCodeAt(i+2))<<16;case 2:n^=(255&e.charCodeAt(i+1))<<8;case 1:n=1540483477*(65535&(n^=255&e.charCodeAt(i)))+((1540483477*(n>>>16)&65535)<<16)}return n=1540483477*(65535&(n^=n>>>13))+((1540483477*(n>>>16)&65535)<<16),((n^=n>>>15)>>>0).toString(36)},C={animationIterationCount:1,borderImageOutset:1,borderImageSlice:1,borderImageWidth:1,boxFlex:1,boxFlexGroup:1,boxOrdinalGroup:1,columnCount:1,columns:1,flex:1,flexGrow:1,flexPositive:1,flexShrink:1,flexNegative:1,flexOrder:1,gridRow:1,gridRowEnd:1,gridRowSpan:1,gridRowStart:1,gridColumn:1,gridColumnEnd:1,gridColumnSpan:1,gridColumnStart:1,msGridRow:1,msGridRowSpan:1,msGridColumn:1,msGridColumnSpan:1,fontWeight:1,lineHeight:1,opacity:1,order:1,orphans:1,tabSize:1,widows:1,zIndex:1,zoom:1,WebkitLineClamp:1,fillOpacity:1,floodOpacity:1,stopOpacity:1,strokeDasharray:1,strokeDashoffset:1,strokeMiterlimit:1,strokeOpacity:1,strokeWidth:1};var A=/[A-Z]|^ms/g,O=/_EMO_([^_]+?)_([^]*?)_EMO_/g,j=function(e){return 45===e.charCodeAt(1)},S=function(e){var t={};return function(r){return void 0===t[r]&&(t[r]=e(r)),t[r]}}(function(e){return j(e)?e:e.replace(A,"-$&").toLowerCase()}),_=function(e,t){if(null==t||"boolean"==typeof t)return"";switch(e){case"animation":case"animationName":"string"==typeof t&&(t=t.replace(O,function(e,t,r){return E={name:t,styles:r,next:E},t}))}return 1===C[e]||j(e)||"number"!=typeof t||0===t?t:t+"px"};function P(e,t,r,n){if(null==r)return"";if(void 0!==r.__emotion_styles)return r;switch(typeof r){case"boolean":return"";case"object":if(1===r.anim)return E={name:r.name,styles:r.styles,next:E},r.name;if(void 0!==r.styles){var i=r.next;if(void 0!==i)for(;void 0!==i;)E={name:i.name,styles:i.styles,next:E},i=i.next;return r.styles}return function(e,t,r){var n="";if(Array.isArray(r))for(var i=0;i=200&&e.status<300)return e;throw e}).then(function(e){return e.json()}).then(function(e){if(!e.success)throw e;var r=!t.state.previewEnabled;t.setState({previewEnabled:r}),t.props.createNotice("info",r?Object(T.__)("Public preview enabled.","public-post-preview"):Object(T.__)("Public preview disabled.","public-post-preview"),{id:"public-post-preview",isDismissible:!0,type:"snackbar"})}).catch(function(){t.props.createNotice("error",Object(T.__)("Error while changing the public preview status.","public-post-preview"),{id:"public-post-preview",isDismissible:!0,type:"snackbar"})})}},{key:"onPreviewUrlInputFocus",value:function(){this.previewUrlInput.current.focus(),this.previewUrlInput.current.select()}},{key:"sendRequest",value:function(e){return e.append("action","public-post-preview"),e.append("_ajax_nonce",J.nonce),window.fetch(Z,{method:"POST",body:e})}},{key:"render",value:function(){var e=this,t=this.state,r=t.previewEnabled,n=t.previewUrl,i=t.hasCopied,a=i?Object(T.__)("Preview URL copied","public-post-preview"):Object(T.__)("Copy the preview URL","public-post-preview");return Object(H.createElement)(H.Fragment,null,Object(H.createElement)(q.PluginPostStatusInfo,null,Object(H.createElement)(V.CheckboxControl,{label:Object(T.__)("Enable public preview","public-post-preview"),checked:r,onChange:this.onChange})),r&&Object(H.createElement)(q.PluginPostStatusInfo,{className:K},Object(H.createElement)("p",{className:Y},Object(H.createElement)("label",{htmlFor:"public-post-preview-url",className:"screen-reader-text"},Object(T.__)("Preview URL","public-post-preview")),Object(H.createElement)("input",{ref:this.previewUrlInput,type:"text",id:"public-post-preview-url",className:Q,value:n,readOnly:!0,onFocus:this.onPreviewUrlInputFocus}),Object(H.createElement)(V.ClipboardButton,{text:n,label:a,onCopy:function(){return e.setState({hasCopied:!0})},onFinishCopy:function(){return e.setState({hasCopied:!1})},"aria-disabled":i,icon:ee})),Object(H.createElement)("p",{className:X},Object(T.__)("Copy and share this preview URL.","public-post-preview"))))}}]),t}(H.Component),re=Object(W.compose)([Object(L.withSelect)(function(e){var t=e("core").getPostType,r=e("core/editor"),n=r.getCurrentPostId,i=r.getEditedPostAttribute,a=t(i("type"));return{postId:n(),status:i("status"),isViewable:Object(D.get)(a,["viewable"],!1)}}),Object(W.ifCondition)(function(e){return e.isViewable}),Object(W.ifCondition)(function(e){var t=e.status;return-1===["auto-draft","publish","private"].indexOf(t)}),Object(L.withDispatch)(function(e){return{createNotice:e("core/notices").createNotice}})])(te);Object(n.registerPlugin)("public-post-preview",{render:re})}]); \ No newline at end of file diff --git a/plugins/public-post-preview/js/public-post-preview.js b/plugins/public-post-preview/js/public-post-preview.js index e25a188e..d35e962d 100644 --- a/plugins/public-post-preview/js/public-post-preview.js +++ b/plugins/public-post-preview/js/public-post-preview.js @@ -47,9 +47,8 @@ post_ID : $( '#post_ID' ).val() }, function( data ) { - // data is '1' if it's a successful request - if ( data ) { - if ( checked ) { + if ( data.success ) { + if ( 'true' === checked ) { t.status.text( DSPublicPostPreviewL10n.enabled ); t._pulsate( t.status, 'green' ); } else { diff --git a/plugins/public-post-preview/js/public-post-preview.min.js b/plugins/public-post-preview/js/public-post-preview.min.js index 4de40d9b..fe6bbcc2 100644 --- a/plugins/public-post-preview/js/public-post-preview.min.js +++ b/plugins/public-post-preview/js/public-post-preview.min.js @@ -1 +1 @@ -(function(a){DSPublicPostPreview={initialize:function(){var b=this;b.checkbox=a("#public-post-preview");b.link=a("#public-post-preview-link");b.nonce=a("#public_post_preview_wpnonce");b.status=a("#public-post-preview-ajax");b.status.css("opacity",0);b.checkbox.bind("change",function(){b.change();});b.link.find("input").on("focus",function(){a(this).select();});},change:function(){var b=this,c=b.checkbox.prop("checked")?"true":"false";b.link.toggle();b.checkbox.prop("disabled","disabled");b.request({_ajax_nonce:b.nonce.val(),checked:c,post_ID:a("#post_ID").val()},function(d){if(d){if(c){b.status.text(DSPublicPostPreviewL10n.enabled);b._pulsate(b.status,"green");}else{b.status.text(DSPublicPostPreviewL10n.disabled);b._pulsate(b.status,"red");}}b.checkbox.prop("disabled","");});},request:function(b,c){a.ajax({type:"POST",url:ajaxurl,data:a.extend(b,{action:"public-post-preview"}),success:c});},_pulsate:function(c,b){c.css("color",b).animate({opacity:1},600,"linear").animate({opacity:0},600,"linear",function(){c.empty();});}};a(DSPublicPostPreview.initialize());})(jQuery); \ No newline at end of file +!function(e){DSPublicPostPreview={initialize:function(){var t=this;t.checkbox=e("#public-post-preview"),t.link=e("#public-post-preview-link"),t.nonce=e("#public_post_preview_wpnonce"),t.status=e("#public-post-preview-ajax"),t.status.css("opacity",0),t.checkbox.bind("change",function(){t.change()}),t.link.find("input").on("focus",function(){e(this).select()})},change:function(){var t=this,i=t.checkbox.prop("checked")?"true":"false";t.link.toggle(),t.checkbox.prop("disabled","disabled"),t.request({_ajax_nonce:t.nonce.val(),checked:i,post_ID:e("#post_ID").val()},function(e){e.success&&("true"===i?(t.status.text(DSPublicPostPreviewL10n.enabled),t._pulsate(t.status,"green")):(t.status.text(DSPublicPostPreviewL10n.disabled),t._pulsate(t.status,"red"))),t.checkbox.prop("disabled","")})},request:function(t,i){e.ajax({type:"POST",url:ajaxurl,data:e.extend(t,{action:"public-post-preview"}),success:i})},_pulsate:function(e,t){e.css("color",t).animate({opacity:1},600,"linear").animate({opacity:0},600,"linear",function(){e.empty()})}},e(DSPublicPostPreview.initialize())}(jQuery); \ No newline at end of file diff --git a/plugins/public-post-preview/js/src/components/preview-toggle/index.js b/plugins/public-post-preview/js/src/components/preview-toggle/index.js index 96502863..41e20868 100644 --- a/plugins/public-post-preview/js/src/components/preview-toggle/index.js +++ b/plugins/public-post-preview/js/src/components/preview-toggle/index.js @@ -14,9 +14,8 @@ import { import { Component, createRef, - Fragment, } from '@wordpress/element'; -import { withSelect } from '@wordpress/data'; +import { withSelect, withDispatch } from '@wordpress/data'; import { PluginPostStatusInfo } from '@wordpress/edit-post'; import { ifCondition, compose } from '@wordpress/compose'; @@ -49,6 +48,8 @@ const pluginPostStatusInfoPreviewUrlInputWrapper = css` margin: 0; ` +const ClipboardIcon = + class PreviewToggle extends Component { constructor( props ) { @@ -67,12 +68,48 @@ class PreviewToggle extends Component { } onChange( checked ) { - this.request( { - checked, - post_ID: this.props.postId - }, () => { - this.setState( { previewEnabled: ! this.state.previewEnabled } ); - } ) + const data = new window.FormData(); + data.append( 'checked', checked ); + data.append( 'post_ID', this.props.postId ); + + this.sendRequest( data) + .then( ( response ) => { + if ( response.status >= 200 && response.status < 300 ) { + return response; + } + + throw response; + } ) + .then( ( response ) => response.json() ) + .then( ( response ) => { + if ( ! response.success ) { + throw response; + } + + const previewEnabled = ! this.state.previewEnabled; + this.setState( { previewEnabled: previewEnabled } ); + + this.props.createNotice( + 'info', + previewEnabled ? __( 'Public preview enabled.', 'public-post-preview' ) : __( 'Public preview disabled.', 'public-post-preview' ), + { + id: 'public-post-preview', + isDismissible: true, + type: 'snackbar' + } + ); + } ) + .catch( () => { + this.props.createNotice( + 'error', + __( 'Error while changing the public preview status.', 'public-post-preview' ), + { + id: 'public-post-preview', + isDismissible: true, + type: 'snackbar' + } + ); + } ); } onPreviewUrlInputFocus() { @@ -80,16 +117,12 @@ class PreviewToggle extends Component { this.previewUrlInput.current.select(); } - request( data, callback ) { - jQuery.ajax( { - type: 'POST', - url: ajaxurl, - data: { - action: 'public-post-preview', - _ajax_nonce: DSPublicPostPreviewData.nonce, - ...data - }, - success: callback, + sendRequest( data ) { + data.append( 'action', 'public-post-preview' ); + data.append( '_ajax_nonce', DSPublicPostPreviewData.nonce ); + return window.fetch( ajaxurl, { + method: 'POST', + body: data, } ); } @@ -103,7 +136,7 @@ class PreviewToggle extends Component { const ariaCopyLabel = hasCopied ? __( 'Preview URL copied', 'public-post-preview' ) : __( 'Copy the preview URL', 'public-post-preview' ); return ( - + <> this.setState( { hasCopied: true } ) } onFinishCopy={ () => this.setState( { hasCopied: false } ) } aria-disabled={ hasCopied } - icon={ } + icon={ ClipboardIcon } />

@@ -138,7 +171,7 @@ class PreviewToggle extends Component {

} -
+ ); } } @@ -168,4 +201,9 @@ export default compose( [ 'private', ].indexOf( status ) === -1; } ), + withDispatch( ( dispatch ) => { + return { + createNotice: dispatch( 'core/notices' ).createNotice + }; + } ), ] )( PreviewToggle ); diff --git a/plugins/public-post-preview/languages/public-post-preview.php b/plugins/public-post-preview/languages/public-post-preview.php deleted file mode 100644 index 118fa0f8..00000000 --- a/plugins/public-post-preview/languages/public-post-preview.php +++ /dev/null @@ -1,19 +0,0 @@ -is_block_editor() ) || - ( function_exists( 'is_gutenberg_page' ) && is_gutenberg_page() ) - ) { + if ( get_current_screen()->is_block_editor() ) { + $script_dependencies_path = plugin_dir_path( __FILE__ ) . 'js/gutenberg-integration.deps.json'; + $script_dependencies = file_exists( $script_dependencies_path ) ? json_decode( file_get_contents( $script_dependencies_path ) ) : array(); wp_enqueue_script( 'public-post-preview-gutenberg', plugins_url( 'js/gutenberg-integration.js', __FILE__ ), - array( - 'lodash', - 'wp-compose', - 'wp-components', - 'wp-data', - 'wp-edit-post', - 'wp-element', - 'wp-i18n', - ), - '20181127', + $script_dependencies, + '20190720', true ); + wp_set_script_translations( 'public-post-preview-gutenberg', 'public-post-preview' ); + $post = get_post(); wp_localize_script( 'public-post-preview-gutenberg', @@ -117,15 +110,6 @@ class DS_Public_Post_Preview { 'nonce' => wp_create_nonce( 'public-post-preview_' . $post->ID ), ) ); - - if ( function_exists( 'gutenberg_get_jed_locale_data' ) ) { - $locale_data = gutenberg_get_jed_locale_data( 'public-post-preview' ); - wp_add_inline_script( - 'public-post-preview-gutenberg', - 'wp.i18n.setLocaleData( ' . wp_json_encode( $locale_data ) . ', "public-post-preview" );', - 'before' - ); - } } else { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; @@ -133,7 +117,7 @@ class DS_Public_Post_Preview { 'public-post-preview', plugins_url( "js/public-post-preview$suffix.js", __FILE__ ), array( 'jquery' ), - '20180914', + '20190713', true ); @@ -155,10 +139,10 @@ class DS_Public_Post_Preview { * * @param array $post_states An array of post display states. * @param WP_Post $post The current post object. - * @return Filtered array of post display states. + * @return array Filtered array of post display states. */ public static function display_preview_state( $post_states, $post ) { - if ( in_array( $post->ID, self::get_preview_post_ids() ) ) { + if ( in_array( (int) $post->ID, self::get_preview_post_ids(), true ) ) { $post_states['ppp_enabled'] = __( 'Public Preview', 'public-post-preview' ); } @@ -166,7 +150,7 @@ class DS_Public_Post_Preview { } /** - * Adds the checkbox to the submit metabox. + * Adds the checkbox to the submit meta box. * * @since 2.2.0 */ @@ -179,7 +163,7 @@ class DS_Public_Post_Preview { $post = get_post(); - if ( ! in_array( $post->post_type, $post_types ) ) { + if ( ! in_array( $post->post_type, $post_types, true ) ) { return false; } @@ -189,7 +173,7 @@ class DS_Public_Post_Preview { } // Post is already published. - if ( in_array( $post->post_status, self::get_published_statuses() ) ) { + if ( in_array( $post->post_status, self::get_published_statuses(), true ) ) { return false; } @@ -269,11 +253,11 @@ class DS_Public_Post_Preview { * @return string The generated public preview link. */ public static function get_preview_link( $post ) { - if ( 'page' == $post->post_type ) { + if ( 'page' === $post->post_type ) { $args = array( 'page_id' => $post->ID, ); - } elseif ( 'post' == $post->post_type ) { + } elseif ( 'post' === $post->post_type ) { $args = array( 'p' => $post->ID, ); @@ -317,18 +301,18 @@ class DS_Public_Post_Preview { } $preview_post_ids = self::get_preview_post_ids(); - $preview_post_id = $post->ID; + $preview_post_id = (int) $post->ID; - if ( empty( $_POST['public_post_preview'] ) && in_array( $preview_post_id, $preview_post_ids ) ) { + if ( empty( $_POST['public_post_preview'] ) && in_array( $preview_post_id, $preview_post_ids, true ) ) { $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id ); } elseif ( ! empty( $_POST['public_post_preview'] ) && ! empty( $_POST['original_post_status'] ) && - ! in_array( $_POST['original_post_status'], self::get_published_statuses() ) && - in_array( $post->post_status, self::get_published_statuses() ) + ! in_array( $_POST['original_post_status'], self::get_published_statuses(), true ) && + in_array( $post->post_status, self::get_published_statuses(), true ) ) { $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id ); - } elseif ( ! empty( $_POST['public_post_preview'] ) && ! in_array( $preview_post_id, $preview_post_ids ) ) { + } elseif ( ! empty( $_POST['public_post_preview'] ) && ! in_array( $preview_post_id, $preview_post_ids, true ) ) { $preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id ); } else { return false; // Nothing has changed. @@ -352,7 +336,7 @@ class DS_Public_Post_Preview { $disallowed_status = self::get_published_statuses(); $disallowed_status[] = 'trash'; - if ( in_array( $new_status, $disallowed_status ) ) { + if ( in_array( $new_status, $disallowed_status, true ) ) { return self::unregister_public_preview( $post->ID ); } @@ -372,7 +356,7 @@ class DS_Public_Post_Preview { $disallowed_status = self::get_published_statuses(); $disallowed_status[] = 'trash'; - if ( in_array( $post->post_status, $disallowed_status ) ) { + if ( in_array( $post->post_status, $disallowed_status, true ) ) { return self::unregister_public_preview( $post_id ); } @@ -388,9 +372,10 @@ class DS_Public_Post_Preview { * @return bool Returns false on a failure, true on a success. */ private static function unregister_public_preview( $post_id ) { + $post_id = (int) $post_id; $preview_post_ids = self::get_preview_post_ids(); - if ( ! in_array( $post_id, $preview_post_ids ) ) { + if ( ! in_array( $post_id, $preview_post_ids, true ) ) { return false; } @@ -402,8 +387,6 @@ class DS_Public_Post_Preview { /** * (Un)Registers a post for a public preview for an AJAX request. * - * Returns '0' on a failure, '1' on success. - * * @since 2.0.0 */ public static function ajax_register_public_preview() { @@ -417,15 +400,15 @@ class DS_Public_Post_Preview { wp_send_json_error( 'cannot_edit' ); } - if ( in_array( $post->post_status, self::get_published_statuses() ) ) { + if ( in_array( $post->post_status, self::get_published_statuses(), true ) ) { wp_send_json_error( 'invalid_post_status' ); } $preview_post_ids = self::get_preview_post_ids(); - if ( 'false' === $_POST['checked'] && in_array( $preview_post_id, $preview_post_ids ) ) { + if ( 'false' === $_POST['checked'] && in_array( $preview_post_id, $preview_post_ids, true ) ) { $preview_post_ids = array_diff( $preview_post_ids, (array) $preview_post_id ); - } elseif ( 'true' === $_POST['checked'] && ! in_array( $preview_post_id, $preview_post_ids ) ) { + } elseif ( 'true' === $_POST['checked'] && ! in_array( $preview_post_id, $preview_post_ids, true ) ) { $preview_post_ids = array_merge( $preview_post_ids, (array) $preview_post_id ); } else { wp_send_json_error( 'unknown_status' ); @@ -498,10 +481,10 @@ class DS_Public_Post_Preview { } if ( ! self::verify_nonce( get_query_var( '_ppp' ), 'public_post_preview_' . $post_id ) ) { - wp_die( __( 'The link has been expired!', 'public-post-preview' ) ); + wp_die( __( 'This link has expired!', 'public-post-preview' ) ); } - if ( ! in_array( $post_id, self::get_preview_post_ids() ) ) { + if ( ! in_array( $post_id, self::get_preview_post_ids(), true ) ) { wp_die( __( 'No public preview available!', 'public-post-preview' ) ); } @@ -544,10 +527,10 @@ class DS_Public_Post_Preview { remove_filter( 'posts_results', array( __CLASS__, 'set_post_to_publish' ), 10 ); if ( empty( $posts ) ) { - return; + return $posts; } - $post_id = $posts[0]->ID; + $post_id = (int) $posts[0]->ID; // If the post has gone live, redirect to it's proper permalink. self::maybe_redirect_to_published_post( $post_id ); @@ -574,11 +557,11 @@ class DS_Public_Post_Preview { * @return false False of post status is not a published status. */ private static function maybe_redirect_to_published_post( $post_id ) { - if ( ! in_array( get_post_status( $post_id ), self::get_published_statuses() ) ) { + if ( ! in_array( get_post_status( $post_id ), self::get_published_statuses(), true ) ) { return false; } - wp_redirect( get_permalink( $post_id ), 301 ); + wp_safe_redirect( get_permalink( $post_id ), 301 ); exit; } @@ -628,12 +611,12 @@ class DS_Public_Post_Preview { $i = self::nonce_tick(); // Nonce generated 0-12 hours ago. - if ( substr( wp_hash( $i . $action, 'nonce' ), -12, 10 ) == $nonce ) { + if ( substr( wp_hash( $i . $action, 'nonce' ), -12, 10 ) === $nonce ) { return 1; } // Nonce generated 12-24 hours ago. - if ( substr( wp_hash( ( $i - 1 ) . $action, 'nonce' ), -12, 10 ) == $nonce ) { + if ( substr( wp_hash( ( $i - 1 ) . $action, 'nonce' ), -12, 10 ) === $nonce ) { return 2; } @@ -642,25 +625,32 @@ class DS_Public_Post_Preview { } /** - * Returns the post ids which are registered for a public preview. + * Returns the post IDs which are registered for a public preview. * * @since 2.0.0 * - * @return array The post ids. (Empty array if no ids are registered.) + * @return array The post IDs. (Empty array if no IDs are registered.) */ private static function get_preview_post_ids() { - return get_option( 'public_post_preview', array() ); + $post_ids = get_option( 'public_post_preview', array() ); + $post_ids = array_map( 'intval', $post_ids ); + + return $post_ids; } /** - * Saves the post ids which are registered for a public preview. + * Saves the post IDs which are registered for a public preview. * * @since 2.0.0 * * @param array $post_ids List of post IDs that have a preview. - * @return array The post ids. (Empty array if no ids are registered.) + * @return array The post IDs. (Empty array if no IDs are registered.) */ private static function set_preview_post_ids( $post_ids = array() ) { + $post_ids = array_map( 'absint', $post_ids ); + $post_ids = array_filter( $post_ids ); + $post_ids = array_unique( $post_ids ); + return update_option( 'public_post_preview', $post_ids ); } diff --git a/plugins/public-post-preview/readme.txt b/plugins/public-post-preview/readme.txt index ebd6f194..abeb1cba 100644 --- a/plugins/public-post-preview/readme.txt +++ b/plugins/public-post-preview/readme.txt @@ -1,19 +1,20 @@ === Public Post Preview === Contributors: ocean90 -Tags: public, post, preview, posts, custom post types, draft -Requires at least: 4.6 -Tested up to: 5.0 -Stable tag: 2.8.0 +Tags: public, preview, posts, anonymous, drafts +Requires at least: 5.0 +Tested up to: 5.2 +Requires PHP: 5.6 +Stable tag: 2.9.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html -Enables you to give a link to anonymous users for public preview of a post before it is published. +Allow anonymous users to preview a draft of a post before it is published. == Description == -Enables you to give a link to anonymous users for public preview of a post (or any other public post type) before it is published. +Share a link to anonymous users to preview a draft of a post (or any other public post type) before it is published. -Have you ever been writing a post with the help of someone who does not have access to your blog and needed to give them the ability to preview it before publishing? This plugin takes care of that by generating an URL with an expiring nonce that can be given out for public preview. +Have you ever been writing a post with the help of someone who does not have access to your site and needed to give them the ability to preview it before publishing? This plugin takes care of that by generating an URL with an expiring nonce that can be given out for public preview. *Previously this plugin was maintained by [Matt Martz](http://profiles.wordpress.org/sivel/) and was an idea of [Jonathan Dingman](http://profiles.wordpress.org/jdingman/). Thanks to Hans Dinkelberg for his [photo](http://www.flickr.com/photos/uitdragerij/7516234430/).* @@ -40,8 +41,7 @@ To upload the plugin through WordPress, instead of FTP: == Screenshots == -1. Setting in block editor -2. Setting in classic editor +1. Edit Posts Page == Usage == * To enable a public post preview check the box below the edit post box. @@ -73,6 +73,15 @@ Or use the [Public Post Preview Configurator](https://wordpress.org/plugins/publ == Change Log == += 2.9.0 (2019-07-20): = +* Requires WordPress 5.0 +* Requires PHP 5.6 +* Adds notice (as Snackbar if supported) when changing preview status in block editor. +* Fixes incorrect status message in classic editor. +* Fixes grammar in expired link notice. Props [@garrett-eclipse](https://github.com/garrett-eclipse). +* Improves internal checks to be more strict. Props [@PatelUtkarsh](https://github.com/PatelUtkarsh). +* Removes deprecated i18n compatibility layer from Gutenberg plugin. + = 2.8.0 (2018-11-27): = * Add support for WordPress 5.0 and the new block editor. @@ -80,59 +89,4 @@ Or use the [Public Post Preview Configurator](https://wordpress.org/plugins/publ * Initial support for Gutenberg. * Block robots for public post previews. Props [@westonruter](https://github.com/westonruter). -= 2.6.0 (2017-04-27): = -* Make `DS_Public_Post_Preview::get_preview_link()` public. Props [@rcstr](https://github.com/rcstr). -* Send no-cache headers for public post previews. - -= 2.5.0 (2016-04-05): = -* Auto select preview link on focus. Props [@JeroenSormani](https://github.com/JeroenSormani). -* Remove preview status from posts which are trashed or after scheduled posts are published. -* Add support for paged posts. - -= 2.4.1 (2015-10-13): = -* Update text domain to support language packs. Translations are now managed via http://translate.wordpress.org/projects/wp-plugins/public-post-preview. - -= 2.4 (2014-08-21): = -* Supports EditFlow and custom statuses -* Disables comments and pings during public post preview -* Adds **Public Preview** to the list of display states used in the Posts list table -* Prevents flickering of link box on Post edit while loading - -= 2.3 (2013-11-18): = -* Introduces a filter `ppp_preview_link`. With the filter you can adjust the preview link. -* If a post has gone live, redirect to it's proper permalink. -* Adds the query var `_ppp` to WordPress SEO by Yoast whitelist. - -= 2.2 (2013-03-15): = -* Based on feedback I have removed the extra metabox and added the preview link to the main Publish metabox. -* Only show the checkbox if the post status/post type is good. -* Requires WordPress 3.5. - -= 2.1.1 (2012-09-19): = -* Sorry for the new update. Through a change in 2.1 a filter was applied to each query. The misplaced "The link has been expired!" message is now gone. Props Aki Björklund and Jonathan Channon. - -= 2.1 (2012-09-16): = -* Introduces a filter `ppp_nonce_life`. With the filter you can adjust the expiration of a link. By default a link has a lifetime of 48 hours. -* In some situations (still not sure when) the preview link is rewritten as a permalink which results in an error. The plugin now works in this situations too. - -= 2.0.1 (2012-07-25): = -* Makes the preview link copyable again - -= 2.0 (2012-07-23): = -* Support for all public post types -* Saves public preview status via an AJAX request -* I18n -* Requires at least WordPress 3.3 - -= 1.3 (2009-06-30): = -* Hook in earlier in the post selection process to fix PHP notices -* Add uninstall functionality to remove options from the options table - -= 1.2 (2009-03-30): = -* Fix preview URL for scheduled posts on sites with a permalink other than default activated. - -= 1.1 (2009-03-11): = -* Don't limit public previews to posts in draft or pending status. Just exclude posts in publish status. - -= 1.0 (2009-02-20): = -* Initial Public Release +For more see [CHANGELOG.md](https://github.com/ocean90/public-post-preview/blob/master/CHANGELOG.md). -- cgit v1.2.3