Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
10/12/2015 05:45:14 AM (11 years ago)
Author:
tw2113
Message:

Further documentation cleanup for Activity Component.

See #6396.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-activity/classes/class-bp-activity-activity.php

    r10217 r10253  
    77 */
    88
    9 // Exit if accessed directly
     9// Exit if accessed directly.
    1010defined( 'ABSPATH' ) || exit;
    1111
    … …  
    164164                }
    165165
    166                 // Generate dynamic 'action' when possible
     166                // Generate dynamic 'action' when possible.
    167167                $action = bp_activity_generate_action_string( $this );
    168168                if ( false !== $action ) {
    … …  
    170170
    171171                // If no callback is available, use the literal string from
    172                 // the database row
     172                // the database row.
    173173                } elseif ( ! empty( $row->action ) ) {
    174174                        $this->action = $row->action;
    175175
    176                 // Provide a fallback to avoid PHP notices
     176                // Provide a fallback to avoid PHP notices.
    177177                } else {
    178178                        $this->action = '';
    … …  
    235235                }
    236236
    237                 // If this is a new activity item, set the $id property
     237                // If this is a new activity item, set the $id property.
    238238                if ( empty( $this->id ) ) {
    239239                        $this->id = $wpdb->insert_id;
    … …  
    271271         * @param array $args {
    272272         *     An array of arguments. All items are optional.
    273          *
    274273         *     @type int          $page              Which page of results to fetch. Using page=1 without per_page will result
    275274         *                                           in no pagination. Default: 1.
    … …  
    296295         * }
    297296         * @return array The array returned has two keys:
    298          *     - 'total' is the count of located activities
    299          *     - 'activities' is an array of the located activities
     297         *               - 'total' is the count of located activities
     298         *               - 'activities' is an array of the located activities
    300299         */
    301300        public static function get( $args = array() ) {
    302301                global $wpdb;
    303302
    304                 // Backward compatibility with old method of passing arguments
     303                // Backward compatibility with old method of passing arguments.
    305304                if ( !is_array( $args ) || func_num_args() > 1 ) {
    306305                        _deprecated_argument( __METHOD__, '1.6', sprintf( __( 'Arguments passed to %1$s should be in an associative array. See the inline documentation at %2$s for more details.', 'buddypress' ), __METHOD__, __FILE__ ) );
    … …  
    326325                $bp = buddypress();
    327326                $r  = wp_parse_args( $args, array(
    328                         'page'              => 1,          // The current page
    329                         'per_page'          => 25,         // Activity items per page
    330                         'max'               => false,      // Max number of items to return
    331                         'fields'            => 'all',
    332                         'sort'              => 'DESC',     // ASC or DESC
    333                         'exclude'           => false,      // Array of ids to exclude
    334                         'in'                => false,      // Array of ids to limit query by (IN)
    335                         'meta_query'        => false,      // Filter by activitymeta
    336                         'date_query'        => false,      // Filter by date
    337                         'filter_query'      => false,      // Advanced filtering - see BP_Activity_Query
    338                         'filter'            => false,      // See self::get_filter_sql()
    339                         'scope'             => false,      // Preset activity arguments
    340                         'search_terms'      => false,      // Terms to search by
    341                         'display_comments'  => false,      // Whether to include activity comments
    342                         'show_hidden'       => false,      // Show items marked hide_sitewide
    343                         'spam'              => 'ham_only', // Spam status
    344                         'update_meta_cache' => true,
    345                         'count_total'       => false,
     327                        'page'              => 1,          // The current page.
     328                        'per_page'          => 25,         // Activity items per page.
     329                        'max'               => false,      // Max number of items to return.
     330                        'fields'            => 'all',      // Fields to include.
     331                        'sort'              => 'DESC',     // ASC or DESC.
     332                        'exclude'           => false,      // Array of ids to exclude.
     333                        'in'                => false,      // Array of ids to limit query by (IN).
     334                        'meta_query'        => false,      // Filter by activitymeta.
     335                        'date_query'        => false,      // Filter by date.
     336                        'filter_query'      => false,      // Advanced filtering - see BP_Activity_Query.
     337                        'filter'            => false,      // See self::get_filter_sql().
     338                        'scope'             => false,      // Preset activity arguments.
     339                        'search_terms'      => false,      // Terms to search by.
     340                        'display_comments'  => false,      // Whether to include activity comments.
     341                        'show_hidden'       => false,      // Show items marked hide_sitewide.
     342                        'spam'              => 'ham_only', // Spam status.
     343                        'update_meta_cache' => true,       // Whether or not to update meta cache.
     344                        'count_total'       => false,      // Whether or not to use count_total.
    346345                ) );
    347346
    348                 // Select conditions
     347                // Select conditions.
    349348                $select_sql = "SELECT DISTINCT a.id";
    350349
    … …  
    353352                $join_sql   = '';
    354353
    355                 // Where conditions
     354                // Where conditions.
    356355                $where_conditions = array();
    357356
    358                 // Excluded types
     357                // Excluded types.
    359358                $excluded_types = array();
    360359
    361                 // Scope takes precedence
     360                // Scope takes precedence.
    362361                if ( ! empty( $r['scope'] ) ) {
    363362                        $scope_query = self::get_scope_query_sql( $r['scope'], $r );
    364363
    365                         // Add our SQL conditions if matches were found
     364                        // Add our SQL conditions if matches were found.
    366365                        if ( ! empty( $scope_query['sql'] ) ) {
    367366                                $where_conditions['scope_query_sql'] = $scope_query['sql'];
    368367                        }
    369368
    370                         // override some arguments if needed
     369                        // Override some arguments if needed.
    371370                        if ( ! empty( $scope_query['override'] ) ) {
    372371                                $r = self::array_replace_recursive( $r, $scope_query['override'] );
    373372                        }
    374373
    375                 // Advanced filtering
     374                // Advanced filtering.
    376375                } elseif ( ! empty( $r['filter_query'] ) ) {
    377376                        $filter_query = new BP_Activity_Query( $r['filter_query'] );
    … …  
    382381                }
    383382
    384                 // Regular filtering
     383                // Regular filtering.
    385384                if ( $r['filter'] && $filter_sql = BP_Activity_Activity::get_filter_sql( $r['filter'] ) ) {
    386385                        $where_conditions['filter_sql'] = $filter_sql;
    387386                }
    388387
    389                 // Spam
     388                // Spam.
    390389                if ( 'ham_only' == $r['spam'] ) {
    391390                        $where_conditions['spam_sql'] = 'a.is_spam = 0';
    … …  
    394393                }
    395394
    396                 // Searching
     395                // Searching.
    397396                if ( $r['search_terms'] ) {
    398397                        $search_terms_like = '%' . bp_esc_like( $r['search_terms'] ) . '%';
    … …  
    400399                }
    401400
    402                 // Sorting
     401                // Sorting.
    403402                $sort = $r['sort'];
    404403                if ( $sort != 'ASC' && $sort != 'DESC' ) {
    … …  
    411410                }
    412411
    413                 // Exclude specified items
     412                // Exclude specified items.
    414413                if ( ! empty( $r['exclude'] ) ) {
    415414                        $exclude = implode( ',', wp_parse_id_list( $r['exclude'] ) );
    … …  
    417416                }
    418417
    419                 // The specific ids to which you want to limit the query
     418                // The specific ids to which you want to limit the query.
    420419                if ( ! empty( $r['in'] ) ) {
    421420                        $in = implode( ',', wp_parse_id_list( $r['in'] ) );
    … …  
    423422                }
    424423
    425                 // Process meta_query into SQL
     424                // Process meta_query into SQL.
    426425                $meta_query_sql = self::get_meta_query_sql( $r['meta_query'] );
    427426
    … …  
    434433                }
    435434
    436                 // Process date_query into SQL
     435                // Process date_query into SQL.
    437436                $date_query_sql = self::get_date_query_sql( $r['date_query'] );
    438437
    … …  
    449448
    450449                // Exclude 'last_activity' items unless the 'action' filter has
    451                 // been explicitly set
     450                // been explicitly set.
    452451                if ( empty( $r['filter']['object'] ) ) {
    453452                        $excluded_types[] = 'last_activity';
    454453                }
    455454
    456                 // Build the excluded type sql part
     455                // Build the excluded type sql part.
    457456                if ( ! empty( $excluded_types ) ) {
    458457                        $not_in = "'" . implode( "', '", esc_sql( $excluded_types ) ) . "'";
    … …  
    473472                $where_conditions = apply_filters( 'bp_activity_get_where_conditions', $where_conditions, $r, $select_sql, $from_sql, $join_sql );
    474473
    475                 // Join the where conditions together
     474                // Join the where conditions together.
    476475                $where_sql = 'WHERE ' . join( ' AND ', $where_conditions );
    477476
    … …  
    488487                        if ( false !== strpos( $where_sql, $index ) ) {
    489488                                $the_index = $index;
    490                                 break; // Take the first one we find
     489                                break; // Take the first one we find.
    491490                        }
    492491                }
    … …  
    498497                }
    499498
    500                 // Sanitize page and per_page parameters
     499                // Sanitize page and per_page parameters.
    501500                $page     = absint( $r['page']     );
    502501                $per_page = absint( $r['per_page'] );
    … …  
    521520                if ( apply_filters( 'bp_use_legacy_activity_query', false, __METHOD__, $r ) ) {
    522521
    523                         // Legacy queries joined against the user table
     522                        // Legacy queries joined against the user table.
    524523                        $select_sql = "SELECT DISTINCT a.*, u.user_email, u.user_nicename, u.user_login, u.display_name";
    525524                        $from_sql   = " FROM {$bp->activity->table_name} a LEFT JOIN {$wpdb->users} u ON a.user_id = u.ID";
    … …  
    528527                                $pag_sql    = $wpdb->prepare( "LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page );
    529528
    530                                 /** this filter is documented in bp-activity/bp-activity-classes.php */
     529                                /** This filter is documented in bp-activity/bp-activity-classes.php */
    531530                                $activities = $wpdb->get_results( apply_filters( 'bp_activity_get_user_join_filter', "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort} {$pag_sql}", $select_sql, $from_sql, $where_sql, $sort, $pag_sql ) );
    532531                        } else {
    … …  
    548547
    549548                } else {
    550                         // Query first for activity IDs
     549                        // Query first for activity IDs.
    551550                        $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}";
    552551
    553552                        if ( ! empty( $per_page ) && ! empty( $page ) ) {
    554553                                // We query for $per_page + 1 items in order to
    555                                 // populate the has_more_items flag
     554                                // populate the has_more_items flag.
    556555                                $activity_ids_sql .= $wpdb->prepare( " LIMIT %d, %d", absint( ( $page - 1 ) * $per_page ), $per_page + 1 );
    557556                        }
    … …  
    572571
    573572                        // If we've fetched more than the $per_page value, we
    574                         // can discard the extra now
     573                        // can discard the extra now.
    575574                        if ( ! empty( $per_page ) && count( $activity_ids ) === $per_page + 1 ) {
    576575                                array_pop( $activity_ids );
    … …  
    585584
    586585                if ( 'ids' !== $r['fields'] ) {
    587                         // Get the fullnames of users so we don't have to query in the loop
     586                        // Get the fullnames of users so we don't have to query in the loop.
    588587                        $activities = self::append_user_fullnames( $activities );
    589588
    590                         // Get activity meta
     589                        // Get activity meta.
    591590                        $activity_ids = array();
    592591                        foreach ( (array) $activities as $activity ) {
    … …  
    602601                        }
    603602
    604                         // Pre-fetch data associated with activity users and other objects
     603                        // Pre-fetch data associated with activity users and other objects.
    605604                        BP_Activity_Activity::prefetch_object_data( $activities );
    606605
    607                         // Generate action strings
     606                        // Generate action strings.
    608607                        $activities = BP_Activity_Activity::generate_action_strings( $activities );
    609608                }
    … …  
    611610                $retval['activities'] = $activities;
    612611
    613                 // If $max is set, only return up to the max results
     612                // If $max is set, only return up to the max results.
    614613                if ( ! empty( $r['count_total'] ) ) {
    615614
    … …  
    644643         *
    645644         * @param array $activity_ids Array of activity IDs.
    646          *
    647645         * @return array
    648646         */
    … …  
    650648                global $wpdb;
    651649
    652                 // Bail if no activity ID's passed
     650                // Bail if no activity ID's passed.
    653651                if ( empty( $activity_ids ) ) {
    654652                        return array();
    655653                }
    656654
    657                 // Get BuddyPress
     655                // Get BuddyPress.
    658656                $bp = buddypress();
    659657
    … …  
    661659                $uncached_ids = bp_get_non_cached_ids( $activity_ids, 'bp_activity' );
    662660
    663                 // Prime caches as necessary
     661                // Prime caches as necessary.
    664662                if ( ! empty( $uncached_ids ) ) {
    665                         // Format the activity ID's for use in the query below
     663                        // Format the activity ID's for use in the query below.
    666664                        $uncached_ids_sql = implode( ',', wp_parse_id_list( $uncached_ids ) );
    667665
    668                         // Fetch data from activity table, preserving order
     666                        // Fetch data from activity table, preserving order.
    669667                        $queried_adata = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} WHERE id IN ({$uncached_ids_sql})");
    670668
    671669                        // Put that data into the placeholders created earlier,
    672                         // and add it to the cache
     670                        // and add it to the cache.
    673671                        foreach ( (array) $queried_adata as $adata ) {
    674672                                wp_cache_set( $adata->id, $adata, 'bp_activity' );
    … …  
    676674                }
    677675
    678                 // Now fetch data from the cache
     676                // Now fetch data from the cache.
    679677                foreach ( $activity_ids as $activity_id ) {
    680678                        $activities[] = wp_cache_get( $activity_id, 'bp_activity' );
    681679                }
    682680
    683                 // Then fetch user data
     681                // Then fetch user data.
    684682                $user_query = new BP_User_Query( array(
    685683                        'user_ids'        => wp_list_pluck( $activities, 'user_id' ),
    … …  
    687685                ) );
    688686
    689                 // Associated located user data with activity items
     687                // Associated located user data with activity items.
    690688                foreach ( $activities as $a_index => $a_item ) {
    691689                        $a_user_id = intval( $a_item->user_id );
    … …  
    709707         *
    710708         * @param array $activities Activities array.
    711          *
    712709         * @return array
    713710         */
    … …  
    750747         *
    751748         * @param array $activities Array of activities.
    752          *
    753749         * @return array $activities Array of activities.
    754750         */
    … …  
    776772         *
    777773         * @param array $activities Array of activities.
    778          *
    779774         * @return array
    780775         */
    … …  
    805800         * @param array $meta_query An array of meta_query filters. See the
    806801         *                          documentation for WP_Meta_Query for details.
    807          *
    808802         * @return array $sql_array 'join' and 'where' clauses.
    809803         */
    … …  
    820814
    821815                        // WP_Meta_Query expects the table name at
    822                         // $wpdb->activitymeta
     816                        // $wpdb->activitymeta.
    823817                        $wpdb->activitymeta = buddypress()->activity->table_name_meta;
    824818
    825819                        $meta_sql = $activity_meta_query->get_sql( 'activity', 'a', 'id' );
    826820
    827                         // Strip the leading AND - BP handles it in get()
     821                        // Strip the leading AND - BP handles it in get().
    828822                        $sql_array['where'] = preg_replace( '/^\sAND/', '', $meta_sql['where'] );
    829823                        $sql_array['join']  = $meta_sql['join'];
    … …  
    846840         * @param array $date_query An array of date_query parameters. See the
    847841         *                          documentation for the first parameter of WP_Date_Query.
    848          *
    849842         * @return string
    850843         */
    … …  
    852845                $sql = '';
    853846
    854                 // Date query
     847                // Date query.
    855848                if ( ! empty( $date_query ) && is_array( $date_query ) ) {
    856849                        $date_query = new BP_Date_Query( $date_query, 'date_recorded' );
    … …  
    874867         * @param  array $r      Current activity arguments. Same as those of BP_Activity_Activity::get(),
    875868         *                       but merged with defaults.
    876          *
    877869         * @return array 'sql' WHERE SQL string and 'override' activity args.
    878870         */
    879871        public static function get_scope_query_sql( $scope = false, $r = array() ) {
    880872
    881                 // Define arrays for future use
     873                // Define arrays for future use.
    882874                $query_args = array();
    883875                $override   = array();
    884876                $retval     = array();
    885877
    886                 // Check for array of scopes
     878                // Check for array of scopes.
    887879                if ( is_array( $scope ) ) {
    888880                        $scopes = $scope;
    889881
    890                 // Explode a comma separated string of scopes
     882                // Explode a comma separated string of scopes.
    891883                } elseif ( is_string( $scope ) ) {
    892884                        $scopes = explode( ',', $scope );
    893885                }
    894886
    895                 // Bail if no scope passed
     887                // Bail if no scope passed.
    896888                if ( empty( $scopes ) ) {
    897889                        return false;
    898890                }
    899891
    900                 // Helper to easily grab the 'user_id'
     892                // Helper to easily grab the 'user_id'.
    901893                if ( ! empty( $r['filter']['user_id'] ) ) {
    902894                        $r['user_id'] = $r['filter']['user_id'];
    903895                }
    904896
    905                 // parse each scope; yes! we handle multiples!
     897                // Parse each scope; yes! we handle multiples!
    906898                foreach ( $scopes as $scope ) {
    907899                        $scope_args = array();
    … …  
    922914                         *  @param array {
    923915                         *     Activity query clauses.
    924                          *
    925916                         *     @type array {
    926917                         *         Activity arguments for your custom scope.
    … …  
    934925
    935926                        if ( ! empty( $scope_args ) ) {
    936                                 // merge override properties from other scopes
     927                                // Merge override properties from other scopes
    937928                                // this might be a problem...
    938929                                if ( ! empty( $scope_args['override'] ) ) {
    … …  
    941932                                }
    942933
    943                                 // save scope args
     934                                // Save scope args.
    944935                                if ( ! empty( $scope_args ) ) {
    945936                                        $query_args[] = $scope_args;
    … …  
    949940
    950941                if ( ! empty( $query_args ) ) {
    951                         // set relation to OR
     942                        // Set relation to OR.
    952943                        $query_args['relation'] = 'OR';
    953944
    … …  
    982973         * @param string   $sort             MySQL column sort; ASC or DESC. (Optional; default is DESC).
    983974         * @param bool     $display_comments Retrieve an activity item's associated comments or not. (Optional; default is false).
    984          *
    985975         * @return array
    986976         */
    … …  
    992982        /**
    993983         * Get the first activity ID that matches a set of criteria.
     984         *
     985         * @todo Should parameters be optional?
    994986         *
    995987         * @param int    $user_id           User ID to filter by.
    … …  
    1001993         * @param string $content           Content to filter by.
    1002994         * @param string $date_recorded     Date to filter by.
    1003          *
    1004          * @todo Should parameters be optional?
    1005          *
    1006995         * @return int|bool Activity ID on success, false if none is found.
    1007996         */
    … …  
    10741063         *     @int    $hide_sitewide     Optional. Default: false.
    10751064         * }
    1076          *
    10771065         * @return array|bool An array of deleted activity IDs on success, false on failure.
    10781066         */
    … …  
    10951083                ) );
    10961084
    1097                 // Setup empty array from where query arguments
     1085                // Setup empty array from where query arguments.
    10981086                $where_args = array();
    10991087
    1100                 // ID
     1088                // ID.
    11011089                if ( ! empty( $r['id'] ) ) {
    11021090                        $where_args[] = $wpdb->prepare( "id = %d", $r['id'] );
    11031091                }
    11041092
    1105                 // User ID
     1093                // User ID.
    11061094                if ( ! empty( $r['user_id'] ) ) {
    11071095                        $where_args[] = $wpdb->prepare( "user_id = %d", $r['user_id'] );
    11081096                }
    11091097
    1110                 // Action
     1098                // Action.
    11111099                if ( ! empty( $r['action'] ) ) {
    11121100                        $where_args[] = $wpdb->prepare( "action = %s", $r['action'] );
    11131101                }
    11141102
    1115                 // Content
     1103                // Content.
    11161104                if ( ! empty( $r['content'] ) ) {
    11171105                        $where_args[] = $wpdb->prepare( "content = %s", $r['content'] );
    11181106                }
    11191107
    1120                 // Component
     1108                // Component.
    11211109                if ( ! empty( $r['component'] ) ) {
    11221110                        $where_args[] = $wpdb->prepare( "component = %s", $r['component'] );
    11231111                }
    11241112
    1125                 // Type
     1113                // Type.
    11261114                if ( ! empty( $r['type'] ) ) {
    11271115                        $where_args[] = $wpdb->prepare( "type = %s", $r['type'] );
    11281116                }
    11291117
    1130                 // Primary Link
     1118                // Primary Link.
    11311119                if ( ! empty( $r['primary_link'] ) ) {
    11321120                        $where_args[] = $wpdb->prepare( "primary_link = %s", $r['primary_link'] );
    11331121                }
    11341122
    1135                 // Item ID
     1123                // Item ID.
    11361124                if ( ! empty( $r['item_id'] ) ) {
    11371125                        $where_args[] = $wpdb->prepare( "item_id = %d", $r['item_id'] );
    11381126                }
    11391127
    1140                 // Secondary item ID
     1128                // Secondary item ID.
    11411129                if ( ! empty( $r['secondary_item_id'] ) ) {
    11421130                        $where_args[] = $wpdb->prepare( "secondary_item_id = %d", $r['secondary_item_id'] );
    11431131                }
    11441132
    1145                 // Date Recorded
     1133                // Date Recorded.
    11461134                if ( ! empty( $r['date_recorded'] ) ) {
    11471135                        $where_args[] = $wpdb->prepare( "date_recorded = %s", $r['date_recorded'] );
    11481136                }
    11491137
    1150                 // Hidden sitewide
     1138                // Hidden sitewide.
    11511139                if ( ! empty( $r['hide_sitewide'] ) ) {
    11521140                        $where_args[] = $wpdb->prepare( "hide_sitewide = %d", $r['hide_sitewide'] );
    11531141                }
    11541142
    1155                 // Bail if no where arguments
     1143                // Bail if no where arguments.
    11561144                if ( empty( $where_args ) ) {
    11571145                        return false;
    11581146                }
    11591147
    1160                 // Join the where arguments for querying
     1148                // Join the where arguments for querying.
    11611149                $where_sql = 'WHERE ' . join( ' AND ', $where_args );
    11621150
    1163                 // Fetch all activities being deleted so we can perform more actions
     1151                // Fetch all activities being deleted so we can perform more actions.
    11641152                $activities = $wpdb->get_results( "SELECT * FROM {$bp->activity->table_name} {$where_sql}" );
    11651153
    … …  
    11741162                do_action_ref_array( 'bp_activity_before_delete', array( $activities, $r ) );
    11751163
    1176                 // Attempt to delete activities from the database
     1164                // Attempt to delete activities from the database.
    11771165                $deleted = $wpdb->query( "DELETE FROM {$bp->activity->table_name} {$where_sql}" );
    11781166
    1179                 // Bail if nothing was deleted
     1167                // Bail if nothing was deleted.
    11801168                if ( empty( $deleted ) ) {
    11811169                        return false;
    … …  
    11921180                do_action_ref_array( 'bp_activity_after_delete', array( $activities, $r ) );
    11931181
    1194                 // Pluck the activity IDs out of the $activities array
     1182                // Pluck the activity IDs out of the $activities array.
    11951183                $activity_ids = wp_parse_id_list( wp_list_pluck( $activities, 'id' ) );
    11961184
    1197                 // Handle accompanying activity comments and meta deletion
     1185                // Handle accompanying activity comments and meta deletion.
    11981186                if ( ! empty( $activity_ids ) ) {
    11991187
    1200                         // Delete all activity meta entries for activity items
     1188                        // Delete all activity meta entries for activity items.
    12011189                        BP_Activity_Activity::delete_activity_meta_entries( $activity_ids );
    12021190
    1203                         // Setup empty array for comments
     1191                        // Setup empty array for comments.
    12041192                        $comment_ids = array();
    12051193
    1206                         // Loop through activity ids and attempt to delete comments
     1194                        // Loop through activity ids and attempt to delete comments.
    12071195                        foreach ( $activity_ids as $activity_id ) {
    12081196
    1209                                 // Attempt to delete comments
     1197                                // Attempt to delete comments.
    12101198                                $comments = BP_Activity_Activity::delete( array(
    12111199                                        'type'    => 'activity_comment',
    … …  
    12131201                                ) );
    12141202
    1215                                 // Merge IDs together
     1203                                // Merge IDs together.
    12161204                                if ( ! empty( $comments ) ) {
    12171205                                        $comment_ids = array_merge( $comment_ids, $comments );
    … …  
    12191207                        }
    12201208
    1221                         // Merge activity IDs with any deleted comment IDs
     1209                        // Merge activity IDs with any deleted comment IDs.
    12221210                        if ( ! empty( $comment_ids ) ) {
    12231211                                $activity_ids = array_unique( array_merge( $activity_ids, $comment_ids ) );
    … …  
    12381226         *
    12391227         * @param array $activity_ids Activity IDs whose comments should be deleted.
    1240          * @param bool  $delete_meta  Should we delete the activity meta items for these comments?
     1228         * @param bool  $delete_meta  Should we delete the activity meta items for these comments.
    12411229         *
    12421230         * @return bool True on success.
    … …  
    12511239
    12521240                if ( $delete_meta ) {
    1253                         // Fetch the activity comment IDs for our deleted activity items
     1241                        // Fetch the activity comment IDs for our deleted activity items.
    12541242                        $activity_comment_ids = $wpdb->get_col( "SELECT id FROM {$bp->activity->table_name} WHERE type = 'activity_comment' AND item_id IN ({$activity_ids})" );
    12551243
    … …  
    12681256         *
    12691257         * @param array $activity_ids Activity IDs whose meta should be deleted.
    1270          *
    12711258         * @return bool True on success.
    12721259         */
    … …  
    12901277         * @param array  $activities Activities to fetch comments for.
    12911278         * @param string $spam       Optional. 'ham_only' (default), 'spam_only' or 'all'.
    1292          *
    12931279         * @return array The updated activities with nested comments.
    12941280         */
    … …  
    13021288                }
    13031289
    1304                 // Merge the comments with the activity items
     1290                // Merge the comments with the activity items.
    13051291                foreach ( (array) $activities as $key => $activity ) {
    13061292                        if ( isset( $activity_comments[$activity->id] ) ) {
    … …  
    13241310         * @param string $spam                Optional. 'ham_only' (default), 'spam_only' or 'all'.
    13251311         * @param int    $top_level_parent_id Optional. The id of the root-level parent activity item.
    1326          *
    13271312         * @return array The updated activities with nested comments.
    13281313         */
    … …  
    13371322
    13381323                // We store the string 'none' to cache the fact that the
    1339                 // activity item has no comments
     1324                // activity item has no comments.
    13401325                if ( 'none' === $comments ) {
    13411326                        $comments = false;
    13421327
    1343                 // A true cache miss
     1328                // A true cache miss.
    13441329                } elseif ( empty( $comments ) ) {
    13451330
    13461331                        $bp = buddypress();
    13471332
    1348                         // Select the user's fullname with the query
     1333                        // Select the user's fullname with the query.
    13491334                        if ( bp_is_active( 'xprofile' ) ) {
    13501335                                $fullname_select = ", pd.value as user_fullname";
    … …  
    13521337                                $fullname_where = "AND pd.user_id = a.user_id AND pd.field_id = 1";
    13531338
    1354                         // Prevent debug errors
     1339                        // Prevent debug errors.
    13551340                        } else {
    13561341                                $fullname_select = $fullname_from = $fullname_where = '';
    13571342                        }
    13581343
    1359                         // Don't retrieve activity comments marked as spam
     1344                        // Don't retrieve activity comments marked as spam.
    13601345                        if ( 'ham_only' == $spam ) {
    13611346                                $spam_sql = 'AND a.is_spam = 0';
    … …  
    13661351                        }
    13671352
    1368                         // Legacy query - not recommended
     1353                        // Legacy query - not recommended.
    13691354                        $func_args = func_get_args();
    13701355
    … …  
    14071392                        $ref = array();
    14081393
    1409                         // Loop descendants and build an assoc array
     1394                        // Loop descendants and build an assoc array.
    14101395                        foreach ( (array) $descendants as $d ) {
    14111396                                $d->children = array();
    14121397
    1413                                 // If we have a reference on the parent
     1398                                // If we have a reference on the parent.
    14141399                                if ( isset( $ref[ $d->secondary_item_id ] ) ) {
    14151400                                        $ref[ $d->secondary_item_id ]->children[ $d->id ] = $d;
    14161401                                        $ref[ $d->id ] =& $ref[ $d->secondary_item_id ]->children[ $d->id ];
    14171402
    1418                                 // If we don't have a reference on the parent, put in the root level
     1403                                // If we don't have a reference on the parent, put in the root level.
    14191404                                } else {
    14201405                                        $comments[ $d->id ] = $d;
    … …  
    14231408                        }
    14241409
    1425                         // Calculate depth for each item
     1410                        // Calculate depth for each item.
    14261411                        foreach ( $ref as &$r ) {
    14271412                                $depth = 1;
    … …  
    14321417
    14331418                                        // When display_comments=stream, the parent comment may not be part of the
    1434                                         // returned results, so we manually fetch it
     1419                                        // returned results, so we manually fetch it.
    14351420                                        if ( empty( $ref[ $parent_id ] ) ) {
    14361421                                                $direct_parent = new BP_Activity_Activity( $parent_id );
    14371422                                                if ( isset( $direct_parent->secondary_item_id ) ) {
    14381423                                                        // If the direct parent is not an activity update, that means we've reached
    1439                                                         // the parent activity item (eg. new_blog_post)
     1424                                                        // the parent activity item (eg. new_blog_post).
    14401425                                                        if ( 'activity_update' !== $direct_parent->type ) {
    14411426                                                                $parent_id = $r->item_id;
    … …  
    14461431
    14471432                                                } else {
    1448                                                         // Something went wrong.  Short-circuit the depth calculation
     1433                                                        // Something went wrong.  Short-circuit the depth calculation.
    14491434                                                        $parent_id = $r->item_id;
    14501435                                                }
    … …  
    14881473                $bp = buddypress();
    14891474
    1490                 // The right value of this node is the left value + 1
     1475                // The right value of this node is the left value + 1.
    14911476                $right = intval( $left + 1 );
    14921477
    1493                 // Get all descendants of this node
     1478                // Get all descendants of this node.
    14941479                $comments    = BP_Activity_Activity::get_child_comments( $parent_id );
    14951480                $descendants = wp_list_pluck( $comments, 'id' );
    14961481
    1497                 // Loop the descendants and recalculate the left and right values
     1482                // Loop the descendants and recalculate the left and right values.
    14981483                foreach ( (array) $descendants as $descendant_id ) {
    14991484                        $right = BP_Activity_Activity::rebuild_activity_comment_tree( $descendant_id, $right );
    … …  
    15011486
    15021487                // We've got the left value, and now that we've processed the children
    1503                 // of this node we also know the right value
     1488                // of this node we also know the right value.
    15041489                if ( 1 === $left ) {
    15051490                        $wpdb->query( $wpdb->prepare( "UPDATE {$bp->activity->table_name} SET mptt_left = %d, mptt_right = %d WHERE id = %d", $left, $right, $parent_id ) );
    … …  
    15081493                }
    15091494
    1510                 // Return the right value of this node + 1
     1495                // Return the right value of this node + 1.
    15111496                return intval( $right + 1 );
    15121497        }
    … …  
    15201505         *
    15211506         * @param int $parent_id ID of an activity or activity comment.
    1522          *
    15231507         * @return object Numerically indexed array of child comments.
    15241508         */
    … …  
    15351519         *
    15361520         * @param bool $skip_last_activity If true, components will not be
    1537          *        included if the only activity type associated with them is
    1538          *        'last_activity'. (Since 2.0.0, 'last_activity' is stored in
    1539          *        the activity table, but these items are not full-fledged
    1540          *        activity items.) Default: true.
    1541          *
     1521         *                                 included if the only activity type associated with them is
     1522         *                                 'last_activity'. (Since 2.0.0, 'last_activity' is stored in
     1523         *                                 the activity table, but these items are not full-fledged
     1524         *                                 activity items.) Default: true.
    15421525         * @return array List of component names.
    15431526         */
    … …  
    15601543         *
    15611544         * @param int $limit Optional. Number of items to fetch. Default: 35.
    1562          *
    15631545         * @return array $activity_feed List of activity items, with RSS data added.
    15641546         */
    … …  
    15871569         * @param string     $field The database field.
    15881570         * @param array|bool $items The values for the IN clause, or false when none are found.
    1589          *
    15901571         * @return string|bool
    15911572         */
    … …  
    15931574                global $wpdb;
    15941575
    1595                 // split items at the comma
     1576                // Split items at the comma.
    15961577                if ( ! is_array( $items ) ) {
    15971578                        $items = explode( ',', $items );
    15981579                }
    15991580
    1600                 // array of prepared integers or quoted strings
     1581                // Array of prepared integers or quoted strings.
    16011582                $items_prepared = array();
    16021583
    1603                 // clean up and format each item
     1584                // Clean up and format each item.
    16041585                foreach ( $items as $item ) {
    1605                         // clean up the string
     1586                        // Clean up the string.
    16061587                        $item = trim( $item );
    1607                         // pass everything through prepare for security and to safely quote strings
     1588                        // Pass everything through prepare for security and to safely quote strings.
    16081589                        $items_prepared[] = ( is_numeric( $item ) ) ? $wpdb->prepare( '%d', $item ) : $wpdb->prepare( '%s', $item );
    16091590                }
    16101591
    1611                 // build IN operator sql syntax
     1592                // Build IN operator sql syntax.
    16121593                if ( count( $items_prepared ) )
    16131594                        return sprintf( '%s IN ( %s )', trim( $field ), implode( ',', $items_prepared ) );
    … …  
    16391620         *                                          given MySQL-formatted date.
    16401621         * }
    1641          *
    16421622         * @return string The filter clause, for use in a SQL query.
    16431623         */
    … …  
    16821662
    16831663                if ( ! empty( $filter_array['since'] ) ) {
    1684                         // Validate that this is a proper Y-m-d H:i:s date
    1685                         // Trick: parse to UNIX date then translate back
     1664                        // Validate that this is a proper Y-m-d H:i:s date.
     1665                        // Trick: parse to UNIX date then translate back.
    16861666                        $translated_date = date( 'Y-m-d H:i:s', strtotime( $filter_array['since'] ) );
    16871667                        if ( $translated_date === $filter_array['since'] ) {
    … …  
    17171697         *
    17181698         * @param int $user_id The ID of the user whose favorites you're counting.
    1719          *
    17201699         * @return int $value A count of the user's favorites.
    17211700         */
    17221701        public static function total_favorite_count( $user_id ) {
    17231702
    1724                 // Get activities from user meta
     1703                // Get activities from user meta.
    17251704                $favorite_activity_entries = bp_get_user_meta( $user_id, 'bp_favorite_activities', true );
    17261705                if ( ! empty( $favorite_activity_entries ) ) {
    … …  
    17281707                }
    17291708
    1730                 // No favorites
     1709                // No favorites.
    17311710                return 0;
    17321711        }
    … …  
    17361715         *
    17371716         * @param string $content The content to filter by.
    1738          *
    17391717         * @return int|bool The ID of the first matching item if found, otherwise false.
    17401718         */
    … …  
    17511729         *
    17521730         * @param int $user_id The ID of the user whose activity you want to mark hidden.
    1753          *
    17541731         * @return mixed
    17551732         */
    … …  
    17651742         * PHP-agnostic version of {@link array_replace_recursive()}.
    17661743         *
    1767          * array_replace_recursive() is a PHP 5.3 function.  BuddyPress (and
     1744         * The array_replace_recursive() function is a PHP 5.3 function.  BuddyPress (and
    17681745         * WordPress) currently supports down to PHP 5.2, so this method is a workaround
    17691746         * for PHP 5.2.
    … …  
    17801757         * @param  array $base         Array with keys needing to be replaced.
    17811758         * @param  array $replacements Array with the replaced keys.
    1782          *
    17831759         * @return array
    17841760         */
    … …  
    17891765
    17901766                // PHP 5.2-compatible version
    1791                 // http://php.net/manual/en/function.array-replace-recursive.php#109390
     1767                // http://php.net/manual/en/function.array-replace-recursive.php#109390.
    17921768                foreach ( array_slice( func_get_args(), 1 ) as $replacements ) {
    17931769                        $bref_stack = array( &$base );
Note: See TracChangeset for help on using the changeset viewer.