View source
<?php
define('DS_SETTINGS_UI', 1);
define('DS_SETTINGS_DEFAULT', 2);
define('DS_SETTINGS_OVERRIDDEN', 3);
define('DS_RENDER_DEFAULT', 'default');
define('DS_RENDER_DRUPAL', 'drupal');
define('DS_RENDER_CCK', 'cck');
define('DS_RENDER_NON_DS', 'other');
define('DS_FIELD_TYPE_NON_DS', 0);
define('DS_FIELD_TYPE_THEME', 1);
define('DS_FIELD_TYPE_FUNCTION', 2);
define('DS_FIELD_TYPE_PREPROCESS', 3);
define('DS_FIELD_TYPE_IGNORE', 4);
define('DS_FIELD_TYPE_CODE', 5);
define('DS_FIELD_TYPE_BLOCK', 6);
define('DS_FIELD_TYPE_GROUP', 7);
define('DS_FIELD_TYPE_MULTIGROUP', 8);
define('DS_FIELD_STATUS_STATIC', 1);
define('DS_FIELD_STATUS_DEFAULT', 2);
define('DS_FIELD_STATUS_CUSTOM', 3);
define('DS_FIELD_STATUS_OVERRIDDEN', 4);
define('DS_BLOCK_TEMPLATE', 1);
define('DS_BLOCK_TITLE_CONTENT', 2);
define('DS_BLOCK_CONTENT', 3);
define('DS_DEFAULT_REGION', 'disabled');
define('DS_DISABLED_REGION', 'disabled');
define('DS_DEFAULT_FORMAT', 'default');
define('DS_DEFAULT_LABEL_FORMAT', 'hidden');
define('DS_DEFAULT_WEIGHT', -19);
define('DS_DEFAULT_THEME_REGIONS', 'ds_regions');
define('DS_DEFAULT_THEME_FIELD', 'ds_field');
define('DS_DEFAULT_THEME_FIELDSET', 'ds_group_fieldset_open');
define('DS_PATH_BASE', 'admin/build/ds');
define('DS_PATH_LAYOUT', 'admin/build/ds/layout');
define('DS_PATH_TOOLS', 'admin/build/ds/tools');
define('DS_PATH_STYLES', 'admin/build/ds/styles');
define('DS_PATH_MODULES', 'admin/build/ds/modules');
function ds_theme() {
require_once 'includes/ds.registry.inc';
return _ds_theme();
}
function ds_views_api() {
return array(
'api' => 2,
'path' => drupal_get_path('module', 'ds') . '/views',
);
}
function ds_ds_plugins() {
require_once 'includes/ds.registry.inc';
return _ds_plugins();
}
function ds_features_api() {
require_once 'includes/ds.features.inc';
return _ds_features_api();
}
function ds_flush_caches() {
ds_reset_fields_cache();
ds_import_default_data();
return array();
}
function ds_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
require_once 'includes/ds.registry.inc';
return _ds_block_list();
case 'view':
$content = array();
$ds_blocks = variable_get('ds_blocks', array());
if (isset($ds_blocks[$delta])) {
$info = $ds_blocks[$delta];
$data = $info['data'];
if (isset($data['filename']) && isset($data['class'])) {
require_once $data['filename'];
$class = $data['class'];
$plugin = new $class();
if (method_exists($plugin, 'block_view')) {
$content = $plugin
->block_view($info);
}
}
}
return $content;
}
}
function ds_variable_get($var_name, $default = '') {
if (ds_static_variables($var_name)) {
$value = ds_static_variables($var_name);
}
elseif (module_exists('variable') && function_exists('variable_get_value')) {
global $language;
$value = variable_get_value($var_name, array(
'default' => $default,
'language' => $language,
));
}
else {
$value = variable_get($var_name, $default);
}
return $value;
}
function ds_static_variables($key, $data = NULL) {
static $variables = array();
if (!isset($data) && isset($variables[$key])) {
return $variables[$key];
}
elseif (isset($data)) {
if (!isset($variables[$key])) {
$variables[$key] = array();
}
$variables[$key][] = $data;
}
}
function ds_api_info($module, $type_name = 'all') {
static $api_info = array();
if (!isset($api_info[$module][$type_name])) {
$api_data = module_invoke($module, 'ds_api');
if (!empty($api_data)) {
$api_info[$module][$type_name] = $api_data;
if (!isset($api_info[$module][$type_name]['extra'])) {
$api_info[$module][$type_name]['extra'] = array();
}
if ($type_name != 'all' && !empty($api_data['extra'])) {
$extra = array();
$types = $api_data['types']();
$type_info = $types[$type_name];
foreach ($api_data['extra'] as $key) {
$extra[$key] = $type_info->{$key};
}
$api_info[$module][$type_name]['extra'] = $extra;
}
}
}
return $api_info[$module][$type_name];
}
function ds_make($key, $module, &$object, &$vars, $build_mode = NULL) {
if (isset($build_mode) && !is_null($build_mode)) {
$object->build_mode = $build_mode;
}
$data = array(
'object' => $object,
'module' => $module,
'vars' => $vars,
);
drupal_alter('ds_render', $data);
ds_build_fields_and_regions($data['object'], $module);
$render = ds_render($key, $data['object'], $module, $data['vars']);
return $render;
}
function ds_render($key, $object, $module, $vars) {
static $renders = array();
if (isset($renders[$module][$object->build_mode][$key])) {
return $renders[$module][$object->build_mode][$key];
}
$renders[$module][$object->build_mode][$key] = ds_render_content($object, $module, $vars);
return $renders[$module][$object->build_mode][$key];
}
function ds_reset_fields_cache() {
db_query("UPDATE {ds_settings} set fields = ''");
}
function ds_build_fields_and_regions(&$object, $module) {
$api_info = ds_api_info($module, $object->type);
$exclude_build_modes = variable_get($module . '_buildmodes_exclude', array());
$object->render_by_ds = isset($exclude_build_modes[$object->type][$object->build_mode]) && $exclude_build_modes[$object->type][$object->build_mode] == TRUE || variable_get($module . '_type_' . $object->type, FALSE) == TRUE ? FALSE : TRUE;
$object->regions = array();
$object->ds_fields = array();
$object->ds_groups = array();
$object->preprocess_fields = array();
$display_settings = ds_get_settings($module, $object->type, $object->build_mode);
if (!empty($display_settings['fields'])) {
$available_fields = ds_get_fields($module, $object->type, $object->build_mode, $api_info['extra']);
if (isset($object->has_empty_body) && $object->has_empty_body == 1) {
$object->body = '';
}
foreach ($display_settings['fields'] as $field_key => $field_defaults) {
$region = isset($field_defaults['region']) ? $field_defaults['region'] : DS_DEFAULT_REGION;
if ($region != DS_DISABLED_REGION) {
if (isset($available_fields[$field_key])) {
$field_settings = $available_fields[$field_key];
if (!isset($field_settings['pipeline'])) {
$field_settings['pipeline'] = DS_RENDER_DEFAULT;
}
}
else {
$field_settings = array();
$field_settings['pipeline'] = DS_RENDER_NON_DS;
}
$field_settings = array_merge($field_defaults, $field_settings);
$field_settings['field_type'] = isset($field_settings['type']) ? $field_settings['type'] : DS_FIELD_TYPE_NON_DS;
$field_settings['module'] = $module;
$field_settings['object'] =& $object;
$field_settings['object_type'] = $api_info['object'];
$object->ds_fields[$field_key] = ds_build_field($field_key, $field_settings);
if (!empty($object->ds_fields[$field_key]['parent'])) {
$parent = $object->ds_fields[$field_key]['parent'];
$object->ds_groups[$parent][$field_key] = $field_settings['weight'];
}
else {
$object->regions[$region][$field_key] = $field_settings['weight'];
}
}
}
}
if (empty($object->regions)) {
$object->render_by_ds = FALSE;
}
}
function ds_build_field($field_key, $field_settings) {
$classes = array();
$classes[] = 'field-' . strtr($field_key, '_', '-');
if (isset($field_settings['properties']['css-class']) && !empty($field_settings['properties']['css-class'])) {
$classes[] = $field_settings['properties']['css-class'];
unset($field_settings['properties']['css-class']);
}
if (isset($field_settings['css-class']) && !empty($field_settings['css-class'])) {
$classes[] = $field_settings['css-class'];
unset($field_settings['css-class']);
}
$field_defaults = array(
'labelformat' => DS_DEFAULT_LABEL_FORMAT,
'label' => '',
'theme' => DS_DEFAULT_THEME_FIELD,
'weight' => DS_DEFAULT_WEIGHT,
'content' => NULL,
);
$field = array_merge($field_defaults, $field_settings);
$field['key'] = $field_key;
$field['type'] = empty($field_settings) ? 'other' : 'ds';
if (isset($field_settings['weight'])) {
$field['weight'] = $field_settings['weight'];
}
$field['parent'] = isset($field_settings['parent']) ? $field_settings['parent'] : NULL;
if ($field['field_type'] == DS_FIELD_TYPE_GROUP || $field['field_type'] == DS_FIELD_TYPE_MULTIGROUP) {
if (isset($field_settings['format'])) {
$field['theme'] = $field_settings['format'];
}
else {
$field['theme'] = DS_DEFAULT_THEME_FIELDSET;
}
if ($field_settings['field_type'] == DS_FIELD_TYPE_GROUP) {
$classes[] = 'field-group';
}
if ($field_settings['field_type'] == DS_FIELD_TYPE_MULTIGROUP) {
$field['subgroup_theme'] = isset($field_settings['subgroup_format']) ? $field_settings['subgroup_format'] : DS_DEFAULT_THEME_FIELDSET;
$classes[] = 'field-multigroup';
}
}
$field['class'] = implode(' ', $classes);
if ($field_settings['pipeline'] = DS_RENDER_DEFAULT) {
if (isset($field_settings['label_value']) && $field['labelformat'] != DS_DEFAULT_LABEL_FORMAT) {
$field['title'] = t('%label', array(
'%label' => $field_settings['label_value'],
));
}
$field['key'] = $field_key;
switch ($field['field_type']) {
case DS_FIELD_TYPE_PREPROCESS:
case DS_FIELD_TYPE_IGNORE:
if (isset($field_settings['properties']['key']) && !empty($field_settings['properties']['key'])) {
$field['preprocess_settings'] = array(
'type' => $field['type'],
'key' => $field['properties']['key'],
);
}
else {
$field['preprocess_settings'] = array(
'type' => $field['type'],
);
}
break;
case DS_FIELD_TYPE_CODE:
$field['formatter'] = isset($field['format']) ? $field['format'] : 'ds_eval_code';
break;
case DS_FIELD_TYPE_BLOCK:
$field['formatter'] = 'ds_eval_block';
break;
case DS_FIELD_TYPE_FUNCTION:
$field['function'] = isset($field_settings['format']) ? $field_settings['format'] : key($field_settings['properties']['formatters']);
break;
case DS_FIELD_TYPE_THEME:
$field['formatter'] = isset($field_settings['format']) ? $field_settings['format'] : key($field_settings['properties']['formatters']);
break;
}
$field['content'] = ds_field_format_content($field);
}
return $field;
}
function ds_render_content(&$object, $module, $vars, $theme_function = DS_DEFAULT_THEME_FIELD) {
$object_display = new stdClass();
$object_display->active_regions = array();
$object_display->all_regions = ds_regions('all', TRUE);
foreach ($object_display->all_regions as $region_name => $region) {
if (isset($vars['regions'][$region_name]) && !empty($vars['regions'][$region_name])) {
$object_display->active_regions[$region_name] = $vars['regions'][$region_name];
}
}
$object_display->themed_regions = array();
$object_display->region_classes = array();
$object_display->build_mode = $object->build_mode;
$object_display->api_info = ds_api_info($module, $object->type);
$object_display->display_settings = ds_get_settings($module, $object->type, $object->build_mode);
$object_display->region_styles = ds_default_value($object_display->display_settings, 'region_styles');
foreach ($object->ds_fields as $key => $field) {
switch ($field['field_type']) {
case DS_FIELD_TYPE_PREPROCESS:
if (!empty($field['preprocess_settings']['key'])) {
$object->ds_fields[$key]['content'] = $vars[$key][$object->preprocess_fields[$key]['key']];
}
else {
$object->ds_fields[$key]['content'] = $vars[$key];
}
break;
case DS_FIELD_TYPE_IGNORE:
$object->ds_fields[$key]['content'] = isset($object->content[$key]['#value']) ? $object->content[$key]['#value'] : '';
break;
}
}
if (!empty($object->ds_groups)) {
foreach ($object->ds_groups as $group_key => $group) {
foreach ($group as $field_key => $field) {
$object->ds_fields[$group_key]['fields'][$field_key] = $object->ds_fields[$field_key];
unset($object->ds_fields[$field_key]);
}
}
}
$count = 0;
foreach (array_keys($object_display->active_regions) as $region_name) {
$region_fields = array();
asort($object_display->active_regions[$region_name]);
foreach (array_keys($object_display->active_regions[$region_name]) as $key) {
$region_fields[$key] = $object->ds_fields[$key];
switch ($object->ds_fields[$key]['field_type']) {
case DS_FIELD_TYPE_GROUP:
$region_fields[$key]['rendered'] = ds_render_group($object, $key, $vars);
break;
case DS_FIELD_TYPE_MULTIGROUP:
$region_fields[$key]['rendered'] = ds_render_multigroup($object, $key, $vars);
break;
default:
$object->ds_fields[$key]['content'] = ds_get_content($object->ds_fields[$key], $vars, $key);
$region_fields[$key]['rendered'] = ds_render_item($object->ds_fields[$key]);
break;
}
if (!empty($object->ds_fields[$key]['theme'])) {
if ($object->ds_fields[$key]['theme'] == 'ds_tabs') {
$object_display->active_regions[$region_name]['tab_' . $region_name] = $object->ds_fields[$key]['weight'];
$region_fields['tab_' . $region_name] = array(
'tab' => TRUE,
'name' => $region_name,
'fields' => array(
$object->ds_fields[$key]['weight'] => $object->ds_fields[$key],
),
);
$region_fields['tab_' . $region_name]['fields'][$object->ds_fields[$key]['weight']]['content'] = $object->ds_fields[$key]['rendered'];
unset($object->ds_fields[$key]);
unset($region_fields[$key]);
}
}
}
if (is_array($region_fields) && !empty($region_fields)) {
if ($region_name == 'left' || $region_name == 'right') {
$object_display->region_classes[$region_name] = $region_name;
}
$style = isset($object_display->region_styles[$region_name]) ? ' ' . $object_display->region_styles[$region_name] : '';
$rendered_region = '';
foreach ($region_fields as $region_field) {
if (!empty($region_field['rendered'])) {
$rendered_region .= $region_field['rendered'];
}
}
$object_display->themed_regions[$region_name] = array(
'content' => $rendered_region,
'extra_class' => $style,
'count' => $count,
'fields' => $region_fields,
'hidden' => FALSE,
);
if (empty($rendered_region)) {
$object_display->themed_regions[$region_name]['hidden'] = TRUE;
}
}
$count++;
}
ds_plugins_process($object_display, $object, $vars);
foreach ($object_display->themed_regions as $key => $region) {
if ($region['hidden'] == TRUE) {
unset($object_display->themed_regions[$key]);
}
}
if (isset($object_display->themed_regions['middle'])) {
$middle_class = $module . '-no-sidebars';
if (isset($object_display->themed_regions['left']) && isset($object_display->themed_regions['right'])) {
$middle_class = $module . '-two-sidebars';
}
elseif (isset($object_display->themed_regions['left'])) {
$middle_class = $module . '-one-sidebar ' . $module . '-sidebar-left';
}
elseif (isset($object_display->themed_regions['right'])) {
$middle_class = $module . '-one-sidebar ' . $module . '-sidebar-right';
}
$object_display->themed_regions['middle']['extra_class'] .= ' ' . $middle_class;
}
return theme(DS_DEFAULT_THEME_REGIONS, $object_display, $module);
}
function ds_field_format_content($field) {
$content = NULL;
switch ($field['pipeline']) {
case DS_RENDER_DRUPAL:
break;
case DS_RENDER_NON_DS:
break;
default:
case DS_RENDER_DEFAULT:
if (isset($field['formatter']) || isset($field['function'])) {
if (isset($field['file'])) {
include_once $field['file'];
}
if (isset($field['function']) && !empty($field['function'])) {
if (function_exists($field['function'])) {
$content = call_user_func($field['function'], $field);
}
}
else {
$content = theme($field['formatter'], $field);
}
}
break;
}
return $content;
}
function ds_render_item($item) {
$content = FALSE;
switch ($item['pipeline']) {
case DS_RENDER_DRUPAL:
$content = drupal_render($item['vars']);
break;
case DS_RENDER_NON_DS:
if (!empty($item['content'])) {
$content = $item['content'];
}
break;
default:
case DS_RENDER_DEFAULT:
if (!empty($item['content'])) {
if (isset($item['tab'])) {
$item['theme'] = 'ds_tabs';
}
elseif (empty($item['theme'])) {
$item['theme'] = DS_DEFAULT_THEME_FIELD;
}
$content = theme($item['theme'], $item);
}
break;
}
if (isset($content) && strlen($content) > 0) {
return $content;
}
return FALSE;
}
function ds_render_group(&$object, $group_key, $vars = array()) {
$object->ds_fields[$group_key]['content'] = '';
if (array_key_exists($group_key, $object->ds_groups)) {
asort($object->ds_groups[$group_key]);
foreach (array_keys($object->ds_groups[$group_key]) as $field_key) {
$object->ds_fields[$group_key]['fields'][$field_key]['content'] = ds_get_content($object->ds_fields[$group_key]['fields'][$field_key], $vars, $field_key);
$object->ds_fields[$group_key]['fields'][$field_key]['rendered'] = ds_render_item($object->ds_fields[$group_key]['fields'][$field_key]);
$object->ds_fields[$group_key]['content'] .= $object->ds_fields[$group_key]['fields'][$field_key]['rendered'];
}
$object->ds_fields[$group_key]['count'] = count($object->ds_fields[$group_key]['fields']);
if (!empty($object->ds_fields[$group_key]['content'])) {
$object->ds_fields[$group_key]['rendered'] = ds_render_item($object->ds_fields[$group_key]);
}
}
return $object->ds_fields[$group_key]['rendered'];
}
function ds_render_multigroup(&$object, $group_key, $vars = array()) {
drupal_add_css(drupal_get_path('module', 'ds') . '/css/ds-multigroup.css');
$object->ds_fields[$group_key]['subgroups'] = array();
$field_keys = array_keys($object->ds_fields[$group_key]['fields']);
$subgroup_count = count($vars[$field_keys[0]]);
for ($i = 0; $i < $subgroup_count; $i++) {
$object->ds_fields[$group_key]['subgroups']['rows'][$i] = array(
'index' => $group_key . '_delta_' . $i,
'class' => 'content-multigroup-wrapper field-multigroup-row ds-multigroup-' . $group_key . '-delta-' . $i . ($i % 2 ? ' odd' : ' even'),
'weight' => $i - 100,
);
$subgroup_content = FALSE;
foreach ($object->ds_fields[$group_key]['fields'] as $field_key => $field_weight) {
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key] = $object->ds_fields[$group_key]['fields'][$field_key];
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['view'] = ds_get_content($object->ds_fields[$group_key]['fields'][$field_key], $vars[$field_key][$i], 'view');
if (empty($object->ds_fields[$group_key]['fields'][$field_key]['title'])) {
$cck_field = content_fields($field_key, $object->type);
$object->ds_fields[$group_key]['fields'][$field_key]['title'] = nd_cck_get_label_value($cck_field, $object->build_mode);
}
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['title'] = $object->ds_fields[$group_key]['fields'][$field_key]['title'];
$field_content = $object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['view'];
if ($field_content != FALSE || strlen($field_content) > 0) {
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['content'] = $field_content;
}
else {
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['content'] = FALSE;
}
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['type'] = 'ds';
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['pipeline'] = DS_RENDER_DEFAULT;
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['rendered'] = ds_render_item($object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]);
if ($object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['rendered'] != FALSE) {
$subgroup_content = TRUE;
}
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['title'] = $object->content[$group_key]['group'][$i]['#title'];
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['content'] .= $object->ds_fields[$group_key]['subgroups']['rows'][$i]['fields'][$field_key]['rendered'];
}
if ($subgroup_content == TRUE) {
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['rendered'] = ds_render_item($object->ds_fields[$group_key]['subgroups']['rows'][$i]);
}
else {
$object->ds_fields[$group_key]['subgroups']['rows'][$i]['rendered'] = FALSE;
}
}
$object->ds_fields[$group_key]['subgroups']['fields'] = $object->ds_fields[$group_key]['fields'];
$object->ds_fields[$group_key]['subgroups']['key'] = $group_key . '_subgroup';
$object->ds_fields[$group_key]['subgroups']['theme'] = isset($object->ds_fields[$group_key]['subgroup_theme']) ? $object->ds_fields[$group_key]['subgroup_theme'] : 'ds_multigroup_fieldset';
$object->ds_fields[$group_key]['subgroups']['content'] = TRUE;
$object->ds_fields[$group_key]['content'] = ds_render_item($object->ds_fields[$group_key]['subgroups']);
if (!empty($object->ds_fields[$group_key]['content'])) {
$object->ds_fields[$group_key]['rendered'] = ds_render_item($object->ds_fields[$group_key]);
return $object->ds_fields[$group_key]['rendered'];
}
return FALSE;
}
function ds_get_content($item, $content_vars = array(), $vars_key = NULL) {
if (!is_array($item)) {
return FALSE;
}
$content = '';
if (!empty($item['content'])) {
$content = $item['content'];
}
elseif (!empty($content_vars)) {
if (isset($content_vars[$vars_key . '_rendered'])) {
$content = $content_vars[$vars_key . '_rendered'];
}
elseif (isset($content_vars[$vars_key])) {
$content = $content_vars[$vars_key];
}
}
if (!empty($content)) {
return $content;
}
return FALSE;
}
function ds_get_settings($module, $type, $build_mode, $return = 'settings', $reset = FALSE) {
static $settings = array();
if ($reset) {
$settings = array();
}
if (!isset($settings[$module][$type][$build_mode])) {
$settings[$module][$type][$build_mode] = array();
$record = db_fetch_array(db_query("SELECT module, type, build_mode, settings, fields FROM {ds_settings} WHERE module = '%s' AND type = '%s' AND build_mode = '%s'", $module, $type, $build_mode));
if (isset($record['module'])) {
$settings[$module][$type][$build_mode]['settings'] = unserialize($record['settings']);
$settings[$module][$type][$build_mode]['fields'] = unserialize($record['fields']);
}
}
return isset($settings[$module][$type][$build_mode][$return]) ? $settings[$module][$type][$build_mode][$return] : array();
}
function ds_default_value($settings, $type, $key = NULL, $search_key = NULL, $default = NULL) {
if ($key == NULL) {
return isset($settings[$type]) ? $settings[$type] : NULL;
}
return isset($settings[$type][$key][$search_key]) ? $settings[$type][$key][$search_key] : $default;
}
function ds_get_fields($module, $type_name, $build_mode, $extra = array(), $reset = FALSE, $cache = TRUE) {
static $static_fields = array();
if (!isset($static_fields[$module][$type_name][$build_mode])) {
$settings = ds_get_settings($module, $type_name, $build_mode, 'fields');
if (!isset($settings) || empty($settings) || $reset) {
$fields = array();
foreach (module_implements('ds_fields') as $prefix) {
$function = $prefix . '_ds_fields';
$all_fields = $function($type_name, $build_mode, $extra);
if (!empty($all_fields)) {
foreach ($all_fields as $key => $field_results) {
if ($key === $module) {
$fields = array_merge($field_results, $fields);
foreach ($fields as $key => $field) {
$exclude = isset($field['exclude'][$type_name]) && $field['exclude'][$type_name] === $type_name ? TRUE : FALSE;
if ($exclude) {
unset($fields[$key]);
}
}
}
}
}
}
$db_fields = variable_get($module . '_fields', array());
if (!empty($db_fields)) {
foreach ($db_fields as $key => $field) {
$fields[$key] = array(
'title' => check_plain($field['title']),
'type' => $field['type'],
'status' => $field['status'],
'properties' => $field['properties'],
);
$exclude = isset($field['exclude'][$type_name]) && $field['exclude'][$type_name] === $type_name ? TRUE : FALSE;
if ($exclude) {
unset($fields[$key]);
}
}
}
if ($cache) {
foreach ($fields as $field_key => $field_value) {
if (isset($field_value['storage'])) {
unset($fields[$field_key]);
}
}
}
drupal_alter('ds_fields', $fields);
if ($cache) {
db_query("UPDATE {ds_settings} set fields = '%s' WHERE module = '%s' AND type = '%s' AND build_mode = '%s'", serialize($fields), $module, $type_name, $build_mode);
}
}
else {
$fields = $settings;
}
$static_fields[$module][$type_name][$build_mode] = $fields;
}
return $static_fields[$module][$type_name][$build_mode];
}
function ds_get_build_modes($module = NULL, $reset = FALSE) {
$build_modes = variable_get('ds_all_build_modes', array());
if (empty($build_modes) || $reset) {
require_once 'includes/ds.registry.inc';
$build_modes = _ds_register_build_modes();
}
if ($module != NULL) {
return $build_modes[$module];
}
else {
return $build_modes;
}
}
function ds_plugins_process(&$display, $object, $vars) {
$plugins = variable_get($display->api_info['module'] . '_plugin_settings', array());
if (!empty($plugins)) {
foreach ($plugins as $key => $data) {
if (isset($data['filename']) && isset($data['class'])) {
require_once $data['filename'];
$class = $data['class'];
$plugin = new $class();
$plugin
->execute($vars, $display, $display->display_settings, $object->type, $display->api_info['module']);
}
}
}
}
function ds_eval($code, $object) {
global $theme_path, $theme_info, $conf;
$old_theme_path = $theme_path;
if (!isset($theme_info)) {
$theme_path = drupal_get_path('theme', $conf['theme_default']);
}
else {
$theme_path = dirname($theme_info->filename);
}
ob_start();
print eval('?>' . $code);
$output = ob_get_contents();
ob_end_clean();
$theme_path = $old_theme_path;
return $output;
}
function ds_regions($regions = 'all', $render = FALSE) {
if ($regions == 'all') {
if ($render == FALSE) {
return array(
'header' => t('Header'),
'left' => t('Left'),
'middle' => t('Middle'),
'right' => t('Right'),
'footer' => t('Footer'),
'disabled' => t('Disabled'),
);
}
else {
return array(
'header' => t('Header'),
'middle' => t('Middle'),
'left' => t('Left'),
'right' => t('Right'),
'footer' => t('Footer'),
'disabled' => t('Disabled'),
);
}
}
else {
return array(
'middle' => t('Enabled'),
'disabled' => t('Disabled'),
);
}
}
function ds_show_field($module, $type_name, $build_mode, $field) {
static $show_fields = array();
if (!isset($show_fields[$module][$type_name][$build_mode][$field])) {
$display_settings = ds_get_settings($module, $type_name, $build_mode);
$show_fields[$module][$type_name][$build_mode][$field] = isset($display_settings['fields'][$field]) && $display_settings['fields'][$field]['region'] != 'disabled' ? TRUE : FALSE;
}
return $show_fields[$module][$type_name][$build_mode][$field];
}
function ds_import_default_data($module = '', $type = '', $build_mode = '') {
$data = module_invoke_all('ds_default_settings');
if (!empty($data)) {
module_load_include('inc', 'ds', 'includes/ds.tools');
ds_import_data($data, FALSE, FALSE, $module, $type, $build_mode);
}
}
function ds_element_children(&$elements, $sort = FALSE) {
$sort = isset($elements['#sorted']) ? !$elements['#sorted'] : $sort;
$children = array();
$sortable = FALSE;
foreach ($elements as $key => $value) {
if ($key === '' || $key[0] !== '#') {
$children[$key] = $value;
if (is_array($value) && isset($value['#weight'])) {
$sortable = TRUE;
}
}
}
if ($sort && $sortable) {
uasort($children, 'element_sort');
foreach ($children as $key => $child) {
unset($elements[$key]);
$elements[$key] = $child;
}
$elements['#sorted'] = TRUE;
}
return array_keys($children);
}
function ds_get_active_build_modes($module, $type = NULL) {
$api_info = ds_api_info($module);
$build_modes = ds_get_build_modes($module);
$filtered_bm = array();
if (!empty($build_modes)) {
if (function_exists($api_info['types'])) {
$types = call_user_func($api_info['types']);
}
else {
$types = array();
}
foreach ($types as $type_name => $type_info) {
if (variable_get($module . '_type_' . $type_info->type, FALSE)) {
continue;
}
$exclude_build_modes = variable_get($module . '_buildmodes_exclude', array());
foreach ($build_modes as $key => $value) {
$excluded = isset($exclude_build_modes[$type_name][$key]) && $exclude_build_modes[$type_name][$key] == TRUE ? TRUE : FALSE;
if ($excluded) {
continue;
}
$filtered_bm[$type_name][$key] = $value;
}
}
}
if (isset($type) && !empty($type)) {
if (isset($filtered_bm[$type])) {
return $filtered_bm[$type];
}
else {
return FALSE;
}
}
return $filtered_bm;
}