danielebarchiesi@0: t('Wysiwyg profile'), danielebarchiesi@0: 'base table' => 'wysiwyg', danielebarchiesi@0: 'controller class' => 'WysiwygProfileController', danielebarchiesi@0: 'fieldable' => FALSE, danielebarchiesi@0: // When loading all entities, DrupalDefaultEntityController::load() ignores danielebarchiesi@0: // its static cache. Therefore, wysiwyg_profile_load_all() implements a danielebarchiesi@0: // custom static cache. danielebarchiesi@0: 'static cache' => FALSE, danielebarchiesi@0: 'entity keys' => array( danielebarchiesi@0: 'id' => 'format', danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: return $types; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Controller class for Wysiwyg profiles. danielebarchiesi@0: */ danielebarchiesi@0: class WysiwygProfileController extends DrupalDefaultEntityController { danielebarchiesi@0: /** danielebarchiesi@0: * Overrides DrupalDefaultEntityController::attachLoad(). danielebarchiesi@0: */ danielebarchiesi@0: function attachLoad(&$queried_entities, $revision_id = FALSE) { danielebarchiesi@0: // Unserialize the profile settings. danielebarchiesi@0: foreach ($queried_entities as $key => $record) { danielebarchiesi@0: $queried_entities[$key]->settings = unserialize($record->settings); danielebarchiesi@0: } danielebarchiesi@0: // Call the default attachLoad() method. danielebarchiesi@0: parent::attachLoad($queried_entities, $revision_id); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implementation of hook_menu(). danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_menu() { danielebarchiesi@0: $items['admin/config/content/wysiwyg'] = array( danielebarchiesi@0: 'title' => 'Wysiwyg profiles', danielebarchiesi@0: 'page callback' => 'drupal_get_form', danielebarchiesi@0: 'page arguments' => array('wysiwyg_profile_overview'), danielebarchiesi@0: 'description' => 'Configure client-side editors.', danielebarchiesi@0: 'access arguments' => array('administer filters'), danielebarchiesi@0: 'file' => 'wysiwyg.admin.inc', danielebarchiesi@0: ); danielebarchiesi@0: $items['admin/config/content/wysiwyg/profile'] = array( danielebarchiesi@0: 'title' => 'List', danielebarchiesi@0: 'type' => MENU_DEFAULT_LOCAL_TASK, danielebarchiesi@0: ); danielebarchiesi@0: $items['admin/config/content/wysiwyg/profile/%wysiwyg_profile/edit'] = array( danielebarchiesi@0: 'title' => 'Edit', danielebarchiesi@0: 'page callback' => 'drupal_get_form', danielebarchiesi@0: 'page arguments' => array('wysiwyg_profile_form', 5), danielebarchiesi@0: 'access arguments' => array('administer filters'), danielebarchiesi@0: 'file' => 'wysiwyg.admin.inc', danielebarchiesi@0: 'tab_root' => 'admin/config/content/wysiwyg/profile', danielebarchiesi@0: 'tab_parent' => 'admin/config/content/wysiwyg/profile/%wysiwyg_profile', danielebarchiesi@0: 'type' => MENU_LOCAL_TASK, danielebarchiesi@0: ); danielebarchiesi@0: $items['admin/config/content/wysiwyg/profile/%wysiwyg_profile/delete'] = array( danielebarchiesi@0: 'title' => 'Remove', danielebarchiesi@0: 'page callback' => 'drupal_get_form', danielebarchiesi@0: 'page arguments' => array('wysiwyg_profile_delete_confirm', 5), danielebarchiesi@0: 'access arguments' => array('administer filters'), danielebarchiesi@0: 'file' => 'wysiwyg.admin.inc', danielebarchiesi@0: 'tab_root' => 'admin/config/content/wysiwyg/profile', danielebarchiesi@0: 'tab_parent' => 'admin/config/content/wysiwyg/profile/%wysiwyg_profile', danielebarchiesi@0: 'type' => MENU_LOCAL_TASK, danielebarchiesi@0: 'weight' => 10, danielebarchiesi@0: ); danielebarchiesi@0: // @see wysiwyg_dialog() danielebarchiesi@0: $items['wysiwyg/%'] = array( danielebarchiesi@0: 'page callback' => 'wysiwyg_dialog', danielebarchiesi@0: 'page arguments' => array(1), danielebarchiesi@0: 'delivery callback' => 'wysiwyg_deliver_dialog_page', danielebarchiesi@0: 'access arguments' => array('access content'), danielebarchiesi@0: 'type' => MENU_CALLBACK, danielebarchiesi@0: 'file' => 'wysiwyg.dialog.inc', danielebarchiesi@0: ); danielebarchiesi@0: return $items; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implements hook_element_info(). danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_element_info() { danielebarchiesi@0: // @see wysiwyg_dialog() danielebarchiesi@0: $types['wysiwyg_dialog_page'] = array( danielebarchiesi@0: '#theme' => 'wysiwyg_dialog_page', danielebarchiesi@0: '#theme_wrappers' => array('html'), danielebarchiesi@0: '#show_messages' => TRUE, danielebarchiesi@0: ); danielebarchiesi@0: return $types; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implementation of hook_theme(). danielebarchiesi@0: * danielebarchiesi@0: * @see drupal_common_theme(), common.inc danielebarchiesi@0: * @see template_preprocess_page(), theme.inc danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_theme() { danielebarchiesi@0: return array( danielebarchiesi@0: 'wysiwyg_profile_overview' => array( danielebarchiesi@0: 'render element' => 'form', danielebarchiesi@0: ), danielebarchiesi@0: 'wysiwyg_admin_button_table' => array( danielebarchiesi@0: 'render element' => 'form', danielebarchiesi@0: ), danielebarchiesi@0: // @see wysiwyg_dialog() danielebarchiesi@0: 'wysiwyg_dialog_page' => array( danielebarchiesi@0: 'render element' => 'page', danielebarchiesi@0: 'file' => 'wysiwyg.dialog.inc', danielebarchiesi@0: 'template' => 'wysiwyg-dialog-page', danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implementation of hook_help(). danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_help($path, $arg) { danielebarchiesi@0: switch ($path) { danielebarchiesi@0: case 'admin/config/content/wysiwyg': danielebarchiesi@0: $output = '
' . 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.') . '
'; danielebarchiesi@0: return $output; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implementation of hook_form_alter(). danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_form_alter(&$form, &$form_state) { danielebarchiesi@0: // Teaser splitter is unconditionally removed and NOT supported. danielebarchiesi@0: if (isset($form['body_field'])) { danielebarchiesi@0: unset($form['body_field']['teaser_js']); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implements hook_element_info_alter(). danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_element_info_alter(&$types) { danielebarchiesi@0: $types['text_format']['#pre_render'][] = 'wysiwyg_pre_render_text_format'; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Process a text format widget to load and attach editors. danielebarchiesi@0: * danielebarchiesi@0: * The element's #id is used as reference to attach client-side editors. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_pre_render_text_format($element) { danielebarchiesi@0: // filter_process_format() copies properties to the expanded 'value' child danielebarchiesi@0: // element. Skip this text format widget, if it contains no 'format' or when danielebarchiesi@0: // the current user does not have access to edit the value. danielebarchiesi@0: if (!isset($element['format']) || !empty($element['value']['#disabled'])) { danielebarchiesi@0: return $element; danielebarchiesi@0: } danielebarchiesi@0: // Allow modules to programmatically enforce no client-side editor by setting danielebarchiesi@0: // the #wysiwyg property to FALSE. danielebarchiesi@0: if (isset($element['#wysiwyg']) && !$element['#wysiwyg']) { danielebarchiesi@0: return $element; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $format_field = &$element['format']; danielebarchiesi@0: $field = &$element['value']; danielebarchiesi@0: $settings = array( danielebarchiesi@0: 'field' => $field['#id'], danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // If this textarea is #resizable and we will load at least one danielebarchiesi@0: // editor, then only load the behavior and let the 'none' editor danielebarchiesi@0: // attach/detach it to avoid hi-jacking the UI. Due to our CSS class danielebarchiesi@0: // parsing, we can add arbitrary parameters for each input format. danielebarchiesi@0: // The #resizable property will be removed below, if at least one danielebarchiesi@0: // profile has been loaded. danielebarchiesi@0: $resizable = 0; danielebarchiesi@0: if (!empty($field['#resizable'])) { danielebarchiesi@0: $resizable = 1; danielebarchiesi@0: drupal_add_js('misc/textarea.js'); danielebarchiesi@0: } danielebarchiesi@0: // Determine the available text formats. danielebarchiesi@0: foreach ($format_field['format']['#options'] as $format_id => $format_name) { danielebarchiesi@0: $format = 'format' . $format_id; danielebarchiesi@0: // Initialize default settings, defaulting to 'none' editor. danielebarchiesi@0: $settings[$format] = array( danielebarchiesi@0: 'editor' => 'none', danielebarchiesi@0: 'status' => 1, danielebarchiesi@0: 'toggle' => 1, danielebarchiesi@0: 'resizable' => $resizable, danielebarchiesi@0: ); danielebarchiesi@0: danielebarchiesi@0: // Fetch the profile associated to this text format. danielebarchiesi@0: $profile = wysiwyg_get_profile($format_id); danielebarchiesi@0: if ($profile) { danielebarchiesi@0: $loaded = TRUE; danielebarchiesi@0: $settings[$format]['editor'] = $profile->editor; danielebarchiesi@0: $settings[$format]['status'] = (int) wysiwyg_user_get_status($profile); danielebarchiesi@0: if (isset($profile->settings['show_toggle'])) { danielebarchiesi@0: $settings[$format]['toggle'] = (int) $profile->settings['show_toggle']; danielebarchiesi@0: } danielebarchiesi@0: // Check editor theme (and reset it if not/no longer available). danielebarchiesi@0: $theme = wysiwyg_get_editor_themes($profile, (isset($profile->settings['theme']) ? $profile->settings['theme'] : '')); danielebarchiesi@0: danielebarchiesi@0: // Add plugin settings (first) for this text format. danielebarchiesi@0: wysiwyg_add_plugin_settings($profile); danielebarchiesi@0: // Add profile settings for this text format. danielebarchiesi@0: wysiwyg_add_editor_settings($profile, $theme); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: // Use a hidden element for a single text format. danielebarchiesi@0: if (!$format_field['format']['#access']) { danielebarchiesi@0: $format_field['wysiwyg'] = array( danielebarchiesi@0: '#type' => 'hidden', danielebarchiesi@0: '#name' => $format_field['format']['#name'], danielebarchiesi@0: '#value' => $format_id, danielebarchiesi@0: '#attributes' => array( danielebarchiesi@0: 'id' => $format_field['format']['#id'], danielebarchiesi@0: 'class' => array('wysiwyg'), danielebarchiesi@0: ), danielebarchiesi@0: ); danielebarchiesi@0: $format_field['wysiwyg']['#attached']['js'][] = array( danielebarchiesi@0: 'data' => array( danielebarchiesi@0: 'wysiwyg' => array( danielebarchiesi@0: 'triggers' => array( danielebarchiesi@0: $format_field['format']['#id'] => $settings, danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: 'type' => 'setting', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: // Otherwise, attach to text format selector. danielebarchiesi@0: else { danielebarchiesi@0: $format_field['format']['#attributes']['class'][] = 'wysiwyg'; danielebarchiesi@0: $format_field['format']['#attached']['js'][] = array( danielebarchiesi@0: 'data' => array( danielebarchiesi@0: 'wysiwyg' => array( danielebarchiesi@0: 'triggers' => array( danielebarchiesi@0: $format_field['format']['#id'] => $settings, danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: ), danielebarchiesi@0: 'type' => 'setting', danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // If we loaded at least one editor, then the 'none' editor will danielebarchiesi@0: // handle resizable textareas instead of core. danielebarchiesi@0: if (isset($loaded) && $resizable) { danielebarchiesi@0: $field['#resizable'] = FALSE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $element; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Determine the profile to use for a given input format id. danielebarchiesi@0: * danielebarchiesi@0: * This function also performs sanity checks for the configured editor in a danielebarchiesi@0: * profile to ensure that we do not load a malformed editor. danielebarchiesi@0: * danielebarchiesi@0: * @param $format danielebarchiesi@0: * The internal id of an input format. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * A wysiwyg profile. danielebarchiesi@0: * danielebarchiesi@0: * @see wysiwyg_load_editor(), wysiwyg_get_editor() danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_profile($format) { danielebarchiesi@0: if ($profile = wysiwyg_profile_load($format)) { danielebarchiesi@0: if (wysiwyg_load_editor($profile)) { danielebarchiesi@0: return $profile; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: return FALSE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Load an editor library and initialize basic Wysiwyg settings. danielebarchiesi@0: * danielebarchiesi@0: * @param $profile danielebarchiesi@0: * A wysiwyg editor profile. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * TRUE if the editor has been loaded, FALSE if not. danielebarchiesi@0: * danielebarchiesi@0: * @see wysiwyg_get_profile() danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_load_editor($profile) { danielebarchiesi@0: static $settings_added; danielebarchiesi@0: static $loaded = array(); danielebarchiesi@0: $path = drupal_get_path('module', 'wysiwyg'); danielebarchiesi@0: danielebarchiesi@0: $name = $profile->editor; danielebarchiesi@0: // Library files must be loaded only once. danielebarchiesi@0: if (!isset($loaded[$name])) { danielebarchiesi@0: // Load editor. danielebarchiesi@0: $editor = wysiwyg_get_editor($name); danielebarchiesi@0: if ($editor) { danielebarchiesi@0: $default_library_options = array( danielebarchiesi@0: 'type' => 'file', danielebarchiesi@0: 'scope' => 'header', danielebarchiesi@0: 'defer' => FALSE, danielebarchiesi@0: 'cache' => TRUE, danielebarchiesi@0: 'preprocess' => TRUE, danielebarchiesi@0: ); danielebarchiesi@0: // Determine library files to load. danielebarchiesi@0: // @todo Allow to configure the library/execMode to use. danielebarchiesi@0: if (isset($profile->settings['library']) && isset($editor['libraries'][$profile->settings['library']])) { danielebarchiesi@0: $library = $profile->settings['library']; danielebarchiesi@0: $files = $editor['libraries'][$library]['files']; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: // Fallback to the first defined library by default (external libraries can change). danielebarchiesi@0: $library = key($editor['libraries']); danielebarchiesi@0: $files = array_shift($editor['libraries']); danielebarchiesi@0: $files = $files['files']; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Check whether the editor requires an initialization script. danielebarchiesi@0: if (!empty($editor['init callback'])) { danielebarchiesi@0: $init = $editor['init callback']($editor, $library, $profile); danielebarchiesi@0: if (!empty($init)) { danielebarchiesi@0: // Build a file for each of the editors to hold the init scripts. danielebarchiesi@0: // @todo Aggregate all initialization scripts into one file. danielebarchiesi@0: $uri = 'public://js/wysiwyg/wysiwyg_' . $name . '_' . drupal_hash_base64($init) . '.js'; danielebarchiesi@0: $init_exists = file_exists($uri); danielebarchiesi@0: if (!$init_exists) { danielebarchiesi@0: $js_path = dirname($uri); danielebarchiesi@0: file_prepare_directory($js_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS); danielebarchiesi@0: } danielebarchiesi@0: // Attempt to create the file, or fall back to an inline script (which danielebarchiesi@0: // will not work in Ajax calls). danielebarchiesi@0: if (!$init_exists && !file_unmanaged_save_data($init, $uri, FILE_EXISTS_REPLACE)) { danielebarchiesi@0: drupal_add_js($init, array('type' => 'inline') + $default_library_options); danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: drupal_add_js(file_create_url($uri), $default_library_options); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: foreach ($files as $file => $options) { danielebarchiesi@0: if (is_array($options)) { danielebarchiesi@0: $options += $default_library_options; danielebarchiesi@0: drupal_add_js($editor['library path'] . '/' . $file, $options); danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: drupal_add_js($editor['library path'] . '/' . $options); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: // If editor defines an additional load callback, invoke it. danielebarchiesi@0: // @todo Isn't the settings callback sufficient? danielebarchiesi@0: if (isset($editor['load callback']) && function_exists($editor['load callback'])) { danielebarchiesi@0: $editor['load callback']($editor, $library); danielebarchiesi@0: } danielebarchiesi@0: // Load JavaScript integration files for this editor. danielebarchiesi@0: $files = array(); danielebarchiesi@0: if (isset($editor['js files'])) { danielebarchiesi@0: $files = $editor['js files']; danielebarchiesi@0: } danielebarchiesi@0: foreach ($files as $file) { danielebarchiesi@0: drupal_add_js($editor['js path'] . '/' . $file); danielebarchiesi@0: } danielebarchiesi@0: // Load CSS stylesheets for this editor. danielebarchiesi@0: $files = array(); danielebarchiesi@0: if (isset($editor['css files'])) { danielebarchiesi@0: $files = $editor['css files']; danielebarchiesi@0: } danielebarchiesi@0: foreach ($files as $file) { danielebarchiesi@0: drupal_add_css($editor['css path'] . '/' . $file); danielebarchiesi@0: } danielebarchiesi@0: $loaded[$name] = TRUE; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $loaded[$name] = FALSE; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Add basic Wysiwyg settings if any editor has been added. danielebarchiesi@0: if (!isset($settings_added) && $loaded[$name]) { danielebarchiesi@0: drupal_add_js(array('wysiwyg' => array( danielebarchiesi@0: 'configs' => array(), danielebarchiesi@0: 'plugins' => array(), danielebarchiesi@0: 'disable' => t('Disable rich-text'), danielebarchiesi@0: 'enable' => t('Enable rich-text'), danielebarchiesi@0: )), 'setting'); danielebarchiesi@0: danielebarchiesi@0: // Initialize our namespaces in the *header* to do not force editor danielebarchiesi@0: // integration scripts to check and define Drupal.wysiwyg on its own. danielebarchiesi@0: drupal_add_js($path . '/wysiwyg.init.js', array('group' => JS_LIBRARY)); danielebarchiesi@0: danielebarchiesi@0: // The 'none' editor is a special editor implementation, allowing us to danielebarchiesi@0: // attach and detach regular Drupal behaviors just like any other editor. danielebarchiesi@0: drupal_add_js($path . '/editors/js/none.js'); danielebarchiesi@0: danielebarchiesi@0: // Add wysiwyg.js to the footer to ensure it's executed after the danielebarchiesi@0: // Drupal.settings array has been rendered and populated. Also, since editor danielebarchiesi@0: // library initialization functions must be loaded first by the browser, danielebarchiesi@0: // and Drupal.wysiwygInit() must be executed AFTER editors registered danielebarchiesi@0: // their callbacks and BEFORE Drupal.behaviors are applied, this must come danielebarchiesi@0: // last. danielebarchiesi@0: drupal_add_js($path . '/wysiwyg.js', array('scope' => 'footer')); danielebarchiesi@0: danielebarchiesi@0: $settings_added = TRUE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $loaded[$name]; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Add editor settings for a given input format. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_add_editor_settings($profile, $theme) { danielebarchiesi@0: static $formats = array(); danielebarchiesi@0: danielebarchiesi@0: if (!isset($formats[$profile->format])) { danielebarchiesi@0: $config = wysiwyg_get_editor_config($profile, $theme); danielebarchiesi@0: // drupal_to_js() does not properly convert numeric array keys, so we need danielebarchiesi@0: // to use a string instead of the format id. danielebarchiesi@0: if ($config) { danielebarchiesi@0: drupal_add_js(array('wysiwyg' => array('configs' => array($profile->editor => array('format' . $profile->format => $config)))), 'setting'); danielebarchiesi@0: } danielebarchiesi@0: $formats[$profile->format] = TRUE; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Add settings for external plugins. danielebarchiesi@0: * danielebarchiesi@0: * Plugins can be used in multiple profiles, but not necessarily in all. Because danielebarchiesi@0: * of that, we need to process plugins for each profile, even if most of their danielebarchiesi@0: * settings are not stored per profile. danielebarchiesi@0: * danielebarchiesi@0: * Implementations of hook_wysiwyg_plugin() may execute different code for each danielebarchiesi@0: * editor. Therefore, we have to invoke those implementations for each editor, danielebarchiesi@0: * but process the resulting plugins separately for each profile. danielebarchiesi@0: * danielebarchiesi@0: * Drupal plugins differ to native plugins in that they have plugin-specific danielebarchiesi@0: * definitions and settings, which need to be processed only once. But they are danielebarchiesi@0: * also passed to the editor to prepare settings specific to the editor. danielebarchiesi@0: * Therefore, we load and process the Drupal plugins only once, and hand off the danielebarchiesi@0: * effective definitions for each profile to the editor. danielebarchiesi@0: * danielebarchiesi@0: * @param $profile danielebarchiesi@0: * A wysiwyg editor profile. danielebarchiesi@0: * danielebarchiesi@0: * @todo Rewrite wysiwyg_process_form() to build a registry of effective danielebarchiesi@0: * profiles in use, so we can process plugins in multiple profiles in one shot danielebarchiesi@0: * and simplify this entire function. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_add_plugin_settings($profile) { danielebarchiesi@0: static $plugins = array(); danielebarchiesi@0: static $processed_plugins = array(); danielebarchiesi@0: static $processed_formats = array(); danielebarchiesi@0: danielebarchiesi@0: // Each input format must only processed once. danielebarchiesi@0: // @todo ...as long as we do not have multiple profiles per format. danielebarchiesi@0: if (isset($processed_formats[$profile->format])) { danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: $processed_formats[$profile->format] = TRUE; danielebarchiesi@0: danielebarchiesi@0: $editor = wysiwyg_get_editor($profile->editor); danielebarchiesi@0: danielebarchiesi@0: // Collect native plugins for this editor provided via hook_wysiwyg_plugin() danielebarchiesi@0: // and Drupal plugins provided via hook_wysiwyg_include_directory(). danielebarchiesi@0: if (!array_key_exists($editor['name'], $plugins)) { danielebarchiesi@0: $plugins[$editor['name']] = wysiwyg_get_plugins($editor['name']); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Nothing to do, if there are no plugins. danielebarchiesi@0: if (empty($plugins[$editor['name']])) { danielebarchiesi@0: return; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Determine name of proxy plugin for Drupal plugins. danielebarchiesi@0: $proxy = (isset($editor['proxy plugin']) ? key($editor['proxy plugin']) : ''); danielebarchiesi@0: danielebarchiesi@0: // Process native editor plugins. danielebarchiesi@0: if (isset($editor['plugin settings callback'])) { danielebarchiesi@0: // @todo Require PHP 5.1 in 3.x and use array_intersect_key(). danielebarchiesi@0: $profile_plugins_native = array(); danielebarchiesi@0: foreach ($plugins[$editor['name']] as $plugin => $meta) { danielebarchiesi@0: // Skip Drupal plugins (handled below). danielebarchiesi@0: if ($plugin === $proxy) { danielebarchiesi@0: continue; danielebarchiesi@0: } danielebarchiesi@0: // Only keep native plugins that are enabled in this profile. danielebarchiesi@0: if (isset($profile->settings['buttons'][$plugin])) { danielebarchiesi@0: $profile_plugins_native[$plugin] = $meta; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: // Invoke the editor's plugin settings callback, so it can populate the danielebarchiesi@0: // settings for native external plugins with required values. danielebarchiesi@0: $settings_native = call_user_func($editor['plugin settings callback'], $editor, $profile, $profile_plugins_native); danielebarchiesi@0: danielebarchiesi@0: if ($settings_native) { danielebarchiesi@0: drupal_add_js(array('wysiwyg' => array('plugins' => array('format' . $profile->format => array('native' => $settings_native)))), 'setting'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Process Drupal plugins. danielebarchiesi@0: if ($proxy && isset($editor['proxy plugin settings callback'])) { danielebarchiesi@0: $profile_plugins_drupal = array(); danielebarchiesi@0: foreach (wysiwyg_get_all_plugins() as $plugin => $meta) { danielebarchiesi@0: if (isset($profile->settings['buttons'][$proxy][$plugin])) { danielebarchiesi@0: // JavaScript and plugin-specific settings for Drupal plugins must be danielebarchiesi@0: // loaded and processed only once. Plugin information is cached danielebarchiesi@0: // statically to pass it to the editor's proxy plugin settings callback. danielebarchiesi@0: if (!isset($processed_plugins[$proxy][$plugin])) { danielebarchiesi@0: $profile_plugins_drupal[$plugin] = $processed_plugins[$proxy][$plugin] = $meta; danielebarchiesi@0: // Load the Drupal plugin's JavaScript. danielebarchiesi@0: drupal_add_js($meta['js path'] . '/' . $meta['js file']); danielebarchiesi@0: // Add plugin-specific settings. danielebarchiesi@0: if (isset($meta['settings'])) { danielebarchiesi@0: drupal_add_js(array('wysiwyg' => array('plugins' => array('drupal' => array($plugin => $meta['settings'])))), 'setting'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $profile_plugins_drupal[$plugin] = $processed_plugins[$proxy][$plugin]; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: // Invoke the editor's proxy plugin settings callback, so it can populate danielebarchiesi@0: // the settings for Drupal plugins with custom, required values. danielebarchiesi@0: $settings_drupal = call_user_func($editor['proxy plugin settings callback'], $editor, $profile, $profile_plugins_drupal); danielebarchiesi@0: danielebarchiesi@0: if ($settings_drupal) { danielebarchiesi@0: drupal_add_js(array('wysiwyg' => array('plugins' => array('format' . $profile->format => array('drupal' => $settings_drupal)))), 'setting'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Retrieve available themes for an editor. danielebarchiesi@0: * danielebarchiesi@0: * Editor themes control the visual presentation of an editor. danielebarchiesi@0: * danielebarchiesi@0: * @param $profile danielebarchiesi@0: * A wysiwyg editor profile; passed/altered by reference. danielebarchiesi@0: * @param $selected_theme danielebarchiesi@0: * An optional theme name that ought to be used. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array of theme names, or a single, checked theme name if $selected_theme danielebarchiesi@0: * was given. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_editor_themes(&$profile, $selected_theme = NULL) { danielebarchiesi@0: static $themes = array(); danielebarchiesi@0: danielebarchiesi@0: if (!isset($themes[$profile->editor])) { danielebarchiesi@0: $editor = wysiwyg_get_editor($profile->editor); danielebarchiesi@0: if (isset($editor['themes callback']) && function_exists($editor['themes callback'])) { danielebarchiesi@0: $themes[$editor['name']] = $editor['themes callback']($editor, $profile); danielebarchiesi@0: } danielebarchiesi@0: // Fallback to 'default' otherwise. danielebarchiesi@0: else { danielebarchiesi@0: $themes[$editor['name']] = array('default'); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Check optional $selected_theme argument, if given. danielebarchiesi@0: if (isset($selected_theme)) { danielebarchiesi@0: // If the passed theme name does not exist, use the first available. danielebarchiesi@0: if (!in_array($selected_theme, $themes[$profile->editor])) { danielebarchiesi@0: $selected_theme = $profile->settings['theme'] = $themes[$profile->editor][0]; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return isset($selected_theme) ? $selected_theme : $themes[$profile->editor]; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return plugin metadata from the plugin registry. danielebarchiesi@0: * danielebarchiesi@0: * @param $editor_name danielebarchiesi@0: * The internal name of an editor to return plugins for. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array for each plugin. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_plugins($editor_name) { danielebarchiesi@0: $plugins = array(); danielebarchiesi@0: if (!empty($editor_name)) { danielebarchiesi@0: $editor = wysiwyg_get_editor($editor_name); danielebarchiesi@0: // Add internal editor plugins. danielebarchiesi@0: if (isset($editor['plugin callback']) && function_exists($editor['plugin callback'])) { danielebarchiesi@0: $plugins = $editor['plugin callback']($editor); danielebarchiesi@0: } danielebarchiesi@0: // Add editor plugins provided via hook_wysiwyg_plugin(). danielebarchiesi@0: $plugins = array_merge($plugins, module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version'])); danielebarchiesi@0: // Add API plugins provided by Drupal modules. danielebarchiesi@0: // @todo We need to pass the filepath to the plugin icon for Drupal plugins. danielebarchiesi@0: if (isset($editor['proxy plugin'])) { danielebarchiesi@0: $plugins += $editor['proxy plugin']; danielebarchiesi@0: $proxy = key($editor['proxy plugin']); danielebarchiesi@0: foreach (wysiwyg_get_all_plugins() as $plugin_name => $info) { danielebarchiesi@0: $plugins[$proxy]['buttons'][$plugin_name] = $info['title']; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: return $plugins; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return an array of initial editor settings for a Wysiwyg profile. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_editor_config($profile, $theme) { danielebarchiesi@0: $editor = wysiwyg_get_editor($profile->editor); danielebarchiesi@0: $settings = array(); danielebarchiesi@0: if (!empty($editor['settings callback']) && function_exists($editor['settings callback'])) { danielebarchiesi@0: $settings = $editor['settings callback']($editor, $profile->settings, $theme); danielebarchiesi@0: danielebarchiesi@0: // Allow other modules to alter the editor settings for this format. danielebarchiesi@0: $context = array('editor' => $editor, 'profile' => $profile, 'theme' => $theme); danielebarchiesi@0: drupal_alter('wysiwyg_editor_settings', $settings, $context); danielebarchiesi@0: } danielebarchiesi@0: return $settings; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Retrieve stylesheets for HTML/IFRAME-based editors. danielebarchiesi@0: * danielebarchiesi@0: * This assumes that the content editing area only needs stylesheets defined danielebarchiesi@0: * for the scope 'theme'. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * An array containing CSS files, including proper base path. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_css() { danielebarchiesi@0: static $files; danielebarchiesi@0: danielebarchiesi@0: if (isset($files)) { danielebarchiesi@0: return $files; danielebarchiesi@0: } danielebarchiesi@0: // In node form previews, the theme has not been initialized yet. danielebarchiesi@0: if (!empty($_POST)) { danielebarchiesi@0: drupal_theme_initialize(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $files = array(); danielebarchiesi@0: foreach (drupal_add_css() as $filepath => $info) { danielebarchiesi@0: if ($info['group'] >= CSS_THEME && $info['media'] != 'print') { danielebarchiesi@0: if ($info['type'] == 'external') { danielebarchiesi@0: $files[] = $filepath; danielebarchiesi@0: } danielebarchiesi@0: elseif (file_exists($filepath)) { danielebarchiesi@0: $files[] = base_path() . $filepath; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: return $files; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Loads a profile for a given text format. danielebarchiesi@0: * danielebarchiesi@0: * Since there are commonly not many text formats, and each text format-enabled danielebarchiesi@0: * form element will possibly have to load every single profile, all existing danielebarchiesi@0: * profiles are loaded and cached once to reduce the amount of database queries. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_profile_load($format) { danielebarchiesi@0: $profiles = wysiwyg_profile_load_all(); danielebarchiesi@0: return (isset($profiles[$format]) ? $profiles[$format] : FALSE); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Loads all profiles. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_profile_load_all() { danielebarchiesi@0: // entity_load(..., FALSE) does not re-use its own static cache upon danielebarchiesi@0: // repetitive calls, so a custom static cache is required. danielebarchiesi@0: // @see wysiwyg_entity_info() danielebarchiesi@0: $profiles = &drupal_static(__FUNCTION__); danielebarchiesi@0: danielebarchiesi@0: if (!isset($profiles)) { danielebarchiesi@0: // Additional database cache to support alternative caches like memcache. danielebarchiesi@0: if ($cached = cache_get('wysiwyg_profiles')) { danielebarchiesi@0: $profiles = $cached->data; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $profiles = entity_load('wysiwyg_profile', FALSE); danielebarchiesi@0: cache_set('wysiwyg_profiles', $profiles); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return $profiles; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Deletes a profile from the database. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_profile_delete($format) { danielebarchiesi@0: db_delete('wysiwyg') danielebarchiesi@0: ->condition('format', $format) danielebarchiesi@0: ->execute(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Clear all Wysiwyg profile caches. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_profile_cache_clear() { danielebarchiesi@0: entity_get_controller('wysiwyg_profile')->resetCache(); danielebarchiesi@0: drupal_static_reset('wysiwyg_profile_load_all'); danielebarchiesi@0: cache_clear_all('wysiwyg_profiles', 'cache'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implements hook_form_FORM_ID_alter(). danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_form_user_profile_form_alter(&$form, &$form_state, $form_id) { danielebarchiesi@0: $account = $form['#user']; danielebarchiesi@0: $user_formats = filter_formats($account); danielebarchiesi@0: $options = array(); danielebarchiesi@0: $options_default = array(); danielebarchiesi@0: foreach (wysiwyg_profile_load_all() as $format => $profile) { danielebarchiesi@0: // Only show profiles that have user_choose enabled. danielebarchiesi@0: if (!empty($profile->settings['user_choose']) && isset($user_formats[$format])) { danielebarchiesi@0: $options[$format] = check_plain($user_formats[$format]->name); danielebarchiesi@0: if (wysiwyg_user_get_status($profile, $account)) { danielebarchiesi@0: $options_default[] = $format; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: if (!empty($options)) { danielebarchiesi@0: $form['wysiwyg']['wysiwyg_status'] = array( danielebarchiesi@0: '#type' => 'checkboxes', danielebarchiesi@0: '#title' => t('Text formats enabled for rich-text editing'), danielebarchiesi@0: '#options' => $options, danielebarchiesi@0: '#default_value' => $options_default, danielebarchiesi@0: ); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implements hook_user_insert(). danielebarchiesi@0: * danielebarchiesi@0: * Wysiwyg's user preferences are normally not exposed on the user registration danielebarchiesi@0: * form, but in case they are manually altered in, we invoke danielebarchiesi@0: * wysiwyg_user_update() accordingly. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_user_insert(&$edit, $account, $category) { danielebarchiesi@0: wysiwyg_user_update($edit, $account, $category); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Implements hook_user_update(). danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_user_update(&$edit, $account, $category) { danielebarchiesi@0: if (isset($edit['wysiwyg_status'])) { danielebarchiesi@0: db_delete('wysiwyg_user') danielebarchiesi@0: ->condition('uid', $account->uid) danielebarchiesi@0: ->execute(); danielebarchiesi@0: $query = db_insert('wysiwyg_user') danielebarchiesi@0: ->fields(array('uid', 'format', 'status')); danielebarchiesi@0: foreach ($edit['wysiwyg_status'] as $format => $status) { danielebarchiesi@0: $query->values(array( danielebarchiesi@0: 'uid' => $account->uid, danielebarchiesi@0: 'format' => $format, danielebarchiesi@0: 'status' => (int) (bool) $status, danielebarchiesi@0: )); danielebarchiesi@0: } danielebarchiesi@0: $query->execute(); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: function wysiwyg_user_get_status($profile, $account = NULL) { danielebarchiesi@0: global $user; danielebarchiesi@0: danielebarchiesi@0: if (!isset($account)) { danielebarchiesi@0: $account = $user; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Default wysiwyg editor status information is only required on forms, so we danielebarchiesi@0: // do not pre-emptively load and attach this information on every user_load(). danielebarchiesi@0: if (!isset($account->wysiwyg_status)) { danielebarchiesi@0: $account->wysiwyg_status = db_query("SELECT format, status FROM {wysiwyg_user} WHERE uid = :uid", array( danielebarchiesi@0: ':uid' => $account->uid, danielebarchiesi@0: ))->fetchAllKeyed(); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: if (!empty($profile->settings['user_choose']) && isset($account->wysiwyg_status[$profile->format])) { danielebarchiesi@0: $status = $account->wysiwyg_status[$profile->format]; danielebarchiesi@0: } danielebarchiesi@0: else { danielebarchiesi@0: $status = isset($profile->settings['default']) ? $profile->settings['default'] : TRUE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: return (bool) $status; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * @defgroup wysiwyg_api Wysiwyg API danielebarchiesi@0: * @{ danielebarchiesi@0: * danielebarchiesi@0: * @todo Forked from Panels; abstract into a separate API module that allows danielebarchiesi@0: * contrib modules to define supported include/plugin types. danielebarchiesi@0: */ danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return library information for a given editor. danielebarchiesi@0: * danielebarchiesi@0: * @param $name danielebarchiesi@0: * The internal name of an editor. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * The library information for the editor, or FALSE if $name is unknown or not danielebarchiesi@0: * installed properly. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_editor($name) { danielebarchiesi@0: $editors = wysiwyg_get_all_editors(); danielebarchiesi@0: return isset($editors[$name]) && $editors[$name]['installed'] ? $editors[$name] : FALSE; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Compile a list holding all supported editors including installed editor version information. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_all_editors() { danielebarchiesi@0: static $editors; danielebarchiesi@0: danielebarchiesi@0: if (isset($editors)) { danielebarchiesi@0: return $editors; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $editors = wysiwyg_load_includes('editors', 'editor'); danielebarchiesi@0: foreach ($editors as $editor => $properties) { danielebarchiesi@0: // Fill in required properties. danielebarchiesi@0: $editors[$editor] += array( danielebarchiesi@0: 'title' => '', danielebarchiesi@0: 'vendor url' => '', danielebarchiesi@0: 'download url' => '', danielebarchiesi@0: 'editor path' => wysiwyg_get_path($editors[$editor]['name']), danielebarchiesi@0: 'library path' => wysiwyg_get_path($editors[$editor]['name']), danielebarchiesi@0: 'libraries' => array(), danielebarchiesi@0: 'version callback' => NULL, danielebarchiesi@0: 'themes callback' => NULL, danielebarchiesi@0: 'settings form callback' => NULL, danielebarchiesi@0: 'settings callback' => NULL, danielebarchiesi@0: 'plugin callback' => NULL, danielebarchiesi@0: 'plugin settings callback' => NULL, danielebarchiesi@0: 'versions' => array(), danielebarchiesi@0: 'js path' => $editors[$editor]['path'] . '/js', danielebarchiesi@0: 'css path' => $editors[$editor]['path'] . '/css', danielebarchiesi@0: ); danielebarchiesi@0: // Check whether library is present. danielebarchiesi@0: if (!($editors[$editor]['installed'] = file_exists($editors[$editor]['library path']))) { danielebarchiesi@0: continue; danielebarchiesi@0: } danielebarchiesi@0: // Detect library version. danielebarchiesi@0: if (function_exists($editors[$editor]['version callback'])) { danielebarchiesi@0: $editors[$editor]['installed version'] = $editors[$editor]['version callback']($editors[$editor]); danielebarchiesi@0: } danielebarchiesi@0: if (empty($editors[$editor]['installed version'])) { danielebarchiesi@0: $editors[$editor]['error'] = t('The version of %editor could not be detected.', array('%editor' => $properties['title'])); danielebarchiesi@0: $editors[$editor]['installed'] = FALSE; danielebarchiesi@0: continue; danielebarchiesi@0: } danielebarchiesi@0: // Determine to which supported version the installed version maps. danielebarchiesi@0: ksort($editors[$editor]['versions']); danielebarchiesi@0: $version = 0; danielebarchiesi@0: foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) { danielebarchiesi@0: if (version_compare($editors[$editor]['installed version'], $supported_version, '>=')) { danielebarchiesi@0: $version = $supported_version; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: if (!$version) { danielebarchiesi@0: $editors[$editor]['error'] = t('The installed version %version of %editor is not supported.', array('%version' => $editors[$editor]['installed version'], '%editor' => $editors[$editor]['title'])); danielebarchiesi@0: $editors[$editor]['installed'] = FALSE; danielebarchiesi@0: continue; danielebarchiesi@0: } danielebarchiesi@0: // Apply library version specific definitions and overrides. danielebarchiesi@0: $editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]); danielebarchiesi@0: unset($editors[$editor]['versions']); danielebarchiesi@0: } danielebarchiesi@0: return $editors; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Invoke hook_wysiwyg_plugin() in all modules. danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_all_plugins() { danielebarchiesi@0: static $plugins; danielebarchiesi@0: danielebarchiesi@0: if (isset($plugins)) { danielebarchiesi@0: return $plugins; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $plugins = wysiwyg_load_includes('plugins', 'plugin'); danielebarchiesi@0: foreach ($plugins as $name => $properties) { danielebarchiesi@0: $plugin = &$plugins[$name]; danielebarchiesi@0: // Fill in required/default properties. danielebarchiesi@0: $plugin += array( danielebarchiesi@0: 'title' => $plugin['name'], danielebarchiesi@0: 'vendor url' => '', danielebarchiesi@0: 'js path' => $plugin['path'] . '/' . $plugin['name'], danielebarchiesi@0: 'js file' => $plugin['name'] . '.js', danielebarchiesi@0: 'css path' => $plugin['path'] . '/' . $plugin['name'], danielebarchiesi@0: 'css file' => $plugin['name'] . '.css', danielebarchiesi@0: 'icon path' => $plugin['path'] . '/' . $plugin['name'] . '/images', danielebarchiesi@0: 'icon file' => $plugin['name'] . '.png', danielebarchiesi@0: 'dialog path' => $plugin['name'], danielebarchiesi@0: 'dialog settings' => array(), danielebarchiesi@0: 'settings callback' => NULL, danielebarchiesi@0: 'settings form callback' => NULL, danielebarchiesi@0: ); danielebarchiesi@0: // Fill in default settings. danielebarchiesi@0: $plugin['settings'] += array( danielebarchiesi@0: 'path' => base_path() . $plugin['path'] . '/' . $plugin['name'], danielebarchiesi@0: ); danielebarchiesi@0: // Check whether library is present. danielebarchiesi@0: if (!($plugin['installed'] = file_exists($plugin['js path'] . '/' . $plugin['js file']))) { danielebarchiesi@0: continue; danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: return $plugins; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Load include files for wysiwyg implemented by all modules. danielebarchiesi@0: * danielebarchiesi@0: * @param $type danielebarchiesi@0: * The type of includes to search for, can be 'editors'. danielebarchiesi@0: * @param $hook danielebarchiesi@0: * The hook name to invoke. danielebarchiesi@0: * @param $file danielebarchiesi@0: * An optional include file name without .inc extension to limit the search to. danielebarchiesi@0: * danielebarchiesi@0: * @see wysiwyg_get_directories(), _wysiwyg_process_include() danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_load_includes($type = 'editors', $hook = 'editor', $file = NULL) { danielebarchiesi@0: // Determine implementations. danielebarchiesi@0: $directories = wysiwyg_get_directories($type); danielebarchiesi@0: $directories['wysiwyg'] = drupal_get_path('module', 'wysiwyg') . '/' . $type; danielebarchiesi@0: $file_list = array(); danielebarchiesi@0: foreach ($directories as $module => $path) { danielebarchiesi@0: $file_list[$module] = drupal_system_listing("/{$file}.inc\$/", $path, 'name', 0); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: // Load implementations. danielebarchiesi@0: $info = array(); danielebarchiesi@0: foreach (array_filter($file_list) as $module => $files) { danielebarchiesi@0: foreach ($files as $file) { danielebarchiesi@0: include_once './' . $file->uri; danielebarchiesi@0: $result = _wysiwyg_process_include($module, $module . '_' . $file->name, dirname($file->uri), $hook); danielebarchiesi@0: if (is_array($result)) { danielebarchiesi@0: $info = array_merge($info, $result); danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: } danielebarchiesi@0: return $info; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Helper function to build paths to libraries. danielebarchiesi@0: * danielebarchiesi@0: * @param $library danielebarchiesi@0: * The external library name to return the path for. danielebarchiesi@0: * @param $base_path danielebarchiesi@0: * Whether to prefix the resulting path with base_path(). danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * The path to the specified library. danielebarchiesi@0: * danielebarchiesi@0: * @ingroup libraries danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_path($library, $base_path = FALSE) { danielebarchiesi@0: static $libraries; danielebarchiesi@0: danielebarchiesi@0: if (!isset($libraries)) { danielebarchiesi@0: $libraries = wysiwyg_get_libraries(); danielebarchiesi@0: } danielebarchiesi@0: if (!isset($libraries[$library])) { danielebarchiesi@0: // Most often, external libraries can be shared across multiple sites. danielebarchiesi@0: return 'sites/all/libraries/' . $library; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $path = ($base_path ? base_path() : ''); danielebarchiesi@0: $path .= $libraries[$library]; danielebarchiesi@0: danielebarchiesi@0: return $path; danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: /** danielebarchiesi@0: * Return an array of library directories. danielebarchiesi@0: * danielebarchiesi@0: * Returns an array of library directories from the all-sites directory danielebarchiesi@0: * (i.e. sites/all/libraries/), the profiles directory, and site-specific danielebarchiesi@0: * directory (i.e. sites/somesite/libraries/). The returned array will be keyed danielebarchiesi@0: * by the library name. Site-specific libraries are prioritized over libraries danielebarchiesi@0: * in the default directories. That is, if a library with the same name appears danielebarchiesi@0: * in both the site-wide directory and site-specific directory, only the danielebarchiesi@0: * site-specific version will be listed. danielebarchiesi@0: * danielebarchiesi@0: * @return danielebarchiesi@0: * A list of library directories. danielebarchiesi@0: * danielebarchiesi@0: * @ingroup libraries danielebarchiesi@0: */ danielebarchiesi@0: function wysiwyg_get_libraries() { danielebarchiesi@0: global $profile; danielebarchiesi@0: danielebarchiesi@0: // When this function is called during Drupal's initial installation process, danielebarchiesi@0: // the name of the profile that is about to be installed is stored in the danielebarchiesi@0: // global $profile variable. At all other times, the regular system variable danielebarchiesi@0: // contains the name of the current profile, and we can call variable_get() danielebarchiesi@0: // to determine the profile. danielebarchiesi@0: if (!isset($profile)) { danielebarchiesi@0: $profile = variable_get('install_profile', 'default'); danielebarchiesi@0: } danielebarchiesi@0: danielebarchiesi@0: $directory = 'libraries'; danielebarchiesi@0: $searchdir = array(); danielebarchiesi@0: $config = conf_path(); danielebarchiesi@0: danielebarchiesi@0: // The 'profiles' directory contains pristine collections of modules and danielebarchiesi@0: // themes as organized by a distribution. It is pristine in the same way danielebarchiesi@0: // that /modules is pristine for core; users should avoid changing anything danielebarchiesi@0: // there in favor of sites/all or sites/