epiceditor.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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://oscargodson.github.com/EpicEditor',
  13. 'download url' => 'http://oscargodson.github.com/EpicEditor/docs/downloads/EpicEditor-v0.1.1.zip',
  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. 'version callback' => 'wysiwyg_epiceditor_version',
  25. 'themes callback' => 'wysiwyg_epiceditor_themes',
  26. 'settings callback' => 'wysiwyg_epiceditor_settings',
  27. 'versions' => array(
  28. '0.1.1' => array(
  29. 'js files' => array('epiceditor.js'),
  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_epiceditor_version($editor) {
  45. $library = $editor['library path'] . '/js/epiceditor.js';
  46. if (!file_exists($library)) {
  47. return;
  48. }
  49. // @todo Do not load the entire file; use fgets() instead.
  50. $library = file_get_contents($library, 'r');
  51. $version = preg_match('%EpicEditor\.version = \'(.*)\'\;%', $library, $matches);
  52. if (!isset($matches[1])) {
  53. return;
  54. }
  55. return $matches[1];
  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_epiceditor_themes($editor, $profile) {
  70. return array('epic-dark', 'epic-light');
  71. // @todo Use the preview themes somewhere.
  72. //return array('preview-dark', 'github');
  73. }
  74. /**
  75. * Return runtime editor settings for a given wysiwyg profile.
  76. *
  77. * @param $editor
  78. * A processed hook_editor() array of editor properties.
  79. * @param $config
  80. * An array containing wysiwyg editor profile settings.
  81. * @param $theme
  82. * The name of a theme/GUI/skin to use.
  83. *
  84. * @return
  85. * A settings array to be populated in
  86. * Drupal.settings.wysiwyg.configs.{editor}
  87. */
  88. function wysiwyg_epiceditor_settings($editor, $config, $theme) {
  89. $settings = array(
  90. 'basePath' => base_path() . $editor['library path'],
  91. 'clientSideStorage' => FALSE,
  92. 'theme' => $theme,
  93. //'preview_theme' => '',
  94. );
  95. return $settings;
  96. }