less.wysiwyg.inc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * @file
  4. * Contains functions that handle WYSIWYG module integration.
  5. */
  6. /**
  7. * Implements hook_wysiwyg_editor_settings_alter().
  8. *
  9. * Check the CSS WYSIWYG setting for LESS files and replace with
  10. * generated CSS files where necessary.
  11. */
  12. function less_wysiwyg_editor_settings_alter(&$settings, $context) {
  13. $wysiwyg = $context['editor']['name'];
  14. // Each editor has a different $settings array key for CSS files.
  15. $editors = array(
  16. 'tinymce' => 'content_css',
  17. 'fckeditor' => 'EditorAreaCSS',
  18. 'ckeditor' => 'contentsCss',
  19. );
  20. if (!empty($editors[$wysiwyg]) && !empty($settings[$editors[$wysiwyg]])) {
  21. $stylesheets = $settings[$editors[$wysiwyg]];
  22. // Keep track if comma separated paths, or array of paths.
  23. $is_array = is_array($stylesheets);
  24. if ($is_array === FALSE) {
  25. // $stylesheets is a list of comma separated file paths.
  26. $stylesheets = explode(',', $stylesheets);
  27. }
  28. // Prepare an array that can be handled by normal LESS module processing.
  29. $styles = array(
  30. '#items' => array(),
  31. );
  32. foreach ($stylesheets as $stylesheet) {
  33. // Might contain ?query portion, separate parts.
  34. $parts = drupal_parse_url($stylesheet);
  35. // Paths are expected to be relative to DRUPAL_ROOT, trim leading '/'.
  36. $path = trim($parts['path'], '/');
  37. $styles['#items'][$path] = array(
  38. 'data' => $path,
  39. );
  40. }
  41. $styles = _less_pre_render($styles);
  42. $processed_stylesheets = array();
  43. foreach ($styles['#items'] as $file) {
  44. $processed_stylesheets[] = file_create_url($file['data']);
  45. }
  46. // Recombine file paths into comma separated list.
  47. if ($is_array === FALSE) {
  48. $processed_stylesheets = implode(',', $processed_stylesheets);
  49. }
  50. $settings[$editors[$wysiwyg]] = $processed_stylesheets;
  51. }
  52. }
  53. /**
  54. * Implements hook_form_FORM_ID_alter().
  55. *
  56. * form_id = 'wysiwyg_profile'
  57. */
  58. function less_form_wysiwyg_profile_form_alter(&$form, $form_state, $form_id) {
  59. $form['css']['css_path']['#description'] .= '<br />' . t('You may enter a path to a LESS file and it will be parsed automatically.');
  60. }
  61. /**
  62. * Implements hook_ckeditor_settings_alter().
  63. */
  64. function less_ckeditor_settings_alter(&$settings) {
  65. $context = array(
  66. 'editor' => array(
  67. 'name' => 'ckeditor',
  68. ),
  69. );
  70. less_wysiwyg_editor_settings_alter($settings, $context);
  71. }