'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 */ 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(); $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); } 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; } /** Implementation of hook_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); } 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; 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; } /** * 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_allow_' . $module . '_' . $test->name, TRUE)) { unset($allowed_providers[$test->name]); } else { $allow_all &= !$field['widget']['providers'][$test->name]; } } if (!$allow_all) { foreach ($allowed_providers as $test) { if (!$field['widget']['providers'][$test->name]) { unset($allowed_providers[$test->name]); } } } return $allowed_providers; } /** * 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 ($cached && $cache = cache_get('emfield_implement_types', 'cache')) { $types = unserialize($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 $types = array(); $modules = array(); foreach (module_implements('emfield_info', TRUE) as $module) { $modules[$module] = $module; } // settings per content type for the module foreach ($content_types as $content_type => $type) { // 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 ($module = $modules[$field_types[$field['type']]['module']]) { // settings per content type per module $types[$module][$content_type][$field_type] = $field; } } } } } cache_set('emfield_implement_types', 'cache', serialize($types), 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. */ 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 return array(); } /** * extract the id from embedded code or url */ function _emfield_field_validate_id($field, $item, $error_field, $module) { // does nothing at this time... TODO: fix this up return _emfield_field_submit_id($field, $item, $module, $error_field); } /** * 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' */ 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); return $item; } 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 ($item['in_preview']) { $item = emfield_parse_embed($field, $item['embed'], $module); } // 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 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 if (!is_array($item['data'])) { $item['data'] = (array)unserialize($item['data']); } // $module = $field['widget']['helper_module']; $output .= theme($module . '_' . $formatter, $field, $item, $formatter, $node); 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; } } 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))); 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; } } /** * Implementation of hook_node_operations(). */ function emfield_node_operations() { $operations = array( 'emfield_reload' => array( 'label' => t('Reload Embedded Media Data'), 'callback' => 'emfield_operations_reload', ), ); return $operations; } /** * This reloads and saves the data for all the nid's in the array. */ function emfield_operations_reload($nids = array()) { foreach ($nids as $nid) { if ($node = node_load($nid)) { $type = content_types($node->type); foreach ($type['fields'] as $field) { if (module_hook($field['type'], 'emfield_info')) { drupal_set_message(t("Reloading %node-title's %field.", array('%node-title' => $node->title, '%field' => $field['type_name']))); $items = $node->{$field['field_name']}; emfield_emfield_field('submit', $node, $field, $items, FALSE, FALSE, $field['type']); $node->{$field['field_name']} = $items; node_save($node); } } } } } /** * Implementation of hook_nodeapi(). */ function emfield_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) { switch ($op) { case 'rss item': $rss = 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); if (!is_null($rss_encl)) { $rss[] = $rss_encl; } } } if (!empty($rss)) { $file = array_shift($rss);//print_r($file); return array( array( 'key' => 'enclosure', 'attributes' => array( 'url' => check_url($file->filepath), 'length' => check_plain($file->filesize), 'type' => check_plain($file->filemime), ) ) ); } break; } } /** * 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. * @param $provider * the string of the third party provider, such as 'youtube', 'flikr', or 'google' * @param $url * the url for the xml request * @param $args * an array of args to pass to the xml url * @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 xml results returned as an array */ 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 $arghash = $provider . ':'; foreach($args as $k => $v){ $arghash .= $k . $v; } // build the url foreach ($args as $k => $v){ $encoded_params[] = urlencode($k).'='.urlencode($v); } if (!empty($encoded_params)) { $url .= '?'. implode('&', $encoded_params); } // some providers, such as bliptv, actually change the url, and not just the queries. // we provide an extra section for a unique identifier in that case if (isset($hash_extra)) { $arghash .= ':' . $hash_extra; } // if it's a cachable request, try to load a cached value if ($cached && $cache = cache_get($arghash, 'cache')) { return unserialize($cache->data); } // connect and fetch a value $result = drupal_http_request($url); if ($result->code != 200) { if ($return_errors) { return array( 'stat' => 'error', 'code' => $result->code, 'message' => 'HTTP Error: '. $result->error, ); } emfield_set_error(t("Could not connect to @provider, HTTP error @error", array('@error' => $result->code, '@provider' => $provider))); return array(); } if ($serialized) { // Flickr gives us a serialized php array. Make sure it unserializes. $response = unserialize($result->data); if (!$response) { if ($return_errors) { return array( 'stat' => 'error', 'code' => '-1', '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(); } } else { $parser = drupal_xml_parser_create($result->data); $vals = array(); $index = array(); xml_parse_into_struct($parser, $result->data, $vals, $index); xml_parser_free($parser); $response = array(); $response['_emfield_arghash'] = $arghash; $level = array(); $start_level = 1; foreach ($vals as $xml_elem) { if ($xml_elem['type'] == 'open') { if (array_key_exists('attributes',$xml_elem)) { list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']); } else { $level[$xml_elem['level']] = $xml_elem['tag']; } } if ($xml_elem['type'] == 'complete') { $php_stmt = '$response'; while($start_level < $xml_elem['level']) { $php_stmt .= '[$level['.$start_level.']]'; $start_level++; } $php_stmt .= '[$xml_elem[\'tag\']][] = $xml_elem[\'value\'];' . $php_stmt . '[$xml_elem[\'tag\']][] = $xml_elem[\'attributes\'];'; eval($php_stmt); $start_level--; } } } cache_set($arghash, 'cache', serialize($response), time() + variable_get('emfield_cache_duration', 3600)); return $response; } function emfield_set_error($error) { watchdog('emfield', $error, WATCHDOG_WARNING); } /** * Return an array of installed .inc files and/or loads them upon request. * This routine is modeled after drupal_system_listing() (and also depends on it). * It's major difference, however, is that it loads .inc files by default. * * @param $provider * Optional; name of the passed $provider to find (e.g. "youtube", "google", etc.). * @param $load * Defaults to TRUE; whether to include matching files into memory. * @return * An array of file objects optionally matching $provider. */ function emfield_system_list($module, $provider = NULL, $load = TRUE) { $files = drupal_system_listing("$provider\.inc", drupal_get_path('module', $module) . "/providers", 'name', 0); ksort($files); if ($load) { foreach ($files as $file) { emfield_include_list($file); } } return $files; } /** * Maintains a list of all loaded include files. * * @param $file * Optional; a file object (from emfield_system_list()) to be included. * @return * An array of all loaded includes (without the .inc extension). */ function emfield_include_list($file = NULL) { static $list = array(); if ($file && !isset($list[$file->name])) { include_once('./' . $file->filename); $list[$file->name] = $file->name; } return $list; } /** * Determine whether an include implements a hook, cf. module_hook. * * @param $provider * The name of the provider file (without the .inc extension), such as 'youtube' or 'google'. * @param $hook * The name of the hook (e.g. "thumbnail", "settings", etc.). * @return * TRUE if the provider is loaded and the hook is implemented. */ function emfield_include_hook($module, $provider, $hook) { return function_exists($module . '_' . $provider .'_'. $hook); } /** * Invoke hook in a particular include. * * @param $module * the helper module * @param $provider * The name of the provider (without the .inc extension). * @param $hook * The name of the hook (e.g. "settings", "thumbnail", etc.). * @param ... * Arguments to pass to the hook implementation. * @return * The return value of the hook implementation. */ function emfield_include_invoke() { $args = func_get_args(); $module = array_shift($args); $provider = array_shift($args); $hook = array_shift($args); $function = $module . '_' . $provider . '_' . $hook; emfield_system_list($module, $provider); return emfield_include_hook($module, $provider, $hook) ? call_user_func_array($function, $args) : NULL; } /** * Custom filter for provider NOT NULL */ function emfield_views_handler_filter_is_not_null($op, $filter, $filterinfo, &$query) { if ($op == 'handler') { $query->ensure_table($filterinfo['table']); if ($filter['value']) { $qs = "%s.%s <> '' AND %s.%s IS NOT NULL"; } else { $qs = "%s.%s = '' OR %s.%s IS NULL"; } $query->add_where($qs, $filterinfo['table'], $filterinfo['content_db_info']['columns']['provider']['column'], $filterinfo['table'], $filterinfo['content_db_info']['columns']['provider']['column']); } } /** * Create a list of providers. */ function emfield_views_handler_filter_provider_list($op) { $providers = array(); foreach (emfield_system_list('video_cck') as $provider => $info) { $providers[$provider] = $info->name; } return $providers; } /** * Views handler for the provider list filter. */ function emfield_views_handler_filter_provider($op, $filter, $filterinfo, &$query) { if ($op == 'handler') { $query->ensure_table($filterinfo['table']); if ($filter['operator'] == 'OR') { foreach ($filter['value'] as $provider) { $items[] = "%s.%s = '$provider'"; $where[] = $filterinfo['table']; $where[] = $filterinfo['content_db_info']['columns']['provider']['column']; } $qs = implode(' OR ', $items); } else { foreach ($filter['value'] as $provider) { $items[] = "%s.%s <> '$provider'"; $where[] = $filterinfo['table']; $where[] = $filterinfo['content_db_info']['columns']['provider']['column']; } $qs = implode(' AND ', $items); } $query->add_where($qs, $where); } } /** * Handle the provider argument. This is called from a wrapper that includes the module. */ function _emfield_handler_arg_provider($op, &$query, $argtype, $arg = '', $module = '') { if ($op == 'filter') { $field_name = substr($argtype['type'], 10); } else { $field_name = substr($argtype, 10); } $field = content_fields($field_name); $db_info = content_database_info($field); $main_column = $db_info['columns']['provider']; // The table name used here is the Views alias for the table, not the actual // table name. $table = 'node_data_'. $field['field_name']; switch($op) { case 'summary': $query->ensure_table($table); $query->add_field($main_column['column'], $table); $query->add_groupby($table .'.'. $main_column['column']); return array('field' => $table .'.'. $main_column['column']); case 'sort': $query->ensure_table($table); $query->add_orderby($table, $main_column['column'], $argtype); break; case 'filter': $query->ensure_table($table); $where = db_escape_string($arg); $query->add_where($table . '.' . $main_column['column'] . " = '%s'", $where); break; case 'link': $provider = emfield_system_list($module, $query->$main_column['column']); $info = emfield_include_invoke($module, $provider[$query]->name, 'info'); $title = $info['name']; return l($title, $arg .'/'. $query->$main_column['column']); case 'title': $provider = emfield_system_list($module, $query); $info = emfield_include_invoke($module, $provider[$query]->name, 'info'); $title = $info['name']; return $title ? $title : check_plain($query); } }