View source
<?php
define('DS_SETTINGS_UI', 1);
define('DS_SETTINGS_DEFAULT', 2);
define('DS_SETTINGS_OVERRIDDEN', 3);
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_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_DEFAULT_FORMAT', 'default');
define('DS_DEFAULT_LABEL_FORMAT', 'hidden');
define('DS_DEFAULT_WEIGHT', -19);
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() {
variable_del('ds_fields_cached');
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();
break;
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;
break;
}
}
function ds_static_variables($key, $data = NULL) {
static $variables = array();
if (!isset($data) && isset($key) && isset($variables[$key])) {
return $variables[$key];
}
elseif (!isset($variables[$key]) && isset($data)) {
$variables[$key] = array();
$variables[$key][] = $data;
}
elseif (isset($variables[$key]) && isset($data)) {
$variables[$key][] = $data;
}
}
function ds_api_info($module, $type_name = 'all') {
static $api_info = array();
if (!isset($api_info[$module][$type_name])) {
$function = $module . '_ds_api';
$api_data = $function();
$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_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;
$regions = array();
$ds_fields = array();
$ds_groups = array();
$ds_preprocess_fields = array();
$display_settings = variable_get($module . '_display_settings_' . $object->type, array());
$fields = ds_get_fields($module, $object->type, $object->build_mode, $api_info['extra']);
$field_settings = ds_default_value($display_settings, $object->build_mode, 'fields');
$object_type = $api_info['object'];
if (!empty($fields)) {
foreach ($fields as $key => $field) {
$region = isset($field_settings[$key]['region']) ? $field_settings[$key]['region'] : DS_DEFAULT_REGION;
if ($region != 'disabled') {
$class = isset($field['properties']['css-class']) ? $field['properties']['css-class'] : 'field-' . strtr($key, '_', '-');
if (isset($field_settings[$key]['css-class']) && !empty($field_settings[$key]['css-class'])) {
$class .= ' ' . $field_settings[$key]['css-class'];
}
if (isset($field['type']) && $field['type'] == DS_FIELD_TYPE_GROUP) {
$class .= ' field-group';
}
$ds_fields[$key]['key'] = $key;
$ds_fields[$key]['region'] = $region;
$ds_fields[$key]['title'] = $field['title'];
$ds_fields[$key]['class'] = $class;
$ds_fields[$key]['labelformat'] = isset($field_settings[$key]['labelformat']) ? $field_settings[$key]['labelformat'] : DS_DEFAULT_LABEL_FORMAT;
$ds_fields[$key]['type'] = isset($field['display_settings']) ? 'other' : 'ds';
$weight = isset($field_settings[$key]['weight']) ? $field_settings[$key]['weight'] : DS_DEFAULT_WEIGHT;
$parent = isset($field_settings[$key]['parent']) ? $field_settings[$key]['parent'] : '';
$ds_fields[$key]['weight'] = $weight;
$regions[$region][$key] = $weight;
if (!empty($parent)) {
unset($regions[$region][$key]);
$format = isset($field_settings[$parent]['format']) ? $field_settings[$parent]['format'] : 'ds_group_fieldset';
$ds_fields[$parent]['theme'] = $format;
$ds_groups[$parent][$key] = $weight;
}
if (isset($field['storage'])) {
continue;
}
if (isset($field_settings[$key]['label_value']) && $ds_fields[$key]['labelformat'] != DS_DEFAULT_LABEL_FORMAT) {
$ds_fields[$key]['title'] = t(check_plain($field_settings[$key]['label_value']));
}
$field['key'] = $key;
$field['module'] = $module;
$field['object'] = $object;
$field['object_type'] = $object_type;
$key_rendered = $key . '_rendered';
switch ($field['type']) {
case DS_FIELD_TYPE_PREPROCESS:
case DS_FIELD_TYPE_IGNORE:
if (isset($field['properties']['key']) && !empty($field['properties']['key'])) {
$ds_preprocess_fields[$key] = array(
'type' => $field['type'],
'key' => $field['properties']['key'],
);
}
else {
$ds_preprocess_fields[$key] = $field['type'];
}
break;
case DS_FIELD_TYPE_CODE:
$format = isset($field_settings[$key]['format']) ? $field_settings[$key]['format'] : 'ds_eval_code';
$field['formatter'] = $format;
$object->{$key_rendered} = theme($format, $field);
break;
case DS_FIELD_TYPE_BLOCK:
$object->{$key_rendered} = theme('ds_eval_block', $field);
break;
case DS_FIELD_TYPE_FUNCTION:
if (isset($field['file'])) {
include_once $field['file'];
}
$function = isset($field_settings[$key]['format']) ? $field_settings[$key]['format'] : key($field['properties']['formatters']);
$object->{$key_rendered} = $function($field);
break;
case DS_FIELD_TYPE_THEME:
$format = isset($field_settings[$key]['format']) ? $field_settings[$key]['format'] : key($field['properties']['formatters']);
$field['formatter'] = $format;
$object->{$key_rendered} = theme($format, $field);
break;
}
}
}
}
$object->ds_fields = $ds_fields;
$object->ds_groups = $ds_groups;
$object->regions = $regions;
$object->preprocess_fields = $ds_preprocess_fields;
if (empty($regions)) {
$object->render_by_ds = FALSE;
}
}
function ds_render_content($object, $module, $vars, $theme_function = 'ds_field') {
$api_info = ds_api_info($module, $object->type);
$display_settings = variable_get($module . '_display_settings_' . $object->type, array());
$region_styles = ds_default_value($display_settings, $object->build_mode, 'region_styles');
$all_regions = ds_regions('all', TRUE);
$regions = $vars['regions'];
$themed_regions = array();
if (!empty($object->preprocess_fields)) {
foreach ($object->preprocess_fields as $key => $type) {
$vars_key = NULL;
if (is_array($type)) {
$vars_key = $type['key'];
$type = $type['type'];
}
switch ($type) {
case DS_FIELD_TYPE_PREPROCESS:
$field_key = $key . '_rendered';
if (!empty($vars_key)) {
$vars[$field_key] = $vars[$key][$vars_key];
}
else {
$vars[$field_key] = $vars[$key];
}
break;
case DS_FIELD_TYPE_IGNORE:
$field_key = $key . '_rendered';
$vars[$field_key] = $object->content[$key]['#value'];
break;
}
}
}
if (!empty($object->ds_groups)) {
foreach ($object->ds_groups as $group => $fields) {
asort($fields);
$group_content = '';
$field_count = 0;
$group_fields = array();
foreach ($fields as $key => $weight) {
$field_content = isset($vars[$key . '_rendered']) ? $vars[$key . '_rendered'] : '';
if (!empty($field_content)) {
$group_content .= theme($theme_function, $field_content, $object->ds_fields[$key]);
$field_count++;
$group_fields[] = $object->ds_fields[$key];
unset($object->ds_fields[$key]);
}
}
if (!empty($group_content)) {
if ($object->ds_fields[$group]['theme'] == 'ds_tabs') {
unset($regions[$object->ds_fields[$group]['region']][$group]);
$regions[$object->ds_fields[$group]['region']]['tab_' . $object->ds_fields[$group]['region']] = $object->ds_fields[$group]['weight'];
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['tab'] = TRUE;
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['name'] = $object->ds_fields[$group]['region'];
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['fields'][$object->ds_fields[$group]['weight']] = $object->ds_fields[$group];
$object->ds_fields['tab_' . $object->ds_fields[$group]['region']]['fields'][$object->ds_fields[$group]['weight']]['content'] = $group_content;
unset($object->ds_fields[$group]);
}
else {
$object->ds_fields[$group]['content'] = $group_content;
$object->ds_fields[$group]['count'] = $field_count;
$object->ds_fields[$group]['fields'] = $group_fields;
}
}
else {
unset($object->ds_fields[$group]);
}
}
}
$region_classes = array();
foreach ($all_regions as $region_name => $region_title) {
if (isset($regions[$region_name])) {
$region_content = '';
$region = $regions[$region_name];
$count = 0;
$region_fields = array();
asort($region);
foreach ($region as $key => $weight) {
if (isset($object->ds_fields[$key]['theme']) && isset($object->ds_fields[$key]['content'])) {
$count++;
$region_fields[] = $object->ds_fields[$key];
$region_content .= theme($object->ds_fields[$key]['theme'], $object->ds_fields[$key]['content'], $object->ds_fields[$key]);
}
elseif (isset($object->ds_fields[$key]['tab'])) {
$count++;
$region_fields[] = $object->ds_fields[$key];
$region_content .= theme('ds_tabs', $object->ds_fields[$key]);
}
else {
$field_content = isset($vars[$key . '_rendered']) ? $vars[$key . '_rendered'] : '';
if (!empty($field_content)) {
$count++;
$region_fields[] = $object->ds_fields[$key];
$region_content .= theme($theme_function, $field_content, $object->ds_fields[$key]);
}
}
}
if (!empty($region_content)) {
if ($region_name == 'left' || $region_name == 'right') {
$region_classes[$region_name] = $region_name;
}
$style = isset($region_styles[$region_name]) ? ' ' . $region_styles[$region_name] : '';
$themed_regions[$region_name] = array(
'content' => $region_content,
'extra_class' => $style,
'count' => $count,
'fields' => $region_fields,
);
}
}
}
$object_display = new stdClass();
$object_display->all_regions = $all_regions;
$object_display->themed_regions = $themed_regions;
$object_display->region_classes = $region_classes;
$object_display->build_mode = $object->build_mode;
ds_plugins_process($module, $api_info['object'], $display_settings, $vars, $object_display);
if (isset($object_display->themed_regions['middle'])) {
$middle_class = $module . '-no-sidebars';
if (isset($object_display->region_classes['left']) && isset($object_display->region_classes['right'])) {
$middle_class = $module . '-two-sidebars';
}
elseif (isset($object_display->region_classes['left'])) {
$middle_class = $module . '-one-sidebar ' . $module . '-sidebar-left';
}
elseif (isset($object_display->region_classes['right'])) {
$middle_class = $module . '-one-sidebar ' . $module . '-sidebar-right';
}
$object_display->themed_regions['middle']['extra_class'] .= ' ' . $middle_class;
}
return theme('ds_regions', $object_display, $module);
}
function ds_default_value($settings, $build_mode, $type, $key = NULL, $search_key = NULL, $default = NULL) {
if ($key == NULL) {
return isset($settings[$build_mode][$type]) ? $settings[$build_mode][$type] : NULL;
}
else {
return isset($settings[$build_mode][$type][$key][$search_key]) ? $settings[$build_mode][$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])) {
$ds_fields_cached = variable_get('ds_fields_cached', array());
if (!isset($ds_fields_cached[$module][$type_name][$build_mode]) || $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]);
}
}
}
drupal_alter('ds_fields', $fields);
if ($reset) {
unset($ds_fields_cached[$module][$type_name][$build_mode]);
}
else {
$ds_fields_cached[$module][$type_name][$build_mode] = $fields;
}
if ($cache) {
variable_set('ds_fields_cached', $ds_fields_cached);
}
}
else {
$fields = $ds_fields_cached[$module][$type_name][$build_mode];
}
$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($module, $object_type, $display_settings, &$vars, &$display) {
$plugins = variable_get($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_settings, $object_type, $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 = variable_get($module . '_display_settings_' . $type_name, array());
$show_fields[$module][$type_name][$build_mode][$field] = isset($display_settings[$build_mode]['fields'][$field]) && $display_settings[$build_mode]['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);
}
}