Make WordPress Core

Ticket #7654: user-settings.patch

File user-settings.patch, 19.2 KB (added by azaozz, 17 years ago)
  • wp-admin/edit-form-advanced.php

     
    486486
    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>
    492492
  • wp-admin/edit-page-form.php

     
    358358
    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>
    364364<?php the_editor($post->post_content); ?>
  • wp-admin/js/editor.js

     
    1 wpEditorInit = function() {
    2         var H;
    31
    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 };
    14 
    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);
    2431
     
    8491
    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() ) {
    94101                        ta.style.color = '#fff';
     
    97104                        edCloseAllTags(); // :-(
    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);
    104112
    105113                        if ( ed ) ed.show();
    106114                        else tinyMCE.execCommand("mceAddControl", false, id);
    107115
    108                         this.wpSetDefaultEditor('tinymce');
     116                        setUserSetting( 'editor', 'tinymce' );
    109117                } else {
    110118                        this.edToggle(H, P);
    111119                        ta.style.height = ed.getContentAreaContainer().offsetHeight + 6 + 'px';
     
    115123
    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        },
    129139
     
    135145                A.onclick = null;
    136146        },
    137147
    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();
    149         },
    150 
    151148        wpautop : function(pee) {
    152149                var blocklist = 'table|thead|tfoot|caption|colgroup|tbody|tr|td|th|div|dl|dd|dt|ul|ol|li|pre|select|form|blockquote|address|math|p|h[1-6]';
    153150
  • wp-admin/js/user-settings.js

     
     1
     2wpCookies = {
     3// The following functions are from Cookie.js class in TinyMCE, Moxiecode, used under LGPL.
     4
     5        each : function(o, cb, s) {
     6                var n, l;
     7
     8                if (!o)
     9                        return 0;
     10
     11                s = s || o;
     12
     13                if (typeof(o.length) != 'undefined') {
     14                        for (n=0, l = o.length; n<l; n++) {
     15                                if (cb.call(s, o[n], n, o) === false)
     16                                        return 0;
     17                        }
     18                } else {
     19                        for (n in o) {
     20                                if (o.hasOwnProperty(n)) {
     21                                        if (cb.call(s, o[n], n, o) === false)
     22                                                return 0;
     23                                }
     24                        }
     25                }
     26                return 1;
     27        },
     28
     29        getHash : function(n) {
     30                var v = this.get(n), h;
     31
     32                if (v) {
     33                        this.each(v.split('&'), function(v) {
     34                                v = v.split('=');
     35                                h = h || {};
     36                                h[v[0]] = v[1];
     37                        });
     38                }
     39                return h;
     40        },
     41
     42        setHash : function(n, v, e, p, d, s) {
     43                var o = '';
     44
     45                this.each(v, function(v, k) {
     46                        o += (!o ? '' : '&') + k + '=' + v;
     47                });
     48
     49                this.set(n, o, e, p, d, s);
     50        },
     51
     52        get : function(n) {
     53                var c = document.cookie, e, p = n + "=", b;
     54
     55                if (!c)
     56                        return;
     57
     58                b = c.indexOf("; " + p);
     59
     60                if (b == -1) {
     61                        b = c.indexOf(p);
     62
     63                        if (b != 0)
     64                                return null;
     65                } else
     66                        b += 2;
     67
     68                e = c.indexOf(";", b);
     69
     70                if (e == -1)
     71                        e = c.length;
     72
     73                return decodeURIComponent(c.substring(b + p.length, e));
     74        },
     75
     76        set : function(n, v, e, p, d, s) {
     77                document.cookie = n + "=" + encodeURIComponent(v) +
     78                        ((e) ? "; expires=" + e.toGMTString() : "") +
     79                        ((p) ? "; path=" + p : "") +
     80                        ((d) ? "; domain=" + d : "") +
     81                        ((s) ? "; secure" : "");
     82        },
     83
     84        remove : function(n, p) {
     85                var d = new Date();
     86
     87                d.setTime(d.getTime() - 1000);
     88
     89                this.set(n, '', d, p, d);
     90        }
     91};
     92
     93// Returns the value as string. Second arg or empty string is returned when value is not set.
     94function getUserSetting( name, def ) {
     95        var o = getAllUserSettings();
     96
     97        if ( o.hasOwnProperty(name) )
     98                return o[name];
     99
     100        if ( typeof def != 'undefined' )
     101                return def;
     102
     103        return '';
     104}
     105
     106// Both name and value must be only ASCII letters, numbers or underscore
     107// and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text.
     108function setUserSetting( name, value, del ) {
     109        var c = 'wp-settings-'+userSettings.uid, o = wpCookies.getHash(c) || {}, d = new Date();
     110        var n = name.toString().replace(/[^A-Za-z0-9_]/, ''), v = value.toString().replace(/[^A-Za-z0-9_]/, '');
     111
     112        if ( del ) delete o[n];
     113        else o[n] = v;
     114
     115        d.setTime( d.getTime() + 31536000000 );
     116        p = userSettings.url;
     117
     118        wpCookies.setHash(c, o, d, p );
     119        wpCookies.set('wp-settings-time-'+userSettings.uid, userSettings.time, d, p );
     120}
     121
     122function deleteUserSetting( name ) {
     123        setUserSetting( name, '', 1 );
     124}
     125
     126// Returns all settings as js object.
     127function getAllUserSettings() {
     128        return wpCookies.getHash('wp-settings-'+userSettings.uid) || {};
     129}
  • wp-includes/default-filters.php

     
    192192add_action('template_redirect', 'wp_old_slug_redirect');
    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?>
  • wp-includes/functions.php

     
    644644}
    645645
    646646/**
     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);
     772}
     773
     774/**
    647775 * Serialize data, if needed.
    648776 *
    649777 * @since 2.0.5
  • wp-includes/general-template.php

     
    942942function wp_default_editor() {
    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
    949949}
  • wp-includes/js/tinymce/plugins/wordpress/editor_plugin.js

     
    1414                        var moreHTML = '<img src="' + url + '/img/trans.gif" class="mceWPmore mceItemNoResize" title="'+ed.getLang('wordpress.wp_more_alt')+'" />';
    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
    2020                        // Hides the specified toolbar and resizes the iframe
     
    4444                                });
    4545
    4646                        ed.addCommand('WP_Adv', function() {
    47                                 var id = ed.controlManager.get(tbId).id, cm = ed.controlManager, cook = tinymce.util.Cookie, date;
     47                                var id = ed.controlManager.get(tbId).id, cm = ed.controlManager;
    4848
    49                                 date = new Date();
    50                                 date.setTime(date.getTime()+(10*365*24*60*60*1000));
    51 
    5249                                if (DOM.isHidden(id)) {
    5350                                        cm.setActive('wp_adv', 1);
    5451                                        DOM.show(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);
    6057                                        DOM.hide(id);
    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                        });
    6663
     
    9491                                title : 'wordpress.add_media',
    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' );
     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                                        }
    9999                                }
    100100                        });
    101 
     101/*
    102102                        ed.addButton('add_image', {
    103103                                title : 'wordpress.add_image',
    104104                                image : url + '/img/image.gif',
     
    125125                                        tinymce.DOM.setStyle( ['TB_overlay','TB_window','TB_load'], 'z-index', '999999' );
    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
    136136                        // Add class "alignleft", "alignright" and "aligncenter" when selecting align for images.
  • wp-includes/js/tinymce/tiny_mce_config.php

     
    134134// TinyMCE init settings
    135135$initArray = array (
    136136        'mode' => 'none',
    137         'onpageload' => 'wpEditorInit',
     137        'onpageload' => 'switchEditors.edInit',
    138138        'width' => '100%',
    139139        'theme' => 'advanced',
    140140        'skin' => 'wp_theme',
     
    214214// Setup cache info
    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 )
    220220                $cacheKey .= $v;
  • wp-includes/script-loader.php

     
    3535 * @param object $scripts WP_Scripts object.
    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
    4650        $scripts->add( 'quicktags', '/wp-includes/js/quicktags.js', false, '20080823' );
     
    6569        $scripts->add( 'editor_functions', '/wp-admin/js/editor.js', false, '20080823' );
    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
    7175        $scripts->add( 'prototype', '/wp-includes/js/prototype.js', false, '1.6');
     
    242246                ) );
    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}
    247258
     
    334345 * @since 2.5.0
    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,
    340350                'previewPageText' => __('Preview this Page'),