You are here

function hashtags_add_filter in Hashtags 6

Same name and namespace in other branches
  1. 7 hashtags.module \hashtags_add_filter()
2 calls to hashtags_add_filter()
hashtags_enable in ./hashtags.install
Implementation of hook_enable().
hashtags_update_6001 in ./hashtags.install
Implementation of hook_update_600N().

File

./hashtags.module, line 143

Code

function hashtags_add_filter() {
  $added_status = array();
  $filtered_html_format = 1;

  // check if hashtag filter has been added to 'Filtered HTML' input formtat
  $is_hashtag_filter_exists = db_result(db_query('SELECT COUNT(*) FROM {filters} WHERE format = %d AND module = "%s" AND delta = 0', $filtered_html_format, 'hashtags'));
  if (!$is_hashtag_filter_exists) {
    $max_filter_weight = db_result(db_query('SELECT MAX(weight) FROM {filters} WHERE format = %d', $filtered_html_format));
    db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $filtered_html_format, 'hashtags', 0, $max_filter_weight + 1);
    $added_status[] = $filtered_html_format;
    drupal_set_message(t('Hashtags module: Hashtags filter has been added to "Filter HTML" input format'));
  }
  $full_html_format = 2;

  // admin can remove Full HTML format from database - need to check...
  $is_format_exists = db_result(db_query('SELECT COUNT(*) FROM {filter_formats} WHERE format = %d', $full_html_format));
  if ($is_format_exists) {
    $is_hashtag_filter_exists = db_result(db_query('SELECT COUNT(*) FROM {filters} WHERE format = %d AND module = "%s" AND delta = 0', $full_html_format, 'hashtags'));
    if (!$is_hashtag_filter_exists) {
      $max_filter_weight = db_result(db_query('SELECT MAX(weight) FROM {filters} WHERE format = %d', $full_html_format));
      db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)", $full_html_format, 'hashtags', 0, $max_filter_weight + 1);
      $added_status[] = $full_html_format;
      drupal_set_message(t('Hashtags module: Hashtags filter has been added to "Full HTML" input format'));
    }
  }
  if (sizeof($added_status)) {
    return TRUE;
  }
  return FALSE;
}