Changeset 9257 for trunk/src/bp-activity/bp-activity-classes.php
- Timestamp:
- 12/22/2014 09:46:50 PM (12 years ago)
- File:
-
- 1 edited
-
trunk/src/bp-activity/bp-activity-classes.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-activity/bp-activity-classes.php
r9256 r9257 261 261 * An array of arguments. All items are optional. 262 262 * 263 * @type int $page Which page of results to fetch. Using page=1 without per_page will result 264 * in no pagination. Default: 1. 265 * @type int|bool $per_page Number of results per page. Default: 25. 266 * @type int|bool $max Maximum number of results to return. Default: false (unlimited). 267 * @type string $sort ASC or DESC. Default: 'DESC'. 268 * @type array $exclude Array of activity IDs to exclude. Default: false. 269 * @type array $in Array of ids to limit query by (IN). Default: false. 270 * @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries. 271 * @type array $date_query Array of date_query conditions. See first parameter of 272 * WP_Date_Query::__construct(). 273 * @type array $filter_query Array of advanced query conditions. See BP_Activity_Query::__construct(). 274 * @type array $filter See BP_Activity_Activity::get_filter_sql(). 275 * @type string $search_terms Limit results by a search term. Default: false. 276 * @type bool $display_comments Whether to include activity comments. Default: false. 277 * @type bool $show_hidden Whether to show items marked hide_sitewide. Default: false. 278 * @type string $spam Spam status. Default: 'ham_only'. 279 * @type bool $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true. 280 * @type string|bool $count_total If true, an additional DB query is run to count the total activity items 281 * for the query. Default: false. 263 * @type int $page Which page of results to fetch. Using page=1 without per_page will result 264 * in no pagination. Default: 1. 265 * @type int|bool $per_page Number of results per page. Default: 25. 266 * @type int|bool $max Maximum number of results to return. Default: false (unlimited). 267 * @type string $sort ASC or DESC. Default: 'DESC'. 268 * @type array $exclude Array of activity IDs to exclude. Default: false. 269 * @type array $in Array of ids to limit query by (IN). Default: false. 270 * @type array $meta_query Array of meta_query conditions. See WP_Meta_Query::queries. 271 * @type array $date_query Array of date_query conditions. See first parameter of 272 * WP_Date_Query::__construct(). 273 * @type array $filter_query Array of advanced query conditions. See BP_Activity_Query::__construct(). 274 * @type string|array $scope Pre-determined set of activity arguments. 275 * @type array $filter See BP_Activity_Activity::get_filter_sql(). 276 * @type string $search_terms Limit results by a search term. Default: false. 277 * @type bool $display_comments Whether to include activity comments. Default: false. 278 * @type bool $show_hidden Whether to show items marked hide_sitewide. Default: false. 279 * @type string $spam Spam status. Default: 'ham_only'. 280 * @type bool $update_meta_cache Whether to pre-fetch metadata for queried activity items. Default: true. 281 * @type string|bool $count_total If true, an additional DB query is run to count the total activity items 282 * for the query. Default: false. 282 283 * } 283 284 * @return array The array returned has two keys: … … 321 322 'filter_query' => false, // Advanced filtering - see BP_Activity_Query 322 323 'filter' => false, // See self::get_filter_sql() 324 'scope' => false, // Preset activity arguments 323 325 'search_terms' => false, // Terms to search by 324 326 'display_comments' => false, // Whether to include activity comments … … 343 345 $excluded_types = array(); 344 346 347 // Scope takes precedence 348 if ( ! empty( $r['scope'] ) ) { 349 $scope_query = self::get_scope_query_sql( $r['scope'], $r ); 350 351 if ( ! empty( $scope_query['sql'] ) ) { 352 $where_conditions['scope_query_sql'] = $scope_query['sql']; 353 } 354 355 // override some arguments if needed 356 if ( ! empty( $scope_query['override'] ) ) { 357 $r = array_replace_recursive( $r, $scope_query['override'] ); 358 } 345 359 // Advanced filtering 346 if ( ! empty( $r['filter_query'] ) ) {360 } elseif ( ! empty( $r['filter_query'] ) ) { 347 361 $filter_query = new BP_Activity_Query( $r['filter_query'] ); 348 362 if ( $sql = $filter_query->get_sql() ) { … … 521 535 522 536 } else { 523 524 537 // Query first for activity IDs 525 538 $activity_ids_sql = "{$select_sql} {$from_sql} {$join_sql} {$where_sql} ORDER BY a.date_recorded {$sort}"; … … 819 832 820 833 return $sql; 834 } 835 836 /** 837 * Get the SQL for the 'scope' param in BP_Activity_Activity::get(). 838 * 839 * A scope is a predetermined set of activity arguments. This method is used 840 * to grab these activity arguments and override any existing args if needed. 841 * 842 * Can handle multple scopes. 843 * 844 * @since BuddyPress (2.2.0) 845 * 846 * @param string $scope The activity scope 847 * @param array $r Current activity arguments. Same as those of BP_Activity_Activity::get(), 848 * but merged with defaults. 849 * @return array 'sql' WHERE SQL string and 'override' activity args 850 */ 851 public static function get_scope_query_sql( $scope = '', $r = array() ) { 852 $query_args = array(); 853 $override = array(); 854 $retval = array(); 855 856 if ( ! is_array( $scope ) ) { 857 $scopes = explode( ',', $scope ); 858 } else { 859 $scopes = $scope; 860 } 861 862 if ( empty( $scopes ) ) { 863 return $sql; 864 } 865 866 // helper to easily grab the 'user_id' 867 if ( ! empty( $r['filter']['user_id'] ) ) { 868 $r['user_id'] = $r['filter']['user_id']; 869 } 870 871 // parse each scope; yes! we handle multiples! 872 foreach ( $scopes as $scope ) { 873 $scope_args = array(); 874 875 switch ( $scope ) { 876 case 'just-me' : 877 $scope_args = array( 878 'column' => 'user_id', 879 'value' => $r['user_id'] 880 ); 881 882 $scope_args['override']['display_comments'] = 'stream'; 883 884 // wipe out the user ID 885 $scope_args['override']['filter']['user_id'] = 0; 886 887 break; 888 889 case 'favorites': 890 $favs = bp_activity_get_user_favorites( $r['user_id'] ); 891 if ( empty( $favs ) ) { 892 return $scope_args; 893 } 894 895 $scope_args = array( 896 'column' => 'id', 897 'compare' => 'IN', 898 'value' => (array) $favs 899 ); 900 $scope_args['override']['display_comments'] = true; 901 902 // wipe out the user ID 903 $scope_args['override']['filter']['user_id'] = 0; 904 905 break; 906 907 case 'mentions': 908 // Are mentions disabled? 909 if ( ! bp_activity_do_mentions() ) { 910 return $scope_args; 911 } 912 913 $scope_args = array( 914 'column' => 'content', 915 'compare' => 'LIKE', 916 917 // Start search at @ symbol and stop search at closing tag delimiter. 918 'value' => '@' . bp_activity_get_user_mentionname( $r['user_id'] ) . '<' 919 ); 920 921 // wipe out current search terms if any 922 // this is so the 'mentions' scope can be combined with other scopes 923 $scope_args['override']['search_terms'] = false; 924 925 $scope_args['override']['display_comments'] = 'stream'; 926 $scope_args['override']['filter']['user_id'] = 0; 927 928 break; 929 930 default : 931 /** 932 * Plugins can hook here to set their activity arguments for custom scopes. 933 * 934 * This is a dynamic filter based on the activity scope. eg: 935 * - 'bp_activity_set_groups_scope_args' 936 * - 'bp_activity_set_friends_scope_args' 937 * 938 * To see how this filter is used, plugin devs should check out: 939 * - bp_groups_filter_activity_scope() - used for 'groups' scope 940 * - bp_friends_filter_activity_scope() - used for 'friends' scope 941 * 942 * @since BuddyPress (2.2.0) 943 * 944 * @param array { 945 * Activity query clauses. 946 * 947 * @type array { 948 * Activity arguments for your custom scope. 949 * See {@link BP_Activity_Query::_construct()} for more details. 950 * } 951 * @type array $override Optional. Override existing activity arguments passed by $r. 952 * } 953 * @param array $r Current activity arguments passed in BP_Activity_Activity::get() 954 */ 955 $scope_args = apply_filters( "bp_activity_set_{$scope}_scope_args", array(), $r ); 956 break; 957 } 958 959 if ( ! empty( $scope_args ) ) { 960 // merge override properties from other scopes 961 // this might be a problem... 962 if ( ! empty( $scope_args['override'] ) ) { 963 $override = array_merge( $override, $scope_args['override'] ); 964 unset( $scope_args['override'] ); 965 } 966 967 // save scope args 968 if ( ! empty( $scope_args ) ) { 969 $query_args[] = $scope_args; 970 } 971 } 972 } 973 974 if ( ! empty( $query_args ) ) { 975 // set relation to OR 976 $query_args['relation'] = 'OR'; 977 978 $query = new BP_Activity_Query( $query_args ); 979 if ( $sql = $query->get_sql() ) { 980 $retval['sql'] = $sql; 981 } 982 } 983 984 if ( ! empty( $override ) ) { 985 $retval['override'] = $override; 986 } 987 988 return $retval; 821 989 } 822 990
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)