Make WordPress Core

Changeset 7927


Ignore:
Timestamp:
05/13/2008 10:12:52 PM (19 years ago)
Author:
ryan
Message:

Don't pass image list via GET. Fetch images remotely. Load photo tab via AJAX. see #6813

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/quick-post.php

    r7924 r7927  
    2222                        $content = '<blockquote>' . $_REQUEST['content'];
    2323                        if ($_REQUEST['content2']) {
    24                                         $content = $content . '</blockquote>';
     24                                $content .= '</blockquote>';
    2525                                $content = $content . '<p>' . $_REQUEST['content2'];
    2626                        }
    … …  
    4444                        $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>';
    4545                        if ($_REQUEST['content2'])
    46                                 $content = $content . '</br><p>' . $_REQUEST['content2'] . '</p>';
     46                                $content .= '</br><p>' . $_REQUEST['content2'] . '</p>';
    4747                        break;                         
    4848        }
    … …  
    6868}
    6969
     70function get_images_from_uri($uri) {
     71        $content = wp_remote_fopen($uri);
     72        if ( false === $content )
     73                return '';
     74
     75        $pattern = '/src=[\'"]?([^\'" >]+)[\'" >]/';
     76        preg_match_all($pattern, $content, $matches);
     77        if ( empty($matches[1]) )
     78                return '';
     79
     80        $from_host = parse_url($uri);
     81        $from_host = $from_host['host'];
     82        $from_host = explode('.', $from_host);
     83        $count = count($from_host);
     84        $from_host = $from_host[$count - 2] . '.' . $from_host[$count - 1];
     85
     86        $sources = array();
     87        foreach ($matches[1] as $src) {
     88                if ( false !== strpos($src, '&') )
     89                        continue;
     90
     91                $img_host = parse_url($src);
     92                $img_host = $img_host['host'];
     93                if ( false === strpos($img_host, $from_host) )
     94                        continue;
     95
     96                $sources[] = $src;
     97        }
     98        return "'" . implode("','", $sources) . "'";
     99}
     100
     101// Clean up the data being passed in
     102$title = stripslashes($_GET['t']);
     103
     104if ( !empty($_GET['load']) && 'photo' == $_GET['load'] ) {
     105?>
     106        <script type="text/javascript">
     107    <?php if ( user_can_richedit() ) {
     108        $language = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) );
     109    ?>
     110
     111                        tinyMCE.init({
     112                                mode: "textareas",
     113                                editor_selector: "mceEditor",
     114                                language : "<?php echo $language; ?>",
     115                                width: "100%",
     116                                theme : "advanced",
     117                                theme_advanced_buttons1 : "bold,italic,underline,blockquote,separator,strikethrough,bullist,numlist,undo,redo,link,unlink",
     118                                theme_advanced_buttons2 : "",
     119                                theme_advanced_buttons3 : "",
     120                                theme_advanced_toolbar_location : "top",
     121                                theme_advanced_toolbar_align : "left",
     122                                theme_advanced_statusbar_location : "bottom",
     123                                theme_advanced_resizing : true,
     124                                theme_advanced_resize_horizontal : false,
     125                                skin : "wp_theme",
     126                                dialog_type : "modal",
     127                                relative_urls : false,
     128                                remove_script_host : false,
     129                                convert_urls : false,
     130                                apply_source_formatting : false,
     131                                remove_linebreaks : true,
     132                                accessibility_focus : false,
     133                                tab_focus : ":next",
     134                                plugins : "safari,inlinepopups"
     135                        });
     136    <?php } ?>
     137                        var last = null;
     138                        function pick(img) {
     139                                if (last) last.style.backgroundColor = '#f4f4f4';
     140                                if (img) {
     141                                        document.getElementById('photo_src').value = img.src;
     142                                        img.style.backgroundColor = '#44f';
     143                                }
     144                                last = img;
     145                                return false;
     146                        }
     147
     148                        jQuery(document).ready(function() {
     149                                var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
     150                                var my_src = [<?php echo get_images_from_uri(clean_url($_GET['u'])); ?>];
     151
     152                                for (i = 0; i < my_src.length; i++) {
     153                                        img = new Image();
     154                                        img.src = my_src[i];
     155                                        img_attr = 'id="img' + i + '" onclick="pick(this);"';
     156                                        skip = false;
     157                                        if (img.width && img.height) {
     158                                                if (img.width * img.height < 2500) skip = true;
     159                                                aspect = img.width / img.height;
     160                                                if (aspect > 1) {
     161                                                        // Image is wide
     162                                                        scale = 75 / img.width;
     163                                                } else {
     164                                                        // Image is tall or square
     165                                                        scale = 75 / img.height;
     166                                                }
     167                                                if (scale < 1) {
     168                                                        w = parseInt(img.width * scale);
     169                                                        h = parseInt(img.height * scale);
     170                                                } else {
     171                                                        w = img.width;
     172                                                        h = img.height;
     173                                                }
     174                                                img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
     175                                        }
     176                                        if (!skip) {
     177                                                strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'
     178                        }
     179                                }
     180                                jQuery('#img_container').html(strtoappend);
     181
     182                                tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
     183                        });
     184        </script>
     185
     186                        <form action="quick-post.php?action=post" method="post" id="photo_form">
     187                                <?php wp_nonce_field('quick-post') ?>
     188                                <input type="hidden" name="source" value="bookmarklet"/>
     189                                <input type="hidden" name="post_type" value="photo"/>
     190                                <div id="posting">
     191                                        <h2><?php _e('Post Title') ?></h2>
     192                                        <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
     193
     194                                        <h2><?php _e('Caption') ?></h2>
     195                                        <div class="editor-container">
     196                                                <textarea name="content" id="photo_post_two" style="height:130px;width:100%;" class="mceEditor"><?php echo stripslashes($_GET['s']);?>
     197                                                <br>&lt;a href="<?php echo clean_url($_GET['u']);?>"&gt;<?php echo $title;?>&lt;/a&gt;</textarea>
     198                                        </div>
     199
     200                                        <h2><?php _e('Photo URL') ?></h2>
     201                                        <input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
     202
     203                                        <style type="text/css">
     204                                                #img_container img {
     205                                                width:          75px;
     206                                                height:         75px;
     207                                                padding:        2px;
     208                                                background-color: #f4f4f4;
     209                                                margin-right:   7px;
     210                                                margin-bottom:  7px;
     211                                                cursor:         pointer;
     212                                            }
     213                                        </style>
     214                                        <div id="img_container" style="border:solid 1px #ccc; background-color:#f4f4f4; padding:5px; width:370px; margin-top:10px; overflow:auto; height:100px;">
     215                                        </div>
     216
     217                                        <h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
     218                                        <input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($_GET['u']);?>"/>
     219
     220                                        <?php tag_input(); ?>
     221     
     222                                        <div>         
     223                                                <input type="submit" value="<?php _e('Create Photo') ?>" style="margin-top:15px;"       onclick="document.getElementById('photo_saving').style.display = '';"/>&nbsp;&nbsp;
     224
     225                                                <a href="#" onclick="if (confirm('<?php _e('Are you sure?') ?>')) { self.close(); } else { return false; }" style="color:#007BFF;"><?php _e('Cancel') ?></a>&nbsp;&nbsp;
     226                                                <img src="/images/bookmarklet_loader.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/>
     227                                        </div>
     228                                </div>
     229                                <div id="categories">
     230                                        <h2><?php _e('Categories') ?></h2>
     231                                        <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
     232                                        <?php wp_category_checklist($post_ID) ?>
     233                                        </ul>
     234                                </div>
     235                        </form>
     236<?php
     237exit;
     238}
    70239?>
    71240<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    … …  
    128297        jQuery(document).ready(function() {
    129298    <?php if ( preg_match("/youtube\.com\/watch/i", $_GET['u']) ) { ?>
    130                 jQuery('#container > ul').tabs({ selected: 4 })({ fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
     299                jQuery('#container > ul').tabs({ selected: 3, fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
    131300        <?php } elseif ( preg_match("/flickr\.com/i", $_GET['u']) ) { ?>
    132                 jQuery('#container > ul').tabs({ selected: 2 })({ fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
     301                jQuery('#container > ul').tabs({ selected: 1, fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
    133302        <?php } else { ?>
    134                 jQuery('#container > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
     303                jQuery('#container > ul').tabs({ selected: 1, fx: { height: 'toggle', opacity: 'toggle', fxSpeed: 'fast' } });
    135304        <?php } ?>
    136305        });
    137                        
     306
    138307        </script>
    139308</head>
    … …  
    151320}
    152321
    153 // Clean up the data being passed in
    154 $title = stripslashes($_GET['t']);
    155 
    156322?>
    157323        <div id="container">
    … …  
    159325                <ul>
    160326                        <li><a href="#section-1"><span><?php _e('Text/Link') ?></span></a></li>
    161                         <li><a href="#section-2"><span><?php _e('Photo') ?></span></a></li>
     327                        <li><a href="<?php echo add_query_arg('load', 'photo') ?>"><span><?php _e('Photo') ?></span></a></li>
    162328                        <li><a href="#section-3"><span><?php _e('Quote') ?></span></a></li>
    163329                        <li><a href="#section-4"><span><?php _e('Video') ?></span></a></li>
    … …  
    194360                                </div>
    195361                         </form>
    196                 </div>
    197 
    198                 <!-- Photo -->
    199                 <div id="section-2">
    200                         <form action="quick-post.php?action=post" method="post" id="photo_form">
    201                                 <?php wp_nonce_field('quick-post') ?>
    202                                 <input type="hidden" name="source" value="bookmarklet"/>
    203                                 <input type="hidden" name="post_type" value="photo"/>
    204                                 <div id="posting">
    205                                         <h2><?php _e('Post Title') ?></h2>
    206                                         <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
    207 
    208                                         <h2><?php _e('Caption') ?></h2>
    209                                         <div class="editor-container">
    210                                                 <textarea name="content" id="photo_post_two" style="height:130px;width:100%;" class="mceEditor"><?php echo "" .stripslashes($_GET['s']);?>
    211                                                 <br>&lt;a href="<?php echo clean_url($_GET['u']);?>"&gt;<?php echo $title;?>&lt;/a&gt;</textarea>
    212                                         </div>
    213 
    214                                         <h2><?php _e('Photo URL') ?></h2>
    215                                         <input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
    216 
    217                                         <style type="text/css">
    218                                                 #img_container img {
    219                                                 width:          75px;
    220                                                 height:         75px;
    221                                                 padding:        2px;
    222                                                 background-color: #f4f4f4;
    223                                                 margin-right:   7px;
    224                                                 margin-bottom:  7px;
    225                                                 cursor:         pointer;
    226                                             }
    227                                         </style>
    228 
    229                                         <div id="img_container" style="border:solid 1px #ccc; background-color:#f4f4f4; padding:5px; width:370px; margin-top:10px; overflow:auto; height:100px;">
    230                                                 <script type="text/javascript">
    231                                                         var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
    232                                                         var my_src = ['<?php echo str_replace(",", "','", rtrim($_GET['imagez'], ","));?>'];
    233                                                         var last = null;
    234 
    235                                                         function pick(img) {
    236                                                                 if (last) last.style.backgroundColor = '#f4f4f4';
    237                                                                 if (img) {
    238                                                                         document.getElementById('photo_src').value = img.src;
    239                                                                         img.style.backgroundColor = '#44f';
    240                                                                 }
    241                                                                 last = img;
    242                                                                 return false;
    243                                                         }
    244                                                         for (i = 0; i < my_src.length; i++) {
    245                                                                 img = new Image();
    246                                                                 img.src = my_src[i];
    247                                                                 img_attr = 'id="img' + i + '" onclick="pick(this);"';
    248                                                                 skip = false;
    249                                                                 if (img.width && img.height) {
    250                                                                         if (img.width * img.height < 2500) skip = true;
    251                                                                         aspect = img.width / img.height;
    252                                                                         if (aspect > 1) {
    253                                                                                 // Image is wide
    254                                                                                 scale = 75 / img.width;
    255                                                                         } else {
    256                                                                                 // Image is tall or square
    257                                                                                 scale = 75 / img.height;
    258                                                                         }
    259                                                                         if (scale < 1) {
    260                                                                                 w = parseInt(img.width * scale);
    261                                                                                 h = parseInt(img.height * scale);
    262                                                                         } else {
    263                                                                                 w = img.width;
    264                                                                                 h = img.height;
    265                                                                         }
    266                                                                         img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
    267                                                                 }
    268                                                                 if (!skip) {
    269                                                                         strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'
    270                                         }
    271                                                         }
    272                                                         if (jQuery.browser.safari) {
    273                                                                 document.getElementById('img_container').innerHTML = strtoappend; 
    274                                                         } else {
    275                                                                 document.write(strtoappend);               
    276                                                         }
    277                                                 </script>
    278                                         </div>
    279 
    280                                         <h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
    281                                         <input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($_GET['u']);?>"/>
    282 
    283                                         <?php tag_input(); ?>
    284      
    285                                         <div>         
    286                                                 <input type="submit" value="<?php _e('Create Photo') ?>" style="margin-top:15px;"       onclick="document.getElementById('photo_saving').style.display = '';"/>&nbsp;&nbsp;
    287 
    288                                                 <a href="#" onclick="if (confirm('<?php _e('Are you sure?') ?>')) { self.close(); } else { return false; }" style="color:#007BFF;"><?php _e('Cancel') ?></a>&nbsp;&nbsp;
    289                                                 <img src="/images/bookmarklet_loader.gif" alt="" id="photo_saving" style="width:16px; height:16px; vertical-align:-4px; display:none;"/>
    290                                         </div>
    291                                 </div>
    292                                 <div id="categories">
    293                                         <h2><?php _e('Categories') ?></h2>
    294                                         <ul id="categorychecklist" class="list:category categorychecklist form-no-clear">
    295                                         <?php wp_category_checklist($post_ID) ?>
    296                                         </ul>
    297                                 </div>
    298                         </form>
    299362                </div>
    300363
  • trunk/wp-includes/link-template.php

    r7924 r7927  
    745745function get_shortcut_link() {
    746746        $link = "javascript:
    747                         var imgstr='';
    748                         var reg=new RegExp('&');
    749                         for(i=0;i<document.images.length;i++){
    750                                 if(! reg.test(document.images[i].src)){
    751                                         imgstr = imgstr + document.images[i].src + ',';
    752                                 }
    753                         }
    754747                        var d=document;
    755748                        var w=window;
    … …  
    761754                        var l=d.location;
    762755                        var e=encodeURIComponent;
    763                         var p='?imagez='+imgstr;
    764                         var u= '&u=' + e(l.href);
     756                        var u= '?u=' + e(l.href);
    765757                        var t= '&t=' + e(d.title);
    766758                        var s= '&s=' + e(s);
    767                         var g= f+p+u+t+s;
     759                        var v='&v=1';
     760                        var g= f+u+t+s+v;
    768761                        function a(){
    769762                                if(!w.open(g,'t','toolbar=0,resizable=0,scrollbars=1,status=1,width=700,height=500')){
Note: See TracChangeset for help on using the changeset viewer.