Make WordPress Core

Ticket #21551: 21551.diff

File 21551.diff, 36.1 KB (added by georgestephanis, 13 years ago)
  • wp-admin/includes/press-this.php

     
     1<?php
     2/**
     3 * Press This Functions
     4 *
     5 * @package WordPress
     6 * @subpackage Press_This
     7 */
     8
     9/**
     10 * Press It form handler.
     11 *
     12 * @package WordPress
     13 * @subpackage Press_This
     14 * @since 2.6.0
     15 *
     16 * @return int Post ID
     17 */
     18function press_it( $post_type ) {
     19
     20        $post = get_default_post_to_edit( $post_type );
     21        $post = get_object_vars( $post );
     22        $post_ID = $post['ID'] = (int) $_POST['post_id'];
     23
     24        if ( ! current_user_can( 'edit_post', $post_ID ) )
     25                wp_die( __('You are not allowed to edit this post.' ) );
     26
     27        $post['post_category'] = isset( $_POST['post_category'] ) ? $_POST['post_category'] : '';
     28        $post['tax_input'] = isset( $_POST['tax_input'] ) ? $_POST['tax_input'] : '';
     29        $post['post_title'] = isset( $_POST['title'] ) ? $_POST['title'] : '';
     30        $content = isset( $_POST['content'] ) ? $_POST['content'] : '';
     31
     32        $upload = false;
     33        if ( !empty( $_POST['photo_src'] ) && current_user_can( 'upload_files' ) ) {
     34                foreach( (array) $_POST['photo_src'] as $key => $image) {
     35                        // see if files exist in content - we don't want to upload non-used selected files.
     36                        if ( strpos( $_POST['content'], htmlspecialchars( $image ) ) !== false ) {
     37                                $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
     38                                $upload = media_sideload_image( $image, $post_ID, $desc );
     39
     40                                // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
     41                                if ( !is_wp_error($upload) )
     42                                        $content = preg_replace( '/<img ([^>]*)src=\\\?(\"|\')' . preg_quote( htmlspecialchars( $image ), '/' ) . '\\\?(\2)([^>\/]*)\/*>/is', $upload, $content );
     43                        }
     44                }
     45        }
     46
     47        // set the post_content and status
     48        $post['post_content'] = $content;
     49        if ( isset( $_POST['publish'] ) && current_user_can( 'publish_posts' ) )
     50                $post['post_status'] = 'publish';
     51        elseif ( isset( $_POST['review'] ) )
     52                $post['post_status'] = 'pending';
     53        else
     54                $post['post_status'] = 'draft';
     55
     56        // error handling for media_sideload
     57        if ( is_wp_error( $upload ) ) {
     58                wp_delete_post( $post_ID );
     59                wp_die( $upload );
     60        } else {
     61                // Post formats
     62                if ( isset( $_POST['post_format'] ) ) {
     63                        if ( current_theme_supports( 'post-formats', $_POST['post_format'] ) )
     64                                set_post_format( $post_ID, $_POST['post_format'] );
     65                        elseif ( '0' == $_POST['post_format'] )
     66                                set_post_format( $post_ID, false );
     67                }
     68
     69                $post_ID = wp_update_post($post);
     70        }
     71
     72        return $post_ID;
     73}
     74
     75/**
     76 * Retrieve all image URLs from given URI.
     77 *
     78 * @package WordPress
     79 * @subpackage Press_This
     80 * @since 2.6.0
     81 *
     82 * @param string $uri
     83 * @return string
     84 */
     85function get_images_from_uri( $uri ) {
     86        $uri = preg_replace( '/\/#.+?$/', '', $uri );
     87        if ( preg_match( '/\.(jpe?g|jpe|gif|png)\b/i', $uri ) && ! strpos( $uri, 'blogger.com' ) )
     88                return "'" . esc_attr( html_entity_decode( $uri ) ) . "'";
     89
     90        $content = wp_remote_fopen( $uri );
     91        if ( false === $content )
     92                return '';
     93
     94        $host = parse_url($uri);
     95        $pattern = '/<img ([^>]*)src=(\"|\')([^<>\'\"]+)(\2)([^>]*)\/*>/i';
     96        $content = str_replace( array("\n","\t","\r"), '', $content );
     97        preg_match_all( $pattern, $content, $matches );
     98        if ( empty($matches[0]) )
     99                return '';
     100
     101        $sources = array();
     102        foreach ( $matches[3] as $src ) {
     103                // if no http in url
     104                if ( strpos( $src, 'http' ) === false )
     105                        // if it doesn't have a relative uri
     106                        if ( strpos( $src, '../' ) === false && strpos( $src, './' ) === false && strpos( $src, '/' ) === 0 )
     107                                $src = 'http://' . str_replace( '//', '/', $host['host'] . '/' . $src );
     108                        else
     109                                $src = 'http://' . str_replace( '//', '/', $host['host'] . '/' . dirname( $host['path'] ) . '/' . $src );
     110                $sources[] = esc_url( $src );
     111        }
     112        return "'" . implode( "','", $sources ) . "'";
     113}
     114
     115
     116function press_this_ajax( $ajax ){
     117        global $title, $url, $image, $selection;
     118
     119        switch ( $ajax ) {
     120                case 'video': ?>
     121                        <script>
     122                        /* <![CDATA[ */
     123                                jQuery('.select').click(function() {
     124                                        append_editor(jQuery('#embed-code').val());
     125                                        jQuery('#extra-fields').hide();
     126                                        jQuery('#extra-fields').html('');
     127                                });
     128                                jQuery('.close').click(function() {
     129                                        jQuery('#extra-fields').hide();
     130                                        jQuery('#extra-fields').html('');
     131                                });
     132                        /* ]]> */
     133                        </script>
     134                        <div class="postbox">
     135                                <h2><label for="embed-code"><?php _e( 'Embed Code' ) ?></label></h2>
     136                                <div class="inside">
     137                                        <textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo esc_textarea( $selection ); ?></textarea>
     138                                        <p id="options">
     139                                                <a href="#" class="select button"><?php _e( 'Insert Video' ); ?></a>
     140                                                <a href="#" class="close button"><?php _e( 'Cancel' ); ?></a>
     141                                        </p>
     142                                </div>
     143                        </div>
     144                        <?php break;
     145
     146                case 'photo_thickbox': ?>
     147                        <script>
     148                                /* <![CDATA[ */
     149                                jQuery('.cancel').click(function() {
     150                                        tb_remove();
     151                                });
     152                                jQuery('.select').click(function() {
     153                                        image_selector(this);
     154                                });
     155                                /* ]]> */
     156                        </script>
     157                        <h3 class="tb"><label for="tb_this_photo_description"><?php _e( 'Description' ) ?></label></h3>
     158                        <div class="titlediv">
     159                                <div class="titlewrap">
     160                                        <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 );?>"/>
     161                                </div>
     162                        </div>
     163
     164                        <p class="centered">
     165                                <input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="tb_this_photo" class="tb_this_photo" />
     166                                <a href="#" class="select">
     167                                        <img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr( __( 'Click to insert.' ) ); ?>" title="<?php echo esc_attr( __( 'Click to insert.' ) ); ?>" />
     168                                </a>
     169                        </p>
     170
     171                        <p id="options">
     172                                <a href="#" class="select button"><?php _e( 'Insert Image' ); ?></a>
     173                                <a href="#" class="cancel button"><?php _e( 'Cancel' ); ?></a>
     174                        </p>
     175                        <?php break;
     176                case 'photo_images':
     177                        $url = wp_kses( urldecode( $url ), null );
     178                        echo 'new Array(' . get_images_from_uri( $url ) . ')';
     179                        break;
     180                case 'photo_js': ?>
     181                        // gather images and load some default JS
     182                        var last = null
     183                        var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
     184                        if(photostorage == false) {
     185                        var my_src = eval(
     186                                jQuery.ajax({
     187                                        type: "GET",
     188                                        url: "<?php echo esc_url( $_SERVER['PHP_SELF'] ); ?>",
     189                                        cache : false,
     190                                        async : false,
     191                                        data: "ajax=photo_images&u=<?php echo urlencode( $url ); ?>",
     192                                        dataType : "script"
     193                                }).responseText
     194                        );
     195                        if(my_src.length == 0) {
     196                                var my_src = eval(
     197                                        jQuery.ajax({
     198                                                type: "GET",
     199                                                url: "<?php echo esc_url( $_SERVER['PHP_SELF'] ); ?>",
     200                                                cache : false,
     201                                                async : false,
     202                                                data: "ajax=photo_images&u=<?php echo urlencode( $url ); ?>",
     203                                                dataType : "script"
     204                                        }).responseText
     205                                );
     206                                if(my_src.length == 0) {
     207                                        strtoappend = '<?php _e( 'Unable to retrieve images or no images on page.' ); ?>';
     208                                }
     209                        }
     210                        }
     211                        for (i = 0; i < my_src.length; i++) {
     212                                img = new Image();
     213                                img.src = my_src[i];
     214                                img_attr = 'id="img' + i + '"';
     215                                skip = false;
     216       
     217                                maybeappend = '<a href="?ajax=photo_thickbox&amp;i=' + encodeURIComponent(img.src) + '&amp;u=<?php echo urlencode($url); ?>&amp;height=400&amp;width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
     218       
     219                                if (img.width && img.height) {
     220                                        if (img.width >= 30 && img.height >= 30) {
     221                                                aspect = img.width / img.height;
     222                                                scale = (aspect > 1) ? (71 / img.width) : (71 / img.height);
     223       
     224                                                w = img.width;
     225                                                h = img.height;
     226       
     227                                                if (scale < 1) {
     228                                                        w = parseInt(img.width * scale);
     229                                                        h = parseInt(img.height * scale);
     230                                                }
     231                                                img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
     232                                                strtoappend += maybeappend;
     233                                        }
     234                                } else {
     235                                        strtoappend += maybeappend;
     236                                }
     237                        }
     238       
     239                        function pick(img, desc) {
     240                                if (img) {
     241                                        if('object' == typeof jQuery('.photolist input') && jQuery('.photolist input').length != 0) length = jQuery('.photolist input').length;
     242                                        if(length == 0) length = 1;
     243                                        jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
     244                                        jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
     245                                        insert_editor( "\n\n" + encodeURI('<p style="text-align: center;"><a href="<?php echo $url; ?>"><img src="' + img +'" alt="' + desc + '" /></a></p>'));
     246                                }
     247                                return false;
     248                        }
     249       
     250                        function image_selector(el) {
     251                                var desc, src, parent = jQuery(el).closest('#photo-add-url-div');
     252       
     253                                if ( parent.length ) {
     254                                        desc = parent.find('input.tb_this_photo_description').val() || '';
     255                                        src = parent.find('input.tb_this_photo').val() || ''
     256                                } else {
     257                                        desc = jQuery('#tb_this_photo_description').val() || '';
     258                                        src = jQuery('#tb_this_photo').val() || ''
     259                                }
     260       
     261                                tb_remove();
     262                                pick(src, desc);
     263                                jQuery('#extra-fields').hide();
     264                                jQuery('#extra-fields').html('');
     265                                return false;
     266                        }
     267       
     268                        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>');
     269                        jQuery('#img_container').html(strtoappend);
     270                        <?php break;
     271        }
     272        exit;
     273}
     274
     275function press_this_media_buttons() {
     276        _e( 'Add:' );
     277
     278        if ( current_user_can( 'upload_files' ) ) {
     279                add_action( 'admin_footer', 'press_this_add_photo_by_url_div' );
     280                ?>
     281                <a id="photo_button" title="<?php esc_attr_e('Insert an Image'); ?>" href="javascript:;">
     282                        <img src="<?php echo esc_url( admin_url( 'images/media-button-image.gif?ver=20100531' ) ); ?>" width="14" height="12" alt="<?php esc_attr_e( 'Insert an Image' ); ?>" />
     283                </a>
     284                <?php
     285        }
     286        ?>
     287
     288        <a id="video_button" title="<?php esc_attr_e( 'Embed a Video' ); ?>" href="javascript:;">
     289                <img src="<?php echo esc_url( admin_url( 'images/media-button-video.gif?ver=20100531' ) ); ?>" width="13" height="12" alt="<?php esc_attr_e( 'Embed a Video' ); ?>" />
     290        </a>
     291        <?php
     292}
     293
     294function press_this_add_photo_by_url_div() {
     295        ?>
     296        <div id="photo-add-url-div" style="display:none;">
     297                <table>
     298                        <tr>
     299                                <th scope="row"><label for="this_photo"><?php _e( 'URL' ) ?></label></th>
     300                                <td><input type="text" id="this_photo" name="this_photo" class="tb_this_photo text" onkeypress="if(event.keyCode==13) image_selector(this);" /></td>
     301                        </tr>
     302                        <tr>
     303                                <th scope="row"><label for="this_photo_description"><?php _e( 'Description' ) ?></label></th>
     304                                <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>
     305                        </tr>
     306                        <tr>
     307                                <td></td>
     308                                <td><input type="button" class="button" onclick="image_selector(this)" value="<?php esc_attr_e( 'Insert Image' ); ?>" /></td>
     309                        </tr>
     310                </table>
     311        </div>
     312        <?php
     313}
  • wp-admin/press-this.php

     
    99define('IFRAME_REQUEST' , true);
    1010
    1111/** WordPress Administration Bootstrap */
    12 require_once('./admin.php');
     12require_once( './admin.php' );
    1313
    14 header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
     14header( 'Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset') );
    1515
    1616if ( ! current_user_can('edit_posts') )
    1717        wp_die( __( 'Cheatin&#8217; uh?' ) );
    1818
    19 /**
    20  * Press It form handler.
    21  *
    22  * @package WordPress
    23  * @subpackage Press_This
    24  * @since 2.6.0
    25  *
    26  * @return int Post ID
    27  */
    28 function press_it() {
     19require_once( './includes/press-this.php' );
    2920
    30         $post = get_default_post_to_edit();
    31         $post = get_object_vars($post);
    32         $post_ID = $post['ID'] = (int) $_POST['post_id'];
     21define( 'PRESS_THIS_POST_TYPE', 'post' );
    3322
    34         if ( !current_user_can('edit_post', $post_ID) )
    35                 wp_die(__('You are not allowed to edit this post.'));
    36 
    37         $post['post_category'] = isset($_POST['post_category']) ? $_POST['post_category'] : '';
    38         $post['tax_input'] = isset($_POST['tax_input']) ? $_POST['tax_input'] : '';
    39         $post['post_title'] = isset($_POST['title']) ? $_POST['title'] : '';
    40         $content = isset($_POST['content']) ? $_POST['content'] : '';
    41 
    42         $upload = false;
    43         if ( !empty($_POST['photo_src']) && current_user_can('upload_files') ) {
    44                 foreach( (array) $_POST['photo_src'] as $key => $image) {
    45                         // see if files exist in content - we don't want to upload non-used selected files.
    46                         if ( strpos($_POST['content'], htmlspecialchars($image)) !== false ) {
    47                                 $desc = isset($_POST['photo_description'][$key]) ? $_POST['photo_description'][$key] : '';
    48                                 $upload = media_sideload_image($image, $post_ID, $desc);
    49 
    50                                 // Replace the POSTED content <img> with correct uploaded ones. Regex contains fix for Magic Quotes
    51                                 if ( !is_wp_error($upload) )
    52                                         $content = preg_replace('/<img ([^>]*)src=\\\?(\"|\')'.preg_quote(htmlspecialchars($image), '/').'\\\?(\2)([^>\/]*)\/*>/is', $upload, $content);
    53                         }
    54                 }
    55         }
    56         // set the post_content and status
    57         $post['post_content'] = $content;
    58         if ( isset( $_POST['publish'] ) && current_user_can( 'publish_posts' ) )
    59                 $post['post_status'] = 'publish';
    60         elseif ( isset( $_POST['review'] ) )
    61                 $post['post_status'] = 'pending';
    62         else
    63                 $post['post_status'] = 'draft';
    64 
    65         // error handling for media_sideload
    66         if ( is_wp_error($upload) ) {
    67                 wp_delete_post($post_ID);
    68                 wp_die($upload);
    69         } else {
    70                 // Post formats
    71                 if ( isset( $_POST['post_format'] ) ) {
    72                         if ( current_theme_supports( 'post-formats', $_POST['post_format'] ) )
    73                                 set_post_format( $post_ID, $_POST['post_format'] );
    74                         elseif ( '0' == $_POST['post_format'] )
    75                                 set_post_format( $post_ID, false );
    76                 }
    77 
    78                 $post_ID = wp_update_post($post);
    79         }
    80 
    81         return $post_ID;
    82 }
    83 
    8423// For submitted posts.
    85 if ( isset($_REQUEST['action']) && 'post' == $_REQUEST['action'] ) {
    86         check_admin_referer('press-this');
    87         $posted = $post_ID = press_it();
     24if ( isset($_REQUEST['action'] ) && 'post' == $_REQUEST['action'] ) {
     25        check_admin_referer( 'press-this' );
     26        $posted = $post_ID = press_it( PRESS_THIS_POST_TYPE );
    8827} else {
    89         $post = get_default_post_to_edit('post', true);
     28        $post = get_default_post_to_edit( PRESS_THIS_POST_TYPE, true );
    9029        $post_ID = $post->ID;
    9130}
    9231
    9332// Set Variables
    94 $title = isset( $_GET['t'] ) ? trim( strip_tags( html_entity_decode( stripslashes( $_GET['t'] ) , ENT_QUOTES) ) ) : '';
     33$title = isset( $_GET['t'] ) ? trim( strip_tags( html_entity_decode( stripslashes( $_GET['t'] ), ENT_QUOTES ) ) ) : '';
     34$url   = isset( $_GET['u'] ) ? esc_url( $_GET['u'] ) : '';
     35$image = isset( $_GET['i'] ) ? $_GET['i'] : '';
    9536
    9637$selection = '';
    97 if ( !empty($_GET['s']) ) {
    98         $selection = str_replace('&apos;', "'", stripslashes($_GET['s']));
    99         $selection = trim( htmlspecialchars( html_entity_decode($selection, ENT_QUOTES) ) );
     38if ( ! empty( $_GET['s'] ) ) {
     39        $selection = str_replace( '&apos;', "'", stripslashes( $_GET['s'] ) );
     40        $selection = trim( htmlspecialchars( html_entity_decode( $selection, ENT_QUOTES ) ) );
    10041}
    10142
    102 if ( ! empty($selection) ) {
    103         $selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection);
    104         $selection = '<p>' . str_replace('<p></p>', '', $selection) . '</p>';
     43if ( ! empty( $selection ) ) {
     44        $selection = preg_replace( '/(\r?\n|\r)/', '</p><p>', $selection );
     45        $selection = '<p>' . str_replace( '<p></p>', '', $selection ) . '</p>';
    10546}
    10647
    107 $url = isset($_GET['u']) ? esc_url($_GET['u']) : '';
    108 $image = isset($_GET['i']) ? $_GET['i'] : '';
     48if ( ! empty( $_REQUEST['ajax'] ) )
     49        press_this_ajax( $_REQUEST['ajax'] );
    10950
    110 if ( !empty($_REQUEST['ajax']) ) {
    111         switch ($_REQUEST['ajax']) {
    112                 case 'video': ?>
    113                         <script type="text/javascript">
    114                         /* <![CDATA[ */
    115                                 jQuery('.select').click(function() {
    116                                         append_editor(jQuery('#embed-code').val());
    117                                         jQuery('#extra-fields').hide();
    118                                         jQuery('#extra-fields').html('');
    119                                 });
    120                                 jQuery('.close').click(function() {
    121                                         jQuery('#extra-fields').hide();
    122                                         jQuery('#extra-fields').html('');
    123                                 });
    124                         /* ]]> */
    125                         </script>
    126                         <div class="postbox">
    127                                 <h2><label for="embed-code"><?php _e('Embed Code') ?></label></h2>
    128                                 <div class="inside">
    129                                         <textarea name="embed-code" id="embed-code" rows="8" cols="40"><?php echo esc_textarea( $selection ); ?></textarea>
    130                                         <p id="options"><a href="#" class="select button"><?php _e('Insert Video'); ?></a> <a href="#" class="close button"><?php _e('Cancel'); ?></a></p>
    131                                 </div>
    132                         </div>
    133                         <?php break;
     51_wp_admin_html_begin();
     52?>
     53<title><?php _e( 'Press This' ) ?></title>
    13454
    135                 case 'photo_thickbox': ?>
    136                         <script type="text/javascript">
    137                                 /* <![CDATA[ */
    138                                 jQuery('.cancel').click(function() {
    139                                         tb_remove();
    140                                 });
    141                                 jQuery('.select').click(function() {
    142                                         image_selector(this);
    143                                 });
    144                                 /* ]]> */
    145                         </script>
    146                         <h3 class="tb"><label for="tb_this_photo_description"><?php _e('Description') ?></label></h3>
    147                         <div class="titlediv">
    148                                 <div class="titlewrap">
    149                                         <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);?>"/>
    150                                 </div>
    151                         </div>
     55<script>
     56addLoadEvent = 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();}}};
     57var userSettings = {
     58                'url': '<?php echo SITECOOKIEPATH; ?>',
     59                'uid': '<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>',
     60                'time':'<?php echo time() ?>'
     61        },
     62        ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>',
     63        pagenow = 'press-this',
     64        typenow = '<?php echo PRESS_THIS_POST_TYPE; ?>',
     65//      adminpage = '',
     66        thousandsSeparator = '<?php echo addslashes( $wp_locale->number_format['thousands_sep'] ); ?>',
     67        decimalPoint = '<?php echo addslashes( $wp_locale->number_format['decimal_point'] ); ?>',
     68        isRtl = <?php echo (int) is_rtl(); ?>,
     69        photostorage = false;
     70</script>
    15271
    153                         <p class="centered">
    154                                 <input type="hidden" name="this_photo" value="<?php echo esc_attr($image); ?>" id="tb_this_photo" class="tb_this_photo" />
    155                                 <a href="#" class="select">
    156                                         <img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr(__('Click to insert.')); ?>" title="<?php echo esc_attr(__('Click to insert.')); ?>" />
    157                                 </a>
    158                         </p>
    15972
    160                         <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p>
    161                         <?php break;
    162         case 'photo_images':
    163                 /**
    164                  * Retrieve all image URLs from given URI.
    165                  *
    166                  * @package WordPress
    167                  * @subpackage Press_This
    168                  * @since 2.6.0
    169                  *
    170                  * @param string $uri
    171                  * @return string
    172                  */
    173                 function get_images_from_uri($uri) {
    174                         $uri = preg_replace('/\/#.+?$/','', $uri);
    175                         if ( preg_match( '/\.(jpe?g|jpe|gif|png)\b/i', $uri ) && !strpos( $uri, 'blogger.com' ) )
    176                                 return "'" . esc_attr( html_entity_decode($uri) ) . "'";
    177                         $content = wp_remote_fopen($uri);
    178                         if ( false === $content )
    179                                 return '';
    180                         $host = parse_url($uri);
    181                         $pattern = '/<img ([^>]*)src=(\"|\')([^<>\'\"]+)(\2)([^>]*)\/*>/i';
    182                         $content = str_replace(array("\n","\t","\r"), '', $content);
    183                         preg_match_all($pattern, $content, $matches);
    184                         if ( empty($matches[0]) )
    185                                 return '';
    186                         $sources = array();
    187                         foreach ($matches[3] as $src) {
    188                                 // if no http in url
    189                                 if (strpos($src, 'http') === false)
    190                                         // if it doesn't have a relative uri
    191                                         if ( strpos($src, '../') === false && strpos($src, './') === false && strpos($src, '/') === 0)
    192                                                 $src = 'http://'.str_replace('//','/', $host['host'].'/'.$src);
    193                                         else
    194                                                 $src = 'http://'.str_replace('//','/', $host['host'].'/'.dirname($host['path']).'/'.$src);
    195                                 $sources[] = esc_url($src);
    196                         }
    197                         return "'" . implode("','", $sources) . "'";
    198                 }
    199                 $url = wp_kses(urldecode($url), null);
    200                 echo 'new Array('.get_images_from_uri($url).')';
    201                 break;
    202 
    203         case 'photo_js': ?>
    204                 // gather images and load some default JS
    205                 var last = null
    206                 var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
    207                 if(photostorage == false) {
    208                 var my_src = eval(
    209                         jQuery.ajax({
    210                                 type: "GET",
    211                                 url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
    212                                 cache : false,
    213                                 async : false,
    214                                 data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
    215                                 dataType : "script"
    216                         }).responseText
    217                 );
    218                 if(my_src.length == 0) {
    219                         var my_src = eval(
    220                                 jQuery.ajax({
    221                                         type: "GET",
    222                                         url: "<?php echo esc_url($_SERVER['PHP_SELF']); ?>",
    223                                         cache : false,
    224                                         async : false,
    225                                         data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
    226                                         dataType : "script"
    227                                 }).responseText
    228                         );
    229                         if(my_src.length == 0) {
    230                                 strtoappend = '<?php _e('Unable to retrieve images or no images on page.'); ?>';
    231                         }
    232                 }
    233                 }
    234                 for (i = 0; i < my_src.length; i++) {
    235                         img = new Image();
    236                         img.src = my_src[i];
    237                         img_attr = 'id="img' + i + '"';
    238                         skip = false;
    239 
    240                         maybeappend = '<a href="?ajax=photo_thickbox&amp;i=' + encodeURIComponent(img.src) + '&amp;u=<?php echo urlencode($url); ?>&amp;height=400&amp;width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
    241 
    242                         if (img.width && img.height) {
    243                                 if (img.width >= 30 && img.height >= 30) {
    244                                         aspect = img.width / img.height;
    245                                         scale = (aspect > 1) ? (71 / img.width) : (71 / img.height);
    246 
    247                                         w = img.width;
    248                                         h = img.height;
    249 
    250                                         if (scale < 1) {
    251                                                 w = parseInt(img.width * scale);
    252                                                 h = parseInt(img.height * scale);
    253                                         }
    254                                         img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
    255                                         strtoappend += maybeappend;
    256                                 }
    257                         } else {
    258                                 strtoappend += maybeappend;
    259                         }
    260                 }
    261 
    262                 function pick(img, desc) {
    263                         if (img) {
    264                                 if('object' == typeof jQuery('.photolist input') && jQuery('.photolist input').length != 0) length = jQuery('.photolist input').length;
    265                                 if(length == 0) length = 1;
    266                                 jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
    267                                 jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
    268                                 insert_editor( "\n\n" + encodeURI('<p style="text-align: center;"><a href="<?php echo $url; ?>"><img src="' + img +'" alt="' + desc + '" /></a></p>'));
    269                         }
    270                         return false;
    271                 }
    272 
    273                 function image_selector(el) {
    274                         var desc, src, parent = jQuery(el).closest('#photo-add-url-div');
    275 
    276                         if ( parent.length ) {
    277                                 desc = parent.find('input.tb_this_photo_description').val() || '';
    278                                 src = parent.find('input.tb_this_photo').val() || ''
    279                         } else {
    280                                 desc = jQuery('#tb_this_photo_description').val() || '';
    281                                 src = jQuery('#tb_this_photo').val() || ''
    282                         }
    283 
    284                         tb_remove();
    285                         pick(src, desc);
    286                         jQuery('#extra-fields').hide();
    287                         jQuery('#extra-fields').html('');
    288                         return false;
    289                 }
    290 
    291                 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>');
    292                 jQuery('#img_container').html(strtoappend);
    293                 <?php break;
    294 }
    295 die;
    296 }
    297 
     73<?php
    29874        wp_enqueue_style( 'colors' );
    29975        wp_enqueue_script( 'post' );
    300         _wp_admin_html_begin();
     76        do_action( 'admin_enqueue_scripts', 'press-this.php' );
     77        do_action( 'admin_print_styles-press-this.php' );
     78        do_action( 'admin_print_styles' );
     79        do_action( 'admin_print_scripts-press-this.php' );
     80        do_action( 'admin_print_scripts' );
     81        do_action( 'admin_head-press-this.php' );
     82        do_action( 'admin_head' );
    30183?>
    302 <title><?php _e('Press This') ?></title>
    303 <script type="text/javascript">
    304 //<![CDATA[
    305 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();}}};
    306 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() ?>'};
    307 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'press-this', isRtl = <?php echo (int) is_rtl(); ?>;
    308 var photostorage = false;
    309 //]]>
    310 </script>
    31184
    312 <?php
    313         do_action('admin_print_styles');
    314         do_action('admin_print_scripts');
    315         do_action('admin_head');
    316 ?>
    317         <script type="text/javascript">
     85        <script>
    31886        var wpActiveEditor = 'content';
    31987
    32088        function insert_plain_editor(text) {
     
    350118                                jQuery('#extra-fields').load('<?php echo esc_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo esc_attr($selection); ?>'}, function() {
    351119                                        <?php
    352120                                        $content = '';
    353                                         if ( preg_match("/youtube\.com\/watch/i", $url) ) {
    354                                                 list($domain, $video_id) = explode("v=", $url);
    355                                                 $video_id = esc_attr($video_id);
     121                                        if ( preg_match( '/youtube\.com\/watch/i', $url) ) {
     122                                                list( $domain, $video_id ) = explode( 'v=', $url );
     123                                                $video_id = esc_attr( $video_id );
    356124                                                $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>';
    357125
    358                                         } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) {
    359                                                 list($domain, $video_id) = explode(".com/", $url);
    360                                                 $video_id = esc_attr($video_id);
     126                                        } elseif ( preg_match( '/vimeo\.com\/[0-9]+/i', $url ) ) {
     127                                                list( $domain, $video_id ) = explode( '.com/', $url );
     128                                                $video_id = esc_attr( $video_id );
    361129                                                $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>';
    362130
    363                                                 if ( trim($selection) == '' )
     131                                                if ( trim( $selection ) == '' )
    364132                                                        $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>';
    365133
    366134                                        } elseif ( strpos( $selection, '<object' ) !== false ) {
     
    419187                jQuery('#photo_button').click(function() { show('photo'); return false; });
    420188                jQuery('#video_button').click(function() { show('video'); return false; });
    421189                // auto select
    422                 <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
     190                <?php if ( preg_match( '/youtube\.com\/watch/i', $url ) ): ?>
    423191                        show('video');
    424                 <?php } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { ?>
     192                <?php elseif ( preg_match( '/vimeo\.com\/[0-9]+/i', $url ) ): ?>
    425193                        show('video');
    426                 <?php } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
     194                <?php elseif ( preg_match( '/flickr\.com/i', $url ) ): ?>
    427195                        show('photo');
    428                 <?php } ?>
     196                <?php endif; ?>
    429197                jQuery('#title').unbind();
    430198                jQuery('#publish, #save').click(function() { jQuery('#saving').css('display', 'inline'); });
    431199
     
    444212<div id="poststuff" class="metabox-holder">
    445213        <div id="side-sortables" class="press-this-sidebar">
    446214                <div class="sleeve">
    447                         <?php wp_nonce_field('press-this') ?>
     215                        <?php wp_nonce_field( 'press-this' ) ?>
    448216                        <input type="hidden" name="post_type" id="post_type" value="text"/>
    449217                        <input type="hidden" name="autosave" id="autosave" />
    450218                        <input type="hidden" id="original_post_status" name="original_post_status" value="draft" />
     
    456224
    457225                        <div id="submitdiv" class="postbox">
    458226                                <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    459                                 <h3 class="hndle"><?php _e('Press This') ?></h3>
     227                                <h3 class="hndle"><?php _e( 'Press This' ) ?></h3>
    460228                                <div class="inside">
    461229                                        <p id="publishing-actions">
    462230                                        <?php
    463231                                                submit_button( __( 'Save Draft' ), 'button', 'draft', false, array( 'id' => 'save' ) );
    464                                                 if ( current_user_can('publish_posts') ) {
     232                                                if ( current_user_can( 'publish_posts' ) ) {
    465233                                                        submit_button( __( 'Publish' ), 'primary', 'publish', false );
    466234                                                } else {
    467235                                                        echo '<br /><br />';
    468236                                                        submit_button( __( 'Submit for Review' ), 'primary', 'review', false );
    469237                                                } ?>
    470                                                 <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" id="saving" style="display:none;" />
     238                                                <img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" height="16" width="16" alt="" id="saving" style="display:none;" />
    471239                                        </p>
    472240                                        <?php if ( current_theme_supports( 'post-formats' ) && post_type_supports( 'post', 'post-formats' ) ) :
    473241                                                        $post_formats = get_theme_support( 'post-formats' );
     
    490258                        <?php $tax = get_taxonomy( 'category' ); ?>
    491259                        <div id="categorydiv" class="postbox">
    492260                                <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    493                                 <h3 class="hndle"><?php _e('Categories') ?></h3>
     261                                <h3 class="hndle"><?php _e( 'Categories' ) ?></h3>
    494262                                <div class="inside">
    495263                                <div id="taxonomy-category" class="categorydiv">
    496264
     
    512280                                        </div>
    513281
    514282                                        <?php if ( !current_user_can($tax->cap->assign_terms) ) : ?>
    515                                         <p><em><?php _e('You cannot modify this Taxonomy.'); ?></em></p>
     283                                        <p><em><?php _e( 'You cannot modify this Taxonomy.' ); ?></em></p>
    516284                                        <?php endif; ?>
    517285                                        <?php if ( current_user_can($tax->cap->edit_terms) ) : ?>
    518286                                                <div id="category-adder" class="wp-hidden-children">
     
    540308
    541309                        <div id="tagsdiv-post_tag" class="postbox">
    542310                                <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle' ); ?>"><br /></div>
    543                                 <h3><span><?php _e('Tags'); ?></span></h3>
     311                                <h3><span><?php _e( 'Tags' ); ?></span></h3>
    544312                                <div class="inside">
    545313                                        <div class="tagsdiv" id="post_tag">
    546314                                                <div class="jaxtag">
    547                                                         <label class="screen-reader-text" for="newtag"><?php _e('Tags'); ?></label>
     315                                                        <label class="screen-reader-text" for="newtag"><?php _e( 'Tags' ); ?></label>
    548316                                                        <input type="hidden" name="tax_input[post_tag]" class="the-tags" id="tax-input[post_tag]" value="" />
    549317                                                        <div class="ajaxtag">
    550318                                                                <input type="text" name="newtag[post_tag]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
    551                                                                 <input type="button" class="button tagadd" value="<?php esc_attr_e('Add'); ?>" />
     319                                                                <input type="button" class="button tagadd" value="<?php esc_attr_e( 'Add' ); ?>" />
    552320                                                        </div>
    553321                                                </div>
    554322                                                <div class="tagchecklist"></div>
    555323                                        </div>
    556                                         <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e('Choose from the most used tags'); ?></a></p>
     324                                        <p class="tagcloud-link"><a href="#titlediv" class="tagcloud-link" id="link-post_tag"><?php _e( 'Choose from the most used tags' ); ?></a></p>
    557325                                </div>
    558326                        </div>
    559327                </div>
     
    563331                <div id="wphead">
    564332                        <img id="header-logo" src="<?php echo esc_url( includes_url( 'images/blank.gif' ) ); ?>" alt="" width="16" height="16" />
    565333                        <h1 id="site-heading">
    566                                 <a href="<?php echo get_option('home'); ?>/" target="_blank">
    567                                         <span id="site-title"><?php bloginfo('name'); ?></span>
     334                                <a href="<?php echo get_option( 'home' ); ?>/" target="_blank">
     335                                        <span id="site-title"><?php bloginfo( 'name' ); ?></span>
    568336                                </a>
    569337                        </h1>
    570338                </div>
     
    573341                if ( isset($posted) && intval($posted) ) {
    574342                        $post_ID = intval($posted); ?>
    575343                        <div id="message" class="updated">
    576                         <p><strong><?php _e('Your post has been saved.'); ?></strong>
     344                        <p><strong><?php _e( 'Your post has been saved.' ); ?></strong>
    577345                        <a onclick="window.opener.location.replace(this.href); window.close();" href="<?php echo get_permalink($post_ID); ?>"><?php _e('View post'); ?></a>
    578346                        | <a href="<?php echo get_edit_post_link( $post_ID ); ?>" onclick="window.opener.location.replace(this.href); window.close();"><?php _e('Edit Post'); ?></a>
    579                         | <a href="#" onclick="window.close();"><?php _e('Close Window'); ?></a></p>
     347                        | <a href="#" onclick="window.close();"><?php _e( 'Close Window' ); ?></a></p>
    580348                        </div>
    581349                <?php } ?>
    582350
    583351                <div id="titlediv">
    584352                        <div class="titlewrap">
    585                                 <input name="title" id="title" class="text" value="<?php echo esc_attr($title);?>"/>
     353                                <input name="title" id="title" class="text" value="<?php echo esc_attr( $title );?>"/>
    586354                        </div>
    587355                </div>
    588356
    589                 <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>
     357                <div id="waiting" style="display: none"><img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" height="16" width="16" alt="" /> <?php esc_html_e( 'Loading...' ); ?></div>
    590358
    591359                <div id="extra-fields" style="display: none"></div>
    592360
     
    598366                        'textarea_rows' => '15'
    599367                );
    600368
    601                 $content = '';
     369                $content = empty( $post ) ? '' : $post->post_content;
    602370                if ( $selection )
    603371                        $content .= $selection;
    604372
     
    608376                        if ( $selection )
    609377                                $content .= __('via ');
    610378
    611                         $content .= sprintf( "<a href='%s'>%s</a>.</p>", esc_url( $url ), esc_html( $title ) );
     379                        $content .= sprintf( '<a href="%s">%s</a>.</p>', esc_url( $url ), esc_html( $title ) );
    612380                }
    613381
    614382                remove_action( 'media_buttons', 'media_buttons' );
    615383                add_action( 'media_buttons', 'press_this_media_buttons' );
    616                 function press_this_media_buttons() {
    617                         _e( 'Add:' );
    618384
    619                         if ( current_user_can('upload_files') ) {
    620                                 ?>
    621                                 <a id="photo_button" title="<?php esc_attr_e('Insert an Image'); ?>" href="#">
    622                                 <img alt="<?php esc_attr_e('Insert an Image'); ?>" src="<?php echo esc_url( admin_url( 'images/media-button-image.gif?ver=20100531' ) ); ?>"/></a>
    623                                 <?php
    624                         }
    625                         ?>
    626                         <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>
    627                         <?php
    628                 }
    629 
    630385                wp_editor( $content, 'content', $editor_settings );
    631386
    632387                ?>
     
    634389        </div>
    635390</div>
    636391</form>
    637 <div id="photo-add-url-div" style="display:none;">
    638         <table><tr>
    639         <td><label for="this_photo"><?php _e('URL') ?></label></td>
    640         <td><input type="text" id="this_photo" name="this_photo" class="tb_this_photo text" onkeypress="if(event.keyCode==13) image_selector(this);" /></td>
    641         </tr><tr>
    642         <td><label for="this_photo_description"><?php _e('Description') ?></label></td>
    643         <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>
    644         </tr><tr>
    645         <td><input type="button" class="button" onclick="image_selector(this)" value="<?php esc_attr_e('Insert Image'); ?>" /></td>
    646         </tr></table>
    647 </div>
    648392<?php
    649 do_action('admin_footer');
    650 do_action('admin_print_footer_scripts');
     393        do_action( 'admin_footer', '' );
     394        do_action( 'admin_print_footer_scripts' );
     395        do_action( 'admin_footer-press-this.php' );
    651396?>
    652 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
     397<script>if(typeof wpOnload=='function')wpOnload();</script>
    653398</body>
    654399</html>