markitup.inc 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. 'install note callback' => 'wysiwyg_markitup_install_note',
  26. 'verified version range' => array('1.1.5', '1.1.14'),
  27. 'version callback' => 'wysiwyg_markitup_version',
  28. 'themes callback' => 'wysiwyg_markitup_themes',
  29. 'settings form callback' => 'wysiwyg_markitup_settings_form',
  30. 'settings callback' => 'wysiwyg_markitup_settings',
  31. 'plugin callback' => '_wysiwyg_markitup_plugins',
  32. 'versions' => array(
  33. '1.1.5' => array(
  34. 'js files' => array('markitup.js'),
  35. ),
  36. ),
  37. );
  38. return $editor;
  39. }
  40. /**
  41. * Return an install note.
  42. */
  43. function wysiwyg_markitup_install_note() {
  44. return '<p class="warning">' . t('Only rename the extracted folder from "latest" to "markitup", no other changes needed.') . '</p>';
  45. }
  46. /**
  47. * Detect editor version.
  48. *
  49. * @param $editor
  50. * An array containing editor properties as returned from hook_editor().
  51. *
  52. * @return
  53. * The installed editor version.
  54. */
  55. function wysiwyg_markitup_version($editor) {
  56. // Changelog was in markitup/markitup/readme.txt <= 1.1.5.
  57. $changelog = $editor['library path'] . '/markitup/readme.txt';
  58. if (!file_exists($changelog)) {
  59. // Changelog was moved up to markitup/CHANGELOG.md after 1.1.5.
  60. $changelog = $editor['library path'] . '/CHANGELOG.md';
  61. if (!file_exists($changelog)) {
  62. return;
  63. }
  64. }
  65. $changelog = fopen($changelog, 'r');
  66. $line = fgets($changelog);
  67. if (preg_match('@([0-9\.]+)@', $line, $version)) {
  68. fclose($changelog);
  69. return $version[1];
  70. }
  71. fclose($changelog);
  72. }
  73. /**
  74. * Determine available editor themes or check/reset a given one.
  75. *
  76. * @param $editor
  77. * A processed hook_editor() array of editor properties.
  78. * @param $profile
  79. * A wysiwyg editor profile.
  80. *
  81. * @return
  82. * An array of theme names. The first returned name should be the default
  83. * theme name.
  84. */
  85. function wysiwyg_markitup_themes($editor, $profile) {
  86. return array('simple', 'markitup');
  87. }
  88. /**
  89. * Enhances the editor profile settings form for markItUp.
  90. */
  91. function wysiwyg_markitup_settings_form(&$form, &$form_state) {
  92. $form['basic']['language']['#access'] = FALSE;
  93. $form['css']['#access'] = FALSE;
  94. }
  95. /**
  96. * Return runtime editor settings for a given wysiwyg profile.
  97. *
  98. * @param $editor
  99. * A processed hook_editor() array of editor properties.
  100. * @param $config
  101. * An array containing wysiwyg editor profile settings.
  102. * @param $theme
  103. * The name of a theme/GUI/skin to use.
  104. *
  105. * @return
  106. * A settings array to be populated in
  107. * Drupal.settings.wysiwyg.configs.{editor}
  108. */
  109. function wysiwyg_markitup_settings($editor, $config, $theme) {
  110. drupal_add_css($editor['library path'] . '/markitup/skins/' . $theme . '/style.css', array(
  111. // Specify an alternate basename; otherwise, style.css would override a
  112. // commonly used style.css file of the theme.
  113. 'basename' => 'markitup.' . $theme . '.style.css',
  114. 'group' => CSS_THEME,
  115. ));
  116. $settings = array(
  117. 'root' => base_path() . $editor['library path'] . '/markitup/',
  118. 'nameSpace' => $theme,
  119. 'markupSet' => array(),
  120. );
  121. // Add configured buttons or all available.
  122. $default_buttons = array(
  123. 'bold' => array(
  124. 'name' => t('Bold'),
  125. 'className' => 'markitup-bold',
  126. 'key' => 'B',
  127. 'openWith' => '(!(<strong>|!|<b>)!)',
  128. 'closeWith' => '(!(</strong>|!|</b>)!)',
  129. ),
  130. 'italic' => array(
  131. 'name' => t('Italic'),
  132. 'className' => 'markitup-italic',
  133. 'key' => 'I',
  134. 'openWith' => '(!(<em>|!|<i>)!)',
  135. 'closeWith' => '(!(</em>|!|</i>)!)',
  136. ),
  137. 'stroke' => array(
  138. 'name' => t('Strike-through'),
  139. 'className' => 'markitup-stroke',
  140. 'key' => 'S',
  141. 'openWith' => '<del>',
  142. 'closeWith' => '</del>',
  143. ),
  144. 'image' => array(
  145. 'name' => t('Image'),
  146. 'className' => 'markitup-image',
  147. 'key' => 'P',
  148. 'replaceWith' => '<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />',
  149. ),
  150. 'link' => array(
  151. 'name' => t('Link'),
  152. 'className' => 'markitup-link',
  153. 'key' => 'K',
  154. 'openWith' => '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>',
  155. 'closeWith' => '</a>',
  156. 'placeHolder' => 'Your text to link...',
  157. ),
  158. // @todo
  159. // 'cleanup' => array('name' => t('Clean-up'), 'className' => 'markitup-cleanup', 'replaceWith' => 'function(markitup) { return markitup.selection.replace(/<(.*?)>/g, "") }'),
  160. 'preview' => array(
  161. 'name' => t('Preview'),
  162. 'className' => 'markitup-preview',
  163. 'call' => 'preview',
  164. ),
  165. );
  166. $settings['markupSet'] = array();
  167. if (!empty($config['buttons'])) {
  168. foreach ($config['buttons'] as $plugin) {
  169. foreach ($plugin as $button => $enabled) {
  170. if (isset($default_buttons[$button])) {
  171. $settings['markupSet'][$button] = $default_buttons[$button];
  172. }
  173. }
  174. }
  175. }
  176. return $settings;
  177. }
  178. /**
  179. * Return internal plugins for this editor; semi-implementation of hook_wysiwyg_plugin().
  180. */
  181. function _wysiwyg_markitup_plugins($editor) {
  182. return array(
  183. 'default' => array(
  184. 'buttons' => array(
  185. 'bold' => t('Bold'), 'italic' => t('Italic'),
  186. 'stroke' => t('Strike-through'),
  187. 'link' => t('Link'),
  188. 'image' => t('Image'),
  189. // 'cleanup' => t('Clean-up'),
  190. 'preview' => t('Preview'),
  191. ),
  192. 'internal' => TRUE,
  193. ),
  194. );
  195. }