Вход Регистрация
Файл: wordpress/wp-includes/js/utils.js
Строк: 189
<?php
/* global userSettings */
/* exported getUserSetting, setUserSetting, deleteUserSetting */
// utility functions

var wpCookies = {
// The following functions are from Cookie.js class in TinyMCE 3, Moxiecode, used under LGPL.

    
each: function( objcbscope ) {
        var 
nl;

        if ( ! 
obj ) {
            return 
0;
        }

        
scope scope || obj;

        if ( 
typeofobj.length ) !== 'undefined' ) {
            for ( 
0obj.lengthln++ ) {
                if ( 
cb.callscopeobj[n], nobj ) === false ) {
                    return 
0;
                }
            }
        } else {
            for ( 
n in obj ) {
                if ( 
obj.hasOwnProperty(n) ) {
                    if ( 
cb.callscopeobj[n], nobj ) === false ) {
                        return 
0;
                    }
                }
            }
        }
        return 
1;
    },

    
/**
     * Get a multi-values cookie.
     * Returns a JS object with the name: 'value' pairs.
     */
    
getHash: function( name ) {
        var 
cookie this.getname ), values;

        if ( 
cookie ) {
            
this.eachcookie.split('&'), function( pair ) {
                
pair pair.split('=');
                
values values || {};
                
values[pair[0]] = pair[1];
            });
        }

        return 
values;
    },

    
/**
     * Set a multi-values cookie.
     *
     * 'values_obj' is the JS object that is stored. It is encoded as URI in wpCookies.set().
     */
    
setHash: function( namevalues_objexpirespathdomainsecure ) {
        var 
str '';

        
this.eachvalues_obj, function( valkey ) {
            
str += ( ! str '' '&' ) + key '=' val;
        });

        
this.setnamestrexpirespathdomainsecure );
    },

    
/**
     * Get a cookie.
     */
    
get: function( name ) {
        var 
eb,
            
cookie document.cookie,
            
name '=';

        if ( ! 
cookie ) {
            return;
        }

        
cookie.indexOf'; ' );

        if ( 
=== -) {
            
cookie.indexOf(p);

            if ( 
!== ) {
                return 
null;
            }
        } else {
            
+= 2;
        }

        
cookie.indexOf';');

        if ( 
=== -) {
            
cookie.length;
        }

        return 
decodeURIComponentcookie.substringp.length) );
    },

    
/**
     * Set a cookie.
     *
     * The 'expires' arg can be either a JS Date() object set to the expiration date (back-compat)
     * or the number of seconds until expiration
     */
    
set: function( namevalueexpirespathdomainsecure ) {
        var 
= new Date();

        if ( 
typeofexpires ) === 'object' && expires.toGMTString ) {
            
expires expires.toGMTString();
        } else if ( 
parseIntexpires10 ) ) {
            
d.setTimed.getTime() + ( parseIntexpires10 ) * 1000 ) ); // time must be in miliseconds
            
expires d.toGMTString();
        } else {
            
expires '';
        }

        
document.cookie name '=' encodeURIComponentvalue ) +
            ( 
expires '; expires=' expires '' ) +
            ( 
path    '; path=' path       '' ) +
            ( 
domain  '; domain=' domain   '' ) +
            ( 
secure  '; secure'             '' );
    },

    
/**
     * Remove a cookie.
     *
     * This is done by setting it to an empty value and setting the expiration time in the past.
     */
    
remove: function( namepathdomainsecure ) {
        
this.setname'', -1000pathdomainsecure );
    }
};

// Returns the value as string. Second arg or empty string is returned when value is not set.
function getUserSettingnamedef ) {
    var 
settings getAllUserSettings();

    if ( 
settings.hasOwnPropertyname ) ) {
        return 
settings[name];
    }

    if ( 
typeof def !== 'undefined' ) {
        return 
def;
    }

    return 
'';
}

// Both name and value must be only ASCII letters, numbers or underscore
// and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text.
// The value is converted and stored as string.
function setUserSettingnamevalue_del ) {
    if ( 
'object' !== typeof userSettings ) {
        return 
false;
    }

    var 
uid userSettings.uid,
        
settings wpCookies.getHash'wp-settings-' uid ),
        
path userSettings.url,
        
secure = !! userSettings.secure;

    
name name.toString().replace( /[^A-Za-z0-9_]/, '' );

    if ( 
typeof value === 'number' ) {
        
value parseIntvalue10 );
    } else {
        
value value.toString().replace( /[^A-Za-z0-9_]/, '' );
    }

    
settings settings || {};

    if ( 
_del ) {
        
delete settings[name];
    } else {
        
settings[name] = value;
    }

    
wpCookies.setHash'wp-settings-' uidsettings31536000path''secure );
    
wpCookies.set'wp-settings-time-' uiduserSettings.time31536000path''secure );

    return 
name;
}

function 
deleteUserSettingname ) {
    return 
setUserSettingname'');
}

// Returns all settings as js object.
function getAllUserSettings() {
    if ( 
'object' !== typeof userSettings ) {
        return {};
    }

    return 
wpCookies.getHash'wp-settings-' userSettings.uid ) || {};
}
?>
Онлайн: 1
Реклама