wysiwyg.install 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <?php
  2. /**
  3. * @file
  4. * Installation functions for Wysiwyg module.
  5. */
  6. /**
  7. * Implementation of hook_schema().
  8. */
  9. function wysiwyg_schema() {
  10. $schema['wysiwyg'] = array(
  11. 'description' => 'Stores Wysiwyg profiles.',
  12. 'fields' => array(
  13. 'format' => array(
  14. 'description' => 'The {filter_format}.format of the text format.',
  15. 'type' => 'varchar',
  16. 'length' => 255,
  17. // Primary keys are implicitly not null.
  18. 'not null' => TRUE,
  19. ),
  20. 'editor' => array(
  21. 'description' => 'Internal name of the editor attached to the text format.',
  22. 'type' => 'varchar',
  23. 'length' => 128,
  24. 'not null' => TRUE,
  25. 'default' => '',
  26. ),
  27. 'settings' => array(
  28. 'description' => 'Configuration settings for the editor.',
  29. 'type' => 'text',
  30. 'size' => 'normal',
  31. 'serialize' => TRUE,
  32. ),
  33. ),
  34. 'primary key' => array('format'),
  35. 'foreign keys' => array(
  36. 'format' => array(
  37. 'table' => 'filter_format',
  38. 'columns' => array('format' => 'format'),
  39. ),
  40. ),
  41. );
  42. $schema['wysiwyg_user'] = array(
  43. 'description' => 'Stores user preferences for wysiwyg profiles.',
  44. 'fields' => array(
  45. 'uid' => array(
  46. 'description' => 'The {users}.uid of the user.',
  47. 'type' => 'int',
  48. 'unsigned' => TRUE,
  49. 'not null' => TRUE,
  50. 'default' => 0,
  51. ),
  52. 'format' => array(
  53. 'description' => 'The {filter_format}.format of the text format.',
  54. 'type' => 'varchar',
  55. 'length' => 255,
  56. 'not null' => TRUE,
  57. ),
  58. 'status' => array(
  59. 'description' => 'Boolean indicating whether the format is enabled by default.',
  60. 'type' => 'int',
  61. 'unsigned' => TRUE,
  62. 'not null' => TRUE,
  63. 'default' => 0,
  64. 'size' => 'tiny',
  65. ),
  66. ),
  67. 'primary key' => array('uid', 'format'),
  68. 'indexes' => array(
  69. 'uid' => array('uid'),
  70. ),
  71. 'foreign keys' => array(
  72. 'uid' => array(
  73. 'table' => 'users',
  74. 'columns' => array('uid' => 'uid'),
  75. ),
  76. 'format' => array(
  77. 'table' => 'filter_format',
  78. 'columns' => array('format' => 'format'),
  79. ),
  80. ),
  81. );
  82. return $schema;
  83. }
  84. /**
  85. * Implementation of hook_enable().
  86. */
  87. function wysiwyg_enable() {
  88. // Disable conflicting, obsolete editor integration modules whenever this
  89. // module is enabled. This is crude, but the only way to ensure no conflicts.
  90. module_disable(array(
  91. 'ckeditor',
  92. 'editarea',
  93. 'editonpro',
  94. 'editor',
  95. 'fckeditor',
  96. 'freerte',
  97. 'htmlarea',
  98. 'htmlbox',
  99. 'jwysiwyg',
  100. 'markitup',
  101. 'nicedit',
  102. 'openwysiwyg',
  103. 'pegoeditor',
  104. 'quicktext',
  105. 'tinymce',
  106. 'tinymce_autoconf',
  107. 'tinytinymce',
  108. 'whizzywig',
  109. 'widgeditor',
  110. 'wymeditor',
  111. 'xstandard',
  112. 'yui_editor',
  113. ));
  114. }
  115. /**
  116. * Implements hook_update_dependencies().
  117. */
  118. function wysiwyg_update_dependencies() {
  119. // Ensure that format columns are only changed after Filter module has changed
  120. // the primary records.
  121. $dependencies['wysiwyg'][7000] = array(
  122. 'filter' => 7010,
  123. );
  124. return $dependencies;
  125. }
  126. /**
  127. * Implements hook_update_last_removed().
  128. */
  129. function wysiwyg_update_last_removed() {
  130. // Users should upgrade to the latest 6.x-2.x release before upgrading to
  131. // 7.x-2.x. Some 7xxx functions duplicate work from 6xxx functions in 6.x-2.x
  132. // because both branches are supported in parallel, but changes will only be
  133. // applied once anyway because of safeguards.
  134. return 6202;
  135. }
  136. /**
  137. * Change {wysiwyg}.format into a string.
  138. */
  139. function wysiwyg_update_7000() {
  140. db_drop_primary_key('wysiwyg');
  141. db_change_field('wysiwyg', 'format', 'format', array(
  142. 'type' => 'varchar',
  143. 'length' => 255,
  144. 'not null' => TRUE,
  145. ));
  146. db_add_primary_key('wysiwyg', array('format'));
  147. }
  148. /**
  149. * Create the {wysiwyg_user} table.
  150. */
  151. function wysiwyg_update_7200() {
  152. if (!db_table_exists('wysiwyg_user')) {
  153. db_create_table('wysiwyg_user', array(
  154. 'description' => 'Stores user preferences for wysiwyg profiles.',
  155. 'fields' => array(
  156. 'uid' => array(
  157. 'description' => 'The {users}.uid of the user.',
  158. 'type' => 'int',
  159. 'unsigned' => TRUE,
  160. 'not null' => TRUE,
  161. 'default' => 0,
  162. ),
  163. 'format' => array(
  164. 'description' => 'The {filter_format}.format of the text format.',
  165. 'type' => 'varchar',
  166. 'length' => 255,
  167. 'not null' => FALSE,
  168. ),
  169. 'status' => array(
  170. 'description' => 'Boolean indicating whether the format is enabled by default.',
  171. 'type' => 'int',
  172. 'unsigned' => TRUE,
  173. 'not null' => TRUE,
  174. 'default' => 0,
  175. 'size' => 'tiny',
  176. ),
  177. ),
  178. 'indexes' => array(
  179. 'uid' => array('uid'),
  180. 'format' => array('format'),
  181. ),
  182. 'foreign keys' => array(
  183. 'uid' => array(
  184. 'table' => 'users',
  185. 'columns' => array('uid' => 'uid'),
  186. ),
  187. 'format' => array(
  188. 'table' => 'filter_format',
  189. 'columns' => array('format' => 'format'),
  190. ),
  191. ),
  192. ));
  193. }
  194. else {
  195. db_change_field('wysiwyg_user', 'format', 'format', array(
  196. 'description' => 'The {filter_format}.format of the text format.',
  197. 'type' => 'varchar',
  198. 'length' => 255,
  199. 'not null' => FALSE,
  200. ));
  201. }
  202. }
  203. /**
  204. * Update enabled font plugin buttons to default plugin in TinyMCE profiles.
  205. */
  206. function wysiwyg_update_7201() {
  207. $query = db_select('wysiwyg', 'w')
  208. ->fields('w', array('format', 'settings'))
  209. ->condition('editor', 'tinymce');
  210. foreach ($query->execute() as $profile) {
  211. $settings = unserialize($profile->settings);
  212. // Move enabled 'font' buttons into 'default' plugin buttons.
  213. $changed = FALSE;
  214. foreach (array('formatselect', 'fontselect', 'fontsizeselect', 'styleselect') as $button) {
  215. if (isset($settings['buttons']['font'][$button])) {
  216. $settings['buttons']['default'][$button] = $settings['buttons']['font'][$button];
  217. unset($settings['buttons']['font'][$button]);
  218. $changed = TRUE;
  219. }
  220. }
  221. if ($changed) {
  222. db_update('wysiwyg')
  223. ->condition('format', $profile->format)
  224. ->fields(array(
  225. 'settings' => serialize($settings),
  226. ))
  227. ->execute();
  228. }
  229. }
  230. }
  231. /**
  232. * Update internal names of settings.
  233. */
  234. function wysiwyg_update_7202() {
  235. $query = db_select('wysiwyg', 'w')
  236. ->fields('w', array('format', 'editor', 'settings'));
  237. foreach ($query->execute() as $profile) {
  238. $settings = unserialize($profile->settings);
  239. $changed = FALSE;
  240. switch ($profile->editor) {
  241. case 'tinymce':
  242. if (isset($settings['path_loc'])) {
  243. $settings['theme_advanced_statusbar_location'] = $settings['path_loc'];
  244. unset($settings['path_loc']);
  245. $changed = TRUE;
  246. }
  247. if (isset($settings['toolbar_loc'])) {
  248. $settings['theme_advanced_toolbar_location'] = $settings['toolbar_loc'];
  249. unset($settings['toolbar_loc']);
  250. $changed = TRUE;
  251. }
  252. if (isset($settings['toolbar_align'])) {
  253. $settings['theme_advanced_toolbar_align'] = $settings['toolbar_align'];
  254. unset($settings['toolbar_align']);
  255. $changed = TRUE;
  256. }
  257. if (isset($settings['block_formats'])) {
  258. $settings['theme_advanced_blockformats'] = $settings['block_formats'];
  259. unset($settings['block_formats']);
  260. $changed = TRUE;
  261. }
  262. if (isset($settings['css_classes'])) {
  263. $settings['theme_advanced_styles'] = $settings['css_classes'];
  264. unset($settings['css_classes']);
  265. $changed = TRUE;
  266. }
  267. if (isset($settings['resizing'])) {
  268. $settings['theme_advanced_resizing'] = $settings['resizing'];
  269. unset($settings['resizing']);
  270. $changed = TRUE;
  271. }
  272. break;
  273. case 'ckeditor':
  274. if (isset($settings['apply_source_formatting'])) {
  275. $settings['simple_source_formatting'] = $settings['apply_source_formatting'];
  276. unset($settings['apply_source_formatting']);
  277. $changed = TRUE;
  278. }
  279. if (isset($settings['resizing'])) {
  280. $settings['resize_enabled'] = $settings['resizing'];
  281. unset($settings['resizing']);
  282. $changed = TRUE;
  283. }
  284. if (isset($settings['toolbar_loc'])) {
  285. $settings['toolbarLocation'] = $settings['toolbar_loc'];
  286. unset($settings['toolbar_loc']);
  287. $changed = TRUE;
  288. }
  289. if (isset($settings['paste_auto_cleanup_on_paste'])) {
  290. $settings['forcePasteAsPlainText'] = $settings['paste_auto_cleanup_on_paste'];
  291. unset($settings['paste_auto_cleanup_on_paste']);
  292. $changed = TRUE;
  293. }
  294. if (isset($settings['css_classes'])) {
  295. $settings['stylesSet'] = $settings['css_classes'];
  296. unset($settings['css_classes']);
  297. $changed = TRUE;
  298. }
  299. break;
  300. case 'fckeditor':
  301. if (isset($settings['apply_source_formatting'])) {
  302. $settings['FormatSource'] = $settings['FormatOutput'] = $settings['apply_source_formatting'];
  303. unset($settings['apply_source_formatting']);
  304. $changed = TRUE;
  305. }
  306. if (isset($settings['paste_auto_cleanup_on_paste'])) {
  307. $settings['ForcePasteAsPlainText'] = $settings['paste_auto_cleanup_on_paste'];
  308. unset($settings['paste_auto_cleanup_on_paste']);
  309. $changed = TRUE;
  310. }
  311. if (isset($settings['block_formats'])) {
  312. $settings['FontFormats'] = strtr($settings['block_formats'], array(',' => ';'));
  313. unset($settings['block_formats']);
  314. $changed = TRUE;
  315. }
  316. break;
  317. case 'yui':
  318. // The resizing setting is triggering autoHeight instead of resize.
  319. if (isset($settings['resizing'])) {
  320. $settings['autoHeight'] = $settings['resizing'];
  321. unset($settings['resizing']);
  322. $changed = TRUE;
  323. }
  324. break;
  325. case 'openwysiwyg':
  326. if (isset($settings['path_loc'])) {
  327. $settings['StatusBarEnabled'] = ($settings['path_loc'] != 'none' );
  328. unset($settings['path_loc']);
  329. $changed = TRUE;
  330. }
  331. break;
  332. default:
  333. // Do not touch any other profiles since the extra settings won't hurt.
  334. }
  335. if ($changed) {
  336. db_update('wysiwyg')
  337. ->condition('format', $profile->format)
  338. ->fields(array(
  339. 'settings' => serialize($settings),
  340. ))
  341. ->execute();
  342. }
  343. }
  344. }
  345. /**
  346. * Add primary index to {wysiwyg_user}.
  347. */
  348. function wysiwyg_update_7203() {
  349. db_drop_index('wysiwyg_user', 'uid');
  350. db_drop_index('wysiwyg_user', 'format');
  351. db_change_field('wysiwyg_user', 'format', 'format',
  352. array(
  353. 'type' => 'varchar',
  354. 'length' => 255,
  355. 'not null' => TRUE,
  356. ),
  357. array(
  358. 'primary key' => array('uid', 'format'),
  359. 'indexes' => array(
  360. 'uid' => array('uid'),
  361. ),
  362. )
  363. );
  364. }
  365. /**
  366. * Remove empty editor profiles and update existing profiles.
  367. */
  368. function wysiwyg_update_7204() {
  369. // Remove unused profiles.
  370. $query = db_delete('wysiwyg')
  371. ->condition('editor', '')
  372. ->execute();
  373. $query = db_select('wysiwyg', 'w')
  374. ->fields('w', array('format', 'editor', 'settings'));
  375. foreach ($query->execute() as $profile) {
  376. // Clear the editing caches.
  377. if (module_exists('ctools')) {
  378. ctools_include('object-cache');
  379. ctools_object_cache_clear_all('wysiwyg_profile', 'format' . $profile->format);
  380. }
  381. cache_clear_all('wysiwyg_profile:format' . $profile->format, 'cache');
  382. // Move profile state to its own section.
  383. $settings = unserialize($profile->settings);
  384. if (!empty($settings['_profile_preferences'])) {
  385. // Skip in case of re-run.
  386. continue;
  387. }
  388. $preferences = array(
  389. 'add_to_summaries' => $settings['add_to_summaries'],
  390. 'default' => $settings['default'],
  391. 'show_toggle' => $settings['show_toggle'],
  392. 'user_choose' => $settings['user_choose'],
  393. 'version' => NULL,
  394. );
  395. unset($settings['add_to_summaries'], $settings['default'], $settings['show_toggle'], $settings['user_choose']);
  396. if (!empty($settings['library'])) {
  397. $prefereces['library'] = $settings['library'];
  398. unset($settings['library']);
  399. }
  400. $editor = wysiwyg_get_editor($profile->editor);
  401. if ($editor['installed']) {
  402. $preferences['version'] = $editor['installed version'];
  403. }
  404. $settings['_profile_preferences'] = $preferences;
  405. db_update('wysiwyg')
  406. ->condition('format', $profile->format)
  407. ->fields(array(
  408. 'settings' => serialize($settings),
  409. ))
  410. ->execute();
  411. }
  412. wysiwyg_profile_cache_clear();
  413. }