Projet

Général

Profil

Paste
Télécharger (7,93 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / modules / media_wysiwyg / media_wysiwyg.install @ b3ab3446

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
}
80

    
81
/**
82
 * Implements hook_update_dependencies().
83
 */
84
function media_wysiwyg_update_dependencies() {
85
  // Ensure the "access media browser" permission is granted to users before
86
  // using it to grant the "use media wysiwyg" permission.
87
  $dependencies['media_wysiwyg'][7201] = array(
88
    'media' => 7226,
89
  );
90
}
91

    
92
/**
93
 * Grant existing user access to new media wysiwyg permission.
94
 */
95
function media_wysiwyg_update_7201() {
96
  $roles = user_roles(TRUE, 'access media browser');
97
  foreach ($roles as $rid => $role) {
98
    user_role_grant_permissions($rid, array('use media wysiwyg'));
99
  }
100

    
101
  return t('Use Media WYSIWYG permission was granted to: @roles.', array(
102
    '@roles' => check_plain(implode(', ', $roles)),
103
  ));
104
}
105

    
106
/**
107
 * Use the legacy file entity rendering method for existing sites.
108
 *
109
 * Existing sites can change this setting at admin/config/media/browser.
110
 */
111
function media_wysiwyg_update_7202() {
112
  variable_set('media_wysiwyg_default_render', 'field_attach');
113
}
114

    
115
/**
116
 * Move integration with the stand-alone CKEditor module into the Media CKEditor module.
117
 */
118
function media_wysiwyg_update_7203() {
119
  $output = '';
120

    
121
  if (module_exists('ckeditor')) {
122
    $output .= t('CKEditor integration has been moved to the Media CKEditor module.');
123
    $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'));
124
  }
125

    
126
  return $output;
127
}
128
/**
129
 * Whitelists certain fields for WYSIWYG overriding.
130
 */
131
function media_wysiwyg_update_7204() {
132
  $instances = field_read_instances(array('entity_type' => 'file'));
133
  $updated = array();
134
  $set_to_default = array();
135
  foreach ($instances as $instance) {
136
    $field_info = field_info_field($instance['field_name']);
137
    $allowed_field_types = variable_get('media_wysiwyg_wysiwyg_override_field_types', array('text', 'text_long'));
138
    if (in_array($field_info['type'], $allowed_field_types)) {
139
      if (!isset($instance['settings']['wysiwyg_override'])) {
140
        $instance['settings']['wysiwyg_override'] = 1;
141
        field_update_instance($instance);
142
        $set_to_default[] = $instance['field_name'];
143
      }
144
    }
145
    elseif (isset($instance['settings']['wysiwyg_override'])) {
146
      unset($instance['settings']['wysiwyg_override']);
147
      field_update_instance($instance);
148
      $updated[] = $instance['field_name'];
149
    }
150
  }
151
  if (count($updated) || count($set_to_default)) {
152
    $updated_string = implode(', ', $updated);
153
    $default_string = implode(', ', $set_to_default);
154
    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(
155
      '@updated_string' => $updated_string,
156
      '@default_string' => $default_string,
157
    ));
158
  }
159
}
160

    
161
/**
162
 * Install {media_restrict_wysiwyg} and {media_view_mode_wysiwyg}.
163
 *
164
 * Remove variables media_wysiwyg_view_mode_%.
165
 *
166
 * Uninstall media_wysiwyg_view_mode module.
167
 */
168
function media_wysiwyg_update_7205() {
169
  $schema = media_wysiwyg_schema();
170

    
171
  // Create the new configuration tables.
172
  if (!db_table_exists('media_restrict_wysiwyg')) {
173
    db_create_table('media_restrict_wysiwyg',  $schema['media_restrict_wysiwyg']);
174
    db_create_table('media_view_mode_wysiwyg', $schema['media_view_mode_wysiwyg']);
175
  }
176

    
177
  // Migrate the configuration from the old variables into the new DB tables.
178
  $types = file_type_load_all(TRUE);
179
  foreach ($types as $type) {
180
    $wysiwyg_restricted_view_modes = variable_get("media_wysiwyg_view_mode_{$type->type}_wysiwyg_restricted_view_modes", array());
181
    foreach ($wysiwyg_restricted_view_modes as $wysiwyg_restricted_view_mode) {
182
      db_insert('media_restrict_wysiwyg')
183
        ->fields(array(
184
          'type' => $type->type,
185
          'display' => $wysiwyg_restricted_view_mode,
186
        ))
187
        ->execute();
188
    }
189

    
190
    $file_wysiwyg_view_mode = variable_get("media_wysiwyg_view_mode_{$type->type}_file_wysiwyg_view_mode", 'wysiwyg');
191
    db_insert('media_view_mode_wysiwyg')
192
      ->fields(array(
193
        'type' => $type->type,
194
        'view_mode' => $file_wysiwyg_view_mode,
195
      ))
196
      ->execute();
197
  }
198

    
199
  // Remove old configuration variables.
200
  db_delete('variable')->condition('name', "media_wysiwyg_view_mode_%", "LIKE")->execute();
201

    
202
  // Disable and uninstall View Mode module.Since the view mode module is
203
  // deleted, this copies from  module_disable() and drupal_uninstall_modules().
204
  // Disable first.
205
  $module = 'media_wysiwyg_view_mode';
206
  db_update('system')
207
    ->fields(array('status' => 0))
208
    ->condition('type', 'module')
209
    ->condition('name', $module)
210
    ->execute();
211
  system_list_reset();
212
  module_list(TRUE);
213
  module_implements('', FALSE, TRUE);
214
  entity_info_cache_clear();
215
  // Invoke hook_modules_disabled before disabling modules,
216
  // so we can still call module hooks to get information.
217
  module_invoke_all('modules_disabled', array($module));
218
  // Update the registry to remove the newly-disabled module.
219
  registry_update();
220
  _system_update_bootstrap_status();
221
  // Update the theme registry to remove the newly-disabled module.
222
  drupal_theme_rebuild();
223

    
224
  // Now uninstall.
225
  drupal_uninstall_schema($module);
226
  drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
227

    
228
  module_invoke_all('modules_uninstalled', array($module));
229
}
230

    
231
/**
232
 * Notify upgraders that there's optional media alignment functionality that needs to be enabled.
233
 */
234
function media_wysiwyg_update_7206() {
235
  $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.');
236
  drupal_set_message($message,'warning',TRUE);
237
}
238

    
239