PageRenderTime 61ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/wysiwyg/editors/openwysiwyg.inc

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