View source
<?php
function node_kaltura_mix_perm() {
return array(
'create kaltura mixes',
'edit kaltura mixes',
'view kaltura mixes',
);
}
function node_kaltura_mix_access($op, $node) {
switch ($op) {
case 'create':
return user_access('create kaltura mixes', $account);
case 'update':
return user_access('edit kaltura mixes', $account);
case 'delete':
return user_access('delete kaltura mixes', $account);
}
}
function node_kaltura_mix_menu() {
$items = array();
$items[] = array(
'path' => 'admin/settings/kaltura/kaltura_mix_settings',
'title' => 'Kaltura Media Mix Settings',
'description' => 'Administer the kaltura mix module.',
'callback' => 'drupal_get_form',
'callback arguments' => array(
'kaltura_mix_settings_form',
),
'access' => user_access('administer kaltura'),
'type' => MENU_NORMAL_ITEM,
'weight' => -6,
);
return $items;
}
function kaltura_mix_settings_form() {
$taxonomy_array = taxonomy_get_vocabularies($type = 'kaltura_mix');
$options[] = '';
foreach ($taxonomy_array as $voc) {
if ($voc->tags == 1) {
$options[$voc->vid] = $voc->name;
}
}
$form['mix_taxonomy'] = array(
'#type' => 'fieldset',
'#title' => 'Taxonomy',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 0,
);
$form['mix_taxonomy']['kaltura_mix_tags_voc'] = array(
'#title' => 'Taxonomy Vocabulary for Tags',
'#description' => 'must be a \'free tagging\' vocabulary that is enabled for kaltura mix content type<br />only vocabularies that meets these requirements will apear in the list',
'#type' => 'select',
'#options' => $options,
'#default_value' => variable_get('kaltura_mix_tags_voc', ''),
'#required' => FALSE,
);
$form['mix_taxonomy']['kaltura_mix_admin_tags_voc'] = array(
'#title' => 'Taxonomy Vocabulary for Admin Tags',
'#description' => 'must be a \'free tagging\' vocabulary that is enabled for kaltura mix content type<br />only vocabularies that meets these requirements will apear in the list',
'#type' => 'select',
'#options' => $options,
'#default_value' => variable_get('kaltura_mix_admin_tags_voc', ''),
'#required' => FALSE,
);
$form['kaltura_mix_display'] = array(
'#type' => 'fieldset',
'#title' => t('Display settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => -1,
);
$players = kaltura_choose_player(0, 'roughcut', 'mix');
$saved_player = variable_get('kaltura_roughcut_mix_widget', KalturaSettings_DEFAULT_RC_PLAYER_UICONF);
$form['kaltura_mix_display']['kaltura_roughcut_mix_widget'] = $players['default_widget'];
$form['kaltura_mix_display']['kaltura_roughcut_mix_widget']['#default_value'] = $saved_player;
$form['kaltura_mix_display']['clear_block_item'] = array(
'#type' => 'item',
'#value' => '<div class="clear-block"></div>',
);
$form['kaltura_mix_display']['kaltura_mix_width'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t('Player Width (in pixels)'),
'#default_value' => variable_get('kaltura_mix_width', '410'),
);
$form['kaltura_mix_display']['kaltura_mix_height'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t('Player Height (in pixels)'),
'#default_value' => variable_get('kaltura_mix_height', '364'),
);
$form['kaltura_mix_display']['kaltura_mix_thumb_width'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t('Thumbnail Width'),
'#default_value' => variable_get('kaltura_mix_thumb_width', '120'),
);
$form['kaltura_mix_display']['kaltura_mix_thumb_height'] = array(
'#type' => 'textfield',
'#size' => 5,
'#title' => t('Thumbnail Height'),
'#default_value' => variable_get('kaltura_mix_thumb_height', '90'),
);
$form['kaltura_mix_display']['kaltura_display_mix_teaser_with_player'] = array(
'#type' => 'radios',
'#title' => t('In Teaser Mode - Display Only Thumbnail'),
'#options' => array(
'0' => 'Only thumbnail',
'1' => 'Thumbnail and player',
),
'#default_value' => variable_get('kaltura_display_mix_teaser_with_player', '0'),
);
return system_settings_form($form);
}
function node_kaltura_mix_node_info() {
$description = t('A Kaltura Media Remix is an intuitive way to create a mashup of rich-media. Similar to the Kaltura Media Node, ' . 'a Remix allows upload and import of rich media, but adds the power of online video editing. Each Media Remix ' . 'encapsulates a "Remix" button linking to a simple to use online video editor that supports trimming videos, transitions, effects, sound-tracks, ' . 'remixing, reordering videos, overlays, and collaborative editing');
return array(
'kaltura_mix' => array(
'name' => t('Kaltura Media Remix'),
'module' => 'node_kaltura_mix',
'description' => $description,
),
);
}
function node_kaltura_mix_form(&$node, $form_state) {
global $user;
$type = node_get_types('type', $node);
if ($node->nid) {
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -5,
);
$form['body_filter']['body'] = array(
'#type' => 'textarea',
'#title' => check_plain($type->body_label),
'#default_value' => $node->body,
'#rows' => 20,
'#required' => FALSE,
);
$action_buttons = '<input type="button" value="Edit Mix" onclick=" kalturaInitModalBox(\'' . url('kaltura/simple_editor/') . '\' + \'' . $node->kaltura_entryId . '\' + \'/entry/empty_partner_data/no_refresh\', { width: 890, height: 546 });" />';
$form['edit_mix'] = array(
'#type' => 'item',
'#value' => $action_buttons,
);
$form['kaltura_tags'] = array(
'#type' => 'hidden',
'#title' => 'Kaltura Tags',
'#required' => FALSE,
'#default_value' => $node->kaltura_tags,
'#weight' => -4,
);
$form['kaltura_admin_tags'] = array(
'#type' => 'hidden',
'#title' => 'Kaltura Admin Tags',
'#required' => FALSE,
'#default_value' => $node->kaltura_admin_tags,
'#weight' => -3,
);
$form['kaltura_entryId'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_entryId,
);
$form['media_preview'] = array(
'#type' => 'item',
'#title' => t('Media'),
'#value' => kaltura_replace_tags(theme('node_kaltura_mix_entryId', $node, 0)),
);
$form['kstatus'] = array(
'#type' => 'hidden',
'#default_value' => $node->kstatus,
);
$form['kaltura_total_rank'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_total_rank,
);
$form['kaltura_rank'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_rank,
);
$form['kaltura_votes'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_votes,
);
$form['kaltura_plays'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_plays,
);
$form['kaltura_views'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_views,
);
$form['kaltura_media_date'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_media_date,
);
$form['kaltura_download_url'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_download_url,
);
$form['kaltura_height'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_height,
);
$form['kaltura_width'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_width,
);
$form['kaltura_source_link'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_source_link,
);
$form['kaltura_source_id'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_source_id,
);
$form['kaltura_source'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_source,
);
$form['kaltura_partner_data'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_partner_data,
);
$form['kaltura_thumbnail_url'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_thumbnail_url,
);
$form['kaltura_duration'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_duration,
);
$form['kaltura_media_type'] = array(
'#type' => 'hidden',
'#default_value' => $node->kaltura_media_type,
);
}
else {
$form['kaltura_tags'] = array(
'#type' => 'hidden',
'#title' => 'Kaltura Tags',
'#required' => FALSE,
'#default_value' => $node->kaltura_tags ? $node->kaltura_tags : $_REQUEST['kaltura_tags'],
);
$form['kaltura_admin_tags'] = array(
'#type' => 'hidden',
'#title' => 'Kaltura Admin Tags',
'#required' => FALSE,
'#default_value' => $node->kaltura_admin_tags ? $node->kaltura_admin_tags : $_REQUEST['kaltura_admin_tags'],
);
$form['title'] = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title ? $node->title : $_REQUEST['title'],
'#weight' => -5,
);
if ($_REQUEST['title'] && $_REQUEST['op'] == 'Continue') {
$partner_data = "user_id@" . $user->uid;
$kaltura_client = KalturaHelpers::getKalturaClient();
$session_user = KalturaHelpers::getSessionUser();
if (WORK_WITH_KSHOW) {
$result = kaltura_add_kshow($session_user, $kaltura_client, $partner_data);
$partner_data .= "|kshow_exist@yes";
$show_entry_id = $result['result']['kshow']['id'];
$cw_vars = kaltura_format_cw_vars(array(
'kshow_id' => $show_entry_id,
'partner_data' => $partner_data,
));
$prefix = "<div class=\"add_video_to_node\"><script>jQuery(document).ready(function(){ kalturaInitModalBox('" . url("kaltura/contribution_wizard/" . $cw_vars) . "'); });</script>";
kaltura_create_node_from_kshow($result['result']);
}
else {
$result = kaltura_add_roughcut($session_user, $kaltura_client, $partner_data);
$partner_data .= "|kshow_exist@yes";
$show_entry_id = $result['result']['entry']['id'];
$cw_vars = kaltura_format_cw_vars(array(
'kshow_id' => $show_entry_id,
'partner_data' => $partner_data,
'type' => 'entry',
));
$prefix = "<div class=\"add_video_to_node\"><script>jQuery(document).ready(function(){ kalturaInitModalBox('" . url("kaltura/contribution_wizard/" . $cw_vars) . "'); });</script>";
kaltura_create_node_from_roughcut($result['result']);
}
$form["add_kaltura"] = array(
"#prefix" => $prefix,
"#type" => "item",
"#value" => "",
"#suffix" => "</div>",
);
}
}
return $form;
}
function kaltura_create_node_from_kshow($result) {
global $user;
$node->title = $result['kshow']['name'];
$node->body = $result['kshow']['description'];
$node->type = 'kaltura_mix';
$node->uid = $user->uid;
$node->status = 1;
$node->created = time();
$node->comment = FALSE;
$node->changed = time();
$node->promote = 0;
$node->sticky = 0;
kaltura_push_mix_extra_fields($node, $result);
$node->kstatus = $result['kshow']['status'];
$node->kaltura_tags = str_replace('a generated show\'', '', $result['kshow']['tags']);
$node->kaltura_entryId = $result['kshow']['id'];
$node->kaltura_admin_tags = $_REQUEST['admin_tags'];
$node->kaltura_entry_data = serialize(array(
$result,
));
node_save($node);
module_invoke('node_kaltura_mix', 'hook_insert', $node);
}
function kaltura_create_node_from_roughcut($result, $status = NULL) {
global $user;
$node->title = $result['entry']['name'];
$node->body = $result['entry']['description'];
$node->type = 'kaltura_mix';
$node->uid = $user->uid;
$node->status = $status ? $status : $_REQUEST['status'];
$node->created = time();
$node->comment = $_REQUEST['comment'];
$node->changed = time();
$node->promote = $_REQUEST['promote'];
$node->sticky = $_REQUEST['sticky'];
kaltura_push_mix_extra_fields($node, $result);
$node->kstatus = $result['entry']['status'];
$node->kaltura_tags = str_replace('a generated show\'', '', $result['entry']['tags']);
$node->kaltura_entryId = $result['entry']['id'];
$node->kaltura_admin_tags = $_REQUEST['admin_tags'];
$node->kaltura_entry_data = serialize(array(
$result,
));
node_save($node);
module_invoke('node_kaltura_mix', 'hook_insert', $node);
}
function kaltura_push_mix_extra_fields(&$node, $result) {
$fields = array(
'kaltura_media_type' => 'mediaType',
'kaltura_duration' => WORK_WITH_KSHOW ? 'lengthInMsecs' : 'duration',
'kaltura_thumbnail_url' => 'thumbnailUrl',
'kaltura_partner_data' => 'partnerData',
'kaltura_source' => '',
'kaltura_source_id' => '',
'kaltura_source_link' => '',
'kaltura_width' => '',
'kaltura_height' => '',
'kaltura_download_url' => '',
'kaltura_media_date' => '',
'kaltura_views' => 'views',
'kaltura_plays' => 'plays',
'kaltura_votes' => 'votes',
'kaltura_rank' => 'rank',
'kaltura_total_rank' => 'totalRank',
);
foreach ($fields as $node_key => $result_key) {
if ($result_key != '') {
if ($result['entry'][$result_key]) {
$node->{$node_key} = $result['entry'][$result_key];
}
}
}
}
function kaltura_add_kshow($session_user, $kaltura_client, $partner_data) {
$kshow = new kalturaKshow();
$kshow->name = $_REQUEST['title'];
$kshow->tags = $_REQUEST['kaltura_tags'];
$kshow->admin_tags = $_REQUEST['kaltura_admin_tags'];
$kshow->partnerData = $partner_data;
$result = $kaltura_client
->addKShow($session_user, $kshow, 1);
return $result;
}
function kaltura_add_roughcut($session_user, $kaltura_client) {
$rc = new KalturaEntry();
$rc->name = $_REQUEST['title'];
$rc->type = ENTRY_TYPE_ROUGHCUT;
$rc->tags = $_REQUEST['kaltura_tags'];
$rc->admin_tags = $_REQUEST['kaltura_admin_tags'];
$rc->partnerData = $partner_data;
$result = $kaltura_client
->addRoughcutEntry($session_user, -2, $rc);
return $result;
}
function node_kaltura_mix_form_alter($form_id, &$form) {
if ($form_id == 'kaltura_mix_node_form' && !$form['nid']['#value']) {
if (isset($form["type"]) && $form["type"]["#value"] . "_node_form" == $form_id) {
unset($form['submit']);
unset($form['preview']);
unset($form['menu']);
unset($form["log"]);
unset($form["author"]);
unset($form["taxonomy"]);
unset($form["revision_information"]);
$form_state['storage']['continue'] = TRUE;
$form['buttons']['continue'] = array(
"#type" => "button",
"#value" => "Continue",
"#weight" => 40,
);
}
}
}
function node_kaltura_mix_theme() {
$themes = array(
'node_kaltura_mix_tags' => array(
'arguments' => array(
'element' => NULL,
),
),
'node_kaltura_mix_admin_tags' => array(
'arguments' => array(
'themeParams' => NULL,
),
),
'node_kaltura_mix_entryId' => array(
'arguments' => array(
'themeParams' => NULL,
),
),
'node_kaltura_mix_thumbnail_url' => array(
'arguments' => array(
'themeParams' => NULL,
'teaser' => NULL,
),
),
);
return $themes;
}
function node_kaltura_mix_insert(&$node) {
$sql = 'INSERT INTO {node_kaltura} (vid, nid, kaltura_entryId, kaltura_tags, kaltura_admin_tags, kstatus, kaltura_media_type, kaltura_duration, ' . 'kaltura_thumbnail_url, kaltura_partner_data, kaltura_source, kaltura_source_id, kaltura_source_link, kaltura_width, kaltura_height, ' . 'kaltura_download_url, kaltura_media_date, kaltura_views, kaltura_plays, kaltura_votes, kaltura_rank, kaltura_total_rank, kaltura_entry_data)' . ' VALUES (%d, %d, \'%s\', \'%s\', \'%s\', %d, %d, %d, \'%s\', \'%s\', %d, %d, \'%s\', %d, %d, \'%s\', \'%s\', %d, %d, %d, %d, %d, \'%s\')';
db_query($sql, $node->vid, $node->nid, $node->kaltura_entryId, $node->kaltura_tags, $node->kaltura_admin_tags, $node->kstatus, $node->kaltura_media_type, $node->kaltura_duration, $node->kaltura_thumbnail_url, $node->kaltura_partner_data, $node->kaltura_source, $node->kaltura_source_id, $node->kaltura_source_link, $node->kaltura_width, $node->kaltura_height, $node->kaltura_download_url, $node->kaltura_media_date, $node->kaltura_views, $node->kaltura_plays, $node->kaltura_votes, $node->kaltura_rank, $node->kaltura_total_rank, $node->kaltura_entry_data);
kaltura_update_mix_node_taxonomy($node);
}
function kaltura_update_mix_node_taxonomy(&$node) {
$voc_id = variable_get('kaltura_mix_tags_voc', '');
$avoc_id = variable_get('kaltura_mix_admin_tags_voc', '');
$terms['tags'] = array();
if ($voc_id) {
watchdog('mix tags', print_r($node->kaltura_tags, TRUE));
$terms['tags'][$voc_id] = $node->kaltura_tags;
}
if ($avoc_id) {
if ($avoc_id == $voc_id) {
$terms['tags'][$admin_voc_id] .= ',' . $node->kaltura_admin_tags;
}
else {
$terms['tags'][$admin_voc_id] = $node->kaltura_admin_tags;
}
}
$node->taxonomy = $terms;
taxonomy_node_save($node->nid, $terms);
}
function node_kaltura_mix_update($node) {
if ($node->revision) {
node_example_insert($node);
}
else {
if ($node->notification_update !== TRUE) {
kaltura_update_mix_tags_from_taxonomy($node);
}
$sql = 'UPDATE {node_kaltura} SET kaltura_tags = \'%s\', kaltura_admin_tags = \'%s\' WHERE vid = %d';
db_query($sql, $node->kaltura_tags, $node->kaltura_admin_tags, $node->vid);
watchdog('upd mix', $node->kaltura_tags);
if ($node->notification_update !== TRUE) {
kaltura_update_mix_tags($node->kaltura_entryId, $node->title, $node->kaltura_tags, $node->kaltura_admin_tags);
}
else {
watchdog('mix update', 'updating taxonomy from tags ' . $node->kaltura_tags);
kaltura_update_mix_node_taxonomy($node);
}
}
}
function kaltura_update_mix_tags_from_taxonomy(&$node) {
$voc = variable_get('kaltura_mix_tags_voc', '');
if ($voc != '') {
$tags = $node->taxonomy['tags'][$voc];
$node->kaltura_tags = $tags;
}
$voc = variable_get('kaltura_mix_admin_tags_voc', '');
if ($voc != '') {
$tags = $node->taxonomy['tags'][$voc];
$node->kaltura_admin_tags = $tags;
}
}
function node_kaltura_mix_delete($node) {
$del_sql = 'DELETE FROM {node_kaltura} WHERE nid = %d';
db_query($del_sql, $node->nid);
}
function node_kaltura_mix_load($node) {
$sql = 'SELECT kaltura_entryId, kaltura_tags, kaltura_admin_tags, kstatus, kaltura_media_type, kaltura_duration, kaltura_thumbnail_url, ' . 'kaltura_partner_data, kaltura_source, kaltura_source_id, kaltura_source_link, kaltura_width, kaltura_height, kaltura_download_url, kaltura_media_date, ' . 'kaltura_views, kaltura_plays, kaltura_votes, kaltura_rank, kaltura_total_rank, kaltura_entry_data FROM {node_kaltura} WHERE vid = %d';
$result = db_query($sql, $node->vid);
$additions = db_fetch_object($result);
return $additions;
}
function node_kaltura_mix_view($node, $teaser = FALSE, $page = FALSE) {
$node = node_prepare($node, $teaser);
$node->content['kaltura_tags'] = array(
'#value' => theme('node_kaltura_mix_tags', $node),
'#weight' => 1,
);
$node->content['kaltura_admin_tags'] = array(
'#value' => theme('node_kaltura_mix_admin_tags', $node),
'#weight' => 6,
);
if ($node->kaltura_entryId) {
$node->content['kaltura_entry'] = array(
'#value' => theme('node_kaltura_mix_entryId', $node, $teaser),
'#weight' => 7,
);
}
$node->content['kaltura_thumbnail_url'] = array(
'#value' => theme('node_kaltura_mix_thumbnail_url', $node, $teaser),
'#weight' => 0,
);
return $node;
}
function theme_node_kaltura_mix_entryId($node, $teaser) {
$width = variable_get('kaltura_mix_width', '410');
$height = variable_get('kaltura_mix_height', '364');
if ($teaser && variable_get('kaltura_display_mix_teaser_with_player', 0) == 0) {
return '';
}
if (WORK_WITH_KSHOW) {
return '[kaltura-widget kid="' . $node->kaltura_entryId . '" size="large" width="' . $width . '" height="' . $height . '" /]';
}
else {
return '[kaltura-widget mix="' . $node->kaltura_entryId . '" size="large" width="' . $width . '" height="' . $height . '" /]';
}
}
function theme_node_kaltura_mix_thumbnail_url($node, $teaser, $nosize = FALSE, $size = array()) {
if (isset($size['width']) && isset($size['height'])) {
$width = $size['width'];
$height = $size['height'];
}
else {
$width = variable_get('kaltura_mix_thumb_width', '120');
$height = variable_get('kaltura_mix_thumb_height', '90');
}
$size_str = '';
if ($nosize == FALSE) {
$size_str = '/width/' . $width . '/height/' . $height;
}
if ($node->link_thumb || $teaser) {
return '<div class="kaltura_thumb"><a href="' . url('node/' . $node->nid) . '"><img src="' . $node->kaltura_thumbnail_url . $size_str . '" ' . $extra . ' /></a></div>';
}
else {
return '<div class="kaltura_thumb"><img src="' . $node->kaltura_thumbnail_url . $size_str . '" ' . $extra . ' /></div>';
}
}
function theme_node_kaltura_mix_admin_tags($node) {
if ($node->kaltura_admin_tags) {
$admin_tags = "<div class=\"kaltura_admin_tags\"><label class=\"field_title\">" . t('Kaltura Admin Tags') . ": </label>" . check_plain($node->kaltura_admin_tags) . '</div>';
}
return $admin_tags;
}
function theme_node_kaltura_mix_tags($node) {
if ($node->kaltura_tags) {
$tags = "<div class=\"kaltura_tags\"><label class=\"field_title\">" . t('Kaltura Tags') . ": </label>" . check_plain($node->kaltura_tags) . '</div>';
}
return $tags;
}
function kaltura_update_mix_tags($eid, $name, $tags, $admin_tags) {
$admin = 0;
if ($need_admin) {
$admin = 1;
}
$kaltura_client = KalturaHelpers::getKalturaClient();
$session_user = KalturaHelpers::getSessionUser();
if (WORK_WITH_KSHOW) {
$kshow = new KalturaKShow();
$kshow->tags = $tags;
$kshow->admin_tags = $admin_tags;
$kshow->name = $name;
$result = $kaltura_client
->updateKShow($session_user, $eid, $kshow, 1);
}
else {
$entry = new KalturaEntry();
$entry->tags = $tags;
$entry->adminTags = $admin_tags;
$entry->name = $name;
$result = $kaltura_client
->updateEntry($session_user, $eid, $entry);
}
kaltura_add_result_to_entry_data($eid, $result['result']);
}