You are here

function _jplayer_check_id in jPlayer 7.2

Same name and namespace in other branches
  1. 6 includes/jplayer.theme.inc \_jplayer_check_id()

Return a unique ID for a jPlayer.

This allows multiple embedded jPlayers to point to an identical file on the same page.

Parameters

string $id: The ID to check for uniqueness.

Return value

string A modified ID if the ID was not unique, or the same ID passed in if it was unique.

2 calls to _jplayer_check_id()
template_preprocess_jplayer in includes/jplayer.theme.inc
Preprocess function for a player.
template_preprocess_jplayer_view_playlist in includes/jplayer.theme.inc
Preprocess function for jplayer.tpl.php when displaying a view as a playlist.

File

includes/jplayer.theme.inc, line 323
Theme and preprocess functions for the jPlayer module.

Code

function _jplayer_check_id($id) {

  // We keep track of player IDs generated per request. This ensures that if a
  // player pointing to the same field is shown multiple times on a page, that
  // each player gets a unique ID. This is especially a problem when jPlayers
  // are embedded in hidden content such as View rendered with Quicktabs.
  static $player_ids = array();

  // Add the request time, so if the same player is inserted multiple times
  // AJAX all players are functional.
  $id = $id . '-' . $_SERVER['REQUEST_TIME'];

  // Store a count of the number of times a unique ID is used, and make it
  // unique if needed.
  if (isset($player_ids[$id])) {
    $id = $id . '-' . $player_ids[$id]++;
  }
  else {
    $player_ids[$id] = 0;
  }
  return $id;
}