Projet

Général

Profil

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

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

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

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

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

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

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

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

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

    
127
  return $output;
128
}
129

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

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

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

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

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

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

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

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

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

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

    
247
/**
248
 * Notify upgraders that there's optional media linking functionality that needs to be enabled.
249
 */
250
function media_wysiwyg_update_7207() {
251
  $message = t('If you would like to be able to link images to a page got o /admin/config/media/browser and check "Provide the ability to link media to pages", and save the settings.');
252
  drupal_set_message($message, 'warning', TRUE);
253
}