From e0f843cd8199821728a48e326a4fd433112fb628 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Mon, 9 Mar 2015 21:48:38 +0000 Subject: [PATCH] PressThis: - Filter and select the content on the PHP side. Then pass only the needed data to JS. - Add the suggested post title and contend directly to the HTML. - Standardise the data type names. - Some cleanup/reduction of the code in the bookmarklet. See #31373. git-svn-id: https://develop.svn.wordpress.org/trunk@31693 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/css/press-this.css | 5 + src/wp-admin/includes/class-wp-press-this.php | 348 ++++++++++++++---- src/wp-admin/js/bookmarklet.js | 42 +-- src/wp-admin/js/bookmarklet.min.js | 2 +- src/wp-admin/js/press-this.js | 298 ++------------- src/wp-includes/link-template.php | 2 +- 6 files changed, 334 insertions(+), 363 deletions(-) diff --git a/src/wp-admin/css/press-this.css b/src/wp-admin/css/press-this.css index f837685c07..35b26bb45f 100644 --- a/src/wp-admin/css/press-this.css +++ b/src/wp-admin/css/press-this.css @@ -1388,6 +1388,11 @@ html { margin: 0 auto; } +/* Make the text inside the editor textarea white. Prevents a "flash" on loading the page */ +#pressthis { + color: #fff; +} + @media (min-width: 901px) { .editor { max-width: 760px; diff --git a/src/wp-admin/includes/class-wp-press-this.php b/src/wp-admin/includes/class-wp-press-this.php index f210b0990d..240c61f2a9 100644 --- a/src/wp-admin/includes/class-wp-press-this.php +++ b/src/wp-admin/includes/class-wp-press-this.php @@ -14,6 +14,10 @@ */ class WP_Press_This { + private $images = array(); + + private $embeds = array(); + /** * Constructor. * @@ -31,16 +35,10 @@ class WP_Press_This { * @return array Site settings. */ public function site_settings() { - $default_html = array( - 'quote' => '
%1$s
', - 'link' => '

' . _x( 'Source:', 'Used in Press This to indicate where the content comes from.' ) . - ' %2$s

', - ); - return array( // Used to trigger the bookmarklet update notice. // Needs to be set here and in get_shortcut_link() in wp-includes/link-template.php. - 'version' => '6', + 'version' => '7', /** * Filter whether or not Press This should redirect the user in the parent window upon save. @@ -50,16 +48,6 @@ class WP_Press_This { * @param bool false Whether to redirect in parent window or not. Default false. */ 'redirInParent' => apply_filters( 'press_this_redirect_in_parent', false ), - - /** - * Filter the default HTML for the Press This editor. - * - * @since 4.2.0 - * - * @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description - * or the selected content, and 'link' there %1$s is link href, %2$s is link text. - */ - 'html' => apply_filters( 'press_this_suggested_html', $default_html ), ); } @@ -435,7 +423,7 @@ class WP_Press_This { } private function _process_meta_entry( $meta_name, $meta_value, $data ) { - if ( preg_match( '/:?(title|description|keywords)$/', $meta_name ) ) { + if ( preg_match( '/:?(title|description|keywords|site_name)$/', $meta_name ) ) { $data['_meta'][ $meta_name ] = $meta_value; } else { switch ( $meta_name ) { @@ -444,12 +432,12 @@ class WP_Press_This { case 'og:video:secure_url': $meta_value = $this->_limit_embed( $meta_value ); - if ( ! isset( $data['_embed'] ) ) { - $data['_embed'] = array(); + if ( ! isset( $data['_embeds'] ) ) { + $data['_embeds'] = array(); } - if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_embed'] ) ) { - $data['_embed'][] = $meta_value; + if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_embeds'] ) ) { + $data['_embeds'][] = $meta_value; } break; @@ -461,12 +449,12 @@ class WP_Press_This { case 'twitter:image': $meta_value = $this->_limit_img( $meta_value ); - if ( ! isset( $data['_img'] ) ) { - $data['_img'] = array(); + if ( ! isset( $data['_images'] ) ) { + $data['_images'] = array(); } - if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_img'] ) ) { - $data['_img'][] = $meta_value; + if ( ! empty( $meta_value ) && ! in_array( $meta_value, $data['_images'] ) ) { + $data['_images'][] = $meta_value; } break; @@ -477,7 +465,7 @@ class WP_Press_This { } /** - * Fetches and parses _meta, _img, and _links data from the source. + * Fetches and parses _meta, _images, and _links data from the source. * * @since 4.2.0 * @access public @@ -521,8 +509,8 @@ class WP_Press_This { } // Fetch and gather data. - if ( empty( $data['_img'] ) ) { - $data['_img'] = array(); + if ( empty( $data['_images'] ) ) { + $data['_images'] = array(); } if ( preg_match_all( '/]+>/', $source_content, $matches ) ) { @@ -537,16 +525,16 @@ class WP_Press_This { if ( preg_match( '/src=(\'|")([^\'"]+)\\1/i', $value, $new_matches ) ) { $src = $this->_limit_img( $new_matches[2] ); - if ( ! empty( $src ) && ! in_array( $src, $data['_img'] ) ) { - $data['_img'][] = $src; + if ( ! empty( $src ) && ! in_array( $src, $data['_images'] ) ) { + $data['_images'][] = $src; } } } } // Fetch and gather