Ticket #5130: 5130.01.patch
| File 5130.01.patch, 12.1 KB (added by , 13 years ago) |
|---|
-
bp-activity/bp-activity-functions.php
function bp_activity_new_comment( $args = '' ) { 1201 1201 // Clear the comment cache for this activity 1202 1202 wp_cache_delete( 'bp_activity_comments_' . $parent_id ); 1203 1203 1204 do_action( 'bp_activity_comment_posted', $comment_id, $params );1204 do_action( 'bp_activity_comment_posted', $comment_id, $params, $activity ); 1205 1205 1206 1206 return $comment_id; 1207 1207 } … … function bp_activity_mark_as_ham( &$activity, $source = 'by_a_person' ) { 1658 1658 do_action( 'bp_activity_mark_as_ham', $activity, $source ); 1659 1659 } 1660 1660 1661 1662 1661 /** Embeds *******************************************************************/ 1663 1662 1664 1663 /** -
bp-blogs/bp-blogs-activity.php
function bp_blogs_delete_activity( $args = true ) { 128 128 'secondary_item_id' => $secondary_item_id 129 129 ) ); 130 130 } 131 132 /** 133 * Syncs activity comments and posts them back as blog comments. 134 * 135 * Note: This is only a one-way sync - activity comments -> blog comment. 136 * 137 * For example, if a blog comment is made from a blog post page, that comment 138 * will *not* be added into the nested blog post's activity item. It will 139 * create a new activity entry. This needs additional R&D. 140 * 141 * @since BuddyPress (1.9) 142 * 143 * @param int $comment_id The activity ID for the posted activity comment. 144 * @param array $params Parameters for the activity comment. 145 * @param obj Parameters of the parent activity item (in this case, the blog post). 146 */ 147 function bp_blogs_sync_add_from_activity_comment( $comment_id, $params, $parent_activity ) { 148 // if parent activity isn't a blog post, stop now! 149 if ( $parent_activity->type != 'new_blog_post' ) { 150 return; 151 } 152 153 // if activity comments are disabled for blog posts, stop now! 154 // 155 // not using bp_disable_blogforum_comments() as that uses bp_get_option(), 156 // which would suck on multisite installs. 157 $cannot_comment = isset( buddypress()->site_options['bp-disable-blogforum-comments'] ) ? buddypress()->site_options['bp-disable-blogforum-comments'] : false; 158 159 // if cannot comment, stop now! 160 if ( $cannot_comment ) { 161 return; 162 } 163 164 // get userdata 165 if ( $params['user_id'] == bp_loggedin_user_id() ) { 166 $user = buddypress()->loggedin_user->userdata; 167 } else { 168 $user = bp_core_get_core_userdata( $params['user_id'] ); 169 } 170 171 // see if a parent WP comment ID exists 172 if ( ! empty( $params['parent_id'] ) ) { 173 $comment_parent = bp_activity_get_meta( $params['parent_id'], 'bp_blogs_post_comment_id' ); 174 } else { 175 $comment_parent = 0; 176 } 177 178 // comment args 179 $args = array( 180 'comment_post_ID' => $parent_activity->secondary_item_id, 181 182 // should this use display name? 183 // using username for now 184 'comment_author' => bp_core_get_username( $params['user_id'], $user->user_nicename, $user->user_login ), 185 186 'comment_author_email' => $user->user_email, 187 'comment_author_url' => bp_core_get_user_domain( $params['user_id'], $user->user_nicename, $user->user_login ), 188 'comment_content' => $params['content'], 189 'comment_type' => '', // could be interesting to add 'buddypress' here... 190 'comment_parent' => (int) $comment_parent, 191 'user_id' => $params['user_id'], 192 193 // commenting these out for now 194 //'comment_author_IP' => '127.0.0.1', 195 //'comment_agent' => '', 196 197 'comment_date' => bp_core_current_time(), 198 'comment_approved' => 1 199 ); 200 201 // prevent separate activity entry being made 202 remove_action( 'comment_post', 'bp_blogs_record_comment', 10, 2 ); 203 204 // handle multisite 205 switch_to_blog( $parent_activity->item_id ); 206 207 // post the comment 208 $post_comment_id = wp_insert_comment( $args ); 209 210 // add meta to comment 211 add_comment_meta( $post_comment_id, 'bp_activity_comment_id', $comment_id ); 212 213 // add meta to activity comment 214 bp_activity_update_meta( $comment_id, 'bp_blogs_post_comment_id', $post_comment_id ); 215 216 // multisite again! 217 restore_current_blog(); 218 219 do_action( 'bp_blogs_sync_add_from_activity_comment', $comment_id, $args, $parent_activity, $user ); 220 } 221 222 /** 223 * Deletes the blog comment when the associated activity comment is deleted. 224 * 225 * @since BuddyPress (1.9) 226 * 227 * @param int $activity_id The activity ID for the posted activity comment. 228 * @param array $params Parameters for the activity comment. 229 * @param obj Parameters of the parent activity item (in this case, the blog post). 230 */ 231 function bp_blogs_sync_delete_from_activity_comment( $activity_id, $comment_id ) { 232 // not using bp_disable_blogforum_comments() as that uses bp_get_option(), 233 // which would suck on multisite installs. 234 $cannot_comment = isset( buddypress()->site_options['bp-disable-blogforum-comments'] ) ? buddypress()->site_options['bp-disable-blogforum-comments'] : false; 235 236 // if cannot comment, stop now! 237 if ( $cannot_comment ) { 238 return; 239 } 240 241 // query args 242 $query_args = array( 243 'meta_query' => array( 244 array( 245 'key' => 'bp_activity_comment_id', 246 'value' => $comment_id 247 ) 248 ) 249 ); 250 251 // get comment 252 $comment_query = new WP_Comment_Query; 253 $comment = $comment_query->query( $query_args ); 254 255 // no comment? stop now! 256 if ( empty( $comment[0] ) ) { 257 return; 258 } else { 259 $comment = $comment[0]; 260 } 261 262 // delete the comment 263 // we force delete the comment, since activity items are deleted immediately 264 wp_delete_comment( $comment->comment_ID, true ); 265 } 266 -
bp-blogs/bp-blogs-functions.php
function bp_blogs_remove_post( $post_id, $blog_id = 0, $user_id = 0 ) { 504 504 add_action( 'delete_post', 'bp_blogs_remove_post' ); 505 505 506 506 function bp_blogs_remove_comment( $comment_id ) { 507 global $wpdb; 507 // get BP's activity comment status for blog / forum posts 508 $cannot_activity_comment = isset( buddypress()->site_options['bp-disable-blogforum-comments'] ) ? buddypress()->site_options['bp-disable-blogforum-comments'] : false; 508 509 509 // Delete activity stream item 510 bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) ); 510 // activity comments are disabled for blog posts 511 // which means that individual activity items exist for blog comments 512 if ( $cannot_activity_comment ) { 513 global $wpdb; 514 515 // Delete the individual activity stream item 516 bp_blogs_delete_activity( array( 'item_id' => $wpdb->blogid, 'secondary_item_id' => $comment_id, 'type' => 'new_blog_comment' ) ); 517 518 // activity comments are enabled for blog posts 519 // remove the associated activity item 520 } else { 521 // get associated activity ID from comment meta 522 $activity_id = get_comment_meta( $comment_id, 'bp_activity_comment_id', true ); 523 524 // delete the associated activity comment 525 // 526 // @todo WP moves nested comments up a level when a comment is deleted, 527 // while BP deletes all nested activity comments... 528 // 529 // right now, we're simply deleting the singular activity comment 530 // with bp_activity_delete() and not using bp_activity_delete_comment() 531 // b/c that deletes activity comment children 532 // 533 // this needs further research: 534 // - how hard would it be to emulate WP's model? 535 // - what would happen if BP_Activity_Activity::rebuild_activity_comment_tree() 536 // is used when the main activity comment is not deleted? 537 bp_activity_delete( array( 538 'id' => $activity_id 539 ) ); 540 } 511 541 512 542 do_action( 'bp_blogs_remove_comment', $wpdb->blogid, $comment_id, bp_loggedin_user_id() ); 513 543 } -
bp-blogs/bp-blogs-loader.php
class BP_Blogs_Component extends BP_Component { 62 62 63 63 // Setup the globals 64 64 parent::setup_globals( $globals ); 65 66 // Activity comment post callback 67 $this->activity_comment_post_callback = apply_filters( 'bp_blogs_activity_comment_post_callback', array( 68 'add' => 'bp_blogs_sync_add_from_activity_comment', 69 'delete' => 'bp_blogs_sync_delete_from_activity_comment' 70 ) ); 65 71 } 66 72 67 73 /** -
bp-core/bp-core-component.php
class BP_Component { 247 247 public function setup_actions() { 248 248 249 249 // Setup globals 250 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ), 10 );250 add_action( 'bp_setup_globals', array( $this, 'setup_globals' ), 10 ); 251 251 252 252 // Include required files. Called early to ensure that BP core 253 253 // components are loaded before plugins that hook their loader functions 254 254 // to bp_include with the default priority of 10. This is for backwards 255 255 // compatibility; henceforth, plugins should register themselves by 256 256 // extending this base class. 257 add_action( 'bp_include', array( $this, 'includes' ), 8);257 add_action( 'bp_include', array( $this, 'includes' ), 10 ); 258 258 259 259 // Setup navigation 260 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 );260 add_action( 'bp_setup_nav', array( $this, 'setup_nav' ), 10 ); 261 261 262 262 // Setup WP Toolbar menus 263 add_action( 'bp_setup_admin_bar', array( $this, 'setup_admin_bar' ), 10 );263 add_action( 'bp_setup_admin_bar', array( $this, 'setup_admin_bar' ), 10 ); 264 264 265 265 // Setup component title 266 add_action( 'bp_setup_title', array( $this, 'setup_title' ), 10 );266 add_action( 'bp_setup_title', array( $this, 'setup_title' ), 10 ); 267 267 268 268 // Register post types 269 add_action( 'bp_register_post_types', array( $this, 'register_post_types' ), 10 );269 add_action( 'bp_register_post_types', array( $this, 'register_post_types' ), 10 ); 270 270 271 271 // Register taxonomies 272 add_action( 'bp_register_taxonomies', array( $this, 'register_taxonomies' ), 10 );272 add_action( 'bp_register_taxonomies', array( $this, 'register_taxonomies' ), 10 ); 273 273 274 274 // Add the rewrite tags 275 add_action( 'bp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10 );275 add_action( 'bp_add_rewrite_tags', array( $this, 'add_rewrite_tags' ), 10 ); 276 276 277 277 // Generate rewrite rules 278 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 ); 278 add_action( 'bp_generate_rewrite_rules', array( $this, 'generate_rewrite_rules' ), 10 ); 279 280 // Activity comment callback setup 281 add_action( 'bp_setup_globals', array( $this, 'activity_comment_post_callback' ), 10 ); 279 282 280 283 // Additional actions can be attached here 281 284 do_action( 'bp_' . $this->id . '_setup_actions' ); … … class BP_Component { 394 397 public function generate_rewrite_rules() { 395 398 do_action( 'bp_' . $this->id . '_generate_rewrite_rules' ); 396 399 } 400 401 /** 402 * Setup activity comment post callbacka. 403 * 404 * If a component has the 'activity_comment_post_callback' property set, 405 * automatically setup the hooks to be used. 406 * 407 * @since BuddyPress (1.9) 408 */ 409 public function activity_comment_post_callback() { 410 // if activity component is not active or callback is not an array, stop now! 411 if ( ! bp_is_active( 'activity' ) || ! is_array( $this->activity_comment_post_callback ) ) { 412 return; 413 } 414 415 $callback = $this->activity_comment_post_callback; 416 417 // Activity comment addition callback 418 if ( ! empty( $callback['add'] ) && is_callable( $callback['add'] ) ) { 419 add_action( 'bp_activity_comment_posted', $callback['add'], 10, 3 ); 420 } 421 422 // Activity comment deletion callback 423 if ( ! empty( $callback['delete'] ) && is_callable( $callback['delete'] ) ) { 424 add_action( 'bp_activity_delete_comment', $callback['delete'], 10, 2 ); 425 } 426 427 } 397 428 } 398 429 endif; // BP_Component
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)