filter_formats

Definition

filter_formats()
modules/filter.module, line 612

Description

Retrieve a list of input formats.

Code

<?php
function filter_formats() {
  global $user;
  static $formats;

  // Administrators can always use all input formats.
  $all = user_access('administer filters');

  if (!isset($formats)) {
    $formats = array();

    $query = 'SELECT * FROM {filter_formats}';

    // Build query for selecting the format(s) based on the user's roles.
    if (!$all) {
      $where = array();
      foreach ($user->roles as $rid => $role) {
        $where[] = "roles LIKE '%%,%d,%%'";
        $args[] = $rid;
      }
      $query .= ' WHERE '. implode(' OR ', $where) . ' OR format = %d';
      $args[] = variable_get('filter_default_format', 1);
    }

    $result = db_query($query, $args);
    while ($format = db_fetch_object($result)) {
      $formats[$format->format] = $format;
    }
  }
  return $formats;
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.