#359626 by sun: Fixed external/Drupal plugins are not loaded for all profiles.
[project/wysiwyg.git] / wysiwyg.module
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Integrate client-side editors with Drupal.
7 */
8
9 /**
10 * Implementation of hook_menu().
11 */
12 function wysiwyg_menu($may_cache) {
13 $items = array();
14 if ($may_cache) {
15 $items[] = array(
16 'path' => 'admin/settings/wysiwyg/profile',
17 'title' => t('Wysiwyg'),
18 'callback' => 'wysiwyg_admin',
19 'description' => t('Configure client-side editor profiles.'),
20 'access' => user_access('administer filters'),
21 );
22 }
23 return $items;
24 }
25
26 /**
27 * Implementation of hook_help().
28 */
29 function wysiwyg_help($section) {
30 switch ($section) {
31 case 'admin/settings/wysiwyg/profile':
32 if (!arg(4)) {
33 $output = '<p>'. t('A Wysiwyg profile can be associated to an input format. A Wysiwyg profile defines which client-side editor is loaded, what buttons or themes are enabled for the editor, how the editor is displayed, and a few other editor-specific functions.') .'</p>';
34 return $output;
35 }
36 break;
37 }
38 }
39
40 /**
41 * Callback handler for admin pages; menu callback.
42 */
43 function wysiwyg_admin($arg = '', $name = '') {
44 require_once drupal_get_path('module', 'wysiwyg') .'/wysiwyg.admin.inc';
45 return _wysiwyg_admin($arg, $name);
46 }
47
48 /**
49 * Implementation of hook_form_alter().
50 *
51 * Before Drupal 7, there is no way to easily identify form fields that are
52 * input format enabled. As a workaround, we assign a form #after_build
53 * processing callback that is executed on all forms after they have been
54 * completely built, so form elements are in their effective order
55 * and position already.
56 *
57 * @see wysiwyg_process_form()
58 */
59 function wysiwyg_form_alter($form_id, &$form) {
60 $form['#after_build'][] = 'wysiwyg_process_form';
61 // Blog module in Drupal 5 uses a wrong/unusual form element key for the input
62 // format selector.
63 if ($form_id == 'blog_node_form') {
64 $form['body_filter']['format'] = $form['body_filter']['filter'];
65 unset($form['body_filter']['filter']);
66 }
67 }
68
69 /**
70 * Process a textarea for Wysiwyg Editor.
71 *
72 * This way, we can recurse into the form and search for certain, hard-coded
73 * elements that have been added by filter_form(). If an input format selector
74 * or input format guidelines element is found, we assume that the preceding
75 * element is the corresponding textarea and use it's #id for attaching
76 * client-side editors.
77 *
78 * @see wysiwyg_elements(), filter_form()
79 */
80 function wysiwyg_process_form(&$form) {
81 // Iterate over element children; resetting array keys to access last index.
82 if ($children = array_values(element_children($form))) {
83 foreach ($children as $index => $item) {
84 $element = &$form[$item];
85
86 // filter_form() always uses the key 'format'. We need a type-agnostic
87 // match to prevent false positives. Also, there must have been at least
88 // one element on this level.
89 if ($item === 'format' && $index > 0) {
90 // Make sure we either match a input format selector or input format
91 // guidelines (displayed if user has access to one input format only).
92 if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) {
93 // The element before this element is the target form field.
94 $field = &$form[$children[$index - 1]];
95
96 // Disable #resizable to avoid resizable behavior to hi-jack the UI,
97 // but load the behavior, so the 'none' editor can attach/detach it.
98 $extra_class = '';
99 if (!isset($field['#resizable']) || !empty($field['#resizable'])) {
100 // Due to our CSS class parsing, we can add arbitrary parameters
101 // for each input format.
102 $extra_class = ' wysiwyg-resizable-1';
103 $field['#resizable'] = FALSE;
104 drupal_add_js('misc/textarea.js');
105 }
106
107 // Determine the available input formats. The last child element is a
108 // link to "More information about formatting options". When only one
109 // input format is displayed, we also have to remove formatting
110 // guidelines, stored in the child 'format'.
111 $formats = element_children($element);
112 array_pop($formats);
113 if (($key = array_search('format', $formats)) !== FALSE) {
114 unset($formats[$key]);
115 }
116 foreach ($formats as $format) {
117 // Default to 'none' editor (Drupal's default behaviors).
118 $editor = 'none';
119 $status = 1;
120 // Fetch the profile associated to this input format.
121 $profile = wysiwyg_get_profile($format);
122 if ($profile) {
123 $editor = $profile->editor;
124 $status = (int)wysiwyg_user_get_status($profile);
125 // Check editor theme (and reset it if not/no longer available).
126 $theme = wysiwyg_get_editor_themes($profile, (isset($profile->settings['theme']) ? $profile->settings['theme'] : ''));
127
128 // Add plugin settings (first) for this input format.
129 wysiwyg_add_plugin_settings($profile);
130 // Add profile settings for this input format.
131 wysiwyg_add_editor_settings($profile, $theme);
132 }
133
134 // Use a prefix/suffix for a single input format, or attach to input
135 // format selector radio buttons.
136 if (isset($element['format']['guidelines'])) {
137 $element['format']['guidelines']['#prefix'] = '<div class="wysiwyg wysiwyg-format-'. $format .' wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] .' wysiwyg-status-'. $status . $extra_class .'">';
138 $element['format']['guidelines']['#suffix'] = '</div>';
139 // Edge-case: Default format contains no input filters.
140 if (empty($element['format']['guidelines']['#value'])) {
141 $element['format']['guidelines']['#value'] = ' ';
142 }
143 }
144 else {
145 if (isset($element[$format]['#attributes']['class'])) {
146 $element[$format]['#attributes']['class'] .= ' ';
147 }
148 else {
149 $element[$format]['#attributes']['class'] = '';
150 }
151 $element[$format]['#attributes']['class'] .= 'wysiwyg wysiwyg-format-'. $format .' wysiwyg-editor-'. $editor .' wysiwyg-field-'. $field['#id'] .' wysiwyg-status-'. $status . $extra_class;
152 }
153 }
154 }
155 // If this element is 'format', do not recurse further.
156 continue;
157 }
158 // Recurse into children.
159 wysiwyg_process_form($element);
160 }
161 }
162 return $form;
163 }
164
165 /**
166 * Determine the profile to use for a given input format id.
167 *
168 * This function also performs sanity checks for the configured editor in a
169 * profile to ensure that we do not load a malformed editor.
170 *
171 * @param $format
172 * The internal id of an input format.
173 *
174 * @return
175 * A wysiwyg profile.
176 *
177 * @see wysiwyg_load_editor(), wysiwyg_get_editor()
178 */
179 function wysiwyg_get_profile($format) {
180 if ($profile = wysiwyg_load_profile($format)) {
181 if (wysiwyg_load_editor($profile)) {
182 return $profile;
183 }
184 }
185 return FALSE;
186 }
187
188 /**
189 * Load an editor library and initialize basic Wysiwyg settings.
190 *
191 * @param $profile
192 * A wysiwyg editor profile.
193 *
194 * @return
195 * TRUE if the editor has been loaded, FALSE if not.
196 *
197 * @see wysiwyg_get_profile()
198 */
199 function wysiwyg_load_editor($profile) {
200 static $settings_added;
201 static $loaded = array();
202
203 $name = $profile->editor;
204 // Library files must be loaded only once.
205 if (!isset($loaded[$name])) {
206 // Load editor.
207 $editor = wysiwyg_get_editor($name);
208 if ($editor) {
209 // Determine library files to load.
210 // @todo Allow to configure the library/execMode to use.
211 if (isset($profile->settings['library']) && isset($editor['libraries'][$profile->settings['library']])) {
212 $library = $profile->settings['library'];
213 $files = $editor['libraries'][$library]['files'];
214 }
215 else {
216 // Fallback to the first defined library by default (external libraries can change).
217 $library = key($editor['libraries']);
218 $files = array_shift($editor['libraries']);
219 $files = $files['files'];
220 }
221 foreach ($files as $file => $options) {
222 if (is_array($options)) {
223 $options += array('type' => 'module', 'scope' => 'header', 'defer' => FALSE, 'cache' => TRUE, 'preprocess' => TRUE);
224 drupal_add_js($editor['library path'] . '/' . $file, $options['type'], $options['scope'], $options['defer'], $options['cache'], $options['preprocess']);
225 }
226 else {
227 drupal_add_js($editor['library path'] . '/' . $options);
228 }
229 }
230 // If editor defines an additional load callback, invoke it.
231 // @todo Isn't the settings callback sufficient?
232 if (isset($editor['load callback']) && function_exists($editor['load callback'])) {
233 $editor['load callback']($editor, $library);
234 }
235 // Load JavaScript integration files for this editor.
236 $files = array();
237 if (isset($editor['js files'])) {
238 $files = $editor['js files'];
239 }
240 foreach ($files as $file) {
241 drupal_add_js($editor['js path'] . '/' . $file);
242 }
243 // Load CSS stylesheets for this editor.
244 $files = array();
245 if (isset($editor['css files'])) {
246 $files = $editor['css files'];
247 }
248 foreach ($files as $file) {
249 drupal_add_css($editor['css path'] . '/' . $file);
250 }
251
252 drupal_add_js(array('wysiwyg' => array(
253 'configs' => array($editor['name'] => array()),
254 // @todo Move into profile settings.
255 'showToggle' => isset($profile->settings['show_toggle']) ? $profile->settings['show_toggle'] : TRUE,
256 // @todo Move into (global) editor settings.
257 // If JS compression is enabled, at least TinyMCE is unable to determine
258 // its own base path and exec mode since it can't find the script name.
259 'editorBasePath' => base_path() . $editor['library path'],
260 'execMode' => $library,
261 )), 'setting');
262
263 $loaded[$name] = TRUE;
264 }
265 else {
266 $loaded[$name] = FALSE;
267 }
268 }
269
270 // Add basic Wysiwyg settings if any editor has been added.
271 if (!isset($settings_added) && $loaded[$name]) {
272 drupal_add_js(array('wysiwyg' => array(
273 'configs' => array(),
274 'disable' => t('Disable rich-text'),
275 'enable' => t('Enable rich-text'),
276 )), 'setting');
277
278 // Initialize our namespaces in the *header* to do not force editor
279 // integration scripts to check and define Drupal.wysiwyg on its own.
280 drupal_add_js(wysiwyg_get_path('wysiwyg.init.js'), 'core');
281
282 // The 'none' editor is a special editor implementation, allowing us to
283 // attach and detach regular Drupal behaviors just like any other editor.
284 drupal_add_js(wysiwyg_get_path('editors/js/none.js'));
285
286 // Add wysiwyg.js to the footer to ensure it's executed after the
287 // Drupal.settings array has been rendered and populated. Also, since editor
288 // library initialization functions must be loaded first by the browser,
289 // and Drupal.wysiwygInit() must be executed AFTER editors registered
290 // their callbacks and BEFORE Drupal.behaviors are applied, this must come
291 // last.
292 drupal_add_js(wysiwyg_get_path('wysiwyg.js'), 'module', 'footer');
293
294 $settings_added = TRUE;
295 }
296
297 return $loaded[$name];
298 }
299
300 /**
301 * Add editor settings for a given input format.
302 */
303 function wysiwyg_add_editor_settings($profile, $theme) {
304 static $formats = array();
305
306 if (!isset($formats[$profile->format])) {
307 $config = wysiwyg_get_editor_config($profile, $theme);
308 // drupal_to_js() does not properly convert numeric array keys, so we need
309 // to use a string instead of the format id.
310 drupal_add_js(array('wysiwyg' => array('configs' => array($profile->editor => array('format'. $profile->format => $config)))), 'setting');
311 $formats[$profile->format] = TRUE;
312 }
313 }
314
315 /**
316 * Add settings for external plugins.
317 *
318 * Plugins can be used in multiple profiles, but not necessarily in all. Because
319 * of that, we need to process plugins for each profile, even if most of their
320 * settings are not stored per profile.
321 *
322 * Implementations of hook_wysiwyg_plugin() may execute different code for each
323 * editor. Therefore, we have to invoke those implementations for each editor,
324 * but process the resulting plugins separately for each profile.
325 *
326 * Drupal plugins differ to native plugins in that they have plugin-specific
327 * definitions and settings, which need to be processed only once. But they are
328 * also passed to the editor to prepare settings specific to the editor.
329 * Therefore, we load and process the Drupal plugins only once, and hand off the
330 * effective definitions for each profile to the editor.
331 *
332 * @param $profile
333 * A wysiwyg editor profile.
334 *
335 * @todo Rewrite wysiwyg_process_form() to build a registry of effective
336 * profiles in use, so we can process plugins in multiple profiles in one shot
337 * and simplify this entire function.
338 */
339 function wysiwyg_add_plugin_settings($profile) {
340 static $plugins_native = array();
341
342 $editor = wysiwyg_get_editor($profile->editor);
343 // Assume that this editor does not support neither native external plugins
344 // nor Drupal plugins if it does not provide a callback.
345 if (!(isset($editor['plugin settings callback']) && function_exists($editor['plugin settings callback']))) {
346 return;
347 }
348
349 // Load our own plugins.
350 include_once drupal_get_path('module', 'wysiwyg') .'/wysiwyg.plugins.inc';
351
352 // Collect native external plugins for this editor provided via
353 // hook_wysiwyg_plugin().
354 if (!array_key_exists($editor['name'], $plugins_native)) {
355 $plugins_native[$editor['name']] = module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']);
356 }
357 // Only keep native external plugins that are enabled in this profile.
358 foreach ($plugins_native[$editor['name']] as $plugin => $meta) {
359 if (!isset($profile->settings['buttons'][$plugin])) {
360 unset($plugins_native[$editor['name']][$plugin]);
361 }
362 }
363 // Invoke the editor's plugin settings callback, so it can populate the
364 // settings for native external plugins with custom, required values.
365 $settings_native = $editor['plugin settings callback']($editor, $profile, $plugins_native[$editor['name']]);
366
367 drupal_add_js(array('wysiwyg' => array('plugins' => array($profile->editor => $settings_native))), 'setting');
368 }
369
370 /**
371 * Retrieve available themes for an editor.
372 *
373 * Editor themes control the visual presentation of an editor.
374 *
375 * @param $profile
376 * A wysiwyg editor profile; passed/altered by reference.
377 * @param $selected_theme
378 * An optional theme name that ought to be used.
379 *
380 * @return
381 * An array of theme names, or a single, checked theme name if $selected_theme
382 * was given.
383 */
384 function wysiwyg_get_editor_themes(&$profile, $selected_theme = NULL) {
385 static $themes = array();
386
387 if (!isset($themes[$profile->editor])) {
388 $editor = wysiwyg_get_editor($profile->editor);
389 if (isset($editor['themes callback']) && function_exists($editor['themes callback'])) {
390 $themes[$editor['name']] = $editor['themes callback']($editor, $profile);
391 }
392 // Fallback to 'default' otherwise.
393 else {
394 $themes[$editor['name']] = array('default');
395 }
396 }
397
398 // Check optional $selected_theme argument, if given.
399 if (isset($selected_theme)) {
400 // If the passed theme name does not exist, use the first available.
401 if (!isset($themes[$profile->editor][$selected_theme])) {
402 $selected_theme = $profile->settings['theme'] = $themes[$profile->editor][0];
403 }
404 }
405
406 return isset($selected_theme) ? $selected_theme : $themes[$profile->editor];
407 }
408
409 /**
410 * Return plugin metadata from the plugin registry.
411 *
412 * @param $editor_name
413 * The internal name of an editor to return plugins for.
414 *
415 * @return
416 * An array for each plugin.
417 */
418 function wysiwyg_get_plugins($editor_name) {
419 $plugins = array();
420 if (!empty($editor_name)) {
421 $editor = wysiwyg_get_editor($editor_name);
422 // Add internal editor plugins.
423 if (isset($editor['plugin callback']) && function_exists($editor['plugin callback'])) {
424 $plugins = $editor['plugin callback']($editor);
425 }
426 // Load our own plugins.
427 include_once drupal_get_path('module', 'wysiwyg') .'/wysiwyg.plugins.inc';
428
429 // Add editor plugins provided via hook_wysiwyg_plugin().
430 $plugins = array_merge($plugins, module_invoke_all('wysiwyg_plugin', $editor['name'], $editor['installed version']));
431 }
432 return $plugins;
433 }
434
435 /**
436 * Return an array of initial editor settings for a Wysiwyg profile.
437 */
438 function wysiwyg_get_editor_config($profile, $theme) {
439 $editor = wysiwyg_get_editor($profile->editor);
440 $settings = array();
441 if (!empty($editor['settings callback']) && function_exists($editor['settings callback'])) {
442 $settings = $editor['settings callback']($editor, $profile->settings, $theme);
443 }
444 return $settings;
445 }
446
447 /**
448 * Retrieve stylesheets for HTML/IFRAME-based editors.
449 *
450 * This assumes that the content editing area only needs stylesheets defined
451 * for the scope 'theme'.
452 *
453 * @return
454 * An array containing CSS files, including proper base path.
455 */
456 function wysiwyg_get_css() {
457 static $files;
458
459 if (isset($files)) {
460 return $files;
461 }
462 $files = array();
463 foreach (drupal_add_css() as $media => $css) {
464 if ($media != 'print') {
465 foreach ($css['theme'] as $filepath => $preprocess) {
466 $files[] = base_path() . $filepath;
467 }
468 }
469 }
470 return $files;
471 }
472
473 /**
474 * Load all profiles. Just load one profile if $name is passed in.
475 */
476 function wysiwyg_load_profile($format = '') {
477 static $profiles;
478
479 if (!isset($profiles)) {
480 $profiles = array();
481 $result = db_query('SELECT * FROM {wysiwyg}');
482 while ($profile = db_fetch_object($result)) {
483 $profile->settings = unserialize($profile->settings);
484 $profiles[$profile->format] = $profile;
485 }
486 }
487
488 return ($format && isset($profiles[$format]) ? $profiles[$format] : ($format ? FALSE : $profiles));
489 }
490
491 /**
492 * Implementation of hook_user().
493 */
494 function wysiwyg_user($type, &$edit, &$user, $category = NULL) {
495 if ($type == 'form' && $category == 'account') {
496 // @todo http://drupal.org/node/322433
497 $profile = new stdClass;
498 if (isset($profile->settings['user_choose']) && $profile->settings['user_choose']) {
499 $form['wysiwyg'] = array(
500 '#type' => 'fieldset',
501 '#title' => t('Wysiwyg Editor settings'),
502 '#weight' => 10,
503 '#collapsible' => TRUE,
504 '#collapsed' => TRUE,
505 );
506 $form['wysiwyg']['wysiwyg_status'] = array(
507 '#type' => 'checkbox',
508 '#title' => t('Enable editor by default'),
509 '#default_value' => isset($user->wysiwyg_status) ? $user->wysiwyg_status : (isset($profile->settings['default']) ? $profile->settings['default'] : FALSE),
510 '#return_value' => 1,
511 '#description' => t('If enabled, rich-text editing is enabled by default in textarea fields.'),
512 );
513 return array('wysiwyg' => $form);
514 }
515 }
516 elseif ($type == 'validate' && isset($edit['wysiwyg_status'])) {
517 return array('wysiwyg_status' => $edit['wysiwyg_status']);
518 }
519 }
520
521 function wysiwyg_user_get_status($profile) {
522 global $user;
523
524 if (!empty($profile->settings['user_choose']) && isset($user->wysiwyg_status)) {
525 $status = $user->wysiwyg_status;
526 }
527 else {
528 $status = isset($profile->settings['default']) ? $profile->settings['default'] : TRUE;
529 }
530
531 return $status;
532 }
533
534 /**
535 * @defgroup wysiwyg_api Wysiwyg API
536 * @{
537 *
538 * @todo Forked from Panels; abstract into a separate API module that allows
539 * contrib modules to define supported include/plugin types.
540 */
541
542 /**
543 * Return library information for a given editor.
544 *
545 * @param $name
546 * The internal name of an editor.
547 *
548 * @return
549 * The library information for the editor, or FALSE if $name is unknown or not
550 * installed properly.
551 */
552 function wysiwyg_get_editor($name) {
553 $editors = wysiwyg_get_all_editors();
554 return isset($editors[$name]) && $editors[$name]['installed'] ? $editors[$name] : FALSE;
555 }
556
557 /**
558 * Compile a list holding all supported editors including installed editor version information.
559 */
560 function wysiwyg_get_all_editors() {
561 static $editors;
562
563 if (isset($editors)) {
564 return $editors;
565 }
566
567 $editors = wysiwyg_load_includes('editors', 'editor');
568 foreach ($editors as $editor => $properties) {
569 // Fill in required properties.
570 $editors[$editor] += array(
571 'title' => '',
572 'vendor url' => '',
573 'download url' => '',
574 'editor path' => wysiwyg_get_path($properties['name']),
575 'library path' => wysiwyg_get_path($properties['name']),
576 'libraries' => array(),
577 'version callback' => NULL,
578 'themes callback' => NULL,
579 'settings callback' => NULL,
580 'plugin callback' => NULL,
581 'plugin settings callback' => NULL,
582 'versions' => array(),
583 'js path' => $properties['path'] .'/js',
584 'css path' => $properties['path'] .'/css',
585 );
586 // Check whether library is present.
587 if (!($editors[$editor]['installed'] = file_exists($properties['library path']))) {
588 continue;
589 }
590 // Detect library version.
591 if (function_exists($editors[$editor]['version callback'])) {
592 $editors[$editor]['installed version'] = $editors[$editor]['version callback']($properties);
593 }
594 if (empty($editors[$editor]['installed version'])) {
595 $editors[$editor]['error'] = t('The version of %editor could not be detected.', array('%editor' => $properties['title']));
596 $editors[$editor]['installed'] = FALSE;
597 continue;
598 }
599 // Determine to which supported version the installed version maps.
600 ksort($editors[$editor]['versions']);
601 $version = 0;
602 foreach ($editors[$editor]['versions'] as $supported_version => $version_properties) {
603 if (version_compare($editors[$editor]['installed version'], $supported_version, '>=')) {
604 $version = $supported_version;
605 }
606 }
607 if (!$version) {
608 $editors[$editor]['error'] = t('The installed version %version of %editor is not supported.', array('%version' => $editors[$editor]['installed version'], '%editor' => $properties['title']));
609 $editors[$editor]['installed'] = FALSE;
610 continue;
611 }
612 // Apply library version specific definitions and overrides.
613 $editors[$editor] = array_merge($editors[$editor], $editors[$editor]['versions'][$version]);
614 unset($editors[$editor]['versions']);
615 }
616 return $editors;
617 }
618
619 /**
620 * Load include files for wysiwyg implemented by all modules.
621 *
622 * @param $type
623 * The type of includes to search for, can be 'editors'.
624 * @param $hook
625 * The hook name to invoke.
626 * @param $file
627 * An optional include file name without .inc extension to limit the search to.
628 *
629 * @see wysiwyg_get_directories(), _wysiwyg_process_include()
630 */
631 function wysiwyg_load_includes($type = 'editors', $hook = 'editor', $file = NULL) {
632 // Determine implementations.
633 $directories = wysiwyg_get_directories($type);
634 $directories['wysiwyg_'] = wysiwyg_get_path($type);
635 $file_list = array();
636 foreach ($directories as $module => $path) {
637 $file_list[$module] = drupal_system_listing("$file" . '.inc$', $path, 'name', 0);
638 }
639
640 // Load implementations.
641 $info = array();
642 foreach (array_filter($file_list) as $module => $files) {
643 foreach ($files as $file) {
644 include_once './' . $file->filename;
645 $result = _wysiwyg_process_include('wysiwyg', $module . $file->name, dirname($file->filename), $hook);
646 if (is_array($result)) {
647 $info = array_merge($info, $result);
648 }
649 }
650 }
651 return $info;
652 }
653
654 /**
655 * Helper function to build module/file paths.
656 *
657 * @param $file
658 * A file or directory in a module to return.
659 * @param $base_path
660 * Whether to prefix the resulting path with base_path().
661 * @param $module
662 * The module name to use as prefix.
663 *
664 * @return
665 * The path to the specified file in a module.
666 */
667 function wysiwyg_get_path($file = '', $base_path = FALSE, $module = 'wysiwyg') {
668 $base_path = ($base_path ? base_path() : '');
669 return $base_path . drupal_get_path('module', $module) . '/' . $file;
670 }
671
672 /**
673 * Return a list of directories by modules implementing wysiwyg_include_directory().
674 *
675 * @param $plugintype
676 * The type of a plugin; can be 'editors'.
677 *
678 * @return
679 * An array containing module names suffixed with '_' and their defined
680 * directory.
681 *
682 * @see wysiwyg_load_includes(), _wysiwyg_process_include()
683 */
684 function wysiwyg_get_directories($plugintype) {
685 $directories = array();
686 foreach (module_implements('wysiwyg_include_directory') as $module) {
687 $result = module_invoke($module, 'wysiwyg_include_directory', $plugintype);
688 if (isset($result) && is_string($result)) {
689 $directories[$module .'_'] = drupal_get_path('module', $module) .'/'. $result;
690 }
691 }
692 return $directories;
693 }
694
695 /**
696 * Process a single hook implementation of a wysiwyg editor.
697 *
698 * @param $module
699 * The module that owns the hook.
700 * @param $identifier
701 * Either the module or 'wysiwyg_' . $file->name
702 * @param $hook
703 * The name of the hook being invoked.
704 */
705 function _wysiwyg_process_include($module, $identifier, $path, $hook) {
706 $function = $identifier . '_' . $hook;
707 if (!function_exists($function)) {
708 return NULL;
709 }
710 $result = $function();
711 if (!isset($result) || !is_array($result)) {
712 return NULL;
713 }
714
715 // Fill in defaults.
716 foreach ($result as $editor => $properties) {
717 $result[$editor]['module'] = $module;
718 $result[$editor]['name'] = $editor;
719 $result[$editor]['path'] = $path;
720 }
721 return $result;
722 }
723
724 /**
725 * @} End of "defgroup wysiwyg_api".
726 */
727