function flag($type, $id, $id2, $reporter) { list($cont_id, $flag_id) = $this->check_flag($type, $id, $id2, $reporter); if ($cont_id && $flag_id) { return 'already flagged'; } $flag_count = false; bpModLoader::load_class('bpModObjContent'); if ($cont_id) { $cont = new bpModObjContent($cont_id); } else { $callaback_info = $this->content_types[$type]->callbacks['info']; $info = call_user_func($callaback_info, $id, $id2); if (!$info) { return false; } $cont = new bpModObjContent(); $cont->item_type = $type; $cont->item_id = $id; $cont->item_id2 = $id2; $cont->item_author = $info['author']; $cont->item_url = $info['url']; $cont->item_date = $info['date']; $cont->status = 'new'; $cont->save(); $cont_id = $cont->content_id; do_action('bp_moderation_first_flag', array(&$cont)); $flag_count = 1; } if (!$cont_id) { return false; } bpModLoader::load_class('bpModObjFlag'); $flag = new bpModObjFlag(); $flag->content_id = $cont_id; $flag->reporter_id = $reporter; $flag->date = gmdate("Y-m-d H:i:s", time()); $flag->save(); if ($flag->flag_id) { if (!$flag_count) { $flag_count = $this->count_flags($cont_id); } //check and send warning message $warning_threshold = $this->options['warning_threshold']; if ('new' == $cont->status && $warning_threshold && $flag_count >= $warning_threshold) { $this->send_warning($cont, $flag_count); } do_action_ref_array('bp_moderation_content_flagged', array(&$cont, &$flag)); return true; } else { return false; } }
/** * generated random data */ function test_data() { set_time_limit(0); global $wpdb; $users = $wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE ID != 1"); if (is_multisite()) { $wpdb->query("DELETE FROM {$wpdb->signups}"); } foreach ($users as $id) { bp_core_delete_account($id); } $ngu = 2; #how much only good users $ngbu = 2; #how much not only good or only bad users $nbu = 2; #how much only bad users $content_types = array('A', 'B', 'C', 'D'); $bpmod =& bpModeration::get_istance(); $statuses = array_keys($bpmod->content_stati); $n_contents = 20; $flags_per_cont = 20; # +/- 30% $goodusers = array(); $badusers = array(); for ($i = 1; $i <= $ngu + $ngbu + $nbu; $i++) { $uid = bp_core_signup_user('user' . $i, 'pass', $i . '@foo.bar', array()); if (is_multisite()) { global $wpdb; $key_sql = "SELECT activation_key FROM {$wpdb->signups} WHERE user_email = '" . $i . "@foo.bar'"; $key = $wpdb->get_var($key_sql); } else { $key = get_user_meta($uid, 'activation_key'); } $uid = bp_core_activate_signup($key); is_multisite() and wp_set_password('pass', $uid); if ($i <= $ngu + $ngbu) { $goodusers[] = $uid; } if ($i > $ngu) { $badusers[] = $uid; } } bpModLoader::load_class('bpModObjContent'); bpModLoader::load_class('bpModObjFlag'); for ($i = 1; $i <= $n_contents; $i++) { $badu = $badusers[mt_rand(0, count($badusers) - 1)]; $cont = new bpModObjContent(); $cont->item_type = $content_types[mt_rand(0, count($content_types) - 1)]; $cont->item_id = mt_rand(1, 1000000); $cont->item_author = $badu; $cont->item_date = gmdate("Y-m-d H:i:s", time() - mt_rand(1000000, 2000000)); $cont->status = $statuses[mt_rand(0, count($statuses) - 1)]; $cont->save(); $flags = mt_rand($flags_per_cont * 0.7, $flags_per_cont * 1.3); for ($j = 1; $j <= $flags; $j++) { while ($badu == ($goodu = $goodusers[mt_rand(0, count($goodusers) - 1)])) { } $f = new bpModObjFlag(); $f->content_id = $cont->content_id; $f->reporter_id = $goodu; $f->date = gmdate("Y-m-d H:i:s", time() - mt_rand(0, 1000000)); $f->save(); } } update_site_option('bp_moderation_test_data_check', 'success'); }