1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Install, update and uninstall functions for the Media WYSIWYG module.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Implements hook_schema().
|
10
|
*/
|
11
|
function media_wysiwyg_schema() {
|
12
|
$schema['media_restrict_wysiwyg'] = array(
|
13
|
'description' => 'Stores media displays restricted in wysiwyg.',
|
14
|
'fields' => array(
|
15
|
'type' => array(
|
16
|
'description' => 'The machine name of the file type.',
|
17
|
'type' => 'varchar',
|
18
|
'length' => 255,
|
19
|
'not null' => TRUE,
|
20
|
'default' => '',
|
21
|
),
|
22
|
'display' => array(
|
23
|
'description' => 'The restricted display.',
|
24
|
'type' => 'varchar',
|
25
|
'length' => '255',
|
26
|
'not null' => TRUE,
|
27
|
'default' => '',
|
28
|
),
|
29
|
),
|
30
|
);
|
31
|
$schema['media_view_mode_wysiwyg'] = array(
|
32
|
'description' => 'Maps WYSIWYG view modes to file types.',
|
33
|
'fields' => array(
|
34
|
'type' => array(
|
35
|
'description' => 'The machine name of the file type.',
|
36
|
'type' => 'varchar',
|
37
|
'length' => 255,
|
38
|
'not null' => TRUE,
|
39
|
'default' => '',
|
40
|
),
|
41
|
'view_mode' => array(
|
42
|
'description' => 'WYSIWYG view mode mapped to this file type.',
|
43
|
'type' => 'varchar',
|
44
|
'length' => 255,
|
45
|
'not null' => TRUE,
|
46
|
'default' => '',
|
47
|
),
|
48
|
|
49
|
),
|
50
|
);
|
51
|
return $schema;
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* Implements hook_install().
|
56
|
*/
|
57
|
function media_wysiwyg_install() {
|
58
|
media_wysiwyg_update_7204();
|
59
|
|
60
|
// Start off with the alignment feature enabled.
|
61
|
variable_set('media_wysiwyg_alignment', TRUE);
|
62
|
}
|
63
|
|
64
|
/**
|
65
|
* Implements hook_uninstall().
|
66
|
*/
|
67
|
function media_wysiwyg_uninstall() {
|
68
|
// Remove variables.
|
69
|
variable_del('media_wysiwyg_wysiwyg_title');
|
70
|
variable_del('media_wysiwyg_wysiwyg_icon_title');
|
71
|
variable_del('media_wysiwyg_wysiwyg_default_view_mode');
|
72
|
variable_del('media_wysiwyg_wysiwyg_upload_directory');
|
73
|
variable_del('media_wysiwyg_wysiwyg_allowed_types');
|
74
|
variable_del('media_wysiwyg_wysiwyg_allowed_attributes');
|
75
|
variable_del('media_wysiwyg_wysiwyg_browser_plugins');
|
76
|
variable_del('media_wysiwyg_wysiwyg_override_field_types');
|
77
|
variable_del('media_wysiwyg_use_link_text_for_filename');
|
78
|
variable_del('media_wysiwyg_alignment');
|
79
|
variable_del('media_wysiwyg_external_link');
|
80
|
variable_del('media_wysiwyg_remove_media_class');
|
81
|
}
|
82
|
|
83
|
/**
|
84
|
* Implements hook_update_dependencies().
|
85
|
*/
|
86
|
function media_wysiwyg_update_dependencies() {
|
87
|
// Ensure the "access media browser" permission is granted to users before
|
88
|
// using it to grant the "use media wysiwyg" permission.
|
89
|
$dependencies['media_wysiwyg'][7201] = array(
|
90
|
'media' => 7226,
|
91
|
);
|
92
|
|
93
|
return $dependencies;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Grant existing user access to new media wysiwyg permission.
|
98
|
*/
|
99
|
function media_wysiwyg_update_7201() {
|
100
|
$roles = user_roles(TRUE, 'access media browser');
|
101
|
foreach ($roles as $rid => $role) {
|
102
|
user_role_grant_permissions($rid, array('use media wysiwyg'));
|
103
|
}
|
104
|
|
105
|
return t('Use Media WYSIWYG permission was granted to: @roles.', array(
|
106
|
'@roles' => check_plain(implode(', ', $roles)),
|
107
|
));
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Use the legacy file entity rendering method for existing sites.
|
112
|
*
|
113
|
* Existing sites can change this setting at admin/config/media/browser.
|
114
|
*/
|
115
|
function media_wysiwyg_update_7202() {
|
116
|
variable_set('media_wysiwyg_default_render', 'field_attach');
|
117
|
}
|
118
|
|
119
|
/**
|
120
|
* Move integration with the stand-alone CKEditor module into the Media CKEditor module.
|
121
|
*/
|
122
|
function media_wysiwyg_update_7203() {
|
123
|
$output = '';
|
124
|
|
125
|
if (module_exists('ckeditor')) {
|
126
|
$output .= t('CKEditor integration has been moved to the Media CKEditor module.');
|
127
|
$output .= t('If you are using the stand-alone CKEditor module in combination with the CKEditor plugin provided by Media WYSIWYG then you must download and enable the <a href="@url">Media CKEditor</a> module.', array('@url' => 'https://www.drupal.org/project/media_ckeditor'));
|
128
|
}
|
129
|
|
130
|
return $output;
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* Whitelists certain fields for WYSIWYG overriding.
|
135
|
*/
|
136
|
function media_wysiwyg_update_7204() {
|
137
|
$instances = field_read_instances(array('entity_type' => 'file'));
|
138
|
$updated = array();
|
139
|
$set_to_default = array();
|
140
|
foreach ($instances as $instance) {
|
141
|
$field_info = field_info_field($instance['field_name']);
|
142
|
$allowed_field_types = variable_get('media_wysiwyg_wysiwyg_override_field_types', array('text', 'text_long'));
|
143
|
if (in_array($field_info['type'], $allowed_field_types)) {
|
144
|
if (!isset($instance['settings']['wysiwyg_override'])) {
|
145
|
$instance['settings']['wysiwyg_override'] = 1;
|
146
|
field_update_instance($instance);
|
147
|
$set_to_default[] = $instance['field_name'];
|
148
|
}
|
149
|
}
|
150
|
elseif (isset($instance['settings']['wysiwyg_override'])) {
|
151
|
unset($instance['settings']['wysiwyg_override']);
|
152
|
field_update_instance($instance);
|
153
|
$updated[] = $instance['field_name'];
|
154
|
}
|
155
|
}
|
156
|
if (count($updated) || count($set_to_default)) {
|
157
|
$updated_string = implode(', ', $updated);
|
158
|
$default_string = implode(', ', $set_to_default);
|
159
|
return t("Updated the following field instances: @updated_string so they can't be overridden when the file is inserted in the WYSIWYG. Updated the following fields @default_string so that they continue to show up when a file is inserted.", array(
|
160
|
'@updated_string' => $updated_string,
|
161
|
'@default_string' => $default_string,
|
162
|
));
|
163
|
}
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* Install {media_restrict_wysiwyg} and {media_view_mode_wysiwyg}.
|
168
|
*
|
169
|
* Remove variables media_wysiwyg_view_mode_%.
|
170
|
*
|
171
|
* Uninstall media_wysiwyg_view_mode module.
|
172
|
*/
|
173
|
function media_wysiwyg_update_7205() {
|
174
|
$schema = media_wysiwyg_schema();
|
175
|
|
176
|
// Create the new configuration tables.
|
177
|
if (!db_table_exists('media_restrict_wysiwyg')) {
|
178
|
db_create_table('media_restrict_wysiwyg', $schema['media_restrict_wysiwyg']);
|
179
|
db_create_table('media_view_mode_wysiwyg', $schema['media_view_mode_wysiwyg']);
|
180
|
}
|
181
|
|
182
|
// Migrate the configuration from the old variables into the new DB tables.
|
183
|
$types = file_type_load_all(TRUE);
|
184
|
foreach ($types as $type) {
|
185
|
$enabled = variable_get("media_wysiwyg_view_mode_" . $type->type . "_wysiwyg_restricted_view_modes_status", FALSE);
|
186
|
if ($enabled) {
|
187
|
$wysiwyg_restricted_view_modes = variable_get("media_wysiwyg_view_mode_" . $type->type . "_wysiwyg_restricted_view_modes", array());
|
188
|
foreach ($wysiwyg_restricted_view_modes as $wysiwyg_restricted_view_mode) {
|
189
|
db_insert('media_restrict_wysiwyg')
|
190
|
->fields(array(
|
191
|
'type' => $type->type,
|
192
|
'display' => $wysiwyg_restricted_view_mode,
|
193
|
))
|
194
|
->execute();
|
195
|
}
|
196
|
}
|
197
|
|
198
|
$enabled = variable_get("media_wysiwyg_view_mode_" . $type->type . "_file_wysiwyg_view_mode_status", FALSE);
|
199
|
if ($enabled) {
|
200
|
$file_wysiwyg_view_mode = variable_get("media_wysiwyg_view_mode_" . $type->type . "_file_wysiwyg_view_mode", 'wysiwyg');
|
201
|
db_insert('media_view_mode_wysiwyg')
|
202
|
->fields(array(
|
203
|
'type' => $type->type,
|
204
|
'view_mode' => $file_wysiwyg_view_mode,
|
205
|
))
|
206
|
->execute();
|
207
|
}
|
208
|
}
|
209
|
|
210
|
// Remove old configuration variables.
|
211
|
db_delete('variable')->condition('name', "media_wysiwyg_view_mode_%", "LIKE")->execute();
|
212
|
|
213
|
// Disable and uninstall View Mode module.Since the view mode module is
|
214
|
// deleted, this copies from module_disable() and drupal_uninstall_modules().
|
215
|
// Disable first.
|
216
|
$module = 'media_wysiwyg_view_mode';
|
217
|
db_update('system')
|
218
|
->fields(array('status' => 0))
|
219
|
->condition('type', 'module')
|
220
|
->condition('name', $module)
|
221
|
->execute();
|
222
|
system_list_reset();
|
223
|
module_list(TRUE);
|
224
|
module_implements('', FALSE, TRUE);
|
225
|
entity_info_cache_clear();
|
226
|
// Invoke hook_modules_disabled before disabling modules,
|
227
|
// so we can still call module hooks to get information.
|
228
|
module_invoke_all('modules_disabled', array($module));
|
229
|
// Update the registry to remove the newly-disabled module.
|
230
|
registry_update();
|
231
|
_system_update_bootstrap_status();
|
232
|
// Update the theme registry to remove the newly-disabled module.
|
233
|
drupal_theme_rebuild();
|
234
|
|
235
|
// Now uninstall.
|
236
|
drupal_uninstall_schema($module);
|
237
|
drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
|
238
|
|
239
|
module_invoke_all('modules_uninstalled', array($module));
|
240
|
}
|
241
|
|
242
|
/**
|
243
|
* Notify upgraders that there's optional media alignment functionality that needs to be enabled.
|
244
|
*/
|
245
|
function media_wysiwyg_update_7206() {
|
246
|
$message = t('If you would like to be able to align your embedded media (left, right, or center), go to /admin/config/media/browser and check "Provide alignment option when embedding media", and save the settings.');
|
247
|
drupal_set_message($message, 'warning', TRUE);
|
248
|
}
|
249
|
|
250
|
/**
|
251
|
* Notify upgraders that there's optional media linking functionality that needs to be enabled.
|
252
|
*/
|
253
|
function media_wysiwyg_update_7207() {
|
254
|
$message = t('If you would like to be able to link images to a page, go to /admin/config/media/browser, check "Provide the ability to link media to pages", and save the settings.');
|
255
|
drupal_set_message($message, 'warning', TRUE);
|
256
|
}
|