mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-03 06:57:35 +01:00
PressThis v2, first run. Props michael-arestad, stephdau, marcelomazza, DrewAPicture, iseulde, afercia, kraftbj, rachelbaker, AramZS, dd32. See #31373.
Built from https://develop.svn.wordpress.org/trunk@31534 git-svn-id: http://core.svn.wordpress.org/trunk@31515 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8b180b9a46
commit
1857055bb8
@ -61,7 +61,8 @@ $core_actions_post = array(
|
||||
'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
|
||||
'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
|
||||
'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail',
|
||||
'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin'
|
||||
'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post',
|
||||
'press-this-add-category',
|
||||
);
|
||||
|
||||
// Register core Ajax calls.
|
||||
|
@ -684,6 +684,9 @@ table.form-table td .updated p {
|
||||
|
||||
.pressthis {
|
||||
margin: 20px 0;
|
||||
vertical-align: top;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.pressthis a,
|
||||
@ -748,6 +751,62 @@ table.form-table td .updated p {
|
||||
box-shadow: 0 10px 8px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.pressthis .button {
|
||||
margin-right: 10px;
|
||||
padding: 0;
|
||||
height: auto;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.pressthis button .dashicons {
|
||||
margin: 5px 7px 6px 8px;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.press-this-install {
|
||||
margin: 20px 0 0 0;
|
||||
padding: 0.7em 2em 1em;
|
||||
max-width: 520px;
|
||||
}
|
||||
|
||||
.press-this-install textarea {
|
||||
width: 100%;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.press-this-install h4 {
|
||||
margin: 2em 0 1em;
|
||||
}
|
||||
|
||||
/* to override the button class being applied */
|
||||
.pressthis .button.button {
|
||||
margin-right: 10px;
|
||||
padding: 0;
|
||||
height: auto;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.pressthis button .dashicons {
|
||||
margin: 5px 7px 6px 8px;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.press-this-install {
|
||||
margin: 20px 0 0 0;
|
||||
padding: 0.7em 2em 1em;
|
||||
max-width: 520px;
|
||||
}
|
||||
|
||||
.press-this-install textarea {
|
||||
width: 100%;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.press-this-install h4 {
|
||||
margin: 2em 0 1em;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
20.0 - Settings
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -684,6 +684,9 @@ table.form-table td .updated p {
|
||||
|
||||
.pressthis {
|
||||
margin: 20px 0;
|
||||
vertical-align: top;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.pressthis a,
|
||||
@ -748,6 +751,62 @@ table.form-table td .updated p {
|
||||
box-shadow: 0 10px 8px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.pressthis .button {
|
||||
margin-left: 10px;
|
||||
padding: 0;
|
||||
height: auto;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.pressthis button .dashicons {
|
||||
margin: 5px 8px 6px 7px;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.press-this-install {
|
||||
margin: 20px 0 0 0;
|
||||
padding: 0.7em 2em 1em;
|
||||
max-width: 520px;
|
||||
}
|
||||
|
||||
.press-this-install textarea {
|
||||
width: 100%;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.press-this-install h4 {
|
||||
margin: 2em 0 1em;
|
||||
}
|
||||
|
||||
/* to override the button class being applied */
|
||||
.pressthis .button.button {
|
||||
margin-left: 10px;
|
||||
padding: 0;
|
||||
height: auto;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.pressthis button .dashicons {
|
||||
margin: 5px 8px 6px 7px;
|
||||
color: #777;
|
||||
}
|
||||
|
||||
.press-this-install {
|
||||
margin: 20px 0 0 0;
|
||||
padding: 0.7em 2em 1em;
|
||||
max-width: 520px;
|
||||
}
|
||||
|
||||
.press-this-install textarea {
|
||||
width: 100%;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.press-this-install h4 {
|
||||
margin: 2em 0 1em;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
20.0 - Settings
|
||||
------------------------------------------------------------------------------*/
|
||||
|
2
wp-admin/css/login-rtl.min.css
vendored
2
wp-admin/css/login-rtl.min.css
vendored
File diff suppressed because one or more lines are too long
2
wp-admin/css/login.min.css
vendored
2
wp-admin/css/login.min.css
vendored
File diff suppressed because one or more lines are too long
123
wp-admin/css/press-this-editor-rtl.css
Normal file
123
wp-admin/css/press-this-editor-rtl.css
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
Press This TinyMCE editor styles :)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Links
|
||||
*/
|
||||
@import url("//fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,600,700");
|
||||
a {
|
||||
color: #0074a2;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #0074a2;
|
||||
}
|
||||
|
||||
a:hover,
|
||||
a:focus,
|
||||
a:active {
|
||||
color: #2ea2cc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists
|
||||
*/
|
||||
ul,
|
||||
ol {
|
||||
margin: 0 3em 1.5em 0;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
ol {
|
||||
list-style: decimal;
|
||||
}
|
||||
|
||||
li > ul,
|
||||
li > ol {
|
||||
margin-bottom: 0;
|
||||
margin-right: 1.5em;
|
||||
}
|
||||
|
||||
dt {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
dd {
|
||||
margin: 0 1.5em 1.5em;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Media
|
||||
*
|
||||
* Basic image and object styles
|
||||
*/
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* Makes sure embeds and iframes fit inside their containers */
|
||||
embed,
|
||||
iframe,
|
||||
object {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TinyMCE styles
|
||||
*
|
||||
* Pretty dang good.
|
||||
*/
|
||||
body {
|
||||
color: #404040;
|
||||
font-family: "Open Sans", Helvetica, Arial, sans-serif;
|
||||
font-size: 20px;
|
||||
font-weight: 400;
|
||||
line-height: 1.6;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
body#tinymce {
|
||||
padding-top: 30px !important;
|
||||
}
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
body {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 320px) {
|
||||
body {
|
||||
margin: 0 15px;
|
||||
}
|
||||
}
|
||||
|
||||
#tinymce b,
|
||||
#tinymce strong {
|
||||
/* overrides TinyMCE's !important. Woohoo. */
|
||||
font-weight: 700 !important;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 1em 1.5em;
|
||||
color: #9ea7af;
|
||||
font-size: em(25px);
|
||||
font-style: italic;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
blockquote {
|
||||
margin: 1.5em 1em;
|
||||
}
|
||||
}
|
||||
|
||||
ul,
|
||||
ol {
|
||||
margin: 0 .75em 1.5em 0;
|
||||
}
|
123
wp-admin/css/press-this-editor.css
Normal file
123
wp-admin/css/press-this-editor.css
Normal file
@ -0,0 +1,123 @@
|
||||
/*
|
||||
Press This TinyMCE editor styles :)
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Links
|
||||
*/
|
||||
@import url("//fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,600,700");
|
||||
a {
|
||||
color: #0074a2;
|
||||
}
|
||||
|
||||
a:visited {
|
||||
color: #0074a2;
|
||||
}
|
||||
|
||||
a:hover,
|
||||
a:focus,
|
||||
a:active {
|
||||
color: #2ea2cc;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Lists
|
||||
*/
|
||||
ul,
|
||||
ol {
|
||||
margin: 0 0 1.5em 3em;
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style: disc;
|
||||
}
|
||||
|
||||
ol {
|
||||
list-style: decimal;
|
||||
}
|
||||
|
||||
li > ul,
|
||||
li > ol {
|
||||
margin-bottom: 0;
|
||||
margin-left: 1.5em;
|
||||
}
|
||||
|
||||
dt {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
dd {
|
||||
margin: 0 1.5em 1.5em;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Media
|
||||
*
|
||||
* Basic image and object styles
|
||||
*/
|
||||
img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
|
||||
/* Makes sure embeds and iframes fit inside their containers */
|
||||
embed,
|
||||
iframe,
|
||||
object {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* TinyMCE styles
|
||||
*
|
||||
* Pretty dang good.
|
||||
*/
|
||||
body {
|
||||
color: #404040;
|
||||
font-family: "Open Sans", Helvetica, Arial, sans-serif;
|
||||
font-size: 20px;
|
||||
font-weight: 400;
|
||||
line-height: 1.6;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
body#tinymce {
|
||||
padding-top: 30px !important;
|
||||
}
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
body {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
@media (max-width: 320px) {
|
||||
body {
|
||||
margin: 0 15px;
|
||||
}
|
||||
}
|
||||
|
||||
#tinymce b,
|
||||
#tinymce strong {
|
||||
/* overrides TinyMCE's !important. Woohoo. */
|
||||
font-weight: 700 !important;
|
||||
}
|
||||
|
||||
blockquote {
|
||||
margin: 1em 1.5em;
|
||||
color: #9ea7af;
|
||||
font-size: em(25px);
|
||||
font-style: italic;
|
||||
}
|
||||
@media (max-width: 900px) {
|
||||
blockquote {
|
||||
margin: 1.5em 1em;
|
||||
}
|
||||
}
|
||||
|
||||
ul,
|
||||
ol {
|
||||
margin: 0 0 1.5em .75em;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -7,7 +7,6 @@
|
||||
@import url(revisions-rtl.css);
|
||||
@import url(media-rtl.css);
|
||||
@import url(themes-rtl.css);
|
||||
@import url(press-this-rtl.css);
|
||||
@import url(about-rtl.css);
|
||||
@import url(nav-menus-rtl.css);
|
||||
@import url(widgets-rtl.css);
|
||||
|
2
wp-admin/css/wp-admin-rtl.min.css
vendored
2
wp-admin/css/wp-admin-rtl.min.css
vendored
File diff suppressed because one or more lines are too long
@ -7,7 +7,6 @@
|
||||
@import url(revisions.css);
|
||||
@import url(media.css);
|
||||
@import url(themes.css);
|
||||
@import url(press-this.css);
|
||||
@import url(about.css);
|
||||
@import url(nav-menus.css);
|
||||
@import url(widgets.css);
|
||||
|
2
wp-admin/css/wp-admin.min.css
vendored
2
wp-admin/css/wp-admin.min.css
vendored
File diff suppressed because one or more lines are too long
@ -2954,3 +2954,29 @@ function wp_ajax_update_plugin() {
|
||||
|
||||
wp_send_json_success( $status );
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for saving a post from Ptrss This.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
function wp_ajax_press_this_save_post() {
|
||||
if ( empty( $GLOBALS['wp_press_this'] ) ) {
|
||||
include( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
|
||||
}
|
||||
|
||||
$GLOBALS['wp_press_this']->save_post();
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for creating new category from Ptrss This.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
function wp_ajax_press_this_add_category() {
|
||||
if ( empty( $GLOBALS['wp_press_this'] ) ) {
|
||||
include( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
|
||||
}
|
||||
|
||||
$GLOBALS['wp_press_this']->add_category();
|
||||
}
|
||||
|
892
wp-admin/includes/class-wp-press-this.php
Normal file
892
wp-admin/includes/class-wp-press-this.php
Normal file
@ -0,0 +1,892 @@
|
||||
<?php
|
||||
/**
|
||||
* Press This class and display functionality
|
||||
*
|
||||
* @package WordPress
|
||||
* @subpackage Press_This
|
||||
* @since 4.2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Press This class
|
||||
*
|
||||
* @since 4.2.0
|
||||
*/
|
||||
class WP_Press_This {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* App and site settings data, including i18n strings for the client-side.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @return array Site settings.
|
||||
*/
|
||||
public function site_settings() {
|
||||
$supported_formats = get_theme_support( 'post-formats' );
|
||||
$post_formats = array();
|
||||
|
||||
if ( ! empty( $supported_formats[0] ) && is_array( $supported_formats[0] ) ) {
|
||||
$post_formats[0] = __( 'Standard' );
|
||||
foreach ( $supported_formats[0] as $post_format ) {
|
||||
$post_formats[ $post_format ] = esc_html( get_post_format_string( $post_format ) );
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'version' => 5,
|
||||
'post_formats' => $post_formats,
|
||||
|
||||
/**
|
||||
* Filter whether or not Press This should redirect the user in the parent window upon save.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param bool $redir_in_parent Whether to redirect in parent window or not. Default false.
|
||||
*/
|
||||
'redir_in_parent' => apply_filters( 'press_this_redirect_in_parent', __return_false() ),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the sources images and save them locally, fr posterity, unless we can't.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @param int $post_id Post ID.
|
||||
* @param string $content Optional. Current expected markup for Press This. Default empty.
|
||||
* @return string New markup with old image URLs replaced with the local attachment ones if swapped.
|
||||
*/
|
||||
public function side_load_images( $post_id, $content = '' ) {
|
||||
$new_content = $content;
|
||||
|
||||
preg_match_all( '/<img [^>]+>/', $content, $matches );
|
||||
|
||||
if ( ! empty( $matches ) && current_user_can( 'upload_files' ) ) {
|
||||
foreach ( (array) $matches[0] as $key => $image ) {
|
||||
preg_match( '/src=["\']{1}([^"\']+)["\']{1}/', stripslashes( $image ), $url_matches );
|
||||
|
||||
if ( empty( $url_matches[1] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$image_url = $url_matches[1];
|
||||
|
||||
// Don't try to sideload a file without a file extension, leads to WP upload error.
|
||||
if ( ! preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $image_url ) )
|
||||
continue;
|
||||
|
||||
// See if files exist in content - we don't want to upload non-used selected files.
|
||||
if ( false !== strpos( $new_content, htmlspecialchars( $image_url ) ) ) {
|
||||
|
||||
// Sideload image, which ives us a new image tag, strip the empty alt that comes with it.
|
||||
$upload = str_replace( ' alt=""', '', media_sideload_image( $image_url, $post_id ) );
|
||||
|
||||
// Preserve assigned class, id, width, height and alt attributes.
|
||||
if ( preg_match_all( '/(class|width|height|id|alt)=\\\?(\"|\')[^"\']+\\\?(\2)/', $image, $attr_matches )
|
||||
&& is_array( $attr_matches[0] )
|
||||
) {
|
||||
foreach ( $attr_matches[0] as $attr ) {
|
||||
$upload = str_replace( '<img', '<img ' . $attr, $upload );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Replace the POSTED content <img> with correct uploaded ones.
|
||||
* Regex contains fix for Magic Quotes.
|
||||
*/
|
||||
if ( ! is_wp_error( $upload ) ) {
|
||||
$new_content = str_replace( $image, $upload, $new_content );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Error handling for media_sideload, send original content back.
|
||||
if ( is_wp_error( $new_content ) ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
return $new_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for saving the post as draft or published.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*/
|
||||
public function save_post() {
|
||||
if ( empty( $_POST['pressthis-nonce'] ) || ! wp_verify_nonce( $_POST['pressthis-nonce'], 'press-this' ) ) {
|
||||
wp_send_json_error( array( 'errorMessage' => __( 'Cheatin’ uh?' ) ) );
|
||||
}
|
||||
|
||||
if ( empty( $_POST['post_ID'] ) || ! $post_id = (int) $_POST['post_ID'] ) {
|
||||
wp_send_json_error( array( 'errorMessage' => __( 'Missing post ID.' ) ) );
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'edit_post', $post_id ) ) {
|
||||
wp_send_json_error( array( 'errorMessage' => __( 'Cheatin’ uh?' ) ) );
|
||||
}
|
||||
|
||||
$post = array(
|
||||
'ID' => $post_id,
|
||||
'post_title' => ( ! empty( $_POST['title'] ) ) ? sanitize_text_field( trim( $_POST['title'] ) ) : '',
|
||||
'post_content' => ( ! empty( $_POST['pressthis'] ) ) ? trim( $_POST['pressthis'] ) : '',
|
||||
'post_type' => 'post',
|
||||
'post_status' => 'draft',
|
||||
'post_format' => ( ! empty( $_POST['post_format'] ) ) ? sanitize_text_field( $_POST['post_format'] ) : '',
|
||||
'tax_input' => ( ! empty( $_POST['tax_input'] ) ) ? $_POST['tax_input'] : array(),
|
||||
'post_category' => ( ! empty( $_POST['post_category'] ) ) ? $_POST['post_category'] : array(),
|
||||
);
|
||||
|
||||
if ( ! empty( $_POST['post_status'] ) && 'publish' === $_POST['post_status'] ) {
|
||||
if ( current_user_can( 'publish_posts' ) ) {
|
||||
$post['post_status'] = 'publish';
|
||||
} else {
|
||||
$post['post_status'] = 'pending';
|
||||
}
|
||||
}
|
||||
|
||||
$new_content = $this->side_load_images( $post_id, $post['post_content'] );
|
||||
|
||||
if ( ! is_wp_error( $new_content ) ) {
|
||||
$post['post_content'] = $new_content;
|
||||
}
|
||||
|
||||
$updated = wp_update_post( $post, true );
|
||||
|
||||
if ( is_wp_error( $updated ) || intval( $updated ) < 1 ) {
|
||||
wp_send_json_error( array( 'errorMessage' => __( 'Error while saving the post. Please try again later.' ) ) );
|
||||
} else {
|
||||
if ( isset( $post['post_format'] ) ) {
|
||||
if ( current_theme_supports( 'post-formats', $post['post_format'] ) ) {
|
||||
set_post_format( $post_id, $post['post_format'] );
|
||||
} elseif ( $post['post_format'] ) {
|
||||
set_post_format( $post_id, false );
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'publish' === get_post_status( $post_id ) ) {
|
||||
/**
|
||||
* Filter the URL to redirect to when Press This saves.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param string $url Redirect URL. If `$status` is 'publish', this will be the post permalink.
|
||||
* Otherwise, the post edit URL will be used.
|
||||
* @param int $post_id Post ID.
|
||||
* @param string $status Post status.
|
||||
*/
|
||||
$redirect = apply_filters( 'press_this_save_redirect', get_post_permalink( $post_id ), $post_id, $post['post_status'] );
|
||||
} else {
|
||||
/** This filter is documented in wp-admin/includes/class-wp-press-this.php */
|
||||
$redirect = apply_filters( 'press_this_save_redirect', get_edit_post_link( $post_id, 'raw' ), $post_id, $post['post_status'] );
|
||||
}
|
||||
|
||||
wp_send_json_success( array( 'redirect' => $redirect ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AJAX handler for adding a new category.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*/
|
||||
public function add_category() {
|
||||
if ( false === wp_verify_nonce( $_POST['new_cat_nonce'], 'add-category' ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$taxonomy = get_taxonomy( 'category' );
|
||||
|
||||
if ( ! current_user_can( $taxonomy->cap->edit_terms ) || empty( $_POST['name'] ) ) {
|
||||
wp_send_json_error();
|
||||
}
|
||||
|
||||
$parent = isset( $_POST['parent'] ) && (int) $_POST['parent'] > 0 ? (int) $_POST['parent'] : 0;
|
||||
$names = explode( ',', $_POST['name'] );
|
||||
$added = $data = array();
|
||||
|
||||
foreach ( $names as $cat_name ) {
|
||||
$cat_name = trim( $cat_name );
|
||||
$cat_nicename = sanitize_title( $cat_name );
|
||||
|
||||
if ( empty( $cat_nicename ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// @todo Find a more performant to check existence, maybe get_term() with a separate parent check.
|
||||
if ( ! $cat_id = term_exists( $cat_name, $taxonomy->name, $parent ) ) {
|
||||
$cat_id = wp_insert_term( $cat_name, $taxonomy->name, array( 'parent' => $parent ) );
|
||||
}
|
||||
|
||||
if ( is_wp_error( $cat_id ) ) {
|
||||
continue;
|
||||
} elseif ( is_array( $cat_id ) ) {
|
||||
$cat_id = $cat_id['term_id'];
|
||||
}
|
||||
|
||||
$added[] = $cat_id;
|
||||
}
|
||||
|
||||
if ( empty( $added ) ) {
|
||||
wp_send_json_error( array( 'errorMessage' => __( 'This category cannot be added. Please change the name and try again.' ) ) );
|
||||
}
|
||||
|
||||
foreach ( $added as $new_cat_id ) {
|
||||
$new_cat = get_category( $new_cat_id );
|
||||
|
||||
if ( is_wp_error( $new_cat ) ) {
|
||||
wp_send_json_error( array( 'errorMessage' => __( 'Error while adding the category. Please try again later.' ) ) );
|
||||
}
|
||||
|
||||
$data[] = array(
|
||||
'term_id' => $new_cat->term_id,
|
||||
'name' => $new_cat->name,
|
||||
'parent' => $new_cat->parent,
|
||||
);
|
||||
}
|
||||
wp_send_json_success( $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads the source's HTML via server-side call for the given URL.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $url URL to scan.
|
||||
* @return string Source's HTML sanitized markup
|
||||
*/
|
||||
public function fetch_source_html( $url ) {
|
||||
// Download source page to tmp file.
|
||||
$source_tmp_file = ( ! empty( $url ) ) ? download_url( $url ) : '';
|
||||
$source_content = '';
|
||||
|
||||
if ( ! is_wp_error( $source_tmp_file ) && file_exists( $source_tmp_file ) ) {
|
||||
// Get the content of the source page from the tmp file..
|
||||
|
||||
$source_content = wp_kses(
|
||||
file_get_contents( $source_tmp_file ),
|
||||
array(
|
||||
'img' => array(
|
||||
'src' => array(),
|
||||
),
|
||||
'iframe' => array(
|
||||
'src' => array(),
|
||||
),
|
||||
'link' => array(
|
||||
'rel' => array(),
|
||||
'itemprop' => array(),
|
||||
'href' => array(),
|
||||
),
|
||||
'meta' => array(
|
||||
'property' => array(),
|
||||
'name' => array(),
|
||||
'content' => array(),
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// All done with backward compatibility. Let's do some cleanup, for good measure :)
|
||||
unlink( $source_tmp_file );
|
||||
|
||||
} else if ( is_wp_error( $source_tmp_file ) ) {
|
||||
$source_content = new WP_Error( 'upload-error', sprintf( __( 'Error: %s' ), sprintf( __( 'Could not download the source URL (native error: %s).' ), $source_tmp_file->get_error_message() ) ) );
|
||||
} else if ( ! file_exists( $source_tmp_file ) ) {
|
||||
$source_content = new WP_Error( 'no-local-file', sprintf( __( 'Error: %s' ), __( 'Could not save or locate the temporary download file for the source URL.' ) ) );
|
||||
}
|
||||
|
||||
return $source_content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches and parses _meta, _img, and _links data from the source.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $url URL to scan.
|
||||
* @param array $data Optional. Existing data array if you have one. Default empty array.
|
||||
* @return array New data array.
|
||||
*/
|
||||
public function source_data_fetch_fallback( $url, $data = array() ) {
|
||||
if ( empty( $url ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
// Download source page to tmp file.
|
||||
$source_content = $this->fetch_source_html( $url );
|
||||
if ( is_wp_error( $source_content ) ) {
|
||||
return array( 'errors' => $source_content->get_error_messages() );
|
||||
}
|
||||
|
||||
// Fetch and gather <img> data.
|
||||
if ( empty( $data['_img'] ) ) {
|
||||
$data['_img'] = array();
|
||||
}
|
||||
|
||||
if ( preg_match_all( '/<img (.+)[\s]?\/>/', $source_content, $matches ) ) {
|
||||
if ( ! empty( $matches[0] ) ) {
|
||||
foreach ( $matches[0] as $value ) {
|
||||
if ( preg_match( '/<img[^>]+src="([^"]+)"[^>]+\/>/', $value, $new_matches ) ) {
|
||||
if ( ! in_array( $new_matches[1], $data['_img'] ) ) {
|
||||
$data['_img'][] = $new_matches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and gather <iframe> data.
|
||||
if ( empty( $data['_embed'] ) ) {
|
||||
$data['_embed'] = array();
|
||||
}
|
||||
|
||||
if ( preg_match_all( '/<iframe (.+)[\s][^>]*>/', $source_content, $matches ) ) {
|
||||
if ( ! empty( $matches[0] ) ) {
|
||||
foreach ( $matches[0] as $value ) {
|
||||
if ( preg_match( '/<iframe[^>]+src=(\'|")([^"]+)(\'|")/', $value, $new_matches ) ) {
|
||||
if ( ! in_array( $new_matches[2], $data['_embed'] ) ) {
|
||||
if ( preg_match( '/\/\/www\.youtube\.com\/embed\/([^\?]+)\?.+$/', $new_matches[2], $src_matches ) ) {
|
||||
$data['_embed'][] = 'https://www.youtube.com/watch?v=' . $src_matches[1];
|
||||
} else if ( preg_match( '/\/\/player\.vimeo\.com\/video\/([\d]+)([\?\/]{1}.*)?$/', $new_matches[2], $src_matches ) ) {
|
||||
$data['_embed'][] = 'https://vimeo.com/' . (int) $src_matches[1];
|
||||
} else if ( preg_match( '/\/\/vine\.co\/v\/([^\/]+)\/embed/', $new_matches[2], $src_matches ) ) {
|
||||
$data['_embed'][] = 'https://vine.co/v/' . $src_matches[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and gather <meta> data.
|
||||
if ( empty( $data['_meta'] ) ) {
|
||||
$data['_meta'] = array();
|
||||
}
|
||||
|
||||
if ( preg_match_all( '/<meta ([^>]+)[\s]?\/?>/ ', $source_content, $matches ) ) {
|
||||
if ( ! empty( $matches[0] ) ) {
|
||||
foreach ( $matches[0] as $key => $value ) {
|
||||
if ( preg_match( '/<meta[^>]+(property|name)="(.+)"[^>]+content="(.+)"/', $value, $new_matches ) ) {
|
||||
if ( empty( $data['_meta'][ $new_matches[2] ] ) ) {
|
||||
if ( preg_match( '/:?(title|description|keywords)$/', $new_matches[2] ) ) {
|
||||
$data['_meta'][ $new_matches[2] ] = str_replace( ''', "'", str_replace( '"', '', html_entity_decode( $new_matches[3] ) ) );
|
||||
} else {
|
||||
$data['_meta'][ $new_matches[2] ] = $new_matches[3];
|
||||
if ( 'og:url' == $new_matches[2] ) {
|
||||
if ( false !== strpos( $new_matches[3], '//www.youtube.com/watch?' )
|
||||
|| false !== strpos( $new_matches[3], '//www.dailymotion.com/video/' )
|
||||
|| preg_match( '/\/\/vimeo\.com\/[\d]+$/', $new_matches[3] )
|
||||
|| preg_match( '/\/\/soundcloud\.com\/.+$/', $new_matches[3] )
|
||||
|| preg_match( '/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/', $new_matches[3] )
|
||||
|| preg_match( '/\/\/vine\.co\/v\/[^\/]+/', $new_matches[3] ) ) {
|
||||
if ( ! in_array( $new_matches[3], $data['_embed'] ) ) {
|
||||
$data['_embed'][] = $new_matches[3];
|
||||
}
|
||||
}
|
||||
} else if ( 'og:video' == $new_matches[2] || 'og:video:secure_url' == $new_matches[2] ) {
|
||||
if ( preg_match( '/\/\/www\.youtube\.com\/v\/([^\?]+)/', $new_matches[3], $src_matches ) ) {
|
||||
if ( ! in_array( 'https://www.youtube.com/watch?v=' . $src_matches[1], $data['_embed'] ) ) {
|
||||
$data['_embed'][] = 'https://www.youtube.com/watch?v=' . $src_matches[1];
|
||||
}
|
||||
} else if ( preg_match( '/\/\/vimeo.com\/moogaloop\.swf\?clip_id=([\d]+)$/', $new_matches[3], $src_matches ) ) {
|
||||
if ( ! in_array( 'https://vimeo.com/' . $src_matches[1], $data['_embed'] ) ) {
|
||||
$data['_embed'][] = 'https://vimeo.com/' . $src_matches[1];
|
||||
}
|
||||
}
|
||||
} else if ( 'og:image' == $new_matches[2] || 'og:image:secure_url' == $new_matches[2] ) {
|
||||
if ( ! in_array( $new_matches[3], $data['_img'] ) ) {
|
||||
$data['_img'][] = $new_matches[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch and gather <link> data
|
||||
if ( empty( $data['_links'] ) ) {
|
||||
$data['_links'] = array();
|
||||
}
|
||||
|
||||
if ( preg_match_all( '/<link ([^>]+)[\s]?\/>/', $source_content, $matches ) ) {
|
||||
if ( ! empty( $matches[0] ) ) {
|
||||
foreach ( $matches[0] as $key => $value ) {
|
||||
if ( preg_match( '/<link[^>]+(rel|itemprop)="([^"]+)"[^>]+href="([^"]+)"[^>]+\/>/', $value, $new_matches ) ) {
|
||||
if ( 'alternate' == $new_matches[2] || 'thumbnailUrl' == $new_matches[2] || 'url' == $new_matches[2] ) {
|
||||
if ( empty( $data['_links'][ $new_matches[2] ] ) ) {
|
||||
$data['_links'][ $new_matches[2] ] = $new_matches[3];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles backward-compat with the legacy version of Press This by supporting its query string params.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function merge_or_fetch_data() {
|
||||
// Merge $_POST and $_GET, as appropriate ($_POST > $_GET), to remain backward compatible.
|
||||
$data = array_merge_recursive( $_POST, $_GET );
|
||||
|
||||
// Get the legacy QS params, or equiv POST data
|
||||
$data['u'] = ( ! empty( $data['u'] ) && preg_match( '/^https?:/', $data['u'] ) ) ? $data['u'] : '';
|
||||
$data['s'] = ( ! empty( $data['s'] ) ) ? $data['s'] : '';
|
||||
$data['t'] = ( ! empty( $data['t'] ) ) ? $data['t'] : '';
|
||||
|
||||
/**
|
||||
* Filter whether to enable in-source media discovery in Press This.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param bool $enable Whether to enable media discovery.
|
||||
*/
|
||||
if ( apply_filters( 'enable_press_this_media_discovery', __return_true() ) ) {
|
||||
/*
|
||||
* If no _meta (a new thing) was passed via $_POST, fetch data from source as fallback,
|
||||
* makes PT fully backward compatible
|
||||
*/
|
||||
if ( empty( $data['_meta'] ) && ! empty( $data['u'] ) ) {
|
||||
$data = $this->source_data_fetch_fallback( $data['u'], $data );
|
||||
}
|
||||
} else {
|
||||
if ( ! empty( $data['_img'] ) ) {
|
||||
$data['_img'] = array();
|
||||
}
|
||||
if ( ! empty( $data['_embed'] ) ) {
|
||||
$data['_embed'] = array();
|
||||
}
|
||||
if ( ! empty( $data['_meta'] ) ) {
|
||||
$data['_meta'] = array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the Press This data array.
|
||||
*
|
||||
* @since 4.2.0
|
||||
*
|
||||
* @param array $data Press This Data array.
|
||||
*/
|
||||
return apply_filters( 'press_this_data', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds another stylesheet inside TinyMCE.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @param string $styles URL to editor stylesheet.
|
||||
* @return string Possibly modified stylesheets list.
|
||||
*/
|
||||
public function add_editor_style( $styles ) {
|
||||
if ( ! empty( $styles ) ) {
|
||||
$styles .= ',';
|
||||
}
|
||||
return $styles . admin_url( 'css/press-this-editor.css' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the post format selection HTML.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
function post_formats_html( $post ) {
|
||||
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) {
|
||||
$post_formats = get_theme_support( 'post-formats' );
|
||||
|
||||
if ( is_array( $post_formats[0] ) ) {
|
||||
$post_format = get_post_format( $post->ID );
|
||||
|
||||
if ( ! $post_format ) {
|
||||
$post_format = '0';
|
||||
}
|
||||
|
||||
// Add in the current one if it isn't there yet, in case the current theme doesn't support it.
|
||||
if ( $post_format && ! in_array( $post_format, $post_formats[0] ) ) {
|
||||
$post_formats[0][] = $post_format;
|
||||
}
|
||||
|
||||
?>
|
||||
<div id="post-formats-select">
|
||||
<input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> />
|
||||
<label for="post-format-0" class="post-format-icon post-format-standard"><?php echo get_post_format_string( 'standard' ); ?></label>
|
||||
<?php
|
||||
|
||||
foreach ( $post_formats[0] as $format ) {
|
||||
$attr_format = esc_attr( $format );
|
||||
?>
|
||||
<br />
|
||||
<input type="radio" name="post_format" class="post-format" id="post-format-<?php echo $attr_format; ?>" value="<?php echo $attr_format; ?>" <?php checked( $post_format, $format ); ?> />
|
||||
<label for="post-format-<?php echo $attr_format ?>" class="post-format-icon post-format-<?php echo $attr_format; ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the categories HTML.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
function categories_html( $post ) {
|
||||
$taxonomy = get_taxonomy( 'category' );
|
||||
|
||||
if ( current_user_can( $taxonomy->cap->edit_terms ) ) {
|
||||
?>
|
||||
<button type="button" class="add-cat-toggle button-subtle">
|
||||
<span class="dashicons dashicons-plus"></span>
|
||||
</button>
|
||||
<div class="add-category is-hidden">
|
||||
<label class="screen-reader-text" for="new-category"><?php echo $taxonomy->labels->add_new_item; ?></label>
|
||||
<input type="text" id="new-category" class="add-category-name" placeholder="<?php echo esc_attr( $taxonomy->labels->new_item_name ); ?>" value="" aria-required="true">
|
||||
<label class="screen-reader-text" for="new-category-parent"><?php echo $taxonomy->labels->parent_item_colon; ?></label>
|
||||
<div class="postform-wrapper">
|
||||
<?php
|
||||
wp_dropdown_categories( array(
|
||||
'taxonomy' => 'category',
|
||||
'hide_empty' => 0,
|
||||
'name' => 'new-category-parent',
|
||||
'orderby' => 'name',
|
||||
'hierarchical' => 1,
|
||||
'show_option_none' => '— ' . $taxonomy->labels->parent_item . ' —'
|
||||
) );
|
||||
?>
|
||||
</div>
|
||||
<button type="button" class="button add-cat-submit"><?php _e( 'Add' ); ?></button>
|
||||
</div>
|
||||
<?php } ?>
|
||||
<div class="categories-search-wrapper">
|
||||
<input id="categories-search" type="search" class="categories-search" placeholder="<?php esc_attr_e( 'Search categories' ) ?>">
|
||||
<label for="categories-search">
|
||||
<span class="dashicons dashicons-search"></span>
|
||||
</label>
|
||||
</div>
|
||||
<ul class="categories-select">
|
||||
<?php wp_terms_checklist( $post->ID, array( 'taxonomy' => 'category' ) ); ?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the tags HTML.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*
|
||||
* @param WP_Post $post Post object.
|
||||
*/
|
||||
function tags_html( $post ) {
|
||||
$taxonomy = get_taxonomy( 'post_tag' );
|
||||
$user_can_assign_terms = current_user_can( $taxonomy->cap->assign_terms );
|
||||
$esc_tags = get_terms_to_edit( $post->ID, 'post_tag' );
|
||||
|
||||
if ( ! $esc_tags || is_wp_error( $esc_tags ) ) {
|
||||
$esc_tags = '';
|
||||
}
|
||||
?>
|
||||
<div class="tagsdiv" id="post_tag">
|
||||
<div class="jaxtag">
|
||||
<input type="hidden" name="tax_input[post_tag]" class="the-tags" value="<?php echo $esc_tags; // escaped in get_terms_to_edit() ?>">
|
||||
|
||||
<?php
|
||||
if ( $user_can_assign_terms ) {
|
||||
?>
|
||||
<div class="ajaxtag hide-if-no-js">
|
||||
<label class="screen-reader-text" for="new-tag-post_tag"><?php _e( 'Tags' ); ?></label>
|
||||
<div class="taghint"><?php echo $taxonomy->labels->add_new_item; ?></div>
|
||||
<p>
|
||||
<input type="text" id="new-tag-post_tag" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
|
||||
<button type="button" class="button tagadd"><?php _e( 'Add' ); ?></button>
|
||||
</p>
|
||||
</div>
|
||||
<p class="howto">
|
||||
<?php echo $taxonomy->labels->separate_items_with_commas; ?>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="tagchecklist"></div>
|
||||
</div>
|
||||
<?php
|
||||
if ( $user_can_assign_terms ) {
|
||||
?>
|
||||
<p>
|
||||
<a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php echo $taxonomy->labels->choose_from_most_used; ?></a>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serves the app's base HTML, which in turns calls the load script.
|
||||
*
|
||||
* @since 4.2.0
|
||||
* @access public
|
||||
*/
|
||||
public function html() {
|
||||
global $wp_locale, $hook_suffix;
|
||||
|
||||
// Get data, new (POST) and old (GET).
|
||||
$data = $this->merge_or_fetch_data();
|
||||
|
||||
// Get site settings array/data.
|
||||
$site_settings = $this->site_settings();
|
||||
|
||||
// Set the passed data.
|
||||
$data['_version'] = $site_settings['version'];
|
||||
|
||||
// Add press-this-editor.css and remove theme's editor-style.css, if any.
|
||||
remove_editor_styles();
|
||||
|
||||
add_filter( 'mce_css', array( $this, 'add_editor_style' ) );
|
||||
|
||||
if ( ! empty( $GLOBALS['is_IE'] ) ) {
|
||||
@header( 'X-UA-Compatible: IE=edge' );
|
||||
}
|
||||
|
||||
@header( 'Content-Type: ' . get_option( 'html_type' ) . '; charset=' . get_option( 'blog_charset' ) );
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" <?php language_attributes(); ?>> <![endif]-->
|
||||
<!--[if IE 8]> <html class="lt-ie9" <?php language_attributes(); ?>> <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html <?php language_attributes(); ?>> <!--<![endif]-->
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="<?php esc_attr( bloginfo( 'html_type' ) ); ?>; charset=<?php echo esc_attr( get_option( 'blog_charset' ) ); ?>" />
|
||||
<meta name="viewport" content="width=device-width">
|
||||
<title><?php esc_html_e( 'Press This!' ) ?></title>
|
||||
|
||||
<script>
|
||||
window.wpPressThisData = <?php echo json_encode( $data ) ?>;
|
||||
window.wpPressThisConfig = <?php echo json_encode( $site_settings ) ?>;
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>',
|
||||
pagenow = 'press-this',
|
||||
typenow = 'post',
|
||||
adminpage = 'press-this-php',
|
||||
thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
|
||||
decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
|
||||
isRtl = <?php echo esc_js( (int) is_rtl() ); ?>;
|
||||
</script>
|
||||
|
||||
<?php
|
||||
/*
|
||||
* $post->ID is needed for the embed shortcode so we can show oEmbed previews in the editor.
|
||||
* Maybe find a way without it.
|
||||
*/
|
||||
$post = get_default_post_to_edit( 'post', true );
|
||||
$post_ID = (int) $post->ID;
|
||||
|
||||
wp_enqueue_style( 'press-this' );
|
||||
wp_enqueue_script( 'press-this' );
|
||||
wp_enqueue_script( 'json2' );
|
||||
wp_enqueue_media( array( 'post' => $post->ID ) );
|
||||
wp_enqueue_script( 'editor' );
|
||||
|
||||
$supports_formats = false;
|
||||
$post_format = 0;
|
||||
|
||||
if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) {
|
||||
$supports_formats = true;
|
||||
|
||||
if ( ! ( $post_format = get_post_format( $post->ID ) ) ) {
|
||||
$post_format = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_enqueue_scripts', $hook_suffix );
|
||||
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_print_styles' );
|
||||
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_print_scripts' );
|
||||
|
||||
?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="adminbar" class="adminbar">
|
||||
<h1 id="current-site" class="current-site">
|
||||
<span class="dashicons dashicons-wordpress"></span>
|
||||
<span><?php bloginfo( 'name' ); ?></span>
|
||||
</h1>
|
||||
<button type="button" class="options-open button-subtle">
|
||||
<span class="dashicons dashicons-tag"></span><span class="screen-reader-text"><?php _e( 'Show post options' ); ?></span>
|
||||
</button>
|
||||
<button type="button" class="options-close button-subtle is-hidden"><?php _e( 'Done' ); ?></button>
|
||||
</div>
|
||||
|
||||
<div id="scanbar" class="scan">
|
||||
<form method="GET">
|
||||
<input type="url" name="u" id="url-scan" class="scan-url" value="" placeholder="<?php esc_attr_e( 'Enter a URL to scan' ) ?>" />
|
||||
<input type="submit" name="url-scan-submit" id="url-scan-submit" class="scan-submit" value="<?php esc_attr_e( 'Scan' ) ?>" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<form id="pressthis-form" name="pressthis-form" method="POST" autocomplete="off">
|
||||
<input type="hidden" name="post_ID" id="post_ID" value="<?php echo esc_attr( $post_ID ); ?>" />
|
||||
<input type="hidden" name="action" value="press-this-save-post" />
|
||||
<input type="hidden" name="post_status" id="post_status" value="draft" />
|
||||
<?php
|
||||
wp_nonce_field( 'press-this', 'pressthis-nonce', false );
|
||||
wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false );
|
||||
?>
|
||||
<input type="hidden" name="title" id="title-field" value="" />
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="editor-wrapper">
|
||||
<div class="alerts">
|
||||
<p class="alert is-notice is-hidden should-upgrade-bookmarklet">
|
||||
<?php printf( __( 'You should upgrade <a href="%s" target="_blank">your bookmarklet</a> to the latest version!' ), admin_url( 'tools.php?page=press_this_options' ) ); ?>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div id='app-container' class="editor">
|
||||
<span id="title-container-label" class="post-title-placeholder" aria-hidden="true"><?php _e( 'Post title' ); ?></span>
|
||||
<h2 id="title-container" class="post-title" contenteditable="true" spellcheck="true" aria-label="<?php esc_attr_e( 'Post title' ); ?>" tabindex="0"></h2>
|
||||
<div id='featured-media-container' class="featured-container no-media">
|
||||
<div id='all-media-widget' class="all-media">
|
||||
<div id='all-media-container'></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
wp_editor( '', 'pressthis', array(
|
||||
'drag_drop_upload' => true,
|
||||
'editor_height' => 600,
|
||||
'media_buttons' => false,
|
||||
'teeny' => true,
|
||||
'tinymce' => array(
|
||||
'resize' => false,
|
||||
'wordpress_adv_hidden' => false,
|
||||
'add_unload_trigger' => false,
|
||||
'statusbar' => false,
|
||||
'autoresize_min_height' => 600,
|
||||
'wp_autoresize_on' => true,
|
||||
'plugins' => 'lists,media,paste,tabfocus,fullscreen,wordpress,wpautoresize,wpeditimage,wpgallery,wplink,wpview',
|
||||
'toolbar1' => 'bold,italic,bullist,numlist,blockquote,link,unlink',
|
||||
'toolbar2' => 'undo,redo',
|
||||
),
|
||||
'quicktags' => false,
|
||||
) );
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="options-panel is-off-screen is-hidden">
|
||||
<div class="post-options">
|
||||
|
||||
<?php if ( $supports_formats ) : ?>
|
||||
<button type="button" class="button-reset post-option">
|
||||
<span class="dashicons dashicons-admin-post"></span>
|
||||
<span class="post-option-title"><?php _e( 'Format' ); ?></span>
|
||||
<span class="post-option-contents" id="post-option-post-format"><?php echo esc_html( get_post_format_string( $post_format ) ); ?></span>
|
||||
<span class="dashicons dashicons-arrow-right-alt2"></span>
|
||||
</button>
|
||||
<?php endif; ?>
|
||||
|
||||
<button type="button" class="button-reset post-option">
|
||||
<span class="dashicons dashicons-category"></span>
|
||||
<span class="post-option-title"><?php _e( 'Categories' ); ?></span>
|
||||
<span class="post-option-contents" id="post-option-category"></span>
|
||||
<span class="dashicons dashicons-arrow-right-alt2"></span>
|
||||
</button>
|
||||
|
||||
<button type="button" class="button-reset post-option">
|
||||
<span class="dashicons dashicons-tag"></span>
|
||||
<span class="post-option-title"><?php _e( 'Tags' ); ?></span>
|
||||
<span class="post-option-contents" id="post-option-tags"></span>
|
||||
<span class="dashicons dashicons-arrow-right-alt2"></span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<?php if ( $supports_formats ) : ?>
|
||||
<div class="setting-modal is-off-screen is-hidden">
|
||||
<button type="button" class="button-reset modal-close">
|
||||
<span class="dashicons dashicons-arrow-left-alt2"></span><span class="setting-title"><?php _e( 'Post format' ); ?></span>
|
||||
</button>
|
||||
<?php $this->post_formats_html( $post ); ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="setting-modal is-off-screen is-hidden">
|
||||
<button type="button" class="button-reset modal-close"><span class="dashicons dashicons-arrow-left-alt2"></span><span class="setting-title"><?php _e( 'Categories' ); ?></span></button>
|
||||
<?php $this->categories_html( $post ); ?>
|
||||
</div>
|
||||
|
||||
<div class="setting-modal tags is-off-screen is-hidden">
|
||||
<button type="button" class="button-reset modal-close"><span class="dashicons dashicons-arrow-left-alt2"></span><span class="setting-title"><?php _e( 'Tags' ); ?></span></button>
|
||||
<?php $this->tags_html( $post ); ?>
|
||||
</div>
|
||||
</div><!-- .options-panel -->
|
||||
</div><!-- .wrapper -->
|
||||
|
||||
<div class="press-this-actions">
|
||||
<div class="pressthis-media-buttons">
|
||||
<button type="button" class="insert-media button-subtle" data-editor="pressthis">
|
||||
<span class="dashicons dashicons-admin-media"></span>
|
||||
<span class="screen-reader-text"><?php _e( 'Add Media' ); ?></span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="post-actions">
|
||||
<button type="button" class="button-subtle" id="draft-field"><?php _e( 'Save Draft' ); ?></button>
|
||||
<button type="button" class="button-primary" id="publish-field"><?php _e( 'Publish' ); ?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
|
||||
// TODO: consider running "special" press-this hooks here?
|
||||
// Maybe better so we don't output stuff accidentally added by plugins. Would probably prevent some errors.
|
||||
do_action( 'admin_footer', '' );
|
||||
do_action( 'admin_print_footer_scripts' );
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
die();
|
||||
}
|
||||
}
|
||||
|
||||
$GLOBALS['wp_press_this'] = new WP_Press_This;
|
187
wp-admin/js/bookmarklet.js
Normal file
187
wp-admin/js/bookmarklet.js
Normal file
@ -0,0 +1,187 @@
|
||||
( function( window, document, href, pt_url ) {
|
||||
var encodeURI = window.encodeURIComponent,
|
||||
form = document.createElement( 'form' ),
|
||||
head = document.getElementsByTagName( 'head' )[0],
|
||||
img = new Image(),
|
||||
target = '_press_this_app',
|
||||
windowWidth, windowHeight,
|
||||
metas, links, content, imgs, ifrs,
|
||||
vid, selection;
|
||||
|
||||
if ( ! pt_url ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( window.getSelection ) {
|
||||
selection = window.getSelection() + '';
|
||||
} else if ( document.getSelection ) {
|
||||
selection = document.getSelection() + '';
|
||||
} else if ( document.selection ) {
|
||||
selection = document.selection.createRange().text;
|
||||
}
|
||||
|
||||
pt_url += ( pt_url.indexOf( '?' ) > -1 ? '&' : '?' ) + 'buster=' + ( new Date().getTime() );
|
||||
|
||||
if ( document.title.length && document.title.length <= 512 ) {
|
||||
pt_url += '&t=' + encodeURI( document.title );
|
||||
}
|
||||
|
||||
if ( selection && selection.length <= 512 ) {
|
||||
pt_url += '&s=' + encodeURI( selection );
|
||||
}
|
||||
|
||||
if ( href.match( /^https?:/ ) ) {
|
||||
pt_url += '&u=' + encodeURI( href );
|
||||
} else {
|
||||
top.location.href = pt_url;
|
||||
return;
|
||||
}
|
||||
|
||||
function add( name, value ) {
|
||||
if ( typeof value === 'undefined' ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var input = document.createElement( 'input' );
|
||||
|
||||
input.name = name;
|
||||
input.value = value;
|
||||
input.type = 'hidden';
|
||||
|
||||
form.appendChild( input );
|
||||
}
|
||||
|
||||
if ( href.match( /\/\/www\.youtube\.com\/watch/ ) ) {
|
||||
add( '_embed[]', href );
|
||||
} else if ( href.match( /\/\/vimeo\.com\/(.+\/)?([\d]+)$/ ) ) {
|
||||
add( '_embed[]', href );
|
||||
} else if ( href.match( /\/\/(www\.)?dailymotion\.com\/video\/.+$/ ) ) {
|
||||
add( '_embed[]', href );
|
||||
} else if ( href.match( /\/\/soundcloud\.com\/.+$/ ) ) {
|
||||
add( '_embed[]', href );
|
||||
} else if ( href.match( /\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/ ) ) {
|
||||
add( '_embed[]', href );
|
||||
} else if ( href.match( /\/\/vine\.co\/v\/[^\/]+/ ) ) {
|
||||
add( '_embed[]', href );
|
||||
}
|
||||
|
||||
metas = head.getElementsByTagName( 'meta' ) || [];
|
||||
|
||||
for ( var m = 0; m < metas.length; m++ ) {
|
||||
if ( m >= 50 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
var q = metas[ m ],
|
||||
q_name = q.getAttribute( 'name' ),
|
||||
q_prop = q.getAttribute( 'property' ),
|
||||
q_cont = q.getAttribute( 'content' );
|
||||
|
||||
if ( q_name ) {
|
||||
add( '_meta[' + q_name + ']', q_cont );
|
||||
} else if ( q_prop ) {
|
||||
add( '_meta[' + q_prop + ']', q_cont );
|
||||
}
|
||||
}
|
||||
|
||||
links = head.getElementsByTagName( 'link' ) || [];
|
||||
|
||||
for ( var y = 0; y < links.length; y++ ) {
|
||||
if ( y >= 50 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
var g = links[ y ],
|
||||
g_rel = g.getAttribute( 'rel' );
|
||||
|
||||
if ( g_rel ) {
|
||||
switch ( g_rel ) {
|
||||
case 'canonical':
|
||||
case 'icon':
|
||||
case 'shortlink':
|
||||
add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
|
||||
break;
|
||||
case 'alternate':
|
||||
if ( 'application/json+oembed' === g.getAttribute( 'type' ) ) {
|
||||
add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
|
||||
} else if ( 'handheld' === g.getAttribute( 'media' ) ) {
|
||||
add( '_links[' + g_rel + ']', g.getAttribute( 'href' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( document.body.getElementsByClassName ) {
|
||||
content = document.body.getElementsByClassName( 'hfeed' )[0];
|
||||
}
|
||||
|
||||
content = document.getElementById( 'content' ) || content || document.body;
|
||||
imgs = content.getElementsByTagName( 'img' ) || [];
|
||||
|
||||
for ( var n = 0; n < imgs.length; n++ ) {
|
||||
if ( n >= 100 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ( imgs[ n ].src.indexOf( 'avatar' ) > -1 || imgs[ n ].className.indexOf( 'avatar' ) > -1 ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
img.src = imgs[ n ].src;
|
||||
|
||||
if ( img.width >= 256 && img.height >= 128 ) {
|
||||
add( '_img[]', img.src );
|
||||
}
|
||||
}
|
||||
|
||||
ifrs = document.body.getElementsByTagName( 'iframe' ) || [];
|
||||
|
||||
for ( var p = 0; p < ifrs.length; p++ ) {
|
||||
if ( p >= 100 ) {
|
||||
break;
|
||||
}
|
||||
|
||||
vid = ifrs[ p ].src.match(/\/\/www\.youtube\.com\/embed\/([^\?]+)\?.+$/);
|
||||
|
||||
if ( vid && 2 === vid.length ) {
|
||||
add( '_embed[]', 'https://www.youtube.com/watch?v=' + vid[1] );
|
||||
}
|
||||
|
||||
vid = ifrs[ p ].src.match( /\/\/player\.vimeo\.com\/video\/([\d]+)$/ );
|
||||
|
||||
if ( vid && 2 === vid.length ) {
|
||||
add( '_embed[]', 'https://vimeo.com/' + vid[1] );
|
||||
}
|
||||
|
||||
vid = ifrs[ p ].src.match( /\/\/vine\.co\/v\/([^\/]+)\/embed/ );
|
||||
|
||||
if ( vid && 2 === vid.length ) {
|
||||
add( '_embed[]', 'https://vine.co/v/' + vid[1] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( document.title && document.title > 512 ) {
|
||||
add( 't', document.title );
|
||||
}
|
||||
|
||||
if ( selection && selection.length > 512 ) {
|
||||
add( 's', selection );
|
||||
}
|
||||
|
||||
form.setAttribute( 'method', 'POST' );
|
||||
form.setAttribute( 'action', pt_url );
|
||||
form.setAttribute( 'target', target );
|
||||
form.setAttribute( 'style', 'display: none;' );
|
||||
|
||||
windowWidth = window.outerWidth || document.documentElement.clientWidth || 600;
|
||||
windowHeight = window.outerHeight || document.documentElement.clientHeight || 700;
|
||||
|
||||
windowWidth = ( windowWidth < 800 || windowWidth > 5000 ) ? 600 : ( windowWidth * 0.7 );
|
||||
windowHeight = ( windowHeight < 800 || windowHeight > 3000 ) ? 700 : ( windowHeight * 0.9 );
|
||||
|
||||
window.open( 'about:blank', target, 'width=' + windowWidth + ',height=' + windowHeight );
|
||||
|
||||
document.body.appendChild( form );
|
||||
|
||||
form.submit();
|
||||
} )( window, document, top.location.href, window.pt_url );
|
1
wp-admin/js/bookmarklet.min.js
vendored
Normal file
1
wp-admin/js/bookmarklet.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(a,b,c,d){function e(a,c){if("undefined"!=typeof c){var d=b.createElement("input");d.name=a,d.value=c,d.type="hidden",p.appendChild(d)}}var f,g,h,i,j,k,l,m,n,o=a.encodeURIComponent,p=b.createElement("form"),q=b.getElementsByTagName("head")[0],r=new Image,s="_press_this_app";if(d){if(a.getSelection?n=a.getSelection()+"":b.getSelection?n=b.getSelection()+"":b.selection&&(n=b.selection.createRange().text),d+=(d.indexOf("?")>-1?"&":"?")+"buster="+(new Date).getTime(),b.title.length&&b.title.length<=512&&(d+="&t="+o(b.title)),n&&n.length<=512&&(d+="&s="+o(n)),!c.match(/^https?:/))return void(top.location.href=d);d+="&u="+o(c),c.match(/\/\/www\.youtube\.com\/watch/)?e("_embed[]",c):c.match(/\/\/vimeo\.com\/(.+\/)?([\d]+)$/)?e("_embed[]",c):c.match(/\/\/(www\.)?dailymotion\.com\/video\/.+$/)?e("_embed[]",c):c.match(/\/\/soundcloud\.com\/.+$/)?e("_embed[]",c):c.match(/\/\/twitter\.com\/[^\/]+\/status\/[\d]+$/)?e("_embed[]",c):c.match(/\/\/vine\.co\/v\/[^\/]+/)&&e("_embed[]",c),h=q.getElementsByTagName("meta")||[];for(var t=0;t<h.length&&!(t>=50);t++){var u=h[t],v=u.getAttribute("name"),w=u.getAttribute("property"),x=u.getAttribute("content");v?e("_meta["+v+"]",x):w&&e("_meta["+w+"]",x)}i=q.getElementsByTagName("link")||[];for(var y=0;y<i.length&&!(y>=50);y++){var z=i[y],A=z.getAttribute("rel");if(A)switch(A){case"canonical":case"icon":case"shortlink":e("_links["+A+"]",z.getAttribute("href"));break;case"alternate":"application/json+oembed"===z.getAttribute("type")?e("_links["+A+"]",z.getAttribute("href")):"handheld"===z.getAttribute("media")&&e("_links["+A+"]",z.getAttribute("href"))}}b.body.getElementsByClassName&&(j=b.body.getElementsByClassName("hfeed")[0]),j=b.getElementById("content")||j||b.body,k=j.getElementsByTagName("img")||[];for(var B=0;B<k.length&&!(B>=100);B++)k[B].src.indexOf("avatar")>-1||k[B].className.indexOf("avatar")>-1||(r.src=k[B].src,r.width>=256&&r.height>=128&&e("_img[]",r.src));l=b.body.getElementsByTagName("iframe")||[];for(var C=0;C<l.length&&!(C>=100);C++)m=l[C].src.match(/\/\/www\.youtube\.com\/embed\/([^\?]+)\?.+$/),m&&2===m.length&&e("_embed[]","https://www.youtube.com/watch?v="+m[1]),m=l[C].src.match(/\/\/player\.vimeo\.com\/video\/([\d]+)$/),m&&2===m.length&&e("_embed[]","https://vimeo.com/"+m[1]),m=l[C].src.match(/\/\/vine\.co\/v\/([^\/]+)\/embed/),m&&2===m.length&&e("_embed[]","https://vine.co/v/"+m[1]);b.title&&b.title>512&&e("t",b.title),n&&n.length>512&&e("s",n),p.setAttribute("method","POST"),p.setAttribute("action",d),p.setAttribute("target",s),p.setAttribute("style","display: none;"),f=a.outerWidth||b.documentElement.clientWidth||600,g=a.outerHeight||b.documentElement.clientHeight||700,f=800>f||f>5e3?600:.7*f,g=800>g||g>3e3?700:.9*g,a.open("about:blank",s,"width="+f+",height="+g),b.body.appendChild(p),p.submit()}}(window,document,top.location.href,window.pt_url);
|
@ -7,182 +7,9 @@ makeSlugeditClickable = editPermalink = function(){};
|
||||
|
||||
window.wp = window.wp || {};
|
||||
|
||||
// return an array with any duplicate, whitespace or values removed
|
||||
function array_unique_noempty(a) {
|
||||
var out = [];
|
||||
jQuery.each( a, function(key, val) {
|
||||
val = jQuery.trim(val);
|
||||
if ( val && jQuery.inArray(val, out) == -1 )
|
||||
out.push(val);
|
||||
} );
|
||||
return out;
|
||||
}
|
||||
|
||||
( function($) {
|
||||
( function( $ ) {
|
||||
var titleHasFocus = false;
|
||||
|
||||
tagBox = {
|
||||
clean : function(tags) {
|
||||
var comma = postL10n.comma;
|
||||
if ( ',' !== comma )
|
||||
tags = tags.replace(new RegExp(comma, 'g'), ',');
|
||||
tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
|
||||
if ( ',' !== comma )
|
||||
tags = tags.replace(/,/g, comma);
|
||||
return tags;
|
||||
},
|
||||
|
||||
parseTags : function(el) {
|
||||
var id = el.id, num = id.split('-check-num-')[1], taxbox = $(el).closest('.tagsdiv'),
|
||||
thetags = taxbox.find('.the-tags'), comma = postL10n.comma,
|
||||
current_tags = thetags.val().split(comma), new_tags = [];
|
||||
delete current_tags[num];
|
||||
|
||||
$.each( current_tags, function(key, val) {
|
||||
val = $.trim(val);
|
||||
if ( val ) {
|
||||
new_tags.push(val);
|
||||
}
|
||||
});
|
||||
|
||||
thetags.val( this.clean( new_tags.join(comma) ) );
|
||||
|
||||
this.quickClicks(taxbox);
|
||||
return false;
|
||||
},
|
||||
|
||||
quickClicks : function(el) {
|
||||
var thetags = $('.the-tags', el),
|
||||
tagchecklist = $('.tagchecklist', el),
|
||||
id = $(el).attr('id'),
|
||||
current_tags, disabled;
|
||||
|
||||
if ( !thetags.length )
|
||||
return;
|
||||
|
||||
disabled = thetags.prop('disabled');
|
||||
|
||||
current_tags = thetags.val().split(postL10n.comma);
|
||||
tagchecklist.empty();
|
||||
|
||||
$.each( current_tags, function( key, val ) {
|
||||
var span, xbutton;
|
||||
|
||||
val = $.trim( val );
|
||||
|
||||
if ( ! val )
|
||||
return;
|
||||
|
||||
// Create a new span, and ensure the text is properly escaped.
|
||||
span = $('<span />').text( val );
|
||||
|
||||
// If tags editing isn't disabled, create the X button.
|
||||
if ( ! disabled ) {
|
||||
xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton">X</a>' );
|
||||
xbutton.click( function(){ tagBox.parseTags(this); });
|
||||
span.prepend(' ').prepend( xbutton );
|
||||
}
|
||||
|
||||
// Append the span to the tag list.
|
||||
tagchecklist.append( span );
|
||||
});
|
||||
},
|
||||
|
||||
flushTags : function(el, a, f) {
|
||||
var tagsval, newtags, text,
|
||||
tags = $('.the-tags', el),
|
||||
newtag = $('input.newtag', el),
|
||||
comma = postL10n.comma;
|
||||
a = a || false;
|
||||
|
||||
text = a ? $(a).text() : newtag.val();
|
||||
tagsval = tags.val();
|
||||
newtags = tagsval ? tagsval + comma + text : text;
|
||||
|
||||
newtags = this.clean( newtags );
|
||||
newtags = array_unique_noempty( newtags.split(comma) ).join(comma);
|
||||
tags.val(newtags);
|
||||
this.quickClicks(el);
|
||||
|
||||
if ( !a )
|
||||
newtag.val('');
|
||||
if ( 'undefined' == typeof(f) )
|
||||
newtag.focus();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
get : function(id) {
|
||||
var tax = id.substr(id.indexOf('-')+1);
|
||||
|
||||
$.post(ajaxurl, {'action':'get-tagcloud', 'tax':tax}, function(r, stat) {
|
||||
if ( 0 === r || 'success' != stat )
|
||||
r = wpAjax.broken;
|
||||
|
||||
r = $('<p id="tagcloud-'+tax+'" class="the-tagcloud">'+r+'</p>');
|
||||
$('a', r).click(function(){
|
||||
tagBox.flushTags( $(this).closest('.inside').children('.tagsdiv'), this);
|
||||
return false;
|
||||
});
|
||||
|
||||
$('#'+id).after(r);
|
||||
});
|
||||
},
|
||||
|
||||
init : function() {
|
||||
var t = this, ajaxtag = $('div.ajaxtag');
|
||||
|
||||
$('.tagsdiv').each( function() {
|
||||
tagBox.quickClicks(this);
|
||||
});
|
||||
|
||||
$('input.tagadd', ajaxtag).click(function(){
|
||||
t.flushTags( $(this).closest('.tagsdiv') );
|
||||
});
|
||||
|
||||
$('div.taghint', ajaxtag).click(function(){
|
||||
$(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
|
||||
});
|
||||
|
||||
$('input.newtag', ajaxtag).blur(function() {
|
||||
if ( '' === this.value )
|
||||
$(this).parent().siblings('.taghint').css('visibility', '');
|
||||
}).focus(function(){
|
||||
$(this).parent().siblings('.taghint').css('visibility', 'hidden');
|
||||
}).keyup(function(e){
|
||||
if ( 13 == e.which ) {
|
||||
tagBox.flushTags( $(this).closest('.tagsdiv') );
|
||||
return false;
|
||||
}
|
||||
}).keypress(function(e){
|
||||
if ( 13 == e.which ) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}).each(function(){
|
||||
var tax = $(this).closest('div.tagsdiv').attr('id');
|
||||
$(this).suggest( ajaxurl + '?action=ajax-tag-search&tax=' + tax, { delay: 500, minchars: 2, multiple: true, multipleSep: postL10n.comma + ' ' } );
|
||||
});
|
||||
|
||||
// save tags on post save/publish
|
||||
$('#post').submit(function(){
|
||||
$('div.tagsdiv').each( function() {
|
||||
tagBox.flushTags(this, false, 1);
|
||||
});
|
||||
});
|
||||
|
||||
// tag cloud
|
||||
$('a.tagcloud-link').click(function(){
|
||||
tagBox.get( $(this).attr('id') );
|
||||
$(this).unbind().click(function(){
|
||||
$(this).siblings('.the-tagcloud').toggle();
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
commentsBox = {
|
||||
st : 0,
|
||||
|
||||
@ -572,11 +399,11 @@ jQuery(document).ready( function($) {
|
||||
|
||||
// multi-taxonomies
|
||||
if ( $('#tagsdiv-post_tag').length ) {
|
||||
tagBox.init();
|
||||
window.tagBox && window.tagBox.init();
|
||||
} else {
|
||||
$('#side-sortables, #normal-sortables, #advanced-sortables').children('div.postbox').each(function(){
|
||||
if ( this.id.indexOf('tagsdiv-') === 0 ) {
|
||||
tagBox.init();
|
||||
window.tagBox && window.tagBox.init();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
2
wp-admin/js/post.min.js
vendored
2
wp-admin/js/post.min.js
vendored
File diff suppressed because one or more lines are too long
1035
wp-admin/js/press-this.js
Normal file
1035
wp-admin/js/press-this.js
Normal file
File diff suppressed because it is too large
Load Diff
1
wp-admin/js/press-this.min.js
vendored
Normal file
1
wp-admin/js/press-this.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
222
wp-admin/js/tags-box.js
Normal file
222
wp-admin/js/tags-box.js
Normal file
@ -0,0 +1,222 @@
|
||||
/* jshint curly: false, eqeqeq: false */
|
||||
/* global ajaxurl, wpAjax */
|
||||
|
||||
/**
|
||||
* The functions and classes in that code are a straight cut-and-paste out of
|
||||
* /wp-admin/js/post.js, coupled with Press This' usage of the post_tags_meta_box()
|
||||
* PHP function.
|
||||
*
|
||||
* If Press This makes it into core, we can refactor that code out of post.js and
|
||||
* make it more reusable, as well as improve it to work better, everywhere.
|
||||
*
|
||||
* Copied-and-pasted instead of enqueuing post.js because the latter has much more,
|
||||
* and has processing instead of just functions/classes.
|
||||
*/
|
||||
var tagBox, array_unique_noempty;
|
||||
|
||||
( function( $ ) {
|
||||
// Return an array with any duplicate, whitespace or empty values removed
|
||||
array_unique_noempty = function( array ) {
|
||||
var out = [];
|
||||
|
||||
$.each( array, function( key, val ) {
|
||||
val = $.trim( val );
|
||||
|
||||
if ( val && $.inArray( val, out ) === -1 ) {
|
||||
out.push( val );
|
||||
}
|
||||
} );
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
tagBox = {
|
||||
clean : function(tags) {
|
||||
var comma = window.tagsBoxL10n.tagDelimiter;
|
||||
if ( ',' !== comma )
|
||||
tags = tags.replace(new RegExp(comma, 'g'), ',');
|
||||
tags = tags.replace(/\s*,\s*/g, ',').replace(/,+/g, ',').replace(/[,\s]+$/, '').replace(/^[,\s]+/, '');
|
||||
if ( ',' !== comma )
|
||||
tags = tags.replace(/,/g, comma);
|
||||
return tags;
|
||||
},
|
||||
|
||||
parseTags : function(el) {
|
||||
var id = el.id,
|
||||
num = id.split('-check-num-')[1],
|
||||
taxbox = $(el).closest('.tagsdiv'),
|
||||
thetags = taxbox.find('.the-tags'),
|
||||
comma = window.tagsBoxL10n.tagDelimiter;
|
||||
current_tags = thetags.val().split( comma ),
|
||||
new_tags = [];
|
||||
|
||||
delete current_tags[num];
|
||||
|
||||
$.each( current_tags, function( key, val ) {
|
||||
val = $.trim( val );
|
||||
if ( val ) {
|
||||
new_tags.push( val );
|
||||
}
|
||||
});
|
||||
|
||||
thetags.val( this.clean( new_tags.join( comma ) ) );
|
||||
|
||||
this.quickClicks( taxbox );
|
||||
return false;
|
||||
},
|
||||
|
||||
quickClicks : function( el ) {
|
||||
var thetags = $('.the-tags', el),
|
||||
tagchecklist = $('.tagchecklist', el),
|
||||
id = $(el).attr('id'),
|
||||
current_tags, disabled;
|
||||
|
||||
if ( ! thetags.length )
|
||||
return;
|
||||
|
||||
disabled = thetags.prop('disabled');
|
||||
|
||||
current_tags = thetags.val().split( window.tagsBoxL10n.tagDelimiter );
|
||||
tagchecklist.empty();
|
||||
|
||||
$.each( current_tags, function( key, val ) {
|
||||
var span, xbutton;
|
||||
|
||||
val = $.trim( val );
|
||||
|
||||
if ( ! val )
|
||||
return;
|
||||
|
||||
// Create a new span, and ensure the text is properly escaped.
|
||||
span = $('<span />').text( val );
|
||||
|
||||
// If tags editing isn't disabled, create the X button.
|
||||
if ( ! disabled ) {
|
||||
xbutton = $( '<a id="' + id + '-check-num-' + key + '" class="ntdelbutton" tabindex="0">X</a>' );
|
||||
|
||||
xbutton.on( 'click keypress', function( e ) {
|
||||
// Trigger function if pressed Enter - keyboard navigation
|
||||
if ( e.type === 'click' || e.keyCode === 13 ) {
|
||||
// When using keyboard, move focus back to the new tag field.
|
||||
if ( e.keyCode === 13 ) {
|
||||
$( this ).closest( '.tagsdiv' ).find( 'input.newtag' ).focus();
|
||||
}
|
||||
|
||||
tagBox.parseTags( this );
|
||||
}
|
||||
});
|
||||
|
||||
span.prepend( ' ' ).prepend( xbutton );
|
||||
}
|
||||
|
||||
// Append the span to the tag list.
|
||||
tagchecklist.append( span );
|
||||
});
|
||||
},
|
||||
|
||||
flushTags : function( el, a, f ) {
|
||||
var tagsval, newtags, text,
|
||||
tags = $( '.the-tags', el ),
|
||||
newtag = $( 'input.newtag', el ),
|
||||
comma = window.tagsBoxL10n.tagDelimiter;
|
||||
|
||||
a = a || false;
|
||||
|
||||
text = a ? $(a).text() : newtag.val();
|
||||
tagsval = tags.val();
|
||||
newtags = tagsval ? tagsval + comma + text : text;
|
||||
|
||||
newtags = this.clean( newtags );
|
||||
newtags = array_unique_noempty( newtags.split( comma ) ).join( comma );
|
||||
tags.val( newtags );
|
||||
this.quickClicks( el );
|
||||
|
||||
if ( ! a )
|
||||
newtag.val('');
|
||||
if ( 'undefined' == typeof( f ) )
|
||||
newtag.focus();
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
get : function( id ) {
|
||||
var tax = id.substr( id.indexOf('-') + 1 );
|
||||
|
||||
$.post( ajaxurl, { 'action': 'get-tagcloud', 'tax': tax }, function( r, stat ) {
|
||||
if ( 0 === r || 'success' != stat ) {
|
||||
return;
|
||||
}
|
||||
|
||||
r = $( '<p id="tagcloud-' + tax + '" class="the-tagcloud">' + r + '</p>' );
|
||||
|
||||
$( 'a', r ).click( function() {
|
||||
tagBox.flushTags( $( '#' + tax ), this );
|
||||
return false;
|
||||
});
|
||||
|
||||
$( '#' + id ).after( r );
|
||||
});
|
||||
},
|
||||
|
||||
init : function() {
|
||||
var t = this, ajaxtag = $('div.ajaxtag');
|
||||
|
||||
$('.tagsdiv').each( function() {
|
||||
tagBox.quickClicks(this);
|
||||
});
|
||||
|
||||
$('.tagadd', ajaxtag).click(function(){
|
||||
t.flushTags( $(this).closest('.tagsdiv') );
|
||||
});
|
||||
|
||||
$('div.taghint', ajaxtag).click(function(){
|
||||
$(this).css('visibility', 'hidden').parent().siblings('.newtag').focus();
|
||||
});
|
||||
|
||||
$('input.newtag', ajaxtag).blur(function() {
|
||||
if ( '' === this.value )
|
||||
$(this).parent().siblings('.taghint').css('visibility', '');
|
||||
}).focus(function(){
|
||||
$(this).parent().siblings('.taghint').css('visibility', 'hidden');
|
||||
}).keyup(function(e){
|
||||
if ( 13 == e.which ) {
|
||||
tagBox.flushTags( $(this).closest('.tagsdiv') );
|
||||
return false;
|
||||
}
|
||||
}).keypress(function(e){
|
||||
if ( 13 == e.which ) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
}
|
||||
}).each( function() {
|
||||
var tax = $(this).closest('div.tagsdiv').attr('id');
|
||||
$(this).suggest(
|
||||
ajaxurl + '?action=ajax-tag-search&tax=' + tax,
|
||||
{ delay: 500, minchars: 2, multiple: true, multipleSep: window.tagsBoxL10n.tagDelimiter + ' ' }
|
||||
);
|
||||
});
|
||||
|
||||
// save tags on post save/publish
|
||||
$('#post').submit(function(){
|
||||
$('div.tagsdiv').each( function() {
|
||||
tagBox.flushTags(this, false, 1);
|
||||
});
|
||||
});
|
||||
|
||||
// tag cloud
|
||||
$('a.tagcloud-link').click(function(){
|
||||
tagBox.get( $(this).attr('id') );
|
||||
$(this).unbind().click(function(){
|
||||
$(this).siblings('.the-tagcloud').toggle();
|
||||
return false;
|
||||
});
|
||||
return false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
$( document ).ready( function() {
|
||||
tagBox.init();
|
||||
});
|
||||
|
||||
}( jQuery ));
|
1
wp-admin/js/tags-box.min.js
vendored
Normal file
1
wp-admin/js/tags-box.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
var tagBox,array_unique_noempty;!function(a){array_unique_noempty=function(b){var c=[];return a.each(b,function(b,d){d=a.trim(d),d&&-1===a.inArray(d,c)&&c.push(d)}),c},tagBox={clean:function(a){var b=window.tagsBoxL10n.tagDelimiter;return","!==b&&(a=a.replace(new RegExp(b,"g"),",")),a=a.replace(/\s*,\s*/g,",").replace(/,+/g,",").replace(/[,\s]+$/,"").replace(/^[,\s]+/,""),","!==b&&(a=a.replace(/,/g,b)),a},parseTags:function(b){var c=b.id,d=c.split("-check-num-")[1],e=a(b).closest(".tagsdiv"),f=e.find(".the-tags"),g=window.tagsBoxL10n.tagDelimiter;return current_tags=f.val().split(g),new_tags=[],delete current_tags[d],a.each(current_tags,function(b,c){c=a.trim(c),c&&new_tags.push(c)}),f.val(this.clean(new_tags.join(g))),this.quickClicks(e),!1},quickClicks:function(b){var c,d,e=a(".the-tags",b),f=a(".tagchecklist",b),g=a(b).attr("id");e.length&&(d=e.prop("disabled"),c=e.val().split(window.tagsBoxL10n.tagDelimiter),f.empty(),a.each(c,function(b,c){var e,h;c=a.trim(c),c&&(e=a("<span />").text(c),d||(h=a('<a id="'+g+"-check-num-"+b+'" class="ntdelbutton" tabindex="0">X</a>'),h.on("click keypress",function(b){("click"===b.type||13===b.keyCode)&&(13===b.keyCode&&a(this).closest(".tagsdiv").find("input.newtag").focus(),tagBox.parseTags(this))}),e.prepend(" ").prepend(h)),f.append(e))}))},flushTags:function(b,c,d){var e,f,g,h=a(".the-tags",b),i=a("input.newtag",b),j=window.tagsBoxL10n.tagDelimiter;return c=c||!1,g=c?a(c).text():i.val(),e=h.val(),f=e?e+j+g:g,f=this.clean(f),f=array_unique_noempty(f.split(j)).join(j),h.val(f),this.quickClicks(b),c||i.val(""),"undefined"==typeof d&&i.focus(),!1},get:function(b){var c=b.substr(b.indexOf("-")+1);a.post(ajaxurl,{action:"get-tagcloud",tax:c},function(d,e){0!==d&&"success"==e&&(d=a('<p id="tagcloud-'+c+'" class="the-tagcloud">'+d+"</p>"),a("a",d).click(function(){return tagBox.flushTags(a("#"+c),this),!1}),a("#"+b).after(d))})},init:function(){var b=this,c=a("div.ajaxtag");a(".tagsdiv").each(function(){tagBox.quickClicks(this)}),a(".tagadd",c).click(function(){b.flushTags(a(this).closest(".tagsdiv"))}),a("div.taghint",c).click(function(){a(this).css("visibility","hidden").parent().siblings(".newtag").focus()}),a("input.newtag",c).blur(function(){""===this.value&&a(this).parent().siblings(".taghint").css("visibility","")}).focus(function(){a(this).parent().siblings(".taghint").css("visibility","hidden")}).keyup(function(b){return 13==b.which?(tagBox.flushTags(a(this).closest(".tagsdiv")),!1):void 0}).keypress(function(a){return 13==a.which?(a.preventDefault(),!1):void 0}).each(function(){var b=a(this).closest("div.tagsdiv").attr("id");a(this).suggest(ajaxurl+"?action=ajax-tag-search&tax="+b,{delay:500,minchars:2,multiple:!0,multipleSep:window.tagsBoxL10n.tagDelimiter+" "})}),a("#post").submit(function(){a("div.tagsdiv").each(function(){tagBox.flushTags(this,!1,1)})}),a("a.tagcloud-link").click(function(){return tagBox.get(a(this).attr("id")),a(this).unbind().click(function(){return a(this).siblings(".the-tagcloud").toggle(),!1}),!1})}},a(document).ready(function(){tagBox.init()})}(jQuery);
|
@ -113,16 +113,6 @@ do_settings_fields('writing', 'remote_publishing'); // A deprecated section.
|
||||
?>
|
||||
</table>
|
||||
|
||||
<h3 class="title"><?php _e('Press This') ?></h3>
|
||||
<p><?php _e('Press This is a bookmarklet: a little app that runs in your browser and lets you grab bits of the web.');?></p>
|
||||
<p><?php _e('Use Press This to clip text, images and videos from any web page. Then edit and add more straight from Press This before you save or publish it in a post on your site.'); ?></p>
|
||||
<p><?php _e('Drag-and-drop the following link to your bookmarks bar or right click it and add it to your favorites for a posting shortcut.') ?></p>
|
||||
<p class="pressthis"><a onclick="return false;" oncontextmenu="if(window.navigator.userAgent.indexOf('WebKit')!=-1||window.navigator.userAgent.indexOf('MSIE')!=-1){jQuery('.pressthis-code').show().find('textarea').focus().select();return false;}" href="<?php echo htmlspecialchars( get_shortcut_link() ); ?>"><span><?php _e('Press This') ?></span></a></p>
|
||||
<div class="pressthis-code" style="display:none;">
|
||||
<p class="description"><?php _e('If your bookmarks toolbar is hidden: copy the code below, open your Bookmarks manager, create new bookmark, type Press This into the name field and paste the code into the URL field.') ?></p>
|
||||
<p><textarea rows="5" cols="120" readonly="readonly"><?php echo htmlspecialchars( get_shortcut_link() ); ?></textarea></p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
/** This filter is documented in wp-admin/options.php */
|
||||
if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
|
||||
|
@ -11,675 +11,11 @@ define('IFRAME_REQUEST' , true);
|
||||
/** WordPress Administration Bootstrap */
|
||||
require_once( dirname( __FILE__ ) . '/admin.php' );
|
||||
|
||||
header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
|
||||
|
||||
if ( ! current_user_can( 'edit_posts' ) || ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) )
|
||||
wp_die( __( 'Cheatin’ uh?' ), 403 );
|
||||
|
||||
/**
|
||||
* Press It form handler.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*
|
||||
* @return int Post ID
|
||||
*/
|
||||
function press_it() {
|
||||
|
||||
$post = get_default_post_to_edit();
|
||||
$post = get_object_vars($post);
|
||||
$post_ID = $post['ID'] = (int) $_POST['post_id'];
|
||||
|
||||
if ( !current_user_can('edit_post', $post_ID) )
|
||||
wp_die(__('You are not allowed to edit this post.'));
|
||||
|
||||
$post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
|
||||
$post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
|
||||
$post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
|
||||
$content = isset($_POST['content']) ? $_POST['content'] : '';
|
||||
|
||||
$upload = false;
|
||||
if ( !empty($_POST['photo_src']) && current_user_can('upload_files') ) {
|
||||
foreach( (array) $_POST['photo_src'] as $key => $image) {
|
||||
// See if files exist in content - we don't want to upload non-used selected files.
|
||||
if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
|
||||
$desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
|
||||
$upload = media_sideload_image($image, $post_ID, $desc);
|
||||
|
||||
// Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
|
||||
if ( !is_wp_error($upload) )
|
||||
$content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set the post_content and status.
|
||||
$post['post_content'] = $content;
|
||||
if ( isset( $_POST['publish'] ) && current_user_can( 'publish_posts' ) )
|
||||
$post['post_status'] = 'publish';
|
||||
elseif ( isset( $_POST['review'] ) )
|
||||
$post['post_status'] = 'pending';
|
||||
else
|
||||
$post['post_status'] = 'draft';
|
||||
|
||||
// Error handling for media_sideload.
|
||||
if ( is_wp_error($upload) ) {
|
||||
wp_delete_post($post_ID);
|
||||
wp_die( esc_html( $upload->get_error_message() ) );
|
||||
} else {
|
||||
// Post formats.
|
||||
if ( isset( $_POST['post_format'] ) ) {
|
||||
if ( current_theme_supports( 'post-formats', $_POST['post_format'] ) )
|
||||
set_post_format( $post_ID, $_POST['post_format'] );
|
||||
elseif ( '0' == $_POST['post_format'] )
|
||||
set_post_format( $post_ID, false );
|
||||
}
|
||||
|
||||
$post_ID = wp_update_post($post);
|
||||
}
|
||||
|
||||
return $post_ID;
|
||||
if ( empty( $GLOBALS['wp_press_this'] ) ) {
|
||||
include( ABSPATH . 'wp-admin/includes/class-wp-press-this.php' );
|
||||
}
|
||||
|
||||
// For submitted posts.
|
||||
if ( isset($_REQUEST['action']) && 'post' == $_REQUEST['action'] ) {
|
||||
check_admin_referer('press-this');
|
||||
$posted = $post_ID = press_it();
|
||||
} else {
|
||||
$post = get_default_post_to_edit('post', true);
|
||||
$post_ID = $post->ID;
|
||||
}
|
||||
|
||||
// Set Variables
|
||||
$title = isset( $_GET['t'] ) ? trim( strip_tags( html_entity_decode( wp_unslash( $_GET['t'] ) , ENT_QUOTES) ) ) : '';
|
||||
|
||||
$selection = '';
|
||||
if ( !empty($_GET['s']) ) {
|
||||
$selection = str_replace(''', "'", wp_unslash($_GET['s']));
|
||||
$selection = trim( htmlspecialchars( html_entity_decode($selection, ENT_QUOTES) ) );
|
||||
}
|
||||
|
||||
if ( ! empty($selection) ) {
|
||||
$selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection);
|
||||
$selection = '<p>' . str_replace('<p></p>', '', $selection) . '</p>';
|
||||
}
|
||||
|
||||
$url = isset($_GET['u']) ? esc_url($_GET['u']) : '';
|
||||
$image = isset($_GET['i']) ? $_GET['i'] : '';
|
||||
|
||||
if ( !empty($_REQUEST['ajax']) ) {
|
||||
switch ($_REQUEST['ajax']) {
|
||||
case 'video': ?>
|
||||
<script type="text/javascript">
|
||||
jQuery('.select').click(function() {
|
||||
append_editor(jQuery('#embed-code').val());
|
||||
jQuery('#extra-fields').hide();
|
||||
jQuery('#extra-fields').html('');
|
||||
});
|
||||
jQuery('.close').click(function() {
|
||||
jQuery('#extra-fields').hide();
|
||||
jQuery('#extra-fields').html('');
|
||||
});
|
||||
</script>
|
||||
<div class="postbox">
|
||||
<h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
|
||||
<div class="inside">
|
||||
<textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo esc_textarea( $selection ); ?></textarea>
|
||||
<p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
<?php break;
|
||||
|
||||
case 'photo_thickbox': ?>
|
||||
<script type="text/javascript">
|
||||
jQuery('.cancel').click(function() {
|
||||
tb_remove();
|
||||
});
|
||||
jQuery('.select').click(function() {
|
||||
image_selector(this);
|
||||
});
|
||||
</script>
|
||||
<h3 class="tb"><label for="tb_this_photo_description"><?php _e('Description') ?></label></h3>
|
||||
<div class="titlediv">
|
||||
<div class="titlewrap">
|
||||
<input id="tb_this_photo_description" name="photo_description" class="tb_this_photo_description tbtitle text" type="text" onkeypress="if(event.keyCode==13) image_selector(this);" value="<?php echo esc_attr($title);?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="centered">
|
||||
<input type="hidden" name="this_photo" value="<?php echo esc_attr( $image ); ?>" id="tb_this_photo" class="tb_this_photo" />
|
||||
<a href="#" class="select">
|
||||
<img src="<?php echo esc_url( $image ); ?>" alt="<?php esc_attr_e( 'Click to insert.' ); ?>" title="<?php esc_attr_e( 'Click to insert.' ); ?>" />
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
|
||||
<?php break;
|
||||
case 'photo_images':
|
||||
/**
|
||||
* Retrieve all image URLs from given URI.
|
||||
*
|
||||
* @since 2.6.0
|
||||
*
|
||||
* @param string $uri
|
||||
* @return string
|
||||
*/
|
||||
function get_images_from_uri($uri) {
|
||||
$uri = preg_replace('/\/#.+?$/','', $uri);
|
||||
if ( preg_match( '/\.(jpe?g|jpe|gif|png)\b/i', $uri ) && !strpos( $uri, 'blogger.com' ) )
|
||||
return "'" . esc_attr( html_entity_decode($uri) ) . "'";
|
||||
$content = wp_remote_fopen($uri);
|
||||
if ( false === $content )
|
||||
return '';
|
||||
$host = parse_url($uri);
|
||||
$pattern = '/<img ([^>]*)src=(\"|\')([^<>\'\"]+)(\2)([^>]*)\/*>/i';
|
||||
$content = str_replace(array("\n","\t","\r"), '', $content);
|
||||
preg_match_all($pattern, $content, $matches);
|
||||
if ( empty($matches[0]) )
|
||||
return '';
|
||||
$sources = array();
|
||||
foreach ($matches[3] as $src) {
|
||||
|
||||
// If no http in URL.
|
||||
if (strpos($src, 'http') === false)
|
||||
// If it doesn't have a relative URI.
|
||||
if ( strpos($src, '../') === false && strpos($src, './') === false && strpos($src, '/') === 0)
|
||||
$src = 'http://'.str_replace('//','/', $host['host'].'/'.$src);
|
||||
else
|
||||
$src = 'http://'.str_replace('//','/', $host['host'].'/'.dirname($host['path']).'/'.$src);
|
||||
$sources[] = esc_url($src);
|
||||
}
|
||||
return "'" . implode("','", $sources) . "'";
|
||||
}
|
||||
$url = wp_kses(urldecode($url), null);
|
||||
echo 'new Array('.get_images_from_uri($url).')';
|
||||
break;
|
||||
|
||||
case 'photo_js': ?>
|
||||
// Gather images and load some default JS.
|
||||
var last = null
|
||||
var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
|
||||
if(photostorage == false) {
|
||||
var my_src = eval(
|
||||
jQuery.ajax({
|
||||
type: "GET",
|
||||
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
|
||||
cache : false,
|
||||
async : false,
|
||||
data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
|
||||
dataType : "script"
|
||||
}).responseText
|
||||
);
|
||||
if(my_src.length == 0) {
|
||||
var my_src = eval(
|
||||
jQuery.ajax({
|
||||
type: "GET",
|
||||
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
|
||||
cache : false,
|
||||
async : false,
|
||||
data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
|
||||
dataType : "script"
|
||||
}).responseText
|
||||
);
|
||||
if(my_src.length == 0) {
|
||||
strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = 0; i < my_src.length; i++) {
|
||||
img = new Image();
|
||||
img.src = my_src[i];
|
||||
img_attr = 'id="img' + i + '"';
|
||||
skip = false;
|
||||
|
||||
maybeappend = '<a href="?ajax=photo_thickbox&i=' + encodeURIComponent(img.src) + '&u=<?php echo urlencode($url); ?>&height=400&width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
|
||||
|
||||
if (img.width && img.height) {
|
||||
if (img.width >= 30 && img.height >= 30) {
|
||||
aspect = img.width / img.height;
|
||||
scale = (aspect > 1) ? (71 / img.width) : (71 / img.height);
|
||||
|
||||
w = img.width;
|
||||
h = img.height;
|
||||
|
||||
if (scale < 1) {
|
||||
w = parseInt(img.width * scale);
|
||||
h = parseInt(img.height * scale);
|
||||
}
|
||||
img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
|
||||
strtoappend += maybeappend;
|
||||
}
|
||||
} else {
|
||||
strtoappend += maybeappend;
|
||||
}
|
||||
}
|
||||
|
||||
function pick(img, desc) {
|
||||
if (img) {
|
||||
if('object' == typeof jQuery('.photolist input') && jQuery('.photolist input').length != 0) length = jQuery('.photolist input').length;
|
||||
if(length == 0) length = 1;
|
||||
jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
|
||||
jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
|
||||
insert_editor( "\n\n" + encodeURI('<p style="text-align: center;"><a href="<?php echo $url; ?>"><img src="' + img +'" alt="' + desc + '" /></a></p>'));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function image_selector(el) {
|
||||
var desc, src, parent = jQuery(el).closest('#photo-add-url-div');
|
||||
|
||||
if ( parent.length ) {
|
||||
desc = parent.find('input.tb_this_photo_description').val() || '';
|
||||
src = parent.find('input.tb_this_photo').val() || ''
|
||||
} else {
|
||||
desc = jQuery('#tb_this_photo_description').val() || '';
|
||||
src = jQuery('#tb_this_photo').val() || ''
|
||||
}
|
||||
|
||||
tb_remove();
|
||||
pick(src, desc);
|
||||
jQuery('#extra-fields').hide();
|
||||
jQuery('#extra-fields').html('');
|
||||
return false;
|
||||
}
|
||||
|
||||
jQuery('#extra-fields').html('<div class="postbox"><h2><?php _e( 'Add Photos' ); ?> <small id="photo_directions">(<?php _e("click images to select") ?>)</small></h2><ul class="actions"><li><a href="#" id="photo-add-url" class="button button-small"><?php _e("Add from URL") ?> +</a></li></ul><div class="inside"><div class="titlewrap"><div id="img_container"></div></div><p id="options"><a href="#" class="close button"><?php _e('Cancel'); ?></a><a href="#" class="refresh button"><?php _e('Refresh'); ?></a></p></div>');
|
||||
jQuery('#img_container').html(strtoappend);
|
||||
<?php break;
|
||||
}
|
||||
die;
|
||||
}
|
||||
|
||||
wp_enqueue_style( 'colors' );
|
||||
wp_enqueue_script( 'post' );
|
||||
add_thickbox();
|
||||
_wp_admin_html_begin();
|
||||
?>
|
||||
<title><?php _e('Press This') ?></title>
|
||||
<script type="text/javascript">
|
||||
addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
|
||||
var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'press-this', isRtl = <?php echo (int) is_rtl(); ?>;
|
||||
var photostorage = false;
|
||||
</script>
|
||||
|
||||
<?php
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_enqueue_scripts', 'press-this.php' );
|
||||
|
||||
/**
|
||||
* Fires when styles are printed for the Press This admin page.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
do_action( 'admin_print_styles-press-this.php' );
|
||||
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_print_styles' );
|
||||
|
||||
/**
|
||||
* Fires when scripts are printed for the Press This admin page.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
do_action( 'admin_print_scripts-press-this.php' );
|
||||
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_print_scripts' );
|
||||
|
||||
/**
|
||||
* Fires in the head tag on the Press This admin page.
|
||||
*
|
||||
* @since 3.7.0
|
||||
*/
|
||||
do_action( 'admin_head-press-this.php' );
|
||||
|
||||
/** This action is documented in wp-admin/admin-header.php */
|
||||
do_action( 'admin_head' );
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var wpActiveEditor = 'content';
|
||||
|
||||
function insert_plain_editor(text) {
|
||||
if ( typeof(QTags) != 'undefined' )
|
||||
QTags.insertContent(text);
|
||||
}
|
||||
function set_editor(text) {
|
||||
if ( '' == text || '<p></p>' == text )
|
||||
text = '<p><br /></p>';
|
||||
|
||||
if ( tinyMCE.activeEditor )
|
||||
tinyMCE.execCommand('mceSetContent', false, text);
|
||||
}
|
||||
function insert_editor(text) {
|
||||
if ( '' != text && tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden()) {
|
||||
tinyMCE.execCommand('mceInsertContent', false, '<p>' + decodeURI(tinymce.DOM.decode(text)) + '</p>', {format : 'raw'});
|
||||
} else {
|
||||
insert_plain_editor(decodeURI(text));
|
||||
}
|
||||
}
|
||||
function append_editor(text) {
|
||||
if ( '' != text && tinyMCE.activeEditor && ! tinyMCE.activeEditor.isHidden()) {
|
||||
tinyMCE.execCommand('mceSetContent', false, tinyMCE.activeEditor.getContent({format : 'raw'}) + '<p>' + text + '</p>');
|
||||
} else {
|
||||
insert_plain_editor(text);
|
||||
}
|
||||
}
|
||||
|
||||
function show(tab_name) {
|
||||
jQuery('#extra-fields').html('');
|
||||
switch(tab_name) {
|
||||
case 'video' :
|
||||
jQuery('#extra-fields').load('<?php echo esc_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo esc_attr($selection); ?>'}, function() {
|
||||
<?php
|
||||
$content = '';
|
||||
if ( preg_match("/youtube\.com\/watch/i", $url) ) {
|
||||
list($domain, $video_id) = explode("v=", $url);
|
||||
$video_id = esc_attr($video_id);
|
||||
$content = '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/' . $video_id . '"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/' . $video_id . '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>';
|
||||
|
||||
} elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) {
|
||||
list($domain, $video_id) = explode(".com/", $url);
|
||||
$video_id = esc_attr($video_id);
|
||||
$content = '<object width="400" height="225"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=' . $video_id . '&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" /> <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=' . $video_id . '&server=www.vimeo.com&show_title=1&show_byline=1&show_portrait=0&color=&fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>';
|
||||
|
||||
if ( trim($selection) == '' )
|
||||
$selection = '<p><a href="http://www.vimeo.com/' . $video_id . '?pg=embed&sec=' . $video_id . '">' . $title . '</a> on <a href="http://vimeo.com?pg=embed&sec=' . $video_id . '">Vimeo</a></p>';
|
||||
|
||||
} elseif ( strpos( $selection, '<object' ) !== false ) {
|
||||
$content = $selection;
|
||||
}
|
||||
?>
|
||||
jQuery('#embed-code').prepend('<?php echo htmlentities($content); ?>');
|
||||
});
|
||||
jQuery('#extra-fields').show();
|
||||
return false;
|
||||
break;
|
||||
case 'photo' :
|
||||
function setup_photo_actions() {
|
||||
jQuery('.close').click(function() {
|
||||
jQuery('#extra-fields').hide();
|
||||
jQuery('#extra-fields').html('');
|
||||
});
|
||||
jQuery('.refresh').click(function() {
|
||||
photostorage = false;
|
||||
show('photo');
|
||||
});
|
||||
jQuery('#photo-add-url').click(function(){
|
||||
var form = jQuery('#photo-add-url-div').clone();
|
||||
jQuery('#img_container').empty().append( form.show() );
|
||||
});
|
||||
jQuery('#waiting').hide();
|
||||
jQuery('#extra-fields').show();
|
||||
}
|
||||
|
||||
jQuery('#waiting').show();
|
||||
if(photostorage == false) {
|
||||
jQuery.ajax({
|
||||
type: "GET",
|
||||
cache : false,
|
||||
url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
|
||||
data: "ajax=photo_js&u=<?php echo urlencode($url)?>",
|
||||
dataType : "script",
|
||||
success : function(data) {
|
||||
eval(data);
|
||||
photostorage = jQuery('#extra-fields').html();
|
||||
setup_photo_actions();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
jQuery('#extra-fields').html(photostorage);
|
||||
setup_photo_actions();
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
jQuery(document).ready(function($) {
|
||||
var $contnet = $( '#content' );
|
||||
|
||||
// Resize screen.
|
||||
window.resizeTo(760,580);
|
||||
|
||||
// Set button actions.
|
||||
jQuery('#photo_button').click(function() { show('photo'); return false; });
|
||||
jQuery('#video_button').click(function() { show('video'); return false; });
|
||||
|
||||
// Auto select.
|
||||
<?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
|
||||
show('video');
|
||||
<?php } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { ?>
|
||||
show('video');
|
||||
<?php } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
|
||||
show('photo');
|
||||
<?php } ?>
|
||||
jQuery('#title').unbind();
|
||||
jQuery('#publish, #save').click(function() { jQuery('.press-this #publishing-actions .spinner').css('display', 'inline-block'); });
|
||||
|
||||
$('#tagsdiv-post_tag, #categorydiv').children('h3, .handlediv').click(function(){
|
||||
$(this).siblings('.inside').toggle();
|
||||
});
|
||||
|
||||
if ( $( '#wp-content-wrap' ).hasClass( 'html-active' ) && window.switchEditors &&
|
||||
( tinyMCEPreInit.mceInit.content && tinyMCEPreInit.mceInit.content.wpautop ) ) {
|
||||
// The Text editor is default, run the initial content through pre_wpautop() to convert the paragraphs
|
||||
$contnet.text( window.switchEditors.pre_wpautop( $contnet.text() ) );
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<?php
|
||||
$admin_body_class = ( is_rtl() ) ? 'rtl' : '';
|
||||
$admin_body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
|
||||
?>
|
||||
<body class="press-this wp-admin wp-core-ui <?php echo $admin_body_class; ?>">
|
||||
<form action="press-this.php?action=post" method="post">
|
||||
<div id="poststuff" class="metabox-holder">
|
||||
<div id="side-sortables" class="press-this-sidebar">
|
||||
<div class="sleeve">
|
||||
<?php wp_nonce_field('press-this') ?>
|
||||
<input type="hidden" name="post_type" id="post_type" value="text"/>
|
||||
<input type="hidden" name="autosave" id="autosave" />
|
||||
<input type="hidden" id="original_post_status" name="original_post_status" value="draft" />
|
||||
<input type="hidden" id="prev_status" name="prev_status" value="draft" />
|
||||
<input type="hidden" id="post_id" name="post_id" value="<?php echo (int) $post_ID; ?>" />
|
||||
|
||||
<!-- This div holds the photo metadata -->
|
||||
<div class="photolist"></div>
|
||||
|
||||
<div id="submitdiv" class="postbox">
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
|
||||
<h3 class="hndle"><?php _e('Press This') ?></h3>
|
||||
<div class="inside">
|
||||
<p id="publishing-actions">
|
||||
<?php
|
||||
submit_button( __( 'Save Draft' ), 'button', 'draft', false, array( 'id' => 'save' ) );
|
||||
if ( current_user_can('publish_posts') ) {
|
||||
submit_button( __( 'Publish' ), 'primary', 'publish', false );
|
||||
} else {
|
||||
echo '<br /><br />';
|
||||
submit_button( __( 'Submit for Review' ), 'primary', 'review', false );
|
||||
} ?>
|
||||
<span class="spinner" style="display: none;"></span>
|
||||
</p>
|
||||
<?php if ( current_theme_supports( 'post-formats' ) && post_type_supports( 'post', 'post-formats' ) ) :
|
||||
$post_formats = get_theme_support( 'post-formats' );
|
||||
if ( is_array( $post_formats[0] ) ) :
|
||||
$default_format = get_option( 'default_post_format', '0' );
|
||||
?>
|
||||
<p>
|
||||
<label for="post_format"><?php _e( 'Post Format:' ); ?>
|
||||
<select name="post_format" id="post_format">
|
||||
<option value="0"><?php echo get_post_format_string( 'standard' ); ?></option>
|
||||
<?php foreach ( $post_formats[0] as $format ): ?>
|
||||
<option<?php selected( $default_format, $format ); ?> value="<?php echo esc_attr( $format ); ?>"> <?php echo esc_html( get_post_format_string( $format ) ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select></label>
|
||||
</p>
|
||||
<?php endif; endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php $tax = get_taxonomy( 'category' ); ?>
|
||||
<div id="categorydiv" class="postbox">
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
|
||||
<h3 class="hndle"><?php _e('Categories') ?></h3>
|
||||
<div class="inside">
|
||||
<div id="taxonomy-category" class="categorydiv">
|
||||
|
||||
<ul id="category-tabs" class="category-tabs">
|
||||
<li class="tabs"><a href="#category-all"><?php echo $tax->labels->all_items; ?></a></li>
|
||||
<li class="hide-if-no-js"><a href="#category-pop"><?php _e( 'Most Used' ); ?></a></li>
|
||||
</ul>
|
||||
|
||||
<div id="category-pop" class="tabs-panel" style="display: none;">
|
||||
<ul id="categorychecklist-pop" class="categorychecklist form-no-clear" >
|
||||
<?php $popular_ids = wp_popular_terms_checklist( 'category' ); ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div id="category-all" class="tabs-panel">
|
||||
<ul id="categorychecklist" data-wp-lists="list:category" class="categorychecklist form-no-clear">
|
||||
<?php wp_terms_checklist($post_ID, array( 'taxonomy' => 'category', 'popular_cats' => $popular_ids ) ) ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
|
||||
<p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
|
||||
<?php endif; ?>
|
||||
<?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
|
||||
<div id="category-adder" class="wp-hidden-children">
|
||||
<h4>
|
||||
<a id="category-add-toggle" href="#category-add" class="hide-if-no-js">
|
||||
<?php printf( __( '+ %s' ), $tax->labels->add_new_item ); ?>
|
||||
</a>
|
||||
</h4>
|
||||
<p id="category-add" class="category-add wp-hidden-child">
|
||||
<label class="screen-reader-text" for="newcategory"><?php echo $tax->labels->add_new_item; ?></label>
|
||||
<input type="text" name="newcategory" id="newcategory" class="form-required form-input-tip" value="<?php echo esc_attr( $tax->labels->new_item_name ); ?>" aria-required="true"/>
|
||||
<label class="screen-reader-text" for="newcategory_parent">
|
||||
<?php echo $tax->labels->parent_item_colon; ?>
|
||||
</label>
|
||||
<?php wp_dropdown_categories( array( 'taxonomy' => 'category', 'hide_empty' => 0, 'name' => 'newcategory_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '— ' . $tax->labels->parent_item . ' —' ) ); ?>
|
||||
<input type="button" id="category-add-submit" data-wp-lists="add:categorychecklist:category-add" class="button category-add-submit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" />
|
||||
<?php wp_nonce_field( 'add-category', '_ajax_nonce-add-category', false ); ?>
|
||||
<span id="category-ajax-response"></span>
|
||||
</p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="tagsdiv-post_tag" class="postbox">
|
||||
<div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
|
||||
<h3><span><?php _e('Tags'); ?></span></h3>
|
||||
<div class="inside">
|
||||
<div class="tagsdiv" id="post_tag">
|
||||
<div class="jaxtag">
|
||||
<label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
|
||||
<input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
|
||||
<div class="ajaxtag">
|
||||
<input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
|
||||
<input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="tagchecklist"></div>
|
||||
</div>
|
||||
<p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="posting">
|
||||
|
||||
<div id="wphead">
|
||||
<h1 id="site-heading">
|
||||
<a href="<?php echo get_option('home'); ?>/" target="_blank">
|
||||
<span id="site-title"><?php bloginfo('name'); ?></span>
|
||||
</a>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
if ( isset($posted) && intval($posted) ) {
|
||||
$post_ID = intval($posted); ?>
|
||||
<div id="message" class="updated">
|
||||
<p><strong><?php _e('Your post has been saved.'); ?></strong>
|
||||
<a onclick="window.opener.location.replace(this.href); window.close();" href="<?php echo get_permalink($post_ID); ?>"><?php _e('View post'); ?></a>
|
||||
| <a href="<?php echo get_edit_post_link( $post_ID ); ?>" onclick="window.opener.location.replace(this.href); window.close();"><?php _e('Edit Post'); ?></a>
|
||||
| <a href="#" onclick="window.close();"><?php _e('Close Window'); ?></a></p>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div id="titlediv">
|
||||
<div class="titlewrap">
|
||||
<input name="title" id="title" class="text" type="text" value="<?php echo esc_attr($title);?>"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="waiting" style="display: none"><span class="spinner"></span> <span><?php esc_html_e( 'Loading…' ); ?></span></div>
|
||||
|
||||
<div id="extra-fields" style="display: none"></div>
|
||||
|
||||
<div class="postdivrich">
|
||||
<?php
|
||||
|
||||
$editor_settings = array(
|
||||
'teeny' => true,
|
||||
'textarea_rows' => '15'
|
||||
);
|
||||
|
||||
$content = '';
|
||||
if ( $selection )
|
||||
$content .= $selection;
|
||||
|
||||
if ( $url ) {
|
||||
$content .= '<p>';
|
||||
|
||||
if ( $selection )
|
||||
$content .= __('via ');
|
||||
|
||||
$content .= sprintf( "<a href='%s'>%s</a>.</p>", esc_url( $url ), esc_html( $title ) );
|
||||
}
|
||||
|
||||
remove_action( 'media_buttons', 'media_buttons' );
|
||||
add_action( 'media_buttons', 'press_this_media_buttons' );
|
||||
function press_this_media_buttons() {
|
||||
_e( 'Add:' );
|
||||
|
||||
if ( current_user_can('upload_files') ) {
|
||||
?>
|
||||
<a id="photo_button" title="<?php esc_attr_e('Insert an Image'); ?>" href="#">
|
||||
<img alt="<?php esc_attr_e('Insert an Image'); ?>" src="<?php echo esc_url( admin_url( 'images/media-button-image.gif?ver=20100531' ) ); ?>"/></a>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<a id="video_button" title="<?php esc_attr_e('Embed a Video'); ?>" href="#"><img alt="<?php esc_attr_e('Embed a Video'); ?>" src="<?php echo esc_url( admin_url( 'images/media-button-video.gif?ver=20100531' ) ); ?>"/></a>
|
||||
<?php
|
||||
}
|
||||
|
||||
wp_editor( $content, 'content', $editor_settings );
|
||||
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div id="photo-add-url-div" style="display:none;">
|
||||
<table><tr>
|
||||
<td><label for="this_photo"><?php _e('URL') ?></label></td>
|
||||
<td><input type="text" id="this_photo" name="this_photo" class="tb_this_photo text" onkeypress="if(event.keyCode==13) image_selector(this);" /></td>
|
||||
</tr><tr>
|
||||
<td><label for="this_photo_description"><?php _e('Description') ?></label></td>
|
||||
<td><input type="text" id="this_photo_description" name="photo_description" class="tb_this_photo_description text" onkeypress="if(event.keyCode==13) image_selector(this);" value="<?php echo esc_attr($title);?>"/></td>
|
||||
</tr><tr>
|
||||
<td><input type="button" class="button" onclick="image_selector(this)" value="<?php esc_attr_e('Insert Image'); ?>" /></td>
|
||||
</tr></table>
|
||||
</div>
|
||||
<?php
|
||||
/** This action is documented in wp-admin/admin-footer.php */
|
||||
do_action( 'admin_footer' );
|
||||
/** This action is documented in wp-admin/admin-footer.php */
|
||||
do_action( 'admin_print_footer_scripts' );
|
||||
?>
|
||||
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
|
||||
</body>
|
||||
</html>
|
||||
$GLOBALS['wp_press_this']->html();
|
||||
|
@ -38,15 +38,62 @@ require_once( ABSPATH . 'wp-admin/admin-header.php' );
|
||||
<?php if ( current_user_can('edit_posts') ) : ?>
|
||||
<div class="tool-box">
|
||||
<h3 class="title"><?php _e('Press This') ?></h3>
|
||||
<p><?php _e('Press This is a bookmarklet: a little app that runs in your browser and lets you grab bits of the web.');?></p>
|
||||
|
||||
<p><?php _e('Use Press This to clip text, images and videos from any web page. Then edit and add more straight from Press This before you save or publish it in a post on your site.'); ?></p>
|
||||
<p class="description"><?php _e('Drag-and-drop the following link to your bookmarks bar or right click it and add it to your favorites for a posting shortcut.') ?></p>
|
||||
<p class="pressthis"><a onclick="return false;" oncontextmenu="if(window.navigator.userAgent.indexOf('WebKit')!=-1||window.navigator.userAgent.indexOf('MSIE')!=-1){jQuery('.pressthis-code').show().find('textarea').focus().select();return false;}" href="<?php echo htmlspecialchars( get_shortcut_link() ); ?>"><span><?php _e('Press This') ?></span></a></p>
|
||||
<div class="pressthis-code" style="display:none;">
|
||||
<p class="description"><?php _e('If your bookmarks toolbar is hidden: copy the code below, open your Bookmarks manager, create new bookmark, type Press This into the name field and paste the code into the URL field.') ?></p>
|
||||
<p><textarea rows="5" cols="120" readonly="readonly"><?php echo htmlspecialchars( get_shortcut_link() ); ?></textarea></p>
|
||||
<div class="postbox press-this-install">
|
||||
<p><?php _e( 'Press This is a little app that lets you grab bits of the web and create new posts with ease.' );?></p>
|
||||
<p><?php _e( 'Use Press This to clip text, images and videos from any web page. Then edit and add more straight from Press This before you save or publish it in a post on your site.' ); ?></p>
|
||||
</div>
|
||||
|
||||
<form>
|
||||
<div class="postbox press-this-install">
|
||||
<h3><?php _e( 'Install Press This' ); ?></h3>
|
||||
<h4><?php _e( 'Bookmarklet' ); ?></h4>
|
||||
<p><?php _e( 'Drag the bookmarklet below to your bookmarks bar. Then, when you\'re on a page you want to share, simply "press" it.' ); ?></p>
|
||||
|
||||
<p class="pressthis">
|
||||
<a class="" onclick="return false;" href="<?php echo htmlspecialchars( get_shortcut_link() ); ?>"><span><?php _e( 'Press This' ) ?></span></a>
|
||||
<button type="button" class="button button-secondary js-show-pressthis-code-wrap" aria-expanded="false" aria-controls="pressthis-code-wrap">
|
||||
<span class="dashicons dashicons-clipboard"></span>
|
||||
<span class="screen-reader-text"><?php _e( 'Copy Press This Bookmarklet' ) ?></span>
|
||||
</button>
|
||||
</p>
|
||||
|
||||
<div class="hidden js-pressthis-code-wrap">
|
||||
<p id="pressthis-code-desc">
|
||||
<?php _e( 'If you can\'t drag it to your bookmarks, copy the following code and create new bookmark. Paste the code into the new bookmark\'s URL field.' ) ?>
|
||||
</p>
|
||||
<p>
|
||||
<textarea class="js-pressthis-code" rows="5" cols="120" readonly="readonly" aria-labelledby="pressthis-code-desc"><?php echo htmlspecialchars( get_shortcut_link() ); ?></textarea>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<h4><?php _e( 'Direct link (best for mobile)' ); ?></h4>
|
||||
<p><?php _e( 'Follow the link to open Press This. Then add it to your device\'s bookmarks or home screen.' ); ?></p>
|
||||
|
||||
<p>
|
||||
<a class="button button-secondary" href="<?php echo htmlspecialchars( admin_url( 'press-this.php' ) ); ?>"><?php _e( 'Open Press This' ) ?></a>
|
||||
</p>
|
||||
<script>
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
var $showPressThisWrap = $( '.js-show-pressthis-code-wrap' );
|
||||
var $pressthisCode = $( '.js-pressthis-code' );
|
||||
|
||||
$showPressThisWrap.on( 'click', function( event ) {
|
||||
var $this = $( this );
|
||||
|
||||
$this.parent().next( '.js-pressthis-code-wrap' ).slideToggle( 200 );
|
||||
$this.attr( 'aria-expanded', $this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
|
||||
});
|
||||
|
||||
// Select Press This code when focusing (tabbing) or clicking the textarea.
|
||||
$pressthisCode.on( 'click focus', function() {
|
||||
var self = this;
|
||||
setTimeout( function() { self.select(); }, 50 );
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
endif;
|
||||
|
@ -2594,23 +2594,54 @@ function paginate_comments_links($args = array()) {
|
||||
* @return string The Press This bookmarklet link URL.
|
||||
*/
|
||||
function get_shortcut_link() {
|
||||
// In case of breaking changes, version this. #WP20071
|
||||
$link = "javascript:
|
||||
var d=document,
|
||||
w=window,
|
||||
e=w.getSelection,
|
||||
k=d.getSelection,
|
||||
x=d.selection,
|
||||
s=(e?e():(k)?k():(x?x.createRange().text:0)),
|
||||
f='" . admin_url('press-this.php') . "',
|
||||
l=d.location,
|
||||
e=encodeURIComponent,
|
||||
u=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=4';
|
||||
a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=720,height=570'))l.href=u;};
|
||||
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();
|
||||
void(0)";
|
||||
global $is_IE, $wp_version;
|
||||
|
||||
$link = str_replace(array("\r", "\n", "\t"), '', $link);
|
||||
$bookmarklet_version = 5;
|
||||
$link = '';
|
||||
|
||||
if ( $is_IE ) {
|
||||
/**
|
||||
* Return the old/shorter bookmarklet code for MSIE 8 and lower,
|
||||
* since they only support a max length of ~2000 characters for
|
||||
* bookmark[let] URLs, which is way to small for our smarter one.
|
||||
* Do update the version number so users do not get the "upgrade your
|
||||
* bookmarklet" notice when using PT in those browsers.
|
||||
*/
|
||||
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||
|
||||
if ( ! empty( $ua ) && preg_match( '/\bMSIE (\d)/', $ua, $matches ) && (int) $matches[1] <= 8 ) {
|
||||
$link = "javascript:
|
||||
var d=document,
|
||||
w=window,
|
||||
e=w.getSelection,
|
||||
k=d.getSelection,
|
||||
x=d.selection,
|
||||
s=(e?e():(k)?k():(x?x.createRange().text:0)),
|
||||
f='" . admin_url('press-this.php') . "',
|
||||
l=d.location,
|
||||
e=encodeURIComponent,
|
||||
u=f+'?u='+e(l.href)+'&t='+e(d.title)+'&s='+e(s)+'&v=" . $bookmarklet_version . "';
|
||||
a=function(){if(!w.open(u,'t','toolbar=0,resizable=1,scrollbars=1,status=1,width=600,height=700'))l.href=u;};
|
||||
if (/Firefox/.test(navigator.userAgent)) setTimeout(a, 0); else a();
|
||||
void(0)";
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $link ) ) {
|
||||
$suffix = '.min';
|
||||
$develop_src = false !== strpos( $wp_version, '-src' );
|
||||
|
||||
if ( $develop_src || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
|
||||
$suffix = '';
|
||||
}
|
||||
|
||||
$url = admin_url( 'press-this.php' ) . '?v=' . $bookmarklet_version;
|
||||
|
||||
$link = 'javascript:' . file_get_contents( ABSPATH . "wp-admin/js/bookmarklet$suffix.js" );
|
||||
$link = str_replace( 'window.pt_url', wp_json_encode( $url ), $link );
|
||||
}
|
||||
|
||||
$link = str_replace( array( "\r", "\n", "\t" ), '', $link );
|
||||
|
||||
/**
|
||||
* Filter the Press This bookmarklet link.
|
||||
|
@ -439,7 +439,12 @@ function wp_default_scripts( &$scripts ) {
|
||||
|
||||
$scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array('jquery-ui-sortable'), false, 1 );
|
||||
|
||||
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array('suggest', 'wp-lists', 'postbox'), false, 1 );
|
||||
$scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'suggest' ), false, 1 );
|
||||
did_action( 'init' ) && $scripts->localize( 'tags-box', 'tagsBoxL10n', array(
|
||||
'tagDelimiter' => _x( ',', 'tag delimiter' ),
|
||||
) );
|
||||
|
||||
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box' ), false, 1 );
|
||||
did_action( 'init' ) && $scripts->localize( 'post', 'postL10n', array(
|
||||
'ok' => __('OK'),
|
||||
'cancel' => __('Cancel'),
|
||||
@ -461,11 +466,43 @@ function wp_default_scripts( &$scripts ) {
|
||||
'password' => __('Password Protected'),
|
||||
'privatelyPublished' => __('Privately Published'),
|
||||
'published' => __('Published'),
|
||||
'comma' => _x( ',', 'tag delimiter' ),
|
||||
'saveAlert' => __('The changes you made will be lost if you navigate away from this page.'),
|
||||
'savingText' => __('Saving Draft…'),
|
||||
) );
|
||||
|
||||
$scripts->add( 'press-this', "/wp-admin/js/press-this$suffix.js", array( 'jquery', 'tags-box' ), false, 1 );
|
||||
did_action( 'init' ) && $scripts->localize( 'press-this', 'pressThisL10n', array(
|
||||
/**
|
||||
* press_this_source_string: string displayed before the source attribution string, defaults to "Source:".
|
||||
*
|
||||
* @since 4.2
|
||||
* @see https://github.com/MichaelArestad/Press-This/issues/25
|
||||
*
|
||||
* @param string $string Internationalized source string
|
||||
*
|
||||
* @return string Source string
|
||||
*/
|
||||
'source' => apply_filters( 'press_this_source_string', __( 'Source:' ) ),
|
||||
|
||||
/**
|
||||
* press_this_source_link: HTML link format for the source attribution, can control target, class, etc
|
||||
*
|
||||
* @since 4.2
|
||||
* @see https://github.com/MichaelArestad/Press-This/issues/25
|
||||
*
|
||||
* @param string $link_format Internationalized link format, %1$s is link href, %2$s is link text
|
||||
*
|
||||
* @return string Link markup
|
||||
*/
|
||||
'sourceLink' => apply_filters( 'press_this_source_link', __( '<a href="%1$s">%2$s</a>' ) ),
|
||||
'newPost' => __( 'Title' ),
|
||||
'unexpectedError' => __( 'Sorry, but an unexpected error occurred.' ),
|
||||
'saveAlert' => __( 'The changes you made will be lost if you navigate away from this page.' ),
|
||||
'allMediaHeading' => __( 'Suggested media' ),
|
||||
'suggestedEmbedAlt' => __( 'Suggested embed #%d' ),
|
||||
'suggestedImgAlt' => __( 'Suggested image #%d' ),
|
||||
) );
|
||||
|
||||
$scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery' ), false, 1 );
|
||||
|
||||
$scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );
|
||||
@ -633,8 +670,9 @@ function wp_default_styles( &$styles ) {
|
||||
$styles->add( 'wp-color-picker', "/wp-admin/css/color-picker$suffix.css" );
|
||||
$styles->add( 'customize-controls', "/wp-admin/css/customize-controls$suffix.css", array( 'wp-admin', 'colors', 'ie', 'imgareaselect' ) );
|
||||
$styles->add( 'customize-widgets', "/wp-admin/css/customize-widgets$suffix.css", array( 'wp-admin', 'colors' ) );
|
||||
$styles->add( 'ie', "/wp-admin/css/ie$suffix.css" );
|
||||
$styles->add( 'press-this', "/wp-admin/css/press-this$suffix.css", array( 'open-sans' ) );
|
||||
|
||||
$styles->add( 'ie', "/wp-admin/css/ie$suffix.css" );
|
||||
$styles->add_data( 'ie', 'conditional', 'lte IE 7' );
|
||||
|
||||
// Common dependencies
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.2-alpha-31533';
|
||||
$wp_version = '4.2-alpha-31534';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user