facebook-stub 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in facebook-stub.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Readme.md ADDED
@@ -0,0 +1,56 @@
1
+ # Facebook JS Stub #
2
+
3
+ Include facebook-stub.js when in your testing environment, and don't include the facebook all.js
4
+
5
+ facebook-stub.js creates valid md5 sig cookie which will be passed to the server.
6
+
7
+ ## Overview ##
8
+
9
+ FacebookStub provides two global objects:
10
+
11
+ * **FB** emulates the same behavior as the FB object.
12
+ * **FBWorld** provides entries to get and set facebook states.
13
+
14
+ ## FBWorld Usage ##
15
+
16
+ The first think you need to do is FBWorld.setSecret(Your App Secret). This allows the creation of valid cookies.
17
+
18
+ ### Setting State ###
19
+
20
+ Then you can simulate different user states by using:
21
+
22
+ FBWorld.notLoggedIn();
23
+ FBWorld.loggedIn();
24
+ FBWorld.notConnected();
25
+ FBWorld.connected();
26
+
27
+ ### Connecting your app as a user ###
28
+ If you are not connected to the application, then when FB.login is called,
29
+ you will need to respond with either
30
+
31
+ FBWorld.allowConnection(); or
32
+ FBWorld.denyConnection();
33
+
34
+ The difference between being not being logged in and connecting and being not logged in has not been flushed out yet, as it's purely a facebook state. In terms of the app, you're either connected or not.
35
+
36
+
37
+ ### Helper Functions ###
38
+ FBWorld provides you with these helper functions for debugging your application state
39
+
40
+ FBWorld.state();
41
+ FBWorld.setUid();
42
+ FBWorld.uid();
43
+ FBWorld.beingPromptedToLogin;
44
+ FBWorld.beingPromptedToConnect;
45
+
46
+ # Forking Instructions #
47
+
48
+ If you modify facebook-stub.js directly it will be overwritten by builder/concat. Modify src/ files only
49
+
50
+ # LICENSE: [MIT](http://www.opensource.org/licenses/mit-license.php) #
51
+
52
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
53
+
54
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/builder/concat ADDED
@@ -0,0 +1,8 @@
1
+ #!/bin/sh
2
+ if [ ! -f src/facebook.js ] ; then
3
+ echo "Please run this from the top level"
4
+ exit 1
5
+ fi
6
+
7
+ cat src/facebook.js src/libs/*.js > facebook-stub.js
8
+ git add facebook-stub.js
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "facebook-stub/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "facebook-stub"
7
+ s.version = Facebook::Stub::VERSION
8
+ s.authors = ["Change.org"]
9
+ s.email = ["techops@change.org"]
10
+ s.homepage = ""
11
+ s.summary = %q{Stub out the FB JS API}
12
+ s.description = %q{facebook-stub is a gem for stubbing out the Facebook JavaScript API in acceptance and integration tests.}
13
+
14
+ s.rubyforge_project = "facebook-stub"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
data/facebook-stub.js ADDED
@@ -0,0 +1,529 @@
1
+ ;(function(window, undefined) {
2
+
3
+ //var standardPerms = '{"extended":["status_update","photo_upload","video_upload","offline_access","email","create_note","share_item","publish_stream","contact_email"],"user":["manage_friendlists","create_event","read_requests","manage_pages"],"friends":[]}';
4
+
5
+ // two globals for creating the cookie
6
+ // FB Functions
7
+ function init(data) {
8
+ FBWorld.initialized = true;
9
+ state('appId', data.appId);
10
+ }
11
+
12
+ function login(callback, options) {
13
+ if (calledBeforeInit('login')) return;
14
+ if (FBWorld.state('loggedIn')) {
15
+ console.log('FB.login() called when user is already connected.');
16
+ if (FBWorld.state('connected')) {
17
+ callback(getStatus('standard'));
18
+ } else {
19
+ simulatePromptToConnect(callback, options);
20
+ }
21
+ } else {
22
+ simulatePromptToLogin(callback, options);
23
+ }
24
+ }
25
+
26
+ function logout(callback) {
27
+ if (calledBeforeInit('logout')) return;
28
+ if (!FBWorld.state('loggedIn')) console.log('FB.logout() called without a session.');
29
+ FBWorld.notLoggedIn();
30
+ callback(getStatus());
31
+ }
32
+
33
+ function getLoginStatus(callback, perms) {
34
+ if (calledBeforeInit('getLoginStatus')) return;
35
+ callback(getStatus(perms ? 'extended' : false));
36
+ }
37
+
38
+ function getUserID() {
39
+ if (calledBeforeInit('getUserID')) return;
40
+ return uid();
41
+ }
42
+
43
+
44
+ function getSession() {
45
+ if (calledBeforeInit('getSession')) return false;
46
+ return getStatus().session;
47
+ }
48
+
49
+ function api(location, callback) {
50
+ if (!FBWorld.state('connected')) {
51
+ callback(undefined);
52
+ } else if (location == '/me/friends') {
53
+ callback({data:FBWorld.friendList()});
54
+ } else if (location == '/me/permissions') {
55
+ var theState = FBWorld.state();
56
+ var perms;
57
+ if (theState && theState.perms) {
58
+ perms = {data:[theState.perms.extended]}
59
+ }
60
+ callback( perms );
61
+ }
62
+ }
63
+
64
+ // FBWorld Functions
65
+ //3 states: loggedOut, loggedIn, connected
66
+ function state() {
67
+ var theState = JSON.parse(FBWorld.Helpers.makeMeACookie('fb-stub') || '{}');
68
+ if (arguments.length === 0) return theState;
69
+ if (arguments.length === 1) return theState[arguments[0]];
70
+ if (arguments.length === 2) {
71
+ theState[arguments[0]] = arguments[1];
72
+ FBWorld.Helpers.makeMeACookie('fb-stub', JSON.stringify(theState), cookieOptions);
73
+ return arguments[1];
74
+ }
75
+ if (arguments.length === 3) {
76
+ if(typeof(theState[arguments[0]]) == 'undefined') theState[arguments[0]] = {};
77
+ theState[arguments[0]][arguments[1]] = arguments[2];
78
+ FBWorld.Helpers.makeMeACookie('fb-stub', JSON.stringify(theState), cookieOptions);
79
+ return arguments[2];
80
+ }
81
+ }
82
+
83
+ function uid() {
84
+ return FBWorld.state('uid');
85
+ }
86
+
87
+ function setUid(newUid) {
88
+ return FBWorld.state('uid', newUid);
89
+ }
90
+
91
+ function setExtendedPermissions(newPermissions) {
92
+ return FBWorld.state('perms', 'extended', newPermissions);
93
+ }
94
+
95
+ function setSecret(newSecret) {
96
+ return state('secret', newSecret);
97
+ }
98
+
99
+ function loggedIn() {
100
+ createConnectedCookie();
101
+ FBWorld.state('loggedIn', true);
102
+ return true;
103
+ }
104
+
105
+ function notLoggedIn() {
106
+ deleteConnectedCookie();
107
+ FBWorld.state('loggedIn', false);
108
+ }
109
+
110
+ function connected() {
111
+ createConnectedCookie();
112
+ FBWorld.state('connected', true);
113
+ }
114
+
115
+ function notConnected() {
116
+ deleteConnectedCookie();
117
+ FBWorld.state('connected', false);
118
+ }
119
+
120
+ function addFriend(id, name) {
121
+ var friends = FBWorld.friendList();
122
+ friends.push({id: id, name: name});
123
+ FBWorld.Helpers.makeMeACookie('fb_friends', JSON.stringify(friends));
124
+ }
125
+
126
+ function friendList() {
127
+ return JSON.parse(FBWorld.Helpers.makeMeACookie('fb_friends') || '[]');
128
+ }
129
+
130
+ var XFBML = {
131
+ parse: function(element, callback) {
132
+ callback();
133
+ }
134
+ };
135
+
136
+ FB = { // Emulates the FB API
137
+ getLoginStatus : getLoginStatus,
138
+ logout : logout,
139
+ login : login,
140
+ init : init,
141
+ getSession : getSession,
142
+ api : api,
143
+ XFBML : XFBML,
144
+ getUserID : getUserID
145
+ };
146
+
147
+ FBWorld = { // used to set the state of Facebook
148
+ state : state,
149
+ loggedIn : loggedIn,
150
+ notLoggedIn : notLoggedIn,
151
+ setUid : setUid,
152
+ setSecret : setSecret,
153
+ uid : uid,
154
+ connected : connected,
155
+ notConnected : notConnected,
156
+ setExtendedPermissions : setExtendedPermissions,
157
+
158
+ initialized : false,
159
+ beingPromptedToLogIn : false,
160
+ beingPromptedToLogInCallback : undefined,
161
+ // this will come later, no need for it now
162
+ // successfullyLogin: successfullyLogin,
163
+ // failToLogin: failToLogin,
164
+
165
+ beingPromptedToConnect : false,
166
+ beingPromptedToConnectInCallback : undefined,
167
+ allowConnection : allowConnection,
168
+ denyConnection : denyConnection,
169
+
170
+ //friends
171
+ addFriend : addFriend,
172
+ friendList : friendList
173
+ };
174
+
175
+ // PRIVATE FUNCTIONS
176
+
177
+ function getStatus(permissions) {
178
+ var theState = FBWorld.state();
179
+
180
+ // Connected
181
+ if (theState.loggedIn && theState.connected) {
182
+ var status = {
183
+ status: "connected",
184
+ authResponse: createConnectedCookie()
185
+ };
186
+
187
+ if(typeof(permissions) != 'undefined') {
188
+ status.perms = permissions == 'extended' ? JSON.stringify(theState.perms) : theState.perms.standard;
189
+ }
190
+ return status;
191
+ }
192
+
193
+ // not connected
194
+ if (theState.loggedIn && !theState.connected) {
195
+ return {
196
+ perms: null,
197
+ authResponse: null,
198
+ status: 'notConnected'
199
+ };
200
+ }
201
+
202
+ // not logged in
203
+ if (!theState.loggedIn) {
204
+ return {
205
+ perms: null,
206
+ authResponse: null,
207
+ status: 'unknown'
208
+ };
209
+ }
210
+
211
+ };
212
+
213
+ function calledBeforeInit() {
214
+ if (FBWorld.initialized) return false;
215
+ console.log("FB."+meth+" called before FB.init");
216
+ return true;
217
+ }
218
+
219
+ function simulatePromptToLogin(callback, options) {
220
+ // simulate being prompted to log in
221
+ FBWorld.beingPromptedToLogIn = true;
222
+ FBWorld.beingPromptedToLogInCallback = function(approved) {
223
+ FBWorld.beingPromptedToLogin = false;
224
+ FBWorld.beingPromptedToLoginCallback = undefined;
225
+ if(approved) {
226
+ FBWorld.loggedIn();
227
+ if (!FBWorld.state('connected')) {
228
+ simulatePromptToConnect(callback, options);
229
+ } else {
230
+ FBWorld.state('perms', 'standard', options.perms);
231
+ callback(getStatus('standard'));
232
+ }
233
+ } else {
234
+ FBWorld.notLoggedIn();
235
+ callback(getStatus());
236
+ }
237
+
238
+ };
239
+ };
240
+
241
+ function simulatePromptToConnect(callback, options) {
242
+ // simulate being prompted to connect
243
+ FBWorld.beingPromptedToConnect = true;
244
+ FBWorld.beingPromptedToConnectCallback = function(approved) {
245
+ approved ? FBWorld.connected() : FBWorld.notConnected();
246
+ FBWorld.beingPromptedToConnect = false;
247
+ FBWorld.beingPromptedToConnectCallback = undefined;
248
+ if (approved) {
249
+ FBWorld.state('perms', 'standard', options.perms);
250
+ }
251
+ callback(getStatus('standard'));
252
+ };
253
+ };
254
+
255
+ function allowConnection() {
256
+ if (!FBWorld.beingPromptedToConnect) throw "you are not being prompted to connect";
257
+ FBWorld.beingPromptedToConnectCallback(true);
258
+ };
259
+
260
+ function denyConnection() {
261
+ if (!FBWorld.beingPromptedToConnect) throw "you are not being prompted to connect";
262
+ FBWorld.beingPromptedToConnectCallback(false);
263
+ };
264
+
265
+ var cookieOptions = { path: '/', domain: window.location.hostname.replace(/^www/, '')};
266
+
267
+ // cookie looks like this: (with the quotes): "access_token=theToken&base_domain=local-change.org&expires=0&secret=theSecret&session_key=theSessionKeysig=theSig-Hashed&uid=theUID"
268
+ function createConnectedCookie() {
269
+ var theState = {
270
+ user_id: state('uid'),
271
+ code: 'theAccessToken|hashData',
272
+ // We need to verify the timezone for this value. Traditionally FB uses PST8PDT, but it may be UTC.
273
+ issued_at: Math.floor(new Date().getTime() / 1000)
274
+ };
275
+
276
+ if (uid() != null) {
277
+ theState.uid = uid();
278
+ }
279
+
280
+ FBWorld.Helpers.makeMeACookie('fbsr_'+state('appId'), cookieToString(theState, state('secret')), cookieOptions);
281
+ return theState;
282
+ }
283
+
284
+ function cookieToString(theState, secret) {
285
+ // Set the algorithm here, to keep any changes here.
286
+ theState.algorithm = 'HMAC-SHA256';
287
+
288
+ var payload = JSON.stringify(theState),
289
+ encodedPayload = FBWorld.Helpers.base64_encode(payload),
290
+ shaObj = new FBWorld.Helpers.jsSHA(encodedPayload, "ASCII"),
291
+ b64Signature = shaObj.getHMAC(secret, "ASCII", "SHA-256", "B64");
292
+
293
+ // jsSHA uses an odd Base64 encoder, which uses + where FB has -. For now we'll just replace them,
294
+ // but if we find other inconsistencies, we should use the HEX value and encode it ourselves.
295
+ b64Signature.replace('+', '-');
296
+
297
+ return b64Signature + '.' + encodedPayload;
298
+ }
299
+
300
+ function deleteConnectedCookie() {
301
+ FBWorld.Helpers.makeMeACookie('fbsr_'+state('appId'), null, cookieOptions);
302
+ }
303
+
304
+
305
+ })(this);
306
+ FBWorld.Helpers = {};
307
+ setTimeout(function() { if (typeof fbAsyncInit === 'function') fbAsyncInit(); }, 1);
308
+ FBWorld.Helpers.base64_encode = function (data, utf8encode) {
309
+ // http://kevin.vanzonneveld.net
310
+ // + original by: Tyler Akins (http://rumkin.com)
311
+ // + improved by: Bayron Guevara
312
+ // + improved by: Thunder.m
313
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
314
+ // + bugfixed by: Pellentesque Malesuada
315
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
316
+ // + improved by: Rafał Kukawski (http://kukawski.pl)
317
+ // - depends on: utf8_encode
318
+ // * example 1: base64_encode('Kevin van Zonneveld');
319
+ // * returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
320
+ // mozilla has this native
321
+ // - but breaks in 2.0.0.12!
322
+ //if (typeof this.window['atob'] == 'function') {
323
+ // return atob(data);
324
+ //}
325
+ var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
326
+ var o1, o2, o3, h1, h2, h3, h4, bits, i = 0,
327
+ ac = 0,
328
+ enc = "",
329
+ tmp_arr = [];
330
+
331
+ if (!data) {
332
+ return data;
333
+ }
334
+
335
+ // Only do this if forced
336
+ if (utf8encode)
337
+ data = this.utf8_encode(data + '');
338
+
339
+ do { // pack three octets into four hexets
340
+ o1 = data.charCodeAt(i++);
341
+ o2 = data.charCodeAt(i++);
342
+ o3 = data.charCodeAt(i++);
343
+
344
+ bits = o1 << 16 | o2 << 8 | o3;
345
+
346
+ h1 = bits >> 18 & 0x3f;
347
+ h2 = bits >> 12 & 0x3f;
348
+ h3 = bits >> 6 & 0x3f;
349
+ h4 = bits & 0x3f;
350
+
351
+ // use hexets to index into b64, and append result to encoded string
352
+ tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
353
+ } while (i < data.length);
354
+
355
+ enc = tmp_arr.join('');
356
+
357
+ var r = data.length % 3;
358
+
359
+ return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
360
+
361
+ };
362
+ /**
363
+ * Cookie plugin
364
+ *
365
+ * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
366
+ * Dual licensed under the MIT and GPL licenses:
367
+ * http://www.opensource.org/licenses/mit-license.php
368
+ * http://www.gnu.org/licenses/gpl.html
369
+ *
370
+ */
371
+
372
+ /**
373
+ * Create a cookie with the given name and value and other optional parameters.
374
+ *
375
+ * @example $.cookie('the_cookie', 'the_value');
376
+ * @desc Set the value of a cookie.
377
+ * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
378
+ * @desc Create a cookie with all available options.
379
+ * @example $.cookie('the_cookie', 'the_value');
380
+ * @desc Create a session cookie.
381
+ * @example $.cookie('the_cookie', null);
382
+ * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
383
+ * used when the cookie was set.
384
+ *
385
+ * @param String name The name of the cookie.
386
+ * @param String value The value of the cookie.
387
+ * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
388
+ * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
389
+ * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
390
+ * If set to null or omitted, the cookie will be a session cookie and will not be retained
391
+ * when the the browser exits.
392
+ * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
393
+ * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
394
+ * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
395
+ * require a secure protocol (like HTTPS).
396
+ * @type undefined
397
+ *
398
+ * @name $.cookie
399
+ * @cat Plugins/Cookie
400
+ * @author Klaus Hartl/klaus.hartl@stilbuero.de
401
+ */
402
+
403
+ /**
404
+ * Get the value of a cookie with the given name.
405
+ *
406
+ * @example $.cookie('the_cookie');
407
+ * @desc Get the value of a cookie.
408
+ *
409
+ * @param String name The name of the cookie.
410
+ * @return The value of the cookie.
411
+ * @type String
412
+ *
413
+ * @name $.cookie
414
+ * @cat Plugins/Cookie
415
+ * @author Klaus Hartl/klaus.hartl@stilbuero.de
416
+ */
417
+
418
+ // Modified to make it not use jquery
419
+ FBWorld.Helpers.makeMeACookie = function(name, value, options) {
420
+ if (typeof value != 'undefined') { // name and value given, set cookie
421
+ options = options || {};
422
+ if (value === null) {
423
+ value = '';
424
+ options.expires = -1;
425
+ } else {
426
+ options.expires = 100; // 100 days from now
427
+ }
428
+ var expires = '';
429
+ if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
430
+ var date;
431
+ if (typeof options.expires == 'number') {
432
+ date = new Date();
433
+ date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
434
+ } else {
435
+ date = options.expires;
436
+ }
437
+ expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
438
+ }
439
+ // CAUTION: Needed to parenthesize options.path and options.domain
440
+ // in the following expressions, otherwise they evaluate to undefined
441
+ // in the packed version for some reason...
442
+ var path = options.path ? '; path=' + (options.path) : '';
443
+ var domain = options.domain ? '; domain=' + (options.domain) : '';
444
+ var secure = options.secure ? '; secure' : '';
445
+ document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
446
+ } else { // only name given, get cookie
447
+ var cookieValue = null;
448
+ if (document.cookie && document.cookie != '') {
449
+ var cookies = document.cookie.split(';');
450
+ for (var i = 0; i < cookies.length; i++) {
451
+ var cookie = FBWorld.Helpers.trim(cookies[i]);
452
+ // Does this cookie string begin with the name we want?
453
+ if (cookie.substring(0, name.length + 1) == (name + '=')) {
454
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
455
+ break;
456
+ }
457
+ }
458
+ }
459
+ return cookieValue;
460
+ }
461
+ };
462
+
463
+ //Taken from jQuery
464
+ FBWorld.Helpers.trim = function( text ) {
465
+ return text == null ?
466
+ "" :
467
+ text.toString().replace( /^\s+/, "" ).replace( /\s+$/, "" );
468
+ };
469
+ /* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
470
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
471
+ * FIPS PUB 198a
472
+ *
473
+ * Version 1.3 Copyright Brian Turek 2008-2010
474
+ * Distributed under the BSD License
475
+ * See http://jssha.sourceforge.net/ for more information
476
+ *
477
+ * Several functions taken from Paul Johnson
478
+ */
479
+ (function(){var charSize=8,b64pad="",hexCase=0,str2binb=function(a){var b=[],mask=(1<<charSize)-1,length=a.length*charSize,i;for(i=0;i<length;i+=charSize){b[i>>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i<length;i+=2){num=parseInt(a.substr(i,2),16);if(!isNaN(num)){b[i>>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i<length;i+=1){srcByte=a[i>>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i<length;i+=3){triplet=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotr=function(x,n){return(x>>>n)|(x<<(32-n))},shr=function(x,n){return x>>>n},ch=function(x,y,z){return(x&y)^(~x&z)},maj=function(x,y,z){return(x&y)^(x&z)^(y&z)},sigma0=function(x){return rotr(x,2)^rotr(x,13)^rotr(x,22)},sigma1=function(x){return rotr(x,6)^rotr(x,11)^rotr(x,25)},gamma0=function(x){return rotr(x,7)^rotr(x,18)^shr(x,3)},gamma1=function(x){return rotr(x,17)^rotr(x,19)^shr(x,10)},safeAdd_2=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF),msw=(x>>>16)+(y>>>16)+(a>>>16);return((msw&0xFFFF)<<16)|(a&0xFFFF)},safeAdd_4=function(a,b,c,d){var e=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16);return((msw&0xFFFF)<<16)|(e&0xFFFF)},safeAdd_5=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((msw&0xFFFF)<<16)|(f&0xFFFF)},coreSHA2=function(j,k,l){var a,b,c,d,e,f,g,h,T1,T2,H,lengthPosition,i,t,K,W=[],appendedMessageLength;if(l==="SHA-224"||l==="SHA-256"){lengthPosition=(((k+65)>>9)<<4)+15;K=[0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0x0FC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x06CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2];if(l==="SHA-224"){H=[0xc1059ed8,0x367cd507,0x3070dd17,0xf70e5939,0xffc00b31,0x68581511,0x64f98fa7,0xbefa4fa4]}else{H=[0x6A09E667,0xBB67AE85,0x3C6EF372,0xA54FF53A,0x510E527F,0x9B05688C,0x1F83D9AB,0x5BE0CD19]}}j[k>>5]|=0x80<<(24-k%32);j[lengthPosition]=k;appendedMessageLength=j.length;for(i=0;i<appendedMessageLength;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];f=H[5];g=H[6];h=H[7];for(t=0;t<64;t+=1){if(t<16){W[t]=j[t+i]}else{W[t]=safeAdd_4(gamma1(W[t-2]),W[t-7],gamma0(W[t-15]),W[t-16])}T1=safeAdd_5(h,sigma1(e),ch(e,f,g),K[t],W[t]);T2=safeAdd_2(sigma0(a),maj(a,b,c));h=g;g=f;f=e;e=safeAdd_2(d,T1);d=c;c=b;b=a;a=safeAdd_2(T1,T2)}H[0]=safeAdd_2(a,H[0]);H[1]=safeAdd_2(b,H[1]);H[2]=safeAdd_2(c,H[2]);H[3]=safeAdd_2(d,H[3]);H[4]=safeAdd_2(e,H[4]);H[5]=safeAdd_2(f,H[5]);H[6]=safeAdd_2(g,H[6]);H[7]=safeAdd_2(h,H[7])}switch(l){case"SHA-224":return[H[0],H[1],H[2],H[3],H[4],H[5],H[6]];case"SHA-256":return H;default:return[]}},jsSHA=function(a,b){this.sha224=null;this.sha256=null;this.strBinLen=null;this.strToHash=null;if("HEX"===b){if(0!==(a.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}this.strBinLen=a.length*4;this.strToHash=hex2binb(a)}else if(("ASCII"===b)||('undefined'===typeof(b))){this.strBinLen=a.length*charSize;this.strToHash=str2binb(a)}else{return"UNKNOWN TEXT INPUT TYPE"}};jsSHA.prototype={getHash:function(a,b){var c=null,message=this.strToHash.slice();switch(b){case"HEX":c=binb2hex;break;case"B64":c=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case"SHA-224":if(null===this.sha224){this.sha224=coreSHA2(message,this.strBinLen,a)}return c(this.sha224);case"SHA-256":if(null===this.sha256){this.sha256=coreSHA2(message,this.strBinLen,a)}return c(this.sha256);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(a,b,c,d){var e,keyToUse,i,retVal,keyBinLen,hashBitSize,keyWithIPad=[],keyWithOPad=[];switch(d){case"HEX":e=binb2hex;break;case"B64":e=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(c){case"SHA-224":hashBitSize=224;break;case"SHA-256":hashBitSize=256;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}keyToUse=hex2binb(a);keyBinLen=a.length*4}else if("ASCII"===b){keyToUse=str2binb(a);keyBinLen=a.length*charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(64<(keyBinLen/8)){keyToUse=coreSHA2(keyToUse,keyBinLen,c);keyToUse[15]&=0xFFFFFF00}else if(64>(keyBinLen/8)){keyToUse[15]&=0xFFFFFF00}for(i=0;i<=15;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA2(keyWithIPad.concat(this.strToHash),512+this.strBinLen,c);retVal=coreSHA2(keyWithOPad.concat(retVal),512+hashBitSize,c);return(e(retVal))}};window.FBWorld.Helpers.jsSHA=jsSHA}());
480
+ FBWorld.Helpers.utf8_encode = function (argString) {
481
+ // http://kevin.vanzonneveld.net
482
+ // + original by: Webtoolkit.info (http://www.webtoolkit.info/)
483
+ // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
484
+ // + improved by: sowberry
485
+ // + tweaked by: Jack
486
+ // + bugfixed by: Onno Marsman
487
+ // + improved by: Yves Sucaet
488
+ // + bugfixed by: Onno Marsman
489
+ // + bugfixed by: Ulrich
490
+ // + bugfixed by: Rafal Kukawski
491
+ // * example 1: utf8_encode('Kevin van Zonneveld');
492
+ // * returns 1: 'Kevin van Zonneveld'
493
+
494
+ if (argString === null || typeof argString === "undefined") {
495
+ return "";
496
+ }
497
+
498
+ var string = (argString + ''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
499
+ var utftext = "",
500
+ start, end, stringl = 0;
501
+
502
+ start = end = 0;
503
+ stringl = string.length;
504
+ for (var n = 0; n < stringl; n++) {
505
+ var c1 = string.charCodeAt(n);
506
+ var enc = null;
507
+
508
+ if (c1 < 128) {
509
+ end++;
510
+ } else if (c1 > 127 && c1 < 2048) {
511
+ enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
512
+ } else {
513
+ enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
514
+ }
515
+ if (enc !== null) {
516
+ if (end > start) {
517
+ utftext += string.slice(start, end);
518
+ }
519
+ utftext += enc;
520
+ start = end = n + 1;
521
+ }
522
+ }
523
+
524
+ if (end > start) {
525
+ utftext += string.slice(start, stringl);
526
+ }
527
+
528
+ return utftext;
529
+ }