]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-admin/press-this.php
WordPress 4.1.3
[autoinstalls/wordpress.git] / wp-admin / press-this.php
index b84025290540df380c1bfccf648300e3ca217e36..6ae7341f3459a98002c81be19e5bb6fe3e84783c 100644 (file)
@@ -9,18 +9,16 @@
 define('IFRAME_REQUEST' , true);
 
 /** WordPress Administration Bootstrap */
-require_once('./admin.php');
+require_once( dirname( __FILE__ ) . '/admin.php' );
 
 header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
 
-if ( ! current_user_can('edit_posts') )
-       wp_die( __( 'Cheatin’ uh?' ) );
+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.
  *
- * @package WordPress
- * @subpackage Press_This
  * @since 2.6.0
  *
  * @return int Post ID
@@ -42,7 +40,7 @@ function press_it() {
        $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.
+                       // 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);
@@ -53,7 +51,7 @@ function press_it() {
                        }
                }
        }
-       // set the post_content and status
+       // Set the post_content and status.
        $post['post_content'] = $content;
        if ( isset( $_POST['publish'] ) && current_user_can( 'publish_posts' ) )
                $post['post_status'] = 'publish';
@@ -62,12 +60,12 @@ function press_it() {
        else
                $post['post_status'] = 'draft';
 
-       // error handling for media_sideload
+       // Error handling for media_sideload.
        if ( is_wp_error($upload) ) {
                wp_delete_post($post_ID);
-               wp_die($upload);
+               wp_die( esc_html( $upload->get_error_message() ) );
        } else {
-               // Post formats
+               // Post formats.
                if ( isset( $_POST['post_format'] ) ) {
                        if ( current_theme_supports( 'post-formats', $_POST['post_format'] ) )
                                set_post_format( $post_ID, $_POST['post_format'] );
@@ -91,11 +89,11 @@ if ( isset($_REQUEST['action']) && 'post' == $_REQUEST['action'] ) {
 }
 
 // Set Variables
-$title = isset( $_GET['t'] ) ? trim( strip_tags( html_entity_decode( stripslashes( $_GET['t'] ) , ENT_QUOTES) ) ) : '';
+$title = isset( $_GET['t'] ) ? trim( strip_tags( html_entity_decode( wp_unslash( $_GET['t'] ) , ENT_QUOTES) ) ) : '';
 
 $selection = '';
 if ( !empty($_GET['s']) ) {
-       $selection = str_replace(''', "'", stripslashes($_GET['s']));
+       $selection = str_replace(''', "'", wp_unslash($_GET['s']));
        $selection = trim( htmlspecialchars( html_entity_decode($selection, ENT_QUOTES) ) );
 }
 
@@ -110,7 +108,7 @@ $image = isset($_GET['i']) ? $_GET['i'] : '';
 if ( !empty($_REQUEST['ajax']) ) {
        switch ($_REQUEST['ajax']) {
                case 'video': ?>
-                       <script type="text/javascript" charset="utf-8">
+                       <script type="text/javascript">
                        /* <![CDATA[ */
                                jQuery('.select').click(function() {
                                        append_editor(jQuery('#embed-code').val());
@@ -133,7 +131,7 @@ if ( !empty($_REQUEST['ajax']) ) {
                        <?php break;
 
                case 'photo_thickbox': ?>
-                       <script type="text/javascript" charset="utf-8">
+                       <script type="text/javascript">
                                /* <![CDATA[ */
                                jQuery('.cancel').click(function() {
                                        tb_remove();
@@ -146,14 +144,14 @@ if ( !empty($_REQUEST['ajax']) ) {
                        <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" onkeypress="if(event.keyCode==13) image_selector(this);" value="<?php echo esc_attr($title);?>"/>
+                                       <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" />
+                               <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 echo esc_attr(__('Click to insert.')); ?>" title="<?php echo esc_attr(__('Click to insert.')); ?>" />
+                                       <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>
 
@@ -163,8 +161,6 @@ if ( !empty($_REQUEST['ajax']) ) {
                /**
                 * Retrieve all image URLs from given URI.
                 *
-                * @package WordPress
-                * @subpackage Press_This
                 * @since 2.6.0
                 *
                 * @param string $uri
@@ -172,7 +168,7 @@ if ( !empty($_REQUEST['ajax']) ) {
                 */
                function get_images_from_uri($uri) {
                        $uri = preg_replace('/\/#.+?$/','', $uri);
-                       if ( preg_match('/\.(jpg|jpe|jpeg|png|gif)$/', $uri) && !strpos($uri,'blogger.com') )
+                       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 )
@@ -185,9 +181,10 @@ if ( !empty($_REQUEST['ajax']) ) {
                                return '';
                        $sources = array();
                        foreach ($matches[3] as $src) {
-                               // if no http in url
+
+                               // If no http in URL.
                                if (strpos($src, 'http') === false)
-                                       // if it doesn't have a relative uri
+                                       // 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
@@ -201,7 +198,7 @@ if ( !empty($_REQUEST['ajax']) ) {
                break;
 
        case 'photo_js': ?>
-               // gather images and load some default JS
+               // Gather images and load some default JS.
                var last = null
                var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
                if(photostorage == false) {
@@ -288,7 +285,7 @@ if ( !empty($_REQUEST['ajax']) ) {
                        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"><?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('#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;
 }
@@ -297,37 +294,52 @@ 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">
 //<![CDATA[
 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 userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time() ?>'};
-var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = 'press-this', isRtl = <?php echo (int) is_rtl(); ?>;
+var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'press-this', isRtl = <?php echo (int) is_rtl(); ?>;
 var photostorage = false;
 //]]>
 </script>
 
 <?php
-       do_action('admin_print_styles');
-       do_action('admin_print_scripts');
-       do_action('admin_head');
+       /** 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' );
 ?>
-       <style type="text/css">
-       #message {
-               margin: 10px 0;
-       }
-       #title,
-       .press-this #wphead {
-               margin-left: 0;
-               margin-right: 0;
-       }
-       .rtl.press-this #header-logo,
-       .rtl.press-this #wphead h1 {
-               float: right;
-       }
-       </style>
        <script type="text/javascript">
        var wpActiveEditor = 'content';
 
@@ -365,12 +377,12 @@ var photostorage = false;
                                        <?php
                                        $content = '';
                                        if ( preg_match("/youtube\.com\/watch/i", $url) ) {
-                                               list($domain, $video_id) = split("v=", $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) = split(".com/", $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 . '&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" />      <embed src="http://www.vimeo.com/moogaloop.swf?clip_id=' . $video_id . '&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="225"></embed></object>';
 
@@ -427,29 +439,43 @@ var photostorage = false;
                }
        }
        jQuery(document).ready(function($) {
-               //resize screen
-               window.resizeTo(720,580);
-               // set button actions
+               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
+
+               // 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) ) { ?>
+               <?php } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
                        show('photo');
                <?php } ?>
                jQuery('#title').unbind();
-               jQuery('#publish, #save').click(function() { jQuery('#saving').css('display', 'inline'); });
+               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>
-<body class="press-this wp-admin<?php if ( is_rtl() ) echo ' rtl'; ?>">
+<?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">
@@ -477,7 +503,7 @@ var photostorage = false;
                                                        echo '<br /><br />';
                                                        submit_button( __( 'Submit for Review' ), 'primary', 'review', false );
                                                } ?>
-                                               <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" id="saving" style="display:none;" />
+                                               <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' );
@@ -487,7 +513,7 @@ var photostorage = false;
                                        <p>
                                                <label for="post_format"><?php _e( 'Post Format:' ); ?>
                                                <select name="post_format" id="post_format">
-                                                       <option value="0"><?php _ex( 'Standard', 'Post format' ); ?></option>
+                                                       <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; ?>
@@ -505,8 +531,8 @@ var photostorage = false;
                                <div id="taxonomy-category" class="categorydiv">
 
                                        <ul id="category-tabs" class="category-tabs">
-                                               <li class="tabs"><a href="#category-all" tabindex="3"><?php echo $tax->labels->all_items; ?></a></li>
-                                               <li class="hide-if-no-js"><a href="#category-pop" tabindex="3"><?php _e( 'Most Used' ); ?></a></li>
+                                               <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;">
@@ -516,7 +542,7 @@ var photostorage = false;
                                        </div>
 
                                        <div id="category-all" class="tabs-panel">
-                                               <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
+                                               <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>
@@ -527,18 +553,18 @@ var photostorage = false;
                                        <?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" tabindex="3">
+                                                               <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 ); ?>" tabindex="3" aria-required="true"/>
+                                                               <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' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;', 'tab_index' => 3 ) ); ?>
-                                                               <input type="button" id="category-add-submit" class="add:categorychecklist:category-add button category-add-sumbit" value="<?php echo esc_attr( $tax->labels->add_new_item ); ?>" tabindex="3" />
+                                                               <?php wp_dropdown_categories( array( 'taxonomy' => 'category', 'hide_empty' => 0, 'name' => 'newcategory_parent', 'orderby' => 'name', 'hierarchical' => 1, 'show_option_none' => '&mdash; ' . $tax->labels->parent_item . ' &mdash;' ) ); ?>
+                                                               <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>
@@ -558,7 +584,7 @@ var photostorage = false;
                                                        <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'); ?>" tabindex="3" />
+                                                               <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
                                                        </div>
                                                </div>
                                                <div class="tagchecklist"></div>
@@ -571,7 +597,6 @@ var photostorage = false;
        <div class="posting">
 
                <div id="wphead">
-                       <img id="header-logo" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" alt="" width="16" height="16" />
                        <h1 id="site-heading">
                                <a href="<?php echo get_option('home'); ?>/" target="_blank">
                                        <span id="site-title"><?php bloginfo('name'); ?></span>
@@ -592,11 +617,11 @@ var photostorage = false;
 
                <div id="titlediv">
                        <div class="titlewrap">
-                               <input name="title" id="title" class="text" value="<?php echo esc_attr($title);?>"/>
+                               <input name="title" id="title" class="text" type="text" value="<?php echo esc_attr($title);?>"/>
                        </div>
                </div>
 
-               <div id="waiting" style="display: none"><img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" /> <?php esc_html_e( 'Loading...' ); ?></div>
+               <div id="waiting" style="display: none"><span class="spinner"></span> <span><?php esc_html_e( 'Loading&hellip;' ); ?></span></div>
 
                <div id="extra-fields" style="display: none"></div>
 
@@ -610,7 +635,7 @@ var photostorage = false;
 
                $content = '';
                if ( $selection )
-                       $content .=  $selection;
+                       $content .= $selection;
 
                if ( $url ) {
                        $content .= '<p>';
@@ -656,8 +681,10 @@ var photostorage = false;
        </tr></table>
 </div>
 <?php
-do_action('admin_footer');
-do_action('admin_print_footer_scripts');
+/** 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>