View source
<?php
define('DND_ID_SUFFIX', '-dnd-library');
function dnd_menu() {
$items = array();
$items['admin/config/content/dnd'] = array(
'title' => 'Drag and Drop Library',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'dnd_admin_form',
),
'description' => 'Configure the resource library used when creating content.',
'access arguments' => array(
'administer dnd',
),
'file' => 'dnd.admin.inc',
);
return $items;
}
function dnd_permission() {
return array(
'administer dnd' => array(
'title' => t('Administer DnD'),
),
);
}
function dnd_theme() {
return array(
'dnd_library_wrapper' => array(
'variables' => array(
'settings' => NULL,
'element' => NULL,
),
),
);
}
function dnd_scald_wysiwyg_context_list() {
$contexts =& drupal_static(__FUNCTION__, NULL);
if (!isset($contexts)) {
$types = scald_types();
foreach (scald_contexts_public() as $name => $definition) {
if (empty($definition['parseable'])) {
continue;
}
$definition['formats'] = $types;
foreach ($definition['formats'] as $type => $data) {
$contexts[$type][$name] = $definition['title'];
}
}
drupal_alter('scald_wysiwyg_context_list', $contexts);
}
return $contexts;
}
function dnd_scald_wysiwyg_context_slugs() {
$contexts_type = dnd_scald_wysiwyg_context_list();
$slugs = array();
foreach ($contexts_type as $contexts) {
foreach ($contexts as $slug => $label) {
$slugs[$slug] = $slug;
}
}
return array_values($slugs);
}
function dnd_library() {
$path = drupal_get_path('module', 'dnd');
$contexts = dnd_scald_wysiwyg_context_list();
$config = array();
foreach (dnd_scald_wysiwyg_context_slugs() as $slug) {
$config[$slug] = scald_context_config_load($slug);
}
$qtip_settings = '';
if (function_exists('qtip_fetch_instances_field')) {
$instance = variable_get('dnd_qtip_instance', '');
if (!empty($instance)) {
$qtip_settings = qtip_clean_settings(qtip_load($instance));
}
}
$libraries['library'] = array(
'title' => 'DnD Library',
'website' => 'http://drupal.org/project/scald',
'version' => '1.x',
'dependencies' => array(
array(
'system',
'jquery.form',
),
),
'js' => array(
$path . '/js/dnd-library.js' => array(),
$path . '/js/dnd-modal.js' => array(),
array(
'type' => 'setting',
'data' => array(
'dnd' => array(
'url' => url(dnd_get_library()),
'contexts' => $contexts,
'contextDefault' => variable_get('dnd_context_default', 'sdl_editor_representation'),
'usesCaptionDefault' => variable_get('dnd_uses_caption_default', TRUE),
'contexts_config' => $config,
'qTipSettings' => $qtip_settings,
),
),
),
),
'css' => array(
$path . '/css/dnd-library.css' => array(
'type' => 'file',
'media' => 'screen',
),
),
);
if (function_exists('qtip_library')) {
$libraries['library']['dependencies'][] = array(
'qtip',
'qtip',
);
}
dnd_library_add_ctools_modal($libraries);
$libraries['library']['dependencies'][] = array(
'dnd',
'ctools.modal',
);
return $libraries;
}
function dnd_library_add_ctools_modal(&$libraries) {
$ctools_path = drupal_get_path('module', 'ctools');
$libraries['ctools.modal'] = array(
'title' => 'CTools modal',
'version' => '1.x',
);
$libraries['ctools.modal']['js'][$ctools_path . '/js/modal.js'] = array();
$settings = array(
'CToolsModal' => array(
'loadingText' => t('Loading...'),
'closeText' => t('Close Window'),
'closeImage' => theme('image', array(
'path' => ctools_image_path('icon-close-window.png'),
'title' => t('Close window'),
'alt' => t('Close window'),
)),
'throbber' => theme('image', array(
'path' => ctools_image_path('throbber.gif'),
'title' => t('Loading...'),
'alt' => t('Loading'),
)),
),
);
$libraries['ctools.modal']['js'][] = array(
'type' => 'setting',
'data' => $settings,
);
$modal_width = (double) variable_get('dnd_modal_width', 500);
$modal_height = (double) variable_get('dnd_modal_height', 300);
$sample_style = array(
'custom-style' => array(
'modalSize' => array(
'type' => $modal_width <= 1 ? 'scale' : 'fixed',
'width' => $modal_width,
'height' => $modal_height,
'addWidth' => 20,
'addHeight' => 15,
),
'modalOptions' => array(
'opacity' => 0.5,
'background-color' => '#000',
),
'animation' => 'fadeIn',
'modalTheme' => 'CToolsSampleModal',
'throbber' => theme('image', array(
'path' => ctools_image_path('ajax-loader.gif', 'ctools_ajax_sample'),
'alt' => t('Loading...'),
'title' => t('Loading'),
)),
),
);
$libraries['ctools.modal']['js'][] = array(
'type' => 'setting',
'data' => $sample_style,
);
$libraries['ctools.modal']['css'][$ctools_path . '/css/modal.css'] = array(
'type' => 'file',
);
$libraries['ctools.modal']['dependencies'][] = array(
'system',
'drupal.progress',
);
$libraries['ctools.modal']['dependencies'][] = array(
'system',
'drupal.ajax',
);
$libraries['ctools.modal']['css'][$ctools_path . '/ctools_ajax_sample/css/ctools-ajax-sample.css'] = array(
'type' => 'file',
);
$libraries['ctools.modal']['js'][$ctools_path . '/ctools_ajax_sample/js/ctools-ajax-sample.js'] = array();
}
function dnd_library_alter(&$libraries, $module) {
if ($module == 'mee' || $module == 'atom_reference') {
$libraries['library']['dependencies'][] = array(
'dnd',
'library',
);
}
}
function dnd_entity_view_alter(&$build, $type) {
if (!module_exists('quickedit')) {
return;
}
if (!user_access('access in-place editing')) {
return;
}
if (path_is_admin(current_path())) {
return;
}
$dnd_enabled = FALSE;
foreach ($build as $item) {
if (!is_array($item)) {
continue;
}
if (isset($item['#field_name'])) {
$instance_info = field_info_instance($type, $item['#field_name'], $build['#bundle']);
if (!empty($instance_info['settings']['dnd_enabled'])) {
$dnd_enabled = TRUE;
}
if (isset($item['#field_type']) && $item['#field_type'] === 'atom_reference') {
$dnd_enabled = TRUE;
}
}
}
if ($dnd_enabled) {
$build['#attached']['library'][] = array(
'dnd',
'library',
);
}
return;
}
function dnd_suppress_library($set = TRUE) {
static $suppress = FALSE;
if ($set && !$suppress) {
$suppress = TRUE;
drupal_add_js(array(
'dnd' => array(
'suppress' => 1,
),
), 'setting');
}
return $suppress;
}
function theme_dnd_library_wrapper($variables) {
return '<div id="' . $variables['settings']['library_id'] . '" class="dnd-library-wrapper"></div>';
}
function dnd_get_libraries() {
static $libraries = NULL;
if (is_null($libraries)) {
$libraries = module_invoke_all('dnd_libraries_info');
drupal_alter('dnd_libraries_info', $libraries);
}
return $libraries;
}
function dnd_get_library() {
$libraries = dnd_get_libraries();
$default = variable_get('dnd_callback_url', '');
if (isset($libraries[$default])) {
$library = $default;
}
else {
reset($libraries);
$library = key($libraries);
}
return $library;
}