nicedit.inc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. 'version callback' => 'wysiwyg_nicedit_version',
  21. 'settings callback' => 'wysiwyg_nicedit_settings',
  22. 'plugin callback' => 'wysiwyg_nicedit_plugins',
  23. 'versions' => array(
  24. '0.9' => array(
  25. 'js files' => array('nicedit.js'),
  26. ),
  27. ),
  28. );
  29. return $editor;
  30. }
  31. /**
  32. * Detect editor version.
  33. *
  34. * @param $editor
  35. * An array containing editor properties as returned from hook_editor().
  36. *
  37. * @return
  38. * The installed editor version.
  39. */
  40. function wysiwyg_nicedit_version($editor) {
  41. // @see http://nicedit.com/forums/viewtopic.php?t=425
  42. return '0.9';
  43. }
  44. /**
  45. * Return runtime editor settings for a given wysiwyg profile.
  46. *
  47. * @param $editor
  48. * A processed hook_editor() array of editor properties.
  49. * @param $config
  50. * An array containing wysiwyg editor profile settings.
  51. * @param $theme
  52. * The name of a theme/GUI/skin to use.
  53. *
  54. * @return
  55. * A settings array to be populated in
  56. * Drupal.settings.wysiwyg.configs.{editor}
  57. */
  58. function wysiwyg_nicedit_settings($editor, $config, $theme) {
  59. $settings = array(
  60. 'iconsPath' => base_path() . $editor['library path'] . '/nicEditorIcons.gif',
  61. );
  62. // Add configured buttons or all available.
  63. $settings['buttonList'] = array();
  64. if (!empty($config['buttons'])) {
  65. $buttons = array();
  66. foreach ($config['buttons'] as $plugin) {
  67. $buttons = array_merge($buttons, $plugin);
  68. }
  69. $settings['buttonList'] = array_keys($buttons);
  70. }
  71. // Add editor content stylesheet.
  72. if (isset($config['css_setting'])) {
  73. if ($config['css_setting'] == 'theme') {
  74. $css = path_to_theme() . '/style.css';
  75. if (file_exists($css)) {
  76. $settings['externalCSS'] = base_path() . $css;
  77. }
  78. }
  79. else if ($config['css_setting'] == 'self' && isset($config['css_path'])) {
  80. $settings['externalCSS'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => path_to_theme()));
  81. }
  82. }
  83. return $settings;
  84. }
  85. /**
  86. * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
  87. */
  88. function wysiwyg_nicedit_plugins($editor) {
  89. return array(
  90. 'default' => array(
  91. 'buttons' => array(
  92. 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
  93. 'strikethrough' => t('Strike-through'),
  94. 'left' => t('Align left'), 'center' => t('Align center'), 'right' => t('Align right'),
  95. 'ul' => t('Bullet list'), 'ol' => t('Numbered list'),
  96. 'outdent' => t('Outdent'), 'indent' => t('Indent'),
  97. 'image' => t('Image'),
  98. 'forecolor' => t('Forecolor'), 'bgcolor' => t('Backcolor'),
  99. 'superscript' => t('Superscript'), 'subscript' => t('Subscript'),
  100. 'hr' => t('Horizontal rule'),
  101. // @todo New challenge: Optional internal plugins packaged into editor
  102. // library.
  103. 'link' => t('Link'), 'unlink' => t('Unlink'),
  104. 'fontFormat' => t('HTML block format'), 'fontFamily' => t('Font'), 'fontSize' => t('Font size'),
  105. 'xhtml' => t('Source code'),
  106. ),
  107. 'internal' => TRUE,
  108. ),
  109. );
  110. }