View source
<?php
require_once 'includes/styling.inc';
function wysiwyg_entity_info() {
$types['wysiwyg_profile'] = array(
'label' => t('Wysiwyg profile'),
'base table' => 'wysiwyg',
'controller class' => 'WysiwygProfileController',
'fieldable' => FALSE,
'static cache' => FALSE,
'entity keys' => array(
'id' => 'format',
),
);
return $types;
}
class WysiwygProfileController extends DrupalDefaultEntityController {
function attachLoad(&$queried_entities, $revision_id = FALSE) {
foreach ($queried_entities as $key => $record) {
$settings = unserialize($record->settings);
if (isset($settings['_profile_preferences'])) {
$preferences = $settings['_profile_preferences'];
unset($settings['_profile_preferences']);
}
else {
$preferences = array();
}
$queried_entities[$key]->settings = $settings;
$queried_entities[$key]->preferences = $preferences;
$queried_entities[$key]->name = 'format' . $record->format;
}
parent::attachLoad($queried_entities, $revision_id);
}
}
function wysiwyg_menu() {
$items['admin/config/content/wysiwyg'] = array(
'title' => 'Wysiwyg profiles',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'wysiwyg_profile_overview',
),
'description' => 'Configure client-side editors.',
'access arguments' => array(
'administer filters',
),
'file' => 'wysiwyg.admin.inc',
);
$items['admin/config/content/wysiwyg/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/content/wysiwyg/profile/%wysiwyg_ui_profile_cache'] = array(
'title callback' => 'wysiwyg_admin_profile_title',
'title arguments' => array(
5,
),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'wysiwyg_profile_form',
5,
),
'access arguments' => array(
'administer filters',
),
'file' => 'wysiwyg.admin.inc',
);
$items['admin/config/content/wysiwyg/profile/%wysiwyg_ui_profile_cache/edit'] = array(
'title' => 'Edit',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['admin/config/content/wysiwyg/profile/%wysiwyg_ui_profile_cache/delete'] = array(
'title' => 'Remove',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'wysiwyg_profile_delete_confirm',
5,
),
'access arguments' => array(
'administer filters',
),
'file' => 'wysiwyg.admin.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 10,
);
$items['admin/config/content/wysiwyg/profile/%wysiwyg_ui_profile_cache/break-lock'] = array(
'title' => 'Break lock',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'wysiwyg_profile_break_lock_confirm',
5,
),
'access arguments' => array(
'administer filters',
),
'file' => 'wysiwyg.admin.inc',
'type' => MENU_VISIBLE_IN_BREADCRUMB,
);
$items['wysiwyg/%'] = array(
'page callback' => 'wysiwyg_dialog',
'page arguments' => array(
1,
),
'delivery callback' => 'wysiwyg_deliver_dialog_page',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
'file' => 'wysiwyg.dialog.inc',
);
$items['wysiwyg_theme/%'] = array(
'theme callback' => '_wysiwyg_theme_callback',
'theme arguments' => array(
1,
),
'page callback' => '_wysiwyg_theme_check_active',
'page arguments' => array(
1,
),
'delivery callback' => '_wysiwyg_delivery_dummy',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function wysiwyg_admin_profile_title($profile) {
$format = filter_format_load($profile->format);
return $format->name;
}
function wysiwyg_admin_menu_map() {
if (!user_access('administer filters')) {
return;
}
$profiles = wysiwyg_profile_load_all();
$map['admin/config/content/wysiwyg/profile/%wysiwyg_ui_profile_cache'] = array(
'parent' => 'admin/config/content/wysiwyg',
'hide' => 'admin/config/content/wysiwyg/list',
'arguments' => array(
array(
'%wysiwyg_ui_profile_cache' => array_keys($profiles),
),
),
);
return $map;
}
function wysiwyg_element_info() {
$types['wysiwyg_dialog_page'] = array(
'#theme' => 'wysiwyg_dialog_page',
'#theme_wrappers' => array(
'html',
),
'#show_messages' => TRUE,
);
return $types;
}
function wysiwyg_theme() {
return array(
'wysiwyg_profile_overview' => array(
'render element' => 'form',
),
'wysiwyg_admin_button_table' => array(
'render element' => 'form',
),
'wysiwyg_dialog_page' => array(
'render element' => 'page',
'file' => 'wysiwyg.dialog.inc',
'template' => 'wysiwyg-dialog-page',
),
);
}
function wysiwyg_help($path, $arg) {
switch ($path) {
case 'admin/config/content/wysiwyg':
$output = '<p>' . t('A Wysiwyg profile is associated with a text format. A Wysiwyg profile defines which client-side editor is loaded with a particular text format, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor-specific functions.') . '</p>';
return $output;
}
}
function wysiwyg_element_info_alter(&$types) {
$types['text_format']['#pre_render'][] = 'wysiwyg_pre_render_text_format';
array_unshift($types['styles']['#pre_render'], '_wysiwyg_filter_editor_styles');
$types['styles']['#pre_render'][] = '_wysiwyg_pre_render_styles';
}
function wysiwyg_pre_render_text_format($element) {
if (!isset($element['format']['format']) || !empty($element['value']['#disabled'])) {
return $element;
}
if (isset($element['#wysiwyg']) && !$element['#wysiwyg']) {
return $element;
}
$format_field =& $element['format'];
$field =& $element['value'];
$settings = array(
'field' => $field['#id'],
);
if (!empty($field['#resizable'])) {
$settings['resizable'] = 1;
}
if (isset($element['summary']) && $element['summary']['#type'] == 'textarea') {
$settings['summary'] = $element['summary']['#id'];
}
if (!$format_field['format']['#access'] || isset($format_field['#access']) && !$format_field['#access']) {
$available_formats = array(
$format_field['format']['#value'] => $format_field['format']['#options'][$format_field['format']['#value']],
);
$settings['activeFormat'] = $format_field['format']['#value'];
}
else {
$available_formats = $format_field['format']['#options'];
$settings['select'] = $format_field['format']['#id'];
}
foreach ($available_formats as $format_id => $format_name) {
$format = 'format' . $format_id;
$profile = wysiwyg_get_profile($format_id);
if ($profile) {
$settings[$format] = array(
'editor' => 'none',
'status' => 1,
'toggle' => 1,
);
$loaded = TRUE;
if (isset($profile->preferences['add_to_summaries']) && !$profile->preferences['add_to_summaries']) {
$settings[$format]['skip_summary'] = 1;
}
$settings[$format]['editor'] = $profile->editor;
$settings[$format]['status'] = (int) wysiwyg_user_get_status($profile);
if (isset($profile->preferences['show_toggle'])) {
$settings[$format]['toggle'] = (int) $profile->preferences['show_toggle'];
}
$theme = wysiwyg_get_editor_themes($profile, isset($profile->settings['theme']) ? $profile->settings['theme'] : '');
wysiwyg_add_plugin_settings($profile);
wysiwyg_add_editor_settings($profile, $theme);
}
}
if (!empty($element['value']['#value'])) {
$original = $element['value']['#value'];
$element['value']['#attributes']['data-wysiwyg-value-original'] = $original;
$element['value']['#attributes']['data-wysiwyg-value-is-changed'] = 'false';
}
if (!empty($element['summary']['#value']) && $element['summary']['#type'] === 'textarea') {
$original = $element['summary']['#value'];
$element['summary']['#attributes']['data-wysiwyg-value-original'] = $original;
$element['summary']['#attributes']['data-wysiwyg-value-is-changed'] = 'false';
}
$element['value']['#attributes']['class'][] = 'wysiwyg';
$element['#attached']['js'][] = array(
'data' => array(
'wysiwyg' => array(
'triggers' => array(
$element['value']['#id'] => $settings,
),
),
),
'type' => 'setting',
);
return $element;
}
function wysiwyg_get_profile($format) {
if ($profile = wysiwyg_profile_load($format)) {
if (wysiwyg_load_editor($profile)) {
return $profile;
}
}
return FALSE;
}
function wysiwyg_load_editor($profile) {
static $settings_added;
static $loaded = array();
$path = drupal_get_path('module', 'wysiwyg');
$name = $profile->editor;
if (!isset($loaded[$name])) {
$editor = wysiwyg_get_editor($name);
if ($editor) {
$default_library_options = array(
'type' => 'file',
'scope' => 'header',
'defer' => FALSE,
'cache' => TRUE,
'preprocess' => TRUE,
);
if (isset($profile->preferences['library']) && isset($editor['libraries'][$profile->preferences['library']])) {
$library = $profile->preferences['library'];
$files = $editor['libraries'][$library]['files'];
}
else {
$library = key($editor['libraries']);
$files = array_shift($editor['libraries']);
$files = $files['files'];
}
if (!empty($editor['init callback'])) {
$init = $editor['init callback']($editor, $library, $profile);
if (!empty($init)) {
$uri = 'public://js/wysiwyg/wysiwyg_' . $name . '_' . drupal_hash_base64($init) . '.js';
$init_exists = file_exists($uri);
if (!$init_exists) {
$js_path = dirname($uri);
file_prepare_directory($js_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
}
if (!$init_exists && !file_unmanaged_save_data($init, $uri, FILE_EXISTS_REPLACE)) {
drupal_add_js($init, array(
'type' => 'inline',
) + $default_library_options);
}
else {
drupal_add_js($uri, $default_library_options);
}
}
}
foreach ($files as $file => $options) {
if (is_array($options)) {
$options += $default_library_options;
drupal_add_js($editor['library path'] . '/' . $file, $options);
}
else {
drupal_add_js($editor['library path'] . '/' . $options);
}
}
if (isset($editor['load callback']) && function_exists($editor['load callback'])) {
$editor['load callback']($editor, $library);
}
$files = array();
if (isset($editor['js files'])) {
$files = $editor['js files'];
}
foreach ($files as $file) {
drupal_add_js($editor['js path'] . '/' . $file);
}
$files = array();
if (isset($editor['css files'])) {
$files = $editor['css files'];
}
foreach ($files as $file) {
drupal_add_css($editor['css path'] . '/' . $file);
}
$loaded[$name] = TRUE;
}
else {
$loaded[$name] = FALSE;
}
}
if (isset($_POST['ajax_page_state']) && !empty($_POST['ajax_page_state']['js'][$path . '/wysiwyg.js'])) {
$settings_added = TRUE;
}
if (!isset($settings_added) && $loaded[$name]) {
drupal_add_js(array(
'wysiwyg' => array(
'configs' => array(),
'plugins' => array(),
'disable' => t('Disable rich-text'),
'enable' => t('Enable rich-text'),
),
), 'setting');
drupal_add_js($path . '/wysiwyg.init.js', array(
'group' => JS_LIBRARY,
));
drupal_add_js($path . '/editors/js/none.js');
drupal_add_js($path . '/wysiwyg.js', array(
'scope' => 'footer',
));
$settings_added = TRUE;
}
return $loaded[$name];
}
function wysiwyg_add_editor_settings($profile, $theme) {
static $formats = array();
if (!isset($formats[$profile->format])) {
$config = wysiwyg_get_editor_config($profile, $theme);
if ($config) {
drupal_add_js(array(
'wysiwyg' => array(
'configs' => array(
$profile->editor => array(
'format' . $profile->format => $config,
),
),
),
), 'setting');
}
$formats[$profile->format] = TRUE;
}
}
function wysiwyg_add_plugin_settings($profile) {
static $plugins = array();
static $processed_plugins = array();
static $processed_formats = array();
if (isset($processed_formats[$profile->format])) {
return;
}
$processed_formats[$profile->format] = TRUE;
$editor = wysiwyg_get_editor($profile->editor);
if (!array_key_exists($editor['name'], $plugins)) {
$plugins[$editor['name']] = wysiwyg_get_plugins($editor['name']);
}
if (empty($plugins[$editor['name']])) {
return;
}
$proxy = isset($editor['proxy plugin']) ? key($editor['proxy plugin']) : '';
$profile_plugins_native = array();
foreach ($plugins[$editor['name']] as $plugin => $meta) {
if ($plugin === $proxy || $plugin === 'default') {
continue;
}
if (isset($profile->settings['buttons'][$plugin])) {
$profile_plugins_native[$plugin] = $meta;
if (!isset($processed_plugins[$editor['name']][$plugin])) {
if (isset($editor['plugin meta callback'])) {
$meta['name'] = $plugin;
if ($native_meta = call_user_func($editor['plugin meta callback'], $editor, $meta)) {
drupal_add_js(array(
'wysiwyg' => array(
'plugins' => array(
'native' => array(
$editor['name'] => array(
$plugin => $native_meta,
),
),
),
),
), 'setting');
}
}
$processed_plugins[$editor['name']][$plugin] = $meta;
}
}
}
if (!empty($profile_plugins_native) && isset($editor['plugin settings callback'])) {
if ($settings_native = call_user_func($editor['plugin settings callback'], $editor, $profile, $profile_plugins_native)) {
drupal_add_js(array(
'wysiwyg' => array(
'plugins' => array(
'format' . $profile->format => array(
'native' => $settings_native,
),
),
),
), 'setting');
}
}
if ($proxy && isset($editor['proxy plugin settings callback'])) {
$profile_plugins_drupal = array();
foreach (wysiwyg_get_all_plugins() as $plugin => $meta) {
if (isset($profile->settings['buttons'][$proxy][$plugin])) {
if (!isset($processed_plugins[$proxy][$plugin])) {
$profile_plugins_drupal[$plugin] = $processed_plugins[$proxy][$plugin] = $meta;
drupal_add_js($meta['js path'] . '/' . $meta['js file']);
$settings = isset($meta['settings']) ? $meta['settings'] : array();
$settings['title'] = $meta['title'];
$settings['icon'] = base_path() . $meta['icon path'] . '/' . $meta['icon file'];
if (!empty($meta['css path']) && !empty($meta['css file'])) {
$settings['css'] = base_path() . $meta['css path'] . '/' . $meta['css file'];
}
drupal_add_js(array(
'wysiwyg' => array(
'plugins' => array(
'drupal' => array(
$plugin => $settings,
),
),
),
), 'setting');
}
else {
$profile_plugins_drupal[$plugin] = $processed_plugins[$proxy][$plugin];
}
}
}
$settings_drupal = call_user_func($editor['proxy plugin settings callback'], $editor, $profile, $profile_plugins_drupal);
if ($settings_drupal) {
drupal_add_js(array(
'wysiwyg' => array(
'plugins' => array(
'format' . $profile->format => array(
'drupal' => $settings_drupal,
),
),
),
), 'setting');
}
}
}
function wysiwyg_get_editor_themes(&$profile, $selected_theme = NULL) {
static $themes = array();
if (!isset($themes[$profile->editor])) {
$editor = wysiwyg_get_editor($profile->editor);
if (isset($editor['themes callback']) && function_exists($editor['themes callback'])) {
$themes[$editor['name']] = $editor['themes callback']($editor, $profile);
}
else {
$themes[$editor['name']] = array(
'default',
);
}
}
if (isset($selected_theme)) {
if (!in_array($selected_theme, $themes[$profile->editor])) {
$selected_theme = $profile->settings['theme'] = $themes[$profile->editor][0];
}
}
return isset($selected_theme) ? $selected_theme : $themes[$profile->editor];
}
function wysiwyg_get_plugins($editor_name) {
$plugins = array();
if (!empty($editor_name)) {
$editor = wysiwyg_get_editor($editor_name);
if (isset($editor['plugin callback']) && function_exists($editor['plugin callback'])) {
$plugins = $editor['plugin callback']($editor);
}
$plugins = array_merge($plugins, module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']));
if (isset($editor['proxy plugin'])) {
$plugins += $editor['proxy plugin'];
$proxy = key($editor['proxy plugin']);
foreach (wysiwyg_get_all_plugins() as $plugin_name => $info) {
$plugins[$proxy]['buttons'][$plugin_name] = $info['title'];
}
}
}
return $plugins;
}
function wysiwyg_get_editor_config($profile, $theme) {
$editor = wysiwyg_get_editor($profile->editor);
$settings = array();
$installed_version = $editor['installed version'];
$settings = $profile->settings;
if (!empty($editor['settings callback']) && function_exists($editor['settings callback'])) {
if (!empty($profile->preferences['version']) && !empty($installed_version)) {
$profile_version = $profile->preferences['version'];
$version_status = version_compare($profile_version, $installed_version);
if ($version_status !== 0) {
$migrated = FALSE;
if (!empty($editor['migrate settings callback']) && function_exists($editor['migrate settings callback'])) {
$migrated = $editor['migrate settings callback']($settings, $editor, $profile_version, $installed_version);
}
}
}
$settings = $editor['settings callback']($editor, $settings, $theme);
$context = array(
'editor' => $editor,
'profile' => $profile,
'theme' => $theme,
);
drupal_alter('wysiwyg_editor_settings', $settings, $context);
}
return $settings;
}
function wysiwyg_get_css($theme = NULL) {
if (empty($theme)) {
$theme = variable_get('node_admin_theme') && user_access('view the administration theme') ? variable_get('admin_theme') : variable_get('theme_default', 'bartik');
}
elseif ($theme == 'wysiwyg_theme_admin' && user_access('view the administration theme') && ($admin_theme = variable_get('admin_theme'))) {
$theme = $admin_theme;
}
$themes = list_themes();
if (!isset($themes[$theme])) {
drupal_theme_initialize();
}
if (!drupal_theme_access($theme)) {
$theme = variable_get('theme_default', 'bartik');
}
$cached = cache_get('wysiwyg_css');
$css = array();
$update_cache = strpos(current_path(), 'wysiwyg_theme/') === FALSE && (!$cached || (empty($cached->data[$theme]) || $cached->data[$theme]['aggregated'] !== variable_get('preprocess_css', FALSE)) || $cached->data['_css_js_query_string'] !== variable_get('css_js_query_string'));
if ($update_cache) {
$css[] = url('wysiwyg_theme/' . $theme, array(
'absolute' => TRUE,
));
}
elseif (!empty($cached->data[$theme])) {
$css = $cached->data[$theme]['files'];
}
return $css;
}
function wysiwyg_themes_enabled($theme_list) {
$cached = cache_get('wysiwyg_css');
if ($cached && !empty($cached->data)) {
$css = $cached->data;
foreach ($theme_list as $theme) {
unset($css[$theme]);
}
cache_set('wysiwyg_css', $css);
}
}
function wysiwyg_form_system_theme_settings_alter(&$form, &$form_state, $form_id) {
$form['#submit'][] = '_wysiwyg_system_theme_settings_submit';
}
function _wysiwyg_system_theme_settings_submit($form, &$form_state) {
$theme = NULL;
if ($form_state['build_info']['form_id'] == 'system_theme_settings' && !empty($form_state['build_info']['args'])) {
$theme = $form_state['build_info']['args'][0];
}
if ($theme !== NULL) {
$cached = cache_get('wysiwyg_css');
if ($cached && !empty($cached->data)) {
$css = $cached->data;
unset($css[$theme]);
cache_set('wysiwyg_css', $css);
}
}
wysiwyg_get_css($theme);
}
function wysiwyg_profile_load($format) {
$profiles = wysiwyg_profile_load_all();
return isset($profiles[$format]) ? $profiles[$format] : FALSE;
}
function wysiwyg_profile_load_all() {
$profiles =& drupal_static(__FUNCTION__);
if (!isset($profiles)) {
if ($cached = cache_get('wysiwyg_profiles')) {
$profiles = $cached->data;
}
else {
$profiles = entity_load('wysiwyg_profile', FALSE);
$formats = filter_formats();
foreach ($profiles as $key => $profile) {
if (empty($profile->editor) || !isset($formats[$profile->format])) {
unset($profiles[$key]);
}
}
cache_set('wysiwyg_profiles', $profiles);
}
}
return $profiles;
}
function wysiwyg_profile_delete($profile) {
db_delete('wysiwyg')
->condition('format', $profile->format)
->execute();
if (module_exists('ctools')) {
ctools_include('object-cache');
ctools_object_cache_clear_all('wysiwyg_profile', $profile->name);
}
else {
cache_clear_all('wysiwyg_profile:' . $profile->name, 'cache');
}
wysiwyg_profile_cache_clear();
}
function wysiwyg_ui_profile_cache_load($format) {
$original_profile = wysiwyg_profile_load($format);
$profile = FALSE;
$name = $original_profile ? $original_profile->name : 'format' . $format;
$profile = wysiwyg_ui_profile_cache_get($name);
if (empty($profile)) {
$profile = $original_profile;
}
if (!empty($profile)) {
$profile->editing = TRUE;
return $profile;
}
return FALSE;
}
function wysiwyg_ui_profile_cache_get($name) {
$profile = FALSE;
if (module_exists('ctools')) {
ctools_include('object-cache');
$profile = ctools_object_cache_get('wysiwyg_profile', $name);
if ($profile) {
$profile->locked = ctools_object_cache_test('wysiwyg_profile', $name);
}
}
else {
$cached = cache_get('wysiwyg_profile:' . $name);
if ($cached) {
$profile = $cached->data;
$profile->locked = FALSE;
}
}
return $profile;
}
function wysiwyg_ui_profile_cache_set(&$profile) {
if (!empty($profile->locked)) {
drupal_set_message(t('Changes can not be made to a locked profile.'), 'error');
return;
}
$profile->changed = TRUE;
if (module_exists('ctools')) {
ctools_include('object-cache');
ctools_object_cache_set('wysiwyg_profile', $profile->name, $profile);
}
else {
cache_set('wysiwyg_profile:' . $profile->name, $profile);
}
}
function wysiwyg_profile_cache_clear() {
entity_get_controller('wysiwyg_profile')
->resetCache();
drupal_static_reset('wysiwyg_profile_load_all');
cache_clear_all('wysiwyg_profiles', 'cache');
}
function wysiwyg_form_user_profile_form_alter(&$form, &$form_state, $form_id) {
if ($form['#user_category'] != 'account') {
return;
}
$account = $form['#user'];
$user_formats = filter_formats($account);
$options = array();
$options_default = array();
foreach (wysiwyg_profile_load_all() as $format => $profile) {
if (!empty($profile->preferences['user_choose']) && isset($user_formats[$format])) {
$options[$format] = check_plain($user_formats[$format]->name);
if (wysiwyg_user_get_status($profile, $account)) {
$options_default[] = $format;
}
}
}
if (!empty($options)) {
$form['wysiwyg']['wysiwyg_status'] = array(
'#type' => 'checkboxes',
'#title' => t('Text formats enabled for rich-text editing'),
'#options' => $options,
'#default_value' => $options_default,
);
}
}
function wysiwyg_user_insert(&$edit, $account, $category) {
wysiwyg_user_update($edit, $account, $category);
}
function wysiwyg_user_update(&$edit, $account, $category) {
if (isset($edit['wysiwyg_status'])) {
db_delete('wysiwyg_user')
->condition('uid', $account->uid)
->execute();
$query = db_insert('wysiwyg_user')
->fields(array(
'uid',
'format',
'status',
));
foreach ($edit['wysiwyg_status'] as $format => $status) {
$query
->values(array(
'uid' => $account->uid,
'format' => $format,
'status' => (int) (bool) $status,
));
}
$query
->execute();
}
}
function wysiwyg_user_get_status($profile, $account = NULL) {
global $user;
if (!isset($account)) {
$account = $user;
}
if (!isset($account->wysiwyg_status)) {
$account->wysiwyg_status = db_query("SELECT format, status FROM {wysiwyg_user} WHERE uid = :uid", array(
':uid' => $account->uid,
))
->fetchAllKeyed();
}
if (!empty($profile->preferences['user_choose']) && isset($account->wysiwyg_status[$profile->format])) {
$status = $account->wysiwyg_status[$profile->format];
}
else {
$status = isset($profile->preferences['default']) ? $profile->preferences['default'] : TRUE;
}
return (bool) $status;
}
function wysiwyg_get_editor($name) {
$editors = wysiwyg_get_all_editors();
return isset($editors[$name]) && $editors[$name]['installed'] ? $editors[$name] : FALSE;
}
function wysiwyg_get_all_editors() {
static $editors;
if (isset($editors)) {
return $editors;
}
$editors = wysiwyg_load_includes('editors', 'editor');
foreach ($editors as $editor => $properties) {
$editors[$editor] += array(
'title' => '',
'vendor url' => '',
'download url' => '',
'editor path' => wysiwyg_get_path($editors[$editor]['name']),
'library path' => wysiwyg_get_path($editors[$editor]['name']),
'libraries' => array(),
'installed' => FALSE,
'version callback' => NULL,
'themes callback' => NULL,
'settings form callback' => NULL,
'settings callback' => NULL,
'plugin callback' => NULL,
'plugin settings callback' => NULL,
'versions' => array(),
'js path' => $editors[$editor]['path'] . '/js',
'css path' => $editors[$editor]['path'] . '/css',
);
if (!$editors[$editor]['installed'] && !($editors[$editor]['installed'] = file_exists($editors[$editor]['library path']))) {
ksort($editors[$editor]['versions']);
$version = key($editors[$editor]['versions']);
foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) {
if (version_compare($version, $supported_version, '<')) {
$version = $supported_version;
}
}
$editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]);
continue;
}
$installed_version = NULL;
if (function_exists($editors[$editor]['version callback'])) {
$installed_version = $editors[$editor]['installed version'] = $editors[$editor]['version callback']($editors[$editor]);
}
if (empty($installed_version)) {
$editors[$editor]['error'] = t('The version of %editor could not be detected.', array(
'%editor' => $properties['title'],
));
$editors[$editor]['installed'] = FALSE;
continue;
}
$editors[$editor]['installed version verified'] = TRUE;
if (!empty($editors[$editor]['verified version range'])) {
$version_range = $editors[$editor]['verified version range'];
if (version_compare($installed_version, $version_range[0], '<') || version_compare($installed_version, $version_range[1], '>')) {
$editors[$editor]['installed version verified'] = FALSE;
}
}
ksort($editors[$editor]['versions']);
$version = 0;
foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) {
if (version_compare($installed_version, $supported_version, '>=')) {
$version = $supported_version;
}
}
if (!$version) {
$editors[$editor]['error'] = t('The installed version %version of %editor is not supported.', array(
'%version' => $installed_version,
'%editor' => $editors[$editor]['title'],
));
$editors[$editor]['installed'] = FALSE;
continue;
}
$editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]);
unset($editors[$editor]['versions']);
}
drupal_alter('wysiwyg_editor', $editors);
return $editors;
}
function wysiwyg_get_all_plugins() {
static $plugins;
if (isset($plugins)) {
return $plugins;
}
$plugins = wysiwyg_load_includes('plugins', 'plugin');
foreach ($plugins as $name => $properties) {
$plugin =& $plugins[$name];
$plugin += array(
'title' => $plugin['name'],
'vendor url' => '',
'js path' => $plugin['path'] . '/' . $plugin['name'],
'js file' => $plugin['name'] . '.js',
'css path' => $plugin['path'] . '/' . $plugin['name'],
'css file' => $plugin['name'] . '.css',
'icon path' => $plugin['path'] . '/' . $plugin['name'] . '/images',
'icon file' => $plugin['name'] . '.png',
'dialog path' => $plugin['name'],
'dialog settings' => array(),
'settings callback' => NULL,
'settings form callback' => NULL,
);
$plugin['settings'] += array(
'path' => base_path() . $plugin['path'] . '/' . $plugin['name'],
);
if (!($plugin['installed'] = file_exists($plugin['js path'] . '/' . $plugin['js file']))) {
continue;
}
}
return $plugins;
}
function wysiwyg_load_includes($type = 'editors', $hook = 'editor', $file = NULL) {
$directories = wysiwyg_get_directories($type);
$directories['wysiwyg'] = drupal_get_path('module', 'wysiwyg') . '/' . $type;
$file_list = array();
foreach ($directories as $module => $path) {
$file_list[$module] = drupal_system_listing("/{$file}.inc\$/", $path, 'name', 0);
}
$info = array();
foreach (array_filter($file_list) as $module => $files) {
foreach ($files as $file) {
include_once './' . $file->uri;
$result = _wysiwyg_process_include($module, $module . '_' . $file->name, dirname($file->uri), $hook);
if (is_array($result)) {
$info = array_merge($info, $result);
}
}
}
drupal_alter('wysiwyg_load_includes', $info, $hook);
return $info;
}
function wysiwyg_get_path($library, $base_path = FALSE) {
static $libraries;
if (!isset($libraries)) {
$libraries = wysiwyg_get_libraries();
}
if (!isset($libraries[$library])) {
return 'sites/all/libraries/' . $library;
}
$path = $base_path ? base_path() : '';
$path .= $libraries[$library];
return $path;
}
function wysiwyg_get_libraries() {
if (function_exists('libraries_get_libraries')) {
$directories = libraries_get_libraries();
}
else {
global $profile;
if (!isset($profile)) {
$profile = variable_get('install_profile', 'default');
}
$directory = 'libraries';
$searchdir = array();
$config = conf_path();
if (file_exists("profiles/{$profile}/{$directory}")) {
$searchdir[] = "profiles/{$profile}/{$directory}";
}
$searchdir[] = 'sites/all/' . $directory;
if (file_exists("{$config}/{$directory}")) {
$searchdir[] = "{$config}/{$directory}";
}
$directories = array();
$nomask = array(
'CVS',
);
foreach ($searchdir as $dir) {
if (is_dir($dir) && ($handle = opendir($dir))) {
while (FALSE !== ($file = readdir($handle))) {
if (!in_array($file, $nomask) && $file[0] != '.') {
if (is_dir("{$dir}/{$file}")) {
$directories[$file] = "{$dir}/{$file}";
}
}
}
closedir($handle);
}
}
}
return $directories;
}
function wysiwyg_get_directories($plugintype) {
$directories = array();
foreach (module_implements('wysiwyg_include_directory') as $module) {
$result = module_invoke($module, 'wysiwyg_include_directory', $plugintype);
if (isset($result) && is_string($result)) {
$directories[$module] = drupal_get_path('module', $module) . '/' . $result;
}
}
return $directories;
}
function wysiwyg_wrap_js_callback($name, $context = NULL) {
$obj = array(
'drupalWysiwygType' => 'callback',
'name' => $name,
);
if ($context) {
$obj['context'] = $context;
}
return $obj;
}
function wysiwyg_wrap_js_regexp($regexp, $modifiers = NULL) {
$obj = array(
'drupalWysiwygType' => 'regexp',
'regexp' => $regexp,
);
if ($modifiers) {
$obj['modifiers'] = $modifiers;
}
return $obj;
}
function _wysiwyg_process_include($module, $identifier, $path, $hook) {
$function = $identifier . '_' . $hook;
if (!function_exists($function)) {
return NULL;
}
$result = $function();
if (!isset($result) || !is_array($result)) {
return NULL;
}
foreach ($result as $editor => $properties) {
$result[$editor]['module'] = $module;
$result[$editor]['name'] = $editor;
$result[$editor]['path'] = $path;
}
return $result;
}
function wysiwyg_features_api() {
return array(
'wysiwyg' => array(
'name' => t('Wysiwyg profiles'),
'default_hook' => 'wysiwyg_default_profiles',
'default_file' => FEATURES_DEFAULTS_INCLUDED,
'feature_source' => TRUE,
'file' => drupal_get_path('module', 'wysiwyg') . '/wysiwyg.features.inc',
),
);
}