You are here

function scald_prerender in Scald: Media Management made easy 7

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

Prepare a Scald Atom for rendering.

@codingStandardsIgnoreStart

Parameters

ScaldAtom $atom: The atom to prerender.

string $context: The context in which to render the atom?.

array $options: An array of options to pass down to the rendering pipeline.

1 call to scald_prerender()
scald_render in ./scald.module
Render a Scald Atom.

File

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

Code

function scald_prerender(&$atom, $context, $options) {

  // @codingStandardsIgnoreEnd
  $types = scald_types();
  $contexts = scald_contexts();
  $transcoders = scald_transcoders();
  $actions = scald_actions();
  $players = scald_players();
  $context_config = $contexts[$context];

  // Build the portion of the Rendered member which Providers are expected to
  // manipulate.
  $atom->rendered = new stdClass();
  $atom->rendered->sid = $atom->sid;
  $atom->rendered->title = $atom->title;
  $atom->rendered->file_source_url = empty($atom->file_source) ? NULL : file_create_url($atom->file_source);
  $atom->rendered->file_transcoded_url = NULL;
  $atom->rendered->thumbnail_source_url = file_create_url($atom->thumbnail_source);
  $atom->rendered->description = $atom->description;
  $atom->rendered->nocache = FALSE;

  // Populate default rendered members & validate other rendered members.
  $atom->rendered->title = check_plain($atom->rendered->title);
  $atom->rendered->description = filter_xss($atom->rendered->description);
  $atom->rendered->type = check_plain($types[$atom->type]->title);

  // Populate the Actions member.
  $atom->rendered->actions = scald_atom_user_build_actions_links($atom);

  // Fetch informations about the atom authors.
  $atom->rendered->authors = array();
  $items = field_get_items('scald_atom', $atom, 'scald_authors');
  if (!empty($items)) {
    foreach ($items as $delta => $term) {
      $tids[$delta] = $term['tid'];
    }
    $authors = taxonomy_term_load_multiple($tids);
    foreach ($authors as $author) {
      $url = field_get_items('taxonomy_term', $author, 'scald_author_url');
      if (!empty($url)) {
        $author->link = l($author->name, $url[0]['value']);
      }
      else {
        $author->link = check_plain($author->name);
      }
      $atom->rendered->authors[] = $author;
    }
  }

  // And get information on the user who published this atom.
  $name = db_select('users', 'u')
    ->fields('u', array(
    'name',
  ))
    ->condition('u.uid', $atom->publisher)
    ->execute()
    ->fetchField();
  $atom->rendered->publisher = array(
    'uid' => $atom->publisher,
    'name' => $name,
    'path' => 'user/' . $atom->publisher,
    'link' => l($name, 'user/' . $atom->publisher),
  );

  // Invoke the Transcoder Provider prerender hook -- only if there is a
  // Transcoder specified for this Context.
  if (!empty($context_config['type_format']) && !empty($context_config['type_format'][$atom->type])) {
    module_invoke($transcoders[$context_config['type_format'][$atom->type]['transcoder']]['provider'], 'scald_prerender', $atom, $context, $options, 'transcoder');
  }

  // Invoke the Type & Atom prerenders hooks.
  module_invoke($atom->provider, 'scald_prerender', $atom, $context, $options, 'atom');
  module_invoke($types[$atom->type]->provider, 'scald_prerender', $atom, $context, $options, 'type');

  // Invoke the Context prerender hook.
  module_invoke($context_config['provider'], 'scald_prerender', $atom, $context, $options, 'context');

  // Invoke the Player prerender hook.
  $player = isset($context_config['player'][$atom->type]) ? $context_config['player'][$atom->type]['*'] : 'default';
  if (!isset($players[$player])) {
    $player = 'default';
  }
  module_invoke($players[$player]['provider'], 'scald_prerender', $atom, $context, $options, 'player');
}