lodlive.utils.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // a causa di un baco di opera e firefox implmento una funzione apposita per
  2. // settare la posizione dei background
  3. $.fn.setBackgroundPosition = function(pos) {
  4. var backPos = $.trim(this.css('background-position'));
  5. var hasString = backPos.indexOf('left') == -1 ? false : true;
  6. //added fix for chrome 25
  7. backPos = backPos.replace(/top/gi, '').replace(/left/gi, '');
  8. backPos = $.trim(backPos.replace(/ /g, ' '));
  9. try {
  10. var backPosArray = backPos.split(" ");
  11. if (pos.x || pos.x == 0) {
  12. backPosArray[0] = pos.x + 'px';
  13. }
  14. if (pos.y || pos.y == 0) {
  15. backPosArray[1] = pos.y + 'px';
  16. }
  17. if (hasString) {
  18. backPos = "left " + backPosArray[0] + " top " + backPosArray[1];
  19. } else {
  20. backPos = backPosArray[0] + " " + backPosArray[1];
  21. }
  22. } catch (e) {
  23. alert(e);
  24. }
  25. this.css({
  26. 'background-position' : backPos
  27. });
  28. return this;
  29. };
  30. var MD5 = function(string) {
  31. if (!string) {
  32. return "";
  33. }
  34. string = string.replace(/http:\/\/.+~~/g, '');
  35. string = string.replace(/nodeID:\/\/.+~~/g, '');
  36. string = string.replace(/_:\/\/.+~~/g, '');
  37. function RotateLeft(lValue, iShiftBits) {
  38. return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
  39. }
  40. function AddUnsigned(lX, lY) {
  41. var lX4, lY4, lX8, lY8, lResult;
  42. lX8 = (lX & 0x80000000);
  43. lY8 = (lY & 0x80000000);
  44. lX4 = (lX & 0x40000000);
  45. lY4 = (lY & 0x40000000);
  46. lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
  47. if (lX4 & lY4) {
  48. return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
  49. }
  50. if (lX4 | lY4) {
  51. if (lResult & 0x40000000) {
  52. return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
  53. } else {
  54. return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
  55. }
  56. } else {
  57. return (lResult ^ lX8 ^ lY8);
  58. }
  59. }
  60. function F(x, y, z) {
  61. return (x & y) | ((~x) & z);
  62. }
  63. function G(x, y, z) {
  64. return (x & z) | (y & (~z));
  65. }
  66. function H(x, y, z) {
  67. return (x ^ y ^ z);
  68. }
  69. function I(x, y, z) {
  70. return (y ^ (x | (~z)));
  71. }
  72. function FF(a, b, c, d, x, s, ac) {
  73. a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
  74. return AddUnsigned(RotateLeft(a, s), b);
  75. }
  76. ;
  77. function GG(a, b, c, d, x, s, ac) {
  78. a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
  79. return AddUnsigned(RotateLeft(a, s), b);
  80. }
  81. ;
  82. function HH(a, b, c, d, x, s, ac) {
  83. a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
  84. return AddUnsigned(RotateLeft(a, s), b);
  85. }
  86. ;
  87. function II(a, b, c, d, x, s, ac) {
  88. a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
  89. return AddUnsigned(RotateLeft(a, s), b);
  90. }
  91. ;
  92. function ConvertToWordArray(string) {
  93. var lWordCount;
  94. var lMessageLength = string.length;
  95. var lNumberOfWords_temp1 = lMessageLength + 8;
  96. var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
  97. var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
  98. var lWordArray = Array(lNumberOfWords - 1);
  99. var lBytePosition = 0;
  100. var lByteCount = 0;
  101. while (lByteCount < lMessageLength) {
  102. lWordCount = (lByteCount - (lByteCount % 4)) / 4;
  103. lBytePosition = (lByteCount % 4) * 8;
  104. lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
  105. lByteCount++;
  106. }
  107. lWordCount = (lByteCount - (lByteCount % 4)) / 4;
  108. lBytePosition = (lByteCount % 4) * 8;
  109. lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
  110. lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
  111. lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
  112. return lWordArray;
  113. }
  114. ;
  115. function WordToHex(lValue) {
  116. var WordToHexValue = "", WordToHexValue_temp = "", lByte, lCount;
  117. for ( lCount = 0; lCount <= 3; lCount++) {
  118. lByte = (lValue >>> (lCount * 8)) & 255;
  119. WordToHexValue_temp = "0" + lByte.toString(16);
  120. WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
  121. }
  122. return WordToHexValue;
  123. }
  124. ;
  125. function Utf8Encode(string) {
  126. string = string.replace(/\r\n/g, "\n");
  127. var utftext = "";
  128. for (var n = 0; n < string.length; n++) {
  129. var c = string.charCodeAt(n);
  130. if (c < 128) {
  131. utftext += String.fromCharCode(c);
  132. } else if ((c > 127) && (c < 2048)) {
  133. utftext += String.fromCharCode((c >> 6) | 192);
  134. utftext += String.fromCharCode((c & 63) | 128);
  135. } else {
  136. utftext += String.fromCharCode((c >> 12) | 224);
  137. utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  138. utftext += String.fromCharCode((c & 63) | 128);
  139. }
  140. }
  141. return utftext;
  142. }
  143. ;
  144. var x = Array();
  145. var k, AA, BB, CC, DD, a, b, c, d;
  146. var S11 = 7, S12 = 12, S13 = 17, S14 = 22;
  147. var S21 = 5, S22 = 9, S23 = 14, S24 = 20;
  148. var S31 = 4, S32 = 11, S33 = 16, S34 = 23;
  149. var S41 = 6, S42 = 10, S43 = 15, S44 = 21;
  150. string = Utf8Encode(string);
  151. x = ConvertToWordArray(string);
  152. a = 0x67452301;
  153. b = 0xEFCDAB89;
  154. c = 0x98BADCFE;
  155. d = 0x10325476;
  156. for ( k = 0; k < x.length; k += 16) {
  157. AA = a;
  158. BB = b;
  159. CC = c;
  160. DD = d;
  161. a = FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
  162. d = FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
  163. c = FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
  164. b = FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
  165. a = FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
  166. d = FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
  167. c = FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
  168. b = FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
  169. a = FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
  170. d = FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
  171. c = FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
  172. b = FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
  173. a = FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
  174. d = FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
  175. c = FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
  176. b = FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
  177. a = GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
  178. d = GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
  179. c = GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
  180. b = GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
  181. a = GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
  182. d = GG(d, a, b, c, x[k + 10], S22, 0x2441453);
  183. c = GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
  184. b = GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
  185. a = GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
  186. d = GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
  187. c = GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
  188. b = GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
  189. a = GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
  190. d = GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
  191. c = GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
  192. b = GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
  193. a = HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
  194. d = HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
  195. c = HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
  196. b = HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
  197. a = HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
  198. d = HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
  199. c = HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
  200. b = HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
  201. a = HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
  202. d = HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
  203. c = HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
  204. b = HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
  205. a = HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
  206. d = HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
  207. c = HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
  208. b = HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
  209. a = II(a, b, c, d, x[k + 0], S41, 0xF4292244);
  210. d = II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
  211. c = II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
  212. b = II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
  213. a = II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
  214. d = II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
  215. c = II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
  216. b = II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
  217. a = II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
  218. d = II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
  219. c = II(c, d, a, b, x[k + 6], S43, 0xA3014314);
  220. b = II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
  221. a = II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
  222. d = II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
  223. c = II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
  224. b = II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
  225. a = AddUnsigned(a, AA);
  226. b = AddUnsigned(b, BB);
  227. c = AddUnsigned(c, CC);
  228. d = AddUnsigned(d, DD);
  229. }
  230. var temp = WordToHex(a) + WordToHex(b) + WordToHex(c) + WordToHex(d);
  231. return temp.toLowerCase();
  232. };
  233. function lang(obj) {
  234. return $.jStorage.get('language')[$.jStorage.get('selectedLanguage')][obj];
  235. }
  236. function breakLines(msg) {
  237. msg = msg.replace(/\//g, '/<span style="font-size:1px"> </span>');
  238. msg = msg.replace(/&/g, '&<span style="font-size:1px"> </span>');
  239. msg = msg.replace(/%/g, '%<span style="font-size:1px"> </span>');
  240. return msg;
  241. }
  242. function getSparqlConf(what, where, lodLiveProfile) {
  243. return where.sparql && where.sparql[what] ? where.sparql[what] : lodLiveProfile['default'].sparql[what]
  244. }