<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[BuddyPress][5912] branches/1.5/bp-themes/bp-default/_inc/ajax.php: Bail early in bp-default ajax functions if not a POST request.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg > ul, #logmsg > ol { margin-left: 0; margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://buddypress.trac.wordpress.org/changeset/5912">5912</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-03-13 21:34:08 +0000 (Tue, 13 Mar 2012)</dd>
</dl>
<h3>Log Message</h3>
<pre>Bail early in bp-default ajax functions if not a POST request. (branches/1.5)</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branches15bpthemesbpdefault_incajaxphp">branches/1.5/bp-themes/bp-default/_inc/ajax.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branches15bpthemesbpdefault_incajaxphp"></a>
<div class="modfile"><h4>Modified: branches/1.5/bp-themes/bp-default/_inc/ajax.php (5911 => 5912)</h4>
<pre class="diff"><span>
<span class="info">--- branches/1.5/bp-themes/bp-default/_inc/ajax.php        2012-03-13 21:26:35 UTC (rev 5911)
+++ branches/1.5/bp-themes/bp-default/_inc/ajax.php        2012-03-13 21:34:08 UTC (rev 5912)
</span><span class="lines">@@ -84,6 +84,10 @@
</span><span class="cx"> /* This function will simply load the template loop for the current object. On an AJAX request */
</span><span class="cx"> function bp_dtheme_object_template_loader() {
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         /**
</span><span class="cx">          * AJAX requests happen too early to be seen by bp_update_is_directory()
</span><span class="cx">          * so we do it manually here to ensure templates load with the correct
</span><span class="lines">@@ -108,6 +112,10 @@
</span><span class="cx"> function bp_dtheme_activity_template_loader() {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         $scope = '';
</span><span class="cx">         if ( !empty( $_POST['scope'] ) )
</span><span class="cx">                 $scope = $_POST['scope'];
</span><span class="lines">@@ -135,6 +143,7 @@
</span><span class="cx">         /* Buffer the loop in the template to a var for JS to spit out. */
</span><span class="cx">         ob_start();
</span><span class="cx">         locate_template( array( 'activity/activity-loop.php' ), true );
</span><ins>+        $result = array();
</ins><span class="cx">         $result['contents'] = ob_get_contents();
</span><span class="cx">         $result['feed_url'] = apply_filters( 'bp_dtheme_activity_feed_url', $feed_url, $scope );
</span><span class="cx">         ob_end_clean();
</span><span class="lines">@@ -146,8 +155,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX update posting */
</span><span class="cx"> function bp_dtheme_post_update() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         // Check the nonce
</span><span class="cx">         check_admin_referer( 'post_update', '_wpnonce_post_update' );
</span><span class="cx">
</span><span class="lines">@@ -188,8 +200,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX activity comment posting */
</span><span class="cx"> function bp_dtheme_new_activity_comment() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         // Check the nonce
</span><span class="cx">         check_admin_referer( 'new_activity_comment', '_wpnonce_new_activity_comment' );
</span><span class="cx">
</span><span class="lines">@@ -245,8 +260,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX delete an activity */
</span><span class="cx"> function bp_dtheme_delete_activity() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         // Check the nonce
</span><span class="cx">         check_admin_referer( 'bp_activity_delete_link' );
</span><span class="cx">
</span><span class="lines">@@ -286,6 +304,10 @@
</span><span class="cx"> function bp_dtheme_delete_activity_comment() {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         /* Check the nonce */
</span><span class="cx">         check_admin_referer( 'bp_activity_delete_link' );
</span><span class="cx">
</span><span class="lines">@@ -319,8 +341,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX mark an activity as a favorite */
</span><span class="cx"> function bp_dtheme_mark_activity_favorite() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         bp_activity_add_user_favorite( $_POST['id'] );
</span><span class="cx">         _e( 'Remove Favorite', 'buddypress' );
</span><span class="cx"> }
</span><span class="lines">@@ -328,8 +353,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX mark an activity as not a favorite */
</span><span class="cx"> function bp_dtheme_unmark_activity_favorite() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         bp_activity_remove_user_favorite( $_POST['id'] );
</span><span class="cx">         _e( 'Favorite', 'buddypress' );
</span><span class="cx"> }
</span><span class="lines">@@ -367,6 +395,10 @@
</span><span class="cx"> function bp_dtheme_ajax_invite_user() {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         check_ajax_referer( 'groups_invite_uninvite_user' );
</span><span class="cx">
</span><span class="cx">         if ( !$_POST['friend_id'] || !$_POST['friend_action'] || !$_POST['group_id'] )
</span><span class="lines">@@ -411,6 +443,10 @@
</span><span class="cx"> function bp_dtheme_ajax_addremove_friend() {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         if ( 'is_friend' == BP_Friends_Friendship::check_is_friend( $bp->loggedin_user->id, $_POST['fid'] ) ) {
</span><span class="cx">
</span><span class="cx">                 check_ajax_referer('friends_remove_friend');
</span><span class="lines">@@ -440,6 +476,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX accept a user as a friend when clicking the "accept" button */
</span><span class="cx"> function bp_dtheme_ajax_accept_friendship() {
</span><ins>+
+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         check_admin_referer( 'friends_accept_friendship' );
</span><span class="cx">
</span><span class="cx">         if ( !friends_accept_friendship( $_POST['id'] ) )
</span><span class="lines">@@ -451,6 +492,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX reject a user as a friend when clicking the "reject" button */
</span><span class="cx"> function bp_dtheme_ajax_reject_friendship() {
</span><ins>+
+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         check_admin_referer( 'friends_reject_friendship' );
</span><span class="cx">
</span><span class="cx">         if ( !friends_reject_friendship( $_POST['id'] ) )
</span><span class="lines">@@ -464,6 +510,10 @@
</span><span class="cx"> function bp_dtheme_ajax_joinleave_group() {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         if ( groups_is_user_banned( $bp->loggedin_user->id, $_POST['gid'] ) )
</span><span class="cx">                 return false;
</span><span class="cx">
</span><span class="lines">@@ -514,6 +564,10 @@
</span><span class="cx"> function bp_dtheme_ajax_close_notice() {
</span><span class="cx">         global $userdata;
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         if ( !isset( $_POST['notice_id'] ) ) {
</span><span class="cx">                 echo "-1<div id='message' class='error'><p>" . __('There was a problem closing the notice.', 'buddypress') . '</p></div>';
</span><span class="cx">         } else {
</span><span class="lines">@@ -530,6 +584,10 @@
</span><span class="cx"> function bp_dtheme_ajax_messages_send_reply() {
</span><span class="cx">         global $bp;
</span><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         check_ajax_referer( 'messages_send_message' );
</span><span class="cx">
</span><span class="cx">         $result = messages_new_message( array( 'thread_id' => $_REQUEST['thread_id'], 'content' => $_REQUEST['content'] ) );
</span><span class="lines">@@ -564,8 +622,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX mark a private message as unread in your inbox */
</span><span class="cx"> function bp_dtheme_ajax_message_markunread() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         if ( !isset($_POST['thread_ids']) ) {
</span><span class="cx">                 echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as unread.', 'buddypress' ) . '</p></div>';
</span><span class="cx">         } else {
</span><span class="lines">@@ -580,8 +641,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX mark a private message as read in your inbox */
</span><span class="cx"> function bp_dtheme_ajax_message_markread() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         if ( !isset($_POST['thread_ids']) ) {
</span><span class="cx">                 echo "-1<div id='message' class='error'><p>" . __('There was a problem marking messages as read.', 'buddypress' ) . '</p></div>';
</span><span class="cx">         } else {
</span><span class="lines">@@ -596,8 +660,11 @@
</span><span class="cx">
</span><span class="cx"> /* AJAX delete a private message or array of messages in your inbox */
</span><span class="cx"> function bp_dtheme_ajax_messages_delete() {
</span><del>-        global $bp;
</del><span class="cx">
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         if ( !isset($_POST['thread_ids']) ) {
</span><span class="cx">                 echo "-1<div id='message' class='error'><p>" . __( 'There was a problem deleting messages.', 'buddypress' ) . '</p></div>';
</span><span class="cx">         } else {
</span><span class="lines">@@ -626,11 +693,9 @@
</span><span class="cx">         if ( $bp->messages->slug == $bp->current_component )
</span><span class="cx">                 $autocomplete_all = $bp->messages->autocomplete_all;
</span><span class="cx">
</span><del>-        $friends = false;
</del><span class="cx">         $pag_page = 1;
</span><ins>+        $limit = !empty( $_GET['limit'] ) ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 );
</ins><span class="cx">
</span><del>-        $limit = $_GET['limit'] ? $_GET['limit'] : apply_filters( 'bp_autocomplete_max_results', 10 );
-
</del><span class="cx">         // Get the user ids based on the search terms
</span><span class="cx">         if ( !empty( $autocomplete_all ) ) {
</span><span class="cx">                 $users = BP_Core_User::search_users( $_GET['q'], $limit, $pag_page );
</span></span></pre>
</div>
</div>
</body>
</html>