Make WordPress Core

Changeset 8784


Ignore:
Timestamp:
08/31/2008 06:34:43 AM (18 years ago)
Author:
azaozz
Message:

Saving/restoring the user interface state, see #7654

Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-form-advanced.php

    r8767 r8784  
    487487<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
    488488
    489 <div id="add-media-button"><a href="<?php echo clean_url( admin_url( 'media-upload.php?post_id=' . ( $post_ID ? $post_ID : $temp_ID ) . '&amp;type=image&amp;TB_iframe=true' ) ); ?>" class="thickbox button"><?php _e( 'Add Media' ); ?></a></div>
     489<div id="add-media-button"><a id="add-media-link" href="<?php echo clean_url( admin_url( 'media-upload.php?post_id=' . ( $post_ID ? $post_ID : $temp_ID ) . '&amp;type=image&amp;TB_iframe=true' ) ); ?>" class="thickbox button"><?php _e( 'Add Media' ); ?></a></div>
    490490
    491491<h3><?php _e('Post') ?></h3>
  • trunk/wp-admin/edit-page-form.php

    r8767 r8784  
    359359<div id="<?php echo user_can_richedit() ? 'postdivrich' : 'postdiv'; ?>" class="postarea">
    360360
    361 <div id="add-media-button"><a href="<?php echo clean_url( admin_url( 'media-upload.php?post_id=' . ( $post_ID ? $post_ID : $temp_ID ) . '&amp;type=image&amp;TB_iframe=true' ) ); ?>" class="thickbox button"><?php _e( 'Add Media' ); ?></a></div>
     361<div id="add-media-button"><a id="add-media-link" href="<?php echo clean_url( admin_url( 'media-upload.php?post_id=' . ( $post_ID ? $post_ID : $temp_ID ) . '&amp;type=image&amp;TB_iframe=true' ) ); ?>" class="thickbox button"><?php _e( 'Add Media' ); ?></a></div>
    362362
    363363<h3><?php _e('Page') ?></h3>
  • trunk/wp-admin/js/editor.js

    r8720 r8784  
    1 wpEditorInit = function() {
    2         var H;
    3 
    4         // Activate tinyMCE if it's the user's default editor
    5         if ( ( 'undefined' == typeof wpTinyMCEConfig ) || 'tinymce' == wpTinyMCEConfig.defaultEditor ) {
    6                 try { document.getElementById('editorcontainer').style.padding = '0px'; } catch(e){};
    7                 try { document.getElementById("quicktags").style.display = "none"; } catch(e){};
    8                 tinyMCE.execCommand("mceAddControl", false, "content");
    9         } else {
    10                 if ( H = tinymce.util.Cookie.getHash("TinyMCE_content_size") )
    11                         try { document.getElementById('content').style.height = H.ch - 30 + 'px'; } catch(e){};
    12         }
    13 };
    141
    152switchEditors = {
    163
     4        I : function(e) {
     5                return document.getElementById(e);
     6        },
     7
     8        edInit : function() {
     9                var h = tinymce.util.Cookie.getHash("TinyMCE_content_size"), H = this.I('edButtonHTML'), P = this.I('edButtonPreview');
     10
     11                // Activate TinyMCE if it's the user's default editor
     12                if ( getUserSetting( 'editor', 'tinymce' ) == 'tinymce' ) {
     13                        try { P.onclick = ''; P.className = 'active'; } catch(e){};
     14                        try { this.I('editorcontainer').style.padding = '0px'; } catch(e){};
     15                        try { this.I("quicktags").style.display = "none"; } catch(e){};
     16                        tinyMCE.execCommand("mceAddControl", false, "content");
     17                } else {
     18                        try { H.onclick = ''; H.className = 'active'; } catch(e){};
     19                        if ( h )
     20                                try { this.I('content').style.height = h.ch - 30 + 'px'; } catch(e){};
     21                }
     22        },
     23       
    1724        saveCallback : function(el, content, body) {
    1825
    19                 document.getElementById(el).style.color = '#fff';
     26                this.I(el).style.color = '#fff';
    2027                if ( tinyMCE.activeEditor.isHidden() )
    21                         content = document.getElementById(el).value;
     28                        content = this.I(el).value;
    2229                else
    2330                        content = this.pre_wpautop(content);
     
    8592        go : function(id) {
    8693                var ed = tinyMCE.get(id);
    87                 var qt = document.getElementById('quicktags');
    88                 var H = document.getElementById('edButtonHTML');
    89                 var P = document.getElementById('edButtonPreview');
    90                 var ta = document.getElementById(id);
    91                 var ec = document.getElementById('editorcontainer');
     94                var qt = this.I('quicktags');
     95                var H = this.I('edButtonHTML');
     96                var P = this.I('edButtonPreview');
     97                var ta = this.I(id);
     98                var ec = (ta.parentNode && ta.parentNode.nodeName == 'DIV') ? ta.parentNode : '';
    9299
    93100                if ( ! ed || ed.isHidden() ) {
     
    98105
    99106                        qt.style.display = 'none';
    100                         ec.style.padding = '0px';
    101107                        ta.style.padding = '0px';
     108                        if ( ec )
     109                                ec.style.padding = '0px';
    102110
    103111                        ta.value = this.wpautop(ta.value);
     
    106114                        else tinyMCE.execCommand("mceAddControl", false, id);
    107115
    108                         this.wpSetDefaultEditor('tinymce');
     116                        setUserSetting( 'editor', 'tinymce' );
    109117                } else {
    110118                        this.edToggle(H, P);
     
    116124                        if ( tinymce.isIE6 ) {
    117125                                ta.style.width = '98%';
    118                                 ec.style.padding = '0px';
     126                                if ( ec )
     127                                        ec.style.padding = '0px';
    119128                                ta.style.padding = '6px';
    120129                        } else {
    121130                                ta.style.width = '100%';
    122                                 ec.style.padding = '6px';
     131                                if ( ec )
     132                                        ec.style.padding = '6px';
    123133                        }
    124134
    125135                        ta.style.color = '';
    126                         this.wpSetDefaultEditor('html');
     136                        setUserSetting( 'editor', 'html' );
    127137                }
    128138        },
     
    134144                B.onclick = A.onclick;
    135145                A.onclick = null;
    136         },
    137 
    138         wpSetDefaultEditor : function(editor) {
    139                 try {
    140                         editor = escape( editor.toString() );
    141                 } catch(err) {
    142                         editor = 'tinymce';
    143                 }
    144 
    145                 var userID = document.getElementById('user-id');
    146                 var date = new Date();
    147                 date.setTime(date.getTime()+(10*365*24*60*60*1000));
    148                 document.cookie = "wordpress_editor_" + userID.value + "=" + editor + "; expires=" + date.toGMTString();
    149146        },
    150147
  • trunk/wp-includes/default-filters.php

    r8213 r8784  
    193193add_action('edit_post', 'wp_check_for_changed_slugs');
    194194add_action('edit_form_advanced', 'wp_remember_old_slug');
     195add_action('init', 'wp_user_settings', 9);
    195196
    196197?>
  • trunk/wp-includes/functions.php

    r8770 r8784  
    642642        }
    643643        return true;
     644}
     645
     646/**
     647 * Saves and restores user interface settings stored in a cookie.
     648 *
     649 * @package WordPress
     650 * @subpackage Option
     651 * @since 2.7.0
     652 *
     653 * Checks if the current user-settings cookie is updated and stores it.
     654 * When no cookie exists (different browser used), adds the last saved cookie restoring the settings.
     655 */
     656function wp_user_settings() {
     657
     658        if ( ! is_admin() )
     659                return;
     660
     661        if ( ! $user = wp_get_current_user() )
     662                return;
     663
     664        $settings = get_user_option( 'user-settings', $user->ID );
     665
     666        if ( isset($_COOKIE['wp-settings-'.$user->ID]) ) {
     667                $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-'.$user->ID] );
     668
     669                if ( ! empty($cookie) && strpos($cookie, '=') ) {
     670                        if ( $cookie == $settings )
     671                                return;
     672
     673                        $last_time = (int) get_user_option( 'user-settings-time', $user->ID );
     674                        $saved = isset($_COOKIE['wp-settings-time-'.$user->ID]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-'.$user->ID] ) : 0;
     675
     676                        if ( $saved > $last_time ) {
     677                                update_user_option( $user->ID, 'user-settings', $cookie );
     678                                update_user_option( $user->ID, 'user-settings-time', time() - 5 );
     679                                return;
     680                        }
     681                }
     682        }
     683
     684        setcookie('wp-settings-'.$user->ID, $settings, time() + 31536000, SITECOOKIEPATH);
     685        setcookie('wp-settings-time-'.$user->ID, time(), time() + 31536000, SITECOOKIEPATH);
     686}
     687
     688/**
     689 * Retrieve user interface setting value based on setting name.
     690 *
     691 * @package WordPress
     692 * @subpackage Option
     693 * @since 2.7.0
     694 *   
     695 * @param string $name The name of the setting.
     696 * @param string $default Optional default value to return when $name is not set.
     697 * @return mixed the last saved user setting or the default value/false if it doesn't exist.
     698 */
     699function get_user_setting( $name, $default = false ) {
     700
     701        $arr = get_all_user_settings();
     702
     703        return isset($arr[$name]) ? $arr[$name] : $default;
     704}
     705
     706/**
     707 * Delete user interface settings.
     708 *
     709 * @package WordPress
     710 * @subpackage Option
     711 * @since 2.7.0
     712 *
     713 * Deleting settings would reset them to the defaults.
     714 *
     715 * @param mixed $names The name or array of names of the setting to be deleted.
     716 */
     717function delete_user_setting( $names ) {
     718        global $current_user;
     719
     720        $arr = get_all_user_settings();
     721        $names = (array) $names;
     722
     723        foreach ( $names as $name ) {
     724                if ( isset($arr[$name]) ) {
     725                        unset($arr[$name]);
     726                        $settings = '';
     727                }
     728        }
     729
     730        if ( isset($settings) ) {
     731                foreach ( $arr as $k => $v )
     732                        $settings .= $k . '=' . $v . '&';
     733
     734                $settings = rtrim($settings, '&');
     735
     736                update_user_option( $current_user->ID, 'user-settings', $settings );
     737                setcookie('wp-settings-'.$current_user->ID, $settings, time() + 31536000, SITECOOKIEPATH);
     738        }
     739}
     740
     741/**
     742 * Retrieve all user interface settings.
     743 *
     744 * @package WordPress
     745 * @subpackage Option
     746 * @since 2.7.0
     747 *
     748 * @return array the last saved user settings or empty array.
     749 */
     750function get_all_user_settings() {
     751        if ( ! $user = wp_get_current_user() )
     752                return array();
     753
     754        if ( isset($_COOKIE['wp-settings-'.$user->ID]) ) {
     755                $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-'.$user->ID] );
     756
     757                if ( $cookie && strpos($cookie, '=') ) { // the '=' cannot be 1st char
     758                        parse_str($cookie, $arr);
     759                        return $arr;
     760                }
     761        }
     762
     763        return array();
     764}
     765
     766function delete_all_user_settings() {
     767        if ( ! $user = wp_get_current_user() )
     768                return;
     769
     770        delete_usermeta( $user->ID, 'user-settings' );
     771        setcookie('wp-settings-'.$user->ID, ' ', time() - 31536000, SITECOOKIEPATH);
    644772}
    645773
  • trunk/wp-includes/general-template.php

    r8721 r8784  
    943943        $r = user_can_richedit() ? 'tinymce' : 'html'; // defaults
    944944        if ( $user = wp_get_current_user() ) { // look for cookie
    945                 if ( isset($_COOKIE['wordpress_editor_' . $user->ID]) && in_array($_COOKIE['wordpress_editor_' . $user->ID], array('tinymce', 'html', 'test') ) )
    946                         $r = $_COOKIE['wordpress_editor_' . $user->ID];
     945                $ed = get_user_setting('editor', 'tinymce');
     946                $r = ( in_array($ed, array('tinymce', 'html', 'test') ) ) ? $ed : $r;
    947947        }
    948948        return apply_filters( 'wp_default_editor', $r ); // filter
  • trunk/wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js

    r8260 r8784  
    1515                        var nextpageHTML = '<img src="' + url + '/img/trans.gif" class="mceWPnextpage mceItemNoResize" title="'+ed.getLang('wordpress.wp_page_alt')+'" />';
    1616
    17                         if ( tinymce.util.Cookie.get('kitchenSink') == '1' )
     17                        if ( getUserSetting('hidetb', '0') == '1' )
    1818                                ed.settings.wordpress_adv_hidden = 0;
    1919
     
    4545
    4646                        ed.addCommand('WP_Adv', function() {
    47                                 var id = ed.controlManager.get(tbId).id, cm = ed.controlManager, cook = tinymce.util.Cookie, date;
    48 
    49                                 date = new Date();
    50                                 date.setTime(date.getTime()+(10*365*24*60*60*1000));
     47                                var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
    5148
    5249                                if (DOM.isHidden(id)) {
     
    5552                                        t._resizeIframe(ed, tbId, -28);
    5653                                        ed.settings.wordpress_adv_hidden = 0;
    57                                         cook.set('kitchenSink', '1', date);
     54                                        setUserSetting('hidetb', '1');
    5855                                } else {
    5956                                        cm.setActive('wp_adv', 0);
     
    6158                                        t._resizeIframe(ed, tbId, 28);
    6259                                        ed.settings.wordpress_adv_hidden = 1;
    63                                         cook.set('kitchenSink', '0', date);
     60                                        setUserSetting('hidetb', '0');
    6461                                }
    6562                        });
     
    9592                                image : url + '/img/media.gif',
    9693                                onclick : function() {
    97                                         tb_show('', tinymce.DOM.get('add_media').href);
    98                                         tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
    99                                 }
    100                         });
    101 
     94                                        var a = tinymce.DOM.get('add-media-link');
     95                                        if ( a ) {
     96                                                tb_show('', a.href);
     97                                                tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
     98                                        }
     99                                }
     100                        });
     101/*
    102102                        ed.addButton('add_image', {
    103103                                title : 'wordpress.add_image',
     
    126126                                }
    127127                        });
    128 
     128*/
    129129                        // Add Media buttons to fullscreen
    130130                        ed.onBeforeExecCommand.add(function(ed, cmd, ui, val) {
    131131                                if ( 'mceFullScreen' != cmd ) return;
    132132                                if ( 'mce_fullscreen' != ed.id )
    133                                         ed.settings.theme_advanced_buttons1 += ',|,add_image,add_video,add_audio,add_media';
     133                                        ed.settings.theme_advanced_buttons1 += ',|,add_media';
    134134                        });
    135135
  • trunk/wp-includes/js/tinymce/tiny_mce_config.php

    r8686 r8784  
    135135$initArray = array (
    136136        'mode' => 'none',
    137         'onpageload' => 'wpEditorInit',
     137        'onpageload' => 'switchEditors.edInit',
    138138        'width' => '100%',
    139139        'theme' => 'advanced',
     
    215215if ( $disk_cache ) {
    216216
    217         $cacheKey = apply_filters('tiny_mce_version', '20080731');
     217        $cacheKey = apply_filters('tiny_mce_version', '20080830');
    218218
    219219        foreach ( $initArray as $v )
  • trunk/wp-includes/script-loader.php

    r8782 r8784  
    3636 */
    3737function wp_default_scripts( &$scripts ) {
     38        global $current_user;
     39       
    3840        if (!$guessurl = site_url())
    3941                $guessurl = wp_guess_url();
     42       
     43        $userid = isset($current_user) ? $current_user->ID : 0;
    4044        $scripts->base_url = $guessurl;
    4145        $scripts->default_version = get_bloginfo( 'version' );
    4246
    43         $scripts->add( 'common', '/wp-admin/js/common.js', array('jquery'), '20080318' );
     47        $scripts->add( 'common', '/wp-admin/js/common.js', array('jquery', 'user-settings'), '20080318' );
    4448        $scripts->add( 'sack', '/wp-includes/js/tw-sack.js', false, '1.6.1' );
    4549
     
    6670
    6771        // Modify this version when tinyMCE plugins are changed.
    68         $mce_version = apply_filters('tiny_mce_version', '20080730');
     72        $mce_version = apply_filters('tiny_mce_version', '20080830');
    6973        $scripts->add( 'tiny_mce', '/wp-includes/js/tinymce/tiny_mce_config.php', array('editor_functions'), $mce_version );
    7074
     
    243247
    244248                $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array('jquery'), '1.2' );
     249               
     250                $scripts->add( 'user-settings', '/wp-admin/js/user-settings.js', array(), '20080829' );
     251                $scripts->localize( 'user-settings', 'userSettings', array(
     252                        'url' => SITECOOKIEPATH,
     253                        'uid' => $userid,
     254                        'time' => time()
     255                ) );
    245256        }
    246257}
     
    335346 */
    336347function wp_just_in_time_script_localization() {
    337         wp_localize_script( 'tiny_mce', 'wpTinyMCEConfig', array( 'defaultEditor' => wp_default_editor() ) );
    338348        wp_localize_script( 'autosave', 'autosaveL10n', array(
    339349                'autosaveInterval' => AUTOSAVE_INTERVAL,
Note: See TracChangeset for help on using the changeset viewer.