Edit File by line
/home/barbar84/public_h.../wp-inclu.../js
File: utils.js
/**
[0] Fix | Delete
* Cookie functions.
[1] Fix | Delete
*
[2] Fix | Delete
* @output wp-includes/js/utils.js
[3] Fix | Delete
*/
[4] Fix | Delete
[5] Fix | Delete
/* global userSettings, getAllUserSettings, wpCookies, setUserSetting */
[6] Fix | Delete
/* exported getUserSetting, setUserSetting, deleteUserSetting */
[7] Fix | Delete
[8] Fix | Delete
window.wpCookies = {
[9] Fix | Delete
// The following functions are from Cookie.js class in TinyMCE 3, Moxiecode, used under LGPL.
[10] Fix | Delete
[11] Fix | Delete
each: function( obj, cb, scope ) {
[12] Fix | Delete
var n, l;
[13] Fix | Delete
[14] Fix | Delete
if ( ! obj ) {
[15] Fix | Delete
return 0;
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
scope = scope || obj;
[19] Fix | Delete
[20] Fix | Delete
if ( typeof( obj.length ) !== 'undefined' ) {
[21] Fix | Delete
for ( n = 0, l = obj.length; n < l; n++ ) {
[22] Fix | Delete
if ( cb.call( scope, obj[n], n, obj ) === false ) {
[23] Fix | Delete
return 0;
[24] Fix | Delete
}
[25] Fix | Delete
}
[26] Fix | Delete
} else {
[27] Fix | Delete
for ( n in obj ) {
[28] Fix | Delete
if ( obj.hasOwnProperty(n) ) {
[29] Fix | Delete
if ( cb.call( scope, obj[n], n, obj ) === false ) {
[30] Fix | Delete
return 0;
[31] Fix | Delete
}
[32] Fix | Delete
}
[33] Fix | Delete
}
[34] Fix | Delete
}
[35] Fix | Delete
return 1;
[36] Fix | Delete
},
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Get a multi-values cookie.
[40] Fix | Delete
* Returns a JS object with the name: 'value' pairs.
[41] Fix | Delete
*/
[42] Fix | Delete
getHash: function( name ) {
[43] Fix | Delete
var cookie = this.get( name ), values;
[44] Fix | Delete
[45] Fix | Delete
if ( cookie ) {
[46] Fix | Delete
this.each( cookie.split('&'), function( pair ) {
[47] Fix | Delete
pair = pair.split('=');
[48] Fix | Delete
values = values || {};
[49] Fix | Delete
values[pair[0]] = pair[1];
[50] Fix | Delete
});
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
return values;
[54] Fix | Delete
},
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Set a multi-values cookie.
[58] Fix | Delete
*
[59] Fix | Delete
* 'values_obj' is the JS object that is stored. It is encoded as URI in wpCookies.set().
[60] Fix | Delete
*/
[61] Fix | Delete
setHash: function( name, values_obj, expires, path, domain, secure ) {
[62] Fix | Delete
var str = '';
[63] Fix | Delete
[64] Fix | Delete
this.each( values_obj, function( val, key ) {
[65] Fix | Delete
str += ( ! str ? '' : '&' ) + key + '=' + val;
[66] Fix | Delete
});
[67] Fix | Delete
[68] Fix | Delete
this.set( name, str, expires, path, domain, secure );
[69] Fix | Delete
},
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Get a cookie.
[73] Fix | Delete
*/
[74] Fix | Delete
get: function( name ) {
[75] Fix | Delete
var e, b,
[76] Fix | Delete
cookie = document.cookie,
[77] Fix | Delete
p = name + '=';
[78] Fix | Delete
[79] Fix | Delete
if ( ! cookie ) {
[80] Fix | Delete
return;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
b = cookie.indexOf( '; ' + p );
[84] Fix | Delete
[85] Fix | Delete
if ( b === -1 ) {
[86] Fix | Delete
b = cookie.indexOf(p);
[87] Fix | Delete
[88] Fix | Delete
if ( b !== 0 ) {
[89] Fix | Delete
return null;
[90] Fix | Delete
}
[91] Fix | Delete
} else {
[92] Fix | Delete
b += 2;
[93] Fix | Delete
}
[94] Fix | Delete
[95] Fix | Delete
e = cookie.indexOf( ';', b );
[96] Fix | Delete
[97] Fix | Delete
if ( e === -1 ) {
[98] Fix | Delete
e = cookie.length;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
return decodeURIComponent( cookie.substring( b + p.length, e ) );
[102] Fix | Delete
},
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Set a cookie.
[106] Fix | Delete
*
[107] Fix | Delete
* The 'expires' arg can be either a JS Date() object set to the expiration date (back-compat)
[108] Fix | Delete
* or the number of seconds until expiration
[109] Fix | Delete
*/
[110] Fix | Delete
set: function( name, value, expires, path, domain, secure ) {
[111] Fix | Delete
var d = new Date();
[112] Fix | Delete
[113] Fix | Delete
if ( typeof( expires ) === 'object' && expires.toGMTString ) {
[114] Fix | Delete
expires = expires.toGMTString();
[115] Fix | Delete
} else if ( parseInt( expires, 10 ) ) {
[116] Fix | Delete
d.setTime( d.getTime() + ( parseInt( expires, 10 ) * 1000 ) ); // Time must be in milliseconds.
[117] Fix | Delete
expires = d.toGMTString();
[118] Fix | Delete
} else {
[119] Fix | Delete
expires = '';
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
document.cookie = name + '=' + encodeURIComponent( value ) +
[123] Fix | Delete
( expires ? '; expires=' + expires : '' ) +
[124] Fix | Delete
( path ? '; path=' + path : '' ) +
[125] Fix | Delete
( domain ? '; domain=' + domain : '' ) +
[126] Fix | Delete
( secure ? '; secure' : '' );
[127] Fix | Delete
},
[128] Fix | Delete
[129] Fix | Delete
/**
[130] Fix | Delete
* Remove a cookie.
[131] Fix | Delete
*
[132] Fix | Delete
* This is done by setting it to an empty value and setting the expiration time in the past.
[133] Fix | Delete
*/
[134] Fix | Delete
remove: function( name, path, domain, secure ) {
[135] Fix | Delete
this.set( name, '', -1000, path, domain, secure );
[136] Fix | Delete
}
[137] Fix | Delete
};
[138] Fix | Delete
[139] Fix | Delete
// Returns the value as string. Second arg or empty string is returned when value is not set.
[140] Fix | Delete
window.getUserSetting = function( name, def ) {
[141] Fix | Delete
var settings = getAllUserSettings();
[142] Fix | Delete
[143] Fix | Delete
if ( settings.hasOwnProperty( name ) ) {
[144] Fix | Delete
return settings[name];
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
if ( typeof def !== 'undefined' ) {
[148] Fix | Delete
return def;
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
return '';
[152] Fix | Delete
};
[153] Fix | Delete
[154] Fix | Delete
/*
[155] Fix | Delete
* Both name and value must be only ASCII letters, numbers or underscore
[156] Fix | Delete
* and the shorter, the better (cookies can store maximum 4KB). Not suitable to store text.
[157] Fix | Delete
* The value is converted and stored as string.
[158] Fix | Delete
*/
[159] Fix | Delete
window.setUserSetting = function( name, value, _del ) {
[160] Fix | Delete
if ( 'object' !== typeof userSettings ) {
[161] Fix | Delete
return false;
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
var uid = userSettings.uid,
[165] Fix | Delete
settings = wpCookies.getHash( 'wp-settings-' + uid ),
[166] Fix | Delete
path = userSettings.url,
[167] Fix | Delete
secure = !! userSettings.secure;
[168] Fix | Delete
[169] Fix | Delete
name = name.toString().replace( /[^A-Za-z0-9_-]/g, '' );
[170] Fix | Delete
[171] Fix | Delete
if ( typeof value === 'number' ) {
[172] Fix | Delete
value = parseInt( value, 10 );
[173] Fix | Delete
} else {
[174] Fix | Delete
value = value.toString().replace( /[^A-Za-z0-9_-]/g, '' );
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
settings = settings || {};
[178] Fix | Delete
[179] Fix | Delete
if ( _del ) {
[180] Fix | Delete
delete settings[name];
[181] Fix | Delete
} else {
[182] Fix | Delete
settings[name] = value;
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
wpCookies.setHash( 'wp-settings-' + uid, settings, 31536000, path, '', secure );
[186] Fix | Delete
wpCookies.set( 'wp-settings-time-' + uid, userSettings.time, 31536000, path, '', secure );
[187] Fix | Delete
[188] Fix | Delete
return name;
[189] Fix | Delete
};
[190] Fix | Delete
[191] Fix | Delete
window.deleteUserSetting = function( name ) {
[192] Fix | Delete
return setUserSetting( name, '', 1 );
[193] Fix | Delete
};
[194] Fix | Delete
[195] Fix | Delete
// Returns all settings as JS object.
[196] Fix | Delete
window.getAllUserSettings = function() {
[197] Fix | Delete
if ( 'object' !== typeof userSettings ) {
[198] Fix | Delete
return {};
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
return wpCookies.getHash( 'wp-settings-' + userSettings.uid ) || {};
[202] Fix | Delete
};
[203] Fix | Delete
[204] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function