Ticket #6719: 6719.01.patch
| File 6719.01.patch, 10.2 KB (added by , 10 years ago) |
|---|
-
src/bp-activity/bp-activity-filters.php
152 152 153 153 // Unset the activity component so activity stream update fails 154 154 // @todo This is temporary until some kind of moderation is built. 155 if ( !bp_core_check_for_moderation( $activity->user_id, '', $activity->content ) ) 155 $moderate = bp_core_check_for_moderation( $activity->user_id, '', $activity->content, 'wp_error' ); 156 if ( is_wp_error( $moderate ) ) { 157 // Send back the same error object. 158 $activity->errors = $moderate; 159 160 // Backpat. 156 161 $activity->component = false; 162 } 157 163 } 158 164 159 165 /** -
src/bp-activity/bp-activity-functions.php
1836 1836 * Add an activity item. 1837 1837 * 1838 1838 * @since 1.1.0 1839 * 1840 * @uses wp_parse_args() 1841 * @uses BP_Activity_Activity::save() {@link BP_Activity_Activity} 1842 * @uses BP_Activity_Activity::rebuild_activity_comment_tree() {@link BP_Activity_Activity} 1843 * @uses wp_cache_delete() 1844 * @uses do_action() To call the 'bp_activity_add' hook. 1839 * @since 2.x.0 Added 'error_type' parameter to $args. 1845 1840 * 1846 1841 * @param array|string $args { 1847 1842 * An array of arguments. … … 1873 1868 * @type bool $hide_sitewide Should the item be hidden on sitewide streams? 1874 1869 * Default: false. 1875 1870 * @type bool $is_spam Should the item be marked as spam? Default: false. 1871 * @type string $error_type Optional. Error type. Either 'bool' or 'wp_error'. Default: 'bool'. 1876 1872 * } 1877 1873 * @return int|bool The ID of the activity on success. False on error. 1878 1874 */ … … 1891 1887 'recorded_time' => bp_core_current_time(), // The GMT time that this activity was recorded. 1892 1888 'hide_sitewide' => false, // Should this be hidden on the sitewide activity stream? 1893 1889 'is_spam' => false, // Is this activity item to be marked as spam? 1890 'error_type' => 'bool' 1894 1891 ), 'activity_add' ); 1895 1892 1896 1893 // Make sure we are backwards compatible. … … 1914 1911 $activity->date_recorded = $r['recorded_time']; 1915 1912 $activity->hide_sitewide = $r['hide_sitewide']; 1916 1913 $activity->is_spam = $r['is_spam']; 1914 $activity->error_type = $r['error_type']; 1917 1915 $activity->action = ! empty( $r['action'] ) 1918 ? $r['action']1919 : bp_activity_generate_action_string( $activity );1916 ? $r['action'] 1917 : bp_activity_generate_action_string( $activity ); 1920 1918 1921 if ( ! $activity->save() ) { 1919 $save = $activity->save(); 1920 if ( 'wp_error' === $r['error_type'] && is_wp_error( $save ) ) { 1921 return $save; 1922 } elseif ('bool' === $r['error_type'] && false === $save ) { 1922 1923 return false; 1923 1924 } 1924 1925 … … 1970 1971 1971 1972 $r = wp_parse_args( $args, array( 1972 1973 'content' => false, 1973 'user_id' => bp_loggedin_user_id() 1974 'user_id' => bp_loggedin_user_id(), 1975 'error_type' => 'bool', 1974 1976 ) ); 1975 1977 1976 1978 if ( empty( $r['content'] ) || !strlen( trim( $r['content'] ) ) ) { … … 2010 2012 'primary_link' => $add_primary_link, 2011 2013 'component' => buddypress()->activity->id, 2012 2014 'type' => 'activity_update', 2015 'error_type' => $r['error_type'] 2013 2016 ) ); 2014 2017 2018 if ( is_wp_error( $activity_id ) ) { 2019 return $activity_id; 2020 } 2021 2015 2022 /** 2016 2023 * Filters the latest update content for the activity item. 2017 2024 * -
src/bp-activity/classes/class-bp-activity-activity.php
134 134 var $is_spam; 135 135 136 136 /** 137 * Error holder. 138 * 139 * @since 2.5.0 140 * 141 * @var WP_Error 142 */ 143 public $errors; 144 145 /** 146 * Error type to return. Either 'bool' or 'wp_error'. 147 * 148 * @since 2.5.0 149 * 150 * @var string 151 */ 152 public $error_type = 'bool'; 153 154 /** 137 155 * Constructor method. 138 156 * 139 157 * @since 1.5.0 … … 141 159 * @param int|bool $id Optional. The ID of a specific activity item. 142 160 */ 143 161 public function __construct( $id = false ) { 162 // Instantiate errors object. 163 $this->errors = new WP_Error; 164 144 165 if ( !empty( $id ) ) { 145 166 $this->id = $id; 146 167 $this->populate(); … … 235 256 */ 236 257 do_action_ref_array( 'bp_activity_before_save', array( &$this ) ); 237 258 259 if ( 'wp_error' === $this->error_type && ! empty( $this->errors->errors ) ) { 260 return $this->errors; 261 } 262 238 263 if ( empty( $this->component ) || empty( $this->type ) ) { 239 return false; 264 if ( 'bool' === $this->error_type ) { 265 return false; 266 } else { 267 if ( empty( $this->component ) ) { 268 $this->errors->add( 'bp_activity_missing_component' ); 269 } else { 270 $this->errors->add( 'bp_activity_missing_type' ); 271 } 272 273 return $this->errors; 274 } 240 275 } 241 276 242 277 if ( empty( $this->primary_link ) ) { -
src/bp-core/bp-core-moderation.php
52 52 * Check for moderation keys and too many links. 53 53 * 54 54 * @since 1.6.0 55 * @since 2.x.0 Added $error_type parameter. 55 56 * 56 * @uses bp_current_author_ip() To get current user IP address. 57 * @uses bp_current_author_ua() To get current user agent. 58 * @uses bp_current_user_can() Allow super admins to bypass blacklist. 59 * 60 * @param int $user_id Topic or reply author ID. 61 * @param string $title The title of the content. 62 * @param string $content The content being posted. 57 * @param int $user_id Topic or reply author ID. 58 * @param string $title The title of the content. 59 * @param string $content The content being posted. 60 * @param string $error_type The error type to return. Either 'bool' or 'wp_error'. 63 61 * @return bool True if test is passed, false if fail. 64 62 */ 65 function bp_core_check_for_moderation( $user_id = 0, $title = '', $content = '' ) {63 function bp_core_check_for_moderation( $user_id = 0, $title = '', $content = '', $error_type = 'bool' ) { 66 64 67 65 /** 68 66 * Filters whether or not to bypass checking for moderation keys and too many links. … … 136 134 137 135 // Das ist zu viele links! 138 136 if ( $num_links >= $max_links ) { 139 return false; 137 if ( 'bool' === $error_type ) { 138 return false; 139 } else { 140 return new WP_Error( 'bp_moderation_too_many_links', __( 'You have inputted too many links', 'buddypress' ) ); 141 } 140 142 } 141 143 } 142 144 … … 174 176 // Check each user data for current word. 175 177 if ( preg_match( $pattern, $post_data ) ) { 176 178 177 // Post does not pass. 178 return false; 179 if ( 'bool' === $error_type ) { 180 return false; 181 } else { 182 return new WP_Error( 'bp_moderation_blacklist_match', __( 'You have inputted an inappropriate word.', 'buddypress' ) ); 183 } 179 184 } 180 185 } 181 186 } -
src/bp-groups/bp-groups-activity.php
379 379 'item_id' => false, 380 380 'secondary_item_id' => false, 381 381 'recorded_time' => bp_core_current_time(), 382 'hide_sitewide' => $hide_sitewide 382 'hide_sitewide' => $hide_sitewide, 383 'error_type' => 'bool' 383 384 ) ); 384 385 385 386 return bp_activity_add( $r ); -
src/bp-groups/bp-groups-functions.php
944 944 * Post an Activity status update affiliated with a group. 945 945 * 946 946 * @since 1.2.0 947 * @since 2.x.0 Added 'error_type' parameter to $args. 947 948 * 948 949 * @param array|string $args { 949 950 * Array of arguments. … … 963 964 $bp = buddypress(); 964 965 965 966 $defaults = array( 966 'content' => false, 967 'user_id' => bp_loggedin_user_id(), 968 'group_id' => 0 967 'content' => false, 968 'user_id' => bp_loggedin_user_id(), 969 'group_id' => 0, 970 'error_type' => 'bool' 969 971 ); 970 972 971 973 $r = wp_parse_args( $args, $defaults ); … … 1006 1008 $content_filtered = apply_filters( 'groups_activity_new_update_content', $activity_content ); 1007 1009 1008 1010 $activity_id = groups_record_activity( array( 1009 'user_id' => $user_id, 1010 'action' => $action, 1011 'content' => $content_filtered, 1012 'type' => 'activity_update', 1013 'item_id' => $group_id 1011 'user_id' => $user_id, 1012 'action' => $action, 1013 'content' => $content_filtered, 1014 'type' => 'activity_update', 1015 'item_id' => $group_id, 1016 'error_type' => $error_type 1014 1017 ) ); 1015 1018 1016 1019 groups_update_groupmeta( $group_id, 'last_activity', bp_core_current_time() ); -
src/bp-templates/bp-legacy/buddypress-functions.php
945 945 } 946 946 947 947 if ( ! $object && bp_is_active( 'activity' ) ) { 948 $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'] ) );948 $activity_id = bp_activity_post_update( array( 'content' => $_POST['content'], 'error_type' => 'wp_error' ) ); 949 949 950 950 } elseif ( 'groups' === $object ) { 951 951 if ( $item_id && bp_is_active( 'groups' ) ) 952 $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id ) );952 $activity_id = groups_post_update( array( 'content' => $_POST['content'], 'group_id' => $item_id, 'error_type' => 'wp_error' ) ); 953 953 954 954 } else { 955 955 … … 957 957 $activity_id = apply_filters( 'bp_activity_custom_update', false, $object, $item_id, $_POST['content'] ); 958 958 } 959 959 960 if ( empty( $activity_id ) )960 if ( false === $activity_id ) { 961 961 exit( '-1<div id="message" class="error bp-ajax-message"><p>' . __( 'There was a problem posting your update. Please try again.', 'buddypress' ) . '</p></div>' ); 962 } elseif ( is_wp_error( $activity_id ) && ! empty( $activity_id->errors ) ) { 963 exit( '-1<div id="message" class="error bp-ajax-message"><p>' . $activity_id->get_error_message() . '</p></div>' ); 964 } 962 965 963 966 $last_recorded = ! empty( $_POST['since'] ) ? date( 'Y-m-d H:i:s', intval( $_POST['since'] ) ) : 0; 964 967 if ( $last_recorded ) {