Projet

Général

Profil

Paste
Télécharger (8,72 ko) Statistiques
| Branche: | Révision:

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

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

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

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

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

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

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

    
128
  return $output;
129
}
130

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

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

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

    
180
  // Migrate the configuration from the old variables into the new DB tables.
181
  $types = file_type_load_all(TRUE);
182
  foreach ($types as $type) {
183
    $enabled = variable_get("media_wysiwyg_view_mode_" . $type->type . "_file_wysiwyg_restricted_view_modes_status", FALSE);
184
    if ($enabled) {
185
      $wysiwyg_restricted_view_modes = variable_get("media_wysiwyg_view_mode_" . $type->type . "_file_wysiwyg_restricted_view_modes", array());
186
      foreach ($wysiwyg_restricted_view_modes as $wysiwyg_restricted_view_mode) {
187
        db_insert('media_restrict_wysiwyg')
188
          ->fields(array(
189
            'type' => $type->type,
190
            'display' => $wysiwyg_restricted_view_mode,
191
          ))
192
          ->execute();
193
      }
194
    }
195

    
196
    $enabled = variable_get("media_wysiwyg_view_mode_" . $type->type . "_wysiwyg_view_mode_status", FALSE);
197
    if ($enabled) {
198
      $file_wysiwyg_view_mode = variable_get("media_wysiwyg_view_mode_" . $type->type . "_file_wysiwyg_view_mode", 'wysiwyg');
199
      db_insert('media_view_mode_wysiwyg')
200
        ->fields(array(
201
          'type' => $type->type,
202
          'view_mode' => $file_wysiwyg_view_mode,
203
        ))
204
        ->execute();
205
    }
206
  }
207

    
208
  // Remove old configuration variables.
209
  db_delete('variable')->condition('name', "media_wysiwyg_view_mode_%", "LIKE")->execute();
210

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

    
233
  // Now uninstall.
234
  drupal_uninstall_schema($module);
235
  drupal_set_installed_schema_version($module, SCHEMA_UNINSTALLED);
236

    
237
  module_invoke_all('modules_uninstalled', array($module));
238
}
239

    
240
/**
241
 * Notify upgraders that there's optional media alignment functionality that needs to be enabled.
242
 */
243
function media_wysiwyg_update_7206() {
244
  $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.');
245
  drupal_set_message($message, 'warning', TRUE);
246
}
247

    
248
/**
249
 * Notify upgraders that there's optional media linking functionality that needs to be enabled.
250
 */
251
function media_wysiwyg_update_7207() {
252
  $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.');
253
  drupal_set_message($message, 'warning', TRUE);
254
}