Ticket #4239: 4239.02.patch
File 4239.02.patch, 19.5 KB (added by , 13 years ago) |
---|
-
bp-groups/bp-groups-forums.php
14 14 // Exit if accessed directly 15 15 if ( !defined( 'ABSPATH' ) ) exit; 16 16 17 /** 18 * Creates a new forum inside a specific BuddyPress group. 19 * 20 * Uses the bundled version of bbPress packaged with BuddyPress. 21 * 22 * @param int $group_id The group ID that the new forum should be attached to 23 * @param string $group_name The group name 24 * @param string $group_description The group description 25 * 26 * @since 1.0 27 */ 17 28 function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = '' ) { 18 29 global $bp; 19 30 20 31 if ( empty( $group_id ) ) 21 $group_id = $bp->groups->current_group->id;32 $group_id = bp_get_current_group_id(); 22 33 23 34 if ( empty( $group_name ) ) 24 $group_name = $bp->groups->current_group->name;35 $group_name = bp_get_current_group_name(); 25 36 26 37 if ( empty( $group_desc ) ) 27 38 $group_desc = $bp->groups->current_group->description; … … function groups_new_group_forum( $group_id = 0, $group_name = '', $group_desc = 40 51 * @subpackage Groups 41 52 * 42 53 * @param int $group_id Group id, passed from groups_details_updated 54 * 55 * @since 1.1 43 56 */ 44 57 function groups_update_group_forum( $group_id ) { 45 58 … … function groups_update_group_forum( $group_id ) { 66 79 } 67 80 add_action( 'groups_details_updated', 'groups_update_group_forum' ); 68 81 82 /** 83 * Creates a new group forum post. 84 * 85 * Uses the bundled version of bbPress packaged with BuddyPress. 86 * 87 * @param string $post_text The text for the forum post 88 * @param int $topic_id The topic ID used so we can identify where the new forum post should reside 89 * @param mixed $page The page number where the new forum post should reside. Defaults to boolean false. 90 * @return mixed The new forum post ID on success. Boolean false on failure. 91 * 92 * @since 1.0 93 */ 69 94 function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) { 70 global $bp;71 72 95 if ( empty( $post_text ) ) 73 96 return false; 74 97 … … function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) { 78 101 if ( $post_id = bp_forums_insert_post( array( 'post_text' => $post_text, 'topic_id' => $topic_id ) ) ) { 79 102 $topic = bp_forums_get_topic_details( $topic_id ); 80 103 81 $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name) . '</a>' );104 $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 82 105 $activity_content = bp_create_excerpt( $post_text ); 83 $primary_link = bp_get_group_permalink( $bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';106 $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/'; 84 107 85 108 if ( $page ) 86 109 $primary_link .= "?topic_page=" . $page; 87 110 88 111 // Record this in activity streams 89 112 groups_record_activity( array( 90 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', 91 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', 113 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_id, $post_text, &$topic ) ), 114 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_id, $post_text, &$topic ) ), 92 115 'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', "{$primary_link}#post-{$post_id}" ), 93 116 'type' => 'new_forum_post', 94 'item_id' => $bp->groups->current_group->id,117 'item_id' => bp_get_current_group_id(), 95 118 'secondary_item_id' => $post_id 96 119 ) ); 97 120 98 do_action( 'groups_new_forum_topic_post', $bp->groups->current_group->id, $post_id );121 do_action( 'groups_new_forum_topic_post', bp_get_current_group_id(), $post_id ); 99 122 100 123 return $post_id; 101 124 } … … function groups_new_group_forum_post( $post_text, $topic_id, $page = false ) { 103 126 return false; 104 127 } 105 128 129 /** 130 * Creates a new group forum topic. 131 * 132 * Uses the bundled version of bbPress packaged with BuddyPress. 133 * 134 * @param string $topic_title The title for the forum topic 135 * @param string $topic_text The text for the forum topic 136 * @param string $topic_tags A comma-delimited string of topic tags 137 * @param int $forum_id The forum ID this forum topic resides in 138 * @return mixed The new topic object on success. Boolean false on failure. 139 * 140 * @since 1.0 141 */ 106 142 function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $forum_id ) { 107 global $bp;108 109 143 if ( empty( $topic_title ) || empty( $topic_text ) ) 110 144 return false; 111 145 … … function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $ 117 151 if ( $topic_id = bp_forums_new_topic( array( 'topic_title' => $topic_title, 'topic_text' => $topic_text, 'topic_tags' => $topic_tags, 'forum_id' => $forum_id ) ) ) { 118 152 $topic = bp_forums_get_topic_details( $topic_id ); 119 153 120 $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name) . '</a>' );154 $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( bp_loggedin_user_id() ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 121 155 $activity_content = bp_create_excerpt( $topic_text ); 122 156 123 157 // Record this in activity streams 124 158 groups_record_activity( array( 125 159 'action' => apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ), 126 160 'content' => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ), 127 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/' ),161 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ), 128 162 'type' => 'new_forum_topic', 129 'item_id' => $bp->groups->current_group->id,163 'item_id' => bp_get_current_group_id(), 130 164 'secondary_item_id' => $topic->topic_id 131 165 ) ); 132 166 133 do_action_ref_array( 'groups_new_forum_topic', array( $bp->groups->current_group->id, &$topic ) );167 do_action_ref_array( 'groups_new_forum_topic', array( bp_get_current_group_id(), &$topic ) ); 134 168 135 169 return $topic; 136 170 } … … function groups_new_group_forum_topic( $topic_title, $topic_text, $topic_tags, $ 138 172 return false; 139 173 } 140 174 175 /** 176 * Updates an existing group forum topic. 177 * 178 * Uses the bundled version of bbPress packaged with BuddyPress. 179 * 180 * @param int $topic_id The topic ID of the existing forum topic 181 * @param string $topic_title The title for the forum topic 182 * @param string $topic_text The text for the forum topic 183 * @param mixed $topic_tags A comma-delimited string of topic tags. Defaults to boolean false. 184 * @return mixed The topic object on success. Boolean false on failure. 185 * 186 * @since 1.1 187 */ 141 188 function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, $topic_tags = false ) { 142 189 global $bp; 143 190 … … function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, 149 196 // Get the corresponding activity item 150 197 if ( bp_is_active( 'activity' ) ) { 151 198 $id = bp_activity_get_activity_id( array( 152 'item_id' => $bp->groups->current_group->id,199 'item_id' => bp_get_current_group_id(), 153 200 'secondary_item_id' => $topic_id, 154 201 'component' => $bp->groups->id, 155 202 'type' => 'new_forum_topic' 156 203 ) ); 157 204 } 158 205 159 $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name) . '</a>' );206 $activity_action = sprintf( __( '%1$s started the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $topic->topic_poster ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'/">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 160 207 $activity_content = bp_create_excerpt( $topic_text ); 161 208 162 209 // Record this in activity streams … … function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, 164 211 'id' => $id, 165 212 'action' => apply_filters_ref_array( 'groups_activity_new_forum_topic_action', array( $activity_action, $topic_text, &$topic ) ), 166 213 'content' => apply_filters_ref_array( 'groups_activity_new_forum_topic_content', array( $activity_content, $topic_text, &$topic ) ), 167 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( $bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/' ),214 'primary_link' => apply_filters( 'groups_activity_new_forum_topic_primary_link', bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/' ), 168 215 'type' => 'new_forum_topic', 169 'item_id' => (int) $bp->groups->current_group->id,216 'item_id' => (int) bp_get_current_group_id(), 170 217 'user_id' => (int) $topic->topic_poster, 171 218 'secondary_item_id' => $topic->topic_id, 172 219 'recorded_time ' => $topic->topic_time … … function groups_update_group_forum_topic( $topic_id, $topic_title, $topic_text, 180 227 return false; 181 228 } 182 229 230 /** 231 * Updates an existing group forum post. 232 * 233 * Uses the bundled version of bbPress packaged with BuddyPress. 234 * 235 * @param int $post_id The post ID of the existing forum post 236 * @param string $post_text The text for the forum post 237 * @param int $topic_id The topic ID of the existing forum topic 238 * @param mixed $page The page number where the new forum post should reside. Defaults to boolean false. 239 * @return mixed The forum post ID on success. Boolean false on failure. 240 * 241 * @since 1.1 242 */ 183 243 function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page = false ) { 184 244 global $bp; 185 245 … … function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page 190 250 if ( $post_id = bp_forums_insert_post( array( 'post_id' => $post_id, 'post_text' => $post_text, 'post_time' => $post->post_time, 'topic_id' => $topic_id, 'poster_id' => $post->poster_id ) ) ) { 191 251 $topic = bp_forums_get_topic_details( $topic_id ); 192 252 193 $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $post->poster_id ), '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . 'forum/topic/' . $topic->topic_slug .'">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( $bp->groups->current_group ) . '">' . esc_attr( $bp->groups->current_group->name) . '</a>' );253 $activity_action = sprintf( __( '%1$s replied to the forum topic %2$s in the group %3$s', 'buddypress'), bp_core_get_userlink( $post->poster_id ), '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug .'">' . esc_attr( $topic->topic_title ) . '</a>', '<a href="' . bp_get_group_permalink( groups_get_current_group() ) . '">' . esc_attr( bp_get_current_group_name() ) . '</a>' ); 194 254 $activity_content = bp_create_excerpt( $post_text ); 195 $primary_link = bp_get_group_permalink( $bp->groups->current_group) . 'forum/topic/' . $topic->topic_slug . '/';255 $primary_link = bp_get_group_permalink( groups_get_current_group() ) . 'forum/topic/' . $topic->topic_slug . '/'; 196 256 197 257 if ( $page ) 198 258 $primary_link .= "?topic_page=" . $page; 199 259 200 // Fetch an existing entry and update if one exists. 201 if ( bp_is_active( 'activity' ) ) 202 $id = bp_activity_get_activity_id( array( 'user_id' => $post->poster_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post', 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id ) ); 260 // Get the corresponding activity item 261 if ( bp_is_active( 'activity' ) ) { 262 $id = bp_activity_get_activity_id( array( 263 'user_id' => $post->poster_id, 264 'component' => $bp->groups->id, 265 'type' => 'new_forum_post', 266 'item_id' => bp_get_current_group_id(), 267 'secondary_item_id' => $post_id 268 ) ); 269 } 203 270 204 271 // Update the entry in activity streams 205 272 groups_record_activity( array( 206 273 'id' => $id, 207 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_text, &$topic, &$ forum_post) ),208 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_text, &$topic, &$ forum_post) ),274 'action' => apply_filters_ref_array( 'groups_activity_new_forum_post_action', array( $activity_action, $post_text, &$topic, &$topic ) ), 275 'content' => apply_filters_ref_array( 'groups_activity_new_forum_post_content', array( $activity_content, $post_text, &$topic, &$topic ) ), 209 276 'primary_link' => apply_filters( 'groups_activity_new_forum_post_primary_link', $primary_link . "#post-" . $post_id ), 210 277 'type' => 'new_forum_post', 211 'item_id' => (int) $bp->groups->current_group->id,278 'item_id' => (int) bp_get_current_group_id(), 212 279 'user_id' => (int) $post->poster_id, 213 280 'secondary_item_id' => $post_id, 214 281 'recorded_time' => $post->post_time … … function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page 223 290 } 224 291 225 292 /** 226 * Handles the forum topic deletion routine 293 * Deletes a group forum topic and also any corresponding activity items. 294 * 295 * Uses the bundled version of bbPress packaged with BuddyPress. 227 296 * 228 297 * @package BuddyPress 229 298 * … … function groups_update_group_forum_post( $post_id, $post_text, $topic_id, $page 232 301 * @uses bp_forums_delete_topic() to do the deletion itself 233 302 * @param int $topic_id The id of the topic to be deleted 234 303 * @return bool True if the delete routine went through properly 304 * 305 * @since 1.1 235 306 */ 236 307 function groups_delete_group_forum_topic( $topic_id ) { 237 308 global $bp; … … function groups_delete_group_forum_topic( $topic_id ) { 242 313 if ( bp_forums_delete_topic( array( 'topic_id' => $topic_id ) ) ) { 243 314 do_action( 'groups_before_delete_group_forum_topic', $topic_id ); 244 315 245 // Delete the activity stream items316 // Delete the corresponding activity stream items 246 317 if ( bp_is_active( 'activity' ) ) { 247 318 // The activity item for the initial topic 248 bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $topic_id, 'component' => $bp->groups->id, 'type' => 'new_forum_topic' ) ); 319 bp_activity_delete( array( 320 'item_id' => bp_get_current_group_id(), 321 'secondary_item_id' => $topic_id, 322 'component' => $bp->groups->id, 323 'type' => 'new_forum_topic' 324 ) ); 249 325 250 326 // The activity item for each post 251 327 foreach ( (array) $posts as $post ) { 252 bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post->post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) ); 328 bp_activity_delete( array( 329 'item_id' => bp_get_current_group_id(), 330 'secondary_item_id' => $post->post_id, 331 'component' => $bp->groups->id, 332 'type' => 'new_forum_post' 333 ) ); 253 334 } 254 335 } 255 336 … … function groups_delete_group_forum_topic( $topic_id ) { 262 343 } 263 344 264 345 /** 265 * Delete a forum post 346 * Deletes a group forum post and its corresponding activity item. 347 * 348 * Uses the bundled version of bbPress packaged with BuddyPress. 266 349 * 267 350 * @package BuddyPress 268 351 * … … function groups_delete_group_forum_topic( $topic_id ) { 270 353 * @param int $topic_id Optional. The topic to which the post belongs. This value isn't used in the 271 354 * function but is passed along to do_action() hooks. 272 355 * @return bool True on success. 356 * 357 * @since 1.1 273 358 */ 274 359 function groups_delete_group_forum_post( $post_id, $topic_id = false ) { 275 360 global $bp; … … function groups_delete_group_forum_post( $post_id, $topic_id = false ) { 277 362 if ( bp_forums_delete_post( array( 'post_id' => $post_id ) ) ) { 278 363 do_action( 'groups_before_delete_group_forum_post', $post_id, $topic_id ); 279 364 280 // Delete the activity stream item365 // Delete the corresponding activity stream item 281 366 if ( bp_is_active( 'activity' ) ) 282 bp_activity_delete( array( 'item_id' => $bp->groups->current_group->id, 'secondary_item_id' => $post_id, 'component' => $bp->groups->id, 'type' => 'new_forum_post' ) ); 367 bp_activity_delete( array( 368 'item_id' => bp_get_current_group_id(), 369 'secondary_item_id' => $post_id, 370 'component' => $bp->groups->id, 371 'type' => 'new_forum_post' 372 ) ); 283 373 284 374 do_action( 'groups_delete_group_forum_post', $post_id, $topic_id ); 285 375 … … function groups_delete_group_forum_post( $post_id, $topic_id = false ) { 289 379 return false; 290 380 } 291 381 382 /** 383 * Get a total count of all public topics of a given type, across groups/forums 384 * 385 * @package BuddyPress 386 * @since 1.5 387 * 388 * @param string $type Either 'newest', 'popular', 'unreplied', 'tags'. Defaults to 'newest'. 389 * @return int The topic count 390 */ 292 391 function groups_total_public_forum_topic_count( $type = 'newest' ) { 293 392 return apply_filters( 'groups_total_public_forum_topic_count', BP_Groups_Group::get_global_forum_topic_count( $type ) ); 294 393 } … … function groups_total_public_forum_topic_count( $type = 'newest' ) { 297 396 * Get a total count of all topics of a given status, across groups/forums 298 397 * 299 398 * @package BuddyPress 300 * @since BuddyPress (1.5)399 * @since 1.5 301 400 * 302 401 * @param str $status 'public', 'private', 'hidden', 'all' Which group types to count 303 402 * @return int The topic count