View source  
  <?php
function commons_reputation_install() {
  
  module_load_include('inc', 'commons_reputation', 'commons_reputation.badges');
  $badges = commons_reputation_default_badges();
  
  commons_reputation_insert_badges($badges);
  
  commons_reputation_set_auth_badge($badges);
  
  commons_reputation_set_point_thresholds($badges);
  
  commons_reputation_insert_vocabulary();
}
function commons_reputation_insert_badges($badges) {
  $sql = "INSERT INTO {user_badges_badges} (name, image, weight, fixedweight) VALUES ('%s', '%s', %d, %d)";
  foreach ($badges as $badge) {
    
    db_query($sql, $badge->name, $badge->image, $badge->weight, $badge->fixedweight);
  }
}
function commons_reputation_set_auth_badge($badges) {
  
  $badge = db_fetch_object(db_query("SELECT * FROM {user_badges_badges} WHERE name = '%s' AND image = '%s'", $badges['user']->name, $badges['user']->image));
  
  if ($badge->bid) {
    $sql = "INSERT INTO {user_badges_roles} (bid, rid) VALUES (%d, %d)";
    
    db_query($sql, $badge->bid, 2);
  }
}
function commons_reputation_set_point_thresholds($badges) {
  
  $sql = "INSERT INTO {userpoints_badges} (bid, userpoints_goal) VALUES (%d, %d)";
  
  foreach ($badges as $key => $badge) {
    
    $bid = db_result(db_query("SELECT bid FROM {user_badges_badges} WHERE name = '%s'", $badge->name));
    
    switch ($key) {
      case 'super_contributor':
        $points = 1500;
        break;
      case 'frequent_contributor':
        $points = 1000;
        break;
      case 'regular_contributor':
        $points = 1000;
        break;
      case 'contributor':
        $points = 50;
        break;
      case 'member':
        $points = 2;
        break;
      default:
        $points = 0;
        break;
    }
    if ($bid && $points) {
      
      db_query($sql, $bid, $points);
    }
  }
}
function commons_reputation_insert_vocabulary() {
  
  $vocab = array(
    'name' => t('Userpoints'),
    'description' => st('Automatically created by the userpoints module'),
    'multiple' => '0',
    'required' => '0',
    'hierarchy' => '1',
    'relations' => '0',
    'module' => 'userpoints',
  );
  taxonomy_save_vocabulary($vocab);
}