Changeset 5435 for trunk/bp-activity/bp-activity-admin.php
- Timestamp:
- 12/03/2011 03:42:58 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/bp-activity/bp-activity-admin.php
r5427 r5435 18 18 19 19 // per_page screen option. Has to be hooked in extremely early. 20 add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 ); 20 if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] ) 21 add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 ); 21 22 22 23 /** … … 122 123 */ 123 124 function bp_activity_admin_screen_options( $value, $option, $new_value ) { 124 if ( 'toplevel_page_bp_activity_ settings_per_page' != $option )125 if ( 'toplevel_page_bp_activity_per_page' != $option ) 125 126 return $value; 126 127 … … 142 143 global $bp_activity_list_table; 143 144 144 // Create the Activity screen list table 145 $bp_activity_list_table = new BP_Activity_List_Table(); 145 // Decide whether to load the dev version of the CSS and JavaScript 146 $dev = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'dev.' : ''; 147 148 // Decide whether to load the index or edit screen 149 $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; 146 150 147 151 // Edit screen 148 if ( 'edit' == $bp_activity_list_table->current_action() && !empty( $_GET['aid'] ) ) { 149 // @todo Contextual help for the edit screen 152 if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) { 153 get_current_screen()->add_help_tab( array( 154 'id' => 'bp-activity-edit-overview', 155 'title' => __( 'Overview', 'buddypress' ), 156 'content' => 157 '<p>' . __( 'You can edit activities made on your site similar to the way you edit a comment. This is useful if you need to change which page the activity links to, or when you notice that the author has made a typographical error.', 'buddypress' ) . '</p>' . 158 '<p>' . __( 'You can also moderate the activity from this screen using the Status box, where you can also change the timestamp of the activity.', 'buddypress' ) . '</p>' 159 ) ); 160 161 // Register metaboxes for the edit screen. 162 add_meta_box( 'submitdiv', _x( 'Status', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_status', 'toplevel_page_bp-activity', 'side', 'core' ); 163 164 // Enqueue javascripts 165 wp_enqueue_script( 'postbox' ); 166 wp_enqueue_script( 'dashboard' ); 167 wp_enqueue_script( 'comment' ); 168 169 // Enqueue CSS 170 wp_enqueue_style( 'bp_activity_admin_css', BP_PLUGIN_URL . "bp-activity/admin/css/admin.{$dev}css", array(), '20111203' ); 150 171 151 172 // Index screen 152 173 } else { 174 // Create the Activity screen list table 175 $bp_activity_list_table = new BP_Activity_List_Table(); 176 153 177 // per_page screen option 154 178 add_screen_option( 'per_page', array( 'label' => _x( 'Activities', 'Activity items per page (screen options)', 'buddypress' )) ); … … 163 187 ) ); 164 188 165 // Help panel - moderation text189 // Help panel - moderation text 166 190 get_current_screen()->add_help_tab( array( 167 191 'id' => 'bp-activity-moderating', … … 175 199 176 200 // Enqueue CSS and JavaScript 177 $dev = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? 'dev.' : '';178 201 wp_enqueue_script( 'bp_activity_admin_js', BP_PLUGIN_URL . "bp-activity/admin/js/admin.{$dev}js", array( 'jquery', 'wp-ajax-response' ), '20111120' ); 179 wp_enqueue_style( 'bp_activity_admin_css', BP_PLUGIN_URL . "bp-activity/admin/css/admin.{$dev}css", array(), '20111 126' );202 wp_enqueue_style( 'bp_activity_admin_css', BP_PLUGIN_URL . "bp-activity/admin/css/admin.{$dev}css", array(), '20111203' ); 180 203 } 181 204 … … 187 210 188 211 // Handle spam/un-spam/delete of activities 189 $doaction = $bp_activity_list_table->current_action(); 190 if ( $doaction && 'edit' != $doaction ) { 212 if ( $doaction && ! in_array( $doaction, array( '-1', 'edit', 'save', ) ) ) { 191 213 192 214 // Build redirection URL … … 295 317 exit; 296 318 319 320 // Save the edit 321 } elseif ( $doaction && 'save' == $doaction ) { 322 // Build redirection URL 323 $redirect_to = remove_query_arg( array( 'action', 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] ); 324 325 // Get activity ID 326 $activity_id = (int) $_REQUEST['aid']; 327 328 // Check this is a valid form submission 329 check_admin_referer( 'edit-activity_' . $activity_id ); 330 331 // Get the activity from the database 332 $activity = new BP_Activity_Activity( $activity_id ); 333 334 // If the activity doesn't exist, just redirect back to the index 335 if ( empty( $activity->component ) ) { 336 wp_redirect( $redirect_to ); 337 exit; 338 } 339 340 // Check the form for the updated properties 341 342 // Store any error that occurs when updating the database item 343 $error = 0; 344 345 // Set tainted if a new form value is different from the object's old value 346 $tainted = false; 347 348 // Activity spam status 349 if ( ! empty( $_REQUEST['activity_status'] ) ) { 350 $prev_spam_status = $activity->is_spam; 351 $new_spam_status = ( 'spam' == $_REQUEST['activity_status'] ) ? 1 : 0; 352 } 353 354 // Activity action 355 if ( ! empty( $_REQUEST['bp-activities-action'] ) && stripslashes( $activity->action ) != stripslashes( $_REQUEST['bp-activities-action'] ) ) { 356 $activity->action = $_REQUEST['bp-activities-action']; 357 $tainted = true; 358 } 359 360 // Activity content 361 if ( ! empty( $_REQUEST['bp-activities-content'] ) && stripslashes( $activity->content ) != stripslashes( $_REQUEST['bp-activities-content'] ) ) { 362 $activity->content = $_REQUEST['bp-activities-content']; 363 $tainted = true; 364 } 365 366 // Activity timestamp 367 if ( ! empty( $_REQUEST['aa'] ) && ! empty( $_REQUEST['mm'] ) && ! empty( $_REQUEST['jj'] ) && ! empty( $_REQUEST['hh'] ) && ! empty( $_REQUEST['mn'] ) && ! empty( $_REQUEST['ss'] ) ) { 368 $aa = $_REQUEST['aa']; 369 $mm = $_REQUEST['mm']; 370 $jj = $_REQUEST['jj']; 371 $hh = $_REQUEST['hh']; 372 $mn = $_REQUEST['mn']; 373 $ss = $_REQUEST['ss']; 374 $aa = ( $aa <= 0 ) ? date( 'Y' ) : $aa; 375 $mm = ( $mm <= 0 ) ? date( 'n' ) : $mm; 376 $jj = ( $jj > 31 ) ? 31 : $jj; 377 $jj = ( $jj <= 0 ) ? date( 'j' ) : $jj; 378 $hh = ( $hh > 23 ) ? $hh -24 : $hh; 379 $mn = ( $mn > 59 ) ? $mn -60 : $mn; 380 $ss = ( $ss > 59 ) ? $ss -60 : $ss; 381 382 // Reconstruct the date into a timestamp. Convert it to GMT. 383 $gmt_date = get_gmt_from_date( sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss ) ); 384 385 if ( $activity->date_recorded != $gmt_date ) { 386 $activity->date_recorded = $gmt_date; 387 $tainted = true; 388 } 389 } 390 391 // Has the spam status has changed? 392 if ( $prev_spam_status != $new_spam_status ) { 393 if ( 1 == $new_spam_status) 394 bp_activity_mark_as_spam( $activity ); 395 else 396 bp_activity_mark_as_ham( $activity ); 397 398 $tainted = true; 399 } 400 401 // Save 402 $result = $activity->save(); 403 404 // Clear the activity stream first page cache, in case this activity's timestamp was changed 405 wp_cache_delete( 'bp_activity_sitewide_front', 'bp' ); 406 407 // Check for any error during activity save 408 if ( ! $result && $tainted ) 409 $error = $activity->id; 410 411 // If an error occured, pass back the activity ID that failed 412 if ( $error ) 413 $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to ); 414 else 415 $redirect_to = add_query_arg( 'updated', (int) $activity->id, $redirect_to ); 416 417 // Redirect 418 wp_redirect( $redirect_to ); 419 exit; 420 421 297 422 // If a referrer and a nonce is supplied, but no action, redirect back. 298 423 } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) { … … 305 430 * Outputs the Activity component admin screens 306 431 * 307 * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table308 432 * @since 1.6 309 433 */ 310 434 function bp_activity_admin() { 311 global $bp_activity_list_table; 435 // Decide whether to load the index or edit screen 436 $doaction = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : ''; 312 437 313 438 // Display the single activity edit screen 314 if ( 'edit' == $ bp_activity_list_table->current_action() && !empty( $_GET['aid'] ) )439 if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) 315 440 bp_activity_admin_edit(); 316 441 … … 323 448 * Display the single activity edit screen 324 449 * 325 * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table326 450 * @since 1.6 327 451 */ 328 452 function bp_activity_admin_edit() { 329 global $bp_activity_list_table; 453 // @todo: Check if user is allowed to edit activity items 454 // if ( ! current_user_can( 'bp_edit_activity' ) ) 455 if ( ! is_super_admin() ) 456 die( '-1' ); 457 458 // Get the activity from the database 459 $activity = bp_activity_get( array( 460 'in' => ! empty( $_REQUEST['aid'] ) ? (int) $_REQUEST['aid'] : 0, 461 'max' => 1, 462 'show_hidden' => true, 463 'spam' => 'all', 464 ) ); 465 466 if ( ! empty( $activity['activities'][0] ) ) { 467 $activity = $activity['activities'][0]; 468 469 // Workaround to use WP's touch_time() without duplicating that function 470 $GLOBALS['comment'] = new stdClass; 471 $GLOBALS['comment']->comment_date = $activity->date_recorded; 472 } else { 473 $activity = ''; 474 } 475 476 // Construct URL for form 477 $form_url = remove_query_arg( array( 'action', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] ); 478 $form_url = add_query_arg( 'action', 'save', $form_url ); 479 ?> 480 481 <div class="wrap"> 482 <?php screen_icon( 'buddypress' ); ?> 483 <h2><?php printf( __( 'Editing Activity (ID #%s)', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) ); ?></h2> 484 485 <?php if ( ! empty( $activity ) ) : ?> 486 487 <form action="<?php echo esc_attr( $form_url ); ?>" id="bp-activities-edit-form" method="post"> 488 <div id="poststuff" class="metabox-holder has-right-sidebar"> 489 <div id="side-info-column" class="inner-sidebar"> 490 <?php do_meta_boxes( 'toplevel_page_bp-activity', 'side', $activity ); ?> 491 </div> 492 493 <div id="post-body" class="has-sidebar"> 494 <div id="post-body-content" class="has-sidebar-content"> 495 <div id="postdiv" class="postarea"> 496 <?php wp_editor( stripslashes( $activity->action ), 'bp-activities-action', array( 'media_buttons' => false, 'textarea_rows' => 7, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ), ) ); ?> 497 498 <?php wp_editor( stripslashes( $activity->content ), 'bp-activities-content', array( 'media_buttons' => false, 'teeny' => true, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ), ) ); ?> 499 </div> 500 501 <?php do_meta_boxes( 'toplevel_page_bp-activity', 'advanced', $activity ); ?> 502 </div> 503 </div> 504 </div> 505 506 <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> 507 <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> 508 <?php wp_nonce_field( 'edit-activity_' . $activity->id ); ?> 509 </form> 510 511 <?php else : ?> 512 <p><?php printf( __( 'No activity found with this ID. <a href="%s">Go back and try again</a>.', 'buddypress' ), network_admin_url( 'admin.php?page=bp-activity' ) ); ?></p> 513 <?php endif; ?> 514 515 </div> 516 517 <?php 518 } 519 520 /** 521 * Status metabox for the Activity admin edit screen 522 * 523 * @param object $item Activity item 524 * @since 1.6 525 */ 526 function bp_activity_admin_edit_metabox_status( $item ) { 527 ?> 528 529 <div class="submitbox" id="submitcomment"> 530 531 <div id="minor-publishing"> 532 <div id="minor-publishing-actions"> 533 <div id="preview-action"> 534 <a class="button preview" href="<?php echo esc_attr( bp_activity_get_permalink( $item->id, $item ) ); ?>" target="_blank"><?php _e( 'View Activity', 'buddypress' ); ?></a> 535 </div> 536 537 <div class="clear"></div> 538 </div><!-- #minor-publishing-actions --> 539 540 <div id="misc-publishing-actions"> 541 <div class="misc-pub-section" id="comment-status-radio"> 542 <label class="approved"><input type="radio" name="activity_status" value="ham" <?php checked( $item->is_spam, 0 ); ?>><?php _e( 'Approved', 'buddypress' ); ?></label><br /> 543 <label class="spam"><input type="radio" name="activity_status" value="spam" <?php checked( $item->is_spam, 1 ); ?>><?php _e( 'Spam', 'buddypress' ); ?></label> 544 </div> 545 546 <div class="misc-pub-section curtime misc-pub-section-last"> 547 <?php 548 // translators: Publish box date format, see http://php.net/date 549 $datef = __( 'M j, Y @ G:i', 'buddypress' ); 550 $date = date_i18n( $datef, strtotime( $item->date_recorded ) ); 551 ?> 552 <span id="timestamp"><?php printf( __( 'Submitted on: <strong>%1$s</strong>', 'buddypress' ), $date ); ?></span> <a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e( 'Edit', 'buddypress' ); ?></a> 553 554 <div id='timestampdiv' class='hide-if-js'> 555 <?php touch_time( 1, 0, 5 ); ?> 556 </div><!-- #timestampdiv --> 557 </div> 558 </div> <!-- #misc-publishing-actions --> 559 560 <div class="clear"></div> 561 </div><!-- #minor-publishing --> 562 563 <div id="major-publishing-actions"> 564 <div id="publishing-action"> 565 <?php submit_button( __( 'Update', 'buddypress' ), 'primary', 'save', false, array( 'tabindex' => '4' ) ); ?> 566 </div> 567 <div class="clear"></div> 568 </div><!-- #major-publishing-actions --> 569 570 </div><!-- #submitcomment --> 571 572 <?php 330 573 } 331 574 … … 343 586 344 587 // If the user has just made a change to an activity item, build status messages 345 if ( ! empty( $_REQUEST['deleted'] ) || !empty( $_REQUEST['spammed'] ) || !empty( $_REQUEST['unspammed'] ) || !empty( $_REQUEST['error'] ) ) {588 if ( ! empty( $_REQUEST['deleted'] ) || ! empty( $_REQUEST['spammed'] ) || ! empty( $_REQUEST['unspammed'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) ) { 346 589 $deleted = !empty( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0; 347 590 $error = !empty( $_REQUEST['error'] ) ? (int) $_REQUEST['error'] : 0; 348 591 $spammed = !empty( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0; 349 592 $unspammed = !empty( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0; 593 $updated = !empty( $_REQUEST['updated'] ) ? (int) $_REQUEST['updated'] : 0; 350 594 351 595 if ( $deleted > 0 ) … … 361 605 $messages[] = sprintf( _n( '%s activity restored from the spam.', '%s activities restored from the spam.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) ); 362 606 607 if ( $updated > 0 ) 608 $messages[] = __( 'The activity has been updated succesfully.', 'buddypress' ); 363 609 } 364 610 … … 563 809 'total_pages' => ceil( $activities['total'] / $per_page ) 564 810 ) ); 811 812 // Don't truncate activity items; bp_activity_truncate_entry() needs to be used inside a BP_Activity_Template loop. 813 remove_filter( 'bp_get_activity_content_body', 'bp_activity_truncate_entry', 5 ); 565 814 } 566 815 … … 838 1087 839 1088 // Get activity content - if not set, use the action 840 if ( ! empty( $item['content'] ) )1089 if ( ! empty( $item['content'] ) ) 841 1090 $content = apply_filters_ref_array( 'bp_get_activity_content_body', array( $item['content'] ) ); 842 1091 else
Note: See TracChangeset
for help on using the changeset viewer.