#273408 by quicksketch: Added blockquote button for TinyMCE 3.
[project/wysiwyg.git] / wysiwyg_editor.install
1 <?php
2 // $Id$
3
4
5 /**
6 * Implementation of hook_schema().
7 */
8 function wysiwyg_editor_schema() {
9 $schema = array();
10 $schema['wysiwyg_editor_profile'] = array(
11 'description' => t('Stores Wysiwyg Editor profiles.'),
12 'fields' => array(
13 'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
14 'settings' => array('type' => 'text', 'size' => 'normal'),
15 'plugin_count' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
16 ),
17 'primary key' => array('name'),
18 );
19 $schema['wysiwyg_editor_role'] = array(
20 'description' => t('Stores user role access permissions for Wysiwyg Editor profiles.'),
21 'fields' => array(
22 'name' => array('type' => 'varchar', 'length' => 128, 'not null' => TRUE, 'default' => ''),
23 'rid' => array('type' => 'int', 'size' => 'tiny', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0),
24 ),
25 'primary key' => array('name', 'rid'),
26 );
27 return $schema;
28 }
29
30 /**
31 * Implementation of hook_install().
32 */
33 function wysiwyg_editor_install() {
34 drupal_install_schema('wysiwyg_editor');
35 // Import data from old editor modules.
36 wysiwyg_editor_migrate_tinymce();
37 }
38
39 /**
40 * Implementation of hook_uninstall()
41 */
42 function wysiwyg_editor_uninstall() {
43 drupal_uninstall_schema('wysiwyg_editor');
44 }
45
46 /**
47 * Migrate from TinyMCE.
48 */
49 function wysiwyg_editor_migrate_tinymce() {
50 if (db_table_exists('tinymce_settings')) {
51 $schema = db_result(db_query("SELECT schema_version FROM {system} WHERE name = 'tinymce'"));
52 if ($schema >= 1) {
53 // Import TinyMCE settings.
54 db_query('INSERT INTO {wysiwyg_editor_profile} (name, settings) SELECT name, settings FROM {tinymce_settings}');
55 // Import TinyMCE profile role assignments.
56 db_query('INSERT INTO {wysiwyg_editor_role} (name, rid) SELECT name, rid FROM {tinymce_role}');
57
58 // Disable TinyMCE module.
59 module_disable(array('tinymce'));
60
61 // Update configuration.
62 wysiwyg_editor_update_5001();
63 }
64 else {
65 drupal_set_message(t('To migrate your existing TinyMCE settings to Wysiwyg Editor, please update TinyMCE module to the latest official release, and re-install Wysiwyg Editor module.'));
66 }
67 }
68 }
69
70 /**
71 * Convert buttons and plugins into associative array and fix plugin count for old profiles.
72 *
73 * Note: This update is required for wysiwyg_editor_migrate_tinymce().
74 */
75 function wysiwyg_editor_update_5001() {
76 $ret = array();
77 $profiles = db_query("SELECT name, settings, plugin_count FROM {wysiwyg_editor_profile}");
78 while ($profile = db_fetch_array($profiles)) {
79 $settings = unserialize($profile['settings']);
80 if (isset($settings['form_id'])) {
81 $old_buttons = (isset($settings['buttons']) ? $settings['buttons'] : array());
82 $settings['buttons'] = array();
83 $plugin_count = 0;
84 foreach ($old_buttons as $old_button => $enabled) {
85 list($plugin, $button) = explode('-', $old_button, 2);
86 $settings['buttons'][$plugin][$button] = 1;
87 $plugin_count++;
88 }
89 // We can't use update_sql() here because of curly braces in serialized
90 // array.
91 db_query("UPDATE {wysiwyg_editor_profile} SET settings = '%s', plugin_count = %d WHERE name = '%s'", serialize($settings), $plugin_count, $profile['name']);
92 }
93 }
94 return $ret;
95 }
96
97 /**
98 * Add editor key to wysiwyg profiles.
99 */
100 function wysiwyg_editor_update_6002() {
101 $ret = array();
102 $profiles = db_query("SELECT name, settings FROM {wysiwyg_editor_profile}");
103 while ($profile = db_fetch_object($profiles)) {
104 $settings = unserialize($profile->settings);
105 if (!isset($settings['editor'])) {
106 $settings['editor'] = 'tinymce';
107 // We can't use update_sql() here because of curly braces in serialized
108 // array.
109 db_query("UPDATE {wysiwyg_editor_profile} SET settings = '%s' WHERE name = '%s'", serialize($settings), $profile->name);
110 }
111 }
112 return $ret;
113 }
114