1 | /** This file is part of KCFinder project
|
---|
2 | *
|
---|
3 | * @desc Helper object
|
---|
4 | * @package KCFinder
|
---|
5 | * @version 2.51
|
---|
6 | * @author Pavel Tzonkov <pavelc@users.sourceforge.net>
|
---|
7 | * @copyright 2010, 2011 KCFinder Project
|
---|
8 | * @license http://www.opensource.org/licenses/gpl-2.0.php GPLv2
|
---|
9 | * @license http://www.opensource.org/licenses/lgpl-2.1.php LGPLv2
|
---|
10 | * @link http://kcfinder.sunhater.com
|
---|
11 | */
|
---|
12 |
|
---|
13 | var _ = function(id) {
|
---|
14 | return document.getElementById(id);
|
---|
15 | };
|
---|
16 |
|
---|
17 | _.nopx = function(val) {
|
---|
18 | return parseInt(val.replace(/^(\d+)px$/, "$1"));
|
---|
19 | };
|
---|
20 |
|
---|
21 | _.unselect = function() {
|
---|
22 | if (document.selection && document.selection.empty)
|
---|
23 | document.selection.empty() ;
|
---|
24 | else if (window.getSelection) {
|
---|
25 | var sel = window.getSelection();
|
---|
26 | if (sel && sel.removeAllRanges)
|
---|
27 | sel.removeAllRanges();
|
---|
28 | }
|
---|
29 | };
|
---|
30 |
|
---|
31 | _.selection = function(field, start, end) {
|
---|
32 | if (field.createTextRange) {
|
---|
33 | var selRange = field.createTextRange();
|
---|
34 | selRange.collapse(true);
|
---|
35 | selRange.moveStart('character', start);
|
---|
36 | selRange.moveEnd('character', end-start);
|
---|
37 | selRange.select();
|
---|
38 | } else if (field.setSelectionRange) {
|
---|
39 | field.setSelectionRange(start, end);
|
---|
40 | } else if (field.selectionStart) {
|
---|
41 | field.selectionStart = start;
|
---|
42 | field.selectionEnd = end;
|
---|
43 | }
|
---|
44 | field.focus();
|
---|
45 | };
|
---|
46 |
|
---|
47 | _.htmlValue = function(value) {
|
---|
48 | return value
|
---|
49 | .replace(/\&/g, "&")
|
---|
50 | .replace(/\"/g, """)
|
---|
51 | .replace(/\'/g, "'");
|
---|
52 | };
|
---|
53 |
|
---|
54 | _.htmlData = function(value) {
|
---|
55 | return value
|
---|
56 | .replace(/\&/g, "&")
|
---|
57 | .replace(/\</g, "<")
|
---|
58 | .replace(/\>/g, ">")
|
---|
59 | .replace(/\ /g, " ");
|
---|
60 | }
|
---|
61 |
|
---|
62 | _.jsValue = function(value) {
|
---|
63 | return value
|
---|
64 | .replace(/\\/g, "\\\\")
|
---|
65 | .replace(/\r?\n/, "\\\n")
|
---|
66 | .replace(/\"/g, "\\\"")
|
---|
67 | .replace(/\'/g, "\\'");
|
---|
68 | };
|
---|
69 |
|
---|
70 | _.basename = function(path) {
|
---|
71 | var expr = /^.*\/([^\/]+)\/?$/g;
|
---|
72 | return expr.test(path)
|
---|
73 | ? path.replace(expr, "$1")
|
---|
74 | : path;
|
---|
75 | };
|
---|
76 |
|
---|
77 | _.dirname = function(path) {
|
---|
78 | var expr = /^(.*)\/[^\/]+\/?$/g;
|
---|
79 | return expr.test(path)
|
---|
80 | ? path.replace(expr, "$1")
|
---|
81 | : '';
|
---|
82 | };
|
---|
83 |
|
---|
84 | _.inArray = function(needle, arr) {
|
---|
85 | if ((typeof arr == 'undefined') || !arr.length || !arr.push)
|
---|
86 | return false;
|
---|
87 | for (var i = 0; i < arr.length; i++)
|
---|
88 | if (arr[i] == needle)
|
---|
89 | return true;
|
---|
90 | return false;
|
---|
91 | };
|
---|
92 |
|
---|
93 | _.getFileExtension = function(filename, toLower) {
|
---|
94 | if (typeof(toLower) == 'undefined') toLower = true;
|
---|
95 | if (/^.*\.[^\.]*$/.test(filename)) {
|
---|
96 | var ext = filename.replace(/^.*\.([^\.]*)$/, "$1");
|
---|
97 | return toLower ? ext.toLowerCase(ext) : ext;
|
---|
98 | } else
|
---|
99 | return "";
|
---|
100 | };
|
---|
101 |
|
---|
102 | _.escapeDirs = function(path) {
|
---|
103 | var fullDirExpr = /^([a-z]+)\:\/\/([^\/^\:]+)(\:(\d+))?\/(.+)$/,
|
---|
104 | prefix = "";
|
---|
105 | if (fullDirExpr.test(path)) {
|
---|
106 | var port = path.replace(fullDirExpr, "$4");
|
---|
107 | prefix = path.replace(fullDirExpr, "$1://$2")
|
---|
108 | if (port.length)
|
---|
109 | prefix += ":" + port;
|
---|
110 | prefix += "/";
|
---|
111 | path = path.replace(fullDirExpr, "$5");
|
---|
112 | }
|
---|
113 |
|
---|
114 | var dirs = path.split('/');
|
---|
115 | var escapePath = '';
|
---|
116 | for (var i = 0; i < dirs.length; i++)
|
---|
117 | escapePath += encodeURIComponent(dirs[i]) + '/';
|
---|
118 |
|
---|
119 | return prefix + escapePath.substr(0, escapePath.length - 1);
|
---|
120 | };
|
---|
121 |
|
---|
122 | _.outerSpace = function(selector, type, mbp) {
|
---|
123 | if (!mbp) mbp = "mbp";
|
---|
124 | var r = 0;
|
---|
125 | if (/m/i.test(mbp)) {
|
---|
126 | var m = _.nopx($(selector).css('margin-' + type));
|
---|
127 | if (m) r += m;
|
---|
128 | }
|
---|
129 | if (/b/i.test(mbp)) {
|
---|
130 | var b = _.nopx($(selector).css('border-' + type + '-width'));
|
---|
131 | if (b) r += b;
|
---|
132 | }
|
---|
133 | if (/p/i.test(mbp)) {
|
---|
134 | var p = _.nopx($(selector).css('padding-' + type));
|
---|
135 | if (p) r += p;
|
---|
136 | }
|
---|
137 | return r;
|
---|
138 | };
|
---|
139 |
|
---|
140 | _.outerLeftSpace = function(selector, mbp) {
|
---|
141 | return _.outerSpace(selector, 'left', mbp);
|
---|
142 | };
|
---|
143 |
|
---|
144 | _.outerTopSpace = function(selector, mbp) {
|
---|
145 | return _.outerSpace(selector, 'top', mbp);
|
---|
146 | };
|
---|
147 |
|
---|
148 | _.outerRightSpace = function(selector, mbp) {
|
---|
149 | return _.outerSpace(selector, 'right', mbp);
|
---|
150 | };
|
---|
151 |
|
---|
152 | _.outerBottomSpace = function(selector, mbp) {
|
---|
153 | return _.outerSpace(selector, 'bottom', mbp);
|
---|
154 | };
|
---|
155 |
|
---|
156 | _.outerHSpace = function(selector, mbp) {
|
---|
157 | return (_.outerLeftSpace(selector, mbp) + _.outerRightSpace(selector, mbp));
|
---|
158 | };
|
---|
159 |
|
---|
160 | _.outerVSpace = function(selector, mbp) {
|
---|
161 | return (_.outerTopSpace(selector, mbp) + _.outerBottomSpace(selector, mbp));
|
---|
162 | };
|
---|
163 |
|
---|
164 | _.kuki = {
|
---|
165 | prefix: '',
|
---|
166 | duration: 356,
|
---|
167 | domain: '',
|
---|
168 | path: '',
|
---|
169 | secure: false,
|
---|
170 |
|
---|
171 | set: function(name, value, duration, domain, path, secure) {
|
---|
172 | name = this.prefix + name;
|
---|
173 | if (duration == null) duration = this.duration;
|
---|
174 | if (secure == null) secure = this.secure;
|
---|
175 | if ((domain == null) && this.domain) domain = this.domain;
|
---|
176 | if ((path == null) && this.path) path = this.path;
|
---|
177 | secure = secure ? true : false;
|
---|
178 |
|
---|
179 | var date = new Date();
|
---|
180 | date.setTime(date.getTime() + (duration * 86400000));
|
---|
181 | var expires = date.toGMTString();
|
---|
182 |
|
---|
183 | var str = name + '=' + value + '; expires=' + expires;
|
---|
184 | if (domain != null) str += '; domain=' + domain;
|
---|
185 | if (path != null) str += '; path=' + path;
|
---|
186 | if (secure) str += '; secure';
|
---|
187 |
|
---|
188 | return (document.cookie = str) ? true : false;
|
---|
189 | },
|
---|
190 |
|
---|
191 | get: function(name) {
|
---|
192 | name = this.prefix + name;
|
---|
193 | var nameEQ = name + '=';
|
---|
194 | var kukis = document.cookie.split(';');
|
---|
195 | var kuki;
|
---|
196 |
|
---|
197 | for (var i = 0; i < kukis.length; i++) {
|
---|
198 | kuki = kukis[i];
|
---|
199 | while (kuki.charAt(0) == ' ')
|
---|
200 | kuki = kuki.substring(1, kuki.length);
|
---|
201 |
|
---|
202 | if (kuki.indexOf(nameEQ) == 0)
|
---|
203 | return kuki.substring(nameEQ.length, kuki.length);
|
---|
204 | }
|
---|
205 |
|
---|
206 | return null;
|
---|
207 | },
|
---|
208 |
|
---|
209 | del: function(name) {
|
---|
210 | return this.set(name, '', -1);
|
---|
211 | },
|
---|
212 |
|
---|
213 | isSet: function(name) {
|
---|
214 | return (this.get(name) != null);
|
---|
215 | }
|
---|
216 | };
|
---|
217 |
|
---|
218 | _.md5 = function(string) {
|
---|
219 |
|
---|
220 | var RotateLeft = function(lValue, iShiftBits) {
|
---|
221 | return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
|
---|
222 | };
|
---|
223 |
|
---|
224 | var AddUnsigned = function(lX,lY) {
|
---|
225 | var lX4, lY4, lX8, lY8, lResult;
|
---|
226 | lX8 = (lX & 0x80000000);
|
---|
227 | lY8 = (lY & 0x80000000);
|
---|
228 | lX4 = (lX & 0x40000000);
|
---|
229 | lY4 = (lY & 0x40000000);
|
---|
230 | lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
|
---|
231 | if (lX4 & lY4)
|
---|
232 | return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
|
---|
233 | if (lX4 | lY4)
|
---|
234 | return (lResult & 0x40000000)
|
---|
235 | ? (lResult ^ 0xC0000000 ^ lX8 ^ lY8)
|
---|
236 | : (lResult ^ 0x40000000 ^ lX8 ^ lY8);
|
---|
237 | else
|
---|
238 | return (lResult ^ lX8 ^ lY8);
|
---|
239 | };
|
---|
240 |
|
---|
241 | var F = function(x, y, z) { return (x & y) | ((~x) & z); };
|
---|
242 | var G = function(x, y, z) { return (x & z) | (y & (~z)); };
|
---|
243 | var H = function(x, y, z) { return (x ^ y ^ z); };
|
---|
244 | var I = function(x, y, z) { return (y ^ (x | (~z))); };
|
---|
245 |
|
---|
246 | var FF = function(a, b, c, d, x, s, ac) {
|
---|
247 | a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
|
---|
248 | return AddUnsigned(RotateLeft(a, s), b);
|
---|
249 | };
|
---|
250 |
|
---|
251 | var GG = function(a, b, c, d, x, s, ac) {
|
---|
252 | a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
|
---|
253 | return AddUnsigned(RotateLeft(a, s), b);
|
---|
254 | };
|
---|
255 |
|
---|
256 | var HH = function(a, b, c, d, x, s, ac) {
|
---|
257 | a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
|
---|
258 | return AddUnsigned(RotateLeft(a, s), b);
|
---|
259 | };
|
---|
260 |
|
---|
261 | var II = function(a, b, c, d, x, s, ac) {
|
---|
262 | a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
|
---|
263 | return AddUnsigned(RotateLeft(a, s), b);
|
---|
264 | };
|
---|
265 |
|
---|
266 | var ConvertToWordArray = function(string) {
|
---|
267 | var lWordCount;
|
---|
268 | var lMessageLength = string.length;
|
---|
269 | var lNumberOfWords_temp1 = lMessageLength + 8;
|
---|
270 | var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
|
---|
271 | var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
|
---|
272 | var lWordArray = [lNumberOfWords - 1];
|
---|
273 | var lBytePosition = 0;
|
---|
274 | var lByteCount = 0;
|
---|
275 | while (lByteCount < lMessageLength) {
|
---|
276 | lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
---|
277 | lBytePosition = (lByteCount % 4) * 8;
|
---|
278 | lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
|
---|
279 | lByteCount++;
|
---|
280 | }
|
---|
281 | lWordCount = (lByteCount - (lByteCount % 4)) / 4;
|
---|
282 | lBytePosition = (lByteCount % 4) * 8;
|
---|
283 | lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
|
---|
284 | lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
|
---|
285 | lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
|
---|
286 | return lWordArray;
|
---|
287 | };
|
---|
288 |
|
---|
289 | var WordToHex = function(lValue) {
|
---|
290 | var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount;
|
---|
291 | for (lCount = 0; lCount <= 3; lCount++) {
|
---|
292 | lByte = (lValue >>> (lCount * 8)) & 255;
|
---|
293 | WordToHexValue_temp = "0" + lByte.toString(16);
|
---|
294 | WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2,2);
|
---|
295 | }
|
---|
296 | return WordToHexValue;
|
---|
297 | };
|
---|
298 |
|
---|
299 | var x = [];
|
---|
300 | var k, AA, BB, CC, DD, a, b, c, d;
|
---|
301 | var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
|
---|
302 | var S21 = 5, S22 = 9, S23 = 14, S24 = 20;
|
---|
303 | var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
|
---|
304 | var S41 = 6, S42 = 10, S43 = 15, S44 = 21;
|
---|
305 |
|
---|
306 | string = _.utf8encode(string);
|
---|
307 |
|
---|
308 | x = ConvertToWordArray(string);
|
---|
309 |
|
---|
310 | a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
|
---|
311 |
|
---|
312 | for (k = 0; k < x.length; k += 16) {
|
---|
313 | AA = a; BB = b; CC = c; DD = d;
|
---|
314 | a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
|
---|
315 | d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
|
---|
316 | c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
|
---|
317 | b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
|
---|
318 | a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
|
---|
319 | d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
|
---|
320 | c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
|
---|
321 | b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
|
---|
322 | a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
|
---|
323 | d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
|
---|
324 | c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
|
---|
325 | b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
|
---|
326 | a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
|
---|
327 | d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
|
---|
328 | c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
|
---|
329 | b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
|
---|
330 | a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
|
---|
331 | d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
|
---|
332 | c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
|
---|
333 | b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
|
---|
334 | a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
|
---|
335 | d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
|
---|
336 | c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
|
---|
337 | b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
|
---|
338 | a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
|
---|
339 | d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
|
---|
340 | c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
|
---|
341 | b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
|
---|
342 | a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
|
---|
343 | d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
|
---|
344 | c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
|
---|
345 | b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
|
---|
346 | a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
|
---|
347 | d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
|
---|
348 | c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
|
---|
349 | b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
|
---|
350 | a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
|
---|
351 | d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
|
---|
352 | c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
|
---|
353 | b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
|
---|
354 | a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
|
---|
355 | d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
|
---|
356 | c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
|
---|
357 | b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
|
---|
358 | a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
|
---|
359 | d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
|
---|
360 | c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
|
---|
361 | b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
|
---|
362 | a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
|
---|
363 | d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
|
---|
364 | c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
|
---|
365 | b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
|
---|
366 | a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
|
---|
367 | d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
|
---|
368 | c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
|
---|
369 | b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
|
---|
370 | a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
|
---|
371 | d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
|
---|
372 | c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
|
---|
373 | b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
|
---|
374 | a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
|
---|
375 | d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
|
---|
376 | c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
|
---|
377 | b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
|
---|
378 | a = AddUnsigned(a, AA);
|
---|
379 | b = AddUnsigned(b, BB);
|
---|
380 | c = AddUnsigned(c, CC);
|
---|
381 | d = AddUnsigned(d, DD);
|
---|
382 | }
|
---|
383 |
|
---|
384 | var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
|
---|
385 |
|
---|
386 | return temp.toLowerCase();
|
---|
387 | };
|
---|
388 |
|
---|
389 | _.utf8encode = function(string) {
|
---|
390 | string = string.replace(/\r\n/g,"\n");
|
---|
391 | var utftext = "";
|
---|
392 |
|
---|
393 | for (var n = 0; n < string.length; n++) {
|
---|
394 |
|
---|
395 | var c = string.charCodeAt(n);
|
---|
396 |
|
---|
397 | if (c < 128) {
|
---|
398 | utftext += String.fromCharCode(c);
|
---|
399 | } else if((c > 127) && (c < 2048)) {
|
---|
400 | utftext += String.fromCharCode((c >> 6) | 192);
|
---|
401 | utftext += String.fromCharCode((c & 63) | 128);
|
---|
402 | } else {
|
---|
403 | utftext += String.fromCharCode((c >> 12) | 224);
|
---|
404 | utftext += String.fromCharCode(((c >> 6) & 63) | 128);
|
---|
405 | utftext += String.fromCharCode((c & 63) | 128);
|
---|
406 | }
|
---|
407 |
|
---|
408 | }
|
---|
409 |
|
---|
410 | return utftext;
|
---|
411 | };
|
---|