Projet

Général

Profil

Paste
Télécharger (16,1 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ckeditor / includes / ckeditor.page.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
function ckeditor_help_delegate($path, $arg) {
37
  global $base_url;
38

    
39
  switch ($path) {
40
    case 'admin/config/content/help#description':
41
      $output = t('Enables the use of CKEditor (a rich text WYSIWYG editor) instead of plain text fields.');
42
      break;
43

    
44
    case 'admin/config/content/ckeditor/edit/%':
45
    case 'admin/config/content/ckeditor/add':
46
      $ckeditor_url = ckeditor_path('local');
47
      if ($ckeditor_url == '<URL>') {
48
        $do_not_touch_configjs = '';
49
      }
50
      else {
51
        $do_not_touch_configjs = '<p>' .
52
          t('It is recommended to not edit the !ckeditor_config_file (!ckeditor_config_path) configuration file that is distributed with CKEditor, because you may overwrite it accidentally when you update the editor.', array(
53
              '!ckeditor_config_path' => '<code>' . $ckeditor_url . '/config.js</code>',
54
              '!ckeditor_config_file' => '<code>config.js</code>',
55
            )
56
          ) .
57
          '</p>';
58
      }
59
      $output = '<p>' . t('CKEditor is highly configurable. The most commonly used features are listed below. You can also adjust CKEditor to your needs by changing the !ckeditor_module_config configuration file.', array(
60
            '!ckeditor_module_config' => '<code>' . ckeditor_module_path('local') . '/ckeditor.config.js</code>',
61
              )
62
          ) .
63
          '</p>'.$do_not_touch_configjs;
64
      break;
65

    
66
    case 'admin/config/content/ckeditor/editg':
67
    case 'admin/config/content/ckeditor/add':
68
      $output = '<p>' . t('The Global Profile allows you to define settings that are common for all profiles. Values defined in other profiles will be appended to the global configuration. This way you can avoid repeating some of the settings that are usually the same for each profile.') . '</p>';
69
      break;
70

    
71
    case 'admin/config/content/ckeditor':
72
      $output =
73
          '<div style="padding:10px;border:1px solid #BEBFB9;margin-bottom:10px;"><p>' .
74
          t('The CKEditor module allows Drupal to replace textarea fields with CKEditor. CKEditor is an online rich text editor that can be embedded inside web pages. It is a !wysiwyg editor which means that the text edited in it looks as similar as possible to the results end users will see after the document gets published. It brings to the Web popular editing features found in desktop word processors such as Microsoft Word and OpenOffice.org Writer. CKEditor is truly lightweight and does not require any kind of installation on the client computer.', array(
75
            '!wysiwyg' => '<acronym title="' . t('What You See Is What You Get') . '">' . t('WYSIWYG') . '</acronym>',
76
              )
77
          ) .
78
          '</p><p>' .
79
          t('Useful links: !ckeditorlink | !devguidelink | !userguidelink.', array(
80
            '!ckeditorlink' => l(t('CKEditor website'), 'http://ckeditor.com'),
81
            '!devguidelink' => l(t('CKEditor for Drupal 7 Documentation'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7'),
82
            '!userguidelink' => l(t('User\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Users_Guide')
83
              )
84
          ) .
85
          '</p></div><p>' .
86
          t('Profiles are linked with input format types. A CKEditor profile defines which buttons are available in the editor, how the editor is displayed, and a few other editor functions. The Global Profile stores some general information about CKEditor.') . '</p>';
87
      break;
88

    
89
    case 'admin/help#ckeditor':
90
      $output =
91
          '<h3>' . t('Introduction') . '</h3>' .
92
          '<p>' .
93
          t('The CKEditor module allows Drupal to replace textarea fields with CKEditor. CKEditor is an online rich text editor that can be embedded inside web pages. It is a !wysiwyg editor which means that the text edited in it looks as similar as possible to the results end users will see after the document gets published. It brings to the Web popular editing features found in desktop word processors such as Microsoft Word and OpenOffice.org Writer. CKEditor is truly lightweight and does not require any kind of installation on the client computer.', array(
94
            '!wysiwyg' => '<acronym title="' . t('What You See Is What You Get') . '">' . t('WYSIWYG') . '</acronym>',
95
              )
96
          ) .
97
          '</p>' .
98
          '<p>' .
99
          t('Useful links: !ckeditorlink | !devguidelink | !userguidelink.', array(
100
            '!ckeditorlink' => l(t('CKEditor website'), 'http://ckeditor.com'),
101
            '!devguidelink' => l(t('CKEditor for Drupal 7 Documentation'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7'),
102
            '!userguidelink' => l(t('User\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Users_Guide')
103
              )
104
          ) .
105
          '</p>' .
106
          '<h4>' .
107
          t('Configuration') .
108
          '</h4>' .
109
          '<ol>' .
110
          '<li>' .
111
          t('CKEditor profiles can be configured in the !adminpath section. Profiles determine which options are available to users based on the input format system.', array(
112
            '!adminpath' => '<strong>' . l(t('Administration panel') . ' > ' . t('Configuration') . ' > ' . t('Content Authoring') . ' > ' . t('CKEditor'), 'admin/config/content/ckeditor') . '</strong>'
113
              )
114
          ) .
115
          '</li>' .
116
          '<li>' .
117
          t('For the Rich Text Editing to work you also need to configure your !filterlink for the users that may access Rich Text Editing. Either grant those users <strong>Full HTML</strong> access or use the following list of tags in the HTML filter:', array(
118
            '!filterlink' => l(t('filters'), 'admin/config/content/formats')
119
              )
120
          ) .
121
          '<br /><code>' .
122
          htmlspecialchars('<a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <caption> <tbody> <tr> <td> <em> <b> <u> <i> <strong> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike>') .
123
          '</code><br />' .
124
          t('<strong>Note:</strong> be careful when granting users access to create tags like %iframe.<br />If you are going to use CKEditor with the <strong>Filtered HTML</strong> input format, please read the "Setting up filters" section in the !readme file.', array(
125
            '%iframe' => '<iframe>',
126
            '!readme' => '<code>' . l(t('README.txt'), $base_url . '/' . drupal_get_path('module', 'ckeditor') . '/README.txt', array('absolute' => TRUE)) . '</code>'
127
              )
128
          ) .
129
          '</li>' .
130
          '<li>' .
131
          t('To have better control over line breaks, you should disable the <strong>%settingname</strong> setting in the chosen Text format (recommended).', array(
132
            '%settingname' => t('Line break converter'),
133
              )
134
          ) .
135
          '</li>' .
136
          '<li>' .
137
          t('All configuration options described in the !apidocs that cannot be easily changed in the administration area can be set in the <strong>Advanced Options</strong> section in the CKEditor profile.', array(
138
            '!apidocs' => l(t('API documentation'), 'http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html')
139
              )
140
          ) .
141
          '</li>' .
142
          '</ol>' .
143
          '<h3>' .
144
          t('Troubleshooting') .
145
          '</h3>' .
146
          '<p>' .
147
          t('Take a look at !listlink when installing CKEditor.', array(
148
            '!listlink' => l(t('the list of common problems'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7/Troubleshooting')
149
              )
150
          ) .
151
          ' ' .
152
          t('If you are looking for more information, have any trouble with the configuration, or found an issue with the CKEditor module, please visit the !officiallink.', array(
153
            '!officiallink' => l(t('official project page'), 'http://drupal.org/project/ckeditor')
154
              )
155
          ) .
156
          ' ' .
157
          t('More information about how to customize CKEditor for your theme can be found !herelink.', array(
158
            '!herelink' => l(t('here'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7/Tricks')
159
              )
160
          ) .
161
          '</p>' .
162
          '<h3>' .
163
          t('Plugins: Code Snippet and MathJax') .
164
          '</h3>' .
165
          '<p>' .
166
          t('Code Snippet and MathJax are special plugins for CKEditor that are using external JavaScript libraries to style content inside editing area. The result that is returned by CKEditor is just an HTML tag that needs to again processed by a filter (either server side or client side) in order to display it properly to the user.') .
167
          '</p>' .
168
          '<h4><a name="mathjax"></a>' .
169
          t('MathJax (Mathematical Formulas)') .
170
          '</h4>' .
171
          '<p>' .
172
          t('With mathjax plugin, CKEditor produces LaTeX code surrounded by !code. In order to have it properly rendered on your site you might need to add !mathjax on your website, the simplest way to do this is to add this to your theme: !script', array(
173
            '!code' => '<code>'.htmlspecialchars('<span class="math-tex"></span>').'</code>',
174
            '!mathjax' => l('MathJax', 'http://www.mathjax.org/'),
175
            '!script' => '<br /><code>'.htmlspecialchars('<script src="http://cdn.mathjax.org/mathjax/2.2-latest/MathJax.js?config=TeX-AMS_HTML" type="text/javascript"></script>').'</code>'
176
          )) .
177
          '</p>' .
178
          '<h4><a name="codesnippet"></a>' .
179
          t('Code Snippet') .
180
          '</h4>' .
181
          '<p>' .
182
          t('With codesnippet plugin, CKEditor produces code snippets surrounded by !code. <strong>Note:</strong> You might need to add !highlight on your website so that the displayed code was rendered nicely as in CKEditor. The simplest way to do this is to add this to your theme: !script', array(
183
            '!highlight' => l('highlight.js', 'http://highlightjs.org/'),
184
            '!code' => '<code>'.htmlspecialchars('<pre><code></code></pre>').'</code>',
185
            '!script' => '<br /><code>'.htmlspecialchars('<link rel="stylesheet" href="http://cdn.ckeditor.com/' . CKEDITOR_LATEST . '/full-all/plugins/codesnippet/lib/highlight/styles/default.css">').'<br />'.
186
htmlspecialchars('<script src="http://cdn.ckeditor.com/' . CKEDITOR_LATEST . '/full-all/plugins/codesnippet/lib/highlight/highlight.pack.js" type="text/javascript"></script>').'<br />'.
187
htmlspecialchars('<script>hljs.initHighlightingOnLoad();</script>').'</code>'
188
          )) .
189
          '</p>' .
190
          '<h3>' .
191
          t('Uploading images and files') .
192
          '</h3>' .
193
          '<p>' .
194
          t('There are three ways for uploading files:') .
195
          '</p>' .
196
          '<ol>' .
197
          '<li>' .
198
          t('By using !ckfinder (commercial), an advanced Ajax file manager.', array(
199
            '!ckfinder' => l(t('CKFinder'), 'http://cksource.com/ckfinder'),
200
              )
201
          ) .
202
          '</li>' .
203
          '<li>' .
204
          t('By using a dedicated module like !imcelink.', array(
205
            '!imcelink' => l(t('IMCE'), 'http://drupal.org/project/imce')
206
              )
207
          ) .
208
          '</li>' .
209
          '<li>' .
210
          t('By using the core upload module.') .
211
          '</li>' .
212
          '</ol>';
213

    
214
      break;
215
  }
216
  return !empty($output) ? $output : '';
217
}
218

    
219
/**
220
 * AJAX callback - XSS filter
221
 */
222
function ckeditor_filter_xss() {
223
  header('Content-Type: text/plain; charset=utf-8');
224
  $GLOBALS['devel_shutdown'] = FALSE;
225

    
226
  if (!isset($_POST['text']) || !is_string($_POST['text']) || !isset($_POST['input_format']) || !is_string($_POST['input_format']) || !isset($_POST['token']) || !drupal_valid_token($_POST['token'], 'ckeditorAjaxCall', FALSE)) {
227
    exit;
228
  }
229

    
230
  $format = filter_format_load($_POST['input_format']);
231
  if ($format == FALSE || !is_object($format) || !filter_access($format)) {
232
    exit;
233
  }
234

    
235
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
236

    
237
  $text = $_POST['text'];
238
  $filters = filter_get_filters();
239
  $format_filters = filter_list_format($_POST['input_format']);
240
  $security_filters = ckeditor_security_filters();
241
  $cache_id = $_POST['input_format'] . ':' . '' . ':' . hash('sha256', $text);
242

    
243
  foreach ((array) $format_filters as $name => $object) {
244
    //If filter is not security filter, not exists, cannot be called or isn't enabled in selected text format then skip this filter
245
    if (!isset($security_filters['filters'][$name]) || !isset($filters[$name]) || !isset($filters[$name]['process callback']) || $object->status == 0) {
246
      continue;
247
    }
248

    
249
    // Built-in filter module, a special case where we would like to strip XSS and nothing more
250
    if ($name == 'filter_html' && $security_filters['filters']['filter_html'] == 1) {
251
      preg_match_all("|</?([a-z][a-z0-9]*)(?:\b[^>]*)>|i", $text, $matches);
252
      if ($matches[1]) {
253

    
254
        // Sources of inspiration:
255
        // http://www.w3.org/TR/html4/index/elements.html
256
        // http://www.w3.org/TR/html-markup/elements.html
257
        // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
258

    
259
        $base_allowed_tags = array('a','abbr','acronym','address','area','article','aside','audio','b','base','basefont',
260
          'bdi','bdo','big','blockquote','body','br','button','canvas','caption','center','cite','code','col','colgroup',
261
          'command','datalist','dd','del','details','dfn','dialog','dir','div','dl','dt','em','fieldset','figcaption',
262
          'figure','font','footer','form','h1','h2','h3','h4','h5','h6','head','header','hgroup','hr','html','i','img',
263
          'input','ins','isindex','kbd','keygen','label','legend','li','main','map','mark','menu','menuitem','meter',
264
          'nav','noframes','noscript','ol','optgroup','option','output','p','param','pre','progress','q','rp','rt',
265
          'ruby','s','samp','section','select','small','source','span','strike','strong','sub','summary','sup','table',
266
          'tbody','td','textarea','tfoot','th','thead','time','title','tr','track','tt','u','ul','var','video','wbr',
267
        );
268

    
269
        // Get tags allowed in filter settings
270
        $filter_allowed_tags = preg_split('/\s+|<|>/', $object->settings['allowed_html'], -1, PREG_SPLIT_NO_EMPTY);
271

    
272
        // Combine allowed tags
273
        $tags = array_merge($base_allowed_tags, $filter_allowed_tags);
274

    
275
        // Tags provided by hook
276
        $hooks_allowed_tags = module_invoke_all('ckeditor_filter_xss_allowed_tags');
277
        if (!empty($hooks_allowed_tags) && is_array($hooks_allowed_tags)){
278
          foreach($hooks_allowed_tags as $tag ){
279
            if (!empty($tag) && is_string($tag) && !in_array($tag,$tags)){
280
              array_push($tags,$tag);
281
            }
282
          }
283
        }
284

    
285
        $text = filter_xss($text, $tags);
286
      }
287
      continue;
288
    }
289
    if (isset($filters[$name]['prepare callback']) && function_exists($filters[$name]['prepare callback'])) {
290
      $text = $filters[$name]['prepare callback']($text, $format_filters[$name], $format, '', TRUE, $cache_id);
291
    }
292
    $text = $filters[$name]['process callback']($text, $format_filters[$name], $format, '', TRUE, $cache_id);
293
  }
294

    
295
  echo $text;
296
}