You are here

function scald_filter in Scald: Media Management made easy 6

Implementation of hook_filter().

File

./scald.module, line 2774

Code

function scald_filter($op, $delta = 0, $format = -1, $text = '', $cache_id = 0) {
  switch ($op) {
    case 'list':
      return array(
        0 => t('Scald Atom Shorthand Filter'),
      );
      break;
    case 'no cache':

      // Caching is disabled to ensure that current renderings of Atoms are
      //  returned.  Invalidating specific {cache_filter} entries is nearly
      //  impossible due to a hash of the text-to-filter being used as a key.
      //  Because Scald caches Atom renderings, the performance hit should be
      //  relatively insignficant.
      return TRUE;
      break;
    case 'description':
      return t('Allows users to include Scald Atom Shorthand (SAS) in a textarea and have the Atoms rendered in a particular Scald Context.  Often combined with WYSIWYG editors and custom textarea parsing to automatically generate the SAS.');
      break;
    case 'prepare':
      return $text;
      break;
    case 'process':
      $override = variable_get('scald_filter_sas_' . $format . '_override', FALSE);
      $context = variable_get('scald_filter_sas_' . $format . '_context', FALSE);
      return scald_sas_to_rendered($text, $context, $override);
      break;
    case 'settings':
      $scald_config = variable_get('scald_config', 0);
      $context_options = array();
      $contexts_result = db_query("SELECT context, title FROM {scald_contexts} WHERE context IN ('" . implode("', '", array_keys($scald_config->contexts)) . "') ORDER BY title");
      while ($context_raw = db_fetch_array($contexts_result)) {
        $context_options[$context_raw['context']] = $context_raw['title'];
      }
      $form['filter_sas'] = array(
        '#type' => 'fieldset',
        '#title' => t('Scald Atom Shorthand Filter'),
        '#collapsible' => TRUE,
        '#collapsed' => FALSE,
      );
      $form['filter_sas']['scald_filter_sas_' . $format . '_context'] = array(
        '#type' => 'select',
        '#title' => t('Scald Context'),
        '#description' => t('Choose a Scald Context to use for rendering Scald Atoms included in the text using Scald Atom Shorthand.'),
        '#default_value' => variable_get('scald_filter_sas_' . $format . '_context', 'title'),
        '#options' => $context_options,
      );
      $form['filter_sas']['scald_filter_sas_' . $format . '_override'] = array(
        '#type' => 'checkbox',
        '#title' => t('Override specified Context'),
        '#description' => t('If checked, the Scald Context specified above will be used even if there is a Context is specified the Scald Atom Shorthand.'),
        '#default_value' => variable_get('scald_filter_sas_' . $format . '_override', FALSE),
      );
      return $form;
      break;
    default:
      return $text;
      break;
  }
}