Index: emfield.module
===================================================================
RCS file: /cvs/drupal/contributions/modules/emfield/emfield.module,v
retrieving revision 1.25
diff -u -r1.25 emfield.module
--- emfield.module 20 Jun 2008 17:04:54 -0000 1.25
+++ emfield.module 27 Nov 2008 16:52:20 -0000
@@ -1,207 +1,78 @@
'admin/content/emfield',
- 'title' => t('Embedded Media Field configuration'),
- 'description' => t('Configure Embedded Media Field: Allow content types to use various 3rd party providers, enter API keys, etc.'),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => 'emfield_settings',
- 'access' => user_access('administer site configuration'),
- );
- $items[] = array(
- 'path' => 'admin/content/emfield/media',
- 'title' => t('Media settings'),
- 'description' => t('Configure Embedded Media Field: Allow content types to use various 3rd party providers, enter API keys, etc.'),
- 'callback' => 'drupal_get_form',
- 'callback arguments' => 'emfield_settings',
- 'access' => user_access('administer site configuration'),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- );
- }
- return $items;
-}
/**
- * Callback for admin/content/emfield
+ * Implementation of hook_menu().
*/
-function emfield_settings() {
- if (!module_exists('video_cck') && !module_exists('image_ncck') && !module_exists('emaudio')) {
- drupal_set_message(t('The Embedded Media Field module does nothing on its own. You should also install the Embedded Video Field, Embedded Image Field, and/or Embedded Audio Field modules from the !modules. (If you do not see them listed there, under the CCK section, you may need to !download from its project page. They are all in the same package.)', array('!download' => l(t('download the module'), 'http://drupal.org/project/emfield'), '!modules' => l(t('modules administration page'), 'admin/build/modules'))), 'error');
- }
- $form = array();
- $form['general'] = array(
- '#type' => 'fieldset',
- '#title' => t('General Settings'),
- '#description' => t('These features will be generally available for use by related modules as needed.'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
+function emfield_menu() {
+ $items['admin/content/emfield'] = array(
+ 'file' => 'emfield.admin.inc',
+ 'title' => 'Embedded Media Field configuration',
+ 'description' => 'Configure Embedded Media Field: Allow content types to use various 3rd party providers, enter API keys, etc.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('emfield_settings'),
+ 'access arguments' => array('administer site configuration'),
);
- if (module_exists('swfobject_api')) {
- $swfobject_desc = t('As you have the !swfobject_api module installed, Embedded Media Field will use those settings, assuming you\'ve configured them properly. Visit its !settings for more information.', array('!swfobject_api' => l(t('SWFObject API'), 'http://drupal.org/project/swfobject_api', array('target' => '_blank')), l(t('settings page'), 'admin/settings/swfobject_api')));
- }
- else {
- $swfobject_desc = t('If you have the swfobject.js file installed on your system, you can make it available to Embedded Media Field and its related modules by entering the information here. You can download and find out more about !here. You may also choose to install the !swfobject_api module, which will integrate automatically with this module..', array('!here' => l(t('SWFObject here'), 'http://code.google.com/p/swfobject/', array('target' => '_blank')), '!swfobject_api' => l(t('SWFObject API'), 'http://drupal.org/project/swfobject_api', array('target' => '_blank'))));
- }
- $form['general']['swfobject'] = array(
- '#type' => 'fieldset',
- '#title' => t('SWF Object'),
- '#description' => $swfobject_desc,
- '#collapsible' => TRUE,
+ $items['admin/content/emfield/media'] = array(
+ 'file' => 'emfield.admin.inc',
+ 'title' => 'Media settings',
+ 'description' => 'Configure Embedded Media Field: Allow content types to use various 3rd party providers, enter API keys, etc.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('emfield_settings'),
+ 'access arguments' => array('administer site configuration'),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
);
- $form['general']['swfobject']['emfield_swfobject'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use SWFObject'),
- '#default_value' => variable_get('emfield_swfobject', FALSE),
- '#description' => t('When checked, then Embedded Media Field will use the SWFObject javascript library when it is able.'),
- );
- if (!module_exists('swfobject_api')) {
- $form['general']['swfobject']['emfield_swfobject_location'] = array(
- '#type' => 'textfield',
- '#title' => t('SWFObject location'),
- '#default_value' => variable_get('emfield_swfobject_location', ''),
- '#description' => t('Enter the relative path to the swfobject.js file, without the preceding slash (/).'),
+
+ if (module_exists('job_queue')) {
+ $items['admin/content/emfield/reload'] = array(
+ 'file' => 'emfield.admin.inc',
+ 'title' => 'Reload data',
+ 'description' => 'Reload emfield fields in bulk',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('emfield_settings_jobqueue'),
+ 'access arguments' => array('administer site configuration'),
+ 'type' => MENU_LOCAL_TASK,
);
}
- $header = array(t('Feature'), t('Supported'), t('Notes'));
- foreach (module_implements('emfield_info', TRUE) as $module) {
- $emfield_info = module_invoke($module, 'emfield_info');
- $providers = emfield_system_list($module);
- $form[$module] = array(
- '#type' => 'fieldset',
- '#title' => t('@neighborhood', array('@neighborhood' => $emfield_info['#name'])),
- '#description' => $emfield_info['#settings_description'],
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- $form[$module]['providers'] = array(
- '#type' => 'fieldset',
- '#title' => t('Providers'),
- '#description' => t('The following settings determine what providers are allowed, and what provider-specific options, if any, are set.'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- foreach ($providers as $provider) {
- $info = emfield_include_invoke($module, $provider->name, 'info');
- $form[$module]['providers'][$provider->name] = array(
- '#type' => 'fieldset',
- '#title' => t('@provider configuration', array('@provider' => $info['name'])),
- '#description' => $info['settings_description'],
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- if (is_array($info['supported_features']) && !empty($info['supported_features'])) {
- $form[$module]['providers'][$provider->name]['supported_features'] = array(
- '#type' => 'fieldset',
- '#title' => t('Supported features'),
- '#description' => t('This is a list of the current state of support for the following features by %provider:', array('%provider' => $info['name'])),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- '#weight' => 7,
- );
- $form[$module]['providers'][$provider->name]['supported_features']['features'] = array(
- '#type' => 'markup',
- '#value' => theme('table', $header, $info['supported_features']),
- );
- }
- $form[$module]['providers'][$provider->name]['emfield_'. $module .'_allow_'. $provider->name] = array( '#type' => 'checkbox',
- '#title' => t('Allow content from %provider', array('%provider' => $info['name'])),
- '#description' => t('If checked, then content types may be created that allow content to be provided by %provider.', array('%provider' => $info['name'])),
- '#weight' => -10,
- '#default_value' => variable_get('emfield_'. $module .'_allow_'. $provider->name, TRUE),
- );
- $form[$module]['providers'][$provider->name][] = emfield_include_invoke($module, $provider->name, 'settings');
- }
- $form[$module] = array_merge($form[$module], module_invoke($module, 'emfield_settings'));
- }
- return system_settings_form($form);
+ return $items;
}
-function emfield_field_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),
- );
- foreach (module_implements('emfield_field_columns_extra') as $module) {
- $extra = module_invoke($module, 'emfield_field_columns_extra');
- if (is_array($extra)) {//print_r($extra);
- $columns = array_merge($columns, $extra);
- }
- }
- return $columns;
+function emfield_field_columns($field) {
+ module_load_include('inc', 'emfield', 'emfield.cck');
+
+ return _emfield_field_columns($field);
}
-/** Implementation of hook_emfield_field **/
+/**
+ * A helper function for hook_field(), called by the various sub-modules.
+ */
function emfield_emfield_field($op, &$node, $field, &$items, $teaser, $page, $module) {
- switch ($op) {
- // TODO: nothing to validate at the moment. we need to have different provider api's have a chance to validate
- case 'validate':
- foreach ($items as $delta => $item) {
- $error_field = $field['multiple'] ? $field['field_name'] .']['. $delta .'][embed' : $field['field_name'];
- _emfield_field_validate_id($field, $item, $error_field, $module, $delta);
- }
- break;
-
- case 'submit':
- foreach ($items as $delta => $item) {
- $list = _emfield_field_submit_id($field, $item, $module);
- $items[$delta]['provider'] = $list['provider'];
- $items[$delta]['value'] = $list['value'];
- $items[$delta]['data'] = $list['data'];
- }
- break;
+ module_load_include('inc', 'emfield', 'emfield.cck');
+ return _emfield_emfield_field($op, $node, $field, $items, $teaser, $page, $module);
+}
- case 'load':
- // We need to unserialize the 'data' column manually
- $field_name = $field['field_name'];
- foreach ($items as $delta => $item) {
- $data = (array)unserialize($items[$delta]['data']);
- $items[$delta]['data'] = $data;
- $node->{$field_name}[$delta]['data'] = $data;
- }
- $return = array();
- $return[$field_name] = $items;
- break;
- case 'delete':
- break;
- }
- // allow modules (such as emthumb) to alter our data.
- foreach (module_implements('emfield_field_extra') as $module) {
- $args = array($op, &$node, $field, &$items, $teaser, $page, $module);
- $ret = call_user_func_array($module .'_emfield_field_extra', $args);
- if (is_array($return) && is_array($ret)) {
- $return = array_merge($return, $ret);
- }
- }
-// drupal_set_message($op .' node field:
'. print_r($items, true) .'
');
- if (in_array($op, array('insert', 'update'))) {
- // we need to manually serialize the 'data' array
- foreach ($items as $delta => $item) {
- $items[$delta]['data'] = serialize($items[$delta]['data']);
- }
- }
- return $return;
+/**
+ * Helper function to implement hook_content_is_empty.
+ */
+function emfield_emfield_content_is_empty($item, $field) {
+ return empty($item['value']);
}
/**
- * return a list of providers allowed for a specific field
+ * Return a list of providers allowed for a specific field.
*/
function emfield_allowed_providers($field, $module) {
-// $module = $field['widget']['helper_module'];
$allowed_providers = emfield_system_list($module);
$providers = array();
$allow_all = TRUE;
foreach ($allowed_providers as $test) {
- if (!variable_get('emfield_' . $module . '_allow_' . $test->name, TRUE)) {
+ if (!variable_get('emfield_'. $module .'_allow_'. $test->name, TRUE)) {
unset($allowed_providers[$test->name]);
}
else {
@@ -215,26 +86,27 @@
}
}
}
+
return $allowed_providers;
}
/**
- * this returns a list of content types that are implemented by emfield
+ * This returns a list of content types that are implemented by emfield.
*/
function emfield_implement_types($cached = TRUE) {
static $types;
if (!isset($types) || !$cached) {
- // if it's a cachable request, try to load a cached value
+ // If it's a cachable request, try to load a cached value.
if ($cached && $cache = cache_get('emfield_implement_types', 'cache')) {
- $types = unserialize($cache->data);
+ $types = $cache->data;
}
else {
$system_types = _content_type_info();
$content_types = $system_types['content types'];
$field_types = $system_types['field types'];
- // the array that will store type/field information for provider import
+ // The array that will store type/field information for provider import.
$types = array();
$modules = array();
@@ -242,14 +114,14 @@
$modules[$module] = $module;
}
- // settings per content type for the module
+ // Settings per content type for the module.
foreach ($content_types as $content_type => $type) {
- // determine which content types implement this module
+ // Determine which content types implement this module.
foreach ($type['fields'] as $field_type => $field) {
- // if this field type is defined by this module, then include it here
+ // If this field type is defined by this module, then include it here.
if ($module = $modules[$field_types[$field['type']]['module']]) {
- // settings per content type per module
+ // Settings per content type per module.
$types[$module][$content_type][$field_type] = $field;
}
}
@@ -257,275 +129,145 @@
}
}
- cache_set('emfield_implement_types', 'cache', serialize($types), CACHE_PERMANENT);
+ cache_set('emfield_implement_types', $types, 'cache', CACHE_PERMANENT);
+
return $types;
}
/**
- * This will parse the url or embedded code pasted by the node submitter.
- * returns either an empty array (if no match), or an array of provider and value.
+ * This will parse the url or embedded code pasted by the node submitter.
+ *
+ * @return
+ * Either an empty array (if no match), or an array of 'provider' and 'value'.
*/
function emfield_parse_embed($field, $embed = '', $module) {
-// if ($embed) {
-// $module = $field['widget']['helper_module'];
- $providers = emfield_allowed_providers($field, $module);
- foreach ($providers as $provider) {
- $success = emfield_include_invoke($module, $provider->name, 'extract', $embed, $field);
- // we've been given an array of regex strings, so let's see if we can find a match
- if (is_array($success)) {
- foreach ($success as $regex) {
- $matches = NULL;
- if (preg_match($regex, $embed, $matches)) {
- return array('provider' => $provider->name, 'value' => $matches[1]);
- }
- }
- }
- // the invoked include module did its own parsing and found a match
- else if ($success) {
- return array('provider' => $provider->name, 'value' => $success);
- }
- }
-// }
- // we found no match
+ if($module == 'emfield_generic'){
+ $types = array("emaudio","emimage","emvideo");
+ foreach($types as $type){
+ $providers = _emfield_generic_allowed_providers($field, $module,$type);
+ foreach ($providers as $provider) {
+ $success = _emfield_generic_include_invoke($module, $type, $provider->name, 'extract', $embed, $field);
+ // We've been given an array of regex strings, so try to find a match.
+ if (is_array($success)) {
+ foreach ($success as $regex) {
+ $matches = NULL;
+ if (preg_match($regex, $embed, $matches)) {
+ return array('provider' => $provider->name, 'value' => $matches[1],'type'=> $type);
+ }
+ }
+ }
+ // the invoked include module did its own parsing and found a match
+ else if ($success) {
+ return array('provider' => $provider->name, 'value' => $success,'type' => $type);
+ }
+ }
+ }
+ return array('provider' => '', 'value' => '');
+ }
+ else {
+ $providers = emfield_allowed_providers($field, $module);
+ foreach ($providers as $provider) {
+ $success = emfield_include_invoke($module, $provider->name, 'extract', $embed, $field);
+
+ // We've been given an array of regex strings, so try to find a match.
+ if (is_array($success)) {
+ foreach ($success as $regex) {
+ $matches = NULL;
+ if (preg_match($regex, $embed, $matches)) {
+ return array('provider' => $provider->name, 'value' => $matches[1]);
+ }
+ }
+ }
+ // the invoked include module did its own parsing and found a match
+ else if ($success) {
+ return array('provider' => $provider->name, 'value' => $success);
+ }
+ }
+ }
+ // We found no match.
return array();
}
/**
- * extract the id from embedded code or url
+ * Extract the id from embedded code or url.
*/
function _emfield_field_validate_id($field, $item, $error_field, $module, $delta = 0) {
- // load the provider info
+ // Load the provider info.
$item = _emfield_field_submit_id($field, $item, $module, $error_field);
- // ensure we have proper provider info
+ // Ensure we have proper provider info.
+ //dpr($item);
+ //exit;
if ($item['embed'] && !$item['value']) {
- form_set_error($error_field, t('You have specified an invalid media URL or embed code.'));
+ form_set_error($error_field, t('You have specified an invalid media URL or embed code or doesn\'t exist a provider for your entry.'));
}
+
return $item;
}
/**
- * replace embedded code with the extracted id. this goes in the field 'value'
- * also allows you to grab directly from the URL to display the content from field 'provider'
+ * Replace embedded code with the extracted id. this goes in the field 'value'.
+ * This also allows you to grab directly from the URL to display the content from field 'provider'.
*/
function _emfield_field_submit_id($field, $item, $module) {
-// $module = $field['widget']['helper_module'];
$item = array_merge($item, emfield_parse_embed($field, $item['embed'], $module));
- $item['data'] = (array)emfield_include_invoke($module, $item['provider'], 'data', $field, $item);
+ if($module == "emfield_generic"){
+ $item['data'] = (array) _emfield_generic_include_invoke($module, $item['type'],$item['provider'], 'data', $field, $item);
+ }
+ else {
+ $item['data'] = (array)emfield_include_invoke($module, $item['provider'], 'data', $field, $item);
+ }
+ /*dpr($item);
+ exit;*/
return $item;
}
+/**
+ * Format our field for display. This is actually called originally by each helper module
+ * that implements hook_field_formatter, which then call this.
+ */
function emfield_emfield_field_formatter($field, $item, $formatter, $node, $module) {
- // if we're coming from a preview, we need to extract our new embedded value...
- if ($node->in_preview) {
+ // If we're coming from a preview, we need to extract our new embedded value.
+ if (isset($node->in_preview)) {
$item = emfield_parse_embed($field, $item['embed'], $module);
}
-
- // if we have no value, then return an empty string
+
+ // If we have no value, then return an empty string.
if (!isset($item['value'])) {
return '';
}
- // unfortunately, when we come from a view, we don't get all the widget fields
+ // Unfortunately, when we come from a view, we don't get all the widget fields.
if (!$node->type) {
$type = content_types($field['type_name']);
$field['widget'] = $type['fields'][$field['field_name']]['widget'];
}
- // and sometimes our data is still unserialized, again from views
+ // Sometimes our data is still unserialized, again from views.
if (!is_array($item['data'])) {
$item['data'] = (array)unserialize($item['data']);
}
-// $module = $field['widget']['helper_module'];
-
- $output .= theme($module .'_'. $formatter, $field, $item, $formatter, $node);
-
+ // The individual modules actually define the theme for the formatter.
+ $output = '';
+ if(empty($item['type'])){
+ $output .= theme($module .'_'. $formatter, $field, $item, $formatter, $node);
+ } else {
+ $output .= theme($item['type'] . '_'. $formatter, $field, $item, $formatter, $node);
+ }
+ //dpr($item);
return $output;
}
/** Widgets **/
function emfield_emfield_widget_settings($op, $widget, $module) {
- switch ($op) {
- case 'form':
- // make sure to register the new type as supported by this module
- emfield_implement_types(FALSE);
-
- $form = array();
- $options = array();
- $providers = emfield_system_list($module);
- foreach ($providers as $provider) {
- if (variable_get('emfield_allow_'. $module .'_'. $provider->name, TRUE)) {
- $info = emfield_include_invoke($module, $provider->name, 'info');
- $options[$provider->name] = $info['name'];
- }
- }
- $form['provider_list'] = array(
- '#type' => 'fieldset',
- '#title' => t('Providers Supported'),
- '#description' => t('Select which third party providers you wish to allow for this content type from the list below. If no checkboxes are checked, then all providers will be supported. When a user submits new content, the URL they enter will be matched to the provider, assuming that provider is allowed here.'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['provider_list']['providers'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Providers'),
- '#default_value' => $widget['providers'] ? $widget['providers'] : array(),
- '#options' => $options,
- );
-
- foreach (module_implements('emfield_widget_settings_extra') as $module) {
- $form[$module] = module_invoke($module, 'emfield_widget_settings_extra', 'form', $widget);
- }
-
- return $form;
-
- case 'save':
- $columns = array('providers'); //, 'helper_module', );
- foreach (module_implements('emfield_widget_settings_extra') as $module) {
- $columns = array_merge($columns, module_invoke($module, 'emfield_widget_settings_extra', 'save', $widget));
- }
- return $columns;
- }
+ module_load_include('inc', 'emfield', 'emfield.cck');
+ return _emfield_emfield_widget_settings($op, $widget, $module);
}
-function emfield_emfield_widget($op, &$node, $field, &$node_field, $module) {
-// $module = $field['widget']['helper_module'];
- switch ($op) {
- case 'prepare form values':
- // Don't save empty fields except the first value
- foreach ($node_field as $delta => $item) {
- if ($item['value'] == '' && $delta > 0) {
- unset($node_field[$delta]);
- }
- }//print 'nodefield:' ; print_r($node_field);
- foreach (module_implements('emfield_widget_extra') as $module) {
- $args = array($op, &$node, $field, &$node_field, $module);
- call_user_func_array($module .'_emfield_widget_extra', $args);
- }
- break;
- case 'form':
- $form = array();
-
- $form[$field['field_name']] = array('#tree' => TRUE);
- $textfield = 'embed';
- $providers = emfield_allowed_providers($field, $module);
- $urls = array();
- $additional_form_elements = array();
- foreach ($providers as $provider) {
- // don't check providers not allowed
- if (variable_get('emfield_allow_'. $module .'_'. $provider->name, TRUE)) {
- $info = emfield_include_invoke($module, $provider->name, 'info');
- $urls[] = l($info['name'], $info['url'], array('target' => '_blank'));
- $additional_element = emfield_include_invoke($module, $provider->name, 'form');
- if ($additional_element) {
- $additional_form_elements[$provider->name] = $additional_element;
- }
- }
- }
- $textfield_title = t($field['widget']['label']);
- if (!(empty($field['widget']['description']))) {
- $textfield_description = $field['widget']['description'];
- }
- else {
- $textfield_description = t('Enter the URL or Embed Code here. The embedded third party content will be parsed and displayed appropriately from this.');
- }
- $textfield_description .= ' '. t('The following services are provided: !urls', array('!urls' => implode(', ', $urls)));
+function emfield_emfield_widget(&$form, &$form_state, $field, $items, $delta = 0, $module) {
+ module_load_include('inc', 'emfield', 'emfield.cck');
- if ($field['multiple']) {
- $form[$field['field_name']]['#type'] = 'fieldset';
- $form[$field['field_name']]['#title'] = t($field['widget']['label']);
- $delta = 0;
- foreach ($node_field as $data) {
- if (isset($data[$textfield])) {
- $form[$field['field_name']][$delta][$textfield] = array(
- '#type' => 'textfield',
- '#title' => $textfield_title,
- '#description' => $textfield_description,
- '#default_value' => $data[$textfield],
- '#required' => ($delta == 0) ? $field['required'] : FALSE,
- '#maxlength' => 2048,
- );
- if (!empty($additional_form_elements)) {
- foreach ($additional_form_elements as $key => $element) {
- $form[$field['field_name']][$delta][$key] = $element;
- }
- }
- $form[$field['field_name']][$delta]['value'] = array(
- '#type' => 'value',
- '#value' => $data['value'],
- );
- if ($data['value']) {
- $info = emfield_include_invoke($module, $data['provider'], 'info');
- $form[$field['field_name']][$delta]['value_markup'] = array(
- '#type' => 'item',
- '#value' => t('(@provider ID: !value)', array('@provider' => $info['name'], '!value' => l($data['value'], emfield_include_invoke($module, $info['provider'], 'embedded_link', $data['value'], $data['data']), array('target' => '_blank')))),
- );
- }
- foreach (module_implements('emfield_widget_extra') as $module) {
- $form[$field['field_name']][$delta][$module] = module_invoke($module, 'emfield_widget_extra', 'form', $node, $field, $data);
- }
- $delta++;
- }
- }
- foreach (range($delta, $delta + 2) as $delta) {
- $form[$field['field_name']][$delta][$textfield] = array(
- '#type' => 'textfield',
- '#title' => $textfield_title,
- '#description' => $textfield_description,
- '#default_value' => '',
- '#required' => ($delta == 0) ? $field['required'] : FALSE,
- '#maxlength' => 2048,
- );
- if (!empty($additional_form_elements)) {
- foreach ($additional_form_elements as $key => $element) {
- $form[$field['field_name']][$delta][$key] = $element;
- }
- }
- $form[$field['field_name']][$delta]['value'] = array(
- '#type' => 'value',
- '#title' => '',
- );
- foreach (module_implements('emfield_widget_extra') as $module) {
- $form[$field['field_name']][$delta][$module] = module_invoke($module, 'emfield_widget_extra', 'form', $node, $field, $data);
- }
- }
- }
- else {
- $form[$field['field_name']][0][$textfield] = array(
- '#type' => 'textfield',
- '#title' => $textfield_title, //t($field['widget']['label']),
- '#description' => $textfield_description,
- '#default_value' => isset($node_field[0][$textfield]) ? $node_field[0][$textfield] : '',
- '#required' => $field['required'],
- '#maxlength' => 2048,
- );
- if ($textfield == 'embed') {
- $value = isset($node_field[0]['value']) ? $node_field[0]['value'] : '';
- $form[$field['field_name']][0]['value'] = array(
- '#type' => 'value',
- '#value' => $value,
- );
- if (!empty($additional_form_elements)) {
- foreach ($additional_form_elements as $key => $element) {
- $form[$field['field_name']][0][$key] = $element;
- }
- }
- if ($value) {
- $info = emfield_include_invoke($module, $node_field[0]['provider'], 'info');
- $form[$field['field_name']][0]['value_markup'] = array(
- '#type' => 'item',
- '#value' => t('(@provider ID: !value)', array('@provider' => $info['provider'], '!value' => l($value, emfield_include_invoke($module, $info['provider'], 'embedded_link', $value, $node_field[0]['data']), array('target' => '_blank')))),
- );
- }
- foreach (module_implements('emfield_widget_extra') as $module) {
- $form[$field['field_name']][$delta][$module] = module_invoke($module, 'emfield_widget_extra', 'form', $node, $field, $node_field[0]);
- }
- }
- }
- return $form;
- default:
- break;
- }
+ return _emfield_emfield_widget($form, $form_state, $field, $items, $delta, $module);
}
/**
@@ -538,6 +280,7 @@
'callback' => 'emfield_operations_reload',
),
);
+
return $operations;
}
@@ -567,130 +310,15 @@
function emfield_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'rss item':
- $files = array();
- $type = content_types($node->type);
- foreach ($type['fields'] as $field) {
- if (module_hook($field['type'], 'emfield_info')) {
- $items = (array)$node->{$field['field_name']};
- $rss_encl = module_invoke($field['type'], 'emfield_rss', $node, $items, $teaser);
- // about here let extras change the data
- // allow modules (such as emthumb, or a future emmetadata) to alter our data.
- foreach (module_implements('emfield_field_extra') as $module) {
- $args = array($op, &$node, $field, &$items, $teaser, $page, $module);
- $ret = call_user_func_array($module .'_emfield_field_extra', $args);
- if (is_array($rss_encl) && is_array($ret)) {
- while (list($delta, ) = each($rss_encl)) {
- if (is_array($ret[$delta]) && is_array($rss_encl[$delta])) {
- $rss_encl[$delta] = $ret[$delta] + $rss_encl[$delta];
- }
- }
- }
- }
- if (is_array($rss_encl)) {
- // by now the delta doesn't matter we have enough data in the individual arrays
- $files = array_merge($files, $rss_encl);
- }
- }
- }
-
- $enclosure = array();
- $rss = array();
- foreach ($files as $file) {
- // RRS2 enclosure http://cyber.law.harvard.edu/rss/rss.html#ltenclosuregtSubelementOfLtitemgt
- if (
- count($enclosure) < 1 && // only one per
- isset($file['filepath']) && isset($file['filesize']) && isset($file['filemime']) &&
- $file['filepath'] != '' && $file['filesize'] > 0 && $file['filemime'] != ''
- ) {
- $enclosure = array(
- 'key' => 'enclosure',
- 'attributes' => array(
- 'url' => check_url($file['filepath']),
- 'length' => (int) $file['filesize'],
- 'type' => check_plain($file['filemime']),
- )
- );
- }
-
- // MRSS media:content http://search.yahoo.com/mrss
- $media = array();
- if (isset($file['filepath']) && $file['filepath'] != '') {
- // actually optional if media:player were to be specified
- $media['url'] = check_url($file['filepath']);
- // the rest of these are optional
- if (isset($file['filesize']) && $file['filesize'] > 1) {
- $media['fileSize'] = (int) $file['filesize'];
- }
- if ($file['filemime']) {
- $media['type'] = check_plain($file['filemime']);
- }
- if (isset($file['medium']) && $file['medium'] != '') {
- $media['medium'] = check_plain($file['medium']);
- }
- // media:isDefault, may be good for multiple CCK fields - ignored for now
- if (isset($file['expression']) && $file['expression'] != '') {
- $media['expression'] = check_plain($file['expression']);
- }
- if (isset($file['bitrate']) && $file['bitrate'] > 0) {
- $media['bitrate'] = (int) $file['bitrate'];
- }
- if (isset($file['framerate']) && $file['framerate'] > 0) {
- $media['framerate'] = (int) $file['framerate'];
- }
- if (isset($file['sampling_rate']) && $file['sampling_rate'] > 0) {
- $media['samplingrate'] = (int) $file['sampling_rate'];
- }
- if (isset($file['channels']) && $file['channels'] > 0) {
- $media['channels'] = check_plain($file['channels']);
- }
- if (isset($file['duration']) && $file['duration'] > 0) {
- $media['duration'] = (int) $file['duration'];
- }
- if (
- isset($file['width']) && isset($file['height']) &&
- $file['width'] > 0 && $file['height'] > 0
- ) {
- $media['width'] = (int) $file['width'];
- $media['height'] = (int) $file['height'];
- }
- // media:lang will be interesting
-
- $mrss_thumbnail = array();
- if (is_array($file['thumbnail']) && $file['thumbnail']['filepath'] != '') {
- $thumbnail = array();
- $thumbnail['url'] = check_url($file['thumbnail']['filepath']);
- if (isset($file['thumbnail']['height']) && $file['thumbnail']['height'] > 0) {
- $thumbnail['height'] = (int) $file['thumbnail']['height'];
- }
- if (isset($file['thumbnail']['width']) && $file['thumbnail']['width'] > 0) {
- $thumbnail['width'] = (int) $file['thumbnail']['width'];
- }
- if (isset($file['thumbnail']['time']) && $file['thumbnail']['time'] > 0) {
- $thumbnail['time'] = (int) $file['thumbnail']['time'];
- }
- $mrss_thumbnail = array('key' => 'media:thumbnail', 'attributes' => $thumbnail);
- }
- $rss[] = array('key' => 'media:content', 'attributes' => $media, 'value' => array($mrss_thumbnail));
- }
- }
-
- // work around for http://drupal.org/node/157709
- static $been_here = FALSE;
- if (! $been_here) {
- $rss[] = array('namespace' => array('xmlns:media="http://search.yahoo.com/mrss/"'));
- $been_here = TRUE;
- }
-
- $rss[] = $enclosure;
-
- return $rss;
+ module_load_include('inc', 'emfield', 'emfield.rss');
+ return _emfield_nodeapi_rss($node, $op, $teaser, $page);
}
}
/**
* When an include file requires to read an xml to receive information, such as for thumbnails,
* this script can be used to request the xml and return it as an array.
- * i suspect it could be done easier (and more quickly) in php 5.
+ * @TODO convert to simplexml
* @param $provider
* the string of the third party provider, such as 'youtube', 'flikr', or 'google'
* @param $url
@@ -706,13 +334,13 @@
function emfield_request_xml($provider, $url, $args = array(), $cached = TRUE, $return_errors = FALSE, $hash_extra = FALSE, $serialized = FALSE) {
ksort($args);
- // build an argument hash that we'll use for the cache id and api signing
+ // Build an argument hash that we'll use for the cache id and api signing.
$arghash = $provider .':';
foreach ($args as $k => $v) {
$arghash .= $k . $v;
}
- // build the url
+ // Build the url.
foreach ( $args as $k => $v) {
$encoded_params[] = urlencode($k) .'='. urlencode($v);
}
@@ -728,7 +356,7 @@
// if it's a cachable request, try to load a cached value
if ($cached && $cache = cache_get($arghash, 'cache')) {
- return unserialize($cache->data);
+ return $cache->data;
}
// connect and fetch a value
@@ -743,6 +371,7 @@
);
}
emfield_set_error(t("Could not connect to @provider, HTTP error @error", array('@error' => $result->code, '@provider' => $provider)));
+
return array();
}
@@ -757,7 +386,9 @@
'message' => 'The response was corrupted, it could not be unserialized.',
);
}
+
emfield_set_error(t("The response from @provider was corrupted and could not be unserialized.", array('@provider' => $provider)));
+
return array();
}
}
@@ -794,27 +425,28 @@
}
}
- cache_set($arghash, 'cache', serialize($response), time() + variable_get('emfield_cache_duration', 3600));
+ cache_set($arghash, $response, 'cache', time() + variable_get('emfield_cache_duration', 3600));
+
return $response;
}
/**
- * Get the HTTP Header of media, for mime-type and length
+ * Get the HTTP Header of media, for mime-type and length.
*
- * @param $provider
- * the string of the third party provider, such as 'youtube', 'flikr', or 'google'
- * @param $url
- * the url for the media
- * @param $cached
- * optional; if TRUE, the result of this xml request will be cached. good to play nice w/
- * the third party folks so they don't stop providing service to your site...
- * @return
- * the header results returned as an array
+ * @param $provider
+ * The string of the third party provider, such as 'youtube', 'flikr', or 'google'.
+ * @param $url
+ * The url for the media.
+ * @param $cached
+ * Optional; if TRUE, the result of this xml request will be cached. good to play nice w/
+ * the third party folks so they don't stop providing service to your site...
+ * @return
+ * The header results, returned as an array.
*/
function emfield_request_header($provider, $url, $cached = TRUE, $return_errors = TRUE) {
// if it's cacheable, try to load a cached value
if ($cached && $cache = cache_get($url, 'cache')) {
- return unserialize($cache->data);
+ return $cache->data;
}
$result = _emfield_http_request_header($url);
@@ -825,11 +457,13 @@
}
emfield_set_error(t("Could not connect to @provider, HTTP error @error", array('@error' => $result->code, '@provider' => $provider)));
+
return array();
}
// @todo does this not want to be changing 'cache' to 'cache_emfield' or similar
- cache_set($url, 'cache', serialize($result), time() + variable_get('emfield_cache_duration', 3600));
+ cache_set($url, $result, 'cache', time() + variable_get('emfield_cache_duration', 3600));
+
return $result;
}
@@ -852,7 +486,7 @@
case 303: // See Other <-- drupal_http_request doesn't deal with this we need this for youtube
case 307: // Moved temporarily
$location = $result->headers['Location'];
- if ($retry) {
+ if ($retry > 0) {
$result = _emfield_http_request_header($result->headers['Location'], --$retry);
$result->redirect_code = $result->code;
}
@@ -866,7 +500,7 @@
}
function emfield_set_error($error) {
- watchdog('emfield', $error, WATCHDOG_WARNING);
+ watchdog('emfield', '!error', array('!error' => $error), WATCHDOG_WARNING);
}
/**
@@ -885,7 +519,9 @@
$override_files = module_invoke_all('emfield_providers', $module, $provider);
$files = drupal_system_listing("$provider\.inc", drupal_get_path('module', $module) ."/providers", 'name', 0);
$files = array_merge($files, $override_files);
-
+ /*print "
";
+ debug_print_backtrace();
+ print "
";*/
ksort($files);
if ($load) {
@@ -955,7 +591,7 @@
}
/**
- * Custom filter for provider NOT NULL
+ * Custom filter for provider NOT NULL.
*/
function emfield_views_handler_filter_is_not_null($op, $filter, $filterinfo, &$query) {
if ($op == 'handler') {
@@ -975,14 +611,14 @@
*/
function emfield_views_handler_filter_provider_list($op) {
$providers = array();
- foreach (emfield_system_list('video_cck') as $provider => $info) {
+ foreach (emfield_system_list('emvideo') as $provider => $info) {
$providers[$provider] = $info->name;
}
return $providers;
}
/**
- * Views handler for the provider list filter.
+ * Views handler for the provider list filter.
*/
function emfield_views_handler_filter_provider($op, $filter, $filterinfo, &$query) {
if ($op == 'handler') {
@@ -1012,14 +648,14 @@
*/
function _emfield_handler_arg_provider($op, &$query, $argtype, $arg = '', $module = '') {
if ($op == 'filter') {
- $field_name = substr($argtype['type'], 10);
+ $field_name = drupal_substr($argtype['type'], 10);
}
else {
- $field_name = substr($argtype, 10);
+ $field_name = drupal_substr($argtype, 10);
}
$field = content_fields($field_name);
- $db_info = content_database_info($field);
+ $db_info = content_database_info($field); // TODO: This hook no longer exists in D6.
$main_column = $db_info['columns']['provider'];
// The table name used here is the Views alias for the table, not the actual
@@ -1054,3 +690,42 @@
}
}
+function emfield_provider_themes($module, $provider = NULL) {
+ $themes = array();
+
+ if($module == 'emfield_generic'){
+
+ $types = array("emaudio","emimage","emvideo");
+
+ if($provider){
+ foreach($types as $type){
+ if ($subthemes = _emfield_include_invoke($module, $type, $provider, 'subtheme')) {
+ $themes = $subthemes;
+ }
+ }
+ }
+
+ foreach($types as $type){
+ $providers = _emfield_generic_system_list($module,$type);
+ foreach ($providers as $provider) {
+ if ($subthemes = _emfield_generic_include_invoke($module,$type,$provider->name, 'emfield_subtheme')) {
+ $themes += $subthemes;
+ }
+ }
+ }
+ }
+ else {
+
+ if ($provider && $subthemes = emfield_include_invoke($module, $provider, 'subtheme')) {
+ $themes = $subthemes;
+ }
+ $providers = module_invoke('emfield', 'system_list', $module);
+
+ foreach ($providers as $provider) {
+ if ($subthemes = emfield_include_invoke($module, $provider->name, 'emfield_subtheme')) {
+ $themes += $subthemes;
+ }
+ }
+ }
+ return $themes;
+}
Index: contrib/emfield_generic/providers/emvideo/dailymotion.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/dailymotion.inc
diff -N contrib/emfield_generic/providers/emvideo/dailymotion.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/dailymotion.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,182 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+function emvideo_dailymotion_info() {
+ $features = array(
+ array(t('Autoplay'), t('Yes'), ''),
+ array(t('RSS Attachment'), t('No'), ''),
+ array(t('Thumbnails'), t('No'), t('')),
+ );
+ return array(
+ 'provider' => 'dailymotion',
+ 'name' => t('Dailymotion'),
+ 'url' => EMVIDEO_DAILYMOTION_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from Dailymotion.', array('@dailymotion' => EMVIDEO_DAILYMOTION_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_settings
+ * this should return a subform to be added to the emvideo_settings() admin settings page.
+ * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['dailymotion'])
+ * so if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emvideo_dailymotion_settings() {
+ $form = array();
+ return $form;
+}
+
+/**
+ * hook emvideo_PROVIDER_extract
+ * this is called to extract the video code from a pasted URL or embed code.
+ * @param $embed
+ * an optional string with the pasted URL or embed code
+ * @return
+ * either an array of regex expressions to be tested, or a string with the video code to be used
+ * if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array.
+ * otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
+ */
+function emvideo_dailymotion_extract($embed = '') {
+ // http://www.dailymotion.com/us/cluster/news/featured/video/x3xk8v_primary-smackdown-obama-girl-return_fun
+ // http://www.dailymotion.com/barelypolitical/video/x3xk8v_primary-smackdown-obama-girl-return_fun
+ // http://www.dailymotion.com/barelypolitical/video/x3xk8v
+ //
+// if (preg_match('@dailymotion\.com@i', $embed, $matches)) {
+// if (preg_match('@/([^/_]+)_@i', $embed, $matches)) {
+// return $matches[0];
+// }
+// }
+ if (preg_match('@dailymotion\.com/swf/([^"\&]+)@i', $embed, $matches)) {
+ return $matches[1];
+ }
+ if (preg_match('@dailymotion\.com@i', $embed, $matches)) {
+ if (preg_match('@/([^/_]+)_@i', $embed, $matches)) {
+ return $matches[1];
+ }
+ }
+ return array();
+}
+
+/**
+ * hook emvideo_PROVIDER_embedded_link($video_code)
+ * returns a link to view the video at the provider's site
+ * @param $video_code
+ * the string containing the video to watch
+ * @return
+ * a string containing the URL to view the video at the original provider's site
+ */
+function emvideo_dailymotion_embedded_link($video_code) {
+ return 'http://www.dailymotion.com/swf/'. $video_code;
+}
+
+/**
+ * the embedded flash displaying the dailymotion video
+ */
+function theme_emvideo_dailymotion_flash($embed, $width, $height, $autoplay) {
+ if ($embed) {
+ if ($autoplay) {
+ $autoplay_value = '&autoStart=1';
+ }
+ $output .= " \n";
+ }
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_thumbnail
+ * returns the external url for a thumbnail of a specific video
+ * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
+ * @param $field
+ * the field of the requesting node
+ * @param $item
+ * the actual content of the field from the requesting node
+ * @return
+ * a URL pointing to the thumbnail
+ */
+function emvideo_dailymotion_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return 'http://www.dailymotion.com/thumbnail/160x120/video/'. $item['value'];
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the full/normal-sized video we want, usually on the default page view
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_dailymotion_video($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_dailymotion_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the preview-sized video we want, commonly for the teaser
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_dailymotion_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_dailymotion_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_dailymotion_emfield_subtheme() {
+ return array(
+ 'emvideo_dailymotion_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL),
+ 'file' => 'providers/emvideo/dailymotion.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emimage/imageshack.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emimage/imageshack.inc
diff -N contrib/emfield_generic/providers/emimage/imageshack.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emimage/imageshack.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,123 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+
+function emimage_imageshack_info() {
+ $features = array();
+ return array(
+ 'provider' => 'imageshack',
+ 'name' => t('ImageShack'),
+ 'url' => EMIMAGE_IMAGESHACK_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect images displayed from ImageShack.', array('@imageshack' => EMIMAGE_IMAGESHACK_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+function emimage_imageshack_data($field, $item) {
+ $data = array();
+
+ $url = stristr($item['embed'], 'my.php?image=')? _emimage_imageshack_scrape_image_url($item['embed']) : $item['embed'];
+ if (preg_match('!([^/.:@]+)\.imageshack\.us/([^/]+)/([^/]+)/(.+)$!i', $url, $matches)) {
+ $data = array(
+ 'server' => $matches[1],
+ 'a1' => $matches[2],
+ 'a2' => $matches[3],
+ 'file' => $matches[4],
+ 'title' => '',
+ );
+ }
+ return $data;
+}
+
+function emimage_imageshack_extract($embed = '') {
+ // http://img255.imageshack.us/my.php?image=dscn0036ky1.jpg
+ // http://img255.imageshack.us/img255/7682/dscn0036ky1.jpg
+ if (preg_match('!([^/.:@]+)\.imageshack\.us/(([^/]+)/([^/]+)/|my.php\?image=)?(.+)$!i', $embed, $matches)) {
+ return $matches[5];
+ }
+
+ return array();
+}
+
+/**
+ * hook emimage_PROVIDER_embedded_link($code)
+ * returns a link to view the content at the provider's site
+ * @param $code
+ * the string containing the content to watch
+ * @return
+ * a string containing the URL to view the image at the original provider's site
+ */
+function emimage_imageshack_embedded_link($code, $data) {
+ return "http://{$data['server']}.imageshack.us/my.php?image={$code}";
+}
+
+/**
+ * implement emimage_PROVIDER_image_url
+ *
+ * @param $code
+ * the code of the image
+ * @param $data
+ * any stored data for the image, which may already have the title
+ * @return
+ * the url directly to the image to display
+ */
+function emimage_imageshack_image_url($code, $data) {
+ if (func_num_args() == 7) {
+ $arg = func_get_arg(5);
+ $code = &$arg['data']['file'];
+ $data = &$arg['data'];
+ }
+ return "http://{$data['server']}.imageshack.us/{$data['a1']}/{$data['a2']}/{$code}";
+}
+
+/**
+ * implement emimage_PROVIDER_image_title
+ *
+ * @param $code
+ * the code of the image
+ * @param $data
+ * any stored data for the image, which may already have the title
+ * @return
+ * the title as the 3rd party provider knows it, if accessible to us. otherwise, ''
+ */
+function emimage_imageshack_image_title($code, $data) {
+ return ''; // Not provided by on ImageShack.
+}
+
+/**
+ * Scrape the actual image URL from the ImageShack page.
+ *
+ * @param String $url
+ * ImageShack page.
+ * @return String
+ * ImageShack image URL.
+ */
+function _emimage_imageshack_scrape_image_url($url) {
+ static $urls;
+ if (isset($urls[$url])) {
+ return $urls[$url];
+ }
+
+ $html = file_get_contents($url);
+ if (preg_match('! 'imeem',
+ 'name' => t('IMEEM'),
+ 'url' => EMVIDEO_IMEEM_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from IMEEM. You can learn more about its API here.', array('@imeem' => EMVIDEO_IMEEM_MAIN_URL, '@api' => EMVIDEO_IMEEM_API_INFO)),
+ 'supported_features' => $features,
+ );
+}
+
+function emvideo_imeem_settings() {
+ $form['imeem']['api'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('IMEEM API'),
+ '#description' => t('If you wish to be able to display IMEEM thumbnails automatically, you will first need to apply for an API Developer Key from the IMEEM Developer Profile page. Note that you do not need this key to display IMEEM videos themselves.', array('@imeem' => EMVIDEO_IMEEM_API_APPLICATION_URL)),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['imeem']['api']['emvideo_imeem_api_key'] = array(
+ '#type' => 'textfield',
+ '#title' => t('IMEEM API Key'),
+ '#default_value' => variable_get('emvideo_imeem_api_key', ''),
+ '#description' => t('Please enter your IMEEM Developer Key here.'),
+ );
+ $form['imeem']['api']['emvideo_imeem_api_secret'] = array(
+ '#type' => 'textfield',
+ '#title' => t('IMEEM API Secret'),
+ '#default_value' => variable_get('emvideo_imeem_api_secret', ''),
+ '#description' => t('If you have a secret for the IMEEM API, enter it here.'),
+ );
+ return $form;
+}
+
+function emvideo_imeem_request($embed, $cacheable = TRUE) {
+ $args = array('docid' => $embed);
+ return module_invoke('emfield', 'request_xml', 'imeem', EMVIDEO_IMEEM_XML . $embed .'&version=1.0', $args, $cacheable);
+}
+
+function emvideo_imeem_extract($embed = '') {
+ return array(
+ '@http://media\.imeem\.com/[a-z]{1,2}/([^"\?/]+)/@i',
+ );
+}
+
+function emvideo_imeem_embedded_link($video_code) {
+ return 'http://www.imeem.com/v/'. $video_code;
+}
+
+function theme_emvideo_imeem_flash($embed, $width, $height, $autoplay) {
+ $autoplay = $autoplay ? '/aus=true' : '/aus=false';
+ $colors = 'backColor=666666&primaryColor=cccccc&secondaryColor=333333&linkColor=cccccc';
+
+ $output .= '';
+ return $output;
+}
+
+function emvideo_imeem_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ $xml = emvideo_imeem_request($item['value']);
+ $tmpthm = $xml['ITEM']['ICONURL'][0];
+ $imgmax = $xml['ITEM']['DURATION'][0];
+ $formatnum = str_pad(rand(0, $imgmax) .'.jpg', 9, "0", STR_PAD_LEFT);;
+ $thm = str_replace('00010.jpg', $formatnum, $tmpthm);
+ return $thm;
+}
+
+function emvideo_imeem_video($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_imeem_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+function emvideo_imeem_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_imeem_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+function emvideo_imeem_emfield_subtheme() {
+ return array(
+ 'emvideo_imeem_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL),
+ 'file' => 'providers/emvideo/imeem.inc'
+ )
+ );
+}
Index: emfield.cck.inc
===================================================================
RCS file: emfield.cck.inc
diff -N emfield.cck.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ emfield.cck.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,245 @@
+ array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'not null' => FALSE, 'sortable' => TRUE),
+ // this contains the code used by the provider to identify the media
+ 'value' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'not null' => FALSE, 'sortable' => TRUE),
+ // this is the actual provider used; matches up with the specific provider.inc file
+ 'provider' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'not null' => FALSE, 'sortable' => TRUE),
+ // an array for any extra data required by this media, such as unique thumbnail requirements or rss feed data
+ 'data' => array('type' => 'text', 'size' => 'big', 'not null' => TRUE, 'not null' => FALSE, 'sortable' => FALSE),
+ );
+ // allow other modules to add new columns
+ // TODO: couldn't we just use module_invoke_all here? also make sure those modules do their magic on enable/disable
+ // finally, is this actually used? seems extraneous with the data array (unless we're using views magic for them)
+ foreach (module_implements('emfield_field_columns_extra') as $module) {
+ $extra = module_invoke($module, 'emfield_field_columns_extra', $field);
+ if (is_array($extra) && !empty($extra)) {
+ $columns = array_merge($columns, $extra);
+ }
+ }
+
+ return $columns;
+}
+
+/**
+ * Implementation of hook_emfield_field().
+ *
+ * This private function is returned directly by emfield_emfield_field().
+ */
+function _emfield_emfield_field($op, &$node, $field, &$items, $teaser, $page, $module) {
+ switch ($op) {
+ // TODO: Nothing to validate at the moment. We need to have different provider api's have a chance to validate.
+ case 'validate':
+ foreach ($items as $delta => $item) {
+ $error_field = $field['multiple'] ? $field['field_name'] .']['. $delta .'][embed' : $field['field_name'];
+ _emfield_field_validate_id($field, $item, $error_field, $module, $delta);
+ }
+ break;
+
+ case 'presave':
+ foreach ($items as $delta => $item) {
+ $list = _emfield_field_submit_id($field, $item, $module);
+ $items[$delta]['provider'] = $list['provider'];
+ $items[$delta]['value'] = $list['value'];
+ $items[$delta]['data'] = $list['data'];
+ }
+ break;
+
+ case 'load':
+ // We need to unserialize the 'data' column manually.
+ $field_name = $field['field_name'];
+ foreach ($items as $delta => $item) {
+ $data = (array)unserialize($items[$delta]['data']);
+ $items[$delta]['data'] = $data;
+ $node->{$field_name}[$delta]['data'] = $data;
+ }
+
+ $return = array();
+ $return[$field_name] = $items;
+ break;
+
+ case 'delete':
+ break;
+ }
+ // Allow modules (such as emthumb) to alter our data.
+ foreach (module_implements('emfield_field_extra') as $module) {
+ $args = array($op, &$node, $field, &$items, $teaser, $page, $module);
+ $ret = call_user_func_array($module .'_emfield_field_extra', $args);
+ if (is_array($return) && is_array($ret)) {
+ $return = array_merge($return, $ret);
+ }
+ }
+ if (in_array($op, array('insert', 'update'))) {
+ // we need to manually serialize the 'data' array
+ foreach ($items as $delta => $item) {
+ $items[$delta]['data'] = serialize($items[$delta]['data']);
+ }
+ }
+ if (isset($return)) {
+ return $return;
+ }
+}
+
+function _emfield_emfield_widget_settings($op, $widget, $module) {
+ switch ($op) {
+ case 'form':
+ // Make sure to register the new type as supported by this module.
+ emfield_implement_types(FALSE);
+
+ $form = array();
+ $options = array();
+ $providers = emfield_system_list($module);
+ foreach ($providers as $provider) {
+ if (variable_get('emfield_'. $module . '_allow_'. $provider->name, FALSE)) {
+ $info = emfield_include_invoke($module, $provider->name, 'info');
+ $options[$provider->name] = $info['name'];
+ }
+ }
+ $form['provider_list'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Providers Supported'),
+ '#description' => t('Select which third party providers you wish to allow for this content type from the list below. If no checkboxes are checked, then all providers will be supported. When a user submits new content, the URL they enter will be matched to the provider, assuming that provider is allowed here.'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+ $form['provider_list']['providers'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Providers'),
+ '#default_value' => empty($widget['providers']) ? array() : $widget['providers'],
+ '#options' => $options,
+ );
+
+ foreach (module_implements('emfield_widget_settings_extra') as $module) {
+ $form[$module] = module_invoke($module, 'emfield_widget_settings_extra', 'form', $widget);
+ }
+
+ return $form;
+
+ case 'save':
+ $columns = array('providers'); //, 'helper_module', );
+ foreach (module_implements('emfield_widget_settings_extra') as $module) {
+ $columns = array_merge($columns, module_invoke($module, 'emfield_widget_settings_extra', 'save', $widget));
+ }
+
+ return $columns;
+ }
+}
+
+
+/**
+ * This creates default widget handling for all the Embedded Media Fields.
+ * Helper modules are expected to call this function to create the widget,
+ * which will include a list of all providers as well as handle data parsing.
+ */
+function _emfield_emfield_widget(&$form, &$form_state, $field, $items, $delta = 0, $module) { //($op, &$node, $field, &$node_field, $module) {
+ // Our form element will need to be processed as a tree, collapsing any children elements.
+ $tree = array('#tree' => TRUE);
+
+ $urls = array();
+ if($module == "emfield_generic"){
+ $types = array("emaudio","emimage","emvideo");
+ $widget = $field['widget'];
+ foreach($types as $type){
+ $type_str = substr($type,2);
+
+ $providers = _emfield_generic_system_list($module,$type);
+
+ foreach ($providers as $provider) {
+ //Only list providers allowed for this field. Honor global settings first. and local cck field settings
+
+ if (variable_get('emfield_'. $module . '_allow_'. $provider->name, FALSE) && $widget['providers_' . $type_str][$provider->name]) {
+ //Get the provider info.
+ $function = "_emfield_generic_include_invoke";
+ $args = array($module,$type,$provider->name, 'info');
+ $info = call_user_func_array($function, $args);
+ // Grab the provider's URL.
+ $urls[] = l($info['name'], $info['url'], array('target' => '_blank'));
+ // Allow the module to add any additional elements to the form, based on individual provider needs.
+ $additional_element = emfield_include_invoke($module, $provider->name, 'form');
+ if ($additional_element) {
+ $additional_form_elements[$provider->name] = $additional_element;
+ }
+ }
+ }
+ }
+ }
+ else
+ {
+ $providers = emfield_allowed_providers($field, $module);
+ $additional_form_elements = array();
+
+ foreach ($providers as $provider) {
+ // Only list providers allowed for this field. Honor global settings first.
+ if (variable_get('emfield_'. $module .'_allow_'. $provider->name, TRUE)) {
+ // Get the provider info.
+ $info = emfield_include_invoke($module, $provider->name, 'info');
+ // Grab the provider's URL.
+ $urls[] = l($info['name'], $info['url'], array('target' => '_blank'));
+ // Allow the module to add any additional elements to the form, based on individual provider needs.
+ $additional_element = emfield_include_invoke($module, $provider->name, 'form');
+ if ($additional_element) {
+ $additional_form_elements[$provider->name] = $additional_element;
+ }
+ }
+ }
+ }
+
+ // Set the widget description, but allow the field to override this.
+ if (!(empty($field['widget']['description']))) {
+ $textfield_description = $field['widget']['description'];
+ }
+ else {
+ $textfield_description = t('Enter the URL or Embed Code here. The embedded third party content will be parsed and displayed appropriately from this.');
+ }
+
+ // Add a list of all supported third party providers.
+ $textfield_description .= ' '. t('The following services are provided: !urls', array('!urls' => implode(', ', $urls)));
+ // Get the value of our data, if it's been set for this node.
+ $value = isset($items[$delta]['embed']) ? $items[$delta]['embed'] : '';
+ $tree['embed'] = array(
+ '#type' => 'textfield',
+ '#title' => t($field['widget']['label']),
+ '#description' => $textfield_description,
+ '#default_value' => $value,
+ '#required' => $field['required'],
+ '#maxlength' => 2048,
+ );
+
+ $tree['value'] = array(
+ '#type' => 'value',
+ '#value' => $value,
+ );
+
+ if (!empty($additional_form_elements)) {
+ foreach ($additional_form_elements as $key => $element) {
+ $tree[$key] = $element;
+ }
+ }
+
+ if ($value) {
+ $info = emfield_include_invoke($module, $items[$delta]['provider'], 'info');
+ $tree['value_markup'] = array(
+ '#type' => 'item',
+ '#value' => t('(@provider ID: !value)', array('@provider' => $info['provider'], '!value' => l($value, emfield_include_invoke($module, $info['provider'], 'embedded_link', $value, $items[$delta]['data']), array('target' => '_blank')))),
+ );
+ }
+
+ // Allow other modules, such as Embedded Media Thumbnail, to add additional elements to the widget.
+ foreach (module_implements('emfield_widget_extra') as $module_extra) {
+ $tree[$module_extra] = module_invoke($module_extra, 'emfield_widget_extra', 'form', $form, $field, $items[$delta]);
+ }
+
+ return $tree;
+}
Index: contrib/emfield_generic/emfield_generic.theme.inc
===================================================================
RCS file: contrib/emfield_generic/emfield_generic.theme.inc
diff -N contrib/emfield_generic/emfield_generic.theme.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/emfield_generic.theme.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,97 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+function emaudio_podomatic_info() {
+ $features = array(
+ array(t('Autoplay'), t('No'), ''),
+ array(t('RSS Attachment'), t('No'), ''),
+ array(t('Thumbnails'), t('No'), t('')),
+ );
+ return array(
+ 'provider' => 'podomatic',
+ 'name' => t('podOmatic'),
+ 'url' => EMAUDIO_PODOMATIC_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect audio podcasts displayed from podOmatic.', array('@podomatic' => EMAUDIO_PODOMATIC_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+/**
+ * hook emaudio_PROVIDER_settings
+ * this should return a subform to be added to the emaudio_settings() admin settings page.
+ * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['podomatic'])
+ * so if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emaudio_podomatic_settings() {
+ $form = array();
+ return $form;
+}
+
+/**
+ * hook emaudio_PROVIDER_extract
+ * this is called to extract the video code from a pasted URL or embed code.
+ * @param $embed
+ * an optional string with the pasted URL or embed code
+ * @return
+ * either an array of regex expressions to be tested, or a string with the audio code to be used
+ * if the hook tests the code itself, it should return either the string of the audio code (if matched), or an empty array.
+ * otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
+ */
+function emaudio_podomatic_extract($embed = '') {
+ // http://www.podomatic.com/podcast/embed/funkylondon
+ // Click here to get your own player.
+ // http://funkylondon.podomatic.com
+ return array(
+ '@podomatic\.com/podcast/embed/([^"\&]+)@i',
+ '@playlist_url\=http://([^\.]+)\.podOmatic\.com@i',
+ '@http://([^\.]+)\.podomatic\.com@i',
+ );
+}
+
+/**
+ * hook emaudio_PROVIDER_embedded_link($audio_code)
+ * returns a link to view the audio at the provider's site
+ * @param $audio_code
+ * the string containing the audio to watch
+ * @return
+ * a string containing the URL to view the audio at the original provider's site
+ */
+function emaudio_podomatic_embedded_link($audio_code) {
+ return 'http://www.podomatic.com/podcast/embed/'. $audio_code;
+}
+
+/**
+ * hook theme_emaudio_PROVIDER_flash
+ * the embedded flash displaying the podomatic audio
+ */
+
+function theme_emaudio_podomatic_flash($code, $width, $height, $field, $item, $autoplay, $flv, $thumbnail, $options = array()) {
+ // Click here to get your own player.
+
+ if ($code) {
+/* if ($autoplay) {
+ $autoplay_value = '&autostart=1';
+ }*/
+ $output .=
+ '\n';
+ }
+ return $output;
+}
+
+/**
+ * hook emaudio_PROVIDER_thumbnail
+ * returns the external url for a thumbnail of a specific audio
+ * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
+ * @param $field
+ * the field of the requesting node
+ * @param $item
+ * the actual content of the field from the requesting node
+ * @return
+ * a URL pointing to the thumbnail
+ */
+function emaudio_podomatic_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return $tn;
+}
+
+/**
+ * hook emaudio_PROVIDER_audio
+ * this actually displays the full/normal-sized video we want, usually on the default page view
+ * @param $embed
+ * the video code for the audio to embed
+ * @param $width
+ * the width to display the audio
+ * @param $height
+ * the height to display the audio
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded audio
+ */
+function emaudio_podomatic_audio($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emaudio_podomatic_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+/**
+ * hook emaudio_PROVIDER_preview
+ * this actually displays the preview-sized video we want, commonly for the teaser
+ * @param $embed
+ * the video code for the audio to embed
+ * @param $width
+ * the width to display the audio
+ * @param $height
+ * the height to display the audio
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded audio
+ */
+function emaudio_podomatic_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emaudio_podomatic_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emaudio_podomatic_subtheme() {
+ return array (
+ 'emaudio_podomatic_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL),
+ 'file' => 'providers/podomatic.inc'
+ )
+ );
+}
+
Index: contrib/emfield_generic/providers/emvideo/sevenload.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/sevenload.inc
diff -N contrib/emfield_generic/providers/emvideo/sevenload.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/sevenload.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,144 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ */
+function emvideo_sevenload_info() {
+ $features = array(
+ array(t('Autoplay'), t('No'), ''),
+ array(t('RSS Attachment'), t('No'), ''),
+ array(t('Thumbnails'), t('No'), ''),
+ );
+ return array(
+ 'provider' => 'sevenload',
+ 'name' => t('Sevenload'),
+ 'url' => EMVIDEO_SEVENLOAD_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from Sevenload.', array('@provider' => EMVIDEO_SEVENLOAD_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_settings
+ * this should return a subform to be added to the emvideo_settings() admin settings page.
+ * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['youtube'])
+ * so if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emvideo_sevenload_settings() {
+ $form = array();
+ return $form;
+}
+
+/**
+ * hook emvideo_PROVIDER_extract
+ * this is called to extract the video code from a pasted URL or embed code.
+ * @param $embed
+ * an optional string with the pasted URL or embed code
+ * @return
+ * either an array of regex expressions to be tested, or a string with the video code to be used
+ * if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array.
+ * otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
+ */
+function emvideo_sevenload_extract($embed = '') {
+ // src="http://de.sevenload.com/pl/zuh5KMt"
+ // http://de.sevenload.com/videos/zuh5KMt/Die-Zeit-rennt
+ // hint: de.sevenload.com can also be en.sevenload.com and probably other languages later
+ return array(
+ '@sevenload\.com/pl/([^"]*)"@i',
+ '@sevenload\.com/videos/(.*)/(.*)@i',
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_video_link($video_code)
+ * returns a link to view the video at the provider's site
+ * @param $video_code
+ * the string containing the video to watch
+ * @return
+ * a string containing the URL to view the video at the original provider's site
+ */
+function emvideo_sevenload_video_link($video_code) {
+ return 'http://www.sevenload.com/videos/'. $video_code;
+}
+
+function emvideo_sevenload_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return '';
+}
+
+/**
+ * the embedded flash displaying the Sevenload video
+ */
+function theme_emvideo_sevenload_flash($embed, $width, $height) {
+ if ($embed) {
+ $output .= "";
+ }
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the full/normal-sized video we want, usually on the default page view
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_sevenload_video($embed, $width, $height, $field, $item) {
+ $output = theme('emvideo_sevenload_flash', $embed, $width, $height);
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the preview-sized video we want, commonly for the teaser
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_sevenload_preview($embed, $width, $height, $field, $item) {
+ $output = theme('emvideo_sevenload_flash', $embed, $width, $height);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_sevenload_emfield_subtheme() {
+ return array(
+ 'emvideo_sevenload_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL),
+ 'file' => 'providers/emvideo/sevenload.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emvideo/spike.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/spike.inc
diff -N contrib/emfield_generic/providers/emvideo/spike.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/spike.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,88 @@
+ 'spike tv',
+ 'name' => t('Spike TV'),
+ 'url' => EMVIDEO_SPIKE_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from Spike TV.', array('@spike' => EMVIDEO_SPIKE_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+function emvideo_spike_settings() {
+ $form = array();
+ return $form;
+}
+
+function emvideo_spike_extract($embed) {
+ return array(
+ // http://www.spike.com/video/2836119/collection/19459/channel/comedy
+ //
+ // http://www.livevideo.com/video/591C1350DD174FE0B10C4DCFC88981DA/mascot-bloopers-video.aspx
+ // NOTE: the order of the following matters very much in this case...
+ return array(
+ '@livevideo\.com/flvplayer/embed/([^\"]*)\"@i',
+ '@livevideo\.com/video/([^/]*)/@i',
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_embedded_link($video_code)
+ * returns a link to view the video at the provider's site
+ * @param $video_code
+ * the string containing the video to watch
+ * @return
+ * a string containing the URL to view the video at the original provider's site
+ */
+function emvideo_livevideo_embedded_link($video_code) {
+ $method = 'GetVideoDetails.ashx';
+ $args = array('videoId' => $video_code);
+ $request = emvideo_livevideo_request($method, $args);
+ $url = $request['VIDEODETAILS']['VIEWURL'][0];
+ return $url;
+}
+
+/**
+ * the embedded flash displaying the livevideo video
+ */
+function theme_emvideo_livevideo_flash($embed, $width, $height, $autoplay) {
+ if ($embed) {
+ $autostart = $autoplay ? '&autoStart=1' : '';
+ $output .= '';
+ }
+
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_thumbnail
+ * returns the external url for a thumbnail of a specific video
+ * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
+ * @param $field
+ * the field of the requesting node
+ * @param $item
+ * the actual content of the field from the requesting node
+ * @return
+ * a URL pointing to the thumbnail
+ */
+function emvideo_livevideo_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ $method = 'GetVideoDetails.ashx';
+ $args = array('videoId' => $item['value']);
+ $request = emvideo_livevideo_request($method, $args);
+ $tn = $request['VIDEODETAILS']['DEFAULTTHUMBNAIL'][0];
+
+ return $tn;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the full/normal-sized video we want, usually on the default page view
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_livevideo_video($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_livevideo_flash', $embed, $width, $height, $autoplay);
+
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the preview-sized video we want, commonly for the teaser
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_livevideo_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_livevideo_flash', $embed, $width, $height, $autoplay);
+
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_livevideo_emfield_subtheme() {
+ return array(
+ 'emvideo_livevideo_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL),
+ 'file' => 'providers/emvideo/livevideo.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emimage/picasa.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emimage/picasa.inc
diff -N contrib/emfield_generic/providers/emimage/picasa.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emimage/picasa.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,161 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+
+function emimage_picasa_info() {
+ $features = array(
+ array(t('Import photosets'), t('No'), ''),
+ );
+ return array(
+ 'provider' => 'picasa',
+ 'name' => t('Picasa'),
+ 'url' => EMIMAGE_PICASA_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect images displayed from Picasa.', array('@picasa' => EMIMAGE_PICASA_MAIN_URL)),
+ 'supported_features' => $features,
+ 'import_sets_word' => t('photosets'),
+ );
+}
+
+/**
+ * This is a wrapper for image_cck_request_xml.
+ */
+function emimage_picasa_request($data = array(), $kind = '', $cached = TRUE) {
+ $args['kind'] = $kind;
+ $xml = module_invoke('emfield', 'request_xml', 'picasa', EMIMAGE_PICASA_REST_ENDPOINT ."{$data['userid']}/album/{$data['album']}/photoid/{$data['photoid']}", $args, $cached, FALSE, ":{$data['userid']}:{$data['album']}?{$data['photoid']}");
+
+ return $xml;
+}
+
+function emimage_picasa_data($field, $item) {
+ $data = array();
+ if (preg_match('!picasaweb\.google\.com/([^/]*)/([^/]*)/photo\#(.*)!i', $item['embed'], $matches)) {
+ $data = array(
+ 'userid' => $matches[1],
+ 'album' => $matches[2],
+ 'photoid' => $matches[3],
+ );
+ }
+ // use the page id, since we'll have that in most cases (except in embed pastes, which gets parsed during extraction)
+ // we use this to get an rss feed w/ all the info for the image. interesting reading ;)
+ $xml = emimage_picasa_request($data, 'tag');
+
+ $data['title'] = $xml['MEDIA:GROUP']['MEDIA:DESCRIPTION'][0];
+ $data['original'] = $xml['MEDIA:GROUP']['MEDIA:CONTENT'][1][URL];
+ $data['small'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][1][URL];
+ $data['medium'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][3][URL];
+ $data['large'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][5][URL];
+ $data['width'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][5][WIDTH];
+ $data['height'] = $xml['MEDIA:GROUP']['MEDIA:THUMBNAIL'][5][HEIGHT];
+
+ return $data;
+}
+
+function emimage_picasa_extract($embed = '') {
+ // http://picasaweb.google.com/kaos777/YearlyKos/photo#5119063656501095090
+ if (preg_match('!picasaweb\.google\.com/([^/]*)/([^/]*)/photo\#(.*)!i', $embed, $matches)) {
+ return $matches[3];
+ }
+
+ return array();
+}
+
+/**
+ * hook emimage_PROVIDER_embedded_link($code)
+ * returns a link to view the content at the provider's site
+ * @param $code
+ * the string containing the content to watch
+ * @return
+ * a string containing the URL to view the image at the original provider's site
+ */
+function emimage_picasa_embedded_link($code, $data) {
+ $userid = $data['userid'];
+ $album= $data['album'];
+ $photoid= $data['photoid'];
+
+ return "http://picasaweb.google.com/$userid/$album/photo#$photoid";
+}
+
+/**
+ * Implement emimage_PROVIDER_image_url.
+ *
+ * @param $code
+ * the code of the image
+ * @param $data
+ * any stored data for the image, which may already have the url of the image to display
+ * @return
+ * the url directly to emfield for the image to display
+ */
+function emimage_picasa_image_url($code, $width, $height, $formatter, $field, $item, $node) {
+ if (func_num_args() == 7) {
+ $arg = func_get_arg(5);
+ $code = &$arg['data']['original'];
+ $data = &$arg['data'];
+ $size = _emimage_picasa_guess_size($width, $height);
+ }
+ //http://lh5.google.com/kaos777/RwqRRgxcKrI/AAAAAAAAAB0/pl5FboT6x2M/IMG_0468.JPG
+ if (preg_match ('!([^/]*)\.ggpht\.com/([^/]*)/([^/]*)/([^/]*)/([^/]*)/(.*)!i', $code, $matches)) {
+ $info = array(
+ 'server' => $matches[1],
+ 'userid' => $matches[2],
+ 's1' => $matches[3],
+ 's2' => $matches[4],
+ 's3' => $matches[5],
+ 'image' => $matches[6],
+ );
+ }
+
+ return "http://{$info['server']}.google.com/{$info['userid']}/{$info['s1']}/{$info['s2']}/{$info['s3']}/s$size/{$info['image']}";
+}
+
+/**
+ * Implement emimage_PROVIDER_image_title.
+ *
+ * @param $code
+ * The code of the image.
+ * @param $data
+ * Any stored data for the image, which may already have the title.
+ * @return
+ * The title as the 3rd party provider knows it, if accessible to us. otherwise, ''.
+ */
+function emimage_picasa_image_title($code, $data) {
+ if (func_num_args() == 7) {
+ $arg = func_get_arg(5);
+ $code = &$arg['data']['title'];
+ $data = &$arg['data'];
+ $title = $code;
+ }
+
+ return "$title";
+}
+
+function _emimage_picasa_guess_size($width, $height) {
+ $max = max($width, $height);
+ foreach (array('144' => 144, '288' => 288, '400' => 400, '800' => 800) as $size => $value) {
+ if ($max <= $value) {
+ return $size;
+ }
+ }
+
+ // we would use the original size if we could, but we can't since google won't serve it
+ return '800';
+}
Index: contrib/emfield_generic/providers/emvideo/myspace.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/myspace.inc
diff -N contrib/emfield_generic/providers/emvideo/myspace.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/myspace.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,125 @@
+ 'myspace',
+ 'name' => t('MySpace'),
+ 'url' => EMVIDEO_MYSPACE_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from MySpace.', array('@provider' => EMVIDEO_MYSPACE_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+function emvideo_myspace_settings() {
+ $form = array();
+ return $form;
+}
+
+function emvideo_myspace_request($code, $cacheable = TRUE) {
+ $args = array();
+ return module_invoke('emfield', 'request_xml', 'myspace', "http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=$code", $args, $cacheable);
+}
+
+/**
+ * this scrapes the thumbnail from the video page and caches it
+ */
+function _emvideo_myspace_scrape_thumbnail($video, $cached = TRUE) {
+ if (!$cached || !$cache = cache_get('myspace:thumbnail:'. $video, 'cache')) {
+ $vidid = drupal_substr($video, 0, 10);
+
+ if ($str = file_get_contents("http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=$vidid")) {
+ // grab videos channel-id first
+ $channel_id = preg_replace('/.*tvchanid=([0-9]+);.*/si', '\1', $str);
+
+ if (is_numeric($channel_id)) {
+ // now from channel-page grab videos thumbnail
+ $str2 = file_get_contents("http://vids.myspace.com/index.cfm?fuseaction=vids.viewVideos&channelid=$channel_id");
+
+ if ($str2) {
+ $picturelink = preg_replace('@.*href="[^"]+'. $vidid .'"[^>]+>]+src="([^"]+)".*@si', '\1', $str2);
+
+ if ($picturelink) {
+ $thumbnail = $picturelink;
+ cache_set('myspace:thumbnail:'. $video, $thumbnail, 'cache', time() + 3600);
+ }
+ }
+ }
+ }
+ }
+ else {
+ $thumbnail = $cache->data;
+ }
+
+ return $thumbnail;
+}
+
+function emvideo_myspace_extract($embed) {
+ // What's That Floating In The Water Part 1
Add to My Profile | More Videos
+ return array(
+ '@src="myspace\.com/index.cfm\?fuseaction=vids\.individual&videoid=([^&"]+)@i',
+ '@myspace\.com/index\.cfm\?fuseaction=vids\.individual&videoid=([^&"]+)@i',
+ '@src="myspacetv\.com/index.cfm\?fuseaction=vids\.individual&videoid=([^&"]+)"@i',
+ '@myspacetv\.com/index\.cfm\?fuseaction=vids\.individual&videoid=([^&"]+)@i',
+ );
+}
+
+function emvideo_myspace_video_link($video_code) {
+ return 'http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid='. $video_code;
+}
+
+function theme_emvideo_myspace_flash($embed, $width, $height) {
+ static $count = 0;
+ if ($embed) {
+ $output .= " \n";
+ }
+ $count++;
+ return $output;
+}
+
+function emvideo_myspace_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return _emvideo_myspace_scrape_thumbnail($item['value']);
+}
+
+function emvideo_myspace_video($embed, $width, $height, $field, $item) {
+ $output = theme('emvideo_myspace_flash', $embed, $width, $height);
+ return $output;
+}
+
+function emvideo_myspace_preview($embed, $width, $height, $field, $item) {
+ $output = theme('emvideo_myspace_flash', $embed, $width, $height);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_myspace_emfield_subtheme() {
+ return array(
+ 'emvideo_myspace_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL),
+ 'file' => 'providers/emvideo/myspace.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emvideo/bliptv.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/bliptv.inc
diff -N contrib/emfield_generic/providers/emvideo/bliptv.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/bliptv.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,316 @@
+ 'bliptv',
+ 'name' => t('Blip.tv'),
+ 'url' => EMVIDEO_BLIPTV_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from Blip.tv.', array('@provider' => EMVIDEO_BLIPTV_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+function emvideo_bliptv_settings() {
+ $tags = array('none' => t('No video'), 'flv' => t('Flash Video'), 'override' => t('Override tag'), 'web' => t('Web'), 'Web High Resolution' => t('Web High Resolution'), 'Portable (iPod)' => t('Portable (iPod)'), 'Portable (other)' => t('Portable (other)'), 'Television' => t('Television'), 'HDTV' => t('HDTV'), 'Cell Phone' => t('Cell Phone'), 'Source' => t('Source'));
+ $formats = array('none' => t('No video'), 'flv' => t('Flash video (flv)'), 'mov' => t('Quicktime Movie (mov)'), 'mp3' => t('MP3'), 'm4a' => t('m4a'), 'mpg' => t('MPEG'), 'mp4' => t('mp4'), 'm4v' => t('m4v'), 'wmv' => t('Windows Media (wmv)'));
+
+ $form = array();
+ $form['video_formats'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Video formats'),
+ '#description' => t("Blip.TV allows users to upload videos of various formats, sizes, and qualities. These options will allow the administrator to choose the default video formats to display. Blip.TV uses 'tags' to determine this, such as 'Web' for a standard web resolution, and 'HDTV' for a high definition. If you select a tag, then the video format provided by Blip.TV for that tag will be displayed. If you select 'Override tag', then you may specify that the first available video of the given format will be displayed instead, which may or may not have your desired resolution. If a tag or format is not available for a specific video, the module will display the Flash video format instead, which is always present."),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+ $form['video_formats']['rss'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('RSS'),
+ '#description' => t("This will determine the preferred video format for RSS feeds."),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+
+ $form['video_formats']['rss']['emvideo_bliptv_rss_tag'] = array(
+ '#type' => 'select',
+ '#title' => t('RSS full page tag'),
+ '#description' => t("When RSS feeds are displayed, and this tag is available for a video, then the clip for that tag will be displayed as an enclosure tag in the feed. Select 'Override tag' if you wish to control the format displayed. Select 'No video' if you do not wish a video to be displayed in RSS feeds."),
+ '#options' => $tags,
+ '#default_value' => variable_get('emvideo_bliptv_rss_tag', array(EMVIDEO_BLIPTV_DEFAULT_RSS_TYPE => EMVIDEO_BLIPTV_DEFAULT_RSS_TYPE)),
+ );
+ $form['video_formats']['rss']['emvideo_bliptv_rss_format'] = array(
+ '#type' => 'select',
+ '#title' => t('RSS full page format override'),
+ '#description' => t("When RSS feeds are displayed, and the 'Override tag' option is selected above, then this format will be displayed as an enclosure tag in the feed."),
+ '#options' => $formats,
+ '#default_value' => variable_get('emvideo_bliptv_rss_format', array(EMVIDEO_BLIPTV_DEFAULT_RSS_TYPE => EMVIDEO_BLIPTV_DEFAULT_RSS_TYPE)),
+ );
+ return $form;
+}
+
+function emvideo_bliptv_data($field, $item) {
+ $data = array();
+
+ // we added new data fields to keep from having to reload the api/rss
+ // because the data is only stored on update/insert, however, we have to know which data type we're using
+ // this will just be an integer, increased when we make a change to data
+ $data['emvideo_bliptv_data_version'] = 2;
+
+ // use the page id, since we'll have that in most cases (except in embed pastes, which gets parsed during extraction)
+ // we use this to get an rss feed w/ all the info for the video. interesting reading ;)
+ // some of our data we'll get from the api, like available files
+ $rss = emvideo_bliptv_request($item['value'], TRUE, 'rss');
+ $api = emvideo_bliptv_request($item['value'], TRUE, 'api');
+
+ // special handling for show/feature pages
+ // TODO: this is disabled for now.
+// if (empty($rss) && empty($api) && preg_match('@http\://([^\.]+)\.blip\.tv/@i', $item['embed'], $matches)) {
+// $show_rss = emvideo_bliptv_request($item['value'], TRUE, 'rss', TRUE);
+// $data['thumbnail']['url'] = $rss['IMAGE']['URL'][0];
+// $data['flv'] = array();
+// $data['showpage'] = "http://{$item['value']}.blip.tv/";
+// $data['is_show'] = TRUE;
+// return $data;
+// }
+
+ $data['is_show'] = FALSE;
+
+ // get our thumbnail url
+ $data['thumbnail']['url'] = $rss['ITEM']['MEDIA:THUMBNAIL'][1]['URL'];
+ // this gets sent to the player
+ foreach ((array)$api['MEDIA']['LINK'] as $x => $link) {
+ $x--;
+ $video_type = '';
+ switch ($link['TYPE']) {
+ case 'video/x-flv':
+ $video_type = 'flv';
+ break;
+ case 'video/x-m4v':
+ $video_type = 'm4v';
+ break;
+ case 'video/quicktime':
+ $video_type = 'mov';
+ break;
+ }
+ if ($video_type) {
+ $video_info = array();
+ $video_info['url'] = $link['HREF'];
+ $video_info['width'] = $api['MEDIA']['WIDTH'][$x];
+ $video_info['height'] = $api['MEDIA']['HEIGHT'][$x];
+ $video_info['duration'] = $api['MEDIA']['DURATION'][$x];
+ $video_info['size'] = $api['MEDIA']['SIZE'][$x];
+ $video_info['mime'] = $link['TYPE'];
+ $video_info['embed_code'] = $rss['ITEM']['BLIP:EMBEDLOOKUP'];
+
+ // we only store the last video of a particular type, for instance if two roles use .mov
+ $data[$video_type] = $video_info;
+
+ // however, we store the whole thing under role, so the information is still saved
+ // but our arrays may be out of synch...
+ $y = $x + 1;
+ if ($api['MEDIA']['ROLE'][$y]) {
+ $data[$video_type]['role'] = $api['MEDIA']['ROLE'][$y];
+ $data[$api['MEDIA']['ROLE'][$y]] = $video_info;
+ $data[$api['MEDIA']['ROLE'][$y]]['role'] = $api['MEDIA']['ROLE'][$y];
+ }
+ }
+ }
+ if (!$data['flv']) {
+ $data['flv'] = array();
+ }
+ if (!$data['flv']['url']) {
+ $data['flv']['url'] = $rss['ITEM']['ENCLOSURE'][1]['URL'];
+ }
+ $data['title'] = $api['en']['TITLE'][0] ? $api['en']['TITLE'][0] : $rss['2.0']['CHANNEL']['TITLE'][0];
+ $data['description'] = $api['en']['DESCRIPTION'][0] ? $api['en']['DESCRIPTION'][0] : $rss['ITEM']['BLIP:PUREDESCRIPTION'][0];
+ $data['blip_user']['uid'] = $api['CREATEDBY']['UID'][0] ? $api['CREATEDBY']['UID'][0] : $rss['ITEM']['BLIP:USERID'][0];
+ $data['blip_user']['username'] = $api['CREATEDBY']['LOGIN'][0] ? $api['CREATEDBY']['LOGIN'][0] : $rss['ITEM']['BLIP:USER'][0];
+ $data['blip_user']['url'] = $api['CREATEDBY']['LINKS']['LINK'][1] ? $api['CREATEDBY']['LINKS']['LINK'][1] : 'http://blip.tv/users/view/'. $data['blip_user']['username'];
+
+ $data['showpage'] = $rss['ITEM']['BLIP:SHOWPAGE'][0];
+ $data['embed_code'] = $rss['ITEM']['BLIP:EMBEDLOOKUP'];
+
+ // this is the code actually used by the player, even though it's different than for the page
+ if ($rss['ITEM']['BLIP:POSTS_ID'][0]) {
+ $data['post_id'] = $rss['ITEM']['BLIP:POSTS_ID'][0];
+ }
+ return $data;
+}
+
+function emvideo_bliptv_request($code, $cacheable = TRUE, $skin = 'rss', $show = FALSE) {
+ $args = array();
+ $file = $show ? "http://$code.blip.tv/file/?skin=" . $skin : "http://blip.tv/file/$code?skin=" . $skin;
+ return module_invoke('emfield', 'request_xml', 'bliptv', $file, $args, $cacheable, FALSE, $code .':'. $skin . ($show ? ':show' : ':post'));
+}
+
+function emvideo_bliptv_extract($embed) {
+ return array(
+ '@blip\.tv/rss/flash/([^"\&\?]+)@i',
+ '@blip\.tv/file/view/([^"\&\?]+)@i',
+ '@blip\.tv/file/([^"\&\?]+)@i',
+ '@blip\.tv/play/([^"\&\?]+)@i',
+
+ // test handling for featured shows. disabled for now.
+// '@http\://([^\.]+)\.blip\.tv/@i',
+ );
+}
+
+function emvideo_bliptv_video_link($video_code) {
+ return 'http://blip.tv/file/'. $video_code;
+}
+
+function _emvideo_bliptv_get_video_info_from_preferred_tag($data, $var) {
+ $preferred_tags = (array)variable_get($var, array(EMVIDEO_BLIPTV_DEFAULT_RSS_TYPE => EMVIDEO_BLIPTV_DEFAULT_RSS_TYPE));
+
+ foreach ($preferred_tags as $test_tag) {
+ // if we override the tag with a type, then break so it can be handled
+ if ($test_tag == 'override') {
+ $video_info = 'override';
+ break;
+ }
+
+ // if we have a clip of that format type, then return it
+ if ($data[$test_tag]['url']) {
+ $video_info = $data[$test_tag];
+ break;
+ }
+ }
+
+ return $video_info;
+}
+
+/**
+ * Providers may supply an enclosure for rss feeds. This expects something in a file format, so would be an object
+ * in the format of $file->filepath, $file->filesize, and $file->filemime. calls the providers hook emvideo_PROVIDER_rss.
+ */
+function emvideo_bliptv_rss($item, $teaser = NULL) {
+ if ($item['value']) {
+ if ($item['data']['emvideo_bliptv_data_version'] >= 1) {
+ $data = $item['data'];
+ }
+ else {
+ $data = emvideo_bliptv_data(NULL, $item);
+ }
+
+ // get the preferred type for the rss feed
+ $var = 'emvideo_bliptv_rss_tag';
+ $video_info = _emvideo_bliptv_get_video_info_from_preferred_tag($data, $var);
+
+ // grab the preferred filetype rather than tag, so .mov rather than 'web'
+ if ($video_info == 'override') {
+ $var = 'emvideo_bliptv_rss_format';
+ $video_info = _emvideo_bliptv_get_video_info_from_preferred_tag($data, $var);
+ }
+
+ // default to flv if there's no available clip format
+ if (is_null($video_info) || ($video_info == 'override') && $video_info != 'none') {
+ $video_info = $data['flv'];
+ }
+
+ if (is_array($video_info)) {
+ // Begin building file object.
+
+ $file = array();
+ // Create temporary name/path for newly uploaded files.
+ $file['filepath'] = $video_info['url'];
+ $file['filesize'] = $video_info['size'];
+ $file['filemime'] = $video_info['mime'];
+
+ // additional data for Y! MRSS
+ $file['thumbnail']['filepath'] = $data['thumbnail']['url'];
+ $file['width'] = ($video_info['width']) ? $video_info['width'] : 0;
+ $file['height'] = ($video_info['height']) ? $video_info['height'] : 0;
+ $file['duration'] = ($video_info['duration']) ? $video_info['duration'] : FALSE;
+ // @todo media:credit role="author" ...
+
+
+
+ }
+ }
+}
+
+function theme_emvideo_bliptv_flash($code, $width, $height, $field, $item, $autoplay, $flv, $thumbnail, $options = array()) {
+ static $count;
+ if ($code) {
+ $count++;
+ $id = isset($options['id']) ? $options['id'] : "emfield_videocck_player_bliptv_$count";
+ $autoplay = $autoplay ? 'autoStart=true' : 'autoStart=false';
+
+ $rss = $item['data']['showpage'] ? "&feedurl={$item['data']['showpage']}/rss" : '';
+ $post_id = $item['data']['post_id'];
+ // if/when we allow featured shows to be embedded, this will handle that.
+// $file = $item['data']['is_show'] ? "http://$code.blip.tv/rss/flash/" : 'http://blip.tv/rss/flash/'. $item['data']['post_id'];
+ $embed_code = $item['data']['flv']['embed_code']['0'];
+ $file = 'http://blip.tv/rss/flash/'. $item['data']['post_id'];
+ $embed_file = 'http://blip.tv/scripts/flash/showplayer.swf?enablejs=true'. $rss .'&file='. $file .'&showplayerpath=http://blip.tv/scripts/flash/showplayer.swf';
+
+ // If you want strict html you may want to use the following code instead of the one blip provides
+ // $output .= '';
+
+ $output .= '';
+ }
+
+ return $output;
+}
+
+function emvideo_bliptv_thumbnail($field, $item, $formatter, $node, $width, $height, $options = array()) {
+ if ($item['data']['emvideo_bliptv_data_version'] >= 1) {
+ $tn = $item['data']['thumbnail']['url'];
+ }
+ else {
+ $tn = $item['data']['thumbnail'];
+ }
+ return $tn;
+}
+
+function emvideo_bliptv_video($code, $width, $height, $field, $item, $autoplay, $options = array()) {
+ if ($item['data']['emvideo_bliptv_data_version'] >= 1) {
+ $flv = $item['data']['flv']['url'];
+ $thumbnail = $item['data']['thumbnail']['url'];
+ }
+ else {
+ $flv = $item['data']['flv'];
+ $thumbnail = $item['data']['thumbnail'];
+ }
+
+ $output = theme('emvideo_bliptv_flash', $code, $width, $height, $field, $item, $autoplay, $flv, $thumbnail);
+ return $output;
+}
+
+function emvideo_bliptv_preview($code, $width, $height, $field, $item, $autoplay, $options = array()) {
+ if ($item['data']['emvideo_bliptv_data_version'] >= 1) {
+ $flv = $item['data']['flv']['url'];
+ $thumbnail = $item['data']['thumbnail']['url'];
+ }
+ else {
+ $flv = $item['data']['flv'];
+ $thumbnail = $item['data']['thumbnail'];
+ }
+ $output = theme('emvideo_bliptv_flash', $code, $width, $height, $field, $item, $autoplay, $flv, $thumbnail);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_bliptv_emfield_subtheme() {
+ return array(
+ 'emvideo_bliptv_flash' => array(
+ 'arguments' => array('code' => NULL, 'width' => NULL, 'height' => NULL, 'field' => NULL, 'item' => NULL, 'autoplay' => NULL, 'flv' => NULL, 'thumbnail' => NULL, 'options' => NULL),
+ 'file' => 'providers/emvideo/bliptv.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emvideo/jumpcut.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/jumpcut.inc
diff -N contrib/emfield_generic/providers/emvideo/jumpcut.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/jumpcut.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,73 @@
+ 'jumpcut',
+ 'name' => t('JumpCut'),
+ 'url' => EMVIDEO_JUMPCUT_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from JumpCut.', array('@provider' => EMVIDEO_JUMPCUT_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+function emvideo_jumpcut_settings() {
+ $form = array();
+ return $form;
+}
+
+function emvideo_jumpcut_extract($embed) {
+ return array(
+ '@jumpcut\.com/view\?id=(.*)@i',
+ '@jumpcut\.com/view\?id=([^\&]*)\&@i',
+ );
+}
+
+function emvideo_jumpcut_video_link($video_code) {
+ return 'http://jumpcut.com/view?id='. $video_code;
+}
+
+function theme_emvideo_jumpcut_flash($embed, $width, $height) {
+ if ($embed) {
+ $output .= '';
+ }
+ return $output;
+}
+
+function emvideo_jumpcut_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return '';
+}
+
+function emvideo_jumpcut_video($embed, $width, $height, $field, $item) {
+ $output = theme('emvideo_jumpcut_flash', $embed, $width, $height);
+ return $output;
+}
+
+function emvideo_jumpcut_preview($embed, $width, $height, $field, $item) {
+ $output = theme('emvideo_jumpcut_flash', $embed, $width, $height);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_jumpcut_emfield_subtheme() {
+ return array(
+ 'emvideo_jumpcut_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL),
+ 'file' => 'providers/emvideo/jumpcut.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emimage/flickr.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emimage/flickr.inc
diff -N contrib/emfield_generic/providers/emimage/flickr.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emimage/flickr.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,240 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+
+function emimage_flickr_info() {
+ $features = array(
+ array(t('Import photosets'), t('Yes'), t('If you have the Embedded Media Import module activated, you may allow @name photosets to be imported into content.', array('@name' => $name))),
+ );
+ return array(
+ 'provider' => 'flickr',
+ 'name' => t('Flickr'),
+ 'url' => EMIMAGE_FLICKR_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect images displayed from Flickr.', array('@flickr' => EMIMAGE_FLICKR_MAIN_URL)),
+ 'supported_features' => $features,
+ 'import_sets_word' => t('photosets'),
+ );
+}
+
+/**
+ * This allows flickr photosets to be imported into nodes
+ */
+function emimage_flickr_import($url, $limit = 0, $page = 0) {
+ $codes = array();
+
+ // http://www.flickr.com/photos/nikkiana/sets/72157601948647678/
+ if (preg_match('@flickr\.com/photos/([^/]*)/([^/]*)/([^/]*)/@i', $url, $matches)) {
+ $page++; // flickr starts current page at 1
+ $codes['#matches'] = $matches;
+ $args = array('photoset_id' => $matches[3]);
+ if ($limit) {
+ $args['per_page'] = $limit;
+ }
+ $args['page'] = $page;
+ $xml = emimage_flickr_request('flickr.photosets.getPhotos', $args);
+// print_r($xml);
+ $codes['#pages'] = $xml['photoset']['pages'];
+ $codes['#page'] = $xml['photoset']['page'] - 1;
+ $codes['#total'] = $xml['photoset']['total'];
+ $codes['#per_page'] = $xml['photoset']['per_page'];
+ $codes['#set'] = array();
+ foreach ($xml['photoset']['photo'] as $photo) {
+ $data = emimage_flickr_data(NULL, array('value' => $photo['id']));
+ $codes['#set'][] = array(
+ '#code' => $photo['id'],
+ '#title' => $photo['title'],
+ '#link' => emimage_flickr_embedded_link($photo['id'], $xml['photoset']['owner']),
+ '#thumb' => emimage_flickr_image_url($photo['id'], 100, 100, NULL, NULL, NULL),
+ '#body' => $data['description'],
+ '#tags' => $data['tags'],
+// '#body' => emimage_flickr_description($photo['id']),
+// '#tags' => emimage_flickr_tags($photo['id']),
+ );
+ }
+/*
+ $data['owner'] = $xml['photo']['owner']['nsid'];
+ $data['title'] = $xml['photo']['title']['_content'];*/
+ }
+// print_r($codes);
+ return $codes;
+}
+
+/**
+ * hook emimage_PROVIDER_settings
+ * this should return a subform to be added to the emimage_settings() admin settings page.
+ * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['flickr'])
+ * so if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emimage_flickr_settings() {
+ $form['flickr']['api'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Flickr API'),
+ '#description' => t('You will first need to apply for an API Developer Key from the Flickr Developer Profile page.', array('@flickr' => EMIMAGE_FLICKR_API_APPLICATION_URL)),
+ '#collapsible' => TRUE,
+ '#collapsed' => (variable_get('emimage_flickr_api_key', '') != ''),
+ );
+ $form['flickr']['api']['emimage_flickr_api_key'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Flickr API Key'),
+ '#default_value' => variable_get('emimage_flickr_api_key', ''),
+ '#description' => t('Please enter your Flickr Developer Key here.'),
+ );
+ $form['flickr']['api']['emimage_flickr_api_secret'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Flickr API Secret'),
+ '#default_value' => variable_get('emimage_flickr_api_secret', ''),
+ '#description' => t('If you have a secret for the Flickr API, enter it here.'),
+ );
+ return $form;
+}
+
+
+/**
+ * this is a wrapper for emimage_request_xml that includes flickr's api key
+ */
+function emimage_flickr_request($method, $args = array(), $cached = TRUE) {
+ // display an error if we don't have an api key yet
+ emimage_flickr_error_check();
+
+ $args['api_key'] = trim(variable_get('emimage_flickr_api_key', ''));
+ if ($secret = trim(variable_get('emimage_flickr_api_secret', ''))) {
+ $args['secret'] = md5($secret . $arghash);
+ }
+ $args['method'] = $method;
+ $args['format'] = 'php_serial';
+
+ $xml = module_invoke('emfield', 'request_xml', 'flickr', EMIMAGE_FLICKR_REST_ENDPOINT, $args, $cached, FALSE, FALSE, TRUE);
+ return $xml;
+}
+
+function emimage_flickr_data($field, $item) {
+ $data = array();
+
+ // use the page id, since we'll have that in most cases (except in embed pastes, which gets parsed during extraction)
+ // we use this to get an rss feed w/ all the info for the video. interesting reading ;)
+ $xml = emimage_flickr_request('flickr.photos.getInfo', array('photo_id' => $item['value']));
+
+ $data['owner'] = $xml['photo']['owner']['nsid'];
+ $data['title'] = $xml['photo']['title']['_content'];
+ $data['description'] = $xml['photo']['description']['_content'];
+ $data['tags'] = array();
+ if (is_array($xml['photo']['tags']['tag'])) {
+ foreach ($xml['photo']['tags']['tag'] as $tag) {
+ $data['tags'][] = $tag['raw'];
+ }
+ }
+ return $data;
+}
+
+/**
+ * This will log an error if we don't have a key yet. In addition, if the user is an admin, we'll display an error.
+ */
+function emimage_flickr_error_check() {
+ static $checked;
+ if (!$checked && (variable_get('emimage_flickr_api_key', '') == '')) {
+ global $user;
+ $error = t('You do not yet have a Flickr API key set. You will need to apply for a Flickr API key and enter your key at the settings administration page before Flickr images may be displayed.', array('@apply' => EMIMAGE_FLICKR_API_APPLICATION_URL, '@settings' => url('admin/content/emfield')));
+ if (user_access('administer site configuration')) {
+ drupal_set_message($error, 'error');
+ }
+ watchdog('Embedded Media Field', '!error', array('!error' => $error));
+ }
+ $checked = TRUE;
+}
+
+function emimage_flickr_extract($embed = '') {
+ // http://flickr.com/photos/96898796@N00/194727976/
+ return array('@flickr\.com/photos/[^/]*/(\d+)@i');
+}
+
+/**
+ * hook emimage_PROVIDER_embedded_link($code)
+ * returns a link to view the content at the provider's site
+ * @param $code
+ * the string containing the content to watch
+ * @return
+ * a string containing the URL to view the video at the original provider's site
+ */
+function emimage_flickr_embedded_link($code, $data = array()) {
+ if ($data['owner']) {
+ $owner = $data['owner'];
+ }
+ else {
+ $xml = emimage_flickr_request('flickr.photos.getInfo', array('photo_id' => $code));
+ $owner = $xml['photo']['owner']['nsid'];
+ }
+ return 'http://www.flickr.com/photos/'. $owner .'/'. $code;
+}
+
+/**
+ * Implements emimage_PROVIDER_image_url.
+ *
+ * @param $code
+ * The provider code of the image.
+ * @param $width
+ * @param $height
+ * The dimensions of the photo to display.
+ * @return
+ * The url directly to the image to display.
+ */
+function emimage_flickr_image_url($code, $width, $height, $formatter = NULL, $field = NULL, $item = NULL, $node = NULL) {
+ if ($code) {
+ $size = _emimage_flickr_guess_size($width, $height);
+ $getsize = emimage_flickr_request('flickr.photos.getSizes', array('photo_id' => $code));
+ $url = $getsize['sizes']['size'][$size]['source'];
+ }
+ return $url;
+}
+
+/**
+ * Implements emimage_PROVIDER_image_title.
+ *
+ * @param $code
+ * The provider code of the image.
+ * @param $data
+ * Any stored data for the image, which may already have the title.
+ * @return
+ * The title as the 3rd party provider knows it, if accessible to us. otherwise, ''.
+ */
+function emimage_flickr_image_title($code, $data) {
+ if ($data['title']) {
+ return $data['title'];
+ }
+ $photo = emimage_flickr_request('flickr.photos.getInfo', array('photo_id' => $code));
+ return $photo['photo']['title']['_content'] ? $photo['photo']['title']['_content'] : '';
+}
+
+/**
+ * Helper function for emimage_flickr_image_url.
+ * This will return the appropriate array key for the image size we wish.
+ */
+function _emimage_flickr_guess_size($width, $height) {
+ $max = max($width, $height);
+ foreach (array('0' => 75, '1' => 100, '2' => 240, '3' => 500, '4' => 1024) as $size => $value) {
+ if ($max <= $value) {
+ return $size;
+ }
+ }
+ return '5';
+}
Index: contrib/emfield_generic/providers/emvideo/lastfm.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/lastfm.inc
diff -N contrib/emfield_generic/providers/emvideo/lastfm.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/lastfm.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,178 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+function emvideo_lastfm_info() {
+ $features = array(
+ array(t('Autoplay'), t('No'), ''),
+ array(t('RSS Attachment'), t('No'), ''),
+ array(t('Thumbnails'), t('No'), t('')),
+ );
+ return array(
+ 'provider' => 'lastfm',
+ 'name' => t('Last.fm'),
+ 'url' => EMVIDEO_LASTFM_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from Last.fm.', array('@lastfm' => EMVIDEO_LASTFM_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_settings
+ * this should return a subform to be added to the emvideo_settings() admin settings page.
+ * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['lastfm'])
+ * so if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emvideo_lastfm_settings() {
+}
+
+/**
+ * hook emvideo_PROVIDER_extract
+ * this is called to extract the video code from a pasted URL or embed code.
+ * @param $embed
+ * an optional string with the pasted URL or embed code
+ * @return
+ * either an array of regex expressions to be tested, or a string with the video code to be used
+ * if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array.
+ * otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
+ */
+function emvideo_lastfm_extract($embed = '') {
+ // http://www.last.fm/music/The+Shins/+videos/2794412
+ //
+
+ // thumb:
+ // http://userserve-ak.last.fm/serve/image:160/2794412.jpg
+
+ // src="http://www.lastfm.com/v/nvbQQnvxXDk"
+ // http://lastfm.com/watch?v=nvbQQnvxXDk
+ // http://www.lastfm.com/watch?v=YzFCA-xUc8w&feature=dir
+ if (preg_match('@cdn.last.fm@i', $embed, $matches)) {
+ if (preg_match('@uniqueName=([0-9]+)@i', $embed, $matches)) {
+ return $matches[1];
+ }
+ }
+ else if (preg_match('@last\.fm@i', $embed, $matches)) {
+ if (preg_match('@([0-9]+)@i', $embed, $matches)) {
+ return $matches[1];
+ }
+ }
+ return array(
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_embedded_link($video_code)
+ * returns a link to view the video at the provider's site
+ * @param $video_code
+ * the string containing the video to watch
+ * @return
+ * a string containing the URL to view the video at the original provider's site
+ */
+function emvideo_lastfm_embedded_link($video_code) {
+ return '';
+}
+
+/**
+ * the embedded flash displaying the lastfm video
+ */
+function theme_emvideo_lastfm_flash($embed, $width, $height, $autoplay) {
+ static $count;
+ if ($embed) {
+ // set css id count
+ $count++;
+ $output .= '';
+ }
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_thumbnail
+ * returns the external url for a thumbnail of a specific video
+ * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
+ * @param $field
+ * the field of the requesting node
+ * @param $item
+ * the actual content of the field from the requesting node
+ * @return
+ * a URL pointing to the thumbnail
+ */
+function emvideo_lastfm_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ $lastfm_id = $item['value'];
+
+ // if we have a large thumbnail size, then get the larger version available.
+ if ($width >= 320) {
+ $tn = "http://userserve-ak.last.fm/serve/image:320/$lastfm_id.jpg";
+ }
+ else {
+ $tn = "http://userserve-ak.last.fm/serve/image:160/$lastfm_id.jpg";
+ }
+ return $tn;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the full/normal-sized video we want, usually on the default page view
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_lastfm_video($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_lastfm_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the preview-sized video we want, commonly for the teaser
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_lastfm_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_lastfm_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+function emvideo_lastfm_emfield_subtheme() {
+ return array(
+ 'emvideo_lastfm_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL),
+ 'file' => 'providers/emvideo/lastfm.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emvideo/zzz_custom_url.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/zzz_custom_url.inc
diff -N contrib/emfield_generic/providers/emvideo/zzz_custom_url.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/zzz_custom_url.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,164 @@
+ 'zzz_custom_url',
+ 'name' => $name,
+ 'url' => '',
+ 'settings_description' => t('These settings specifically affect videos displayed from custom URLs. When a field uses a URL it determines to be a link directly to a video file, it will embed that file into the content.'),
+ 'supported_features' => $features,
+ 'weight' => 9,
+ );
+}
+
+function emvideo_zzz_custom_url_settings() {
+ $options = array(
+ 'wmv' => t('Windows Media (wmv)'),
+ 'wma' => t('Windows Media (wma)'),
+ 'swf' => t('Flash (swf)'),
+ 'flv' => t('Flash Video (flv)'),
+ 'mov' => t('Quicktime (mov)'),
+ 'mp4' => t('Quicktime (mp4)'),
+ 'rm' => t('Real Media (rm)'),
+ );
+ $form = array();
+ $form['emvideo_zzz_custom_url_supported_types'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Supported Types'),
+ '#options' => $options,
+ '#default_value' => variable_get('emvideo_zzz_custom_url_supported_types', _emvideo_zzz_custom_url_default_types()),
+ '#description' => t('Select the video types you wish to support. When a custom url with that type is entered into an embedded video field, it will be parsed and displayed appropriately. If a type is not supported, then it will be ignored.'),
+ );
+ return $form;
+}
+
+function _emvideo_zzz_custom_url_implode_types() {
+ return implode('|', variable_get('emvideo_zzz_custom_url_supported_types', _emvideo_zzz_custom_url_default_types()));
+}
+
+function emvideo_zzz_custom_url_extract($embed = '') {
+ $types = _emvideo_zzz_custom_url_implode_types();
+ $baseurl = preg_quote(url(null, array('absolute' => TRUE)), '@');
+
+ return array(
+ '@' . $baseurl . '(.*' . '\.(?:' . $types . ')' . '(\?.*)?)@i',
+ '@(.*\.(?:'. $types .')(\?.*)?)@i'
+ );
+}
+
+function emvideo_zzz_custom_url_data($field, $item) {
+ $data = array();
+ // adding the version control
+ $data['emvideo_zzz_custom_url_data_version'] = 1;
+
+ // attempt to get info from headers
+ $response = emfield_request_header('zzz_custom_url', $item['embed']);
+
+ if ($response->code == 200) {
+ $data['url'] = $item['embed'];
+ $data['size'] = $response->headers['Content-Length'];
+ $data['mime'] = $response->headers['Content-Type'];
+ }
+ // @todo replace ['type'] with converted mime info if available
+ $types = _emvideo_zzz_custom_url_implode_types();
+ $regex = '@\.('. $types .')@i';
+ if (preg_match($regex, $item['embed'], $matches)) {
+ $data['type'] = $matches[1];
+ }
+ return $data;
+}
+
+/**
+ * hook emfield_PROVIDER_rss
+ */
+function emvideo_zzz_custom_url_rss($item, $teaser = NULL) {
+ if ($item['value']) {
+ if ($item['data']['emvideo_zzz_custom_url_data_version'] >= 1) {
+ $data = $item['data'];
+ }
+ else {
+ $data = emvideo_zzz_custom_url_data(NULL, $item);
+ }
+
+ $file = array();
+ if ($data['size'] > 0) {
+ $file['filepath'] = $data['url'];
+ $file['filesize'] = $data['size'];
+ $file['filemime'] = $data['mime'];
+ }
+
+ return $file;
+ }
+}
+
+
+function emvideo_zzz_custom_url_embedded_link($video_code) {
+ return $video_code;
+}
+
+function theme_emvideo_zzz_custom_url_embedded_video($type, $url, $width, $height, $autoplay = FALSE, $field = NULL, $item = NULL) {
+ if ($url) {
+ switch ($type) {
+ case 'wmv':
+ case 'wma':
+ $autostart = $autoplay ? '1' : '0';
+ return '';
+ case 'mov':
+ case 'mp4':
+ $autostart = $autoplay ? 'true' : 'false';
+ return '';
+ case 'rm':
+ $autostart = $autoplay ? 'true' : 'false';
+ return ' ';
+ case 'swf':
+ return '';
+ case 'flv':
+ $autostart = $autoplay ? 'true' : 'false';
+ return '';
+ }
+ }
+}
+
+function emvideo_zzz_custom_url_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return '';
+}
+
+function emvideo_zzz_custom_url_video($code, $width, $height, $field, $item, $autoplay) {
+ $type = $item['data']['type'];
+ $output = theme('emvideo_zzz_custom_url_embedded_video', $type, $code, $width, $height, $autoplay, $field, $item);
+ return $output;
+}
+
+function emvideo_zzz_custom_url_preview($code, $width, $height, $field, $item, $autoplay) {
+ $type = $item['data']['type'];
+ $output = theme('emvideo_zzz_custom_url_embedded_video', $type, $code, $width, $height, $autoplay, $field, $item);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_zzz_custom_url_emfield_subtheme() {
+ return array(
+ 'emvideo_zzz_custom_url_embedded_video' => array(
+ 'arguments' => array('type' => NULL, 'url' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => FALSE, 'field' => NULL, 'item' => NULL),
+ 'file' => 'providers/emvideo/zzz_custom_url.inc'
+ )
+ );
+}
Index: contrib/emfield_generic/providers/emaudio/podcastalley.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emaudio/podcastalley.inc
diff -N contrib/emfield_generic/providers/emaudio/podcastalley.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emaudio/podcastalley.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,167 @@
+ The translated name of the provider.
+ * 'url' => The url to the main page for the provider.
+ * 'settings_description' => A description of the provider that will be posted in the admin settings form.
+ * 'supported_features' => An array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+function emaudio_podcastalley_info() {
+ $features = array(
+ array(t('Autoplay'), t('No'), ''),
+ array(t('RSS Attachment'), t('No'), ''),
+ array(t('Thumbnails'), t('No'), t('')),
+ );
+
+ return array(
+ 'provider' => 'Podcast Alley',
+ 'name' => t('Podcast Alley'),
+ 'url' => EMAUDIO_PODCASTALLEY_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect audio podcasts displayed from Podcast Alley.', array('@podcastalley' => EMAUDIO_PODCASTALLEY_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+/**
+ * Implementation of hook emaudio_podcastalley_settings().
+ *
+ * This should return a subform to be added to the emaudio_settings() admin settings page.
+ * Note that a form field will already be provided, at $form['podcastalley'].
+ * So if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emaudio_podcastalley_settings() {
+ $form = array();
+ return $form;
+}
+
+/**
+ * Implementation of hook emaudio_podcastalley_extract().
+ *
+ * This is called to extract the video code from a pasted URL or embed code.
+ *
+ * @param $embed
+ * An optional string with the pasted URL or embed code.
+ * @return
+ * Either an array of regex expressions to be tested, or a string with the
+ * audio code to be used. If the hook tests the code itself, it should return
+ * either the string of the audio code (if matched), or an empty array.
+ * Otherwise, the calling function will handle testing the embed code against
+ * each regex string in the returned array.
+ */
+function emaudio_podcastalley_extract($embed = '') {
+ // http://www.podcastalley.com/podcast_details.php?pod_id=929#
+ return array(
+ '@podcastalley\.com/podcast_details\.php\?pod_id=([0-9]+)@i'
+ );
+}
+
+/**
+ * The embedded flash displaying the podcastalley audio.
+ *
+ * Default width is 419, height is 202.
+ */
+function theme_emaudio_podcastalley_flash($embed, $width, $height, $autoplay) {
+ if ($embed) {
+ /*
+ if ($autoplay) {
+ $autoplay_value = '&autostart=1';
+ }
+ */
+ $output .= "
+
+ \n";
+ }
+
+ return $output;
+}
+
+/**
+ * Implementation of hook emaudio_podcastalley_thumbnail.
+ *
+ * Returns the external url for a thumbnail of a specific audio.
+ * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things.
+ *
+ * @param $field
+ * The field of the requesting node.
+ * @param $item
+ * The actual content of the field from the requesting node.
+ * @return
+ * A URL pointing to the thumbnail.
+ */
+function emaudio_podcastalley_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return $tn;
+}
+
+/**
+ * Implementation of hook emaudio_podcastalley_audio().
+ *
+ * This actually displays the full/normal-sized video we want,
+ * usually on the default page view.
+ *
+ * @param $embed
+ * The video code for the audio to embed.
+ * @param $width
+ * The width to display the audio.
+ * @param $height
+ * The height to display the audio.
+ * @param $field
+ * The field info from the requesting node.
+ * @param $item
+ * The actual content from the field.
+ * @return
+ * The html of the embedded audio.
+ */
+function emaudio_podcastalley_audio($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emaudio_podcastalley_flash', $embed, $width, $height, $autoplay);
+
+ return $output;
+}
+
+/**
+ * Implementation of hook emaudio_podcastalley_preview().
+ *
+ * This actually displays the preview-sized video we want, commonly for the teaser.
+ *
+ * @param $embed
+ * The video code for the audio to embed.
+ * @param $width
+ * The width to display the audio.
+ * @param $height
+ * The height to display the audio.
+ * @param $field
+ * The field info from the requesting node.
+ * @param $item
+ * The actual content from the field.
+ * @return
+ * The html of the embedded audio.
+ */
+function emaudio_podcastalley_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emaudio_podcastalley_flash', $embed, $width, $height, $autoplay);
+
+ return $output;
+}
Index: contrib/emfield_generic/providers/emaudio/odeo.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emaudio/odeo.inc
diff -N contrib/emfield_generic/providers/emaudio/odeo.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emaudio/odeo.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,168 @@
+ The translated name of the provider.
+ * 'url' => The url to the main page for the provider.
+ * 'settings_description' => A description of the provider that will be posted in the admin settings form.
+ * 'supported_features' => An array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+function emaudio_odeo_info() {
+ $features = array(
+ array(t('Autoplay'), t('No'), ''),
+ array(t('RSS Attachment'), t('No'), ''),
+ array(t('Thumbnails'), t('No'), t('')),
+ );
+ return array(
+ 'provider' => 'odeo',
+ 'name' => t('odeo'),
+ 'url' => EMAUDIO_ODEO_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect audio podcasts displayed from odeo.', array('@odeo' => EMAUDIO_ODEO_MAIN_URL)),
+ 'supported_features' => $features,
+ );
+}
+
+/**
+ * Implementation of hook emaudio_odeo_settings().
+ *
+ * This should return a subform to be added to the emaudio_settings() admin settings page.
+ * Note that a form field will already be provided, at $form['odeo'] (such as $form['podomatic']).
+ * So if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emaudio_odeo_settings() {
+ $form = array();
+
+ return $form;
+}
+
+/**
+ * Implementation of hook emaudio_odeo_extract().
+ *
+ * This is called to extract the video code from a pasted URL or embed code.
+ *
+ * @param $embed
+ * An optional string with the pasted URL or embed code.
+ * @return
+ * Either an array of regex expressions to be tested, or a string with the
+ * audio code to be used. If the hook tests the code itself, it should return
+ * either the string of the audio code (if matched), or an empty array.
+ * Otherwise, the calling function will handle testing the embed code against
+ * each regex string in the returned array.
+ */
+function emaudio_odeo_extract($embed = '') {
+ return array(
+ '@odeo\.com/audio/([0-9]+)/@i',
+ '@href="http://odeo.com/audio/([0-9]+)/@i',
+ );
+}
+
+/**
+ * The embedded flash displaying the odeo audio.
+ *
+ * Default width is 322, height is 54.
+ */
+function theme_emaudio_odeo_flash($embed, $width, $height, $autoplay) {
+ if ($embed) {
+ /*
+ if ($autoplay) {
+ $autoplay_value = '&autostart=1';
+ }
+ */
+
+ $output .= "
+
+ \n";
+ }
+
+ return $output;
+}
+
+/**
+ * Implementation of hook emaudio_odeo_thumbnail().
+ *
+ * Returns the external url for a thumbnail of a specific audio.
+ * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things.
+ *
+ * @param $field
+ * The field of the requesting node.
+ * @param $item
+ * The actual content of the field from the requesting node.
+ * @return
+ * A URL pointing to the thumbnail.
+ */
+function emaudio_odeo_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ return $tn;
+}
+
+/**
+ * Implementation of hook emaudio_odeo_audio().
+ *
+ * This actually displays the full/normal-sized video we want, usually on the default page view.
+ *
+ * @param $embed
+ * The video code for the audio to embed.
+ * @param $width
+ * The width to display the audio.
+ * @param $height
+ * The height to display the audio.
+ * @param $field
+ * The field info from the requesting node.
+ * @param $item
+ * The actual content from the field.
+ * @return
+ * The html of the embedded audio.
+ */
+function emaudio_odeo_audio($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emaudio_odeo_flash', $embed, $width, $height, $autoplay);
+
+ return $output;
+}
+
+/**
+ * Implementation of hook emaudio_odeo_preview().
+ *
+ * This actually displays the preview-sized video we want, commonly for the teaser.
+ *
+ * @param $embed
+ * The video code for the audio to embed.
+ * @param $width
+ * The width to display the audio.
+ * @param $height
+ * The height to display the audio.
+ * @param $field
+ * The field info from the requesting node.
+ * @param $item
+ * The actual content from the field.
+ * @return
+ * The html of the embedded audio.
+ */
+function emaudio_odeo_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emaudio_odeo_flash', $embed, $width, $height, $autoplay);
+
+ return $output;
+}
Index: contrib/emfield_generic/providers/emvideo/youtube.inc
===================================================================
RCS file: contrib/emfield_generic/providers/emvideo/youtube.inc
diff -N contrib/emfield_generic/providers/emvideo/youtube.inc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ contrib/emfield_generic/providers/emvideo/youtube.inc 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,379 @@
+ the translated name of the provider
+ * 'url' => the url to the main page for the provider
+ * 'settings_description' => a description of the provider that will be posted in the admin settings form
+ * 'supported_features' => an array of rows describing the state of certain supported features by the provider.
+ * These will be rendered in a table, with the columns being 'Feature', 'Supported', 'Notes'.
+ */
+function emvideo_youtube_info() {
+ $features = array(
+ array(t('Autoplay'), t('Yes'), ''),
+ array(t('RSS Attachment'), t('Yes'), ''),
+ array(t('Show related videos'), t('Yes'), t('This is embedded in the video itself when enabled; currently not available with other providers. Set the feature above.')),
+ array(t('Thumbnails'), t('Yes'), t('')),
+ array(t('Custom player colors'), t('Yes'), t("You may customize the player's skin by choosing your own colors, and/or border in that setting field set.")),
+ );
+ return array(
+ 'provider' => 'youtube',
+ 'name' => t('YouTube'),
+ 'url' => EMVIDEO_YOUTUBE_MAIN_URL,
+ 'settings_description' => t('These settings specifically affect videos displayed from YouTube. You can learn more about its API here.', array('@youtube' => EMVIDEO_YOUTUBE_MAIN_URL, '@api' => EMVIDEO_YOUTUBE_API_INFO)),
+ 'supported_features' => $features,
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_settings
+ * this should return a subform to be added to the emvideo_settings() admin settings page.
+ * note that a form field will already be provided, at $form['PROVIDER'] (such as $form['youtube'])
+ * so if you want specific provider settings within that field, you can add the elements to that form field.
+ */
+function emvideo_youtube_settings() {
+ $form['youtube']['emvideo_youtube_show_related_videos'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Show related videos'),
+ '#default_value' => variable_get('emvideo_youtube_show_related_videos', 0),
+ '#description' => t('If checked, then when playing a video from YouTube, users may hover over the video to see thumbnails & links to related videos.'),
+ );
+ $form['youtube']['api'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('YouTube API'),
+ '#description' => t('The API is no longer required. However, there may be future features requiring it (such as the ability to display otherwise private videos). You will first need to apply for an API Developer Key from the YouTube Developer Profile page. Note that you do not need this key to display YouTube videos or their thumbnails.', array('@youtube' => EMVIDEO_YOUTUBE_API_APPLICATION_URL)),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['youtube']['api']['emvideo_youtube_api_key'] = array(
+ '#type' => 'textfield',
+ '#title' => t('YouTube API Key'),
+ '#default_value' => variable_get('emvideo_youtube_api_key', ''),
+ '#description' => t('Please enter your YouTube Developer Key here.'),
+ );
+ $form['youtube']['api']['emvideo_youtube_api_secret'] = array(
+ '#type' => 'textfield',
+ '#title' => t('YouTube API Secret'),
+ '#default_value' => variable_get('emvideo_youtube_api_secret', ''),
+ '#description' => t('If you have a secret for the YouTube API, enter it here.'),
+ );
+ $form['youtube']['colors'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Embedded Video Player Colors'),
+ '#description' => t('If allowed, these two colors, in hexidecimal form (#RRGGBB), will be used to skin the YouTube player.'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ $form['youtube']['colors']['emvideo_youtube_show_colors'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Override player colors'),
+ '#default_value' => variable_get('emvideo_youtube_show_colors', FALSE),
+ );
+ $form['youtube']['colors']['emvideo_youtube_show_border'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display border around player'),
+ '#default_value' => variable_get('emvideo_youtube_show_border', FALSE),
+ );
+ $form['youtube']['colors']['emvideo_youtube_colors_color1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Color 1'),
+ '#default_value' => variable_get('emvideo_youtube_colors_color1', EMVIDEO_YOUTUBE_COLOR1_DEFAULT),
+ );
+ $form['youtube']['colors']['emvideo_youtube_colors_color2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Color 2'),
+ '#default_value' => variable_get('emvideo_youtube_colors_color2', EMVIDEO_YOUTUBE_COLOR2_DEFAULT),
+ );
+ if (module_exists('colorpicker')) {
+ $form['youtube']['colors']['emvideo_youtube_colors_color1']['#type'] = 'colorpicker_textfield';
+ $form['youtube']['colors']['emvideo_youtube_colors_color1']['#colorpicker'] = 'colorpicker_1';
+ $form['youtube']['colors']['emvideo_youtube_colors_color2']['#type'] = 'colorpicker_textfield';
+ $form['youtube']['colors']['emvideo_youtube_colors_color2']['#colorpicker'] = 'colorpicker_2';
+ $form['youtube']['colors']['colorpicker_1'] = array(
+ '#type' => 'colorpicker',
+ '#title' => t('Color 1 picker'),
+ '#description' => t('Click in this textfield to start picking your color'),
+ );
+ $form['youtube']['colors']['colorpicker_2'] = array(
+ '#type' => 'colorpicker',
+ '#title' => t('Color 2 picker'),
+ '#description' => t('Click in this textfield to start picking your color'),
+ );
+ }
+ else {
+ $form['youtube']['colors']['#description'] .= ' '. t('The Colorpicker module, if active, gives an easy way to select these colors.', array('@colorpicker' => 'http://drupal.org/project/colorpicker'));
+ }
+ return $form;
+}
+
+/**
+ * hook emfield_PROVIDER_data
+ *
+ * provides an array to be serialised and made available with $item elsewhere
+ */
+function emvideo_youtube_data($field, $item) {
+ $data = array();
+ // create some 'field' version control
+ $data['emvideo_youtube_version'] = 1;
+
+ // be nice to make this an array for changing media:thumbnail?
+ $data['thumbnail']['url'] = 'http://img.youtube.com/vi/'. $item['value'] .'/0.jpg';
+
+ // gather info about the item
+ // RSS / MRSS feeds with the item would have enough info
+ // alternative try getting the minimum from an http get
+ $url = 'http://youtube.com/v/'. $item['value'];
+ $response = emfield_request_header('youtube', $url);
+
+ if ($response->code == 200) {
+ // probably shouldn't give the 303 path
+ $data['flash']['url'] = $url;
+ $data['flash']['size'] = $response->headers['Content-Length'];
+ $data['flash']['mime'] = $response->headers['Content-Type'];
+ }
+
+ return $data;
+}
+
+/**
+ *
+ */
+function emvideo_youtube_rss($item, $teaser = NULL) {
+ if ($item['value']) {
+ if ($item['data']['emvideo_youtube_data_version'] >= 1) {
+ $data = $item['data'];
+ }
+ else {
+ $data = emvideo_youtube_data(NULL, $item);
+ }
+
+ $file = array();
+ if (is_array($data['flash'])) {
+ $file['filepath'] = $data['flash']['url'];
+ $file['filesize'] = $data['flash']['size'];
+ $file['filemime'] = $data['flash']['mime'];
+ }
+ $file['thumbnail']['filepath'] = $data['thumbnail']['url'];
+
+ return $file;
+ }
+}
+
+/**
+ * this is a wrapper for emvideo_request_xml that includes youtube's api key
+ */
+function emvideo_youtube_request($method, $args = array(), $cached = TRUE) {
+ $args['dev_id'] = trim(variable_get('emvideo_youtube_api_key', ''));
+ $args['method'] = $method;
+
+ // if we've got a secret sign the arguments
+ // TODO: doesn't seem to matter
+// if ($secret = trim(variable_get('emvideo_youtube_api_secret', ''))) {
+// $args['api_sig'] = md5($secret . $arghash);
+// }
+
+ $request = module_invoke('emfield', 'request_xml', 'youtube', EMVIDEO_YOUTUBE_REST_ENDPOINT, $args, $cached);
+ return $request;
+}
+
+/**
+ * hook emvideo_PROVIDER_extract
+ * this is called to extract the video code from a pasted URL or embed code.
+ * @param $embed
+ * an optional string with the pasted URL or embed code
+ * @return
+ * either an array of regex expressions to be tested, or a string with the video code to be used
+ * if the hook tests the code itself, it should return either the string of the video code (if matched), or an empty array.
+ * otherwise, the calling function will handle testing the embed code against each regex string in the returned array.
+ */
+function emvideo_youtube_extract($embed = '') {
+ // src="http://www.youtube.com/v/nvbQQnvxXDk"
+ // http://youtube.com/watch?v=nvbQQnvxXDk
+ // http://www.youtube.com/watch?v=YzFCA-xUc8w&feature=dir
+ return array(
+ '@youtube\.com/v/([^"\&]+)@i',
+ '@youtube\.com/watch\?v=([^"\&]+)@i',
+ '@youtube\.com/\?v=([^"\&]+)@i',
+ );
+}
+
+/**
+ * hook emvideo_PROVIDER_embedded_link($video_code)
+ * returns a link to view the video at the provider's site
+ * @param $video_code
+ * the string containing the video to watch
+ * @return
+ * a string containing the URL to view the video at the original provider's site
+ */
+function emvideo_youtube_embedded_link($video_code) {
+ return 'http://www.youtube.com/watch?v='. $video_code;
+}
+
+function emvideo_youtube_convert_color($color = NULL) {
+ if ($color{0} == '#') {
+ return drupal_substr($color, 1);
+ }
+
+ return $color;
+}
+
+/**
+ * The embedded flash displaying the youtube video.
+ */
+function theme_emvideo_youtube_flash($embed, $width, $height, $autoplay, $options = array()) {
+ static $count;
+ if ($embed) {
+ $related = isset($options['related']) ? $options['related'] : variable_get('emvideo_youtube_show_related_videos', 0);
+ $related = "rel=$related";
+ $autoplay = isset($options['autoplay']) ? $options['autoplay'] : $autoplay;
+ $autoplay_value = $autoplay ? '&autoplay=1' : '';
+ $show_colors = isset($options['show_colors']) ? $options['show_colors'] : variable_get('emvideo_youtube_show_colors', FALSE);
+ if ($show_colors) {
+ $color1 = isset($options['color1']) ? $options['color1'] : variable_get('emvideo_youtube_colors_color1', emvideo_YOUTUBE_COLOR1_DEFAULT);
+ $color2 = isset($options['color2']) ? $options['color2'] : variable_get('emvideo_youtube_colors_color2', emvideo_YOUTUBE_COLOR2_DEFAULT);
+ $colors='&color1=0x'. emvideo_youtube_convert_color($color1) .'&color2=0x'. emvideo_youtube_convert_color($color2);
+ }
+ $border = isset($options['border']) ? $options['border'] : variable_get('emvideo_youtube_show_border', FALSE);
+ $border = $border ? '&border=1' : '';
+ $enablejsapi = isset($options['enablejsapi']) ? $options['enablejsapi'] : variable_get('emvideo_youtube_enablejsapi', TRUE);
+ $enablejsapi = $enablejsapi ? '&enablejsapi=1&playerapiid=ytplayer' : '';
+ $id = isset($options['id']) ? $options['id'] : 'video-cck-youtube-flash-'. (++$count);
+ $div_id = isset($options['div_id']) ? $options['div_id'] : 'video-cck-youtube-flash-wrapper-'. $count;
+ $url = "http://www.youtube.com/v/$embed&$related$autoplay_value$colors$border$enablejsap";
+ if (variable_get('emfield_swfobject', FALSE) && (module_exists('swfobject_api') || variable_get('emfield_swfobject_location', ''))) {
+ if (module_exists('swfobject_api')) {
+ $params['width'] = $width;
+ $params['height'] = $height;
+ $params['div_id'] = $id;
+ $output .= theme('swfobject_api', $url, $params, $vars, $id);
+ }
+ else {
+ drupal_add_js(variable_get('emfield_swfobject_location', ''));
+ $output .= <<
+ Sorry, you need to install flash to see this content.
+
+
+FLASH;
+ }
+ }
+ else {
+ $output .= <<
+FLASH;
+ }
+ }
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_thumbnail
+ * returns the external url for a thumbnail of a specific video
+ * TODO: make the args: ($embed, $field, $item), with $field/$item provided if we need it, but otherwise simplifying things
+ * @param $field
+ * the field of the requesting node
+ * @param $item
+ * the actual content of the field from the requesting node
+ * @return
+ * a URL pointing to the thumbnail
+ */
+function emvideo_youtube_thumbnail($field, $item, $formatter, $node, $width, $height) {
+ $youtube_id = $item['value'];
+ // Old code to grab thumbnail via API.
+//$request = emvideo_youtube_request('youtube.videos.get_details', array('video_id' => $youtube_id));
+//$tn = $request['THUMBNAIL_URL'][0];
+
+ // if we have a large thumbnail size, then get the larger version available.
+ if ($width > 130 || $height > 97) {
+ $tn = "http://img.youtube.com/vi/$youtube_id/0.jpg";
+ }
+ else {
+ // youtube offers 3 thumbnails. select one randomly.
+ $rand = rand(0, 2) + 1;
+ $tn = "http://img.youtube.com/vi/$youtube_id/$rand.jpg";
+ }
+
+ return $tn;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the full/normal-sized video we want, usually on the default page view
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_youtube_video($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_youtube_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+/**
+ * hook emvideo_PROVIDER_video
+ * this actually displays the preview-sized video we want, commonly for the teaser
+ * @param $embed
+ * the video code for the video to embed
+ * @param $width
+ * the width to display the video
+ * @param $height
+ * the height to display the video
+ * @param $field
+ * the field info from the requesting node
+ * @param $item
+ * the actual content from the field
+ * @return
+ * the html of the embedded video
+ */
+function emvideo_youtube_preview($embed, $width, $height, $field, $item, $autoplay) {
+ $output = theme('emvideo_youtube_flash', $embed, $width, $height, $autoplay);
+ return $output;
+}
+
+/**
+ * Implementation of hook_emfield_subtheme.
+ */
+function emvideo_youtube_emfield_subtheme() {
+ return array(
+ 'emvideo_youtube_flash' => array(
+ 'arguments' => array('embed' => NULL, 'width' => NULL, 'height' => NULL, 'autoplay' => NULL),
+ 'file' => 'providers/emvideo/youtube.inc'
+ )
+ );
+}