Make WordPress Core


Ignore:
Timestamp:
07/02/2008 11:07:56 PM (17 years ago)
Author:
mdawaffe
Message:

crazyhorse: merge with log:trunk@8151:8240

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/crazyhorse/wp-admin/press-this.php

    r8151 r8242  
    55
    66<?php
     7
     8function preg_quote2($string) {
     9    return str_replace('/', '\/', preg_quote($string));
     10}
    711function press_it() {
    8     #define some basic variables
     12    // define some basic variables
    913    $quick['post_status'] = $_REQUEST['post_status'];
    1014    $quick['post_category'] = $_REQUEST['post_category'];
     
    1317    $quick['post_content'] = '';
    1418       
    15     # insert the post with nothing in it, to get an ID
     19    // insert the post with nothing in it, to get an ID
    1620    $post_ID = wp_insert_post($quick, true);
    1721       
     
    2428       
    2529        case 'photo':
    26             foreach($_REQUEST['photo_src'] as $key => $data) {
     30            $content = $_REQUEST['content'];
     31           
     32            foreach($_REQUEST['photo_src'] as $key => $image) {
    2733                #quote for matching
    28                 $quoted = str_replace('/', '\/', preg_quote($data));
     34                $quoted = preg_quote2($image);
    2935               
    30                 # see if files exist in content - we don't want to upload non-used selected files.
     36                // see if files exist in content - we don't want to upload non-used selected files.
    3137                preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]);
    32                 if($matches[0])
    33                     media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]);   
     38                if($matches[0]) {
     39                    $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]);
     40                    // Replace the POSTED content <img> with correct uploaded ones.
     41                    if( !is_wp_error($upload) ) $content = preg_replace('/<img ([^>]*)src=(\"|\')'.$quoted.'(\2)([^>\/]*)\/*>/is', $upload, $content);
     42                }
    3443            }
    35             $content = $_REQUEST['content'];
     44           
    3645            break;
    3746           
     
    4655
    4756    #error handling for $post
    48     if ( is_wp_error($post_ID) ) {
     57    if ( is_wp_error($post_ID)) {
    4958        wp_die($id);
    5059        wp_delete_post($post_ID);
    51 
    5260    #error handling for media_sideload
     61    } elseif ( is_wp_error($upload)) {
     62        wp_die($upload);
     63        wp_delete_post($post_ID);
    5364    } else {   
    5465        $quick['ID'] = $post_ID;
     
    7990    </head>
    8091    <body class="press-this">
    81         <div id="message" class="updated fade"><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="post.php?action=edit&amp;post=<?php echo $post_ID; ?>" onclick="window.opener.location.replace(this.href); window.close();"><?php _e('Edit post'); ?></a> | <a href="#" onclick="window.close();">Close Window</a></p></div>
     92       
     93        <div id="message" class="updated fade"><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="post.php?action=edit&amp;post=<?php echo $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>
    8294       
    8395        <div id="footer">
     
    104116
    105117// Ajax Requests
    106 $title = wp_specialchars(stripslashes($_GET['t']));
     118$title = wp_specialchars(aposfix(stripslashes($_GET['t'])));
    107119
    108120$selection = str_replace("\n", "<br />", aposfix( stripslashes($_GET['s']) ) );
     
    111123
    112124if($_REQUEST['ajax'] == 'thickbox') { ?>
     125    <script type="text/javascript" charset="utf-8">
     126        jQuery('.cancel').click(function() {
     127            tb_remove();
     128        });
     129       
     130        jQuery('.select').click(function() {
     131            image_selector();
     132        });
     133    </script>
    113134    <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3>
    114135    <div class="titlewrap">
     
    116137    </div>
    117138       
    118     <p><input type="hidden" name="this_photo" value="<?php echo $image; ?>" id="this_photo" />
    119         <a href="#" class="select"><img src="<?php echo $image; ?>" width="475" alt="Click to insert." title="Click to insert." /></a></p>
    120    
    121     <p id="options"><a href="#" class="select">Insert Image</a> | <a href="#" class="cancel">Cancel</a></p>
     139    <p><input type="hidden" name="this_photo" value="<?php echo attribute_escape($image); ?>" id="this_photo" />
     140        <a href="#" class="select"><img src="<?php echo clean_url($image); ?>" width="475" alt="<?php echo attribute_escape(__('Click to insert.')); ?>" title="<?php echo attribute_escape(__('Click to insert.')); ?>" /></a></p>
     141   
     142    <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
    122143<?php die;
    123144}
    124145
    125146if($_REQUEST['ajax'] == 'thickbox_url') { ?>
     147    <script type="text/javascript" charset="utf-8">
     148        jQuery('.cancel').click(function() {
     149            tb_remove();
     150        });
     151       
     152        jQuery('.select').click(function() {
     153            image_selector();
     154        });
     155    </script>
    126156    <h3 id="title"><label for="post_title"><?php _e('URL') ?></label></h3>
    127157    <div class="titlewrap">
     
    135165    </div>
    136166   
    137     <p id="options"><a href="#" class="select">Insert Image</a> | <a href="#" class="cancel">Cancel</a></p>
     167    <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p>
    138168<?php die;
    139169}
     
    142172    <h2 id="embededcode"><label for="embed_code"><?php _e('Embed Code') ?></label></h2>
    143173    <div class="titlewrap" >
    144         <textarea name="embed_code" id="embed_code" rows="8" cols="40"><?php echo $selection; ?></textarea>
     174        <textarea name="embed_code" id="embed_code" rows="8" cols="40"><?php echo format_to_edit($selection); ?></textarea>
    145175    </div>
    146176<?php die;
     
    149179if($_REQUEST['ajax'] == 'photo_images') {
    150180    function get_images_from_uri($uri) {
    151         if(preg_match('/\.(jpg|png|gif)/', $uri) && !strpos($uri,'blogger.com'))
     181        if(preg_match('/\.(jpg|jpe|jpeg|png|gif)/', $uri) && !strpos($uri,'blogger.com'))
    152182            return "'".$uri."'";
    153183
     
    157187        $host = parse_url($uri);
    158188       
    159         $pattern = '/<img ([^>]*)src=(\"|\')(.+?)(\2)([^>\/]*)\/*>/is';
     189        $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))(\2)([^>\/]*)\/*>/is';
    160190        preg_match_all($pattern, $content, $matches);
    161191       
     
    170200                    $src = 'http://'.str_replace('//','/', $host['host'].'/'.$host['path'].'/'.$src);
    171201                                       
    172             $sources[] = $src;
     202            $sources[] = clean_url($src);
    173203        }
    174204        return "'" . implode("','", $sources) . "'";
     
    182212
    183213if($_REQUEST['ajax'] == 'photo_js') { ?>
    184 
    185             tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
     214   
     215   
     216    // gather images and load some default JS
     217   
     218    var last = null
     219    var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
     220    var my_src = eval(
     221        jQuery.ajax({
     222            type: "GET",
     223            url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>",
     224            cache : false,
     225            async : false,
     226            data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
     227            dataType : "script"
     228        }).responseText
     229    );
     230   
     231    for (i = 0; i < my_src.length; i++) {
     232        img = new Image();
     233        img.src = my_src[i];
     234        img_attr = 'id="img' + i + '"';
     235        skip = false;
     236        if (img.width && img.height) {
     237            if (img.width * img.height < 2500)
     238                skip = true;
     239            aspect = img.width / img.height;
     240            scale = (aspect > 1) ? (75 / img.width) : (75 / img.height);
    186241           
    187             function image_selector() {
    188                 desc = jQuery('#this_photo_description').val();
    189                 src = jQuery('#this_photo').val();
    190                 pick(src, desc);
    191                 tb_remove();
    192                 return false;
     242            w = img.width;
     243            h = img.height;
     244           
     245            if (scale < 1) {
     246                w = parseInt(img.width * scale);
     247                h = parseInt(img.height * scale);
    193248            }
    194            
    195             jQuery(document).ready(function() {
    196                 jQuery('#this_photo').focus();
    197 
    198                 jQuery('.cancel').click(function() {
    199                     tb_remove();
    200                 });
    201                
    202                 jQuery('.select').click(function() {
    203                     image_selector();
    204                 });
    205                
    206                 jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500');
    207                
    208             });
    209            
    210            
    211             function pick(img, desc) {
    212                 if (img) {
    213                     length = jQuery('.photolist input').length;
    214                     if(length == 0) length = 1;
    215                     jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
    216                     jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
    217                     append_editor('<img src="' + img +'" alt="' + desc + '" />'); }
    218                     tinyMCE.activeEditor.resizeToContent();
    219                 return false;
    220             }
    221 
    222             var last = null
    223             var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = "";
    224             var my_src = eval(
    225             jQuery.ajax({
    226                 type: "GET",
    227                 url: "<?php echo clean_url($_SERVER['PHP_SELF']); ?>",
    228                 cache : false,
    229                 async : false,
    230                 data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
    231                 dataType : "script"
    232                 }).responseText);
    233 
    234             for (i = 0; i < my_src.length; i++) {
    235                 img = new Image(); img.src = my_src[i]; img_attr = 'id="img' + i; skip = false;
    236 
    237                 if (img.width && img.height) {
    238                     if (img.width * img.height < 2500)
    239                         skip = true;
    240                     aspect = img.width / img.height;
    241                     scale = (aspect > 1) ? (75 / img.width) : (75 / img.height);
    242                    
    243                     if (scale < 1) {
    244                         w = parseInt(img.width * scale);
    245                         h = parseInt(img.height * scale);
    246                     } else {
    247                         w = img.width;
    248                         h = img.height;
    249                     }
    250                     img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
    251                 }
    252 
    253                 if (!skip) strtoappend += '<a href="?ajax=thickbox&amp;i=' + img.src + '&amp;u=<?php echo $url; ?>&amp;height=400&amp;width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
    254 
    255             }
    256             jQuery('#img_container').html(strtoappend);
    257 
     249            img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
     250        }
     251        if (!skip) strtoappend += '<a href="?ajax=thickbox&amp;i=' + img.src + '&amp;u=<?php echo $url; ?>&amp;height=400&amp;width=500" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
     252    }
     253   
     254    function pick(img, desc) {
     255        if (img) {
     256            length = jQuery('.photolist input').length;
     257            if(length == 0) length = 1;
     258            jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
     259            jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
     260            append_editor('<img src="' + img +'" alt="' + desc + '" />');
     261        }
     262        tinyMCE.activeEditor.resizeToContent();
     263        return false;
     264    }
     265   
     266    function image_selector() {
     267        tb_remove();
     268        desc = jQuery('#this_photo_description').val();
     269        src = jQuery('#this_photo').val();
     270        pick(src, desc);
     271        return false;
     272    }
     273   
     274    jQuery(document).ready(function() {
     275        jQuery('#img_container').html(strtoappend);
     276        jQuery('#photo_add_url').attr('href', '?ajax=thickbox_url&height=200&width=500');
     277        tb_init('a.thickbox, area.thickbox, input.thickbox');
     278    });
     279   
    258280<?php die; }
    259281
     
    288310<script type="text/javascript">
    289311    jQuery('#tags-input').hide();
    290 
    291312    tag_update_quickclicks();
    292313
     
    314335        jQuery("#post_type").val(type);
    315336    }
     337   
    316338    function set_editor(text) {
    317339
     
    319341        if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);
    320342    }
     343   
    321344    function append_editor(text) {
    322345        if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);
    323346    }
     347   
    324348    function set_title(title) { jQuery("#content_type").text(title); }
    325349
     
    331355                set_menu('text');
    332356                set_title('<?php _e('Post') ?>');
    333 
    334357                return false;
    335             break;
     358                break;
    336359            case 'quote' :
    337360                set_menu('quote');
    338361                set_title('<?php _e('Quote') ?>');
    339                 set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>");
     362                set_editor("<blockquote><p><?php echo format_to_edit($selection); ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>");
    340363                return false;
    341             break;
     364                break;
    342365            case 'video' :
    343 
    344366                set_menu('video');
    345367                set_title('<?php _e('Caption') ?>');
     
    348370                jQuery('body').addClass('video_split');
    349371                jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() {
    350                    
    351372                    <?php
    352373                    if ( preg_match("/youtube\.com\/watch/i", $url) ) {
     
    359380                    $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>';
    360381                   
    361                     if(trim($selection) == '') $selection = '<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>';
    362                     }else {
     382                    if ( trim($selection) == '' )
     383                        $selection = '<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>';
     384                    } else {
    363385                        $content = $selection;
    364386                    } ?>
     
    367389                    set_editor("<?php echo $title; ?>");
    368390                });
    369                
    370391                return false;
    371             break;
    372            
     392                break;
    373393            case 'photo' :
    374394                set_menu('photo');
    375                 set_title('Post');
    376                 <?php if($selection) { ?>
    377                     set_editor("<?php echo $selection; ?>");
     395                set_title('<?php _e('Post') ?>');
     396                <?php if ($selection) { ?>
     397                    set_editor("<?php echo format_to_edit($selection); ?>");
    378398                <?php } ?>
    379399                jQuery('#extra_fields').show();
    380                 jQuery('#extra_fields').before('<h2 id="waiting"><img src="images/loading.gif" alt="" /> Loading...</h2>');
     400                jQuery('#extra_fields').before('<h2 id="waiting"><img src="images/loading.gif" alt="" /><?php echo js_escape( __( 'Loading...' ) ); ?></h2>');
    381401                jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']).'/?ajax=photo&u='.attribute_escape($url); ?>');
    382402                jQuery.ajax({
     
    390410                    }
    391411                });
    392                
    393412                return false;
    394             break;
    395 
     413                break;
    396414        }
    397    
    398415    }
    399416   
     
    405422        });
    406423       
     424        // Set default tabs
    407425        <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
    408426            show('video');
     
    413431        <?php } ?>
    414432    });
     433   
    415434</script>
    416435</head>
    417436<body class="press-this">
    418437<div id="wphead">
    419 <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1>
     438    <h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1>
    420439</div>
    421440
    422         <ul id="menu" class="ui-tabs-nav">
    423             <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li>
    424             <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li>
    425             <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li>
    426             <li id="video_button"><a href="#"><?php _e('Video') ?></a></li>
    427         </ul>
    428 
    429             <form action="press-this.php?action=post" method="post">
    430 
    431                 <?php wp_nonce_field('press-this') ?>
    432                 <input type="hidden" name="post_type" id="post_type" value="text"/>
    433                 <div id="posting">
    434                    
    435                     <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2>
    436                     <div class="titlewrap">
    437                         <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
    438                     </div>
    439                    
    440                     <div id="extra_fields" style="display: none"></div>
    441                     <div class="editor_area">
    442                     <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2>
    443                     <div class="editor-container">
    444                         <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if($selection) { ?><a href='<?php echo $url ?>'><?php echo $selection ?></a><?php } else { ?><a href='<?php echo $url ?>'><?php echo $title; ?></a><?php } ?></textarea>
    445                     </div>
    446                     </div>
    447                    
    448                 </div>
    449                 <div id="categories">
    450                     <div class="submitbox" id="submitpost">
    451                     <div id="previewview"></div>
    452                     <div class="inside">
    453                         <h2><?php _e('Categories') ?></h2>
    454                         <div id="categories-all">
    455                             <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    456                                 <?php wp_category_checklist() ?>
    457                             </ul>
    458                         </div>
    459                         <h2><?php _e('Tags') ?></h2>
    460                         <p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p>
    461                         <div id="tagchecklist"></div>
    462                     </div>
    463                     <label for="post_status" id="post_status"><input type="radio" name="post_status" value="publish" checked="checked" id="published" />Published <input type="radio" name="post_status" value="draft" id="unpubplished" /> Unpublished</label>
    464                    
    465                     <p class="submit">         
    466                         <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/>
    467                         <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/>
    468                     </p>
    469                 </div>
    470                
    471                
    472             </form>     
    473                    
     441<ul id="menu" class="ui-tabs-nav">
     442    <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li>
     443    <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li>
     444    <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li>
     445    <li id="video_button"><a href="#"><?php _e('Video') ?></a></li>
     446</ul>
     447
     448<form action="press-this.php?action=post" method="post">
     449    <?php wp_nonce_field('press-this') ?>
     450    <input type="hidden" name="post_type" id="post_type" value="text"/>
     451    <div id="posting">
     452        <h2 id="title"><label for="post_title"><?php _e('Title') ?></label></h2>
     453        <div class="titlewrap">
     454            <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
     455        </div>
     456       
     457        <div id="extra_fields" style="display: none"></div>
     458       
     459        <div class="editor_area">
     460            <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2>
     461            <div class="editor-container">
     462                <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if ($selection) { ?><a href='<?php echo $url ?>'><?php echo format_to_edit($selection) ?></a><?php } else { ?><a href='<?php echo $url ?>'><?php echo $title; ?></a><?php } ?></textarea>
     463            </div>
     464        </div>
     465    </div>
     466   
     467    <div id="categories">
     468        <div class="submitbox" id="submitpost">
     469        <div id="previewview"></div>
     470        <div class="inside">
     471            <h2><?php _e('Categories') ?></h2>
     472            <div id="categories-all">
     473                <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
     474                    <?php wp_category_checklist() ?>
     475                </ul>
     476            </div>
     477            <h2><?php _e('Tags') ?></h2>
     478            <p id="jaxtag"><label class="hidden" for="newtag"><?php _e('Tags'); ?></label><input type="text" name="tags_input" class="tags-input" id="tags-input" size="40" tabindex="3" value="<?php echo get_tags_to_edit( $post->ID ); ?>" /></p>
     479            <div id="tagchecklist"></div>
     480        </div>
     481        <div id="post_status">
     482            <input type="radio" name="post_status" value="publish" checked="checked" id="published" /> <label for="published"><?php _e('Published'); ?></label>
     483            <input type="radio" name="post_status" value="draft" id="unpublished" /> <label for="unpublished"><?php _e('Unpublished'); ?></label>
     484        </div>
     485        <p class="submit">         
     486            <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/>
     487            <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/>
     488        </p>
     489    </div>
     490</form>
    474491</body>
    475492</html>
Note: See TracChangeset for help on using the changeset viewer.