Esempio n. 1
0
 /**
  * Get flag/unflag link
  *
  * static method for getting a reporting link
  *
  * @see bpModFrontend::generate_link for args details
  */
 function get_link($args = '')
 {
     $_this =& bpModeration::get_istance();
     return $_this->generate_link($args);
 }
Esempio n. 2
0
 /**
  * Use this function to register a content type not supported by default
  *
  * You must provides some callbacks for the content type to be handled by the plugin:
  * - init : takes no args and returns void, it is called on frontend when this content
  *		 type is active use it to hook around your link generation functions
  * - info : takes id and id2 as args, returns false if no content correspond to those ids,
  *		 otherwise an array in this format:
  *			 author => [the content author ID]
  *			 url	=> [the content permalink]
  *			 date   => [the content generation date, in mysql DATETIME format]
  * - delete : (optional) takes id and id2 as args, takes care of
  *		 deleting specified content; returns true if deleted or if it doesn't exist, false if the content exist but wasn't possible to delete it.
  * - edit : (optional) takes id and id2 as args, returns the url of
  *		 the page where the admin can edit the specified content
  *
  * If the registered content is also present in the activity stream then you should
  * provide an array of activity types that this content can be posted with, the
  * plugin will take care of displaying the flag/unflag link in the activity stream
  * id and secondary id that you provide to the activity component must coincide with those
  * you provide to this plugin
  *
  * @param string $slug internal slug, used to differentiate between content types (alfanumeric and underscore only)
  * @param string $label how this content type is called in the backend
  * @param array $callbacks associative array of callbacks, see function description for mandatory and supported callbacks
  * @param array $activity_types activity types that correspond to this content type
  * @return bool false if passed args are invalid
  */
 function register_content_type($slug, $label, $callbacks, $activity_types = null)
 {
     $_this =& bpModeration::get_istance();
     if (!$slug || !$label || !is_array($callbacks) || !is_callable($callbacks['info'])) {
         return false;
     }
     $callbacks = array_merge(array('init' => false, 'info' => false, 'delete' => false, 'editurl' => false), $callbacks);
     $ct = new stdClass();
     $ct->label = $label;
     $ct->callbacks = $callbacks;
     $_this->content_types[$slug] = $ct;
     if (empty($_this->options['active_types'][$slug])) {
         return true;
     }
     if (is_callable($callbacks['init'])) {
         call_user_func($callbacks['init']);
     }
     foreach ((array) $activity_types as $act_type) {
         $_this->types_map[$act_type] = $slug;
     }
     return true;
 }
Esempio n. 3
0
 /**
  * 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');
 }