View source
<?php
define('CONTENT_DB_STORAGE_PER_FIELD', 0);
define('CONTENT_DB_STORAGE_PER_CONTENT_TYPE', 1);
define('CONTENT_CALLBACK_NONE', 0x1);
define('CONTENT_CALLBACK_DEFAULT', 0x2);
define('CONTENT_CALLBACK_CUSTOM', 0x4);
define('CONTENT_HANDLE_CORE', 0x1);
define('CONTENT_HANDLE_MODULE', 0x2);
require_once dirname(__FILE__) . '/includes/content.token.inc';
function content_help($path, $arg) {
switch ($path) {
case 'admin/help#content':
$output = '<p>' . t('The content module, a required component of the Content Construction Kit (CCK), allows administrators to associate custom fields with content types. In Drupal, content types are used to define the characteristics of a post, including the title and description of the fields displayed on its add and edit pages. Using the content module (and the other helper modules included in CCK), custom fields beyond the default "Title" and "Body" may be added. CCK features are accessible through tabs on the <a href="@content-types">content types administration page</a>. (See the <a href="@node-help">node module help page</a> for more information about content types.)', array(
'@content-types' => url('admin/content/types'),
'@node-help' => url('admin/help/node'),
)) . '</p>';
$output .= '<p>' . t('When adding a custom field to a content type, you determine its type (whether it will contain text, numbers, or references to other objects) and how it will be displayed (either as a text field or area, a select box, checkbox, radio button, or autocompleting field). A field may have multiple values (i.e., a "person" may have multiple e-mail addresses) or a single value (i.e., an "employee" has a single employee identification number). As you add and edit fields, CCK automatically adjusts the structure of the database as necessary. CCK also provides a number of other features, including intelligent caching for your custom data, an import and export facility for content type definitions, and integration with other contributed modules.') . '</p>';
$output .= '<p>' . t('Custom field types are provided by a set of optional modules included with CCK (each module provides a different type). The <a href="@modules">modules page</a> allows you to enable or disable CCK components. A default installation of CCK includes:', array(
'@modules' => url('admin/build/modules'),
)) . '</p>';
$output .= '<ul>';
$output .= '<li>' . t('<em>number</em>, which adds numeric field types, in integer, decimal or floating point form. You may define a set of allowed inputs, or specify an allowable range of values. A variety of common formats for displaying numeric data are available.') . '</li>';
$output .= '<li>' . t("<em>text</em>, which adds text field types. A text field may contain plain text only, or optionally, may use Drupal's input format filters to securely manage rich text input. Text input fields may be either a single line (text field), multiple lines (text area), or for greater input control, a select box, checkbox, or radio buttons. If desired, CCK can validate the input to a set of allowed values.") . '</li>';
$output .= '<li>' . t('<em>nodereference</em>, which creates custom references between Drupal nodes. By adding a <em>nodereference</em> field and two different content types, for instance, you can easily create complex parent/child relationships between data (multiple "employee" nodes may contain a <em>nodereference</em> field linking to an "employer" node).') . '</li>';
$output .= '<li>' . t('<em>userreference</em>, which creates custom references to your sites\' user accounts. By adding a <em>userreference</em> field, you can create complex relationships between your site\'s users and posts. To track user involvement in a post beyond Drupal\'s standard <em>Authored by</em> field, for instance, add a <em>userreference</em> field named "Edited by" to a content type to store a link to an editor\'s user account page.') . '</li>';
$output .= '<li>' . t('<em>fieldgroup</em>, which creates collapsible fieldsets to hold a group of related fields. A fieldset may either be open or closed by default. The order of your fieldsets, and the order of fields within a fieldset, is managed via a drag-and-drop interface provided by content module.') . '</li>';
$output .= '</ul>';
$output .= '<p>' . t('For more information, see the online handbook entry for <a href="@handbook-cck">CCK</a> or the <a href="@project-cck">CCK project page</a>.', array(
'@handbook-cck' => 'http://drupal.org/handbook/modules/cck',
'@project-cck' => 'http://drupal.org/project/cck',
)) . '</p>';
return $output;
}
}
function content_flush_caches() {
return array(
content_cache_tablename(),
);
}
function content_init() {
drupal_add_css(drupal_get_path('module', 'content') . '/theme/content-module.css');
if (module_exists('diff') && !function_exists('content_diff')) {
module_load_include('inc', 'content', 'includes/content.diff');
}
}
function content_perm() {
return array(
'Use PHP input for field settings (dangerous - grant with care)',
);
}
function content_menu_alter(&$items) {
$items['admin/content/types']['page callback'] = 'content_types_overview';
$items['admin/content/types']['file'] = 'content.admin.inc';
$items['admin/content/types']['file path'] = drupal_get_path('module', 'content') . '/includes';
}
function content_menu() {
$items = array();
$items['admin/content/types/fields'] = array(
'title' => 'Fields',
'page callback' => 'content_fields_list',
'access arguments' => array(
'administer content types',
),
'file' => 'includes/content.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['content/js_add_more'] = array(
'page callback' => 'content_add_more_js',
'access arguments' => array(
'access content',
),
'file' => 'includes/content.node_form.inc',
'type' => MENU_CALLBACK,
);
if (!defined('MAINTENANCE_MODE') && variable_get('content_schema_version', -1) >= 6007) {
foreach (node_get_types() as $type) {
$type_name = $type->type;
$content_type = content_types($type_name);
$type_url_str = $content_type['url_str'];
$items['admin/content/node-type/' . $type_url_str . '/fields'] = array(
'title' => 'Manage fields',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'content_field_overview_form',
$type_name,
),
'access arguments' => array(
'administer content types',
),
'file' => 'includes/content.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 1,
);
$items['admin/content/node-type/' . $type_url_str . '/display'] = array(
'title' => 'Display fields',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'content_display_overview_form',
$type_name,
),
'access arguments' => array(
'administer content types',
),
'file' => 'includes/content.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 2,
);
$contexts = content_build_modes('_tabs');
foreach ($contexts as $key => $tab) {
$items['admin/content/node-type/' . $type_url_str . '/display/' . $key] = array(
'title' => $tab['title'],
'page arguments' => array(
'content_display_overview_form',
$type_name,
$key,
),
'access arguments' => array(
'administer content types',
),
'type' => $key == 'basic' ? MENU_DEFAULT_LOCAL_TASK : MENU_LOCAL_TASK,
'weight' => $key == 'basic' ? 0 : 1,
);
}
foreach ((array) $content_type['fields'] as $field) {
$field_name = $field['field_name'];
$items['admin/content/node-type/' . $type_url_str . '/fields/' . $field_name] = array(
'title' => $field['widget']['label'],
'page callback' => 'drupal_get_form',
'page arguments' => array(
'content_field_edit_form',
$type_name,
$field_name,
),
'access arguments' => array(
'administer content types',
),
'file' => 'includes/content.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/content/node-type/' . $type_url_str . '/fields/' . $field_name . '/remove'] = array(
'title' => 'Remove field',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'content_field_remove_form',
$type_name,
$field_name,
),
'access arguments' => array(
'administer content types',
),
'file' => 'includes/content.admin.inc',
'type' => MENU_CALLBACK,
);
}
}
}
return $items;
}
function content_elements() {
return array(
'content_multiple_values' => array(),
'content_field' => array(),
);
}
function content_theme() {
$path = drupal_get_path('module', 'content') . '/theme';
module_load_include('inc', 'content', 'theme/theme');
return array(
'content_field' => array(
'template' => 'content-field',
'arguments' => array(
'element' => NULL,
),
'path' => $path,
),
'content_overview_links' => array(
'arguments' => array(),
),
'content_field_overview_form' => array(
'template' => 'content-admin-field-overview-form',
'file' => 'theme.inc',
'path' => $path,
'arguments' => array(
'form' => NULL,
),
),
'content_display_overview_form' => array(
'template' => 'content-admin-display-overview-form',
'file' => 'theme.inc',
'path' => $path,
'arguments' => array(
'form' => NULL,
),
),
'content_exclude' => array(
'arguments' => array(
'content' => NULL,
'object' => array(),
'context' => NULL,
),
),
'content_view_multiple_field' => array(
'arguments' => array(
'items' => NULL,
'field' => NULL,
'data' => NULL,
),
),
'content_multiple_values' => array(
'arguments' => array(
'element' => NULL,
),
),
);
}
function content_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'content') . '/includes/views',
);
}
function content_ctools_plugin_directory($module, $plugin) {
if ($module == 'ctools' && $plugin == 'content_types') {
return 'includes/panels/' . $plugin;
}
}
function content_load(&$node) {
$cid = 'content:' . $node->nid . ':' . $node->vid;
if ($cached = cache_get($cid, content_cache_tablename())) {
foreach ($cached->data as $key => $value) {
$node->{$key} = $value;
}
}
else {
$default_additions = _content_field_invoke_default('load', $node);
if ($default_additions) {
foreach ($default_additions as $key => $value) {
$node->{$key} = $value;
}
}
$additions = _content_field_invoke('load', $node);
if ($additions) {
foreach ($additions as $key => $value) {
$node->{$key} = $value;
$default_additions[$key] = $value;
}
}
cache_set($cid, $default_additions, content_cache_tablename());
}
}
function content_validate(&$node, $form = NULL) {
_content_field_invoke('validate', $node, $form);
_content_field_invoke_default('validate', $node, $form);
}
function content_presave(&$node) {
_content_field_invoke('presave', $node);
_content_field_invoke_default('presave', $node);
}
function content_insert(&$node) {
_content_field_invoke('insert', $node);
_content_field_invoke_default('insert', $node);
}
function content_update(&$node) {
_content_field_invoke('update', $node);
_content_field_invoke_default('update', $node);
cache_clear_all('content:' . $node->nid . ':' . $node->vid, content_cache_tablename());
}
function content_delete(&$node) {
_content_field_invoke('delete', $node);
_content_field_invoke_default('delete', $node);
cache_clear_all('content:' . $node->nid . ':', content_cache_tablename(), TRUE);
}
function content_delete_revision(&$node) {
_content_field_invoke('delete revision', $node);
_content_field_invoke_default('delete revision', $node);
cache_clear_all('content:' . $node->nid . ':' . $node->vid, content_cache_tablename());
}
function content_view(&$node, $teaser = FALSE, $page = FALSE) {
_content_field_invoke('sanitize', $node, $teaser, $page);
$additions = _content_field_invoke_default('view', $node, $teaser, $page);
$old = isset($node->content) ? (array) $node->content : array();
$node->content = array_merge($old, $additions);
}
function content_view_field($field, $node, $teaser = FALSE, $page = FALSE) {
$output = '';
if (isset($node->{$field}['field_name'])) {
$items = $node->{$field}['field_name'];
$node->build_mode = isset($node->build_mode) ? $node->build_mode : NODE_BUILD_NORMAL;
$field_types = _content_field_types();
$module = $field_types[$field['type']]['module'];
$function = $module . '_field';
if (function_exists($function)) {
$function('sanitize', $node, $field, $items, $teaser, $page);
$node->{$field}['field_name'] = $items;
}
$view = content_field('view', $node, $field, $items, $teaser, $page);
$output = drupal_render($view[$field['field_name']]['field']);
}
return $output;
}
function content_alter(&$node, $teaser = FALSE, $page = FALSE) {
_content_field_invoke_default('alter', $node, $teaser, $page);
}
function content_prepare_translation(&$node) {
$default_additions = _content_field_invoke_default('prepare translation', $node);
$additions = _content_field_invoke('prepare translation', $node);
$node = (object) array_merge((array) $node, $default_additions, $additions);
}
function content_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if (isset($node->type)) {
$type = content_types($node->type);
if (!empty($type['fields'])) {
$callback = 'content_' . str_replace(' ', '_', $op);
if (function_exists($callback)) {
$callback($node, $a3, $a4);
}
}
if ($op == 'view') {
$node->content['#pre_render'][] = 'content_alter_extra_weights';
$node->content['#content_extra_fields'] = $type['extra'];
}
}
}
function content_form_alter(&$form, $form_state, $form_id) {
if (isset($form['type']) && isset($form['#node']) && $form['type']['#value'] . '_node_form' == $form_id) {
$type = content_types($form['#node']->type);
if (!empty($type['fields'])) {
module_load_include('inc', 'content', 'includes/content.node_form');
$form = array_merge($form, content_form($form, $form_state));
}
$form['#pre_render'][] = 'content_alter_extra_weights';
$form['#content_extra_fields'] = $type['extra'];
}
}
function content_alter_extra_weights($elements) {
if (isset($elements['#content_extra_fields'])) {
foreach ($elements['#content_extra_fields'] as $key => $value) {
if (!isset($elements['#build_id']) && isset($value['view']) && isset($elements[$value['view']])) {
$elements[$value['view']]['#weight'] = $value['weight'];
}
elseif (isset($elements[$key])) {
$elements[$key]['#weight'] = $value['weight'];
}
}
}
return $elements;
}
function content_add_more_submit_proxy($form, &$form_state) {
module_load_include('inc', 'content', 'includes/content.node_form');
content_add_more_submit($form, $form_state);
}
function theme_content_multiple_values($element) {
$field_name = $element['#field_name'];
$field = content_fields($field_name);
$output = '';
if ($field['multiple'] >= 1) {
$table_id = $element['#field_name'] . '_values';
$order_class = $element['#field_name'] . '-delta-order';
$required = !empty($element['#required']) ? '<span class="form-required" title="' . t('This field is required.') . '">*</span>' : '';
$header = array(
array(
'data' => t('!title: !required', array(
'!title' => $element['#title'],
'!required' => $required,
)),
'colspan' => 2,
),
t('Order'),
);
$rows = array();
$items = array();
foreach (element_children($element) as $key) {
if ($key !== $element['#field_name'] . '_add_more') {
$items[] =& $element[$key];
}
}
usort($items, '_content_sort_items_value_helper');
foreach ($items as $key => $item) {
$item['_weight']['#attributes']['class'] = $order_class;
$delta_element = drupal_render($item['_weight']);
$cells = array(
array(
'data' => '',
'class' => 'content-multiple-drag',
),
drupal_render($item),
array(
'data' => $delta_element,
'class' => 'delta-order',
),
);
$rows[] = array(
'data' => $cells,
'class' => 'draggable',
);
}
$output .= theme('table', $header, $rows, array(
'id' => $table_id,
'class' => 'content-multiple-table',
));
$output .= $element['#description'] ? '<div class="description">' . $element['#description'] . '</div>' : '';
$output .= drupal_render($element[$element['#field_name'] . '_add_more']);
drupal_add_tabledrag($table_id, 'order', 'sibling', $order_class);
}
else {
foreach (element_children($element) as $key) {
$output .= drupal_render($element[$key]);
}
}
return $output;
}
function content_notify($op, $module) {
switch ($op) {
case 'install':
content_clear_type_cache();
break;
case 'uninstall':
module_load_include('inc', 'content', 'includes/content.crud');
content_module_delete($module);
break;
case 'enable':
content_associate_fields($module);
content_clear_type_cache();
break;
case 'disable':
if (variable_get('content_schema_version', -1) < 6007) {
return FALSE;
}
db_query("UPDATE {" . content_field_tablename() . "} SET active=0 WHERE module='%s'", $module);
db_query("UPDATE {" . content_instance_tablename() . "} SET widget_active=0 WHERE widget_module='%s'", $module);
content_clear_type_cache(TRUE);
break;
}
}
function content_associate_fields($module) {
if (variable_get('content_schema_version', -1) < 6007) {
return FALSE;
}
$module_fields = module_invoke($module, 'field_info');
if ($module_fields) {
foreach ($module_fields as $name => $field_info) {
watchdog('content', 'Updating field type %type with module %module.', array(
'%type' => $name,
'%module' => $module,
));
db_query("UPDATE {" . content_field_tablename() . "} SET module = '%s', active = %d WHERE type = '%s'", $module, 1, $name);
}
}
$module_widgets = module_invoke($module, 'widget_info');
if ($module_widgets) {
foreach ($module_widgets as $name => $widget_info) {
watchdog('content', 'Updating widget type %type with module %module.', array(
'%type' => $name,
'%module' => $module,
));
db_query("UPDATE {" . content_instance_tablename() . "} SET widget_module = '%s', widget_active = %d WHERE widget_type = '%s'", $module, 1, $name);
}
}
$fields_set = array();
module_load_include('install', 'content');
$types = content_types_install();
foreach ($types as $type_name => $fields) {
foreach ($fields as $field) {
if ($field['module'] == $module && !in_array($field['field_name'], $fields_set)) {
$columns = (array) module_invoke($field['module'], 'field_settings', 'database columns', $field);
db_query("UPDATE {" . content_field_tablename() . "} SET db_columns = '%s' WHERE field_name = '%s'", serialize($columns), $field['field_name']);
$fields_set[] = $field['field_name'];
}
}
}
}
function content_field($op, &$node, $field, &$items, $teaser, $page) {
switch ($op) {
case 'validate':
break;
case 'presave':
if (!empty($node->devel_generate)) {
include_once './' . drupal_get_path('module', 'content') . '/includes/content.devel.inc';
content_generate_fields($node, $field);
$items = $node->{$field['field_name']};
}
if (empty($items) && !isset($node->nid)) {
foreach (array_keys($field['columns']) as $column) {
$items[0][$column] = NULL;
}
$node->{$field}['field_name'] = $items;
}
unset($items[$field['field_name'] . '_add_more']);
if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) {
$items = _content_sort_items($field, $items);
}
$items = content_set_empty($field, $items);
break;
case 'view':
$addition = array();
if ($node->build_mode == NODE_BUILD_PREVIEW && content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) {
if (content_handle('widget', 'multiple values', $field) == CONTENT_HANDLE_CORE) {
$items = _content_sort_items($field, $items);
}
$items = content_set_empty($field, $items);
}
if ($node->build_mode === NODE_BUILD_NORMAL || $node->build_mode == NODE_BUILD_PREVIEW) {
$context = $teaser ? 'teaser' : 'full';
}
else {
$context = $node->build_mode;
}
$formatter_name = isset($field['display_settings'][$context]) && isset($field['display_settings'][$context]['format']) ? $field['display_settings'][$context]['format'] : 'default';
if ($formatter = _content_get_formatter($formatter_name, $field['type'])) {
$theme = $formatter['module'] . '_formatter_' . $formatter_name;
$single = content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE;
$label_display = isset($field['display_settings']['label']['format']) ? $field['display_settings']['label']['format'] : 'above';
if ($context == NODE_BUILD_SEARCH_INDEX) {
$label_display = 'hidden';
}
$element = array(
'#type' => 'content_field',
'#title' => check_plain(t($field['widget']['label'])),
'#field_name' => $field['field_name'],
'#access' => $formatter_name != 'hidden' && content_access('view', $field, NULL, $node),
'#label_display' => $label_display,
'#node' => $node,
'#teaser' => $teaser,
'#page' => $page,
'#context' => $context,
'#single' => $single,
'items' => array(),
);
foreach ($items as $delta => $item) {
$element['items'][$delta] = array(
'#item' => $item,
'#weight' => $delta,
);
}
$format_info = array(
'#theme' => $theme,
'#field_name' => $field['field_name'],
'#type_name' => $node->type,
'#formatter' => $formatter_name,
'#node' => $node,
);
if ($single) {
foreach ($items as $delta => $item) {
$element['items'][$delta] += $format_info;
$element['items'][$delta]['#item']['#delta'] = $delta;
}
}
else {
$element['items'] += $format_info;
}
$wrapper = array(
'field' => $element,
'#weight' => $field['widget']['weight'],
'#post_render' => array(
'content_field_wrapper_post_render',
),
'#field_name' => $field['field_name'],
'#type_name' => $node->type,
'#context' => $context,
);
$addition = array(
$field['field_name'] => $wrapper,
);
}
return $addition;
case 'alter':
$wrapper = NULL;
if (isset($node->content[$field['field_name']])) {
$wrapper = $node->content[$field['field_name']];
}
elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) {
$wrapper = $node->content[$group_name]['group'][$field['field_name']];
}
if ($wrapper) {
$element = $wrapper['field'];
if (isset($element['#single'])) {
if (!empty($element['#single'])) {
foreach (element_children($element['items']) as $delta) {
$items[$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : '';
}
}
elseif (isset($element['items']['#children'])) {
$items[0]['view'] = $element['items']['#children'];
}
}
else {
$items[0]['view'] = '';
}
}
break;
case 'preprocess_node':
$addition = array(
$field['field_name'] . '_rendered' => '',
);
$wrapper = NULL;
if (isset($node->content[$field['field_name']])) {
$wrapper = $node->content[$field['field_name']];
}
elseif (module_exists('fieldgroup') && ($group_name = fieldgroup_get_group($node->type, $field['field_name'])) && isset($node->content[$group_name]['group'][$field['field_name']])) {
$wrapper = $node->content[$group_name]['group'][$field['field_name']];
}
if ($wrapper) {
$addition[$field['field_name'] . '_rendered'] = isset($wrapper['#children']) ? $wrapper['#children'] : '';
}
return $addition;
case 'prepare translation':
$addition = array();
if (isset($node->translation_source->{$field}['field_name'])) {
$addition[$field['field_name']] = $node->translation_source->{$field}['field_name'];
}
return $addition;
}
}
function content_set_empty($field, $items) {
$filtered = array();
$function = $field['module'] . '_content_is_empty';
foreach ((array) $items as $delta => $item) {
if (!$function($item, $field)) {
$filtered[] = $item;
}
}
$empty = array();
foreach (array_keys($field['columns']) as $column) {
$empty[$column] = NULL;
}
$pad = $field['multiple'] > 1 ? $field['multiple'] : 1;
$filtered = array_pad($filtered, $pad, $empty);
return $filtered;
}
function _content_sort_items($field, $items) {
if ($field['multiple'] >= 1 && isset($items[0]['_weight'])) {
usort($items, '_content_sort_items_helper');
foreach ($items as $delta => $item) {
if (is_array($items[$delta])) {
unset($items[$delta]['_weight']);
}
}
}
return $items;
}
function _content_sort_items_helper($a, $b) {
$a_weight = is_array($a) && isset($a['_weight']) ? $a['_weight'] : 0;
$b_weight = is_array($b) && isset($b['_weight']) ? $b['_weight'] : 0;
if ($a_weight == $b_weight) {
return 0;
}
return $a_weight < $b_weight ? -1 : 1;
}
function _content_sort_items_value_helper($a, $b) {
$a_weight = is_array($a) && isset($a['_weight']['#value']) ? $a['_weight']['#value'] : 0;
$b_weight = is_array($b) && isset($b['_weight']['#value']) ? $b['_weight']['#value'] : 0;
if ($a_weight == $b_weight) {
return 0;
}
return $a_weight < $b_weight ? -1 : 1;
}
function content_storage($op, $node) {
if (variable_get('content_schema_version', -1) < 6007) {
return FALSE;
}
$type_name = $node->type;
$type = content_types($type_name);
switch ($op) {
case 'load':
$additions = array();
foreach ($type['tables'] as $table) {
$schema = drupal_get_schema($table);
if (!$schema['content fields']) {
continue;
}
$query = 'SELECT * FROM {' . $table . '} WHERE vid = %d';
$result = isset($schema['fields']['delta']) ? db_query($query . ' ORDER BY delta', $node->vid) : db_query_range($query, $node->vid, 0, 1);
while ($row = db_fetch_array($result)) {
foreach ($schema['content fields'] as $field_name) {
$item = array();
$field = content_fields($field_name, $type_name);
$db_info = content_database_info($field);
foreach ($db_info['columns'] as $column => $attributes) {
$item[$column] = $row[$attributes['column']];
}
if (!isset($additions[$field_name])) {
$additions[$field_name] = array();
}
$additions[$field_name][] = $item;
}
}
}
return $additions;
case 'insert':
case 'update':
foreach ($type['tables'] as $table) {
$schema = drupal_get_schema($table);
$record = array();
foreach ($schema['content fields'] as $field_name) {
if (isset($node->{$field_name})) {
$field = content_fields($field_name, $type_name);
if ($field['multiple']) {
continue;
}
$db_info = content_database_info($field);
foreach ($db_info['columns'] as $column => $attributes) {
$record[$attributes['column']] = $node->{$field_name}[0][$column];
}
}
}
if (count($record) || empty($schema['content fields'])) {
$record['nid'] = $node->nid;
$record['vid'] = $node->vid;
if (db_result(db_query("SELECT COUNT(*) FROM {" . $table . "} WHERE vid = %d", $node->vid))) {
content_write_record($table, $record, array(
'vid',
));
}
else {
content_write_record($table, $record);
}
}
}
foreach ($type['fields'] as $field) {
if ($field['multiple'] && isset($node->{$field}['field_name'])) {
$db_info = content_database_info($field);
if ($op == 'update') {
db_query('DELETE FROM {' . $db_info['table'] . '} WHERE vid = %d', $node->vid);
}
foreach ($node->{$field}['field_name'] as $delta => $item) {
$record = array();
foreach ($db_info['columns'] as $column => $attributes) {
$record[$attributes['column']] = $item[$column];
}
$record['nid'] = $node->nid;
$record['vid'] = $node->vid;
$record['delta'] = $delta;
content_write_record($db_info['table'], $record);
}
}
}
break;
case 'delete':
foreach ($type['tables'] as $table) {
db_query('DELETE FROM {' . $table . '} WHERE nid = %d', $node->nid);
}
break;
case 'delete revision':
foreach ($type['tables'] as $table) {
db_query('DELETE FROM {' . $table . '} WHERE vid = %d', $node->vid);
}
break;
}
}
function content_write_record($table, &$object, $update = array()) {
if (is_string($update)) {
$update = array(
$update,
);
}
if (is_array($object)) {
$object = (object) $object;
$array = TRUE;
}
else {
$array = FALSE;
}
$schema = drupal_get_schema($table);
if (empty($schema)) {
return FALSE;
}
$fields = $defs = $values = $serials = $placeholders = array();
foreach ($schema['fields'] as $field => $info) {
if ($info['type'] == 'serial' && count($update)) {
continue;
}
if (!isset($object->{$field}) && !count($update) && isset($info['default'])) {
$object->{$field} = $info['default'];
}
if ($info['type'] == 'serial') {
$serials[] = $field;
unset($object->{$field});
}
if (isset($object->{$field}) || array_key_exists($field, $object)) {
$fields[] = $field;
if (isset($object->{$field})) {
$placeholders[] = db_type_placeholder($info['type']);
if (empty($info['serialize'])) {
$values[] = $object->{$field};
}
else {
$values[] = serialize($object->{$field});
}
}
else {
$placeholders[] = 'NULL';
}
}
}
$query = '';
if (!count($update)) {
$query = "INSERT INTO {" . $table . "} (" . implode(', ', $fields) . ') VALUES (' . implode(', ', $placeholders) . ')';
$return = SAVED_NEW;
}
else {
$query = '';
foreach ($fields as $id => $field) {
if ($query) {
$query .= ', ';
}
$query .= $field . ' = ' . $placeholders[$id];
}
foreach ($update as $key) {
$conditions[] = "{$key} = " . db_type_placeholder($schema['fields'][$key]['type']);
$values[] = $object->{$key};
}
$query = "UPDATE {" . $table . "} SET {$query} WHERE " . implode(' AND ', $conditions);
$return = SAVED_UPDATED;
}
if (db_query($query, $values)) {
if ($serials) {
foreach ($serials as $field) {
$object->{$field} = db_last_insert_id($table, $field);
}
}
if ($array) {
$object = (array) $object;
}
return $return;
}
return FALSE;
}
function _content_field_invoke($op, &$node, $teaser = NULL, $page = NULL) {
$type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
$type = content_types($type_name);
$field_types = _content_field_types();
$return = array();
foreach ($type['fields'] as $field) {
$items = isset($node->{$field}['field_name']) ? $node->{$field}['field_name'] : array();
unset($items[$field['field_name'] . '_add_more']);
$module = $field_types[$field['type']]['module'];
$function = $module . '_field';
if (function_exists($function)) {
$result = $function($op, $node, $field, $items, $teaser, $page);
if (is_array($result)) {
$return = array_merge($return, $result);
}
else {
if (isset($result)) {
$return[] = $result;
}
}
}
if (isset($node->{$field}['field_name']) || count($items)) {
$node->{$field}['field_name'] = $items;
}
}
return $return;
}
function _content_field_invoke_default($op, &$node, $teaser = NULL, $page = NULL) {
$type_name = is_string($node) ? $node : (is_array($node) ? $node['type'] : $node->type);
$type = content_types($type_name);
$field_types = _content_field_types();
$return = array();
if (in_array($op, array(
'load',
'insert',
'update',
'delete',
'delete revision',
))) {
return content_storage($op, $node);
}
else {
foreach ($type['fields'] as $field) {
$items = isset($node->{$field}['field_name']) ? $node->{$field}['field_name'] : array();
$result = content_field($op, $node, $field, $items, $teaser, $page);
if (is_array($result)) {
$return = array_merge($return, $result);
}
else {
if (isset($result)) {
$return[] = $result;
}
}
if (isset($node->{$field}['field_name'])) {
$node->{$field}['field_name'] = $items;
}
}
}
return $return;
}
function content_types($type_name = NULL) {
$type_name = !empty($type_name) ? str_replace('-', '_', $type_name) : NULL;
$info = _content_type_info();
if (isset($info['content types'])) {
if (!isset($type_name)) {
return $info['content types'];
}
if (isset($info['content types'][$type_name])) {
return $info['content types'][$type_name];
}
}
return array(
'tables' => array(),
'fields' => array(),
'extra' => array(),
);
}
function content_fields($field_name = NULL, $content_type_name = NULL) {
$info = _content_type_info();
if (isset($info['fields'])) {
if (empty($field_name)) {
return $info['fields'];
}
if (isset($info['fields'][$field_name])) {
if (empty($content_type_name)) {
return $info['fields'][$field_name];
}
if (isset($info['content types'][$content_type_name]['fields'][$field_name])) {
return $info['content types'][$content_type_name]['fields'][$field_name];
}
}
}
}
function _content_field_types() {
$info = _content_type_info();
return isset($info['field types']) ? $info['field types'] : array();
}
function _content_widget_types() {
$info = _content_type_info();
return isset($info['widget types']) ? $info['widget types'] : array();
}
function _content_get_formatter($formatter_name, $field_type) {
$field_types = _content_field_types();
$formatters = $field_types[$field_type]['formatters'];
if (!isset($formatters[$formatter_name]) && $formatter_name != 'hidden') {
$formatter_name = 'default';
}
return isset($formatters[$formatter_name]) ? $formatters[$formatter_name] : FALSE;
}
function _content_type_info($reset = FALSE) {
global $language;
static $info;
if ($reset || !isset($info)) {
if (variable_get('content_schema_version', -1) < 6007) {
return array();
}
if (!$reset && ($cached = cache_get('content_type_info:' . $language->language, content_cache_tablename()))) {
$info = $cached->data;
}
else {
$info = array(
'field types' => array(),
'widget types' => array(),
'fields' => array(),
'content types' => array(),
);
foreach (module_list() as $module) {
$module_field_types = module_invoke($module, 'field_info');
if ($module_field_types) {
foreach ($module_field_types as $name => $field_info) {
$db_name = substr($name, 0, 32);
$info['field types'][$db_name] = $field_info;
$info['field types'][$db_name]['module'] = $module;
$info['field types'][$db_name]['formatters'] = array();
}
}
}
foreach (module_list() as $module) {
if ($module_widgets = module_invoke($module, 'widget_info')) {
foreach ($module_widgets as $name => $widget_info) {
$db_name = substr($name, 0, 32);
$info['widget types'][$db_name] = $widget_info;
$info['widget types'][$db_name]['module'] = $module;
$info['widget types'][$db_name]['field types'] = array();
foreach ($widget_info['field types'] as $field_type) {
$field_type_db_name = substr($field_type, 0, 32);
if (isset($info['field types'][$field_type_db_name])) {
$info['widget types'][$db_name]['field types'][] = $field_type_db_name;
}
}
}
}
if ($module_formatters = module_invoke($module, 'field_formatter_info')) {
foreach ($module_formatters as $name => $formatter_info) {
foreach ($formatter_info['field types'] as $field_type) {
$db_name = substr($field_type, 0, 32);
if (isset($info['field types'][$db_name])) {
$info['field types'][$db_name]['formatters'][$name] = $formatter_info;
$info['field types'][$db_name]['formatters'][$name]['module'] = $module;
}
}
}
}
}
module_load_include('inc', 'content', 'includes/content.crud');
foreach (node_get_types('types', NULL, TRUE) as $type_name => $data) {
$type = (array) $data;
$type['url_str'] = str_replace('_', '-', $type['type']);
$type['fields'] = array();
$type['tables'] = array();
if ($fields = content_field_instance_read(array(
'type_name' => $type_name,
))) {
foreach ($fields as $field) {
$db_info = content_database_info($field);
$type['tables'][$db_info['table']] = $db_info['table'];
$field_strings = array(
'widget_label' => $field['widget']['label'],
'widget_description' => $field['widget']['description'],
);
drupal_alter('content_field_strings', $field_strings, $field['type_name'], $field['field_name']);
$field['widget']['label'] = $field_strings['widget_label'];
$field['widget']['description'] = $field_strings['widget_description'];
$type['fields'][$field['field_name']] = $field;
$info['fields'][$field['field_name']] = $field;
}
$table = _content_tablename($type['type'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
$type['tables'][$table] = $table;
}
$extra = module_invoke_all('content_extra_fields', $type_name);
drupal_alter('content_extra_fields', $extra, $type_name);
foreach (variable_get('content_extra_weights_' . $type_name, array()) as $key => $value) {
if (isset($extra[$key])) {
$extra[$key]['weight'] = $value;
}
}
$type['extra'] = $extra;
$info['content types'][$type_name] = $type;
}
cache_set('content_type_info:' . $language->language, $info, content_cache_tablename());
}
}
return $info;
}
function content_node_type($op, $info) {
switch ($op) {
case 'insert':
module_load_include('inc', 'content', 'includes/content.crud');
content_type_create($info);
break;
case 'update':
module_load_include('inc', 'content', 'includes/content.crud');
content_type_update($info);
break;
case 'delete':
module_load_include('inc', 'content', 'includes/content.crud');
content_type_delete($info);
break;
}
}
function content_clear_type_cache($rebuild_schema = FALSE) {
cache_clear_all('*', content_cache_tablename(), TRUE);
_content_type_info(TRUE);
if ($rebuild_schema) {
$schema = drupal_get_schema(NULL, TRUE);
}
if (module_exists('views')) {
module_load_include('module', 'views');
views_invalidate_cache();
}
}
function content_database_info($field) {
$db_info = array();
if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) {
$db_info['table'] = _content_tablename($field['field_name'], CONTENT_DB_STORAGE_PER_FIELD);
}
else {
$db_info['table'] = _content_tablename($field['type_name'], CONTENT_DB_STORAGE_PER_CONTENT_TYPE);
}
$db_info['columns'] = (array) $field['columns'];
foreach ($db_info['columns'] as $column_name => $attributes) {
$db_info['columns'][$column_name]['column'] = $field['field_name'] . '_' . $column_name;
}
return $db_info;
}
function content_storage_type($field) {
if ($field['multiple'] > 0) {
return CONTENT_DB_STORAGE_PER_FIELD;
}
else {
module_load_include('inc', 'content', 'includes/content.crud');
$instances = content_field_instance_read(array(
'field_name' => $field['field_name'],
));
if (count($instances) > 1) {
return CONTENT_DB_STORAGE_PER_FIELD;
}
}
return CONTENT_DB_STORAGE_PER_CONTENT_TYPE;
}
function content_transpose_array_rows_cols($array) {
$result = array();
if (is_array($array)) {
foreach ($array as $key1 => $value1) {
if (is_array($value1)) {
foreach ($value1 as $key2 => $value2) {
if (!isset($result[$key2])) {
$result[$key2] = array();
}
$result[$key2][$key1] = $value2;
}
}
}
}
return $result;
}
function content_array_flatten($array) {
$result = array();
if (is_array($array)) {
foreach ($array as $key => $value) {
if (is_array($value)) {
$result += content_array_flatten($value);
}
else {
$result[$key] = $value;
}
}
}
return $result;
}
function content_allowed_values($field, $flatten = TRUE) {
static $allowed_values;
$cid = $field['field_name'] . ':' . ($flatten ? '1' : '0');
if (isset($allowed_values[$cid])) {
return $allowed_values[$cid];
}
$allowed_values[$cid] = array();
if (isset($field['allowed_values_php'])) {
ob_start();
$result = eval($field['allowed_values_php']);
if (is_array($result)) {
if ($flatten) {
$result = content_array_flatten($result);
}
$allowed_values[$cid] = $result;
}
ob_end_clean();
}
if (empty($allowed_values[$cid]) && isset($field['allowed_values'])) {
$list = explode("\n", $field['allowed_values']);
$list = array_map('trim', $list);
$list = array_filter($list, 'strlen');
foreach ($list as $opt) {
$opt = content_filter_xss($opt);
if (strpos($opt, '|') !== FALSE) {
list($key, $value) = explode('|', $opt);
$allowed_values[$cid][$key] = isset($value) && $value !== '' ? $value : $key;
}
else {
$allowed_values[$cid][$opt] = $opt;
}
}
drupal_alter('content_allowed_values', $allowed_values[$cid], $field);
}
return $allowed_values[$cid];
}
function content_allowed_values_filter_html(&$options) {
foreach ($options as $key => $opt) {
if (is_array($opt)) {
content_allowed_values_filter_html($options[$key]);
}
else {
$options[$key] = html_entity_decode(strip_tags($opt), ENT_QUOTES);
}
}
}
function content_filter_xss($string) {
return filter_xss($string, _content_filter_xss_allowed_tags());
}
function _content_filter_xss_allowed_tags() {
return array(
'a',
'b',
'big',
'code',
'del',
'em',
'i',
'ins',
'pre',
'q',
'small',
'span',
'strong',
'sub',
'sup',
'tt',
'ol',
'ul',
'li',
'p',
'br',
'img',
);
}
function _content_filter_xss_display_allowed_tags() {
return '<' . implode('> <', _content_filter_xss_allowed_tags()) . '>';
}
function content_format($field, $item, $formatter_name = 'default', $node = NULL) {
if (!is_array($field)) {
$field = content_fields($field);
}
if (content_access('view', $field, NULL, $node) && ($formatter = _content_get_formatter($formatter_name, $field['type']))) {
$theme = $formatter['module'] . '_formatter_' . $formatter_name;
$element = array(
'#theme' => $theme,
'#field_name' => $field['field_name'],
'#type_name' => isset($node->type) ? $node->type : '',
'#formatter' => $formatter_name,
'#node' => $node,
'#delta' => isset($item['#delta']) ? $item['#delta'] : NULL,
);
if (content_handle('formatter', 'multiple values', $formatter) == CONTENT_HANDLE_CORE) {
$items = array(
$item,
);
$function = $field['module'] . '_field';
if (function_exists($function)) {
$function('sanitize', $node, $field, $items, FALSE, FALSE);
}
$element['#item'] = $items[0];
}
else {
$items = $item;
$function = $field['module'] . '_field';
if (function_exists($function)) {
$function('sanitize', $node, $field, $items, FALSE, FALSE);
}
foreach ($items as $delta => $item) {
$element[$delta] = array(
'#item' => $item,
'#weight' => $delta,
);
}
}
return theme($theme, $element);
}
}
function content_build_modes($selector = NULL) {
static $info;
if (!isset($info)) {
$data = array();
foreach (module_implements('content_build_modes') as $module) {
$function = $module . '_content_build_modes';
$data = array_merge($data, (array) $function());
}
$flat = array();
foreach ($data as $tab) {
$flat += (array) $tab['build modes'];
}
$info = array(
'tabs' => $data,
'build modes' => $flat,
);
}
if ($selector === '_tabs') {
return $info['tabs'];
}
elseif (isset($selector) && isset($info['tabs'][$selector])) {
return isset($info['tabs'][$selector]) ? $info['tabs'][$selector]['build modes'] : array();
}
else {
return $info['build modes'];
}
}
function node_content_build_modes() {
return array(
'basic' => array(
'title' => t('Basic'),
'build modes' => array(
'teaser' => array(
'title' => t('Teaser'),
'views style' => TRUE,
),
'full' => array(
'title' => t('Full node'),
'views style' => TRUE,
),
),
),
'rss' => array(
'title' => t('RSS'),
'build modes' => array(
NODE_BUILD_RSS => array(
'title' => t('RSS'),
'views style' => FALSE,
),
),
),
);
}
function search_content_build_modes() {
return array(
'search' => array(
'title' => t('Search'),
'build modes' => array(
NODE_BUILD_SEARCH_INDEX => array(
'title' => t('Search Index'),
'views style' => FALSE,
),
NODE_BUILD_SEARCH_RESULT => array(
'title' => t('Search Result'),
'views style' => FALSE,
),
),
),
);
}
function book_content_build_modes() {
return array(
'print' => array(
'title' => t('Print'),
'build modes' => array(
NODE_BUILD_PRINT => array(
'title' => t('Print'),
'views style' => TRUE,
),
),
),
);
}
function _content_tablename($name, $storage, $version = NULL) {
if (is_null($version)) {
$version = variable_get('content_schema_version', 0);
}
if ($version < 1003) {
$version = 0;
}
else {
$version = 1003;
}
$name = str_replace('-', '_', $name);
switch ("{$version}-{$storage}") {
case '0-' . CONTENT_DB_STORAGE_PER_CONTENT_TYPE:
return "node_{$name}";
case '0-' . CONTENT_DB_STORAGE_PER_FIELD:
return "node_data_{$name}";
case '1003-' . CONTENT_DB_STORAGE_PER_CONTENT_TYPE:
return "content_type_{$name}";
case '1003-' . CONTENT_DB_STORAGE_PER_FIELD:
return "content_{$name}";
}
}
function content_field_tablename($version = NULL) {
if (is_null($version)) {
$version = variable_get('content_schema_version', 0);
}
return $version < 6001 ? 'node_field' : 'content_node_field';
}
function content_instance_tablename($version = NULL) {
if (is_null($version)) {
$version = variable_get('content_schema_version', 0);
}
return $version < 6001 ? 'node_field_instance' : 'content_node_field_instance';
}
function content_cache_tablename() {
if (variable_get('content_schema_version', -1) < 6000) {
return 'cache';
}
else {
return 'cache_content';
}
}
function content_table_schema($field = NULL) {
$schema = array(
'fields' => array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'vid',
),
'indexes' => array(
'nid' => array(
'nid',
),
),
);
if (!empty($field['multiple'])) {
$schema['fields']['delta'] = array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
);
$schema['primary key'][] = 'delta';
}
$schema['content fields'] = array();
if (!empty($field['columns'])) {
foreach ($field['columns'] as $column => $attributes) {
$column_name = $field['field_name'] . '_' . $column;
if (isset($attributes['index']) && $attributes['index']) {
$schema['indexes'][$column_name] = array(
$column_name,
);
unset($attributes['index']);
}
unset($attributes['column']);
unset($attributes['sortable']);
$schema['fields'][$column_name] = $attributes;
}
$schema['content fields'][] = $field['field_name'];
}
return $schema;
}
function content_db_index_exists($table, $name) {
global $db_type;
if ($db_type == 'mysql' || $db_type == 'mysqli') {
if (version_compare(db_version(), '5.0.3') < 0) {
$result = db_query('SHOW INDEX FROM {' . $table . '}');
while ($row = db_fetch_array($result)) {
if ($row['Key_name'] == $name) {
return TRUE;
}
}
return FALSE;
}
return (bool) db_result(db_query("SHOW INDEX FROM {" . $table . "} WHERE key_name = '{$name}'"));
}
elseif ($db_type == 'pgsql') {
return (bool) db_result(db_query("SELECT COUNT(indexname) FROM pg_indexes WHERE indexname = '{" . $table . "}_{$name}_idx'"));
}
return FALSE;
}
function content_callback($entity, $op, $field) {
switch ($entity) {
case 'field':
$info = module_invoke($field['module'], "field_info");
return isset($info[$field['type']]['callbacks'][$op]) ? $info[$field['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT;
case 'widget':
$info = module_invoke($field['widget']['module'], "widget_info");
return isset($info[$field['widget']['type']]['callbacks'][$op]) ? $info[$field['widget']['type']]['callbacks'][$op] : CONTENT_CALLBACK_DEFAULT;
}
}
function content_handle($entity, $op, $object) {
switch ($entity) {
case 'field':
$info = module_invoke($object['module'], "field_info");
return isset($info[$object['type']][$op]) ? $info[$object['type']][$op] : CONTENT_HANDLE_CORE;
case 'widget':
$info = module_invoke($object['widget']['module'], "widget_info");
return isset($info[$object['widget']['type']][$op]) ? $info[$object['widget']['type']][$op] : CONTENT_HANDLE_CORE;
case 'formatter':
return isset($object[$op]) ? $object[$op] : CONTENT_HANDLE_CORE;
}
}
function content_default_value(&$form, &$form_state, $field, $delta) {
$widget_types = _content_widget_types();
$module = $widget_types[$field['widget']['type']]['module'];
$default_value = array();
if (!empty($field['widget']['default_value_php'])) {
ob_start();
$result = eval($field['widget']['default_value_php']);
ob_end_clean();
if (is_array($result)) {
$default_value = $result;
}
}
elseif (!empty($field['widget']['default_value'])) {
$default_value = $field['widget']['default_value'];
}
return (array) $default_value;
}
function content_access($op, $field, $account = NULL, $node = NULL) {
global $user;
if (is_null($account)) {
$account = $user;
}
if (!isset($field['field_name'])) {
return FALSE;
}
$access = module_invoke_all('field_access', $op, $field, $account, $node);
foreach ($access as $value) {
if ($value === FALSE) {
return FALSE;
}
}
return TRUE;
}
function content_field_wrapper_post_render($content, $element) {
$field = content_fields($element['#field_name'], $element['#type_name']);
if (theme('content_exclude', $content, $field, $element['#context'])) {
return '';
}
return $content;
}
function theme_content_exclude($content, $object, $context) {
if (empty($object['display_settings']) || empty($object['display_settings'][$context]) || !is_array($object['display_settings'][$context]) || empty($object['display_settings'][$context]['exclude'])) {
return FALSE;
}
else {
return TRUE;
}
}
function template_preprocess_content_field(&$variables) {
$element = $variables['element'];
$field = content_fields($element['#field_name'], $element['#node']->type);
$variables['node'] = $element['#node'];
$variables['field'] = $field;
$variables['items'] = array();
if ($element['#single']) {
foreach (element_children($element['items']) as $delta) {
$variables['items'][$delta] = $element['items'][$delta]['#item'];
$variables['items'][$delta]['view'] = isset($element['items'][$delta]['#children']) ? $element['items'][$delta]['#children'] : '';
}
}
else {
foreach (element_children($element['items']) as $delta) {
$variables['items'][$delta] = $element['items'][$delta]['#item'];
}
$variables['items'][0]['view'] = $element['items']['#children'];
}
$variables['teaser'] = $element['#teaser'];
$variables['page'] = $element['#page'];
$field_empty = TRUE;
foreach ($variables['items'] as $delta => $item) {
if (!isset($item['view']) || empty($item['view']) && (string) $item['view'] !== '0') {
$variables['items'][$delta]['empty'] = TRUE;
}
else {
$field_empty = FALSE;
$variables['items'][$delta]['empty'] = FALSE;
}
}
$additions = array(
'field_type' => $field['type'],
'field_name' => $field['field_name'],
'field_type_css' => strtr($field['type'], '_', '-'),
'field_name_css' => strtr($field['field_name'], '_', '-'),
'label' => check_plain(t($field['widget']['label'])),
'label_display' => $element['#label_display'],
'field_empty' => $field_empty,
'template_files' => array(
'content-field',
'content-field-' . $element['#field_name'],
'content-field-' . $element['#node']->type,
'content-field-' . $element['#field_name'] . '-' . $element['#node']->type,
),
);
$variables = array_merge($variables, $additions);
}
function content_preprocess_node(&$vars) {
$additions = _content_field_invoke_default('preprocess_node', $vars['node']);
$vars = array_merge($vars, $additions);
}
function content_content_fieldapi($op, $field) {
if (module_exists('devel')) {
}
}
function content_content_extra_fields($type_name) {
$type = node_get_types('type', $type_name);
$extra = array();
if ($type->has_title) {
$extra['title'] = array(
'label' => $type->title_label,
'description' => t('Node module form.'),
'weight' => -5,
);
}
if ($type->has_body) {
$extra['body_field'] = array(
'label' => $type->body_label,
'description' => t('Node module form.'),
'weight' => 0,
'view' => 'body',
);
}
$extra['revision_information'] = array(
'label' => t('Revision information'),
'description' => t('Node module form.'),
'weight' => 20,
);
$extra['author'] = array(
'label' => t('Authoring information'),
'description' => t('Node module form.'),
'weight' => 20,
);
$extra['options'] = array(
'label' => t('Publishing options'),
'description' => t('Node module form.'),
'weight' => 25,
);
if (module_exists('comment')) {
$extra['comment_settings'] = array(
'label' => t('Comment settings'),
'description' => t('Comment module form.'),
'weight' => 30,
);
}
if (module_exists('locale') && variable_get("language_content_type_{$type_name}", 0)) {
$extra['language'] = array(
'label' => t('Language'),
'description' => t('Locale module form.'),
'weight' => 0,
);
}
if (module_exists('translation') && translation_supported_type($type_name)) {
$extra['translation'] = array(
'label' => t('Translation settings'),
'description' => t('Translation module form.'),
'weight' => 30,
);
}
if (module_exists('menu')) {
$extra['menu'] = array(
'label' => t('Menu settings'),
'description' => t('Menu module form.'),
'weight' => -2,
);
}
if (module_exists('taxonomy') && taxonomy_get_vocabularies($type_name)) {
$extra['taxonomy'] = array(
'label' => t('Taxonomy'),
'description' => t('Taxonomy module form.'),
'weight' => -3,
);
}
if (module_exists('book')) {
$extra['book'] = array(
'label' => t('Book'),
'description' => t('Book module form.'),
'weight' => 10,
);
}
if (module_exists('path')) {
$extra['path'] = array(
'label' => t('Path settings'),
'description' => t('Path module form.'),
'weight' => 30,
);
}
if ($type_name == 'poll' && module_exists('poll')) {
$extra['title'] = array(
'label' => t('Poll title'),
'description' => t('Poll module title.'),
'weight' => -5,
);
$extra['choice_wrapper'] = array(
'label' => t('Poll choices'),
'description' => t('Poll module choices.'),
'weight' => -4,
);
$extra['settings'] = array(
'label' => t('Poll settings'),
'description' => t('Poll module settings.'),
'weight' => -3,
);
}
if (module_exists('upload') && variable_get("upload_{$type_name}", TRUE)) {
$extra['attachments'] = array(
'label' => t('File attachments'),
'description' => t('Upload module form.'),
'weight' => 30,
'view' => 'files',
);
}
return $extra;
}
function content_extra_field_weight($type_name, $pseudo_field_name) {
$type = content_types($type_name);
if (!isset($type['extra'][$pseudo_field_name])) {
content_clear_type_cache();
$type = content_types($type_name);
}
if (isset($type['extra'][$pseudo_field_name])) {
return $type['extra'][$pseudo_field_name]['weight'];
}
}
function content_max_delta($field_name, $type_name = NULL) {
$fields = content_fields();
$field = $fields[$field_name];
if (empty($field['multiple'])) {
$content_types = content_types();
foreach ($content_types as $content_type) {
if (empty($type_name) || $content_type['type'] == $type_name) {
foreach ($content_type['fields'] as $field) {
$db_info = content_database_info($field);
if (db_result(db_query("SELECT COUNT(*) FROM {" . $db_info['table'] . "}")) >= 1) {
return 0;
}
}
}
}
}
else {
$db_info = content_database_info($field);
if (!empty($type_name)) {
$delta = db_result(db_query("SELECT MAX(delta) FROM {" . $db_info['table'] . "} f LEFT JOIN {node} n ON f.vid = n.vid WHERE n.type = '%s'", $type_name));
}
else {
$delta = db_result(db_query("SELECT MAX(delta) FROM {" . $db_info['table'] . "}"));
}
if ($delta >= 0) {
return $delta;
}
}
return NULL;
}
function content_inactive_fields($type_name = NULL) {
module_load_include('inc', 'content', 'includes/content.crud');
if (!empty($type_name)) {
$param = array(
'type_name' => $type_name,
);
$inactive = array(
$type_name => array(),
);
}
else {
$param = array();
$inactive = array();
}
$all = content_field_instance_read($param, TRUE);
$active = array_keys(content_fields());
foreach ($all as $field) {
if (!in_array($field['field_name'], $active)) {
$inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field);
}
}
if (!empty($type_name)) {
return $inactive[$type_name];
}
return $inactive;
}
function content_inactive_instances($type_name = NULL) {
module_load_include('inc', 'content', 'includes/content.crud');
if (!empty($type_name)) {
$param = array(
'type_name' => $type_name,
);
$inactive = array(
$type_name => array(),
);
}
else {
$param = array();
$inactive = array();
}
$all = content_field_instance_read($param, TRUE);
foreach ($all as $field) {
$inactive[$field['type_name']][$field['field_name']] = content_field_instance_expand($field);
}
if (!empty($type_name)) {
return $inactive[$type_name];
}
return $inactive;
}