forked from polem/redactor_wysiwyg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
redactor.module
230 lines (205 loc) · 5.33 KB
/
redactor.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<?php
/**
* @file
* Integrates redactor editors with Drupal.
*/
/**
* Implements hook_wysiwyg_include_directory().
*/
function redactor_wysiwyg_include_directory($type) {
return $type;
}
/**
* Implements hook_redactor_plugins.
*/
function redactor_redactor_plugins($editor) {
return array(
'counter' => array(
'name' => 'Counter',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/counter.js',
),
),
),
'clips' => array(
'name' => 'Clips',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/clips/clips.js',
),
'css' => array(
$editor['library path'] . '/plugins/clips/clips.css',
),
),
),
'definedlinks' => array(
'name' => 'Defined links',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/definedlinks.js',
),
),
),
'fontcolor' => array(
'name' => 'Font color',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/fontcolor.js',
),
),
),
'fontfamily' => array(
'name' => 'Font family',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/fontfamily.js',
),
),
),
'fontsize' => array(
'name' => 'Font size',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/fontsize.js',
),
),
),
'fullscreen' => array(
'name' => 'Fullscreen',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/fullscreen.js',
),
),
),
'limiter' => array(
'name' => 'Limiter',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/limiter.js',
),
),
),
'table' => array(
'name' => 'Table',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/table.js',
),
),
),
'textdirection' => array(
'name' => 'Text direction',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/textdirection.js',
),
),
),
'textexpander' => array(
'name' => 'Text expander',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/textexpander.js',
),
),
),
'video' => array(
'name' => 'Video',
'files' => array(
'js' => array(
$editor['library path'] . '/plugins/video.js',
),
),
),
);
}
/**
* get redactor plugin definition
*
* @return array plugin definition
*/
function redactor_get_plugin_definition($plugin_name) {
$plugins = redactor_get_plugin_definitions();
$plugin = isset($plugins[$plugin_name]) ? $plugins[$plugin_name] : null;
return $plugin;
}
/**
* Return redactor plugins definitions
* @return array plugin definitions
*/
function redactor_get_plugin_definitions() {
$plugins = &drupal_static(__FUNCTION__);
if (!isset($plugins)) {
$editor = wysiwyg_get_editor('redactor');
$plugins = module_invoke_all('redactor_plugins', $editor);
drupal_alter('redactor_plugins', $plugins);
}
return $plugins;
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function redactor_form_wysiwyg_profile_form_alter(&$form, &$form_state, $profile) {
if($form_state['wysiwyg']['editor'] == 'redactor') {
return;
}
$form['plugins'] = array(
'#weight' => -10,
'#type' => 'fieldset',
'#title' => t('Redactor plugins'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#tree' => TRUE,
'#theme' => 'wysiwyg_admin_button_table',
);
$plugins = redactor_get_plugin_definitions();
$profile = $form_state['wysiwyg_profile'];
foreach($plugins as $name => $infos) {
$form['plugins'][$name][$name] = array(
'#type' => 'checkbox',
'#title' => $infos['name'],
'#default_value' => !empty($profile->settings['plugins'][$name][$name]) ? $profile->settings['plugins'][$name][$name] : FALSE,
'#description' => NULL,
);
}
array_unshift($form['#submit'], 'redactor_profile_form_submit');
return $form;
}
/**
* extra submit form callback
*
* @param object $form
* @param object $form_state
*/
function redactor_profile_form_submit($form, &$form_state) {
$values = &$form_state['values'];
if (isset($values['plugins'])) {
// Store only enabled plugins for each plugin.
foreach ($values['plugins'] as $plugin => $plugins) {
$values['plugins'][$plugin] = array_filter($values['plugins'][$plugin]);
}
// Store only enabled plugins.
$values['plugins'] = array_filter($values['plugins']);
}
}
/**
* Get plugin config from hook_redactor plugin 'config' key
* and merge it with wysiwyg_profile config values (admin form)
*
* @param string $plugin_name
* @param object $wysiwyg_profile
* @return array merged config
*/
function redactor_get_plugin_config($plugin_name, $wysiwyg_profile = null) {
$config = array();
$plugin = redactor_get_plugin_definition($plugin_name);
if(!is_null($wysiwyg_profile) && isset($wysiwyg_profile->settings[$plugin_name])) {
$config = $wysiwyg_profile->settings[$plugin_name];
}
if(isset($plugin['config'])) {
$config += $plugin['config'];
}
return $config;
}