-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwysiwyg_features.module
85 lines (75 loc) · 2.49 KB
/
wysiwyg_features.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
/**
* @file Features support.
* Wysiwyg Features integration from catch. http://drupal.org/node/624018#comment-2307894
*/
/**
* Implementation of hook_features_api().
*/
function wysiwyg_features_features_api() {
return array(
'wysiwyg' => array(
'default_hook' => 'features_default_wysiwyg',
'features_source' => TRUE,
),
);
}
/**
* Implementation of hook_features_export_options().
*/
function wysiwyg_features_export_options() {
return array('editor' => t('Editor settings'));
}
/**
* Implementation of hook_features_export().
*/
function wysiwyg_features_export($data, &$export, $module_name = '') {
// The filter_default_formats() hook integration is provided by the
// features module so we need to add it as a dependency.
$export['dependencies']['features'] = 'features';
$result = db_query("SELECT editor FROM {wysiwyg}");
while ($row = db_fetch_object($result)) {
// Add format to exports
$export['features']['wysiwyg'][$row->editor] = $row->editor;
}
return array();
}
/**
* Implementation of hook_features_export_render().
*/
function wysiwyg_features_export_render($module = 'foo', $data) {
// @todo - without this there is an undefined function features_var_export().
module_load_include('inc', 'features', 'features.export');
$code = array();
$code[] = ' $defaults = array();';
$code[] = '';
$result = db_query("SELECT * FROM {wysiwyg}");
while ($row = db_fetch_array($result)) {
$row['settings'] = unserialize($row['settings']);
$code[] = ' $defaults[] = '. features_var_export($row, ' ') .';';
$code[] = '';
}
$code[] = ' return $defaults;';
$code = implode("\n", $code);
return array('features_default_wysiwyg' => $code);
}
/**
* Implementation of hook_features_export_revert().
*/
function wysiwyg_features_revert($module) {
wysiwyg_features_rebuild($module);
}
/**
* Implementation of hook_features_export_rebuild().
*/
function wysiwyg_features_rebuild($module) {
$defaults = module_invoke($module, 'features_default_wysiwyg');
if (!empty($defaults)) {
foreach ($defaults as $default) {
db_query("UPDATE {wysiwyg} SET format = %d, editor = '%s', settings = '%s' WHERE format = %d", $default['format'], $default['editor'], serialize($default['settings']), $default['format']);
if (!db_affected_rows()) {
db_query("INSERT INTO {wysiwyg} (format, editor, settings) VALUES (%d, '%s', '%s')", $default['format'], $default['editor'], serialize($default['settings']));
}
}
}
}