<!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][5908] trunk/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/5908">5908</a></dd>
<dt>Author</dt> <dd>johnjamesjacoby</dd>
<dt>Date</dt> <dd>2012-03-13 20:33:06 +0000 (Tue, 13 Mar 2012)</dd>
</dl>

<h3>Log Message</h3>
<pre>Bail early in bp-default ajax functions if not a POST request.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkbpthemesbpdefault_incajaxphp">trunk/bp-themes/bp-default/_inc/ajax.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkbpthemesbpdefault_incajaxphp"></a>
<div class="modfile"><h4>Modified: trunk/bp-themes/bp-default/_inc/ajax.php (5907 => 5908)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/bp-themes/bp-default/_inc/ajax.php        2012-03-11 17:36:10 UTC (rev 5907)
+++ trunk/bp-themes/bp-default/_inc/ajax.php        2012-03-13 20:33:06 UTC (rev 5908)
</span><span class="lines">@@ -85,6 +85,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">@@ -117,6 +121,10 @@
</span><span class="cx"> // This function will load the activity loop template when activity is requested via AJAX
</span><span class="cx"> function bp_dtheme_activity_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">         $scope = '';
</span><span class="cx">         if ( !empty( $_POST['scope'] ) )
</span><span class="cx">                 $scope = $_POST['scope'];
</span><span class="lines">@@ -156,6 +164,10 @@
</span><span class="cx"> /* AJAX update posting */
</span><span class="cx"> function bp_dtheme_post_update() {
</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( 'post_update', '_wpnonce_post_update' );
</span><span class="cx"> 
</span><span class="lines">@@ -197,6 +209,10 @@
</span><span class="cx"> /* AJAX activity comment posting */
</span><span class="cx"> function bp_dtheme_new_activity_comment() {
</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( 'new_activity_comment', '_wpnonce_new_activity_comment' );
</span><span class="cx"> 
</span><span class="lines">@@ -253,6 +269,10 @@
</span><span class="cx"> /* AJAX delete an activity */
</span><span class="cx"> function bp_dtheme_delete_activity() {
</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">@@ -291,6 +311,10 @@
</span><span class="cx"> /* AJAX delete an activity comment */
</span><span class="cx"> function bp_dtheme_delete_activity_comment() {
</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">@@ -331,6 +355,10 @@
</span><span class="cx"> function bp_dtheme_spam_activity() {
</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 that user is logged in, Activity Streams are enabled, and Akismet is present.
</span><span class="cx">         if ( !is_user_logged_in() || !bp_is_active( 'activity' ) || empty( $bp-&gt;activity-&gt;akismet ) ) {
</span><span class="cx">                 echo '-1';
</span><span class="lines">@@ -373,6 +401,10 @@
</span><span class="cx"> /* AJAX mark an activity as a favorite */
</span><span class="cx"> function bp_dtheme_mark_activity_favorite() {
</span><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">@@ -381,6 +413,10 @@
</span><span class="cx"> /* AJAX mark an activity as not a favorite */
</span><span class="cx"> function bp_dtheme_unmark_activity_favorite() {
</span><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">@@ -393,6 +429,10 @@
</span><span class="cx">  * @since 1.5
</span><span class="cx">  */
</span><span class="cx"> function bp_dtheme_get_single_activity_content() {
</span><ins>+        // Bail if not a POST action
+        if ( 'POST' !== strtoupper( $_SERVER['REQUEST_METHOD'] ) )
+                return;
+
</ins><span class="cx">         $activity_array = bp_activity_get_specific( array(
</span><span class="cx">                 'activity_ids'     =&gt; $_POST['activity_id'],
</span><span class="cx">                 'display_comments' =&gt; 'stream'
</span><span class="lines">@@ -400,7 +440,7 @@
</span><span class="cx"> 
</span><span class="cx">         $activity = !empty( $activity_array['activities'][0] ) ? $activity_array['activities'][0] : false;
</span><span class="cx"> 
</span><del>-        if ( !$activity )
</del><ins>+        if ( empty( $activity ) )
</ins><span class="cx">                 exit(); // todo: error?
</span><span class="cx"> 
</span><span class="cx">         do_action_ref_array( 'bp_dtheme_get_single_activity_content', array( &amp;$activity ) );
</span><span class="lines">@@ -417,6 +457,10 @@
</span><span class="cx"> /* AJAX invite a friend to a group functionality */
</span><span class="cx"> function bp_dtheme_ajax_invite_user() {
</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">@@ -460,6 +504,10 @@
</span><span class="cx"> /* AJAX add/remove a user as a friend when clicking the button */
</span><span class="cx"> function bp_dtheme_ajax_addremove_friend() {
</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">@@ -489,6 +537,11 @@
</span><span class="cx"> 
</span><span class="cx"> /* AJAX accept a user as a friend when clicking the &quot;accept&quot; 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">@@ -500,6 +553,10 @@
</span><span class="cx"> 
</span><span class="cx"> /* AJAX reject a user as a friend when clicking the &quot;reject&quot; 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">@@ -512,6 +569,10 @@
</span><span class="cx"> /* AJAX join or leave a group when clicking the &quot;join/leave&quot; button */
</span><span class="cx"> function bp_dtheme_ajax_joinleave_group() {
</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">@@ -562,6 +623,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 &quot;-1&lt;div id='message' class='error'&gt;&lt;p&gt;&quot; . __('There was a problem closing the notice.', 'buddypress') . '&lt;/p&gt;&lt;/div&gt;';
</span><span class="cx">         } else {
</span><span class="lines">@@ -578,6 +643,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' =&gt; $_REQUEST['thread_id'], 'content' =&gt; $_REQUEST['content'] ) );
</span><span class="lines">@@ -613,6 +682,10 @@
</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><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 &quot;-1&lt;div id='message' class='error'&gt;&lt;p&gt;&quot; . __('There was a problem marking messages as unread.', 'buddypress' ) . '&lt;/p&gt;&lt;/div&gt;';
</span><span class="cx">         } else {
</span><span class="lines">@@ -628,6 +701,10 @@
</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><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 &quot;-1&lt;div id='message' class='error'&gt;&lt;p&gt;&quot; . __('There was a problem marking messages as read.', 'buddypress' ) . '&lt;/p&gt;&lt;/div&gt;';
</span><span class="cx">         } else {
</span><span class="lines">@@ -643,6 +720,10 @@
</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><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 &quot;-1&lt;div id='message' class='error'&gt;&lt;p&gt;&quot; . __( 'There was a problem deleting messages.', 'buddypress' ) . '&lt;/p&gt;&lt;/div&gt;';
</span><span class="cx">         } else {
</span></span></pre>
</div>
</div>

</body>
</html>