Newer
Older
Daniel Kudwien
committed
* Integrate client-side editors with Drupal.
*
* Please note that this module is slowly moving to become wysiwyg.module. Most
* functions are still based on the obsolete wysiwyg_editor name, which was
* originally chosen, because it was not clear whether editors would just be
* one component of a larger API.
*/
/**
* Implementation of hook_menu().
*/
$items['admin/settings/wysiwyg/profile'] = array(
'title' => 'Wysiwyg Editor',
'page callback' => 'wysiwyg_editor_admin',
Daniel Kudwien
committed
'description' => 'Configure client-side editors profiles.',
'access arguments' => array('administer site configuration'),
'file' => 'wysiwyg_editor.admin.inc',
);
/**
* Implementation of hook_theme().
*/
function wysiwyg_editor_theme() {
return array(
'wysiwyg_editor_admin_button_table' => array('arguments' => array('form')),
);
}
/**
* Implementation of hook_help().
*/
function wysiwyg_editor_help($path, $arg) {
switch ($path) {
case 'admin/settings/wysiwyg/profile':
case 'admin/help#wysiwyg_editor':
$output = '<p>'. t('Profiles can be defined based on user roles. A Wysiwyg Editor profile can define which pages receive this Wysiwyg Editor capability, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor functions. Lastly, only users with the %permission <a href="!url">user permission</a> are able to use Wysiwyg Editor.', array('%permission' => 'access wysiwyg editor', '!url' => url('admin/user/permissions'))) .'</p>';
}
}
/**
* Implementation of hook_perm().
*/
function wysiwyg_editor_perm() {
Daniel Kudwien
committed
return array('access wysiwyg editor');
}
/**
* Implementation of hook_elements().
Daniel Kudwien
committed
*
Daniel Kudwien
committed
* Before Drupal 7, there is no way to easily identify form fields that are
* input format enabled. This is a workaround: We assign a form #after_build
* processing callback that is executed on all forms after they have been
* completely built, so that form elements already are in their effective order
* and position.
*
* @see wysiwyg_process_form()
*
Daniel Kudwien
committed
* @todo Remove #wysiwyg_style; the GUI for an editor should be solely handled
* via profiles, when profiles are attached to an input format. It makes no
* sense to display TinyMCE's simple GUI/theme for the user signature, when
* the input format allows users to use advanced HTML and hence, editor
Daniel Kudwien
committed
* plugins. Fix this here, in wysiwyg_editor_process_element(), and lastly
Daniel Kudwien
committed
* in wysiwyg_editor_get_config().
function wysiwyg_editor_elements() {
if (user_access('access wysiwyg editor')) {
Daniel Kudwien
committed
// @todo Derive editor theme from input format.
$type['textarea'] = array('#wysiwyg_style' => 'advanced');
$type['form'] = array('#after_build' => array('wysiwyg_process_form'));
/**
* Implementation of hook_form_alter().
*/
function wysiwyg_editor_form_alter(&$form, &$form_state) {
// Disable 'teaser' textarea.
if (isset($form['body_field'])) {
unset($form['body_field']['teaser_js']);
$form['body_field']['teaser_include'] = array();
}
Daniel Kudwien
committed
* Process a textarea for Wysiwyg Editor.
*
* This way, we can recurse into the form and search for certain, hard-coded
* elements that have been added by filter_form(). If an input format selector
* or input format guidelines element is found, we assume that the preceding
* element is the corresponding textarea and use it's #id for attaching
* client-side editors.
Daniel Kudwien
committed
*
Daniel Kudwien
committed
* @see wysiwyg_editor_elements(), filter_form()
Daniel Kudwien
committed
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
function wysiwyg_process_form(&$form) {
// Iterate over element children; resetting array keys to access last index.
if ($children = array_values(element_children($form))) {
foreach ($children as $index => $item) {
$element = &$form[$item];
// filter_form() always uses the key 'format'. We need a type-agnostic
// match to prevent false positives. Also, there must have been at least
// one element on this level.
if ($item === 'format' && $index > 0) {
// Make sure we either match a input format selector or input format
// guidelines (displayed if user has access to one input format only).
if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) {
// The element before this element is the target form field.
$field = &$form[$children[$index - 1]];
// Disable #resizable to avoid resizable behavior to hi-jack the UI,
// but load the behavior, so the 'none' editor can attach/detach it.
$extra_class = '';
if (!empty($field['#resizable'])) {
// Due to our CSS class parsing, we can add arbitrary parameters
// for each input format.
$extra_class = ' wysiwyg-resizable-1';
$field['#resizable'] = FALSE;
drupal_add_js('misc/textarea.js');
}
// Determine the available input formats. The last child element is a
// link to "More information about formatting options". When only one
// input format is displayed, we also have to remove formatting
// guidelines, stored in the child 'format'.
$formats = element_children($element);
array_pop($formats);
unset($formats['format']);
foreach ($formats as $format) {
// Default to 'none' editor (Drupal's default behaviors).
$editor = 'none';
$theme = '';
// Fetch the profile associated to this input format.
$profile = wysiwyg_get_profile($format);
if ($profile) {
$editor = $profile->settings['editor'];
// Check editor theme (and reset it if not/no longer available).
$theme = wysiwyg_editor_get_themes($profile, $field['#wysiwyg_style']);
// Add profile settings for this input format.
wysiwyg_editor_add_settings($profile, $theme);
// Add plugin settings for this input format.
wysiwyg_editor_add_plugin_settings($profile);
$theme = ' wysiwyg-theme-'. $theme;
}
// Use a prefix/suffix for a single input format, or attach to input
// format selector radio buttons.
if (isset($element['format']['guidelines'])) {
$element[$format]['#prefix'] = '<div class="wysiwyg wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] . $theme . $extra_class .'">';
$element[$format]['#suffix'] = '</div>';
}
else {
if (isset($element[$format]['#attributes']['class'])) {
$element[$format]['#attributes']['class'] .= ' ';
}
else {
$element[$format]['#attributes']['class'] = '';
}
$element[$format]['#attributes']['class'] .= 'wysiwyg wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] . $theme . $extra_class;
}
}
}
// If this element is 'format', do not recurse further.
continue;
}
// Recurse into children.
wysiwyg_process_form($element);
}
Daniel Kudwien
committed
return $form;
Daniel Kudwien
committed
* Determine the profile to use for a given input format id.
*
* This function also performs sanity checks for the configured editor in a
* profile to ensure that we do not load a malformed editor.
*
* @param $format
* The internal id of an input format.
*
* @return
* A wysiwyg profile.
*
* @see wysiwyg_editor_load_editor(), wysiwyg_get_editor()
*
* @todo Replace wysiwyg_editor_current_profile() with a input format to profile
* association.
Daniel Kudwien
committed
function wysiwyg_get_profile($format) {
// Determine whether this input format has PHP filter enabled.
// Temporary, until input format to profile associations are in place.
$filters = filter_list_format($format);
foreach ($filters as $filter) {
if ($filter->module == 'php') {
return FALSE;
Daniel Kudwien
committed
if ($profile = wysiwyg_editor_load_profile(wysiwyg_editor_current_profile())) {
if (wysiwyg_editor_load_editor($profile)) {
return $profile;
}
}
return FALSE;
Daniel Kudwien
committed
/**
* Load an editor library and initialize basic Wysiwyg settings.
*
* @param $profile
* A wysiwyg editor profile.
*
* @return
* TRUE if the editor has been loaded, FALSE if not.
*
Daniel Kudwien
committed
* @see wysiwyg_get_profile()
Daniel Kudwien
committed
*/
function wysiwyg_editor_load_editor($profile) {
static $settings_added;
static $loaded = array();
Daniel Kudwien
committed
$name = $profile->settings['editor'];
Daniel Kudwien
committed
// Library files must be loaded only once.
Daniel Kudwien
committed
if (!isset($loaded[$name])) {
Daniel Kudwien
committed
// Load editor.
Daniel Kudwien
committed
$editor = wysiwyg_get_editor($name);
if ($editor) {
// Determine library files to load.
Daniel Kudwien
committed
// @todo Allow to configure the library/execMode to use.
Daniel Kudwien
committed
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
if (isset($profile->settings['library']) && isset($editor['libraries'][$profile->settings['library']])) {
$library = $profile->settings['library'];
$files = $editor['libraries'][$profile->settings['library']]['files'];
}
else {
// Fallback to the first by default (external libraries can change).
$library = key($editor['libraries']);
$files = array_shift($editor['libraries']);
$files = $files['files'];
}
foreach ($files as $file) {
drupal_add_js($editor['library path'] . '/' . $file);
}
// Load JavaScript integration files for this editor.
if (isset($editor['js files'])) {
$files = $editor['js files'];
}
foreach ($files as $file) {
drupal_add_js($editor['js path'] . '/' . $file, 'module', 'footer');
}
$status = wysiwyg_editor_user_get_status($profile);
drupal_add_js(array('wysiwygEditor' => array(
'configs' => array($editor['name'] => array()),
'showToggle' => $profile->settings['show_toggle'],
'status' => $status,
// If JS compression is enabled, at least TinyMCE is unable to determine
// its own base path and exec mode since it can't find the script name.
'editorBasePath' => base_path() . $editor['library path'],
'execMode' => $library,
)), 'setting');
$loaded[$name] = TRUE;
}
else {
$loaded[$name] = FALSE;
}
}
Daniel Kudwien
committed
// Add basic Wysiwyg settings if any editor has been added.
Daniel Kudwien
committed
if (!isset($settings_added) && $loaded[$name]) {
Daniel Kudwien
committed
drupal_add_js(array('wysiwygEditor' => array(
'configs' => array(),
'disable' => t('Disable rich-text'),
'enable' => t('Enable rich-text'),
)), 'setting');
Daniel Kudwien
committed
Daniel Kudwien
committed
// Initialize our namespaces in the *header* to do not force editor
// integration scripts to check and define Drupal.wysiwyg on its own.
drupal_add_js(wysiwyg_get_path('wysiwyg.init.js'));
Daniel Kudwien
committed
// The 'none' editor is a special editor implementation, allowing us to
// attach and detach regular Drupal behaviors just like any other editor.
drupal_add_js(wysiwyg_get_path('editors/js/none.js'), 'module', 'footer');
Daniel Kudwien
committed
// Add wysiwyg_editor.js to the footer to ensure it's executed after the
Daniel Kudwien
committed
// Drupal.settings array has been rendered and populated. Also, since editor
// library initialization functions must be loaded first by the browser,
// Drupal.wysiwygEditorInit() must be executed AFTER editors registered
// their callbacks, and BEFORE Drupal.behaviors are applied, this must come
// last.
Daniel Kudwien
committed
drupal_add_js(wysiwyg_get_path('wysiwyg_editor.js'), 'module', 'footer');
Daniel Kudwien
committed
Daniel Kudwien
committed
// Add our stylesheet to stack editor buttons into one row.
Daniel Kudwien
committed
// @todo This is TinyMCE 2.x specific at the moment.
Daniel Kudwien
committed
drupal_add_css(wysiwyg_get_path('wysiwyg_editor.css'));
$settings_added = TRUE;
}
return $loaded[$name];
}
/**
* Register a theme.
*/
Daniel Kudwien
committed
function wysiwyg_editor_add_settings($profile, $theme) {
Daniel Kudwien
committed
if (!isset($themes[$theme])) {
$config = wysiwyg_editor_get_config($profile, $theme);
// Convert the config values into the form expected by Wysiwyg Editor.
Daniel Kudwien
committed
// @todo Is this conversion TinyMCE specific?
foreach ($config as $key => $value) {
if (is_bool($value)) {
continue;
}
if (is_array($value)) {
$config[$key] = implode(',', $config[$key]);
}
}
Daniel Kudwien
committed
drupal_add_js(array('wysiwygEditor' => array('configs' => array($profile->settings['editor'] => array($theme => $config)))), 'setting');
$themes[$theme] = TRUE;
Daniel Kudwien
committed
* Add settings for external plugins.
Daniel Kudwien
committed
* @param $profile
* A wysiwyg editor profile.
Daniel Kudwien
committed
function wysiwyg_editor_add_plugin_settings($profile) {
static $plugins_added = array();
Daniel Kudwien
committed
if (!isset($plugins_added[$profile->settings['editor']])) {
Daniel Kudwien
committed
$editor = wysiwyg_get_editor($profile->settings['editor']);
Daniel Kudwien
committed
// Collect editor plugins provided via hook_wysiwyg_plugin().
Daniel Kudwien
committed
$info = module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']);
// Only keep enabled plugins in this profile.
foreach ($info as $plugin => $meta) {
if (!isset($profile->settings['buttons'][$plugin])) {
unset($info[$plugin]);
}
}
Daniel Kudwien
committed
if (isset($editor['plugin settings callback']) && function_exists($editor['plugin settings callback'])) {
$plugins = $editor['plugin settings callback']($editor, $profile, $info);
Daniel Kudwien
committed
drupal_add_js(array('wysiwygEditor' => array('plugins' => array($profile->settings['editor'] => $plugins))), 'setting');
Daniel Kudwien
committed
$plugins_added[$profile->settings['editor']] = TRUE;
* Grab the themes available to Wysiwyg Editor.
* Wysiwyg Editor themes control the functionality and buttons that are available to a
* user. Themes are only looked for within the default Wysiwyg Editor theme directory.
Daniel Kudwien
committed
* @param $profile
* A wysiwyg editor profile; passed/altered by reference.
* @param $selected_theme
* An optional theme name that ought to be used.
*
Daniel Kudwien
committed
* An array of theme names, or a single, checked theme name if $selected_theme
* was given.
Daniel Kudwien
committed
function wysiwyg_editor_get_themes(&$profile, $selected_theme = NULL) {
static $themes = array();
Daniel Kudwien
committed
if (!isset($themes[$profile->settings['editor']])) {
$editor = wysiwyg_get_editor($profile->settings['editor']);
if (isset($editor['themes callback']) && function_exists($editor['themes callback'])) {
$themes[$editor['name']] = $editor['themes callback']($editor, $profile);
}
// Fallback to 'default' otherwise.
else {
$themes[$editor['name']] = array('default');
}
}
// Check optional $selected_theme argument, if given.
if (isset($selected_theme)) {
// If the passed theme name does not exist, use the first available.
if (!isset($themes[$profile->settings['editor']][$selected_theme])) {
$selected_theme = $profile->settings['theme'] = $themes[$profile->settings['editor']][0];
Daniel Kudwien
committed
return isset($selected_theme) ? $selected_theme : $themes[$profile->settings['editor']];
}
/**
* Return plugin metadata from the plugin registry.
*
Daniel Kudwien
committed
* @param $editor_name
* The internal name of an editor to return plugins for.
*
* @return
* An array for each plugin.
*/
Daniel Kudwien
committed
function wysiwyg_editor_get_plugins($editor_name) {
$plugins = array();
if (!empty($editor_name)) {
$editor = wysiwyg_get_editor($editor_name);
Daniel Kudwien
committed
// Add internal editor plugins.
Daniel Kudwien
committed
if (isset($editor['plugin callback']) && function_exists($editor['plugin callback'])) {
$plugins = $editor['plugin callback']($editor);
Daniel Kudwien
committed
// Load our own plugins.
include_once drupal_get_path('module', 'wysiwyg_editor') .'/wysiwyg_editor.plugins.inc';
Daniel Kudwien
committed
// Add editor plugins provided via hook_wysiwyg_plugin().
Daniel Kudwien
committed
$plugins = array_merge($plugins, module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']));
Daniel Kudwien
committed
return $plugins;
* Return an array of initial Wysiwyg Editor config options from the current role.
Daniel Kudwien
committed
function wysiwyg_editor_get_config($profile, $theme) {
$editor = wysiwyg_get_editor($profile->settings['editor']);
$settings = array();
if (!empty($editor['settings callback']) && function_exists($editor['settings callback'])) {
$settings = $editor['settings callback']($editor, $profile->settings, $theme);
Daniel Kudwien
committed
return $settings;
}
/**
* Return the name of the current user's default profile.
*/
function wysiwyg_editor_current_profile() {
Daniel Kudwien
committed
global $user;
Daniel Kudwien
committed
if (!isset($profile_name)) {
Daniel Kudwien
committed
$profile_name = db_result(db_query_range('SELECT p.name FROM {wysiwyg_editor_profile} p INNER JOIN {wysiwyg_editor_role} r ON r.name = p.name WHERE r.rid IN (%s) ORDER BY plugin_count DESC', implode(',', array_keys($user->roles)), 0, 1));
}
return $profile_name;
}
/**
* Load all profiles. Just load one profile if $name is passed in.
*/
Daniel Kudwien
committed
function wysiwyg_editor_load_profile($name = '') {
// If $name is passed from wysiwyg_editor_current_profile(), it may be FALSE,
Daniel Kudwien
committed
// which means the user is not allowed to use a wysiwyg editor.
if ($name === FALSE) {
return FALSE;
}
if (!isset($profiles)) {
$profiles = array();
$result = db_query('SELECT * FROM {wysiwyg_editor_profile}');
while ($profile = db_fetch_object($result)) {
$profile->settings = unserialize($profile->settings);
$result2 = db_query("SELECT rid FROM {wysiwyg_editor_role} WHERE name = '%s'", $profile->name);
$profile_roles = array();
while ($role = db_fetch_object($result2)) {
$profile_roles[$role->rid] = $roles[$role->rid];
return ($name && isset($profiles[$name]) ? $profiles[$name] : ($name ? FALSE : $profiles));
Daniel Kudwien
committed
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
/**
* Implementation of hook_user().
*/
function wysiwyg_editor_user($type, &$edit, &$user, $category = NULL) {
if ($type == 'form' && $category == 'account' && user_access('access wysiwyg editor')) {
$profile = wysiwyg_editor_user_get_profile($user);
if (isset($profile->settings['user_choose']) && $profile->settings['user_choose']) {
$form['wysiwyg'] = array(
'#type' => 'fieldset',
'#title' => t('Wysiwyg Editor settings'),
'#weight' => 10,
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['wysiwyg']['wysiwyg_editor_status'] = array(
'#type' => 'checkbox',
'#title' => t('Enable editor by default'),
'#default_value' => isset($user->wysiwyg_editor_status) ? $user->wysiwyg_editor_status : (isset($profile->settings['default']) ? $profile->settings['default'] : FALSE),
'#return_value' => 1,
'#description' => t('If enabled, rich-text editing is enabled by default in textarea fields.'),
);
return array('wysiwyg_editor' => $form);
}
}
if ($type == 'validate') {
return array('wysiwyg_editor_status' => $edit['wysiwyg_editor_status']);
}
}
function wysiwyg_editor_user_get_profile($account) {
$profile_name = db_result(db_query('SELECT s.name FROM {wysiwyg_editor_profile} s INNER JOIN {wysiwyg_editor_role} r ON r.name = s.name WHERE r.rid IN (%s)', implode(',', array_keys($account->roles))));
if ($profile_name) {
Daniel Kudwien
committed
return wysiwyg_editor_load_profile($profile_name);
}
else {
return FALSE;
}
}
Daniel Kudwien
committed
function wysiwyg_editor_user_get_status($profile) {
global $user;
$settings = $profile->settings;
if ($settings['user_choose'] && isset($user->wysiwyg_editor_status)) {
$status = $user->wysiwyg_editor_status;
$status = isset($settings['default']) ? $settings['default'] : FALSE;
Daniel Kudwien
committed
/**
Daniel Kudwien
committed
* @defgroup wysiwyg_api Wysiwyg API
Daniel Kudwien
committed
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
* @{
*
* @todo Forked from Panels; abstract into a separate API module that allows
* contrib modules to define supported include/plugin types.
*/
/**
* Return library information for a given editor.
*
* @param $name
* The internal name of an editor.
*
* @return
* The library information for the editor, or FALSE if $name is unknown or not
* installed properly.
*/
function wysiwyg_get_editor($name) {
$editors = wysiwyg_get_all_editors();
return isset($editors[$name]) && $editors[$name]['installed'] ? $editors[$name] : FALSE;
}
/**
* Compile a list holding all supported editors including installed editor version information.
*/
function wysiwyg_get_all_editors() {
static $editors;
if (isset($editors)) {
return $editors;
}
$editors = wysiwyg_load_includes('editors', 'editor');
foreach ($editors as $editor => $properties) {
// Fill in required properties.
$editors[$editor] += array(
'title' => '',
'vendor url' => '',
'download url' => '',
Daniel Kudwien
committed
'editor path' => wysiwyg_get_path($properties['name']),
'library path' => wysiwyg_get_path($properties['name']),
Daniel Kudwien
committed
'libraries' => array(),
Daniel Kudwien
committed
'version callback' => NULL,
'themes callback' => NULL,
'settings callback' => NULL,
'plugin callback' => NULL,
'plugin settings callback' => NULL,
Daniel Kudwien
committed
'versions' => array(),
Daniel Kudwien
committed
'js path' => $properties['path'] .'/js',
'css path' => $properties['path'] .'/css',
Daniel Kudwien
committed
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
);
// Check whether library is present.
if (!($editors[$editor]['installed'] = file_exists($properties['library path']))) {
continue;
}
// Detect library version.
if (function_exists($editors[$editor]['version callback'])) {
$editors[$editor]['installed version'] = $editors[$editor]['version callback']($properties);
}
if (empty($editors[$editor]['installed version'])) {
$editors[$editor]['error'] = t('The version of %editor could not be detected.', array('%editor' => $properties['title']));
$editors[$editor]['installed'] = FALSE;
continue;
}
// Determine to which supported version the installed version maps.
ksort($editors[$editor]['versions']);
$version = 0;
foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) {
if (version_compare($editors[$editor]['installed version'], $supported_version, '>=')) {
$version = $supported_version;
}
}
if (!$version) {
$editors[$editor]['error'] = t('The installed version of %editor is not supported.', array('%editor' => $properties['title']));
$editors[$editor]['installed'] = FALSE;
continue;
}
// Apply library version specific definitions and overrides.
$editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]);
unset($editors[$editor]['versions']);
$editors[$editor]['title'] = $editors[$editor]['title'] . ' ' . $editors[$editor]['installed version'];
}
return $editors;
}
/**
* Load include files for wysiwyg implemented by all modules.
*
* @param $type
* The type of includes to search for, can be 'editors'.
* @param $hook
* The hook name to invoke.
* @param $file
* An optional include file name without .inc extension to limit the search to.
*
* @see wysiwyg_get_directories(), _wysiwyg_process_include()
*/
function wysiwyg_load_includes($type = 'editors', $hook = 'editor', $file = NULL) {
// Determine implementations.
$directories = wysiwyg_get_directories($type);
$directories['wysiwyg_'] = wysiwyg_get_path($type);
$file_list = array();
foreach ($directories as $module => $path) {
$file_list[$module] = drupal_system_listing("$file" . '.inc$', $path, 'name', 0);
}
// Load implementations.
$info = array();
foreach (array_filter($file_list) as $module => $files) {
foreach ($files as $file) {
include_once './' . $file->filename;
$result = _wysiwyg_process_include('wysiwyg', $module . $file->name, dirname($file->filename), $hook);
if (is_array($result)) {
$info = array_merge($info, $result);
}
}
}
return $info;
}
/**
* Helper function to build module/file paths.
*
* @param $file
* A file or directory in a module to return.
* @param $base_path
* Whether to prefix the resulting path with base_path().
* @param $module
* The module name to use as prefix.
*
* @return
* The path to the specified file in a module.
*/
function wysiwyg_get_path($file = '', $base_path = FALSE, $module = 'wysiwyg_editor') {
$base_path = ($base_path ? base_path() : '');
return $base_path . drupal_get_path('module', $module) . '/' . $file;
}
/**
* Return a list of directories by modules implementing wysiwyg_include_directory().
*
* @param $plugintype
* The type of a plugin; can be 'editors'.
*
* @return
* An array containing module names suffixed with '_' and their defined
* directory.
*
* @see wysiwyg_load_includes(), _wysiwyg_process_include()
*/
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;
}
/**
* Process a single hook implementation of a wysiwyg editor.
*
* @param $module
* The module that owns the hook.
* @param $identifier
* Either the module or 'wysiwyg_' . $file->name
* @param $hook
* The name of the hook being invoked.
*/
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;
}
// Fill in defaults.
foreach ($result as $editor => $properties) {
$result[$editor]['module'] = $module;
$result[$editor]['name'] = $editor;
$result[$editor]['path'] = $path;
}
return $result;
}
/**
Daniel Kudwien
committed
* @} End of "defgroup wysiwyg_api".