Changeset 8316

Show
Ignore:
Timestamp:
07/11/08 20:27:50 (4 months ago)
Author:
ryan
Message:

Press This: Fix inserting the selection in the editor and stripping of paragraphs when saving, IE CSS styling fixes, fix continuous linking in editor. Props noel and azaozz. see #6813

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/wp-admin/css/press-this.css

    r8303 r8316  
    232232 
    233233#photo_saving { 
    234     margin-bottom: 8px; 
     234    margin: 0 8px 8px; 
     235    vertical-align: middle; 
    235236} 
    236237 
     
    303304    clear: both; 
    304305    padding-left: 1em; 
     306    margin: 0; 
    305307} 
    306308 
     
    349351    border-bottom-right-radius: 3px; 
    350352    margin: 0; 
    351     padding: 0
     353    padding: 10px
    352354} 
    353355.submitbox { 
     
    364366    border: none; 
    365367    text-align: left; 
    366     padding: 12px 10px 10px 10px; 
     368    padding: 6px 4px; 
    367369    font-size: 12px; 
    368     margin: 10px; 
    369  
     370    margin: 2px; 
    370371    -moz-border-radius: 3px; 
    371372    -khtml-border-radius: 3px; 
  • trunk/wp-admin/press-this.php

    r8303 r8316  
    1111    $translation_table[chr(38)] = '&'; 
    1212    $translation_table[chr(39)] = '''; 
    13     return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($text, $translation_table));    
     13    return preg_replace("/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,3};)/","&" , strtr($text, $translation_table)); 
    1414} 
    1515function press_it() { 
    1616    // define some basic variables 
    17     $quick['post_status'] = $_REQUEST['post_status']
     17    $quick['post_status'] = isset($_REQUEST['publish']) ? 'publish' : 'draft'
    1818    $quick['post_category'] = $_REQUEST['post_category']; 
    1919    $quick['tags_input'] = $_REQUEST['tags_input']; 
    2020    $quick['post_title'] = $_REQUEST['post_title']; 
    2121    $quick['post_content'] = ''; 
    22          
     22 
     23    $posted = str_replace('<br />', "\n", str_replace('<p>', '', $_REQUEST['content'])); 
     24    $posted = str_replace('</p>', "\n\n", $posted); 
     25 
    2326    // insert the post with nothing in it, to get an ID 
    2427    $post_ID = wp_insert_post($quick, true); 
    25          
     28 
    2629    $content = ''; 
    2730    switch ( $_REQUEST['post_type'] ) { 
    2831        case 'text': 
    2932        case 'quote': 
    30             $content .= $_REQUEST['content']
     33            $content .= $posted
    3134            break; 
    32          
     35 
    3336        case 'photo': 
    34             $content = $_REQUEST['content']
    35              
    36             foreach($_REQUEST['photo_src'] as $key => $image) { 
     37            $content = $posted
     38 
     39            foreach( (array) $_REQUEST['photo_src'] as $key => $image) { 
    3740                // escape quote for matching 
    3841                $quoted = preg_quote2($image); 
    39                  
     42 
    4043                // see if files exist in content - we don't want to upload non-used selected files. 
    41                 preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]); 
    42                 if($matches[0]) { 
     44                if( strpos($posted, $quoted) !== false ) { 
    4345                    $upload = media_sideload_image($image, $post_ID, $_REQUEST['photo_description'][$key]); 
    4446                    // Replace the POSTED content <img> with correct uploaded ones. 
     
    4648                } 
    4749            } 
    48              
     50 
    4951            break; 
    50              
     52 
    5153        case "video": 
    5254            if($_REQUEST['embed_code'])  
    5355                $content .= $_REQUEST['embed_code']."\n\n"; 
    54             $content .= $_REQUEST['content']
    55             break;  
     56            $content .= $posted
     57            break; 
    5658        } 
    5759    // set the post_content 
    58     $quick['post_content'] = str_replace('<br />', "\n", preg_replace('/<\/?p>/','',$content)); 
     60    $quick['post_content'] = preg_replace("/\n\n+/", "\n\n", $content); 
    5961 
    6062    // error handling for $post 
     
    6668        wp_die($upload); 
    6769        wp_delete_post($post_ID); 
    68     } else {    
     70    } else { 
    6971        $quick['ID'] = $post_ID; 
    7072        wp_update_post($quick); 
     
    8183        <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" /> 
    8284        <title><?php _e('Press This') ?></title> 
     85        <!--[if gte IE 6]> 
     86        <link rel="stylesheet" href="./css/press-this-ie.css" type="text/css" media="screen" charset="utf-8" /> 
     87        <![endif]--> 
    8388    <?php 
    8489        add_thickbox(); 
     
    9297    ?> 
    9398    </head> 
    94     <body class="press-this">   
    95         <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>   
     99    <body class="press-this"> 
     100        <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> 
    96101        <div id="footer"> 
    97102        <p><?php 
     
    101106        ?></p> 
    102107        </div> 
    103         <?php do_action('admin_footer', ''); ?>         
     108        <?php do_action('admin_footer', ''); ?> 
    104109    </body> 
    105110    </html> 
     
    110115$title = wp_specialchars(aposfix(stripslashes($_GET['t']))); 
    111116 
    112 $selection = str_replace("\n", "<br />", aposfix( stripslashes($_GET['s']) ) ); 
     117$selection = trim( aposfix( stripslashes($_GET['s']) ) ); 
     118if ( ! empty($selection) ) { 
     119    $selection = preg_replace('/(\r?\n|\r)/', '</p><p>', $selection); 
     120    $selection = '<p>'.str_replace('<p></p>', '', $selection).'</p>'; 
     121
     122 
    113123$url = clean_url($_GET['u']); 
    114124$image = $_GET['i']; 
     
    119129            tb_remove(); 
    120130        }); 
    121          
     131 
    122132        jQuery('.select').click(function() { 
    123133            image_selector(); 
     
    128138        <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/> 
    129139    </div> 
    130          
     140 
    131141    <p class="centered"><input type="hidden" name="this_photo" value="<?php echo attribute_escape($image); ?>" id="this_photo" /> 
    132142        <a href="#" class="select"><img src="<?php echo clean_url($image); ?>" alt="<?php echo attribute_escape(__('Click to insert.')); ?>" title="<?php echo attribute_escape(__('Click to insert.')); ?>" /></a></p> 
    133      
     143 
    134144    <p id="options"><a href="#" class="select button"><?php _e('Insert Image'); ?></a> <a href="#" class="cancel button"><?php _e('Cancel'); ?></a></p> 
    135145<?php die;  
     
    141151            tb_remove(); 
    142152        }); 
    143          
     153 
    144154        jQuery('.select').click(function() { 
    145155            image_selector(); 
     
    150160        <input id="this_photo" name="this_photo" class="text" onkeypress="if(event.keyCode==13) image_selector();" /> 
    151161    </div> 
    152      
    153      
     162 
     163 
    154164    <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3> 
    155165    <div class="titlewrap"> 
    156166        <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/> 
    157167    </div> 
    158      
     168 
    159169    <p id="options"><a href="#" class="select"><?php _e('Insert Image'); ?></a> | <a href="#" class="cancel"><?php _e('Cancel'); ?></a></p> 
    160170<?php die;  
     
    176186        $content = wp_remote_fopen($uri); 
    177187        if ( false === $content ) return ''; 
    178          
     188 
    179189        $host = parse_url($uri); 
    180          
     190 
    181191        $pattern = '/<img ([^>]*)src=(\"|\')([^<>]+?\.(png|jpeg|jpg|jpe|gif))(\2)([^>\/]*)\/*>/is'; 
    182192        preg_match_all($pattern, $content, $matches); 
    183          
     193 
    184194        if ( empty($matches[1]) ) return ''; 
    185          
     195 
    186196        $sources = array(); 
    187197        foreach ($matches[3] as $src) { 
     
    191201                else 
    192202                    $src = 'http://'.str_replace('//','/', $host['host'].'/'.$host['path'].'/'.$src); 
    193                                          
     203 
    194204            $sources[] = clean_url($src); 
    195205        } 
    196206        return "'" . implode("','", $sources) . "'"; 
    197207    }  
    198      
     208 
    199209    $url = urldecode($url); 
    200210    $url = str_replace(' ', '%20', $url); 
    201211    echo 'new Array('.get_images_from_uri($url).')';  
    202 die;        
     212die; 
    203213} 
    204214 
     
    217227        }).responseText 
    218228    ); 
    219      
     229 
    220230    for (i = 0; i < my_src.length; i++) { 
    221231        img = new Image();  
     
    228238            aspect = img.width / img.height; 
    229239            scale = (aspect > 1) ? (75 / img.width) : (75 / img.height); 
    230              
     240 
    231241            w = img.width; 
    232242            h = img.height; 
    233              
     243 
    234244            if (scale < 1) { 
    235245                w = parseInt(img.width * scale); 
     
    240250        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>'; 
    241251    } 
    242      
     252 
    243253    function pick(img, desc) { 
    244254        if (img) {  
     
    252262        return false; 
    253263    } 
    254      
     264 
    255265    function image_selector() { 
    256266        tb_remove(); 
     
    260270        return false; 
    261271    } 
    262      
     272 
    263273    jQuery(document).ready(function() { 
    264274        jQuery('#img_container').html(strtoappend); 
     
    266276        tb_init('a.thickbox, area.thickbox, input.thickbox'); 
    267277    }); 
    268      
     278 
    269279<?php die; 
    270280} 
     
    288298 
    289299    <script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce.js?ver=311"></script> 
     300    <!--[if gte IE 6]> 
     301    <?php wp_enqueue_style('press-this-ie'); ?> 
     302    <![endif]--> 
    290303<?php 
    291304    add_thickbox(); 
     
    310323                sl.markDone(base + '/themes/advanced/langs/' + ln + '_dlg.js'); 
    311324            })(); 
    312              
     325 
    313326            tinyMCE.init({ 
    314327                mode: "textareas", 
     
    331344                convert_urls : false, 
    332345                apply_source_formatting : false, 
    333                 remove_linebreaks : false, 
     346                remove_linebreaks : true, 
    334347                accessibility_focus : false, 
    335348                tab_focus : ":next", 
     
    346359    // add the quickadd form 
    347360    jQuery('#jaxtag').prepend('<span id="ajaxtag"><input type="text" name="newtag" id="newtag" class="form-input-tip" size="16" autocomplete="off" value="'+postL10n.addTag+'" /><input type="submit" class="button" id="tagadd" value="' + postL10n.add + '" tabindex="3" onclick="return false;" /><input type="hidden"/><input type="hidden"/><span class="howto">'+postL10n.separate+'</span></span>'); 
    348          
     361 
    349362    jQuery('#tagadd').click( tag_flush_to_text ); 
    350363    jQuery('#newtag').focus(function() { 
     
    360373    jQuery('#publish').click( tag_save_on_publish ); 
    361374    jQuery('#save-post').click( tag_save_on_publish ); 
    362          
     375 
    363376    function set_menu(type) { 
    364377        jQuery('#text_button').removeClass('ui-tabs-selected'); 
     
    367380        jQuery("#post_type").val(type); 
    368381    } 
    369      
     382 
    370383    function set_editor(text) { 
    371         if(tinyMCE.activeEditor) tinyMCE.activeEditor.setContent('')
    372         if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text); 
    373     } 
    374      
     384        if ( '' == text || '<p></p>' == text ) text = '<p><br /></p>'
     385        if ( tinyMCE.activeEditor ) tinyMCE.execCommand('mceSetContent', false, text); 
     386    } 
     387 
    375388    function append_editor(text) { 
    376         if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text); 
    377     } 
    378      
     389        if ( '' != text && tinyMCE.activeEditor ) tinyMCE.execCommand('mceInsertContent', false, text); 
     390    } 
     391 
    379392    function set_title(title) { jQuery("#content_type").text(title); } 
    380393 
     
    387400                set_title('<?php _e('Post') ?>'); 
    388401                <?php if ($selection) { ?> 
    389                     set_editor("<?php echo $selection; ?>"); 
     402                    set_editor('<?php echo $selection; ?><p><a href="<?php echo $url ?>"><?php echo $title; ?></a> &rlm;</p>'); 
    390403                <?php } else { ?> 
    391                     set_editor("<a href='<?php echo $url ?>'><?php echo $title; ?></a>"); 
     404                    set_editor('<p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>'); 
    392405                <?php } ?> 
    393406                return false; 
     
    396409                set_menu('quote'); 
    397410                set_title('<?php _e('Quote') ?>'); 
    398                 set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo $url; ?>'><?php echo $title; ?> </a> </cite> </p></blockquote>"); 
     411                set_editor('<blockquote><?php echo $selection; ?> <p><cite><a href="<?php echo $url; ?>"><?php echo $title; ?> </a> </cite> </p></blockquote>'); 
    399412                return false; 
    400413                break; 
     
    406419                jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']); ?>', { ajax: 'video', s: '<?php echo attribute_escape($selection); ?>'}, function() { 
    407420                    <?php  
     421                    $content = ''; 
    408422                    if ( preg_match("/youtube\.com\/watch/i", $url) ) { 
    409423                        list($domain, $video_id) = split("v=", $url); 
    410424                        $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>'; 
    411                          
     425 
    412426                    } elseif ( preg_match("/vimeo\.com\/[0-9]+/i", $url) ) { 
    413427                        list($domain, $video_id) = split(".com/", $url); 
    414428                        $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>'; 
    415                      
     429 
    416430                        if ( trim($selection) == '' ) 
    417                             $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>'; 
    418                                          
    419                     } else
     431                            $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>'; 
     432 
     433                    } elseif ( strpos( $selection, '<object' ) !== false )
    420434                        $content = $selection; 
    421435                    } 
    422                      
    423436                    ?> 
    424437                    jQuery('#embed_code').prepend('<?php echo htmlentities($content); ?>'); 
    425                      
    426                     set_editor("<?php echo $title; ?>"); 
     438 
     439                    set_editor('<a href="<?php echo $url ?>"><?php echo $title; ?></a> &rlm;'); 
    427440                }); 
    428441                return false; 
     
    432445                set_title('<?php _e('Post') ?>'); 
    433446                <?php if ($selection) { ?> 
    434                     set_editor("<?php echo $selection; ?>"); 
     447                    set_editor('<?php echo $selection; ?><p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>'); 
    435448                <?php } else { ?> 
    436                     set_editor("<a href='<?php echo $url ?>'><?php echo $title; ?></a>"); 
     449                    set_editor('<p><a href="<?php echo $url ?>"><?php echo $title; ?></a></p>'); 
    437450                <?php } ?> 
    438451                jQuery('#extra_fields').show(); 
     
    453466        } 
    454467    } 
    455      
     468 
    456469    jQuery(document).ready(function() { 
    457470        jQuery('#menu li').click(function (){  
     
    492505            <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/> 
    493506        </div> 
    494          
     507 
    495508        <div id="extra_fields" style="display: none"></div> 
    496          
     509 
    497510        <div class="editor_area"> 
    498511            <h2 id="content_type"><label for="content"><?php _e('Post') ?></label></h2> 
    499512            <div class="editor-container"> 
    500                 <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if ($selection) { echo wp_richedit_pre($selection); } else { ?><a href='<?php echo $url ?>'><?php echo $title; ?></a><?php } ?></textarea> 
     513                <textarea name="content" id="content" style="width:100%;" class="mceEditor"><?php if ($selection) { echo wp_richedit_pre($selection); } ?><a href="<?php echo $url ?>"><?php echo $title; ?></a> &rlm;</textarea> 
    501514            </div> 
    502515        </div> 
     
    505518    <div id="categories"> 
    506519        <div class="submitbox" id="submitpost"> 
    507         <div id="previewview"></div> 
    508         <div class="inside"> 
    509             <h2><?php _e('Categories') ?></h2> 
    510             <div id="categories-all"> 
    511                 <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 
    512                     <?php wp_category_checklist() ?> 
    513                 </ul> 
     520            <div id="previewview"></div> 
     521            <div class="inside"> 
     522                <h2><?php _e('Categories') ?></h2> 
     523                <div id="categories-all"> 
     524                    <ul id="categorychecklist" class="list:category categorychecklist form-no-clear"> 
     525                        <?php wp_category_checklist() ?> 
     526                    </ul> 
     527                </div> 
     528                 
     529                <h2><?php _e('Tags') ?></h2> 
     530                <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> 
     531                <div id="tagchecklist"></div> 
    514532            </div> 
    515             <h2><?php _e('Tags') ?></h2> 
    516             <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> 
    517             <div id="tagchecklist"></div> 
     533 
     534            <p class="submit">          
     535                <input type="submit" name="draft" value="<?php _e('Save') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> 
     536                <input type="submit" name="publish" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> 
     537                <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/> 
     538            </p> 
    518539        </div> 
    519         <div id="post_status"> 
    520             <input type="radio" name="post_status" value="publish" checked="checked" id="published" /> <label for="published"><?php _e('Published'); ?></label> 
    521             <input type="radio" name="post_status" value="draft" id="unpublished" /> <label for="unpublished"><?php _e('Unpublished'); ?></label> 
    522         </div> 
    523         <p class="submit">          
    524             <input type="submit" value="<?php _e('Publish') ?>" onclick="document.getElementById('photo_saving').style.display = '';"/> 
    525             <img src="images/loading-publish.gif" alt="" id="photo_saving" style="display:none;"/> 
    526         </p> 
    527540    </div> 
    528541</form> 
  • trunk/wp-includes/script-loader.php

    r8313 r8316  
    230230    $styles->add( 'install', '/wp-admin/css/install.css', array(), '20080708' ); 
    231231    $styles->add( 'theme-editor', '/wp-admin/css/theme-editor.css' ); 
    232     $styles->add( 'press-this', '/wp-admin/css/press-this.css', array(), '20080704' ); 
     232    $styles->add( 'press-this', '/wp-admin/css/press-this.css', array(), '20080710' ); 
    233233    $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array(), '20080613' ); 
    234234    $styles->add( 'login', '/wp-admin/css/login.css' );