[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-activity/ -> bp-activity-admin.php (source)

   1  <?php
   2  /**
   3   * BuddyPress Activity component admin screen.
   4   *
   5   * Props to WordPress core for the Comments admin screen, and its contextual
   6   * help text, on which this implementation is heavily based.
   7   *
   8   * @package BuddyPress
   9   * @subpackage ActivityAdmin
  10   * @since 1.6.0
  11   */
  12  
  13  // Exit if accessed directly.
  14  defined( 'ABSPATH' ) || exit;
  15  
  16  // Include WP's list table class.
  17  if ( !class_exists( 'WP_List_Table' ) ) require( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
  18  
  19  // Per_page screen option. Has to be hooked in extremely early.
  20  if ( is_admin() && ! empty( $_REQUEST['page'] ) && 'bp-activity' == $_REQUEST['page'] )
  21      add_filter( 'set-screen-option', 'bp_activity_admin_screen_options', 10, 3 );
  22  
  23  /**
  24   * Register the Activity component admin screen.
  25   *
  26   * @since 1.6.0
  27   */
  28  function bp_activity_add_admin_menu() {
  29  
  30      // Add our screen.
  31      $hook = add_menu_page(
  32          _x( 'Activity', 'Admin Dashboard SWA page title', 'buddypress' ),
  33          _x( 'Activity', 'Admin Dashboard SWA menu', 'buddypress' ),
  34          'bp_moderate',
  35          'bp-activity',
  36          'bp_activity_admin',
  37          'div'
  38      );
  39  
  40      // Hook into early actions to load custom CSS and our init handler.
  41      add_action( "load-$hook", 'bp_activity_admin_load' );
  42  }
  43  add_action( bp_core_admin_hook(), 'bp_activity_add_admin_menu' );
  44  
  45  /**
  46   * Add activity component to custom menus array.
  47   *
  48   * Several BuddyPress components have top-level menu items in the Dashboard,
  49   * which all appear together in the middle of the Dashboard menu. This function
  50   * adds the Activity page to the array of these menu items.
  51   *
  52   * @since 1.7.0
  53   *
  54   * @param array $custom_menus The list of top-level BP menu items.
  55   * @return array $custom_menus List of top-level BP menu items, with Activity added.
  56   */
  57  function bp_activity_admin_menu_order( $custom_menus = array() ) {
  58      array_push( $custom_menus, 'bp-activity' );
  59      return $custom_menus;
  60  }
  61  add_filter( 'bp_admin_menu_order', 'bp_activity_admin_menu_order' );
  62  
  63  /**
  64   * AJAX receiver for Activity replies via the admin screen.
  65   *
  66   * Processes requests to add new activity comments, and echoes HTML for a new
  67   * table row.
  68   *
  69   * @since 1.6.0
  70   */
  71  function bp_activity_admin_reply() {
  72      // Check nonce.
  73      check_ajax_referer( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply' );
  74  
  75      $parent_id = ! empty( $_REQUEST['parent_id'] ) ? (int) $_REQUEST['parent_id'] : 0;
  76      $root_id   = ! empty( $_REQUEST['root_id'] )   ? (int) $_REQUEST['root_id']   : 0;
  77  
  78      // $parent_id is required.
  79      if ( empty( $parent_id ) )
  80          die( '-1' );
  81  
  82      // If $root_id not set (e.g. for root items), use $parent_id.
  83      if ( empty( $root_id ) )
  84          $root_id = $parent_id;
  85  
  86      // Check that a reply has been entered.
  87      if ( empty( $_REQUEST['content'] ) )
  88          die( __( 'Error: Please type a reply.', 'buddypress' ) );
  89  
  90      // Check parent activity exists.
  91      $parent_activity = new BP_Activity_Activity( $parent_id );
  92      if ( empty( $parent_activity->component ) )
  93          die( __( 'Error: The item you are trying to reply to cannot be found, or it has been deleted.', 'buddypress' ) );
  94  
  95      // @todo: Check if user is allowed to create new activity items
  96      // if ( ! current_user_can( 'bp_new_activity' ) )
  97      if ( ! bp_current_user_can( 'bp_moderate' ) )
  98          die( '-1' );
  99  
 100      // Add new activity comment.
 101      $new_activity_id = bp_activity_new_comment( array(
 102          'activity_id' => $root_id,              // ID of the root activity item.
 103          'content'     => $_REQUEST['content'],
 104          'parent_id'   => $parent_id,            // ID of a parent comment.
 105      ) );
 106  
 107      // Fetch the new activity item, as we need it to create table markup to return.
 108      $new_activity = new BP_Activity_Activity( $new_activity_id );
 109  
 110      // This needs to be set for the BP_Activity_List_Table constructor to work.
 111      set_current_screen( 'toplevel_page_bp-activity' );
 112  
 113      // Set up an output buffer.
 114      ob_start();
 115      $list_table = new BP_Activity_List_Table();
 116      $list_table->single_row( (array) $new_activity );
 117  
 118      // Get table markup.
 119      $response =  array(
 120          'data'     => ob_get_contents(),
 121          'id'       => $new_activity_id,
 122          'position' => -1,
 123          'what'     => 'bp_activity',
 124      );
 125      ob_end_clean();
 126  
 127      // Send response.
 128      $r = new WP_Ajax_Response();
 129      $r->add( $response );
 130      $r->send();
 131  
 132      exit();
 133  }
 134  add_action( 'wp_ajax_bp-activity-admin-reply', 'bp_activity_admin_reply' );
 135  
 136  /**
 137   * Handle save/update of screen options for the Activity component admin screen.
 138   *
 139   * @since 1.6.0
 140   *
 141   * @param string $value     Will always be false unless another plugin filters it first.
 142   * @param string $option    Screen option name.
 143   * @param string $new_value Screen option form value.
 144   * @return string|int Option value. False to abandon update.
 145   */
 146  function bp_activity_admin_screen_options( $value, $option, $new_value ) {
 147      if ( 'toplevel_page_bp_activity_per_page' != $option && 'toplevel_page_bp_activity_network_per_page' != $option )
 148          return $value;
 149  
 150      // Per page.
 151      $new_value = (int) $new_value;
 152      if ( $new_value < 1 || $new_value > 999 )
 153          return $value;
 154  
 155      return $new_value;
 156  }
 157  
 158  /**
 159   * Hide the advanced edit meta boxes by default, so we don't clutter the screen.
 160   *
 161   * @since 1.6.0
 162   *
 163   * @param array     $hidden Array of items to hide.
 164   * @param WP_Screen $screen Screen identifier.
 165   * @return array Hidden Meta Boxes.
 166   */
 167  function bp_activity_admin_edit_hidden_metaboxes( $hidden, $screen ) {
 168      if ( empty( $screen->id ) || 'toplevel_page_bp-activity' !== $screen->id && 'toplevel_page_bp-activity-network' !== $screen->id ) {
 169          return $hidden;
 170      }
 171  
 172      // Hide the primary link meta box by default.
 173      $hidden  = array_merge( (array) $hidden, array( 'bp_activity_itemids', 'bp_activity_link', 'bp_activity_type', 'bp_activity_userid', ) );
 174  
 175      /**
 176       * Filters default hidden metaboxes so plugins can alter list.
 177       *
 178       * @since 1.6.0
 179       *
 180       * @param array     $hidden Default metaboxes to hide.
 181       * @param WP_Screen $screen Screen identifier.
 182       */
 183      return apply_filters( 'bp_hide_meta_boxes', array_unique( $hidden ), $screen );
 184  }
 185  add_filter( 'default_hidden_meta_boxes', 'bp_activity_admin_edit_hidden_metaboxes', 10, 2 );
 186  
 187  /**
 188   * Set up the Activity admin page.
 189   *
 190   * Does the following:
 191   *   - Register contextual help and screen options for this admin page.
 192   *   - Enqueues scripts and styles.
 193   *   - Catches POST and GET requests related to Activity.
 194   *
 195   * @since 1.6.0
 196   *
 197   * @global object                 $bp                     BuddyPress global settings.
 198   * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
 199   */
 200  function bp_activity_admin_load() {
 201      global $bp_activity_list_table;
 202  
 203      $bp       = buddypress();
 204      $doaction = bp_admin_list_table_current_bulk_action();
 205      $min      = bp_core_get_minified_asset_suffix();
 206  
 207      /**
 208       * Fires at top of Activity admin page.
 209       *
 210       * @since 1.6.0
 211       *
 212       * @param string $doaction Current $_GET action being performed in admin screen.
 213       */
 214      do_action( 'bp_activity_admin_load', $doaction );
 215  
 216      // Edit screen.
 217      if ( 'edit' == $doaction && ! empty( $_GET['aid'] ) ) {
 218          // Columns screen option.
 219          add_screen_option( 'layout_columns', array( 'default' => 2, 'max' => 2, ) );
 220  
 221          get_current_screen()->add_help_tab( array(
 222              'id'      => 'bp-activity-edit-overview',
 223              'title'   => __( 'Overview', 'buddypress' ),
 224              'content' =>
 225                  '<p>' . __( 'You 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>' .
 226                  '<p>' . __( 'The two big editing areas for the activity title and content are fixed in place, but you can reposition all the other boxes using drag and drop, and can minimize or expand them by clicking the title bar of each box. Use the Screen Options tab to unhide more boxes (Primary Item/Secondary Item, Link, Type, Author ID) or to choose a 1- or 2-column layout for this screen.', 'buddypress' ) . '</p>' .
 227                  '<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>'
 228          ) );
 229  
 230          get_current_screen()->add_help_tab( array(
 231              'id'      => 'bp-activity-edit-advanced',
 232              'title'   => __( 'Item, Link, Type', 'buddypress' ),
 233              'content' =>
 234                  '<p>' . __( '<strong>Primary Item/Secondary Item</strong> - These identify the object that created the activity. For example, the fields could reference a comment left on a specific site. Some types of activity may only use one, or none, of these fields.', 'buddypress' ) . '</p>' .
 235                  '<p>' . __( '<strong>Link</strong> - Used by some types of activity (blog posts and comments) to store a link back to the original content.', 'buddypress' ) . '</p>' .
 236                  '<p>' . __( '<strong>Type</strong> - Each distinct kind of activity has its own type. For example, <code>created_group</code> is used when a group is created and <code>joined_group</code> is used when a user joins a group.', 'buddypress' ) . '</p>' .
 237                  '<p>' . __( 'For information about when and how BuddyPress uses all of these settings, see the Managing Activity link in the panel to the side.', 'buddypress' ) . '</p>'
 238          ) );
 239  
 240          // Help panel - sidebar links.
 241          get_current_screen()->set_help_sidebar(
 242              '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
 243              '<p>' . __( '<a href="https://codex.buddypress.org/administrator-guide/activity-stream-management-panels/">Managing Activity</a>', 'buddypress' ) . '</p>' .
 244              '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
 245          );
 246  
 247          // Register metaboxes for the edit screen.
 248          add_meta_box( 'submitdiv',           _x( 'Status', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_status', get_current_screen()->id, 'side', 'core' );
 249          add_meta_box( 'bp_activity_itemids', _x( 'Primary Item/Secondary Item', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_itemids', get_current_screen()->id, 'normal', 'core' );
 250          add_meta_box( 'bp_activity_link',    _x( 'Link', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_link', get_current_screen()->id, 'normal', 'core' );
 251          add_meta_box( 'bp_activity_type',    _x( 'Type', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_type', get_current_screen()->id, 'normal', 'core' );
 252          add_meta_box( 'bp_activity_userid',  _x( 'Author ID', 'activity admin edit screen', 'buddypress' ), 'bp_activity_admin_edit_metabox_userid', get_current_screen()->id, 'normal', 'core' );
 253  
 254          /**
 255           * Fires after the registration of all of the default activity meta boxes.
 256           *
 257           * @since 2.4.0
 258           */
 259          do_action( 'bp_activity_admin_meta_boxes' );
 260  
 261          // Enqueue JavaScript files.
 262          wp_enqueue_script( 'postbox' );
 263          wp_enqueue_script( 'dashboard' );
 264          wp_enqueue_script( 'comment' );
 265  
 266      // Index screen.
 267      } else {
 268          // Create the Activity screen list table.
 269          $bp_activity_list_table = new BP_Activity_List_Table();
 270  
 271          // The per_page screen option.
 272          add_screen_option( 'per_page', array( 'label' => _x( 'Activity', 'Activity items per page (screen options)', 'buddypress' )) );
 273  
 274          // Help panel - overview text.
 275          get_current_screen()->add_help_tab( array(
 276              'id'      => 'bp-activity-overview',
 277              'title'   => __( 'Overview', 'buddypress' ),
 278              'content' =>
 279                  '<p>' . __( 'You can manage activities made on your site similar to the way you manage comments and other content. This screen is customizable in the same ways as other management screens, and you can act on activities using the on-hover action links or the Bulk Actions.', 'buddypress' ) . '</p>' .
 280                  '<p>' . __( 'There are many different types of activities. Some are generated automatically by BuddyPress and other plugins, and some are entered directly by a user in the form of status update. To help manage the different activity types, use the filter dropdown box to switch between them.', 'buddypress' ) . '</p>'
 281          ) );
 282  
 283          // Help panel - moderation text.
 284          get_current_screen()->add_help_tab( array(
 285              'id'        => 'bp-activity-moderating',
 286              'title'        => __( 'Moderating Activity', 'buddypress' ),
 287              'content'    =>
 288                  '<p>' . __( 'In the <strong>Activity</strong> column, above each activity it says &#8220;Submitted on,&#8221; followed by the date and time the activity item was generated on your site. Clicking on the date/time link will take you to that activity on your live site. Hovering over any activity gives you options to reply, edit, spam mark, or delete that activity.', 'buddypress' ) . '</p>' .
 289                  '<p>' . __( "In the <strong>In Response To</strong> column, if the activity was in reply to another activity, it shows that activity's author's picture and name, and a link to that activity on your live site. If there is a small bubble, the number in it shows how many other activities are related to this one; these are usually comments. Clicking the bubble will filter the activity screen to show only related activity items.", 'buddypress' ) . '</p>'
 290          ) );
 291  
 292          // Help panel - sidebar links.
 293          get_current_screen()->set_help_sidebar(
 294              '<p><strong>' . __( 'For more information:', 'buddypress' ) . '</strong></p>' .
 295              '<p>' . __( '<a href="https://buddypress.org/support/">Support Forums</a>', 'buddypress' ) . '</p>'
 296          );
 297  
 298          // Add accessible hidden heading and text for Activity screen pagination.
 299          get_current_screen()->set_screen_reader_content( array(
 300              /* translators: accessibility text */
 301              'heading_pagination' => __( 'Activity list navigation', 'buddypress' ),
 302          ) );
 303  
 304      }
 305  
 306      // Enqueue CSS and JavaScript.
 307      wp_enqueue_script( 'bp_activity_admin_js', $bp->plugin_url . "bp-activity/admin/js/admin{$min}.js",   array( 'jquery', 'wp-ajax-response' ), bp_get_version(), true );
 308      wp_localize_script( 'bp_activity_admin_js', 'bp_activity_admin_vars', array(
 309          'page' => get_current_screen()->id
 310      ) );
 311      wp_enqueue_style( 'bp_activity_admin_css', $bp->plugin_url . "bp-activity/admin/css/admin{$min}.css", array(),                               bp_get_version()       );
 312  
 313      wp_style_add_data( 'bp_activity_admin_css', 'rtl', 'replace' );
 314      if ( $min ) {
 315          wp_style_add_data( 'bp_activity_admin_css', 'suffix', $min );
 316      }
 317  
 318      /**
 319       * Fires after the activity js and style has been enqueued.
 320       *
 321       * @since 2.4.0
 322       */
 323      do_action( 'bp_activity_admin_enqueue_scripts' );
 324  
 325      // Handle spam/un-spam/delete of activities.
 326      if ( ! empty( $doaction ) && ! in_array( $doaction, array( '-1', 'edit', 'save', 'delete', 'bulk_delete' ) ) ) {
 327  
 328          // Build redirection URL.
 329          $redirect_to = remove_query_arg( array( 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), wp_get_referer() );
 330          $redirect_to = add_query_arg( 'paged', $bp_activity_list_table->get_pagenum(), $redirect_to );
 331  
 332          // Get activity IDs.
 333          $activity_ids = wp_parse_id_list( $_REQUEST['aid'] );
 334  
 335          /**
 336           * Filters list of IDs being spammed/un-spammed/deleted.
 337           *
 338           * @since 1.6.0
 339           *
 340           * @param array $activity_ids Activity IDs to spam/un-spam/delete.
 341           */
 342          $activity_ids = apply_filters( 'bp_activity_admin_action_activity_ids', $activity_ids );
 343  
 344          // Is this a bulk request?
 345          if ( 'bulk_' == substr( $doaction, 0, 5 ) && ! empty( $_REQUEST['aid'] ) ) {
 346              // Check this is a valid form submission.
 347              check_admin_referer( 'bulk-activities' );
 348  
 349              // Trim 'bulk_' off the action name to avoid duplicating a ton of code.
 350              $doaction = substr( $doaction, 5 );
 351  
 352              // This is a request to delete single or multiple item.
 353          } elseif ( 'do_delete'  === $doaction && ! empty( $_REQUEST['aid'] ) ) {
 354              check_admin_referer( 'bp-activities-delete' );
 355  
 356          // This is a request to spam, or un-spam, a single item.
 357          } elseif ( !empty( $_REQUEST['aid'] ) ) {
 358  
 359              // Check this is a valid form submission.
 360              check_admin_referer( 'spam-activity_' . $activity_ids[0] );
 361          }
 362  
 363          // Initialize counters for how many of each type of item we perform an action on.
 364          $deleted = $spammed = $unspammed = 0;
 365  
 366          // Store any errors that occurs when updating the database items.
 367          $errors = array();
 368  
 369          // "We'd like to shoot the monster, could you move, please?"
 370          foreach ( $activity_ids as $activity_id ) {
 371              // @todo: Check the permissions on each
 372              // if ( ! current_user_can( 'bp_edit_activity', $activity_id ) )
 373              // continue;
 374              // Get the activity from the database.
 375              $activity = new BP_Activity_Activity( $activity_id );
 376              if ( empty( $activity->component ) ) {
 377                  $errors[] = $activity_id;
 378                  continue;
 379              }
 380  
 381              switch ( $doaction ) {
 382                  case 'do_delete' :
 383                      if ( 'activity_comment' === $activity->type ) {
 384                          $delete_result = bp_activity_delete_comment( $activity->item_id, $activity->id );
 385                      } else {
 386                          $delete_result = bp_activity_delete( array( 'id' => $activity->id ) );
 387                      }
 388  
 389                      if ( ! $delete_result ) {
 390                          $errors[] = $activity->id;
 391                      } else {
 392                          $deleted++;
 393                      }
 394                      break;
 395  
 396                  case 'ham' :
 397                      /**
 398                       * Remove moderation and disallowed keyword checks in case we want to ham an activity
 399                       * which contains one of these listed keys.
 400                       */
 401                      remove_action( 'bp_activity_before_save', 'bp_activity_check_moderation_keys', 2 );
 402                      remove_action( 'bp_activity_before_save', 'bp_activity_check_disallowed_keys', 2 );
 403  
 404                      bp_activity_mark_as_ham( $activity );
 405                      $result = $activity->save();
 406  
 407                      // Check for any error during activity save.
 408                      if ( ! $result ) {
 409                          $errors[] = $activity->id;
 410                      } else {
 411                          $unspammed++;
 412                      }
 413                      break;
 414  
 415                  case 'spam' :
 416                      bp_activity_mark_as_spam( $activity );
 417                      $result = $activity->save();
 418  
 419                      // Check for any error during activity save.
 420                      if ( ! $result ) {
 421                          $errors[] = $activity->id;
 422                      } else {
 423                          $spammed++;
 424                      }
 425                      break;
 426  
 427                  default:
 428                      break;
 429              }
 430  
 431              // Release memory.
 432              unset( $activity );
 433          }
 434  
 435          /**
 436           * Fires before redirect for plugins to do something with activity.
 437           *
 438           * Passes an activity array counts how many were spam, not spam, deleted, and IDs that were errors.
 439           *
 440           * @since 1.6.0
 441           *
 442           * @param array  $value        Array holding spam, not spam, deleted counts, error IDs.
 443           * @param string $redirect_to  URL to redirect to.
 444           * @param array  $activity_ids Original array of activity IDs.
 445           */
 446          do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
 447  
 448          // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
 449          if ( $spammed ) {
 450              $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
 451          }
 452  
 453          if ( $unspammed ) {
 454              $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
 455          }
 456  
 457          if ( $deleted ) {
 458              $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
 459          }
 460  
 461          // If an error occurred, pass back the activity ID that failed.
 462          if ( ! empty( $errors ) ) {
 463              $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to );
 464          }
 465  
 466          /**
 467           * Filters redirect URL after activity spamming/un-spamming/deletion occurs.
 468           *
 469           * @since 1.6.0
 470           *
 471           * @param string $redirect_to URL to redirect to.
 472           */
 473          wp_redirect( apply_filters( 'bp_activity_admin_action_redirect', $redirect_to ) );
 474          exit;
 475  
 476  
 477      // Save the edit.
 478      } elseif ( $doaction && 'save' == $doaction ) {
 479          // Build redirection URL.
 480          $redirect_to = remove_query_arg( array( 'action', 'aid', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
 481  
 482          // Get activity ID.
 483          $activity_id = (int) $_REQUEST['aid'];
 484  
 485          // Check this is a valid form submission.
 486          check_admin_referer( 'edit-activity_' . $activity_id );
 487  
 488          // Get the activity from the database.
 489          $activity = new BP_Activity_Activity( $activity_id );
 490  
 491          // If the activity doesn't exist, just redirect back to the index.
 492          if ( empty( $activity->component ) ) {
 493              wp_redirect( $redirect_to );
 494              exit;
 495          }
 496  
 497          // Check the form for the updated properties.
 498          // Store any error that occurs when updating the database item.
 499          $error = 0;
 500  
 501          // Activity spam status.
 502          $prev_spam_status = $new_spam_status = false;
 503          if ( ! empty( $_POST['activity_status'] ) ) {
 504              $prev_spam_status = $activity->is_spam;
 505              $new_spam_status  = ( 'spam' == $_POST['activity_status'] ) ? true : false;
 506          }
 507  
 508          // Activity action.
 509          if ( isset( $_POST['bp-activities-action'] ) )
 510              $activity->action = $_POST['bp-activities-action'];
 511  
 512          // Activity content.
 513          if ( isset( $_POST['bp-activities-content'] ) )
 514              $activity->content = $_POST['bp-activities-content'];
 515  
 516          // Activity primary link.
 517          if ( ! empty( $_POST['bp-activities-link'] ) )
 518              $activity->primary_link = $_POST['bp-activities-link'];
 519  
 520          // Activity user ID.
 521          if ( ! empty( $_POST['bp-activities-userid'] ) )
 522              $activity->user_id = (int) $_POST['bp-activities-userid'];
 523  
 524          // Activity item primary ID.
 525          if ( isset( $_POST['bp-activities-primaryid'] ) )
 526              $activity->item_id = (int) $_POST['bp-activities-primaryid'];
 527  
 528          // Activity item secondary ID.
 529          if ( isset( $_POST['bp-activities-secondaryid'] ) )
 530              $activity->secondary_item_id = (int) $_POST['bp-activities-secondaryid'];
 531  
 532          // Activity type.
 533          if ( ! empty( $_POST['bp-activities-type'] ) ) {
 534              $actions = bp_activity_admin_get_activity_actions();
 535  
 536              // Check that the new type is a registered activity type.
 537              if ( in_array( $_POST['bp-activities-type'], $actions ) ) {
 538                  $activity->type = $_POST['bp-activities-type'];
 539              }
 540          }
 541  
 542          // Activity timestamp.
 543          if ( ! empty( $_POST['aa'] ) && ! empty( $_POST['mm'] ) && ! empty( $_POST['jj'] ) && ! empty( $_POST['hh'] ) && ! empty( $_POST['mn'] ) && ! empty( $_POST['ss'] ) ) {
 544              $aa = $_POST['aa'];
 545              $mm = $_POST['mm'];
 546              $jj = $_POST['jj'];
 547              $hh = $_POST['hh'];
 548              $mn = $_POST['mn'];
 549              $ss = $_POST['ss'];
 550              $aa = ( $aa <= 0 ) ? date( 'Y' ) : $aa;
 551              $mm = ( $mm <= 0 ) ? date( 'n' ) : $mm;
 552              $jj = ( $jj > 31 ) ? 31 : $jj;
 553              $jj = ( $jj <= 0 ) ? date( 'j' ) : $jj;
 554              $hh = ( $hh > 23 ) ? $hh -24 : $hh;
 555              $mn = ( $mn > 59 ) ? $mn -60 : $mn;
 556              $ss = ( $ss > 59 ) ? $ss -60 : $ss;
 557  
 558              // Reconstruct the date into a timestamp.
 559              $gmt_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
 560  
 561              $activity->date_recorded = $gmt_date;
 562          }
 563  
 564          // Has the spam status has changed?
 565          if ( $new_spam_status != $prev_spam_status ) {
 566              if ( $new_spam_status )
 567                  bp_activity_mark_as_spam( $activity );
 568              else
 569                  bp_activity_mark_as_ham( $activity );
 570          }
 571  
 572          // Save.
 573          $result = $activity->save();
 574  
 575          // Clear the activity stream first page cache, in case this activity's timestamp was changed.
 576          wp_cache_delete( 'bp_activity_sitewide_front', 'bp' );
 577  
 578          // Check for any error during activity save.
 579          if ( false === $result )
 580              $error = $activity->id;
 581  
 582          /**
 583           * Fires before redirect so plugins can do something first on save action.
 584           *
 585           * @since 1.6.0
 586           *
 587           * @param array $value Array holding activity object and ID that holds error.
 588           */
 589          do_action_ref_array( 'bp_activity_admin_edit_after', array( &$activity, $error ) );
 590  
 591          // If an error occurred, pass back the activity ID that failed.
 592          if ( $error )
 593              $redirect_to = add_query_arg( 'error', $error, $redirect_to );
 594          else
 595              $redirect_to = add_query_arg( 'updated', $activity->id, $redirect_to );
 596  
 597          /**
 598           * Filters URL to redirect to after saving.
 599           *
 600           * @since 1.6.0
 601           *
 602           * @param string $redirect_to URL to redirect to.
 603           */
 604          wp_redirect( apply_filters( 'bp_activity_admin_edit_redirect', $redirect_to ) );
 605          exit;
 606  
 607  
 608      // If a referrer and a nonce is supplied, but no action, redirect back.
 609      } elseif ( ! empty( $_GET['_wp_http_referer'] ) ) {
 610          wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce' ), stripslashes( $_SERVER['REQUEST_URI'] ) ) );
 611          exit;
 612      }
 613  }
 614  
 615  /**
 616   * Output the Activity component admin screens.
 617   *
 618   * @since 1.6.0
 619   */
 620  function bp_activity_admin() {
 621      // Decide whether to load the index or edit screen.
 622      $doaction = bp_admin_list_table_current_bulk_action();
 623  
 624      // Display the single activity edit screen.
 625      if ( 'edit' === $doaction && ! empty( $_GET['aid'] ) ) {
 626          bp_activity_admin_edit();
 627  
 628      // Display the activty delete confirmation screen.
 629      } elseif ( in_array( $doaction, array( 'bulk_delete', 'delete' ) ) && ! empty( $_GET['aid'] ) ) {
 630          bp_activity_admin_delete();
 631  
 632      // Otherwise, display the Activity index screen.
 633      } else {
 634          bp_activity_admin_index();
 635      }
 636  }
 637  
 638  /**
 639   * Display the Activity delete confirmation screen.
 640   *
 641   * @since 7.0.0
 642   */
 643  function bp_activity_admin_delete() {
 644  
 645      if ( ! bp_current_user_can( 'bp_moderate' ) ) {
 646          die( '-1' );
 647      }
 648  
 649      $activity_ids = isset( $_REQUEST['aid'] ) ? $_REQUEST['aid'] : 0;
 650  
 651      if ( ! is_array( $activity_ids ) ) {
 652          $activity_ids = explode( ',', $activity_ids );
 653      }
 654  
 655      $activities = bp_activity_get( array(
 656          'in'               => $activity_ids,
 657          'show_hidden'      => true,
 658          'spam'             => 'all',
 659          'display_comments' => 0,
 660          'per_page'         => null
 661      ) );
 662  
 663      // Create a new list of activity ids, based on those that actually exist.
 664      $aids = array();
 665      foreach ( $activities['activities'] as $activity ) {
 666          $aids[] = $activity->id;
 667      }
 668  
 669      $base_url = remove_query_arg( array( 'action', 'action2', 'paged', 's', '_wpnonce', 'aid' ), $_SERVER['REQUEST_URI'] ); ?>
 670  
 671      <div class="wrap">
 672          <h1><?php esc_html_e( 'Delete Activities', 'buddypress' ) ?></h1>
 673          <p><?php esc_html_e( 'You are about to delete the following activities:', 'buddypress' ) ?></p>
 674  
 675          <ul class="bp-activity-delete-list">
 676          <?php foreach ( $activities['activities'] as $activity ) : ?>
 677              <li>
 678              <?php
 679              $actions = bp_activity_admin_get_activity_actions();
 680  
 681              if ( isset( $actions[ $activity->type ] ) ) {
 682                  $activity_type =  $actions[ $activity->type ];
 683              } else {
 684                  /* translators: %s: the name of the activity type */
 685                  $activity_type = sprintf( __( 'Unregistered action - %s', 'buddypress' ), $activity->type );
 686              }
 687  
 688              printf(
 689                  /* translators: 1: activity type. 2: activity author. 3: activity date and time. */
 690                  __( '"%1$s" activity submitted by %2$s on %3$s', 'buddypress' ),
 691                  esc_html( $activity_type ),
 692                  bp_core_get_userlink( $activity->user_id ),
 693                  sprintf(
 694                      '<a href="%1$s">%2$s</a>',
 695                      esc_url( bp_activity_get_permalink( $activity->id, $activity ) ),
 696                      date_i18n( bp_get_option( 'date_format' ), strtotime( $activity->date_recorded ) )
 697                  )
 698              );
 699              ?>
 700              </li>
 701          <?php endforeach; ?>
 702          </ul>
 703  
 704          <p><strong><?php esc_html_e( 'This action cannot be undone.', 'buddypress' ) ?></strong></p>
 705  
 706          <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'do_delete', 'aid' => implode( ',', $aids ) ), $base_url ), 'bp-activities-delete' ) ); ?>"><?php esc_html_e( 'Delete Permanently', 'buddypress' ) ?></a>
 707          <a class="button" href="<?php echo esc_attr( $base_url ); ?>"><?php esc_html_e( 'Cancel', 'buddypress' ) ?></a>
 708      </div>
 709  
 710      <?php
 711  }
 712  
 713  
 714  /**
 715   * Display the single activity edit screen.
 716   *
 717   * @since 1.6.0
 718   */
 719  function bp_activity_admin_edit() {
 720  
 721      // @todo: Check if user is allowed to edit activity items
 722      // if ( ! current_user_can( 'bp_edit_activity' ) )
 723      if ( ! is_super_admin() )
 724          die( '-1' );
 725  
 726      // Get the activity from the database.
 727      $activity = bp_activity_get( array(
 728          'in'               => ! empty( $_REQUEST['aid'] ) ? (int) $_REQUEST['aid'] : 0,
 729          'max'              => 1,
 730          'show_hidden'      => true,
 731          'spam'             => 'all',
 732          'display_comments' => 0
 733      ) );
 734  
 735      if ( ! empty( $activity['activities'][0] ) ) {
 736          $activity = $activity['activities'][0];
 737  
 738          // Workaround to use WP's touch_time() without duplicating that function.
 739          $GLOBALS['comment'] = new stdClass;
 740          $GLOBALS['comment']->comment_date = $activity->date_recorded;
 741      } else {
 742          $activity = '';
 743      }
 744  
 745      // Construct URL for form.
 746      $form_url = remove_query_arg( array( 'action', 'deleted', 'error', 'spammed', 'unspammed', ), $_SERVER['REQUEST_URI'] );
 747      $form_url = add_query_arg( 'action', 'save', $form_url );
 748  
 749      /**
 750       * Fires before activity edit form is displays so plugins can modify the activity.
 751       *
 752       * @since 1.6.0
 753       *
 754       * @param array $value Array holding single activity object that was passed by reference.
 755       */
 756      do_action_ref_array( 'bp_activity_admin_edit', array( &$activity ) ); ?>
 757  
 758      <div class="wrap">
 759          <h1>
 760              <?php
 761              /* translators: %s: the activity ID */
 762              printf( __( 'Editing Activity (ID #%s)', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) );
 763              ?>
 764          </h1>
 765  
 766          <?php if ( ! empty( $activity ) ) : ?>
 767  
 768              <form action="<?php echo esc_url( $form_url ); ?>" id="bp-activities-edit-form" method="post">
 769                  <div id="poststuff">
 770  
 771                      <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
 772                          <div id="post-body-content">
 773                              <div id="postdiv">
 774                                  <div id="bp_activity_action" class="postbox">
 775                                      <h2><?php _e( 'Action', 'buddypress' ); ?></h2>
 776                                      <div class="inside">
 777                                          <label for="bp-activities-action" class="screen-reader-text"><?php
 778                                              /* translators: accessibility text */
 779                                              _e( 'Edit activity action', 'buddypress' );
 780                                          ?></label>
 781                                          <?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' ) ) ); ?>
 782                                      </div>
 783                                  </div>
 784  
 785                                  <div id="bp_activity_content" class="postbox">
 786                                      <h2><?php _e( 'Content', 'buddypress' ); ?></h2>
 787                                      <div class="inside">
 788                                          <label for="bp-activities-content" class="screen-reader-text"><?php
 789                                              /* translators: accessibility text */
 790                                              _e( 'Edit activity content', 'buddypress' );
 791                                          ?></label>
 792                                          <?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' ) ) ); ?>
 793                                      </div>
 794                                  </div>
 795                              </div>
 796                          </div><!-- #post-body-content -->
 797  
 798                          <div id="postbox-container-1" class="postbox-container">
 799                              <?php do_meta_boxes( get_current_screen()->id, 'side', $activity ); ?>
 800                          </div>
 801  
 802                          <div id="postbox-container-2" class="postbox-container">
 803                              <?php do_meta_boxes( get_current_screen()->id, 'normal', $activity ); ?>
 804                              <?php do_meta_boxes( get_current_screen()->id, 'advanced', $activity ); ?>
 805                          </div>
 806                      </div><!-- #post-body -->
 807  
 808                  </div><!-- #poststuff -->
 809                  <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
 810                  <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
 811                  <?php wp_nonce_field( 'edit-activity_' . $activity->id ); ?>
 812              </form>
 813  
 814          <?php else : ?>
 815  
 816              <p><?php
 817                  printf(
 818                      '%1$s <a href="%2$s">%3$s</a>',
 819                      __( 'No activity found with this ID.', 'buddypress' ),
 820                      esc_url( bp_get_admin_url( 'admin.php?page=bp-activity' ) ),
 821                      __( 'Go back and try again.', 'buddypress' )
 822                  );
 823              ?></p>
 824  
 825          <?php endif; ?>
 826  
 827      </div><!-- .wrap -->
 828  
 829  <?php
 830  }
 831  
 832  /**
 833   * Status metabox for the Activity admin edit screen.
 834   *
 835   * @since 1.6.0
 836   *
 837   * @param object $item Activity item.
 838   */
 839  function bp_activity_admin_edit_metabox_status( $item ) {
 840      $base_url = add_query_arg( array(
 841          'page' => 'bp-activity',
 842          'aid'  => $item->id
 843      ), bp_get_admin_url( 'admin.php' ) );
 844  ?>
 845  
 846      <div class="submitbox" id="submitcomment">
 847  
 848          <div id="minor-publishing">
 849              <div id="minor-publishing-actions">
 850                  <div id="preview-action">
 851                      <a class="button preview" href="<?php echo esc_attr( bp_activity_get_permalink( $item->id, $item ) ); ?>" target="_blank"><?php _e( 'View Activity', 'buddypress' ); ?></a>
 852                  </div>
 853  
 854                  <div class="clear"></div>
 855              </div><!-- #minor-publishing-actions -->
 856  
 857              <div id="misc-publishing-actions">
 858                  <div class="misc-pub-section" id="comment-status-radio">
 859                      <label class="approved" for="activity-status-approved"><input type="radio" name="activity_status" id="activity-status-approved" value="ham" <?php checked( $item->is_spam, 0 ); ?>><?php _e( 'Approved', 'buddypress' ); ?></label><br />
 860                      <label class="spam" for="activity-status-spam"><input type="radio" name="activity_status" id="activity-status-spam" value="spam" <?php checked( $item->is_spam, 1 ); ?>><?php _e( 'Spam', 'buddypress' ); ?></label>
 861                  </div>
 862  
 863                  <div class="misc-pub-section curtime misc-pub-section-last">
 864                      <?php
 865                      // Translators: Publish box date format, see http://php.net/date.
 866                      $datef = __( 'M j, Y @ G:i', 'buddypress' );
 867                      $date  = date_i18n( $datef, strtotime( $item->date_recorded ) );
 868                      ?>
 869                      <span id="timestamp">
 870                          <?php
 871                          /* translators: %s: the date the activity was submitted on */
 872                          printf( __( 'Submitted on: %s', 'buddypress' ), '<strong>' . $date . '</strong>' );
 873                          ?>
 874                      </span>&nbsp;<a href="#edit_timestamp" class="edit-timestamp hide-if-no-js" tabindex='4'><?php _e( 'Edit', 'buddypress' ); ?></a>
 875  
 876                      <div id='timestampdiv' class='hide-if-js'>
 877                          <?php touch_time( 1, 0, 5 ); ?>
 878                      </div><!-- #timestampdiv -->
 879                  </div>
 880              </div> <!-- #misc-publishing-actions -->
 881  
 882              <div class="clear"></div>
 883          </div><!-- #minor-publishing -->
 884  
 885          <div id="major-publishing-actions">
 886              <div id="delete-action">
 887                  <a class="submitdelete deletion" href="<?php echo esc_url( wp_nonce_url( add_query_arg( 'action', 'delete', $base_url ), 'bp-activities-delete' ) ); ?>"><?php esc_html_e( 'Delete Permanently', 'buddypress' ) ?></a>
 888              </div>
 889  
 890              <div id="publishing-action">
 891                  <?php submit_button( __( 'Update', 'buddypress' ), 'primary', 'save', false ); ?>
 892              </div>
 893              <div class="clear"></div>
 894          </div><!-- #major-publishing-actions -->
 895  
 896      </div><!-- #submitcomment -->
 897  
 898  <?php
 899  }
 900  
 901  /**
 902   * Primary link metabox for the Activity admin edit screen.
 903   *
 904   * @since 1.6.0
 905   *
 906   * @param object $item Activity item.
 907   */
 908  function bp_activity_admin_edit_metabox_link( $item ) {
 909  ?>
 910  
 911      <label class="screen-reader-text" for="bp-activities-link"><?php
 912          /* translators: accessibility text */
 913          _e( 'Link', 'buddypress' );
 914      ?></label>
 915      <input type="url" name="bp-activities-link" id="bp-activities-link" value="<?php echo esc_url( $item->primary_link ); ?>" aria-describedby="bp-activities-link-description" />
 916      <p id="bp-activities-link-description"><?php _e( 'Activity generated by posts and comments uses the link field for a permalink back to the content item.', 'buddypress' ); ?></p>
 917  
 918  <?php
 919  }
 920  
 921  /**
 922   * User ID metabox for the Activity admin edit screen.
 923   *
 924   * @since 1.6.0
 925   *
 926   * @param object $item Activity item.
 927   */
 928  function bp_activity_admin_edit_metabox_userid( $item ) {
 929  ?>
 930  
 931      <label class="screen-reader-text" for="bp-activities-userid"><?php
 932          /* translators: accessibility text */
 933          _e( 'Author ID', 'buddypress' );
 934      ?></label>
 935      <input type="number" name="bp-activities-userid" id="bp-activities-userid" value="<?php echo esc_attr( $item->user_id ); ?>" min="1" />
 936  
 937  <?php
 938  }
 939  
 940  /**
 941   * Get flattened array of all registered activity actions.
 942   *
 943   * Format is [activity_type] => Pretty name for activity type.
 944   *
 945   * @since 2.0.0
 946   *
 947   * @return array $actions
 948   */
 949  function bp_activity_admin_get_activity_actions() {
 950      $actions  = array();
 951  
 952      // Walk through the registered actions, and build an array of actions/values.
 953      foreach ( bp_activity_get_actions() as $action ) {
 954          $action = array_values( (array) $action );
 955  
 956          for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) {
 957              /**
 958               * Don't take in account:
 959               * - a mis-named Friends activity type from before BP 1.6,
 960               * - The Group's component 'activity_update' one as the Activity component is using it.
 961               */
 962              if ( 'friends_register_activity_action' === $action[$i]['key'] || 'bp_groups_format_activity_action_group_activity_update' === $action[$i]['format_callback'] ) {
 963                  continue;
 964              }
 965  
 966              $actions[ $action[$i]['key'] ] = $action[$i]['value'];
 967          }
 968      }
 969  
 970      // Sort array by the human-readable value.
 971      natsort( $actions );
 972  
 973      return $actions;
 974  }
 975  
 976  /**
 977   * Activity type metabox for the Activity admin edit screen.
 978   *
 979   * @since 1.6.0
 980   *
 981   * @param object $item Activity item.
 982   */
 983  function bp_activity_admin_edit_metabox_type( $item ) {
 984      $bp = buddypress();
 985  
 986      $actions  = array();
 987      $selected = $item->type;
 988  
 989      // Walk through the registered actions, and build an array of actions/values.
 990      foreach ( bp_activity_get_actions() as $action ) {
 991          $action = array_values( (array) $action );
 992  
 993          for ( $i = 0, $i_count = count( $action ); $i < $i_count; $i++ ) {
 994              /**
 995               * Don't take in account:
 996               * - a mis-named Friends activity type from before BP 1.6,
 997               * - The Group's component 'activity_update' one as the Activity component is using it.
 998               */
 999              if ( 'friends_register_activity_action' === $action[$i]['key'] || 'bp_groups_format_activity_action_group_activity_update' === $action[$i]['format_callback'] ) {
1000                  continue;
1001              }
1002  
1003              $actions[ $action[$i]['key'] ] = $action[$i]['value'];
1004          }
1005      }
1006  
1007      // Sort array by the human-readable value.
1008      natsort( $actions );
1009  
1010      /*
1011       * If the activity type is not registered properly (eg, a plugin has
1012       * not called bp_activity_set_action()), add the raw type to the end
1013       * of the list.
1014       */
1015      if ( ! isset( $actions[ $selected ] ) ) {
1016          _doing_it_wrong(
1017              __FUNCTION__,
1018              sprintf(
1019                  /* translators: %s: the name of the activity type */
1020                  __( 'This activity item has a type (%s) that is not registered using bp_activity_set_action(), so no label is available.', 'buddypress' ),
1021                  $selected
1022              ),
1023              '2.0.0'
1024          );
1025  
1026          $actions[ $selected ] = $selected;
1027      }
1028  
1029      ?>
1030  
1031      <label for="bp-activities-type" class="screen-reader-text"><?php
1032          /* translators: accessibility text */
1033          esc_html_e( 'Select activity type', 'buddypress' );
1034      ?></label>
1035      <select name="bp-activities-type" id="bp-activities-type">
1036          <?php foreach ( $actions as $k => $v ) : ?>
1037              <option value="<?php echo esc_attr( $k ); ?>" <?php selected( $k,  $selected ); ?>><?php echo esc_html( $v ); ?></option>
1038          <?php endforeach; ?>
1039      </select>
1040  
1041  <?php
1042  }
1043  
1044  /**
1045   * Primary item ID/Secondary item ID metabox for the Activity admin edit screen.
1046   *
1047   * @since 1.6.0
1048   *
1049   * @param object $item Activity item.
1050   */
1051  function bp_activity_admin_edit_metabox_itemids( $item ) {
1052  ?>
1053  
1054      <label for="bp-activities-primaryid"><?php _e( 'Primary Item ID', 'buddypress' ); ?></label>
1055      <input type="number" name="bp-activities-primaryid" id="bp-activities-primaryid" value="<?php echo esc_attr( $item->item_id ); ?>" min="0" />
1056      <br />
1057  
1058      <label for="bp-activities-secondaryid"><?php _e( 'Secondary Item ID', 'buddypress' ); ?></label>
1059      <input type="number" name="bp-activities-secondaryid" id="bp-activities-secondaryid" value="<?php echo esc_attr( $item->secondary_item_id ); ?>" min="0" />
1060  
1061      <p><?php _e( 'These identify the object that created this activity. For example, the fields could reference a pair of site and comment IDs.', 'buddypress' ); ?></p>
1062  
1063  <?php
1064  }
1065  
1066  /**
1067   * Display the Activity admin index screen, which contains a list of all the activities.
1068   *
1069   * @since 1.6.0
1070   *
1071   * @global BP_Activity_List_Table $bp_activity_list_table Activity screen list table.
1072   * @global string                 $plugin_page            The current plugin page.
1073   */
1074  function bp_activity_admin_index() {
1075      global $bp_activity_list_table, $plugin_page;
1076  
1077      $messages = array();
1078  
1079      // If the user has just made a change to an activity item, build status messages.
1080      if ( ! empty( $_REQUEST['deleted'] ) || ! empty( $_REQUEST['spammed'] ) || ! empty( $_REQUEST['unspammed'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) ) {
1081          $deleted   = ! empty( $_REQUEST['deleted']   ) ? (int) $_REQUEST['deleted']   : 0;
1082          $errors    = ! empty( $_REQUEST['error']     ) ? $_REQUEST['error']           : '';
1083          $spammed   = ! empty( $_REQUEST['spammed']   ) ? (int) $_REQUEST['spammed']   : 0;
1084          $unspammed = ! empty( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
1085          $updated   = ! empty( $_REQUEST['updated']   ) ? (int) $_REQUEST['updated']   : 0;
1086  
1087          $errors = array_map( 'absint', explode( ',', $errors ) );
1088  
1089          // Make sure we don't get any empty values in $errors.
1090          for ( $i = 0, $errors_count = count( $errors ); $i < $errors_count; $i++ ) {
1091              if ( 0 === $errors[$i] ) {
1092                  unset( $errors[$i] );
1093              }
1094          }
1095  
1096          // Reindex array.
1097          $errors = array_values( $errors );
1098  
1099          if ( $deleted > 0 ) {
1100              /* translators: %s: the number of permanently deleted activities */
1101              $messages[] = sprintf( _n( '%s activity item has been permanently deleted.', '%s activity items have been permanently deleted.', $deleted, 'buddypress' ), number_format_i18n( $deleted ) );
1102          }
1103  
1104          if ( ! empty( $errors ) ) {
1105              if ( 1 == count( $errors ) ) {
1106                  /* translators: %s: the ID of the activity which errored during an update */
1107                  $messages[] = sprintf( __( 'An error occurred when trying to update activity ID #%s.', 'buddypress' ), number_format_i18n( $errors[0] ) );
1108  
1109              } else {
1110                  $error_msg  = __( 'Errors occurred when trying to update these activity items:', 'buddypress' );
1111                  $error_msg .= '<ul class="activity-errors">';
1112  
1113                  // Display each error as a list item.
1114                  foreach ( $errors as $error ) {
1115                      /* Translators: %s: the activity ID */
1116                      $error_msg .= '<li>' . sprintf( __( '#%s', 'buddypress' ), number_format_i18n( $error ) ) . '</li>';
1117                  }
1118  
1119                  $error_msg  .= '</ul>';
1120                  $messages[] = $error_msg;
1121              }
1122          }
1123  
1124          if ( $spammed > 0 ) {
1125              /* translators: %s: the number of activities successfully marked as spam */
1126              $messages[] = sprintf( _n( '%s activity item has been successfully spammed.', '%s activity items have been successfully spammed.', $spammed, 'buddypress' ), number_format_i18n( $spammed ) );
1127          }
1128  
1129          if ( $unspammed > 0 ) {
1130              /* translators: %s: the number of activities successfully marked as ham */
1131              $messages[] = sprintf( _n( '%s activity item has been successfully unspammed.', '%s activity items have been successfully unspammed.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) );
1132          }
1133  
1134          if ( $updated > 0 ) {
1135              $messages[] = __( 'The activity item has been updated successfully.', 'buddypress' );
1136          }
1137      }
1138  
1139      // Prepare the activity items for display.
1140      $bp_activity_list_table->prepare_items();
1141  
1142      /**
1143       * Fires before edit form is displayed so plugins can modify the activity messages.
1144       *
1145       * @since 1.6.0
1146       *
1147       * @param array $messages Array of messages to display at top of page.
1148       */
1149      do_action( 'bp_activity_admin_index', $messages ); ?>
1150  
1151      <div class="wrap">
1152          <h1>
1153              <?php if ( !empty( $_REQUEST['aid'] ) ) : ?>
1154                  <?php
1155                  /* translators: %s: the activity ID */
1156                  printf( __( 'Activity related to ID #%s', 'buddypress' ), number_format_i18n( (int) $_REQUEST['aid'] ) );
1157                  ?>
1158              <?php else : ?>
1159                  <?php _ex( 'Activity', 'Admin SWA page', 'buddypress' ); ?>
1160              <?php endif; ?>
1161  
1162              <?php if ( !empty( $_REQUEST['s'] ) ) : ?>
1163                  <span class="subtitle">
1164                      <?php
1165                      /* translators: %s: the activity search terms */
1166                      printf( __( 'Search results for &#8220;%s&#8221;', 'buddypress' ), wp_html_excerpt( esc_html( stripslashes( $_REQUEST['s'] ) ), 50 ) );
1167                      ?>
1168                  </span>
1169              <?php endif; ?>
1170          </h1>
1171  
1172          <?php // If the user has just made a change to an activity item, display the status messages. ?>
1173          <?php if ( !empty( $messages ) ) : ?>
1174              <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?> notice is-dismissible"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
1175          <?php endif; ?>
1176  
1177          <?php // Display each activity on its own row. ?>
1178          <?php $bp_activity_list_table->views(); ?>
1179  
1180          <form id="bp-activities-form" action="" method="get">
1181              <?php $bp_activity_list_table->search_box( __( 'Search all Activity', 'buddypress' ), 'bp-activity' ); ?>
1182              <input type="hidden" name="page" value="<?php echo esc_attr( $plugin_page ); ?>" />
1183              <?php $bp_activity_list_table->display(); ?>
1184          </form>
1185  
1186          <?php // This markup is used for the reply form. ?>
1187          <table style="display: none;">
1188              <tr id="bp-activities-container" style="display: none;">
1189                  <td colspan="4">
1190                      <form method="get" action="">
1191  
1192                          <h3 id="bp-replyhead"><?php _e( 'Reply to Activity', 'buddypress' ); ?></h3>
1193                          <label for="bp-activities" class="screen-reader-text"><?php
1194                              /* translators: accessibility text */
1195                              _e( 'Reply', 'buddypress' );
1196                          ?></label>
1197                          <?php wp_editor( '', 'bp-activities', array( 'dfw' => false, 'media_buttons' => false, 'quicktags' => array( 'buttons' => 'strong,em,link,block,del,ins,img,code,spell,close' ), 'tinymce' => false, ) ); ?>
1198  
1199                          <p id="bp-replysubmit" class="submit">
1200                              <a href="#" class="cancel button-secondary alignleft"><?php _e( 'Cancel', 'buddypress' ); ?></a>
1201                              <a href="#" class="save button-primary alignright"><?php _e( 'Reply', 'buddypress' ); ?></a>
1202  
1203                              <img class="waiting" style="display:none;" src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />
1204                              <span class="error" style="display:none;"></span>
1205                              <br class="clear" />
1206                          </p>
1207  
1208                          <?php wp_nonce_field( 'bp-activity-admin-reply', '_ajax_nonce-bp-activity-admin-reply', false ); ?>
1209  
1210                      </form>
1211                  </td>
1212              </tr>
1213          </table>
1214      </div>
1215  
1216  <?php
1217  }


Generated: Wed Aug 12 01:01:32 2020 Cross-referenced by PHPXref 0.7.1