/** * Get the SQL for the 'scope' param in BP_Activity_Activity::get(). * * A scope is a predetermined set of activity arguments. This method is used * to grab these activity arguments and override any existing args if needed. * * Can handle multiple scopes. * * @since 2.2.0 * * @param mixed $scope The activity scope. Accepts string or array of scopes. * @param array $r Current activity arguments. Same as those of BP_Activity_Activity::get(), * but merged with defaults. * @return array 'sql' WHERE SQL string and 'override' activity args. */ public static function get_scope_query_sql($scope = false, $r = array()) { // Define arrays for future use. $query_args = array(); $override = array(); $retval = array(); // Check for array of scopes. if (is_array($scope)) { $scopes = $scope; // Explode a comma separated string of scopes. } elseif (is_string($scope)) { $scopes = explode(',', $scope); } // Bail if no scope passed. if (empty($scopes)) { return false; } // Helper to easily grab the 'user_id'. if (!empty($r['filter']['user_id'])) { $r['user_id'] = $r['filter']['user_id']; } // Parse each scope; yes! we handle multiples! foreach ($scopes as $scope) { $scope_args = array(); /** * Plugins can hook here to set their activity arguments for custom scopes. * * This is a dynamic filter based on the activity scope. eg: * - 'bp_activity_set_groups_scope_args' * - 'bp_activity_set_friends_scope_args' * * To see how this filter is used, plugin devs should check out: * - bp_groups_filter_activity_scope() - used for 'groups' scope * - bp_friends_filter_activity_scope() - used for 'friends' scope * * @since 2.2.0 * * @param array { * Activity query clauses. * @type array { * Activity arguments for your custom scope. * See {@link BP_Activity_Query::_construct()} for more details. * } * @type array $override Optional. Override existing activity arguments passed by $r. * } * @param array $r Current activity arguments passed in BP_Activity_Activity::get(). */ $scope_args = apply_filters("bp_activity_set_{$scope}_scope_args", array(), $r); if (!empty($scope_args)) { // Merge override properties from other scopes // this might be a problem... if (!empty($scope_args['override'])) { $override = array_merge($override, $scope_args['override']); unset($scope_args['override']); } // Save scope args. if (!empty($scope_args)) { $query_args[] = $scope_args; } } } if (!empty($query_args)) { // Set relation to OR. $query_args['relation'] = 'OR'; $query = new BP_Activity_Query($query_args); $sql = $query->get_sql(); if (!empty($sql)) { $retval['sql'] = $sql; } } if (!empty($override)) { $retval['override'] = $override; } return $retval; }
/** * Access protection in the activity feed. * * Users should not see activity related to papers to which they do not have access. */ function cacsp_access_protection_for_activity_feed($where_conditions) { $protected_paper_ids = cacsp_get_protected_papers_for_user(bp_loggedin_user_id()); if (!$protected_paper_ids) { return $where_conditions; } // DeMorgan says: A & B == ( ! A || ! B ) $activity_query = new BP_Activity_Query(array('relation' => 'OR', array('column' => 'type', 'value' => array('new_cacsp_post', 'new_cacsp_comment', 'new_cacsp_edit', 'cacsp_paper_added_to_group'), 'compare' => 'NOT IN'), array('column' => 'secondary_item_id', 'value' => $protected_paper_ids, 'compare' => 'NOT IN'))); $aq_sql = $activity_query->get_sql(); if ($aq_sql) { $where_conditions[] = $aq_sql; } return $where_conditions; }