whizzywig.inc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * @file
  4. * Editor integration functions for Whizzywig.
  5. */
  6. /**
  7. * Plugin implementation of hook_editor().
  8. */
  9. function wysiwyg_whizzywig_editor() {
  10. $editor['whizzywig'] = array(
  11. 'title' => 'Whizzywig',
  12. 'vendor url' => 'http://www.unverse.net',
  13. 'download url' => 'http://www.unverse.net/whizzywig-download.html',
  14. 'libraries' => array(
  15. '' => array(
  16. 'title' => 'Default',
  17. 'files' => array('whizzywig.js'),
  18. ),
  19. ),
  20. 'verified version range' => array('55', '63'),
  21. 'version callback' => 'wysiwyg_whizzywig_version',
  22. 'settings form callback' => 'wysiwyg_whizzywig_settings_form',
  23. 'settings callback' => 'wysiwyg_whizzywig_settings',
  24. 'plugin callback' => '_wysiwyg_whizzywig_plugins',
  25. 'versions' => array(
  26. '55' => array(
  27. 'js files' => array('whizzywig.js'),
  28. 'libraries' => array(
  29. '' => array(
  30. 'title' => 'Default',
  31. 'files' => array('whizzywig.js', 'xhtml.js'),
  32. ),
  33. ),
  34. ),
  35. '56' => array(
  36. 'js files' => array('whizzywig-56.js'),
  37. ),
  38. '60' => array(
  39. 'js files' => array('whizzywig-60.js'),
  40. ),
  41. ),
  42. );
  43. return $editor;
  44. }
  45. /**
  46. * Detect editor version.
  47. *
  48. * @param $editor
  49. * An array containing editor properties as returned from hook_editor().
  50. *
  51. * @return
  52. * The installed editor version.
  53. */
  54. function wysiwyg_whizzywig_version($editor) {
  55. $script = $editor['library path'] . '/whizzywig.js';
  56. if (!file_exists($script)) {
  57. return;
  58. }
  59. $script = fopen($script, 'r');
  60. $line = fgets($script, 43);
  61. // 55: Whizzywig v55i
  62. // 60: Whizzywig 60
  63. if (preg_match('@Whizzywig v?([0-9]+)@', $line, $version)) {
  64. fclose($script);
  65. return $version[1];
  66. }
  67. fclose($script);
  68. }
  69. /**
  70. * Enhances the editor profile settings form for Whizzywig.
  71. */
  72. function wysiwyg_whizzywig_settings_form(&$form, &$form_state) {
  73. $form['basic']['language']['#access'] = FALSE;
  74. // @todo CSS settings are currently not used.
  75. $form['css']['#access'] = FALSE;
  76. }
  77. /**
  78. * Return runtime editor settings for a given wysiwyg profile.
  79. *
  80. * @param $editor
  81. * A processed hook_editor() array of editor properties.
  82. * @param $config
  83. * An array containing wysiwyg editor profile settings.
  84. * @param $theme
  85. * The name of a theme/GUI/skin to use.
  86. *
  87. * @return
  88. * A settings array to be populated in
  89. * Drupal.settings.wysiwyg.configs.{editor}
  90. */
  91. function wysiwyg_whizzywig_settings($editor, $config, $theme) {
  92. $settings = array();
  93. // Add path to button images, if available.
  94. if (is_dir($editor['library path'] . '/btn')) {
  95. $settings['buttonPath'] = base_path() . $editor['library path'] . '/btn/';
  96. }
  97. if (file_exists($editor['library path'] . '/WhizzywigToolbar.png')) {
  98. $settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/WhizzywigToolbar.png';
  99. }
  100. // Filename changed in version 60.
  101. elseif (file_exists($editor['library path'] . '/icons.png')) {
  102. $settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/icons.png';
  103. }
  104. // Add configured buttons or all available.
  105. $settings['buttons'] = array();
  106. if (!empty($config['buttons'])) {
  107. $buttons = array();
  108. foreach ($config['buttons'] as $plugin) {
  109. $buttons = array_merge($buttons, $plugin);
  110. }
  111. $settings['buttons'] = implode(' ', array_keys($buttons));
  112. }
  113. // Add editor content stylesheet.
  114. // @todo CSS settings are currently not used.
  115. if (isset($config['css_setting'])) {
  116. if ($config['css_setting'] == 'theme') {
  117. $css = drupal_get_path('theme', variable_get('theme_default', NULL)) . '/style.css';
  118. if (file_exists($css)) {
  119. $settings['externalCSS'] = base_path() . $css;
  120. }
  121. }
  122. elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
  123. $settings['externalCSS'] = strtr($config['css_path'], array(
  124. '%b' => base_path(),
  125. '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)),
  126. '%q' => variable_get('css_js_query_string', ''),
  127. ));
  128. }
  129. }
  130. return $settings;
  131. }
  132. /**
  133. * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
  134. */
  135. function _wysiwyg_whizzywig_plugins($editor) {
  136. return array(
  137. 'default' => array(
  138. 'buttons' => array(
  139. 'formatblock' => t('HTML block format'), 'fontname' => t('Font'), 'fontsize' => t('Font size'),
  140. 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
  141. 'left' => t('Align left'), 'center' => t('Align center'), 'right' => t('Align right'),
  142. 'bullet' => t('Bullet list'), 'number' => t('Numbered list'),
  143. 'outdent' => t('Outdent'), 'indent' => t('Indent'),
  144. 'undo' => t('Undo'), 'redo' => t('Redo'),
  145. 'image' => t('Image'),
  146. 'color' => t('Forecolor'), 'hilite' => t('Backcolor'),
  147. 'rule' => t('Horizontal rule'),
  148. 'link' => t('Link'),
  149. 'image' => t('Image'),
  150. 'table' => t('Table'),
  151. 'clean' => t('Clean-up'),
  152. 'html' => t('Source code'),
  153. 'spellcheck' => t('Spell check'),
  154. ),
  155. 'internal' => TRUE,
  156. ),
  157. );
  158. }