';
}
/**
* VimeoField admin settings form.
*/
function vimeo_settings() {
$form['player'] = array(
'#type' => 'fieldset',
'#title' => t('Player Options'),
'#description' => t('Note: You cannot override any options set by Vimeo Plus members.'),
'#weight' => -2,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['player']['vimeo_width'] = array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => variable_get('vimeo_width', '640'),
'#field_suffix' => 'px',
'#required' => TRUE,
'#size' => '10',
'#description' => t('Width of the video player.'),
);
$form['player']['vimeo_height'] = array(
'#type' => 'textfield',
'#title' => t('Height'),
'#default_value' => variable_get('vimeo_height', '360'),
'#field_suffix' => 'px',
'#required' => TRUE,
'#size' => '10',
'#description' => t('Height of the video player.'),
);
$form['player']['vimeo_colour'] = array(
'#type' => 'textfield',
'#title' => t('Colour'),
'#default_value' => variable_get('vimeo_colour', '00ADEF'),
'#required' => TRUE,
'#size' => '10',
'#field_prefix' => '#',
'#description' => t("The colour to use in the video's UI controls."),
);
$form['player']['vimeo_title'] = array(
'#type' => 'select',
'#title' => t('Title'),
'#default_value' => variable_get('vimeo_title', 1),
'#options' => array(0 => t('No'), 1 => t('Yes')),
'#description' => t("If yes, users will see the video's title."),
);
$form['player']['vimeo_byline'] = array(
'#type' => 'select',
'#title' => t('Byline'),
'#default_value' => variable_get('vimeo_byline', 1),
'#options' => array(0 => t('No'), 1 => t('Yes')),
'#description' => t("If yes, users will see the video's byline."),
);
$form['player']['vimeo_portrait'] = array(
'#type' => 'select',
'#title' => t('Portrait'),
'#default_value' => variable_get('vimeo_portrait', 1),
'#options' => array(0 => t('No'), 1 => t('Yes')),
'#description' => t("If yes, users will see the Vimeo user's portrait."),
);
$form['player']['vimeo_fullscreen'] = array(
'#type' => 'select',
'#title' => t('Fullscreen'),
'#default_value' => variable_get('vimeo_fullscreen', 1),
'#options' => array(0 => t('No'), 1 => t('Yes')),
'#description' => t('If yes, users can watch videos fullscreen.'),
);
$form['player']['vimeo_autoplay'] = array(
'#type' => 'select',
'#title' => t('Auto Play'),
'#default_value' => variable_get('vimeo_autoplay', 0),
'#options' => array(0 => t('No'), 1 => t('Yes')),
'#description' => t('Video will automatically start playing on page load.'),
);
$form['cache'] = array(
'#type' => 'fieldset',
'#title' => t('Cache Settings'),
'#description' => t('Note: You can always manually refresh video data when editing individual nodes.'),
'#weight' => 0,
'#collapsible' => FALSE,
'#collapsed' => FALSE,
);
$form['cache']['vimeo_source_cache'] = array(
'#type' => 'select',
'#title' => t('Source Cache Time'),
'#default_value' => variable_get('vimeo_source_cache', 3),
'#options' => array(0 => t('Temporary - Flush on Cron'), '0.5' => t('30 minutes'), 1 => t('1 hour'), 2 => t('2 hours'), 3 => t('3 hours (recommended)'), 5 => t('5 hours'), 24 => t('1 day'), 168 => t('1 week')),
'#description' => t('How long until vimeo source lists automatically get updated.'),
);
$form['cache']['vimeo_video_cache'] = array(
'#type' => 'select',
'#title' => t('Video Cache Time'),
'#default_value' => variable_get('vimeo_video_cache', '-1'),
'#options' => array(0 => t('Temporary (Not recommended)'), 24 => t('1 day'), 168 => t('1 week'), 744 => t('1 month'), 2232 => t('3 months'), '-1' => t('Never (recommended)')),
'#description' => t('How long until vimeo video data automatically get updated.'),
);
return system_settings_form($form);
}
/**
* Implementation of hook_theme().
*/
function vimeo_theme($existing, $type, $theme, $path) {
//If template exists in the current theme use that instead.
// if (file_exists(path_to_theme() . '/vimeo_custom_formatter.tpl.php')) {
// $path = path_to_theme();
// }
// else {
// $path = drupal_get_path('module', 'vimeo') . '/theme';
// }
return array(
'vimeo_browser' => array(
'render element' => 'element',
),
'vimeo_formatter_default' => array(
'variables' => array('id' => NULL, 'settings' => NULL),
),
'vimeo_formatter_plain' => array(
'variables' => array('id' => NULL),
),
'vimeo_formatter_custom' => array(
'variables' => array('element' => NULL),
'template' => 'vimeo_custom_formatter',
'path' => $path . '/theme',
),
);
}
/**
* Setup variables for the insert window.
*
* @param array $vars
*/
function template_preprocess_vimeo_formatter_custom(&$vars) {
$data = vimeo_cache_video_get($vars['element']['#item']['value']);
//Vimeo video data
$vars['video'] = $data;
//Node data
$vars['node'] = $vars['element']['#node'];
//Vimeo player settings
$vars['player']['width'] = variable_get('vimeo_width', 640);
$vars['player']['height'] = variable_get('vimeo_height', 360);
$vars['player']['title'] = variable_get('vimeo_title', 1);
$vars['player']['byline'] = variable_get('vimeo_byline', 1);
$vars['player']['portrait'] = variable_get('vimeo_portrait', 1);
$vars['player']['color'] = variable_get('vimeo_colour', '00ADEF');
$vars['player']['fullscreen'] = variable_get('vimeo_fullscreen', 1);
$vars['player']['autoplay'] = variable_get('vimeo_autoplay', 0);
return $vars;
}
/**
* Implementation of hook_field_info().
*/
function vimeo_field_info() {
return array(
'vimeo' => array(
'label' => t('Vimeo'),
'description' => t('Store vimeo video URL in the database.'),
'settings' => array(),
'instance_settings' => array(),
'default_widget' => 'vimeo_browser',
'default_formatter' => 'default',
),
);
}
/**
* Implementation of hook_field_schema().
*/
function vimeo_field_schema($field) {
switch ($field['type']) {
case 'vimeo' :
$columns['value'] = array(
'type' => 'varchar',
'length' => 16,
'not null' => FALSE,
'sortable' => FAlSE,
'views' => FALSE
);
break;
}
return array(
'columns' => $columns,
);
}
/**
* Implementation of hook_field_validate().
*/
function vimeo_field_validate($entity_type, $entity, $field, $instance, $langcode, $items, &$errors) {
if (is_array($items)) {
foreach ($items as $delta => $item) {
$error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
if (is_array($item) && isset($item['_error_element'])) {
unset($item['_error_element']);
}
}
}
}
/**
* Implementation of hook_field_is_empty().
*/
function vimeo_field_is_empty($item, $field) {
if (empty($item['value']) && (string) $item['value'] !== '0') {
return TRUE;
}
return FALSE;
}
/**
* Implementation of hook_field_formatter_info().
*/
function vimeo_field_formatter_info() {
return array(
'vimeo_default' => array(
'label' => t('Default'),
'field types' => array('vimeo'),
),
'vimeo_plain' => array(
'label' => t('Vimeo video ID'),
'field types' => array('vimeo'),
),
'vimeo_custom' => array(
'label' => t('Custom Template'),
'field types' => array('vimeo'),
),
);
}
/**
* Implements hook_field_formatter_view().
*
*/
function vimeo_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
switch ($display['type']) {
// The video iframe.
case 'vimeo_default':
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#theme' => 'vimeo_formatter_default',
'#id' => $item['value'],
'#settings' => array(),
);
}
break;
// Video ID
case 'vimeo_plain':
foreach ($items as $delta => $item) {
// @todo add a setting to control if this should be output safe for a
// HTML page or raw, which could be used as a value.
$element[$delta] = array(
'#theme' => 'vimeo_formatter_plain',
'#id' => $item['value'],
);
}
break;
}
return $element;
}
/**
* Theme function for 'default' vimeo field formatter.
*/
function theme_vimeo_formatter_default($variables) {
if (!empty($variables['id'])) {
$video_vid = $variables['id'];
return '';
}
else {
// Nothing to output
return '';
}
}
/**
* Theme function for 'plain' vimeo field formatter.
*/
function theme_vimeo_formatter_plain($variables) {
return $variables['id'];
}
/**
* Implementation of hook_widget_info().
*
* Here we indicate that the content module will handle
* the default value and multiple values for these widgets.
*
* Callbacks can be omitted if default handing is used.
* They're included here just so this module can be used
* as an example for custom modules that might do things
* differently.
*/
function vimeo_field_widget_info() {
return array(
'vimeo_browser' => array(
'label' => t('Vimeo Browser'),
'field types' => array('vimeo'),
'behaviors' => array(
'multiple values' => FIELD_BEHAVIOR_DEFAULT,
'default value' => FIELD_BEHAVIOR_DEFAULT,
),
),
);
}
/**
* Implementation of hook_element_info().
*
* Any FAPI callbacks needed for individual widgets can be declared here,
* and the element will be passed to those callbacks for processing.
*
* Drupal will automatically theme the element using a theme with
* the same name as the hook_elements key.
*
* Autocomplete_path is not used by vimeo_widget but other widgets can use it
* (see nodereference and userreference).
*/
function vimeo_element_info() {
return array(
'vimeo_browser' => array(
'#input' => TRUE,
'#process' => array('vimeo_browser_process'),
'#autocomplete_path' => FALSE,
),
);
}
/**
* Implementation of hook_field_widget_form().
*/
function vimeo_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {
$element = array(
'#type' => $instance['widget']['type'],
'#default_value' => isset($items[$delta]) ? $items[$delta] : '',
);
return $element;
}
/**
* Process an individual element.
*
* Build the form element. When creating a form using FAPI #process,
* note that $element['#value'] is already set.
*
* The $fields array is in $form['#field_info'][$element['#field_name']].
*/
function vimeo_browser_process($element, $form_state, $complete_form) {
drupal_add_js(drupal_get_path('module', 'vimeo') . '/vimeo.js');
drupal_add_css(drupal_get_path('module', 'vimeo') . '/theme/vimeo.css', array('media' => 'screen', 'preprocess' => FALSE));
if (module_exists('jquery_ui')) {
drupal_add_library('system', 'ui.dialog');
}
// Probably won't work in all cases... but I'm hoping it will
$field = $form_state['field'][$element['#parents'][0]][$element['#parents'][1]]['field'];
$instance = $form_state['field'][$element['#parents'][0]][$element['#parents'][1]]['instance'];
$field_name = explode('_', $field['field_name']);
$settings = array();
$settings['title'] = $instance['label'];
$settings['description'] = $instance['description'];
$settings['required'] = $instance['required'];
$settings = base64_encode(serialize($settings));
//Get data if available
$field_key = 'value';
if (isset($element['#value'][$field_key])) {
$data = vimeo_cache_video_get($element['#value'][$field_key]);
//$hash = md5(rand() * rand());
$button = '' . t('Remove') . ' | ' . t('Refresh') . '';
//$thumb = '';
$thumb = '';
$title = $data['title'];
$owner = $data['user_name'];
$vid = $element['#value'][$field_key];
}
else {
$button = '' . t('Browse') . '';
$thumb = NULL;
$title = NULL;
$owner = NULL;
$vid = NULL;
}
//Vimeo video ID
$element[$field_key] = array(
'#type' => 'textfield',
'#default_value' => $vid,
'#autocomplete_path' => $element['#autocomplete_path'],
'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60,
'#attributes' => array('class' => array('vimeo-field-id')),
'#field_prefix' => '
' . $thumb . '
',
'#field_suffix' => '
' . $title .' ' . $owner . '
' . $button . '
',
'#prefix' => '
',
'#suffix' => '
',
// The following values were set by the content module and need
// to be passed down to the nested element.
'#title' => $instance['label'],
'#description' => $instance['description'],
'#required' => $instance['required'],
'#field_name' => $field['field_name'],
'#type_name' => $field['type'],
'#delta' => $element['#parents'][2],
'#columns' => $field['columns'],
);
// Used so that hook_field('validate') knows where to flag an error.
$element['_error_element'] = array(
'#type' => 'value',
'#value' => implode('][', array_merge($element['#parents'], array($field_key))),
);
return $element;
}
/**
* FAPI theme for an individual vimeo elements.
*
* The vimeofield or vimeoarea is already rendered by the
* vimeofield or vimeoarea themes and the html output
* lives in $element['#children']. Override this theme to
* make custom changes to the output.
*
* $element['#field_name'] contains the field name
* $element['#delta] is the position of this element in the group
*/
function theme_vimeo_browser($element) {
return drupal_render($element);
}
/**
* Implements hook_image_default_styles().
*/
function vimeo_image_default_styles() {
$styles = array();
$styles['vimeo_thumbnail'] = array(
'label' => 'VIMEO thumbnail',
'effects' =>
array(
array(
'name' => 'image_scale_and_crop',
'weight' => '1',
'data' => array(
'width' => 160,
'height' => 90,
'upscale' => 0,
),
),
),
);
return $styles;
}