Projet

Général

Profil

Paste
Télécharger (9,67 ko) Statistiques
| Branche: | Révision:

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

1
<?php
2

    
3
/**
4
 * @file
5
 * CKEditor hooks implemented by the CKEditor module.
6
 */
7

    
8
/**
9
 * Implements hook_ckeditor_plugin().
10
 */
11
function ckeditor_ckeditor_plugin() {
12
  $plugins = array();
13
  $editor_path = '%editor_path%';
14
  $plugin_dir = '%plugin_dir%';
15
  $plugin_dir_additional = '%plugin_dir_extra%';
16
  $pattern = '#\.addButton\([\s]*[\'"](.*?)[\'"][\s]*\,[\s]*\{[\s]*(.*?)[\s]*\}#s';
17

    
18
  /**
19
   * CKEditor built-in plugins.
20
   */
21
  $_editor_path = ckeditor_path('local');
22
  if ($_editor_path != '<URL>') {
23
    if (file_exists($_editor_path . '/plugins/tableresize/plugin.js')) {
24
      $plugins['tableresize'] = array(
25
        'name' => 'tableresize',
26
        'desc' => t('Table Resize plugin'),
27
        'path' => $editor_path . '/plugins/tableresize/',
28
        'buttons' => FALSE,
29
        'default' => 't'
30
      );
31
    }
32

    
33
    if (file_exists($_editor_path . '/plugins/autogrow/plugin.js')) {
34
      $plugins['autogrow'] = array(
35
        'name' => 'autogrow',
36
        'desc' => t('Auto Grow plugin'),
37
        'path' => $editor_path . '/plugins/autogrow/',
38
        'buttons' => FALSE,
39
        'default' => 'f'
40
      );
41
    }
42

    
43
    if (file_exists($_editor_path . '/plugins/stylesheetparser/plugin.js')) {
44
      $plugins['stylesheetparser'] = array(
45
        'name' => 'stylesheetparser',
46
        'desc' => t('Stylesheet Parser plugin'),
47
        'path' => $editor_path . '/plugins/stylesheetparser/',
48
        'buttons' => FALSE,
49
        'default' => 'f'
50
      );
51
    }
52
  }
53
  else {
54
    $_editor_url = ckeditor_path('url');
55
    if (preg_match("/\/(standard|full)-all/", $_editor_url)) {
56
      $plugins['tableresize'] = array(
57
        'name' => 'tableresize',
58
        'desc' => t('Table Resize plugin. See <a href="@ckdocs-tableresize">addon page</a> for more details.',
59
          array('@ckdocs-tableresize' => 'http://ckeditor.com/addon/tableresize')
60
        ),
61
        'path' => $_editor_url . '/plugins/tableresize/',
62
        'buttons' => FALSE,
63
        'default' => 't'
64
      );
65
      $plugins['autogrow'] = array(
66
        'name' => 'autogrow',
67
        'desc' => t('Auto Grow plugin. See <a href="@ckdocs-autogrow">addon page</a> for more details.',
68
          array('@ckdocs-autogrow' => 'http://ckeditor.com/addon/autogrow')
69
        ),
70
        'path' => $_editor_url . '/plugins/autogrow/',
71
        'buttons' => FALSE,
72
        'default' => 'f'
73
      );
74
      $plugins['stylesheetparser'] = array(
75
        'name' => 'stylesheetparser',
76
        'desc' => t('Stylesheet Parser plugin. See <a href="@ckdocs-stylesheetparser">addon page</a> for more details.',
77
          array('@ckdocs-stylesheetparser' => 'http://ckeditor.com/addon/stylesheetparser')
78
        ),
79
        'path' => $_editor_url . '/plugins/stylesheetparser/',
80
        'buttons' => FALSE,
81
        'default' => 'f'
82
      );
83
      $plugins['codesnippet'] = array(
84
        'name' => 'codesnippet',
85
        'desc' => t('Plugin for inserting Code Snippets. See <a href="@ckdocs-codesnippet">addon page</a> for more details. See <a href="@ckdocs-codesnippet-help">help</a> for additional instructions.',
86
          array(
87
            '@ckdocs-codesnippet' => 'http://ckeditor.com/addon/codesnippet',
88
            '@ckdocs-codesnippet-help' => url('admin/help/ckeditor', array('fragment' => 'codesnippet')),
89
          )
90
        ),
91
        'path' => $_editor_url . '/plugins/codesnippet/',
92
        'buttons' => array(
93
          'CodeSnippet' => array(
94
            'icon' => 'icons/codesnippet.png',
95
            'label' => t('Insert Code Snippet'),
96
          )
97
        ),
98
        'default' => 'f'
99
      );
100
      $plugins['mathjax'] = array(
101
        'name' => 'mathjax',
102
        'desc' => t('Plugin for inserting Mathematical Formula (MathJax). See <a href="@ckdocs-mathjax">addon page</a> for more details. See <a href="@ckdocs-mathjax-help">help</a> for additional instructions.',
103
          array(
104
            '@ckdocs-mathjax' => 'http://ckeditor.com/addon/mathjax',
105
            '@ckdocs-mathjax-help' => url('admin/help/ckeditor', array('fragment' => 'mathjax')),
106
        )),
107
        'path' => $_editor_url . '/plugins/mathjax/',
108
        'buttons' => array(
109
          'Mathjax' => array(
110
            'icon' => 'icons/mathjax.png',
111
            'label' => t('Insert Mathematical Formulas'),
112
          )
113
        ),
114
        'default' => 'f'
115
      );
116
      $plugins['image2'] = array(
117
        'name' => 'image2',
118
        'desc' => t('Enhanced Image plugin. See <a href="@ckdocs-image2">addon page</a> for more details.',
119
          array('@ckdocs-image2' => 'http://ckeditor.com/addon/image2')
120
        ),
121
        'path' => $_editor_url . '/plugins/image2/',
122
        'buttons' => array(
123
          'Enhanced Image' => array(
124
            'icon' => 'icons/image.png',
125
            'label' => t('Insert Enhanced Image'),
126
          )
127
        ),
128
        'default' => 't'
129
      );
130
    }
131
  }
132

    
133
  /**
134
   * Plugins located directly in the CKEditor module folder.
135
   */
136
  $_plugin_dir = ckeditor_module_path('local') . '/plugins/';
137
  if ($handle = opendir($_plugin_dir)) {
138
    while (false !== ($file = readdir($handle))) {
139
      if (is_dir($_plugin_dir . $file) && file_exists($_plugin_dir . $file . '/plugin.js')) {
140
        $source = file_get_contents($_plugin_dir . $file . '/plugin.js');
141
        $buttons = array();
142
        if (preg_match_all($pattern, $source, $matches)) {
143
          foreach ($matches[1] as $i => $button_name) {
144
            // Check for icon in button definition (legacy method)
145
            if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) {
146
              $buttons[$button_name] = array();
147
              $buttons[$button_name]['label'] = $button_name;
148
              $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
149
              $buttons[$button_name]['icon'] = trim($matches2[2]);
150
            }
151
            else {
152
              // Otherwise we assume the icon is being stored in the icons
153
              // folder using the lowercased button name as the filename.
154
              $buttons[$button_name] = array();
155
              $buttons[$button_name]['label'] = $button_name;
156
              $buttons[$button_name]['icon'] = 'icons/' . strtolower($button_name) . '.png';
157
            }
158
          }
159
        }
160
        if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) {
161
          $plugins[$file] = array(
162
            'name' => $file,
163
            'desc' => check_plain($matches[1]),
164
            'path' => $plugin_dir . $file . '/',
165
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
166
            'default' => 'f'
167
          );
168
        }
169
        else {
170
          $plugins[$file] = array(
171
            'name' => $file,
172
            'desc' => t('Plugin file: @plugin_filename', array('@plugin_filename' => $file)),
173
            'path' => $plugin_dir . $file . '/',
174
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
175
            'default' => 'f'
176
          );
177
        }
178
      }
179
    }
