Make WordPress Core

Changeset 8067


Ignore:
Timestamp:
06/10/2008 04:13:06 PM (17 years ago)
Author:
ryan
Message:

Press This improvements from noel. fixes #7117

Location:
trunk/wp-admin
Files:
3 edited

Legend:

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

    r8062 r8067  
    357357    float: left;
    358358}
     359
    359360#embed_code {
    360361    border: 0;
     
    395396    text-decoration: underline;
    396397}
     398
     399
     400.photolist {
     401display: none;
     402}
     403
     404#extra_fields small {
     405display: block;
     406margin-top: .5em;
     407padding-bottom: .25em;
     408}
     409
     410#TB_ajaxContent #options {
     411position: absolute;
     412top: 20px;
     413right: 25px;
     414background: white;
     415padding: 5px;
     416}
     417#TB_ajaxContent h3 {
     418margin-bottom: .25em;
     419}
     420
     421.updated {
     422    margin: 0;
     423    margin-left: 15px;
     424    margin-right: 15px;
     425    padding: 0;
     426    max-width: 980px;
     427    border-width: 1px;
     428    border-style: solid;
     429    padding: 0 0.6em;
     430    max-width: 950px;
     431    margin-top: 1em;
     432    margin-bottom: 1em;
     433}
     434
     435.updated p, .error p {
     436    margin: 0.6em 0;
     437}
     438
     439.updated a, .error a {
     440    text-decoration: underline;
     441}
     442
     443.updated a {
     444    text-decoration: none;
     445    padding-bottom: 2px;
     446}
  • trunk/wp-admin/includes/media.php

    r8048 r8067  
    117117
    118118
    119 function media_sideload_image($file, $post_id) {
     119function media_sideload_image($file, $post_id, $desc = null) {
    120120
    121121    if (!empty($file) ) {
     
    124124        $file_array['name'] = basename($file);
    125125        $file_array['tmp_name'] = download_url($file);
     126        $desc = @$desc;
    126127       
    127         $sideload = media_handle_sideload($file_array, $post_id);
     128        $sideload = media_handle_sideload($file_array, $post_id, $desc);
    128129
    129130        $id = $sideload['id'];
     
    142143       
    143144        $src = "http://$src";
    144         /*$alt = attribute_escape($_POST['insertonly']['alt']);
    145         if ( isset($_POST['insertonly']['align']) ) {
    146             $align = attribute_escape($_POST['insertonly']['align']);
    147             $class = " class='align$align'";
    148         } */
     145        $alt = @$desc;
     146       
    149147        if ( !empty($src) )
    150             $html = "<img src='$src' alt='$alt'$class />";
     148            $html = "<img src='$src' alt='$alt' />";
    151149            return $html;
    152150   
    153151}
    154152
    155 function media_handle_sideload($file_array, $post_id, $post_data = array()) {
     153function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
    156154    $overrides = array('test_form'=>false);
    157155    $file = wp_handle_sideload($file_array, $overrides);
     
    173171            $content = $image_meta['caption'];
    174172    }
     173   
     174    $title = @$desc;
    175175
    176176    // Construct the attachment array
  • trunk/wp-admin/press-this.php

    r8059 r8067  
    66<?php
    77function press_it() {
    8         $quick['post_status'] = 'publish';
    9         $quick['post_category'] = $_REQUEST['post_category'];
    10         $quick['tags_input'] = $_REQUEST['tags_input'];
    11         $quick['post_title'] = $_REQUEST['post_title'];
    12         $quick['post_content'] = '';
    13        
    14         // insert the post with nothing in it, to get an ID
    15         $post_ID = wp_insert_post($quick, true);
    16        
    17         $content = '';
    18         switch ( $_REQUEST['post_type'] ) {
    19             case 'text':
    20                 $content .= $_REQUEST['content'];
    21 
    22             case 'quote':
    23                 $content .= $_REQUEST['content'];
    24                 break;
    25 
    26             case 'photo':
    27                 if ($_REQUEST['photo_link'])
    28                     $content .= '<a href="' . $_REQUEST['photo_link'] . '">';
    29                    
    30                     $content .= media_sideload_image($_REQUEST['photo_src'], $post_ID);
    31 
    32                 if ($_REQUEST['photo_link'])
    33                     $content .= '</a>';
    34 
    35                 if ($_REQUEST['content'])
    36                     $content .= $content . "\n\n".$_REQUEST['content'];
    37 
    38                 break;
    39             case "video":
    40                 if($_REQUEST['embed_code'])
    41                     $content .= $_REQUEST['embed_code']."\n\n";
    42                 $content .= $_REQUEST['content'];
    43                 break; 
     8    #define some basic variables
     9    $quick['post_status'] = 'publish';
     10    $quick['post_category'] = $_REQUEST['post_category'];
     11    $quick['tags_input'] = $_REQUEST['tags_input'];
     12    $quick['post_title'] = $_REQUEST['post_title'];
     13    $quick['post_content'] = '';
     14       
     15    # insert the post with nothing in it, to get an ID
     16    $post_ID = wp_insert_post($quick, true);
     17       
     18    $content = '';
     19    switch ( $_REQUEST['post_type'] ) {
     20        case 'text':
     21        case 'quote':
     22            $content .= $_REQUEST['content'];
     23            break;
     24       
     25        case 'photo':
     26            foreach($_REQUEST['photo_src'] as $key => $data) {
     27                #quote for matching
     28                $quoted = str_replace('/', '\/', preg_quote($data));
     29               
     30                # see if files exist in content - we don't want to upload non-used selected files.
     31                preg_match('/'.$quoted.'/', $_REQUEST['content'], $matches[0]);
     32                if($matches[0])
     33                    media_sideload_image($data, $post_ID, $_REQUEST['photo_description'][$key]);   
     34            }
     35            $content = $_REQUEST['content'];
     36            break;
     37           
     38        case "video":
     39            if($_REQUEST['embed_code'])
     40                $content .= $_REQUEST['embed_code']."\n\n";
     41            $content .= $_REQUEST['content'];
     42            break; 
    4443        }
    45 
     44    # set the post_content
    4645    $quick['post_content'] = $content;
    4746
     47    #error handling for $post
    4848    if ( is_wp_error($post_ID) ) {
    4949        wp_die($id);
    5050        wp_delete_post($post_ID);
    51     } else {
     51
     52    #error handling for media_sideload
     53    } else {   
    5254        $quick['ID'] = $post_ID;
    5355        wp_update_post($quick);
     
    5658}
    5759
    58     function tag_div() { ?>
     60function tag_div() { ?>
    5961        <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>
    6062        <div id="tagchecklist"></div>
    61     <?php
    62     }
    63 
    64     function category_div() {
    65     ?>
     63<?php }
     64
     65function category_div() { ?>
    6666    <div id="categories">
    6767        <div class="submitbox" id="submitpost">
     
    7979            </p>
    8080        </div> 
    81     <?php
    82     }
    83 
    84 // For posts submitted
     81<?php }
     82
     83# For submitted posts.
    8584if ( 'post' == $_REQUEST['action'] ) {
    8685    check_admin_referer('press-this'); $post_ID = press_it(); ?>
    87         <script>if(confirm("<?php _e('Your post is saved. Do you want to view the post?') ?>")){window.opener.location.replace("<?php echo get_permalink($post_ID);?>");}window.close();</script>
     86   
     87    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     88    <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
     89    <head>
     90        <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
     91        <title><?php _e('Press This') ?></title>
     92    <?php
     93        add_thickbox();
     94        wp_enqueue_style('press-this');
     95        wp_enqueue_style( 'colors' );
     96        wp_enqueue_script('post');
     97
     98        do_action('admin_print_styles');
     99        do_action('admin_print_scripts');
     100        do_action('admin_head');
     101    ?>
     102    </head>
     103    <body class="press-this">
     104        <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>
     105    </body>
     106    </html>
    88107    <?php die;
    89108}
     
    93112$selection = trim(wp_specialchars(str_replace("\n", ' ',stripslashes($_GET['s']))));
    94113$url = $_GET['u'];
     114$image = $_GET['i'];
     115if($_REQUEST['ajax'] == 'thickbox') { ?>
     116    <script type="text/javascript" charset="utf-8">
     117        jQuery('.cancel').click(function() {
     118            tb_remove();
     119        });
     120       
     121        function image_selector() {
     122            desc = jQuery('#this_photo_description').val();
     123            src = jQuery('#this_photo').val();
     124            pick(src, desc);
     125            tb_remove();
     126            return false;
     127        }
     128       
     129        jQuery('.select').click(function() {
     130            image_selector();
     131        });
     132
     133    </script>
     134    <h3 id="title"><label for="post_title"><?php _e('Description') ?></label></h3>
     135    <div class="titlewrap">
     136        <input id="this_photo_description" name="photo_description" class="text" onkeypress="if(event.keyCode==13) image_selector();" value="<?php echo attribute_escape($title);?>"/>
     137    </div>
     138       
     139    <p><input type="hidden" name="this_photo" value="<?php echo $image; ?>" id="this_photo" />
     140        <a href="#" class="select" rel="<?php echo $image; ?>"><img src="<?php echo $image; ?>" width="475" alt="Click to insert." title="Click to insert." /></a></p>
     141   
     142    <p id="options"><a href="#" class="select" rel="<?php echo $image; ?>">Insert Image</a> | <a href="#" class="cancel">Cancel</a></p>
     143<?php die;
     144}
     145
    95146
    96147if($_REQUEST['ajax'] == 'video') { ?>
     
    138189   
    139190            var last = null
    140             function pick(img) {
    141 
    142                 if (last) last.style.backgroundColor = '#f4f4f4';
    143                 if (img) {
    144                     jQuery('#photo_src').val(img.src);
    145                     img.style.backgroundColor = '#44f';
    146                 }
    147                 last = img;
    148                
    149                 /*noel's code to select more than one image....
    150                 jQuery('.photolist').append('<h2><?php _e("Photo URL") ?></h2>' +
    151                 '<div class="titlewrap">' +
    152                 '<a href="#" class="remove">remove <input name="photo_src" id="photo_src[]" value ="'+ img.src +'" class="text" onkeydown="pick(0);"/></a>' +
    153                 '</div>');*/
    154 
     191           
     192            function pick(img, desc) {
     193                if (img) {
     194                    length = jQuery('.photolist input').length;
     195                    if(length == 0) length = 1;
     196                    jQuery('.photolist').append('<input name="photo_src[' + length + ']" value="' + img +'" type="hidden"/>');
     197                    jQuery('.photolist').append('<input name="photo_description[' + length + ']" value="' + desc +'" type="hidden"/>');
     198                    append_editor('<img src="' + img +'" alt="' + desc + '" />'); }
    155199                return false;
    156200            }
    157201
    158             jQuery('.remove').click(function() {
    159                 jQuery(this).remove;
    160             });
    161 
    162 
    163202            var my_src, img, img_tag, aspect, w, h, skip, i, strtoappend = "";
    164203           
    165             var my_src =eval(
     204            var my_src = eval(
    166205            jQuery.ajax({
    167206                type: "GET",
     
    170209                async : false,
    171210                data: "ajax=photo_images&u=<?php echo urlencode($url); ?>",
    172             dataType : "script"
    173             }).responseText);
     211                dataType : "script"
     212                }).responseText);
    174213
    175214            for (i = 0; i < my_src.length; i++) {
    176215                img = new Image();
    177216                img.src = my_src[i];
    178                 img_attr = 'id="img' + i + '" onclick="pick(this);"';
     217                img_attr = 'id="img' + i;
    179218                skip = false;
    180219
     
    197236                }
    198237
    199                 if (!skip) strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
     238                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>';
    200239
    201240            }
     
    208247
    209248if($_REQUEST['ajax'] == 'photo') { ?>
    210         <h2><?php _e('Photo URL') ?></h2>
    211         <div class="titlewrap">
    212             <input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
    213         </div>
    214249   
    215250        <div class="photolist"></div>
    216    
    217         <h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
    218         <div class="titlewrap">
    219             <input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($url);?>"/>
    220         </div>
    221251   
    222252        <small><?php _e('Click images to select:') ?></small>
     
    265295                theme : "advanced",
    266296                theme_advanced_buttons1 : "bold,italic,underline,blockquote,separator,strikethrough,bullist,numlist,undo,redo,link,unlink",
    267                 extended_valid_elements : "object[width|height],param[name|value],embed[src|type|wmode|width|height], a[name|href|target|title|onclick], img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name], hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
    268297                theme_advanced_buttons2 : "",
    269298                theme_advanced_buttons3 : "",
     
    279308                convert_urls : false,
    280309                apply_source_formatting : false,
    281                 remove_linebreaks : true,
     310                remove_linebreaks : false,
    282311                accessibility_focus : false,
    283312                tab_focus : ":next",
     
    316345    function set_editor(text) {
    317346        if(tinyMCE.activeEditor) tinyMCE.activeEditor.setContent('');
     347        if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);
     348    }
     349    function append_editor(text) {
    318350        if(tinyMCE.activeEditor) tinyMCE.execCommand('mceInsertContent' ,false, text);
    319351    }
     
    332364                set_menu('text');
    333365                set_title('<?php _e('Text') ?>');
    334                 set_editor('<?php echo $selection; ?>');
     366                set_editor("<?php echo $selection; ?>");
    335367                return false;
    336368            break;
     
    341373                set_menu('quote');
    342374                set_title('<?php _e('Quote') ?>');
    343                 set_editor('<blockquote><p><?php echo $selection; ?> </p><p><cite><a href="<?php echo $url; ?>"><?php echo $title; ?></a></cite> </p></blockquote>');
     375                set_editor("<blockquote><p><?php echo $selection; ?> </p><p><cite><a href='<?php echo ''; ?>'><?php echo ''; ?></a></cite> </p></blockquote>");
    344376
    345377                return false;
     
    373405                    } ?>
    374406                    jQuery('#embed_code').prepend('<?php echo htmlentities($content); ?>');
    375                     set_editor('<?php echo $title; ?>');
     407                    set_editor("<?php echo $title; ?>");
    376408                   
    377409                });
     
    384416                reset_height();
    385417                set_menu('photo');
    386                 set_title('Caption');
    387                 set_editor('<a href="<?php echo $url; ?>"><?php echo $title; ?></a>');
    388                
     418                set_title('Post');
     419                <?php if($selection) { ?>
     420                    set_editor("<?php echo $selection; ?>");
     421                <?php } else { ?>
     422                    set_editor('')
     423                <?php } ?>
    389424                jQuery('#extra_fields').show();
    390425                jQuery('#extra_fields').load('<?php echo clean_url($_SERVER['PHP_SELF']).'/?ajax=photo&u='.attribute_escape($url); ?>');
     
    399434                    }
    400435                });
     436               
    401437                return false;
    402438            break;
     
    445481                        <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
    446482                    </div>
    447 
     483                   
    448484                    <div id="extra_fields" style="display: none"></div>
    449485                    <div class="editor_area">
Note: See TracChangeset for help on using the changeset viewer.