whizzywig.inc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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', 'xhtml.js'),
  18. ),
  19. ),
  20. 'version callback' => 'wysiwyg_whizzywig_version',
  21. 'settings callback' => 'wysiwyg_whizzywig_settings',
  22. 'plugin callback' => 'wysiwyg_whizzywig_plugins',
  23. 'versions' => array(
  24. '55' => array(
  25. 'js files' => array('whizzywig.js'),
  26. ),
  27. '56' => array(
  28. 'js files' => array('whizzywig-56.js'),
  29. ),
  30. '60' => array(
  31. 'js files' => array('whizzywig-60.js'),
  32. ),
  33. ),
  34. );
  35. return $editor;
  36. }
  37. /**
  38. * Detect editor version.
  39. *
  40. * @param $editor
  41. * An array containing editor properties as returned from hook_editor().
  42. *
  43. * @return
  44. * The installed editor version.
  45. */
  46. function wysiwyg_whizzywig_version($editor) {
  47. $script = $editor['library path'] . '/whizzywig.js';
  48. if (!file_exists($script)) {
  49. return;
  50. }
  51. $script = fopen($script, 'r');
  52. $line = fgets($script, 43);
  53. // 55: Whizzywig v55i
  54. // 60: Whizzywig 60
  55. if (preg_match('@Whizzywig v?([0-9]+)@', $line, $version)) {
  56. fclose($script);
  57. return $version[1];
  58. }
  59. fclose($script);
  60. }
  61. /**
  62. * Return runtime editor settings for a given wysiwyg profile.
  63. *
  64. * @param $editor
  65. * A processed hook_editor() array of editor properties.
  66. * @param $config
  67. * An array containing wysiwyg editor profile settings.
  68. * @param $theme
  69. * The name of a theme/GUI/skin to use.
  70. *
  71. * @return
  72. * A settings array to be populated in
  73. * Drupal.settings.wysiwyg.configs.{editor}
  74. */
  75. function wysiwyg_whizzywig_settings($editor, $config, $theme) {
  76. $settings = array();
  77. // Add path to button images, if available.
  78. if (is_dir($editor['library path'] . '/btn')) {
  79. $settings['buttonPath'] = base_path() . $editor['library path'] . '/btn/';
  80. }
  81. if (file_exists($editor['library path'] . '/WhizzywigToolbar.png')) {
  82. $settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/WhizzywigToolbar.png';
  83. }
  84. // Filename changed in version 60.
  85. elseif (file_exists($editor['library path'] . '/icons.png')) {
  86. $settings['toolbarImagePath'] = base_path() . $editor['library path'] . '/icons.png';
  87. }
  88. // Add configured buttons or all available.
  89. $settings['buttons'] = array();
  90. if (!empty($config['buttons'])) {
  91. $buttons = array();
  92. foreach ($config['buttons'] as $plugin) {
  93. $buttons = array_merge($buttons, $plugin);
  94. }
  95. $settings['buttons'] = implode(' ', array_keys($buttons));
  96. }
  97. // Add editor content stylesheet.
  98. if (isset($config['css_setting'])) {
  99. if ($config['css_setting'] == 'theme') {
  100. $css = path_to_theme() . '/style.css';
  101. if (file_exists($css)) {
  102. $settings['externalCSS'] = base_path() . $css;
  103. }
  104. }
  105. else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
  106. $settings['externalCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
  107. }
  108. }
  109. return $settings;
  110. }
  111. /**
  112. * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
  113. */
  114. function wysiwyg_whizzywig_plugins($editor) {
  115. return array(
  116. 'default' => array(
  117. 'buttons' => array(
  118. 'formatblock' => t('HTML block format'), 'fontname' => t('Font'), 'fontsize' => t('Font size'),
  119. 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
  120. 'left' => t('Align left'), 'center' => t('Align center'), 'right' => t('Align right'),
  121. 'bullet' => t('Bullet list'), 'number' => t('Numbered list'),
  122. 'outdent' => t('Outdent'), 'indent' => t('Indent'),
  123. 'undo' => t('Undo'), 'redo' => t('Redo'),
  124. 'image' => t('Image'),
  125. 'color' => t('Forecolor'), 'hilite' => t('Backcolor'),
  126. 'rule' => t('Horizontal rule'),
  127. 'link' => t('Link'),
  128. 'image' => t('Image'),
  129. 'table' => t('Table'),
  130. 'clean' => t('Clean-up'),
  131. 'html' => t('Source code'),
  132. 'spellcheck' => t('Spell check'),
  133. ),
  134. 'internal' => TRUE,
  135. ),
  136. );
  137. }