View source
<?php
define('VIDEO_CCK_DEFAULT_VIDEO_WIDTH', 425);
define('VIDEO_CCK_DEFAULT_VIDEO_HEIGHT', 350);
define('VIDEO_CCK_DEFAULT_PREVIEW_WIDTH', 425);
define('VIDEO_CCK_DEFAULT_PREVIEW_HEIGHT', 350);
define('VIDEO_CCK_DEFAULT_THUMBNAIL_WIDTH', 120);
define('VIDEO_CCK_DEFAULT_THUMBNAIL_HEIGHT', 90);
function video_cck_emfield_info() {
$name = t('Embedded Video Field');
return array(
'#name' => $name,
'#settings_description' => t('The following settings configure content with any fields controlled by @name.', array(
'@name' => $name,
)),
);
}
function video_cck_emfield_settings() {
$form = array();
return $form;
}
function video_cck_field_info() {
$fields = array(
'video_cck' => array(
'label' => t('Embedded Video'),
),
);
return $fields;
}
function video_cck_field_settings($op, $field) {
switch ($op) {
case 'database columns':
$columns = array(
'embed' => array(
'type' => 'longtext',
'not null' => TRUE,
'default' => "''",
'sortable' => TRUE,
),
'value' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => "''",
'sortable' => TRUE,
),
'provider' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => "''",
'sortable' => TRUE,
),
'data' => array(
'type' => 'longtext',
'not null' => TRUE,
'default' => "''",
'sortable' => false,
),
);
switch ($field['type']) {
case 'video_cck':
break;
}
return $columns;
break;
case 'filters':
return array(
'not null' => array(
'name' => t('Has Embedded Video'),
'operator' => array(
'=' => t('Has Embedded Video'),
),
'list' => 'views_handler_operator_yesno',
'list-type' => 'select',
'handler' => 'emfield_views_handler_filter_is_not_null',
'help' => t('Selecting yes will choose only nodes with this field that successfully provide an embedded video.'),
),
'provider' => array(
'name' => t('Video Provider'),
'list' => 'emfield_views_handler_filter_provider_list',
'list-type' => 'list',
'operator' => 'views_handler_operator_or',
'value-type' => 'array',
'handler' => 'emfield_views_handler_filter_provider',
'help' => t('Include or exclude videos from the selected provider.'),
),
);
break;
case 'arguments':
return array(
'content: ' . $field['field_name'] => array(
'name' => t('Embedded Video: @widget (@field)', array(
'@widget' => $field['widget']['label'],
'@field' => $field['field_name'],
)),
'handler' => 'content_views_argument_handler',
'help' => t('This is the default argument handler provided by CCK. It uses the original embed code or URL pasted into the field.'),
),
'provider: ' . $field['field_name'] => array(
'name' => t('Embedded Video Provider: @widget (@field)', array(
'@widget' => $field['widget']['label'],
'@field' => $field['field_name'],
)),
'handler' => 'video_cck_handler_arg_provider',
'help' => t('The Embedded Video Provider argument allows users to filter a view by specifying the video provider.'),
),
);
break;
}
}
function video_cck_field($op, &$node, $field, &$items, $teaser, $page) {
if (module_hook('emfield', 'emfield_field')) {
return emfield_emfield_field($op, $node, $field, $items, $teaser, $page, 'video_cck');
}
}
function video_cck_field_formatter_info() {
$types = array(
'video_cck',
);
$formats = array(
'default' => array(
'label' => t('Default'),
'field types' => $types,
),
'video_video' => array(
'label' => t('Full Size Video'),
'field types' => $types,
),
'video_preview' => array(
'label' => t('Preview Video'),
'field types' => $types,
),
'video_thumbnail' => array(
'label' => t('Image Thumbnail'),
'field types' => $types,
),
'video_embed' => array(
'label' => t('Embed Code'),
'field types' => $types,
),
);
if (module_exists('thickbox')) {
$formats['thickbox'] = array(
'label' => t('Thickbox: Image Thumbnail -> Full Size Video'),
'field types' => $types,
);
}
return $formats;
}
function video_cck_field_formatter($field, $item, $formatter, $node) {
return module_invoke('emfield', 'emfield_field_formatter', $field, $item, $formatter, $node, 'video_cck');
}
function video_cck_widget_info() {
return array(
'video_cck_textfields' => array(
'label' => t('3rd Party Video'),
'field types' => array(
'video_cck',
),
),
);
}
function video_cck_widget_settings($op, $widget) {
switch ($op) {
case 'form':
if ($widget['type'] == 'video_cck_textfields') {
$form = (array) module_invoke('emfield', 'emfield_widget_settings', 'form', $widget, 'video_cck');
$width = variable_get('video_cck_default_video_width', VIDEO_CCK_DEFAULT_VIDEO_WIDTH);
$height = variable_get('video_cck_default_video_height', VIDEO_CCK_DEFAULT_VIDEO_HEIGHT);
$form['video'] = array(
'#type' => 'fieldset',
'#title' => t('Video Display Settings'),
'#description' => t('These settings control how this video is displayed in its full size, which defaults to @widthx@height.', array(
'@width' => $width,
'@height' => $height,
)),
'#collapsible' => true,
'#collapsed' => false,
);
$form['video']['video_width'] = array(
'#type' => 'textfield',
'#title' => t('Video display width'),
'#default_value' => $widget['video_width'] ? $widget['video_width'] : $width,
'#required' => true,
'#description' => t('The width of the video. It defaults to @width.', array(
'@width' => $width,
)),
);
$form['video']['video_height'] = array(
'#type' => 'textfield',
'#title' => t('Video display height'),
'#default_value' => $widget['video_height'] ? $widget['video_height'] : $height,
'#required' => true,
'#description' => t('The height of the video. It defaults to @height.', array(
'@height' => $height,
)),
);
$form['video']['video_autoplay'] = array(
'#type' => 'checkbox',
'#title' => t('Autoplay'),
'#default_value' => $widget['video_autoplay'] ? $widget['video_autoplay'] : false,
'#description' => t('If supported by the provider, checking this box will cause the video to automatically begin after the video loads when in its full size.'),
);
$width = variable_get('video_cck_default_preview_width', VIDEO_CCK_DEFAULT_PREVIEW_WIDTH);
$height = variable_get('video_cck_default_preview_height', VIDEO_CCK_DEFAULT_PREVIEW_HEIGHT);
$form['preview'] = array(
'#type' => 'fieldset',
'#title' => t('Video Preview Settings'),
'#description' => t('These settings control how this video is displayed in its preview size, which defaults to @widthx@height.', array(
'@width' => $width,
'@height' => $height,
)),
'#collapsible' => true,
'#collapsed' => false,
);
$form['preview']['preview_width'] = array(
'#type' => 'textfield',
'#title' => t('Video preview width'),
'#default_value' => $widget['preview_width'] ? $widget['preview_width'] : variable_get('video_cck_default_preview_width', VIDEO_CCK_DEFAULT_PREVIEW_WIDTH),
'#required' => true,
'#description' => t('The width of the preview video. It defaults to @width.', array(
'@width' => $width,
)),
);
$form['preview']['preview_height'] = array(
'#type' => 'textfield',
'#title' => t('Video preview height'),
'#default_value' => $widget['preview_height'] ? $widget['preview_height'] : variable_get('video_cck_default_preview_height', VIDEO_CCK_DEFAULT_PREVIEW_HEIGHT),
'#required' => true,
'#description' => t('The height of the preview video. It defaults to @height.', array(
'@height' => $height,
)),
);
$form['preview']['preview_autoplay'] = array(
'#type' => 'checkbox',
'#title' => t('Autoplay'),
'#default_value' => $widget['preview_autoplay'] ? $widget['preview_autoplay'] : false,
'#description' => t('If supported by the provider, checking this box will cause the video to automatically begin after the video loads when in its preview size.'),
);
$width = variable_get('video_cck_default_thumbnail_width', VIDEO_CCK_DEFAULT_THUMBNAIL_WIDTH);
$height = variable_get('video_cck_default_thumbnail_height', VIDEO_CCK_DEFAULT_THUMBNAIL_HEIGHT);
$form['tn'] = array(
'#type' => 'fieldset',
'#title' => t('Thumbnail'),
'#description' => t('When displayed as a thumbnail, these settings control the image returned. Note that not all 3rd party video content providers offer thumbnails, and others may require an API key or other requirements. More information from the !settings. The default size for thumbnails is @widthx@height.', array(
'!settings' => l(t('settings page'), 'admin/content/emfield'),
'@width' => $width,
'@height' => $height,
)),
'#collapsible' => true,
'#collapsed' => false,
);
$form['tn']['thumbnail_width'] = array(
'#type' => 'textfield',
'#title' => t('Thumbnail width'),
'#default_value' => $widget['thumbnail_width'] ? $widget['thumbnail_width'] : variable_get('video_cck_default_thumbnail_width', VIDEO_CCK_DEFAULT_THUMBNAIL_WIDTH),
'#required' => true,
'#description' => t('The width of the thumbnail. It defaults to @width.', array(
'@width' => $width,
)),
);
$form['tn']['thumbnail_height'] = array(
'#type' => 'textfield',
'#title' => t('Thumbnail height'),
'#default_value' => $widget['thumbnail_height'] ? $widget['thumbnail_height'] : variable_get('video_cck_default_thumbnail_height', VIDEO_CCK_DEFAULT_THUMBNAIL_HEIGHT),
'#required' => true,
'#description' => t('The height of the thumbnail. It defaults to @height.', array(
'@height' => $height,
)),
);
if (!module_exists('emthumb')) {
$tn_desc = t(' You may be interested in activating the Embedded Media Thumbnails module as well, which will allow you to specify custom thumbnails on a per-node basis.');
}
$form['tn']['thumbnail_default_path'] = array(
'#type' => 'textfield',
'#title' => t('Default thumbnail path'),
'#default_value' => $widget['thumbnail_default_path'] ? $widget['thumbnail_default_path'] : variable_get('video_cck_default_thumbnail_path', ''),
'#description' => t('Path to a local default thumbnail image for cases when a thumbnail can\'t be found. For example, you might have a default thumbnail at %files.', array(
'%files' => 'files/thumbnail.png',
)) . $tn_desc,
);
}
return $form;
case 'validate':
if ($widget['type'] == 'video_cck_textfields') {
if (!is_numeric($widget['video_width']) || intval($widget['video_width']) != $widget['video_width'] || $widget['video_width'] < 1) {
form_set_error('video_width', t('"Video width" must be a positive integer.'));
}
if (!is_numeric($widget['video_height']) || intval($widget['video_height']) != $widget['video_height'] || $widget['video_height'] < 1) {
form_set_error('video_height', t('"Video height" must be a positive integer.'));
}
if (!is_numeric($widget['preview_width']) || intval($widget['preview_width']) != $widget['preview_width'] || $widget['preview_width'] < 1) {
form_set_error('preview_width', t('"Preview width" must be a positive integer.'));
}
if (!is_numeric($widget['preview_height']) || intval($widget['preview_height']) != $widget['preview_height'] || $widget['preview_height'] < 1) {
form_set_error('preview_height', t('"Preview height" must be a positive integer.'));
}
if (!is_numeric($widget['thumbnail_width']) || intval($widget['thumbnail_width']) != $widget['thumbnail_width'] || $widget['thumbnail_width'] < 1) {
form_set_error('thumbnail_width', t('"Thumbnail width" must be a positive integer.'));
}
if (!is_numeric($widget['thumbnail_height']) || intval($widget['thumbnail_height']) != $widget['thumbnail_height'] || $widget['thumbnail_height'] < 1) {
form_set_error('thumbnail_height', t('"Thumbnail height" must be a positive integer.'));
}
}
break;
case 'save':
if ($widget['widget']['type'] == 'video_cck_textfields') {
$columns = array(
'video_width',
'video_height',
'video_autoplay',
'preview_width',
'preview_height',
'preview_autoplay',
'thumbnail_width',
'thumbnail_height',
'thumbnail_default_path',
);
$columns = array_merge($columns, module_invoke('emfield', 'emfield_widget_settings', 'save', $widget, 'video_cck'));
return $columns;
}
break;
}
}
function video_cck_widget($op, &$node, $field, &$node_field) {
if (module_hook('emfield', 'emfield_widget')) {
return emfield_emfield_widget($op, $node, $field, $node_field, 'video_cck');
}
}
function video_cck_embed_form($field, $item, $formatter, $node, $options = array()) {
$embed = $item['value'];
$width = $options['width'] ? $options['width'] : $field['widget']['video_width'];
$height = $options['height'] ? $options['height'] : $field['widget']['video_height'];
$autoplay = $options['autoplay'] ? $options['autoplay'] : $field['widget']['video_autoplay'];
$text = module_invoke('emfield', 'include_invoke', 'video_cck', $item['provider'], 'video', $embed, $width, $height, $field, $item, $autoplay);
$form = array();
$form['video_cck_embed'] = array(
'#type' => 'textarea',
'#title' => t('Embed Code'),
'#description' => t('To embed this video on your own site, simply copy and paste the html code from this text area.'),
'#default_value' => $text,
);
return $form;
}
function video_cck_emfield_rss($node, $items = array(), $teaser = NULL) {
$rss_data = array();
foreach ($items as $item) {
if ($item['value'] && $item['provider']) {
$rss_data[] = module_invoke('emfield', 'include_invoke', 'video_cck', $item['provider'], 'rss', $item, $teaser);
}
}
return $rss_data;
}
function theme_video_cck_video_embed($field, $item, $formatter, $node, $options = array()) {
if ($item['value'] && $item['provider']) {
$output = drupal_get_form('video_cck_embed_form', $field, $item, $formatter, $node, $options);
}
return $output;
}
function theme_video_cck_video_thumbnail($field, $item, $formatter, $node, $no_link = FALSE, $options = array()) {
if (is_array($no_link) && empty($options)) {
$options = $no_link;
}
if (is_array($no_link)) {
$no_link = FALSE;
}
$options['node'] = $node;
if ($item['value'] && $item['provider']) {
$thumbnail_url = $options['thumbnail_url'] ? $options['thumbnail_url'] : module_invoke('emthumb', 'thumbnail_url', $item);
$thumbnail_url = $thumbnail_url ? $thumbnail_url : module_invoke('emfield', 'include_invoke', 'video_cck', $item['provider'], 'thumbnail', $field, $item, $formatter, $node, $width, $height, $options);
if (!$thumbnail_url) {
$default_thumbnail_url = $field['widget']['thumbnail_default_path'] ? $field['widget']['thumbnail_default_path'] : variable_get('video_cck_default_thumbnail_path', NULL);
if ($default_thumbnail_url) {
$thumbnail_url = base_path() . $default_thumbnail_url;
}
}
}
else {
if (!$thumbnail_url) {
$default_thumbnail_url = $field['widget']['thumbnail_default_path'] ? $field['widget']['thumbnail_default_path'] : variable_get('video_cck_default_thumbnail_path', NULL);
if ($default_thumbnail_url) {
$thumbnail_url = base_path() . $default_thumbnail_url;
}
}
}
$link_url = isset($options['link_url']) ? $options['link_url'] : 'node/' . $node->nid;
$link_title = isset($options['link_title']) ? $options['link_title'] : t('See video');
$image_title = isset($options['image_title']) ? $options['image_title'] : $link_title;
$image_alt = isset($options['image_alt']) ? $options['image_alt'] : $link_title;
if ($thumbnail_url) {
$width = isset($options['width']) ? $options['width'] : NULL;
$width = isset($width) ? $width : ($field['widget']['thumbnail_width'] ? $field['widget']['thumbnail_width'] : variable_get('video_cck_default_thumbnail_width', VIDEO_CCK_DEFAULT_THUMBNAIL_WIDTH));
$height = isset($options['height']) ? $options['height'] : NULL;
$height = isset($height) ? $height : ($field['widget']['thumbnail_height'] ? $field['widget']['thumbnail_height'] : variable_get('video_cck_default_thumbnail_height', VIDEO_CCK_DEFAULT_THUMBNAIL_HEIGHT));
if ($no_link) {
$output = '<img src="' . $thumbnail_url . '" width="' . $width . '" height="' . $height . '" alt="' . $image_alt . '" title="' . $image_title . '" />';
}
else {
$output = l('<img src="' . $thumbnail_url . '" width="' . $width . '" height="' . $height . '" alt="' . $image_alt . '" title="' . $image_title . '" />', $link_url, array(), NULL, NULL, false, true);
}
}
else {
if ($no_link) {
$output = '';
}
else {
if ($item['value'] && $item['provider']) {
$output = l($link_title, $link_url);
}
else {
$output = '';
}
}
}
return $output;
}
function theme_video_cck_video_video($field, $item, $formatter, $node, $options = array()) {
if ($item['value'] && $item['provider']) {
$embed = $item['value'];
$width = isset($options['width']) ? $options['width'] : (isset($field['widget']['video_width']) ? $field['widget']['video_width'] : variable_get('video_cck_default_video_width', VIDEO_CCK_DEFAULT_VIDEO_WIDTH));
$height = isset($options['height']) ? $options['height'] : (isset($field['widget']['video_height']) ? $field['widget']['video_height'] : variable_get('video_cck_default_video_height', VIDEO_CCK_DEFAULT_VIDEO_HEIGHT));
$autoplay = isset($options['autoplay']) ? $options['autoplay'] : $field['widget']['video_autoplay'];
$options['node'] = $node;
$output = module_invoke('emfield', 'include_invoke', 'video_cck', $item['provider'], 'video', $embed, $width, $height, $field, $item, $autoplay, $options);
}
return $output;
}
function theme_video_cck_default($field, $item, $formatter, $node, $options = array()) {
return theme('video_cck_video_video', $field, $item, $formatter, $node, $options);
}
function theme_video_cck_video_preview($field, $item, $formatter, $node, $options = array()) {
if ($item['value'] && $item['provider']) {
$embed = $item['value'];
$width = isset($options['width']) ? $options['width'] : (isset($field['widget']['preview_width']) ? $field['widget']['preview_width'] : variable_get('video_cck_default_preview_width', VIDEO_CCK_DEFAULT_PREVIEW_WIDTH));
$height = isset($options['height']) ? $options['height'] : (isset($field['widget']['preview_height']) ? $field['widget']['preview_height'] : variable_get('video_cck_default_preview_height', VIDEO_CCK_DEFAULT_PREVIEW_HEIGHT));
$autoplay = isset($options['autoplay']) ? $options['autoplay'] : $field['widget']['preview_autoplay'];
$options['node'] = $node;
$output = module_invoke('emfield', 'include_invoke', 'video_cck', $item['provider'], 'preview', $embed, $width, $height, $field, $item, $autoplay, $options);
}
return $output;
}
function theme_video_cck_thickbox($field, $item, $formatter, $node, $options = array()) {
$thumbnail = theme('video_cck_video_thumbnail', $field, $item, 'video_thumbnail', $node, true, $options);
$width = isset($options['width']) ? $options['width'] : (isset($field['widget']['video_width']) ? $field['widget']['video_width'] : variable_get('video_cck_default_video_width', VIDEO_CCK_DEFAULT_VIDEO_WIDTH));
$height = isset($options['height']) ? $options['height'] : (isset($field['widget']['video_height']) ? $field['widget']['video_height'] : variable_get('video_cck_default_video_height', VIDEO_CCK_DEFAULT_VIDEO_HEIGHT));
$field_name = isset($options['field_name']) ? $options['field_name'] : $field['field_name'];
$type_name = isset($options['type_name']) ? $options['type_name'] : $field['type_name'];
$title = isset($options['title']) ? $options['title'] : $node->title;
$destination = 'video-cck/thickbox/' . $node->nid . '/' . $width . '/' . $height . '/' . $field_name;
$output = l($thumbnail, $destination, array(
'title' => $title,
'class' => 'thickbox',
'rel' => $type_name,
), NULL, NULL, FALSE, TRUE);
return $output;
}
function video_cck_handler_arg_provider($op, &$query, $argtype, $arg = '') {
return _emfield_handler_arg_provider($op, $query, $argtype, $arg, 'video_cck');
}
function video_cck_menu($may_cache) {
$items = array();
if (module_exists('thickbox')) {
if (!$may_cache) {
if (arg(0) == 'video-cck' && arg(1) == 'thickbox' && is_numeric(arg(2))) {
$node = node_load(arg(2));
if ($node->nid) {
$items[] = array(
'path' => 'video-cck/thickbox/' . arg(2),
'callback' => 'video_cck_thickbox',
'callback arguments' => array(
$node,
),
'access' => node_access('view', $node),
'type' => MENU_CALLBACK,
);
}
}
}
}
return $items;
}
function video_cck_thickbox($node, $width, $height, $field_name) {
$field = array();
$field['widget']['video_width'] = $width;
$field['widget']['video_height'] = $height;
$field['widget']['video_autoplay'] = 1;
$field['field_name'] = $field_name;
$items = $node->{$field_name};
$item = $items[0];
$type = $node->type;
if (module_exists('cck_field_perms') && ($types = variable_get('cfp_types', null))) {
if ($types[$type]) {
$disallowed_fields = unserialize(variable_get('cfp_values', null));
if ($disallowed_fields && $disallowed_fields[$type][$field_name] != 0) {
if (!user_access(_cfp_content_to_readable($type, $disallowed_field, 'view'))) {
drupal_access_denied();
return;
}
}
}
}
print theme('video_cck_video_video', $field, $item, 'video_video', $node);
}