Projet

Général

Profil

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

root / drupal7 / sites / all / modules / media / modules / media_wysiwyg / media_wysiwyg.install @ 0939d55c

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

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

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

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

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

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

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

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

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

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