You are here

function scald_rendered_to_sas in Scald: Media Management made easy 6

Same name and namespace in other branches
  1. 7 scald.module \scald_rendered_to_sas()

Process a text string and replace rendered Scald Atoms with Scald Atom Shorthand (SAS).

NOTE: Scald Core only contains an implementation for parsing Scald Atoms rendered in XHTML. Additional implementations can be supplied by implementing hook_scald_rendered_to_sas_RENDER_LANGUAGE()

NOTE: The Scald Core implementation of parsing for XHTML *assumes* that the standard Scald classes are attached to the outermost (containing) HTML element. If a Scald Context does not produce output matching this format then this function will fail to detect and replace the Scald Atoms rendered by that Context. See docs/scald_overview.txt and docs/scald_provider_api.txt for additional details. Also see the Context section in the Scald Administration pages for a tool to detect which Scald Contexts will not produce output which can be parsed by this function.

Parameters

$string: A text string to be processed.

$render_language: The expected format of $text. Should correspond to the render_language specified by Scald Contexts. Defaults to XHTML.

Return value

The source string with all rendered Scald Atoms replaced with Scald Atom Shorthand (SAS).

See also

scald_sas_to_rendered

3 calls to scald_rendered_to_sas()
mee_field in mee/mee.module
Implementation of hook_field().
scald_composite_nodeapi in scald_composite/scald_composite.module
Implementation of hook_nodeapi().
theme_mee_formatter_default in mee/mee.module

File

./scald.module, line 1947

Code

function scald_rendered_to_sas($string, $render_language = 'XHTML') {

  // If Scald Core can't handle it, maybe a Scald Provider can.
  // NOTE: This will probably fail if more than one Scald Provider implements
  //        support for the same render language.
  if ($render_language != 'XHTML') {
    $strings = module_invoke_all('scald_rendered_to_sas_' . $render_language, $string);
    return $strings[0];
  }
  return preg_replace_callback(SCALD_RENDERED_MATCH_PATTERN, create_function('$matches', '
        return \'[scald=\' . $matches[1] . (!empty($matches[2]) ? \':\' . $matches[2] : \'\') . (!empty($matches[3]) ? \' \' . $matches[3] : \'\') . \']\';
      '), $string);
}