openwysiwyg.inc 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. /**
  3. * @file
  4. * Editor integration functions for openWYSIWYG.
  5. */
  6. /**
  7. * Plugin implementation of hook_editor().
  8. */
  9. function wysiwyg_openwysiwyg_editor() {
  10. $editor['openwysiwyg'] = array(
  11. 'title' => 'openWYSIWYG',
  12. 'vendor url' => 'http://www.openwebware.com',
  13. 'download url' => 'http://www.openwebware.com/download.shtml',
  14. 'library path' => wysiwyg_get_path('openwysiwyg') . '/scripts',
  15. 'libraries' => array(
  16. 'src' => array(
  17. 'title' => 'Source',
  18. 'files' => array('wysiwyg.js'),
  19. ),
  20. ),
  21. 'version callback' => 'wysiwyg_openwysiwyg_version',
  22. 'themes callback' => 'wysiwyg_openwysiwyg_themes',
  23. 'settings callback' => 'wysiwyg_openwysiwyg_settings',
  24. 'plugin callback' => 'wysiwyg_openwysiwyg_plugins',
  25. 'versions' => array(
  26. '1.4.7' => array(
  27. 'js files' => array('openwysiwyg.js'),
  28. 'css files' => array('openwysiwyg.css'),
  29. ),
  30. ),
  31. );
  32. return $editor;
  33. }
  34. /**
  35. * Detect editor version.
  36. *
  37. * @param $editor
  38. * An array containing editor properties as returned from hook_editor().
  39. *
  40. * @return
  41. * The installed editor version.
  42. */
  43. function wysiwyg_openwysiwyg_version($editor) {
  44. // 'library path' has '/scripts' appended already.
  45. $changelog = $editor['editor path'] . '/changelog';
  46. if (!file_exists($changelog)) {
  47. return;
  48. }
  49. $changelog = fopen($changelog, 'r');
  50. $line = fgets($changelog, 20);
  51. if (preg_match('@v([\d\.]+)@', $line, $version)) {
  52. fclose($changelog);
  53. return $version[1];
  54. }
  55. fclose($changelog);
  56. }
  57. /**
  58. * Determine available editor themes or check/reset a given one.
  59. *
  60. * @param $editor
  61. * A processed hook_editor() array of editor properties.
  62. * @param $profile
  63. * A wysiwyg editor profile.
  64. *
  65. * @return
  66. * An array of theme names. The first returned name should be the default
  67. * theme name.
  68. */
  69. function wysiwyg_openwysiwyg_themes($editor, $profile) {
  70. return array('default');
  71. }
  72. /**
  73. * Return runtime editor settings for a given wysiwyg profile.
  74. *
  75. * @param $editor
  76. * A processed hook_editor() array of editor properties.
  77. * @param $config
  78. * An array containing wysiwyg editor profile settings.
  79. * @param $theme
  80. * The name of a theme/GUI/skin to use.
  81. *
  82. * @return
  83. * A settings array to be populated in
  84. * Drupal.settings.wysiwyg.configs.{editor}
  85. */
  86. function wysiwyg_openwysiwyg_settings($editor, $config, $theme) {
  87. $settings = array(
  88. 'path' => base_path() . $editor['editor path'] . '/',
  89. 'Width' => '100%',
  90. );
  91. if (isset($config['path_loc']) && $config['path_loc'] == 'none') {
  92. $settings['StatusBarEnabled'] = FALSE;
  93. }
  94. if (isset($config['css_setting'])) {
  95. if ($config['css_setting'] == 'theme') {
  96. $settings['CSSFile'] = reset(wysiwyg_get_css());
  97. }
  98. elseif ($config['css_setting'] == 'self' && isset($config['css_path'])) {
  99. $settings['CSSFile'] = strtr($config['css_path'], array('%b' => base_path(), '%t' => drupal_get_path('theme', variable_get('theme_default', NULL))));
  100. }
  101. }
  102. $settings['Toolbar'] = array();
  103. if (!empty($config['buttons'])) {
  104. $plugins = wysiwyg_get_plugins($editor['name']);
  105. foreach ($config['buttons'] as $plugin => $buttons) {
  106. foreach ($buttons as $button => $enabled) {
  107. foreach (array('buttons', 'extensions') as $type) {
  108. // Skip unavailable plugins.
  109. if (!isset($plugins[$plugin][$type][$button])) {
  110. continue;
  111. }
  112. // Add buttons.
  113. if ($type == 'buttons') {
  114. $settings['Toolbar'][0][] = $button;
  115. }
  116. }
  117. }
  118. }
  119. }
  120. // @todo
  121. // if (isset($config['block_formats'])) {
  122. // $settings['DropDowns']['headings']['elements'] = explode(',', $config['block_formats']);
  123. // }
  124. return $settings;
  125. }
  126. /**
  127. * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
  128. */
  129. function wysiwyg_openwysiwyg_plugins($editor) {
  130. $plugins = array(
  131. 'default' => array(
  132. 'buttons' => array(
  133. 'bold' => t('Bold'), 'italic' => t('Italic'), 'underline' => t('Underline'),
  134. 'strikethrough' => t('Strike-through'),
  135. 'justifyleft' => t('Align left'), 'justifycenter' => t('Align center'), 'justifyright' => t('Align right'), 'justifyfull' => t('Justify'),
  136. 'unorderedlist' => t('Bullet list'), 'orderedlist' => t('Numbered list'),
  137. 'outdent' => t('Outdent'), 'indent' => t('Indent'),
  138. 'undo' => t('Undo'), 'redo' => t('Redo'),
  139. 'createlink' => t('Link'),
  140. 'insertimage' => t('Image'),
  141. 'cleanup' => t('Clean-up'),
  142. 'forecolor' => t('Forecolor'), 'backcolor' => t('Backcolor'),
  143. 'superscript' => t('Sup'), 'subscript' => t('Sub'),
  144. 'blockquote' => t('Blockquote'), 'viewSource' => t('Source code'),
  145. 'hr' => t('Horizontal rule'),
  146. 'cut' => t('Cut'), 'copy' => t('Copy'), 'paste' => t('Paste'),
  147. 'visualaid' => t('Visual aid'),
  148. 'removeformat' => t('Remove format'),
  149. 'charmap' => t('Character map'),
  150. 'headings' => t('HTML block format'), 'font' => t('Font'), 'fontsize' => t('Font size'),
  151. 'maximize' => t('Fullscreen'),
  152. 'preview' => t('Preview'),
  153. 'print' => t('Print'),
  154. 'inserttable' => t('Table'),
  155. 'help' => t('Help'),
  156. ),
  157. 'internal' => TRUE,
  158. ),
  159. );
  160. return $plugins;
  161. }