180
    closedir($handle);
181
  }
182

    
183
  /**
184
   * Plugins located in a folder specified in the CKEditor Global Profile.
185
   */
186
  $_plugin_dir_additional = ckeditor_plugins_path('local') . '/';
187
  if ($_plugin_dir != $_plugin_dir_additional && is_dir($_plugin_dir_additional) && $handle = opendir($_plugin_dir_additional)) {
188
    while (false !== ($file = readdir($handle))) {
189
      if (is_dir($_plugin_dir_additional . $file) && file_exists($_plugin_dir_additional . $file . '/plugin.js')) {
190
        $source = file_get_contents($_plugin_dir_additional . $file . '/plugin.js');
191
        $buttons = array();
192
        if (preg_match_all($pattern, $source, $matches)) {
193
          foreach ($matches[1] as $i => $button_name) {
194
            // Check for icon in button definition (legacy method)
195
            if (preg_match('#(icon)[\s]*\:[\s]*([^\,\n]*)#', $matches[2][$i], $matches2)) {
196
              $buttons[$button_name] = array();
197
              $buttons[$button_name]['label'] = $button_name;
198
              $matches2[2] = str_replace(array('this.path', '+', '\'', '"'), array('', '', '', ''), $matches2[2]);
199
              $buttons[$button_name]['icon'] = trim($matches2[2]);
200
            }
201
            else {
202
              // Otherwise we assume the icon is being stored in the icons
203
              // folder using the lowercased button name as the filename.
204
              $buttons[$button_name] = array();
205
              $buttons[$button_name]['label'] = $button_name;
206
              $buttons[$button_name]['icon'] = 'icons/' . strtolower($button_name) . '.png';
207
            }
208
          }
209
        }
210
        if (preg_match('#@file ([^\n\r]*)#', $source, $matches)) {
211
          $plugins[$file] = array(
212
            'name' => $file,
213
            'desc' => check_plain($matches[1]),
214
            'path' => $plugin_dir_additional . $file . '/',
215
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
216
            'default' => 'f'
217
          );
218
        }
219
        else {
220
          $plugins[$file] = array(
221
            'name' => $file,
222
            'desc' => t('Plugin file: @plugin_filename', array('@plugin_filename' => $file)),
223
            'path' => $plugin_dir_additional . $file . '/',
224
            'buttons' => (count($buttons) > 0) ? $buttons : FALSE,
225
            'default' => 'f'
226
          );
227
        }
228
      }
229
    }
230

    
231
    closedir($handle);
232
  }
233

    
234
  // Remove the IMCE plugin if the IMCE module isn't installed.
235
  if (isset($plugins['imce']) && module_exists('imce') == FALSE) {
236
    unset($plugins['imce']);
237
  }
238

    
239
  // Enable the Drupal Breaks plugin by default if the plugin is available.
240
  if (isset($plugins['drupalbreaks'])) {
241
    $plugins['drupalbreaks']['default'] = 't';
242

    
243
    // Remove the page break button if there is no module to handle it.
244
    if (isset($plugins['drupalbreaks']['buttons']['DrupalPageBreak']) && !module_exists('paging') && !module_exists('pagebreak')) {
245
      unset($plugins['drupalbreaks']['buttons']['DrupalPageBreak']);
246
    }
247
  }
248

    
249
  return $plugins;
250
}