Projet

Général

Profil

Paste
Télécharger (3,09 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media_ckeditor / media_ckeditor.install @ f2fc85df

1
<?php
2

    
3
/**
4
 * @file
5
 * Install tasks for media_ckeditor.
6
 */
7

    
8
/**
9
 * Implements hook_install().
10
 */
11
function media_ckeditor_install() {
12
  // Get all the CKEditor profiles for a site.
13
  $ckeditor_profiles = db_query("SELECT * FROM {ckeditor_settings}
14
    WHERE name <> :name",
15
    array(':name' => 'CKEditor Global Profile'))
16
    ->fetchAllAssoc('name');
17
  // Get the path to the module.
18
  $mod_path = drupal_get_path('module', 'media_ckeditor');
19
  foreach ((array) $ckeditor_profiles as $profile) {
20
    // Get the name of the profile.
21
    $name = $profile->name;
22
    // Unserialize all the settings for that profile.
23
    $profile_settings = unserialize($profile->settings);
24
    // Check to see if the profile is using plugins.
25
    if (isset($profile_settings['loadPlugins'])) {
26
      // Loop over each plugin.
27
      foreach ((array) $profile_settings['loadPlugins'] as $i => $plugin) {
28
        // Check if the media plugin is used.
29
        if ($i === 'media') {
30
          // Update the path variable to the new path.
31
          $plugin['path'] = '%base_path%' . $mod_path . '/js/plugins/media/';
32
          // Update the plugin with the new path.
33
          $profile_settings['loadPlugins'][$i] = $plugin;
34
        }
35
      }
36
    }
37
    // Serialize the settings array before saving back into the database.
38
    $profile_settings = serialize($profile_settings);
39
    // Update the ckeditor settings for that profile name.
40
    db_query("UPDATE {ckeditor_settings} set settings = :settings WHERE name = :name",
41
      array(
42
        ':settings' => $profile_settings,
43
        ':name' => $name,
44
      ));
45
  }
46
}
47

    
48
/**
49
 * Updates the path to the Media plugin if used. *.
50
 */
51
function media_ckeditor_update_7201() {
52
  // Get all the CKEditor profiles for a site.
53
  $ckeditor_profiles = db_query("SELECT * FROM {ckeditor_settings}
54
    WHERE name <> :name",
55
    array(':name' => 'CKEditor Global Profile'))
56
    ->fetchAllAssoc('name');
57
  // Get the path to the module.
58
  $mod_path = drupal_get_path('module', 'media_ckeditor');
59
  foreach ((array) $ckeditor_profiles as $profile) {
60
    // Get the name of the profile.
61
    $name = $profile->name;
62
    // Unserialize all the settings for that profile.
63
    $profile_settings = unserialize($profile->settings);
64
    // Check to see if the profile is using plugins.
65
    if (isset($profile_settings['loadPlugins'])) {
66
      // Loop over each plugin.
67
      foreach ((array) $profile_settings['loadPlugins'] as $i => $plugin) {
68
        // Check if the media plugin is used.
69
        if ($i === 'media') {
70
          // Update the path variable to the new path.
71
          $plugin['path'] = '%base_path%' . $mod_path . '/js/plugins/media/';
72
          // Update the plugin with the new path.
73
          $profile_settings['loadPlugins'][$i] = $plugin;
74
        }
75
      }
76
    }
77
    // Serialize the settings array before saving back into the database.
78
    $profile_settings = serialize($profile_settings);
79
    // Update the ckeditor settings for that profile name.
80
    db_query("UPDATE {ckeditor_settings} set settings = :settings WHERE name = :name",
81
      array(
82
        ':settings' => $profile_settings,
83
        ':name' => $name,
84
      ));
85
  }
86
}