You are here

function scald_rendered_to_sas in Scald: Media Management made easy 7

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

Process a text string and replace rendered atoms with their SAS.

Find all the Scald Atoms rendered markup that are embedded in the provided source string, and replace all of them with their Scald Atom Shorthand.

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 $string: A text string to be processed.

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

Return value

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

See also

scald_sas_to_rendered()

2 calls to scald_rendered_to_sas()
text_field_presave in modules/fields/mee/mee.module
Implements hook_field_presave() on behalf of Text module.
_mee_process_item_value in modules/fields/mee/mee.module
Extracts sids and copyright from $item. Updates $item if necessary.

File

./scald.module, line 955
The Scald Core, which handles all Scald Registries and dispatch.

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, '_scald_rendered_to_sas_callback', $string);
}