Projet

Général

Profil

Paste
Télécharger (4 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ckeditor / includes / ckeditor.features.inc @ 2e0f6994

1
<?php
2

    
3
/**
4
 * CKEditor - The text editor for the Internet - http://ckeditor.com
5
 * Copyright (c) 2003-2013, CKSource - Frederico Knabben. All rights reserved.
6
 *
7
 * == BEGIN LICENSE ==
8
 *
9
 * Licensed under the terms of any of the following licenses of your
10
 * choice:
11
 *
12
 *  - GNU General Public License Version 2 or later (the "GPL")
13
 *    http://www.gnu.org/licenses/gpl.html
14
 *
15
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
16
 *    http://www.gnu.org/licenses/lgpl.html
17
 *
18
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
19
 *    http://www.mozilla.org/MPL/MPL-1.1.html
20
 *
21
 * == END LICENSE ==
22
 *
23
 * @file
24
 * CKEditor Module for Drupal 7.x
25
 *
26
 * This module allows Drupal to replace textarea fields with CKEditor.
27
 *
28
 * CKEditor is an online rich text editor that can be embedded inside web pages.
29
 * It is a WYSIWYG (What You See Is What You Get) editor which means that the
30
 * text edited in it looks as similar as possible to the results end users will
31
 * see after the document gets published. It brings to the Web popular editing
32
 * features found in desktop word processors such as Microsoft Word and
33
 * OpenOffice.org Writer. CKEditor is truly lightweight and does not require any
34
 * kind of installation on the client computer.
35
 */
36

    
37
/**
38
 * Implementation of hook_features_export_options()
39
 */
40
function ckeditor_profile_features_export_options() {
41
  $options = array();
42
  $profiles = (array) ckeditor_profile_load();
43
  foreach ($profiles as $name => $profile) {
44
    $options[$name] = $profile->name;
45
  }
46
  return $options;
47
}
48

    
49
/**
50
 * Implementation of hook_features_export()
51
 */
52
function ckeditor_profile_features_export($data, &$export, $module_name = '') {
53
  $pipe = array();
54
  foreach ((array) $data as $name) {
55
    $profile = ckeditor_profile_load($name);
56
    if ($profile) {
57
      $export['features']['ckeditor_profile'][$name] = $name;
58

    
59
      // Write dependencies on all the roles referenced by this profile
60
      foreach ((array) $profile->input_formats as $input_format => $input_format_name) {
61
        $pipe['input_formats'][] = $input_format;
62
      }
63
    }
64
  }
65
  $export['dependencies']['ckeditor'] = 'ckeditor';
66
  return $pipe;
67
}
68

    
69
/**
70
 * Implementation of hook_features_export_render()
71
 */
72
function ckeditor_profile_features_export_render($module_name, $data) {
73
  $profiles = array();
74
  $roles = user_roles();
75
  foreach ($data as $name) {
76
    $profile = (array) ckeditor_profile_load($name, TRUE, FALSE);
77

    
78
    $profiles[$name] = $profile;
79
  }
80
  $code = '  $data = ' . features_var_export($profiles, '  ') . ';' . PHP_EOL;
81
  $code .= '  return $data;';
82

    
83
  return array('ckeditor_profile_defaults' => $code);
84
}
85

    
86
/**
87
 * Implementation of hook_features_rebuild()
88
 */
89
function ckeditor_profile_features_rebuild($module) {
90
  ckeditor_profile_features_revert($module);
91
}
92

    
93
/**
94
 * Implementation of hook_features_revert()
95
 */
96
function ckeditor_profile_features_revert($module) {
97
  if ($data = features_get_default('ckeditor_profile', $module)) {
98
    $input_formats = filter_formats();
99
    foreach ($data as $name => $profile) {
100
      // Restore the profile settings
101
      db_query("DELETE FROM {ckeditor_settings} WHERE name = :name", array(':name' => $name));
102
      db_query("INSERT INTO {ckeditor_settings} (name, settings) VALUES(:name, :settings)", array(':name' => $name, ':settings' => serialize($profile['settings'])));
103

    
104
      if (empty($profile["input_formats"])) {
105
        // Remove input format if none is specified
106
        db_query("DELETE FROM {ckeditor_input_format} WHERE name = :name", array(':name' => $name));
107
      }
108
      else {
109
        // Restore the profile roles
110
        foreach ($profile["input_formats"] as $input_format => $input_format_name) {
111
          if (!db_query("SELECT name FROM {ckeditor_input_format} WHERE format = :format AND name = :name", array(':name' => $name, ':format' => $input_format))->fetchField()) {
112
            db_query("INSERT INTO {ckeditor_input_format} (name, format) VALUES(:name, :format)", array(':name' => $name, ':format' => $input_format));
113
          }
114
        }
115
      }
116
    }
117
  }
118
}