jplayer.theme.inc in jPlayer 6
File
includes/jplayer.theme.inc
View source
<?php
function theme_jplayer_formatter_single($element) {
if (isset($element['#item']['fid'])) {
jplayer_add();
return theme('jplayer_single', $element);
}
return '';
}
function template_preprocess_jplayer_single(&$vars) {
$vars['mode'] = 'single';
$vars['item'] = array(
'url' => file_create_url($vars['element']['#item']['filepath']),
'label' => !empty($vars['element']['#item']['data']['description']) ? $vars['element']['#item']['data']['description'] : $vars['element']['#item']['filename'],
);
$vars['player_id'] = _jplayer_check_id('jplayer-' . $vars['element']['#node']->nid . '-' . str_replace('_', '-', $vars['element']['#field_name']) . '-' . $vars['element']['#item']['#delta']);
}
function theme_jplayer_formatter_playlist($element) {
if (isset($element[0]['#item']['fid'])) {
jplayer_add();
if (isset($element[1])) {
return theme('jplayer_playlist', $element);
}
$element += $element[0];
return theme('jplayer_single', $element);
}
return '';
}
function template_preprocess_jplayer_playlist(&$vars) {
$vars['mode'] = 'playlist';
$vars['items'] = array();
$children = element_children($vars['element']);
$count = count($children);
$number = 0;
foreach ($children as $key) {
$classes = array();
if ($number == 0) {
$classes[] = 'first';
$classes[] = 'jplayer_playlist_item_first';
}
if ($number == $count - 1) {
$classes[] = 'last';
$classes[] = 'jplayer_playlist_item_last';
}
$vars['items'][] = array(
'class' => implode(' ', $classes),
'url' => file_create_url($vars['element'][$key]['#item']['filepath']),
'label' => !empty($vars['element'][$key]['#item']['data']['description']) ? $vars['element'][$key]['#item']['data']['description'] : $vars['element'][$key]['#item']['filename'],
);
$number++;
}
$vars['player_id'] = _jplayer_check_id('jplayer-' . $vars['element']['#node']->nid . '-' . str_replace('_', '-', $vars['element']['#field_name']));
}
function template_preprocess_jplayer_view_playlist(&$vars) {
if (empty($vars['items'])) {
return;
}
jplayer_add();
$count = count($vars['items']);
foreach ($vars['items'] as $number => $item) {
$classes = array();
if ($number == 0) {
$classes[] = 'first';
$classes[] = 'jplayer_playlist_item_first';
}
if ($number == $count - 1) {
$classes[] = 'last';
$classes[] = 'jplayer_playlist_item_last';
}
$vars['items'][$number]['class'] = implode(' ', $classes);
}
$vars['mode'] = 'playlist';
$vars['player_id'] = _jplayer_check_id('jplayer-view-' . str_replace('_', '-', $vars['view']->name));
}
function _jplayer_check_id($id) {
static $player_ids = array();
$id = $id . '-' . $_SERVER['REQUEST_TIME'];
if (isset($player_ids[$id])) {
$id = $id . '-' . $player_ids[$id]++;
}
else {
$player_ids[$id] = 0;
}
return $id;
}