Skip to:
Content

BuddyPress.org

Changeset 6940


Ignore:
Timestamp:
04/22/2013 05:01:53 AM (13 years ago)
Author:
r-a-y
Message:

Only pass BP-related cookies to BP AJAX queries.

Previously, we would pass all cookies to admin-ajax.php. This could
potentially lead to a '414 Long Request' error because of the length of the
querystring, resulting in the AJAX request failing.

This commit only passes cookies with the 'bp-' prefix to admin-ajax.php,
thus limiting the length of the URI request.

Fixes #4606.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-templates/bp-legacy/js/buddypress.js

    r6894 r6940  
    7676                jq.post( ajaxurl, {
    7777                        action: 'post_update',
    78                         'cookie': encodeURIComponent(document.cookie),
     78                        'cookie': bp_get_cookies(),
    7979                        '_wpnonce_post_update': jq("#_wpnonce_post_update").val(),
    8080                        'content': content,
     
    196196                        jq.post( ajaxurl, {
    197197                                action: 'activity_mark_' + type,
    198                                 'cookie': encodeURIComponent(document.cookie),
     198                                'cookie': bp_get_cookies(),
    199199                                'id': parent_id
    200200                        },
     
    253253                        jq.post( ajaxurl, {
    254254                                action: 'delete_activity',
    255                                 'cookie': encodeURIComponent(document.cookie),
     255                                'cookie': bp_get_cookies(),
    256256                                'id': id,
    257257                                '_wpnonce': nonce
     
    307307                        jq.post( ajaxurl, {
    308308                                action: 'activity_get_older_updates',
    309                                 'cookie': encodeURIComponent(document.cookie),
     309                                'cookie': bp_get_cookies(),
    310310                                'page': oldest_page
    311311                        },
     
    423423                        var ajaxdata = {
    424424                                action: 'new_activity_comment',
    425                                 'cookie': encodeURIComponent(document.cookie),
     425                                'cookie': bp_get_cookies(),
    426426                                '_wpnonce_new_activity_comment': jq("#_wpnonce_new_activity_comment").val(),
    427427                                'comment_id': comment_id,
     
    496496                        jq.post( ajaxurl, {
    497497                                action: 'delete_activity_comment',
    498                                 'cookie': encodeURIComponent(document.cookie),
     498                                'cookie': bp_get_cookies(),
    499499                                '_wpnonce': nonce,
    500500                                'id': comment_id
     
    773773                        action: 'groups_invite_user',
    774774                        'friend_action': friend_action,
    775                         'cookie': encodeURIComponent(document.cookie),
     775                        'cookie': bp_get_cookies(),
    776776                        '_wpnonce': jq("#_wpnonce_invite_uninvite_user").val(),
    777777                        'friend_id': friend_id,
     
    806806                        action: 'groups_invite_user',
    807807                        'friend_action': 'uninvite',
    808                         'cookie': encodeURIComponent(document.cookie),
     808                        'cookie': bp_get_cookies(),
    809809                        '_wpnonce': jq("#_wpnonce_invite_uninvite_user").val(),
    810810                        'friend_id': friend_id,
     
    873873                jq.post( ajaxurl, {
    874874                        action: action,
    875                         'cookie': encodeURIComponent(document.cookie),
     875                        'cookie': bp_get_cookies(),
    876876                        'id': id,
    877877                        '_wpnonce': nonce
     
    915915                jq.post( ajaxurl, {
    916916                        action: 'addremove_friend',
    917                         'cookie': encodeURIComponent(document.cookie),
     917                        'cookie': bp_get_cookies(),
    918918                        'fid': fid,
    919919                        '_wpnonce': nonce
     
    964964                jq.post( ajaxurl, {
    965965                        action: 'joinleave_group',
    966                         'cookie': encodeURIComponent(document.cookie),
     966                        'cookie': bp_get_cookies(),
    967967                        'gid': gid,
    968968                        '_wpnonce': nonce
     
    10211021                        jq.post( ajaxurl, {
    10221022                                action: 'messages_send_reply',
    1023                                 'cookie': encodeURIComponent(document.cookie),
     1023                                'cookie': bp_get_cookies(),
    10241024                                '_wpnonce': jq("#send_message_nonce").val(),
    10251025
     
    13071307        bp_ajax_request = jq.post( ajaxurl, {
    13081308                action: object + '_filter',
    1309                 'cookie': encodeURIComponent(document.cookie),
     1309                'cookie': bp_get_cookies(),
    13101310                'object': object,
    13111311                'filter': filter,
     
    13551355        bp_ajax_request = jq.post( ajaxurl, {
    13561356                action: 'activity_widget_filter',
    1357                 'cookie': encodeURIComponent(document.cookie),
     1357                'cookie': bp_get_cookies(),
    13581358                '_wpnonce_activity_filter': jq("#_wpnonce_activity_filter").val(),
    13591359                'scope': scope,
     
    14491449}
    14501450
     1451/* Returns a querystring of BP cookies (cookies beginning with 'bp-') */
     1452function bp_get_cookies() {
     1453        // get all cookies and split into an array
     1454        var allCookies   = document.cookie.split(";");
     1455
     1456        var bpCookies    = {};
     1457        var cookiePrefix = 'bp-';
     1458
     1459        // loop through cookies
     1460        for (var i = 0; i < allCookies.length; i++) {
     1461                var cookie    = allCookies[i];
     1462                var delimiter = cookie.indexOf("=");
     1463                var name      = unescape( cookie.slice(0, delimiter) ).trim();
     1464                var value     = unescape( cookie.slice(delimiter + 1) );
     1465
     1466                // if BP cookie, store it
     1467                if ( name.indexOf(cookiePrefix) == 0 ) {
     1468                        bpCookies[name] = value;
     1469                }
     1470        }
     1471
     1472        // returns BP cookies as querystring
     1473        return encodeURIComponent( jq.param(bpCookies) );
     1474}
     1475
    14511476/* ScrollTo plugin - just inline and minified */
    14521477;(function($){var h=$.scrollTo=function(a,b,c){$(window).scrollTo(a,b,c)};h.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1,limit:true};h.window=function(a){return $(window)._scrollable()};$.fn._scrollable=function(){return this.map(function(){var a=this,isWin=!a.nodeName||$.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!isWin)return a;var b=(a.contentWindow||a).document||a.ownerDocument||a;return/webkit/i.test(navigator.userAgent)||b.compatMode=='BackCompat'?b.body:b.documentElement})};$.fn.scrollTo=function(e,f,g){if(typeof f=='object'){g=f;f=0}if(typeof g=='function')g={onAfter:g};if(e=='max')e=9e9;g=$.extend({},h.defaults,g);f=f||g.duration;g.queue=g.queue&&g.axis.length>1;if(g.queue)f/=2;g.offset=both(g.offset);g.over=both(g.over);return this._scrollable().each(function(){if(e==null)return;var d=this,$elem=$(d),targ=e,toff,attr={},win=$elem.is('html,body');switch(typeof targ){case'number':case'string':if(/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(targ)){targ=both(targ);break}targ=$(targ,this);if(!targ.length)return;case'object':if(targ.is||targ.style)toff=(targ=$(targ)).offset()}$.each(g.axis.split(''),function(i,a){var b=a=='x'?'Left':'Top',pos=b.toLowerCase(),key='scroll'+b,old=d[key],max=h.max(d,a);if(toff){attr[key]=toff[pos]+(win?0:old-$elem.offset()[pos]);if(g.margin){attr[key]-=parseInt(targ.css('margin'+b))||0;attr[key]-=parseInt(targ.css('border'+b+'Width'))||0}attr[key]+=g.offset[pos]||0;if(g.over[pos])attr[key]+=targ[a=='x'?'width':'height']()*g.over[pos]}else{var c=targ[pos];attr[key]=c.slice&&c.slice(-1)=='%'?parseFloat(c)/100*max:c}if(g.limit&&/^\d+$/.test(attr[key]))attr[key]=attr[key]<=0?0:Math.min(attr[key],max);if(!i&&g.queue){if(old!=attr[key])animate(g.onAfterFirst);delete attr[key]}});animate(g.onAfter);function animate(a){$elem.animate(attr,f,g.easing,a&&function(){a.call(this,e,g)})}}).end()};h.max=function(a,b){var c=b=='x'?'Width':'Height',scroll='scroll'+c;if(!$(a).is('html,body'))return a[scroll]-$(a)[c.toLowerCase()]();var d='client'+c,html=a.ownerDocument.documentElement,body=a.ownerDocument.body;return Math.max(html[scroll],body[scroll])-Math.min(html[d],body[d])};function both(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
  • trunk/bp-themes/bp-default/_inc/global.js

    r6922 r6940  
    7676                jq.post( ajaxurl, {
    7777                        action: 'post_update',
    78                         'cookie': encodeURIComponent(document.cookie),
     78                        'cookie': bp_get_cookies(),
    7979                        '_wpnonce_post_update': jq("input#_wpnonce_post_update").val(),
    8080                        'content': content,
     
    196196                        jq.post( ajaxurl, {
    197197                                action: 'activity_mark_' + type,
    198                                 'cookie': encodeURIComponent(document.cookie),
     198                                'cookie': bp_get_cookies(),
    199199                                'id': parent_id
    200200                        },
     
    250250                        jq.post( ajaxurl, {
    251251                                action: 'delete_activity',
    252                                 'cookie': encodeURIComponent(document.cookie),
     252                                'cookie': bp_get_cookies(),
    253253                                'id': id,
    254254                                '_wpnonce': nonce
     
    304304                        jq.post( ajaxurl, {
    305305                                action: 'activity_get_older_updates',
    306                                 'cookie': encodeURIComponent(document.cookie),
     306                                'cookie': bp_get_cookies(),
    307307                                'page': oldest_page
    308308                        },
     
    417417                        var ajaxdata = {
    418418                                action: 'new_activity_comment',
    419                                 'cookie': encodeURIComponent(document.cookie),
     419                                'cookie': bp_get_cookies(),
    420420                                '_wpnonce_new_activity_comment': jq("input#_wpnonce_new_activity_comment").val(),
    421421                                'comment_id': comment_id,
     
    489489                        jq.post( ajaxurl, {
    490490                                action: 'delete_activity_comment',
    491                                 'cookie': encodeURIComponent(document.cookie),
     491                                'cookie': bp_get_cookies(),
    492492                                '_wpnonce': nonce,
    493493                                'id': comment_id
     
    761761                        action: 'groups_invite_user',
    762762                        'friend_action': friend_action,
    763                         'cookie': encodeURIComponent(document.cookie),
     763                        'cookie': bp_get_cookies(),
    764764                        '_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(),
    765765                        'friend_id': friend_id,
     
    794794                        action: 'groups_invite_user',
    795795                        'friend_action': 'uninvite',
    796                         'cookie': encodeURIComponent(document.cookie),
     796                        'cookie': bp_get_cookies(),
    797797                        '_wpnonce': jq("input#_wpnonce_invite_uninvite_user").val(),
    798798                        'friend_id': friend_id,
     
    861861                jq.post( ajaxurl, {
    862862                        action: action,
    863                         'cookie': encodeURIComponent(document.cookie),
     863                        'cookie': bp_get_cookies(),
    864864                        'id': id,
    865865                        '_wpnonce': nonce
     
    903903                jq.post( ajaxurl, {
    904904                        action: 'addremove_friend',
    905                         'cookie': encodeURIComponent(document.cookie),
     905                        'cookie': bp_get_cookies(),
    906906                        'fid': fid,
    907907                        '_wpnonce': nonce
     
    952952                jq.post( ajaxurl, {
    953953                        action: 'joinleave_group',
    954                         'cookie': encodeURIComponent(document.cookie),
     954                        'cookie': bp_get_cookies(),
    955955                        'gid': gid,
    956956                        '_wpnonce': nonce
     
    10091009                        jq.post( ajaxurl, {
    10101010                                action: 'messages_send_reply',
    1011                                 'cookie': encodeURIComponent(document.cookie),
     1011                                'cookie': bp_get_cookies(),
    10121012                                '_wpnonce': jq("input#send_message_nonce").val(),
    10131013
     
    12901290        bp_ajax_request = jq.post( ajaxurl, {
    12911291                action: object + '_filter',
    1292                 'cookie': encodeURIComponent(document.cookie),
     1292                'cookie': bp_get_cookies(),
    12931293                'object': object,
    12941294                'filter': filter,
     
    13381338        bp_ajax_request = jq.post( ajaxurl, {
    13391339                action: 'activity_widget_filter',
    1340                 'cookie': encodeURIComponent(document.cookie),
     1340                'cookie': bp_get_cookies(),
    13411341                '_wpnonce_activity_filter': jq("input#_wpnonce_activity_filter").val(),
    13421342                'scope': scope,
     
    14321432}
    14331433
     1434/* Returns a querystring of BP cookies (cookies beginning with 'bp-') */
     1435function bp_get_cookies() {
     1436        // get all cookies and split into an array
     1437        var allCookies   = document.cookie.split(";");
     1438
     1439        var bpCookies    = {};
     1440        var cookiePrefix = 'bp-';
     1441
     1442        // loop through cookies
     1443        for (var i = 0; i < allCookies.length; i++) {
     1444                var cookie    = allCookies[i];
     1445                var delimiter = cookie.indexOf("=");
     1446                var name      = unescape( cookie.slice(0, delimiter) ).trim();
     1447                var value     = unescape( cookie.slice(delimiter + 1) );
     1448
     1449                // if BP cookie, store it
     1450                if ( name.indexOf(cookiePrefix) == 0 ) {
     1451                        bpCookies[name] = value;
     1452                }
     1453        }
     1454
     1455        // returns BP cookies as querystring
     1456        return encodeURIComponent( jq.param(bpCookies) );
     1457}
     1458
    14341459/* ScrollTo plugin - just inline and minified */
    14351460;(function($){var h=$.scrollTo=function(a,b,c){$(window).scrollTo(a,b,c)};h.defaults={axis:'xy',duration:parseFloat($.fn.jquery)>=1.3?0:1,limit:true};h.window=function(a){return $(window)._scrollable()};$.fn._scrollable=function(){return this.map(function(){var a=this,isWin=!a.nodeName||$.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!isWin)return a;var b=(a.contentWindow||a).document||a.ownerDocument||a;return/webkit/i.test(navigator.userAgent)||b.compatMode=='BackCompat'?b.body:b.documentElement})};$.fn.scrollTo=function(e,f,g){if(typeof f=='object'){g=f;f=0}if(typeof g=='function')g={onAfter:g};if(e=='max')e=9e9;g=$.extend({},h.defaults,g);f=f||g.duration;g.queue=g.queue&&g.axis.length>1;if(g.queue)f/=2;g.offset=both(g.offset);g.over=both(g.over);return this._scrollable().each(function(){if(e==null)return;var d=this,$elem=$(d),targ=e,toff,attr={},win=$elem.is('html,body');switch(typeof targ){case'number':case'string':if(/^([+-]=?)?\d+(\.\d+)?(px|%)?$/.test(targ)){targ=both(targ);break}targ=$(targ,this);if(!targ.length)return;case'object':if(targ.is||targ.style)toff=(targ=$(targ)).offset()}$.each(g.axis.split(''),function(i,a){var b=a=='x'?'Left':'Top',pos=b.toLowerCase(),key='scroll'+b,old=d[key],max=h.max(d,a);if(toff){attr[key]=toff[pos]+(win?0:old-$elem.offset()[pos]);if(g.margin){attr[key]-=parseInt(targ.css('margin'+b))||0;attr[key]-=parseInt(targ.css('border'+b+'Width'))||0}attr[key]+=g.offset[pos]||0;if(g.over[pos])attr[key]+=targ[a=='x'?'width':'height']()*g.over[pos]}else{var c=targ[pos];attr[key]=c.slice&&c.slice(-1)=='%'?parseFloat(c)/100*max:c}if(g.limit&&/^\d+$/.test(attr[key]))attr[key]=attr[key]<=0?0:Math.min(attr[key],max);if(!i&&g.queue){if(old!=attr[key])animate(g.onAfterFirst);delete attr[key]}});animate(g.onAfter);function animate(a){$elem.animate(attr,f,g.easing,a&&function(){a.call(this,e,g)})}}).end()};h.max=function(a,b){var c=b=='x'?'Width':'Height',scroll='scroll'+c;if(!$(a).is('html,body'))return a[scroll]-$(a)[c.toLowerCase()]();var d='client'+c,html=a.ownerDocument.documentElement,body=a.ownerDocument.body;return Math.max(html[scroll],body[scroll])-Math.min(html[d],body[d])};function both(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
Note: See TracChangeset for help on using the changeset viewer.