View source
<?php
define('DS_SETTINGS_UI', 1);
define('DS_SETTINGS_DEFAULT', 2);
define('DS_SETTINGS_OVERRIDDEN', 3);
define('DS_FIELD_TYPE_BASIC', 'basic');
define('DS_FIELD_TYPE_NON_DS', 'non_ds');
define('DS_FIELD_TYPE_THEME', 'theme');
define('DS_FIELD_TYPE_FUNCTION', 'function');
define('DS_FIELD_TYPE_PREPROCESS', 'preprocess');
define('DS_FIELD_TYPE_IGNORE', 'ignore');
define('DS_FIELD_TYPE_CODE', 'code');
define('DS_FIELD_TYPE_BLOCK', 'block');
define('DS_FIELD_TYPE_GROUP', 'group');
define('DS_FIELD_TYPE_MULTIGROUP', 'multigroup');
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_LAYOUT', 'default');
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_REGION', 'ds_region');
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_EXPORT', 'admin/build/ds/tools');
define('DS_PATH_STYLES', 'admin/build/ds/styles');
define('DS_PATH_MODULES', 'admin/build/ds/modules');
define('DS_PATH_PLUGINS', 'admin/build/ds/plugins');
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_ds_layouts() {
require_once 'includes/ds.registry.inc';
return _ds_ds_layouts();
}
function ds_features_api() {
require_once 'includes/ds.features.inc';
return _ds_features_api();
}
function ds_ctools_plugin_directory($module, $plugin) {
if ($module == 'ds' && !empty($plugin)) {
return "plugins/{$plugin}";
}
}
function ds_get_plugin($type, $name) {
ctools_include('plugins');
return ctools_get_plugins('ds', $type, $name);
}
function ds_get_plugins($type) {
static $types = array();
if (!isset($types[$type])) {
ctools_include('plugins');
$types[$type] = ctools_get_plugins('ds', $type);
}
return $types[$type];
}
function ds_get_field_type($field_type) {
ctools_include('plugins');
return ctools_get_plugins('ds', 'ds_field', $field_type);
}
function ds_get_field_types() {
static $types = NULL;
if (!isset($types)) {
ctools_include('plugins');
$types = ctools_get_plugins('ds', 'ds_field');
}
return $types;
}
function ds_get_display_handler($module) {
ctools_include('plugins');
$plugin = ctools_get_plugins('ds', 'ds_display', $module);
if (isset($plugin['types_callback']) && function_exists($plugin['types_callback'])) {
$plugin['types'] = call_user_func($plugin['types_callback']);
}
}
function ds_get_display_handlers() {
static $plugins = NULL;
if (!isset($plugins)) {
ctools_include('plugins');
$plugins = ctools_get_plugins('ds', 'ds_display');
foreach ($plugins as $key => $plugin) {
if (isset($plugin['types_callback']) && function_exists($plugin['types_callback'])) {
$plugins[$key]['types'] = call_user_func($plugin['types_callback']);
}
}
}
return $plugins;
}
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();
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_variable_get($var_name, $default = '') {
$value = $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($variable_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;
return TRUE;
}
return FALSE;
}
function ds_api_info($module, $type_name = 'all') {
static $api_info = array();
if (!isset($api_info[$module][$type_name])) {
$function = $module . '_ds_api';
if (function_exists($function)) {
$api_data = call_user_func($function);
}
else {
return FALSE;
}
$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_reset_fields_cache() {
db_query("UPDATE {ds_settings} set fields = ''");
}
function ds_attach_display(&$item) {
module_load_include('inc', 'ds', 'includes/ds.api');
if (is_object($item)) {
$item->ds = ds_create_display();
$item->ds
->initialise($item);
}
else {
return FALSE;
}
}
function ds_create_display() {
module_load_include('php', 'ds', 'includes/dsDisplay');
return new dsDisplay();
}
function ds_create_field($type) {
module_load_include('php', 'ds', 'includes/dsField');
$type_info = ds_get_field_type($field_type);
$field = new $type_info['class']();
return $field;
}
function ds_get_layout($name = DS_DEFAULT_LAYOUT) {
$layouts = module_invoke_all('ds_layouts');
foreach ($layouts as $key => $layout) {
if ($key == $name) {
$layout['regions']['disabled'] = array(
'name' => t('Disabled'),
);
return $layout;
}
}
}
function ds_get_regions($layout_name) {
$layout = ds_get_layout($layout_name);
return $layout['regions'];
}
function ds_api_invoke($callback, $args = array()) {
foreach (module_implements('dsapi') as $module) {
return module_invoke($module, 'dsapi', $args);
}
}
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']);
}
if (!isset($settings[$module][$type][$build_mode]['settings']['layout'])) {
$settings[$module][$type][$build_mode]['settings']['layout'] = DS_DEFAULT_LAYOUT;
}
}
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';
if (function_exists($function)) {
$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_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 $tkey => $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[$tkey][$key] = $value;
}
}
}
if (isset($type) && !empty($type)) {
if (isset($filtered_bm[$type])) {
return $filtered_bm[$type];
}
else {
return FALSE;
}
}
return $filtered_bm;
}
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_clean_attributes($attributes) {
foreach ($attributes as $key => $attr) {
if (is_array($attr)) {
$attributes[$key] = implode(' ', $attributes[$key]);
}
}
return ' ' . drupal_attributes($attributes);
}
function ds_machine_name($parts = array()) {
$name = implode('_', $parts);
return $name;
}