epiceditor.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * @file
  4. * Editor integration functions for EpicEditor.
  5. */
  6. /**
  7. * Plugin implementation of hook_editor().
  8. */
  9. function wysiwyg_epiceditor_editor() {
  10. $editor['epiceditor'] = array(
  11. 'title' => 'EpicEditor',
  12. 'vendor url' => 'http://epiceditor.com',
  13. 'download url' => 'http://epiceditor.com',
  14. 'libraries' => array(
  15. '' => array(
  16. 'title' => 'Minified',
  17. 'files' => array('js/epiceditor.min.js'),
  18. ),
  19. 'src' => array(
  20. 'title' => 'Source',
  21. 'files' => array('js/epiceditor.js'),
  22. ),
  23. ),
  24. 'verified version range' => array('0.1.1', '0.2.2'),
  25. 'version callback' => 'wysiwyg_epiceditor_version',
  26. 'themes callback' => 'wysiwyg_epiceditor_themes',
  27. 'settings form callback' => 'wysiwyg_epiceditor_settings_form',
  28. 'settings callback' => 'wysiwyg_epiceditor_settings',
  29. 'versions' => array(
  30. '0.1.1' => array(
  31. 'js files' => array('epiceditor.js'),
  32. ),
  33. ),
  34. );
  35. return $editor;
  36. }
  37. /**
  38. * Detect editor version.
  39. *
  40. * @param $editor
  41. * An array containing editor properties as returned from hook_editor().
  42. *
  43. * @return
  44. * The installed editor version.
  45. */
  46. function wysiwyg_epiceditor_version($editor) {
  47. $library = $editor['library path'] . '/js/epiceditor.js';
  48. if (!file_exists($library)) {
  49. return;
  50. }
  51. // @todo Do not load the entire file; use fgets() instead.
  52. $library = file_get_contents($library, 'r');
  53. $version = preg_match('%EpicEditor\.version = \'(.*)\'\;%', $library, $matches);
  54. if (!isset($matches[1])) {
  55. return;
  56. }
  57. return $matches[1];
  58. }
  59. /**
  60. * Determine available editor themes or check/reset a given one.
  61. *
  62. * @param $editor
  63. * A processed hook_editor() array of editor properties.
  64. * @param $profile
  65. * A wysiwyg editor profile.
  66. *
  67. * @return
  68. * An array of theme names. The first returned name should be the default
  69. * theme name.
  70. */
  71. function wysiwyg_epiceditor_themes($editor, $profile) {
  72. return array('epic-dark', 'epic-light');
  73. // @todo Use the preview themes somewhere.
  74. //return array('preview-dark', 'github');
  75. }
  76. /**
  77. * Enhances the editor profile settings form for EpicEditor.
  78. *
  79. */
  80. function wysiwyg_epiceditor_settings_form(&$form, &$form_state) {
  81. $form['buttons']['#access'] = FALSE;
  82. $form['basic']['language']['#access'] = FALSE;
  83. $form['css']['#access'] = FALSE;
  84. }
  85. /**
  86. * Return runtime editor settings for a given wysiwyg profile.
  87. *
  88. * @param $editor
  89. * A processed hook_editor() array of editor properties.
  90. * @param $config
  91. * An array containing wysiwyg editor profile settings.
  92. * @param $theme
  93. * The name of a theme/GUI/skin to use.
  94. *
  95. * @return
  96. * A settings array to be populated in
  97. * Drupal.settings.wysiwyg.configs.{editor}
  98. */
  99. function wysiwyg_epiceditor_settings($editor, $config, $theme) {
  100. $settings = array(
  101. 'basePath' => base_path() . $editor['library path'],
  102. 'clientSideStorage' => FALSE,
  103. 'theme' => $theme,
  104. //'preview_theme' => '',
  105. );
  106. return $settings;
  107. }