You are here

function better_formats_install in Better Formats 6

Same name and namespace in other branches
  1. 8 better_formats.install \better_formats_install()
  2. 6.2 better_formats.install \better_formats_install()
  3. 7 better_formats.install \better_formats_install()

Implementation of hook_install().

File

./better_formats.install, line 65
Installs the better_formats module.

Code

function better_formats_install() {

  // Create tables.
  drupal_install_schema('better_formats');

  // Increase module weight to prevent compatibility issues.
  $sql = "UPDATE {system}\n          SET weight = 100\n          WHERE name = 'better_formats'";
  db_query($sql);

  // Insert format defaults.
  $roles = user_roles();
  $sql = "INSERT INTO {better_formats_defaults}\n            VALUES (%d, '%s', %d, %d, %d)";
  foreach ($roles as $rid => $role) {
    db_query($sql, $rid, 'node', 0, 1, 0);
    db_query($sql, $rid, 'comment', 0, 1, 0);
    db_query($sql, $rid, 'block', 0, 1, 25);
  }

  // Set default perms to be like core defaults.
  $default_perms = ', show format selection for nodes, show format selection for comments, show format selection for blocks, show format tips, show more format tips link, collapsible format selection, collapse format fieldset by default';

  // Get current core perms.
  $sql = "SELECT *\n          FROM {permission}\n          WHERE rid IN (1,2)";
  $result = db_query($sql);
  $role_perms = array();
  while ($row = db_fetch_object($result)) {
    $role_perms[$row->rid] = $row;
  }

  // If a role has no permissions set it will not have a row in the database.
  // Assume that roles do not need perms set for BF as well if none are set.
  if (!empty($role_perms)) {

    // Add perms to core roles (anonymous user, authenticated user).
    foreach ($role_perms as $perms) {
      $sql = "UPDATE {permission}\n              SET perm = '%s'\n              WHERE pid = %d";
      db_query($sql, $perms->perm . $default_perms, $perms->pid);
    }

    // Clear the cache.
    cache_clear_all();
  }
}