Make WordPress Core


Ignore:
Timestamp:
05/28/2008 06:18:44 PM (18 years ago)
Author:
ryan
Message:

Press this reorg. Remove old bookmarklet. Props noel. see #7049

File:
1 edited

Legend:

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

    r7993 r8007  
    2020        $content = '';
    2121        switch ( $_REQUEST['post_type'] ) {
    22                 case 'regular':
     22                case 'text':
    2323                        $content = $_REQUEST['content'];
    24                         if ($_REQUEST['content2'])
    25                                 $content .= $_REQUEST['content2'];
     24
     25                case 'quote':
     26                        $content = $_REQUEST['content'];
    2627                        break;
    2728
    28                 case 'quote':
    29                         $content = '<blockquote>' . $_REQUEST['content'];
    30                         if ($_REQUEST['content2']) {
    31                                 $content .= '</blockquote>
    32                                 ';
    33                                 $content = $content . $_REQUEST['content2'];
    34                         }
    35                         break;
    36 
    3729                case 'photo':
     30               
     31//              http_post_data();
     32                       
    3833                        if ($_REQUEST['photo_link'])
    39                                 $content = '<a href="' . $_REQUEST['photo_link'] . '" target="_new">';
     34                                $content = '<a href="' . $_REQUEST['photo_link'] . '">';
    4035
    4136                        $content .= '<img src="' . $_REQUEST['photo_src'] . '" alt=""/>';
     
    5045                        break;
    5146                case "video":
    52                         list($garbage,$video_id) = split("v=", $_REQUEST['content']);
    53                         $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>';
    54                         if ($_REQUEST['content2'])
    55                                 $content .= "\n" . $_REQUEST['content2'];
    56                         break;                         
     47                        $content = $_REQUEST['content'];
     48                       
     49                        break; 
    5750        }
    5851
     
    9689
    9790        $content = wp_remote_fopen($uri);
     91        $uri = str_replace(basename($uri), '', $uri);                   
     92        $host = parse_url($uri);
     93       
    9894        if ( false === $content ) return '';
    9995
     
    10399       
    104100        $sources = array();
     101
    105102        foreach ($matches[1] as $src) {
    106103                if ( false !== strpos($src, '&') )
    107104                        continue;
    108                
    109                 $host = parse_url($_GET['u']);
    110                
    111                 if (strpos($src, 'http://') === false) {
    112                         $src = 'http://'.str_replace('//','/', $host['host'].'/'.$src);
    113                 }
     105                $src = 'http://'.str_replace('//','/', $host['host'].'/'.$host['path'].'/'.$src);
    114106               
    115107                $sources[] = $src;
     
    118110}
    119111
    120 function press_this_js_init() { ?>
    121     <?php if ( user_can_richedit() ) {
     112// Clean up the data being passed in
     113$title = wp_specialchars(stripslashes($_GET['t']));
     114$selection = trim(wp_specialchars(str_replace("\n", ' ',stripslashes($_GET['s']))));
     115$url = clean_url($_GET['u']);
     116?>
     117<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     118<html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
     119<head>
     120        <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
     121        <title><?php _e('Press This') ?></title>
     122
     123        <script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce.js"></script>
     124<?php
     125        wp_enqueue_script('jquery-ui-tabs');
     126        add_thickbox();
     127        wp_enqueue_style('press-this');
     128        wp_enqueue_style( 'colors' );
     129        wp_enqueue_script('post');
     130
     131        do_action('admin_print_styles');
     132        do_action('admin_print_scripts');
     133        do_action('admin_head');
     134?>
     135        <script type="text/javascript">
     136        <?php if ( user_can_richedit() ) {
    122137                $language = ( '' == get_locale() ) ? 'en' : strtolower( substr(get_locale(), 0, 2) );
    123138                // Add TinyMCE languages
     
    180195                jQuery('#publish').click( tag_save_on_publish );
    181196                jQuery('#save-post').click( tag_save_on_publish );
    182 <?php
    183 }
    184 
    185 // Clean up the data being passed in
    186 $title = wp_specialchars(stripslashes($_GET['t']));
    187 $selection = wp_specialchars(stripslashes($_GET['s']));
    188 $url = clean_url($_GET['u']);                         
    189 
    190 if ( empty($_GET['tab']) ) {
    191 ?>
    192 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    193 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
    194 <head>
    195         <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
    196         <title><?php _e('Press This') ?></title>
    197 
    198         <script type="text/javascript" src="../wp-includes/js/tinymce/tiny_mce.js"></script>
    199 <?php
    200         wp_enqueue_script('jquery-ui-tabs');
    201         add_thickbox();
    202         wp_enqueue_style('press-this');
    203         wp_enqueue_style( 'colors' );
    204         wp_enqueue_script('post');
    205 
    206         do_action('admin_print_styles');
    207         do_action('admin_print_scripts');
    208         do_action('admin_head');
    209 ?>
    210         <script type="text/javascript">
     197               
     198        function set_menu(type) {
     199                jQuery('#text_button').removeClass('ui-tabs-selected');
     200                jQuery('#menu li').removeClass('ui-tabs-selected');
     201                jQuery('#' + type + '_button').addClass('ui-tabs-selected');
     202                jQuery("#post_type").val(type);
     203        }
     204        function set_editor(text) {
     205                tinyMCE.activeEditor.setContent('');
     206                tinyMCE.execCommand('mceInsertContent' ,false, text);
     207        }
     208        function set_title(title) { jQuery("#content_type").text(title); }
     209       
     210                var last = null;
     211        function pick(img) {
     212                if (last) last.style.backgroundColor = '#f4f4f4';
     213                if (img) {
     214                        document.getElementById('photo_src').value = img.src;
     215                        img.style.backgroundColor = '#44f';
     216                }
     217                last = img;
     218               
     219                /*noel's code to select more than one image....
     220                jQuery('.photolist').append('<h2><?php _e("Photo URL") ?></h2>' +
     221                '<div class="titlewrap">' +
     222                '<a href="#" class="remove">remove <input name="photo_src" id="photo_src[]" value ="'+ img.src +'" class="text" onkeydown="pick(0);"/></a>' +
     223                '</div>');*/
     224               
     225                return false;
     226        }
    211227
    212228        jQuery(document).ready(function() {
    213     <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
    214                 jQuery('#container > ul').tabs({ selected: 3 });
    215         <?php } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
    216                 jQuery('#container > ul').tabs({ selected: 1 });
    217         <?php } else { ?>
    218                 jQuery('#container > ul').tabs();
    219         <?php } ?>
     229               
     230       
     231                <?php if ( preg_match("/youtube\.com\/watch/i", $url) ) { ?>
     232       
     233                <?php } elseif ( preg_match("/flickr\.com/i", $url) ) { ?>
     234                       
     235                <?php } else { ?>
     236
     237                <?php } ?>
     238       
     239       
     240                jQuery("#text_button").click(function () {
     241                        jQuery('.editor-container').show();
     242                        jQuery('#content_type').show();
     243                        jQuery('#photo_fields').hide();
     244                        set_menu('text');
     245                        set_title('<?php _e('Text') ?>');
     246                        set_editor('<?php echo $selection; ?>');
     247                        return false;
     248                });
     249       
     250                jQuery("#quote_button").click(function () {
     251                        jQuery('.editor-container').show();
     252                        jQuery('#content_type').show();
     253                        jQuery('#photo_fields').hide();
     254                        set_menu('quote');
     255                        set_title('<?php _e('Quote') ?>');
     256                        set_editor('<blockquote><p><?php echo $selection; ?> </p><p><cite><a href="<?php echo $url; ?>"><?php echo $title; ?></a></cite> </p></blockquote>');
     257                       
     258                        return false;
     259                });
     260               
     261
     262                jQuery("#video_button").click(function () {
     263                        jQuery('.editor-container').show();
     264                        jQuery('#content_type').show();
     265                        jQuery('#photo_fields').hide();
     266                        set_menu('video');
     267                        set_title('<?php _e('Video') ?>');
     268                        set_editor('<a href="<?php echo $url; ?>"><?php echo $title; ?></a>');
     269                        <?php /*
     270                        <!--list($garbage,$video_id) = split("v=", $_REQUEST['content']);
     271                        $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>';-->
     272                        */?>
     273                        return false;
     274                });     
     275       
     276
     277        jQuery("#photo_button").click(function () {
     278                set_menu('photo');
     279                set_title('Caption');
     280                set_editor('<a href="<?php echo $url; ?>"><?php echo $title; ?></a>');
     281                jQuery('#photo_fields').show();
     282                jQuery('.remove').click(function() {
     283                        jQuery(this).remove;
     284
     285                });
     286               
     287               
     288                var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
     289                var my_src = [<?php echo get_images_from_uri($url); ?>];
     290
     291                for (i = 0; i < my_src.length; i++) {
     292                        img = new Image();
     293                        img.src = my_src[i];
     294                        img_attr = 'id="img' + i + '" onclick="pick(this);"';
     295                        skip = false;
     296                       
     297                        if (img.width && img.height) {
     298                                if (img.width * img.height < 2500) skip = true;
     299                                aspect = img.width / img.height;
     300                                if (aspect > 1) { // Image is wide
     301                                        scale = 75 / img.width;
     302                                } else { // Image is tall or square
     303                                        scale = 75 / img.height;
     304                                }
     305                                if (scale < 1) {
     306                                        w = parseInt(img.width * scale);
     307                                        h = parseInt(img.height * scale);
     308                                } else {
     309                                        w = img.width;
     310                                        h = img.height;
     311                                }
     312                                img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
     313                        }
     314                       
     315                        if (!skip) strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';
     316               
     317                }
     318                       
     319                        jQuery('#img_container').html(strtoappend);
     320
     321                        tb_init('a.thickbox, area.thickbox, input.thickbox'); //pass where to apply thickbox
     322               
     323                });
    220324        });
    221 
    222325        </script>
    223326       
     
    228331<h1><span id="viewsite"><a href="<?php echo get_option('home'); ?>/"><?php _e('Visit:') ?> <?php bloginfo('name'); ?></a></span></h1>
    229332</div>
    230         <div id="container">
    231                 <ul>
    232                         <li><a href="<?php echo clean_url(add_query_arg('tab', 'text', stripslashes($_SERVER['REQUEST_URI']))) ?>"><?php _e('Text') ?></a></li>
    233                         <li><a href="<?php echo clean_url(add_query_arg('tab', 'photo', stripslashes($_SERVER['REQUEST_URI']))) ?>"><?php _e('Photo') ?></a></li>
    234                         <li><a href="<?php echo clean_url(add_query_arg('tab', 'quote', stripslashes($_SERVER['REQUEST_URI']))) ?>"><?php _e('Quote') ?></a></li>
    235                         <li><a href="<?php echo clean_url(add_query_arg('tab', 'video', stripslashes($_SERVER['REQUEST_URI']))) ?>"><?php _e('Video') ?></a></li>
     333
     334                <ul id="menu" class="ui-tabs-nav">
     335                        <li id="text_button" class="ui-tabs-selected"><a href="#"><?php _e('Text') ?></a></li>
     336                        <li id="photo_button"><a href="#"><?php _e('Photo') ?></a></li>
     337                        <li id="quote_button"><a href="#"><?php _e('Quote') ?></a></li>
     338                        <li id="video_button"><a href="#"><?php _e('Video') ?></a></li>
    236339                </ul>
    237                
    238         </div>
    239 </body>
    240 </html>
    241 <?php exit; } elseif ( 'photo' == $_GET['tab'] ) { ?>
    242         <script type="text/javascript">
    243                 <?php press_this_js_init(); ?>
    244                         var last = null;
    245                         function pick(img) {
    246                                 if (last) last.style.backgroundColor = '#f4f4f4';
    247                                 if (img) {
    248                                         document.getElementById('photo_src').value = img.src;
    249                                         img.style.backgroundColor = '#44f';
    250                                 }
    251                                 last = img;
    252                                
    253                                 /*jQuery('.photolist').append('<h2><?php _e("Photo URL") ?></h2>' +
    254                                 '<div class="titlewrap">' +
    255                                 '<a href="#" class="remove">remove <input name="photo_src" id="photo_src[]" value ="'+ img.src +'" class="text" onkeydown="pick(0);"/></a>' +
    256                                 '</div>');*/
    257                                 return false;
    258                         }
    259 
    260                         jQuery('.remove').click(function() {
    261                                 jQuery(this).remove;
    262                                
    263                         });
    264                         jQuery(document).ready(function() {
    265                                 var img, img_tag, aspect, w, h, skip, i, strtoappend = "";
    266                                 var my_src = [<?php echo get_images_from_uri($url); ?>];
    267 
    268                                 for (i = 0; i < my_src.length; i++) {
    269                                         img = new Image();
    270                                         img.src = my_src[i];
    271                                         img_attr = 'id="img' + i + '" onclick="pick(this);"';
    272                                         skip = false;
    273                                         if (img.width && img.height) {
    274                                                 if (img.width * img.height < 2500) skip = true;
    275                                                 aspect = img.width / img.height;
    276                                                 if (aspect > 1) {
    277                                                         // Image is wide
    278                                                         scale = 75 / img.width;
    279                                                 } else {
    280                                                         // Image is tall or square
    281                                                         scale = 75 / img.height;
    282                                                 }
    283                                                 if (scale < 1) {
    284                                                         w = parseInt(img.width * scale);
    285                                                         h = parseInt(img.height * scale);
    286                                                 } else {
    287                                                         w = img.width;
    288                                                         h = img.height;
    289                                                 }
    290                                                 img_attr += ' style="width: ' + w + 'px; height: ' + h + 'px;"';
    291                                         }
    292                                         if (!skip) {
    293                                                 strtoappend += '<a href="' + img.src + '" title="" class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>'
    294                         }
    295                                 }
    296                                
    297                                 jQuery('#img_container').html(strtoappend);
    298 
    299                                 tb_init('a.thickbox, area.thickbox, input.thickbox');//pass where to apply thickbox
    300                         });
    301         </script>
    302                         <form action="press-this.php?action=post" method="post" id="photo_form">
     340
     341                        <form action="press-this.php?action=post" method="post">
    303342                                <?php wp_nonce_field('press-this') ?>
    304343                                <input type="hidden" name="source" value="bookmarklet"/>
    305                                 <input type="hidden" name="post_type" value="photo"/>
     344                                <input type="hidden" name="post_type" id="post_type" value="text"/>
    306345                                <div id="posting">
    307346                                       
    308                                         <h2><?php _e('Title') ?></h2>
     347                                        <h2 id="title"><?php _e('Title') ?></h2>
    309348                                        <div class="titlewrap">
    310                                         <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
     349                                                <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
    311350                                        </div>
    312                                        
    313                                         <h2><?php _e('Photo URL') ?></h2>
    314                                         <div class="titlewrap">
    315                                         <input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
     351                                        <div id="photo_fields" style="display: none;">
     352                                                <h2><?php _e('Photo URL') ?></h2>
     353                                                <div class="titlewrap">
     354                                                        <input name="photo_src" id="photo_src" class="text" onkeydown="pick(0);"/>
     355                                                </div>
     356                                       
     357                                                <div class="photolist"></div>
     358                                       
     359                                                <h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
     360                                                <div class="titlewrap">
     361                                                        <input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($url);?>"/>
     362                                                </div>
     363                                       
     364                                                <small><?php _e('Click images to select:') ?></small>
     365                                                <div class="titlewrap">
     366                                                        <div id="img_container"></div>
     367                                                </div>
     368                                       
    316369                                        </div>
    317370                                       
    318                                         <div class="photolist"></div>
    319                                        
    320                                         <h2><?php _e('Link Photo to following URL') ?></h2><?php _e('(leave blank to leave the photo unlinked)') ?>
    321                                         <div class="titlewrap">
    322                                         <input name="photo_link" id="photo_link" class="text" value="<?php echo attribute_escape($url);?>"/>
    323                                         </div>
    324                                        
    325                                         <small><?php _e('Click images to select:') ?></small>
    326                                         <div class="titlewrap">
    327                                         <div id="img_container">
    328                                         </div>
    329                                         </div>
    330                                        
    331                                        
    332                                         <h2><?php _e('Caption') ?></h2>
     371                                        <h2 id="content_type"><?php _e('Post') ?></h2>
    333372                                        <div class="editor-container">
    334                                                 <textarea name="content" id="photo_post_two" style="" class="mceEditor">
    335                                                 <?php echo $selection; ?>
    336                                                 &lt;p&gt;&lt;a href="<?php echo attribute_escape($url);?>"&gt;<?php echo $title;?>&lt;/a&gt; &lt;/p&gt;
    337                                                 </textarea>
    338                                         </div>
    339 
    340                                         <?php tag_div(); ?>
    341                                        
    342                                 </div>
    343                                         <?php category_div() ?>
    344                         </form>
    345 <?php
    346 exit;
    347 } elseif ( 'text' == $_GET['tab'] ) {
    348 ?>
    349                 <script type="text/javascript">
    350                 <?php press_this_js_init(); ?>
    351                 </script>
    352 
    353                   <form action="press-this.php?action=post" method="post" id="regular_form">
    354                                 <?php wp_nonce_field('press-this') ?>
    355                                 <input type="hidden" name="source" value="bookmarklet"/>
    356                                 <input type="hidden" name="post_type" value="regular"/>
    357                                 <div id="posting">
    358                                         <h2><?php _e('Title') ?></h2>
    359                                         <div class="titlewrap">
    360                                         <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
    361                                         </div>
    362                                        
    363                                         <h2><?php _e('Post') ?></h2>
    364                                         <div class="editor-container">
    365                                                 <textarea name="content" id="regular_post_two" style="height:170px;width:100%;" class="mceEditor">
    366                                                 <?php echo $selection; ?>
    367                                                 &lt;p&gt;&lt;a href="<?php echo $url;?>"&gt;<?php echo $title;?>&lt;/a&gt; &lt;/p&gt;
    368                                                 </textarea>
    369                                         </div>       
    370                                         <?php tag_div(); ?>
    371        
    372                                 </div>
    373                                 <?php category_div() ?>
    374                          </form>
    375 <?php
    376 exit;
    377 } elseif ( 'quote' == $_GET['tab'] ) {
    378 ?>
    379                 <script type="text/javascript">
    380                 <?php press_this_js_init(); ?>
    381                 </script>
    382 
    383                         <form action="press-this.php?action=post" method="post" id="quote_form">
    384                                 <?php wp_nonce_field('press-this') ?>
    385                                 <input type="hidden" name="source" value="bookmarklet"/>
    386                                 <input type="hidden" name="post_type" value="quote"/>
    387                                 <div id="posting">
    388                                         <h2><?php _e('Title') ?></h2>
    389                                         <div class="titlewrap">
    390                                         <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape(sprintf(__('Quote by %s'), $title)); ?>"/>
    391                                         </div>
    392                                        
    393                                         <h2><?php _e('Quote') ?></h2>
    394                                         <div class="editor-container">
    395                                                 <textarea name="content" id="quote_post_one" style="height:130px;width:100%;" class="mceEditor">
     373                                                <textarea name="content" id="content" style="height:170px;width:100%;" class="mceEditor">
    396374                                                <?php echo $selection; ?>
    397375                                                </textarea>
    398376                                        </div>
    399 
    400                                         <h2><?php _e('Source'); ?> <span class="optional"><?php _e('(optional)'); ?></span></h2>
    401                                         <div class="editor-container">
    402                                                 <textarea name="content2" id="quote_post_two" style="height:130px;width:100%;" class="mceEditor">
    403                                                 &lt;p&gt;&lt;cite&gt;&lt;a href="<?php echo $url;?>"&gt;<?php echo $title;?>&lt;/a&gt;&lt;/cite&gt; &lt;/p&gt;
    404                                                 </textarea>
    405                                         </div>
    406 
     377                                       
    407378                                        <?php tag_div(); ?>
     379                                       
    408380                                </div>
    409                                 <?php category_div() ?>
    410                         </form>
    411 <?php
    412 exit;
    413 } elseif ( 'video' == $_GET['tab'] ) {
    414 ?>
    415                 <script type="text/javascript">
    416                 <?php press_this_js_init(); ?>
    417                 </script>
    418 
    419                         <form action="press-this.php?action=post" method="post" id="video_form">
    420                                 <?php wp_nonce_field('press-this') ?>
    421                                 <input type="hidden" name="source" value="bookmarklet"/>
    422                                 <input type="hidden" name="post_type" value="video"/>
    423                                 <div id="posting">
    424                                
    425                                         <h2><?php _e('Video Title') ?></h2>
    426                                 <div class="titlewrap">
    427                                         <input name="post_title" id="post_title" class="text" value="<?php echo attribute_escape($title);?>"/>
    428                                 </div>
    429                                         <?php
     381                                <?php category_div(); ?>
     382                        </form>         
     383                                        <?php /*
    430384                                        if ( preg_match("/youtube\.com\/watch/i", $url) ) {
    431385                                                list($domain, $video_id) = split("v=", $url);
     
    437391                                        <h2><?php _e('Embed Code') ?></h2>
    438392                                        <textarea name="content" id="video_post_one" style="height:80px;width:100%;"></textarea>
    439                                         <?php } ?>
    440 
    441                                         <h2><?php _e('Caption <span class="optional">(optional)</span>') ?></h2>
    442 
    443                                         <div class="editor-container">
    444                                                 <textarea name="content2" id="video_post_two" style="height:130px;width:100%;" class="mceEditor">
    445                                                 <?php echo $selection; ?>
    446                                                 &lt;p&gt;&lt;a href="<?php echo $url; ?>"&gt;<?php echo $title; ?>&lt;/a&gt; &lt;/p&gt;
    447                                                 </textarea>
    448                                         </div>
    449 
    450                                         <?php tag_div(); ?>
    451                                 </div>
    452                                 <?php category_div() ?>
    453                         </form>
    454 <?php
    455 exit;
    456 }
    457 ?>                     
     393                                        <?php } */?>
     394                                       
     395</body>
     396</html>
Note: See TracChangeset for help on using the changeset viewer.