nicedit.inc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * @file
  4. * Editor integration functions for NicEdit.
  5. */
  6. /**
  7. * Plugin implementation of hook_editor().
  8. */
  9. function wysiwyg_nicedit_editor() {
  10. $editor['nicedit'] = array(
  11. 'title' => 'NicEdit',
  12. 'vendor url' => 'http://nicedit.com',
  13. 'download url' => 'http://nicedit.com/download.php',
  14. 'libraries' => array(
  15. '' => array(
  16. 'title' => 'Source',
  17. 'files' => array('nicEdit.js'),
  18. ),
  19. ),
  20. 'verified version range' => array('0.9', '0.9'),
  21. 'version callback' => 'wysiwyg_nicedit_version',
  22. 'settings form callback' => 'wysiwyg_nicedit_settings_form',
  23. 'settings callback' => 'wysiwyg_nicedit_settings',
  24. 'plugin callback' => '_wysiwyg_nicedit_plugins',
  25. 'versions' => array(
  26. '0.9' => array(
  27. 'js files' => array('nicedit.js'),
  28. ),
  29. ),
  30. );
  31. return $editor;
  32. }
  33. /**
  34. * Detect editor version.
  35. *
  36. * @param $editor
  37. * An array containing editor properties as returned from hook_editor().
  38. *
  39. * @return
  40. * The installed editor version.
  41. */
  42. function wysiwyg_nicedit_version($editor) {
  43. // @see http://nicedit.com/forums/viewtopic.php?t=425
  44. return '0.9';
  45. }
  46. /**
  47. * Enhances the editor profile settings form for NicEdit.
  48. *
  49. * @see http://wiki.nicedit.com/w/page/515/Configuration%20Options
  50. */
  51. function wysiwyg_nicedit_settings_form(&$form, &$form_state) {
  52. $form['basic']['language']['#access'] = FALSE;
  53. // NicEdit only supports loading a single stylesheet, and only in FF2.
  54. // This essentially means we're dropping stylesheet support for NiceEdit.
  55. $form['css']['#access'] = FALSE;
  56. }
  57. /**
  58. * Return runtime editor settings for a given wysiwyg profile.
  59. *
  60. * @param $editor
  61. * A processed hook_editor() array of editor properties.
  62. * @param $config
  63. * An array containing wysiwyg editor profile settings.
  64. * @param $theme
  65. * The name of a theme/GUI/skin to use.
  66. *
  67. * @return
  68. * A settings array to be populated in
  69. * Drupal.settings.wysiwyg.configs.{editor}
  70. */
  71. function wysiwyg_nicedit_settings($editor, $config, $theme) {
  72. $settings = array(
  73. 'iconsPath' => base_path() . $editor['library path'] . '/nicEditorIcons.gif',
  74. );
  75. // Add configured buttons or all available.
  76. $settings['buttonList'] = array();
  77. if (!empty($config['buttons'])) {
  78. $buttons = array();
  79. foreach ($config['buttons'] as $plugin) {
  80. $buttons = array_merge($buttons, $plugin);
  81. }
  82. $settings['buttonList'] = array_keys($buttons);
  83. }
  84. // Add editor content stylesheet.
  85. // @todo Drop stylsheet support since it's only used in FF2.
  86. if (isset($config['css_setting'])) {
  87. if ($config['css_setting'] == 'theme') {
  88. $css = drupal_get_path('theme', variable_get('theme_default', NULL)) . '/style.css';
  89. if (file_exists($css)) {
  90. $settings['externalCSS'] = base_path() . $css;
  91. }
  92. }
  93. elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
  94. $settings['externalCSS'] = strtr($config['css_path'], array(
  95. '%b' => base_path(),
  96. '%t' => drupal_get_path('theme', variable_get('theme_default', NULL)),
  97. '%q' => variable_get('css_js_query_string', ''),
  98. ));
  99. }
  100. }
  101. return $settings;
  102. }
  103. /**
  104. * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
  105. */
  106. function _wysiwyg_nicedit_plugins($editor) {
  107. return array(
  108. 'default' => array(
  109. 'buttons' => array(
  110. 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
  111. 'strikethrough' => t('Strike-through'),
  112. 'left' => t('Align left'), 'center' => t('Align center'), 'right' => t('Align right'),
  113. 'ul' => t('Bullet list'), 'ol' => t('Numbered list'),
  114. 'outdent' => t('Outdent'), 'indent' => t('Indent'),
  115. 'image' => t('Image'),
  116. 'forecolor' => t('Forecolor'), 'bgcolor' => t('Backcolor'),
  117. 'superscript' => t('Superscript'), 'subscript' => t('Subscript'),
  118. 'hr' => t('Horizontal rule'),
  119. // @todo New challenge: Optional internal plugins packaged into editor
  120. // library.
  121. 'link' => t('Link'), 'unlink' => t('Unlink'),
  122. 'fontFormat' => t('HTML block format'), 'fontFamily' => t('Font'), 'fontSize' => t('Font size'),
  123. 'xhtml' => t('Source code'),
  124. ),
  125. 'internal' => TRUE,
  126. ),
  127. );
  128. }