You are here

function better_formats_get_default_format in Better Formats 6

Same name and namespace in other branches
  1. 6.2 better_formats.module \better_formats_get_default_format()

Returns the default format for an new node or comment.

Parameters

$mode: 'node', 'comment', or 'block'. Describes the top level type of default.

Return value

Format ID.

See also

better_formats_set_node_format()

better_formats_set_comment_format()

better_formats_textarea_process()

4 calls to better_formats_get_default_format()
better_formats_set_block_format in ./better_formats.module
Processes formats for core block form.
better_formats_set_comment_format in ./better_formats.module
Processes formats for core node comment form.
better_formats_set_node_format in ./better_formats.module
Processes formats for core node body fields.
better_formats_text_process in ./better_formats.module
Processes a CCK text elements.

File

./better_formats.module, line 464
Enhances Drupal's core input format settings.

Code

function better_formats_get_default_format($mode, $node_type = '') {
  static $format;

  // Default our type to the mode (node or comment).
  $type = $mode;

  // Check if per node type is enabled and set type accordingly.
  $per_node_type = variable_get('better_formats_per_node_type', FALSE);
  if ($per_node_type && $node_type) {
    $type = $mode . '/' . $node_type;
  }

  // Only pull from the DB if we have not already checked for this specific type.
  if (!isset($format[$type])) {
    global $user;
    $types = $type;
    $format = array();
    $roles = implode(',', array_keys($user->roles));

    // Prepare types for SQL.
    if ($mode !== 'block' && $per_node_type && $node_type) {
      $types .= "','" . $mode;
    }

    // Get user's lowest weight role default.
    $sql = "SELECT format\n            FROM {better_formats_defaults}\n            WHERE rid IN ({$roles}) AND type IN ('{$types}')\n            ORDER BY type_weight DESC, weight ASC";
    $row = db_fetch_object(db_query_range($sql, 0, 1));
    $format[$type] = filter_resolve_format($row->format);
  }
  return $format[$type];
}