markitup.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * @file
  4. * Editor integration functions for markItUp.
  5. */
  6. /**
  7. * Plugin implementation of hook_editor().
  8. */
  9. function wysiwyg_markitup_editor() {
  10. $editor['markitup'] = array(
  11. 'title' => 'markItUp',
  12. 'vendor url' => 'http://markitup.jaysalvat.com',
  13. 'download url' => 'http://markitup.jaysalvat.com/downloads',
  14. 'library path' => wysiwyg_get_path('markitup'),
  15. 'libraries' => array(
  16. '' => array(
  17. 'title' => 'Source',
  18. 'files' => array('markitup/jquery.markitup.js'),
  19. ),
  20. 'pack' => array(
  21. 'title' => 'Packed',
  22. 'files' => array('markitup/jquery.markitup.pack.js'),
  23. ),
  24. ),
  25. 'version callback' => 'wysiwyg_markitup_version',
  26. 'themes callback' => 'wysiwyg_markitup_themes',
  27. 'settings callback' => 'wysiwyg_markitup_settings',
  28. 'plugin callback' => 'wysiwyg_markitup_plugins',
  29. 'versions' => array(
  30. '1.1.5' => array(
  31. 'js files' => array('markitup.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_markitup_version($editor) {
  47. // Changelog was in markitup/markitup/readme.txt <= 1.1.5.
  48. $changelog = $editor['library path'] . '/markitup/readme.txt';
  49. if (!file_exists($changelog)) {
  50. // Changelog was moved up to markitup/CHANGELOG.md after 1.1.5.
  51. $changelog = $editor['library path'] . '/CHANGELOG.md';
  52. if (!file_exists($changelog)) {
  53. return;
  54. }
  55. }
  56. $changelog = fopen($changelog, 'r');
  57. $line = fgets($changelog);
  58. if (preg_match('@([0-9\.]+)@', $line, $version)) {
  59. fclose($changelog);
  60. return $version[1];
  61. }
  62. fclose($changelog);
  63. }
  64. /**
  65. * Determine available editor themes or check/reset a given one.
  66. *
  67. * @param $editor
  68. * A processed hook_editor() array of editor properties.
  69. * @param $profile
  70. * A wysiwyg editor profile.
  71. *
  72. * @return
  73. * An array of theme names. The first returned name should be the default
  74. * theme name.
  75. */
  76. function wysiwyg_markitup_themes($editor, $profile) {
  77. return array('simple', 'markitup');
  78. }
  79. /**
  80. * Return runtime editor settings for a given wysiwyg profile.
  81. *
  82. * @param $editor
  83. * A processed hook_editor() array of editor properties.
  84. * @param $config
  85. * An array containing wysiwyg editor profile settings.
  86. * @param $theme
  87. * The name of a theme/GUI/skin to use.
  88. *
  89. * @return
  90. * A settings array to be populated in
  91. * Drupal.settings.wysiwyg.configs.{editor}
  92. */
  93. function wysiwyg_markitup_settings($editor, $config, $theme) {
  94. drupal_add_css($editor['library path'] . '/markitup/skins/' . $theme . '/style.css', array(
  95. // Specify an alternate basename; otherwise, style.css would override a
  96. // commonly used style.css file of the theme.
  97. 'basename' => 'markitup.' . $theme . '.style.css',
  98. 'group' => CSS_THEME,
  99. ));
  100. $settings = array(
  101. 'root' => base_path() . $editor['library path'] . '/markitup/',
  102. 'nameSpace' => $theme,
  103. 'markupSet' => array(),
  104. );
  105. // Add configured buttons or all available.
  106. $default_buttons = array(
  107. 'bold' => array(
  108. 'name' => t('Bold'),
  109. 'className' => 'markitup-bold',
  110. 'key' => 'B',
  111. 'openWith' => '(!(<strong>|!|<b>)!)',
  112. 'closeWith' => '(!(</strong>|!|</b>)!)',
  113. ),
  114. 'italic' => array(
  115. 'name' => t('Italic'),
  116. 'className' => 'markitup-italic',
  117. 'key' => 'I',
  118. 'openWith' => '(!(<em>|!|<i>)!)',
  119. 'closeWith' => '(!(</em>|!|</i>)!)',
  120. ),
  121. 'stroke' => array(
  122. 'name' => t('Strike-through'),
  123. 'className' => 'markitup-stroke',
  124. 'key' => 'S',
  125. 'openWith' => '<del>',
  126. 'closeWith' => '</del>',
  127. ),
  128. 'image' => array(
  129. 'name' => t('Image'),
  130. 'className' => 'markitup-image',
  131. 'key' => 'P',
  132. 'replaceWith' => '<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />',
  133. ),
  134. 'link' => array(
  135. 'name' => t('Link'),
  136. 'className' => 'markitup-link',
  137. 'key' => 'K',
  138. 'openWith' => '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>',
  139. 'closeWith' => '</a>',
  140. 'placeHolder' => 'Your text to link...',
  141. ),
  142. // @todo
  143. // 'cleanup' => array('name' => t('Clean-up'), 'className' => 'markitup-cleanup', 'replaceWith' => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }'),
  144. 'preview' => array(
  145. 'name' => t('Preview'),
  146. 'className' => 'markitup-preview',
  147. 'call' => 'preview',
  148. ),
  149. );
  150. $settings['markupSet'] = array();
  151. if (!empty($config['buttons'])) {
  152. foreach ($config['buttons'] as $plugin) {
  153. foreach ($plugin as $button => $enabled) {
  154. if (isset($default_buttons[$button])) {
  155. $settings['markupSet'][$button] = $default_buttons[$button];
  156. }
  157. }
  158. }
  159. }
  160. return $settings;
  161. }
  162. /**
  163. * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
  164. */
  165. function wysiwyg_markitup_plugins($editor) {
  166. return array(
  167. 'default' => array(
  168. 'buttons' => array(
  169. 'bold' => t('Bold'), 'italic' => t('Italic'),
  170. 'stroke' => t('Strike-through'),
  171. 'link' => t('Link'),
  172. 'image' => t('Image'),
  173. // 'cleanup' => t('Clean-up'),
  174. 'preview' => t('Preview'),
  175. ),
  176. 'internal' => TRUE,
  177. ),
  178. );
  179. }