jwysiwyg.inc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * @file
  4. * Editor integration functions for jWYSIWYG.
  5. */
  6. /**
  7. * Plugin implementation of hook_editor().
  8. */
  9. function wysiwyg_jwysiwyg_editor() {
  10. $editor['jwysiwyg'] = array(
  11. 'title' => 'jWYSIWYG',
  12. 'vendor url' => 'http://github.com/akzhan/jwysiwyg',
  13. 'download url' => 'http://github.com/akzhan/jwysiwyg/tags',
  14. 'libraries' => array(
  15. '' => array(
  16. 'title' => 'Source',
  17. 'files' => array('jquery.wysiwyg.js'),
  18. ),
  19. ),
  20. 'verified version range' => array('0.5', '0.97'),
  21. 'version callback' => 'wysiwyg_jwysiwyg_version',
  22. 'settings form callback' => 'wysiwyg_jwysiwyg_settings_form',
  23. 'settings callback' => 'wysiwyg_jwysiwyg_settings',
  24. // @todo Wrong property; add separate properties for editor requisites.
  25. 'css path' => wysiwyg_get_path('jwysiwyg'),
  26. 'versions' => array(
  27. '0.97' => array(
  28. 'js files' => array('jwysiwyg.js'),
  29. 'css files' => array('jquery.wysiwyg.css'),
  30. ),
  31. ),
  32. );
  33. return $editor;
  34. }
  35. /**
  36. * Enhances the editor profile settings form for jWYSIWYG.
  37. */
  38. function wysiwyg_jwysiwyg_settings_form(&$form, &$form_state) {
  39. $form['buttons']['#access'] = FALSE;
  40. $form['basic']['language']['#access'] = FALSE;
  41. $form['css']['#access'] = FALSE;
  42. }
  43. /**
  44. * Return runtime editor settings for a given wysiwyg profile.
  45. *
  46. * @param $editor
  47. * A processed hook_editor() array of editor properties.
  48. * @param $config
  49. * An array containing wysiwyg editor profile settings.
  50. * @param $theme
  51. * The name of a theme/GUI/skin to use.
  52. *
  53. * @return
  54. * A settings array to be populated in
  55. * Drupal.settings.wysiwyg.configs.{editor}
  56. */
  57. function wysiwyg_jwysiwyg_settings($editor, $config, $theme) {
  58. $settings = array(
  59. 'initialContent' => '',
  60. );
  61. return $settings;
  62. }
  63. /**
  64. * Detect editor version.
  65. *
  66. * @param $editor
  67. * An array containing editor properties as returned from hook_editor().
  68. *
  69. * @return
  70. * The installed editor version.
  71. */
  72. function wysiwyg_jwysiwyg_version($editor) {
  73. $script = $editor['library path'] . '/jquery.wysiwyg.js';
  74. if (!file_exists($script)) {
  75. return;
  76. }
  77. $script = fopen($script, 'r');
  78. fgets($script);
  79. $line = fgets($script);
  80. if (preg_match('@([0-9\.]+)$@', $line, $version)) {
  81. fclose($script);
  82. return $version[1];
  83. }
  84. fclose($script);
  85. }