Projet

Général

Profil

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

root / drupal7 / sites / all / modules / ckeditor / includes / ckeditor.page.inc @ 0695d136

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
  $is_url = false;
39
  $ckeditor_url = ckeditor_path('local');
40
  if ($ckeditor_url == '<URL>') {
41
    $ckeditor_url = ckeditor_path('url');
42
    $is_url = true;
43
  }
44

    
45
  $do_not_touch_configjs = '';
46
  if (!$is_url) {
47
    $do_not_touch_configjs = '<p>' .
48
          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(
49
            '!ckeditor_config_path' => '<code>' . $ckeditor_url . '/config.js</code>',
50
            '!ckeditor_config_file' => '<code>config.js</code>',
51
              )
52
          ) .
53
          '</p>';
54
  }
55
  switch ($path) {
56
    case 'admin/config/content/help#description':
57
      $output = t('Enables the use of CKEditor (a rich text WYSIWYG editor) instead of plain text fields.');
58
      break;
59

    
60
    case 'admin/config/content/ckeditor/edit/%':
61
    case 'admin/config/content/ckeditor/add':
62
      $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(
63
            '!ckeditor_module_config' => '<code>' . ckeditor_module_path('local') . '/ckeditor.config.js</code>',
64
              )
65
          ) .
66
          '</p>'.$do_not_touch_configjs;
67
      break;
68

    
69
    case 'admin/config/content/ckeditor/editg':
70
    case 'admin/config/content/ckeditor/add':
71
      $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>';
72
      break;
73

    
74
    case 'admin/config/content/ckeditor':
75
      $output =
76
          '<div style="padding:10px;border:1px solid #BEBFB9;margin-bottom:10px;"><p>' .
77
          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(
78
            '!wysiwyg' => '<acronym title="' . t('What You See Is What You Get') . '">' . t('WYSIWYG') . '</acronym>',
79
              )
80
          ) .
81
          '</p><p>' .
82
          t('Useful links: !ckeditorlink | !devguidelink | !userguidelink.', array(
83
            '!ckeditorlink' => l(t('CKEditor website'), 'http://ckeditor.com'),
84
            '!devguidelink' => l(t('CKEditor for Drupal 7 Documentation'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7'),
85
            '!userguidelink' => l(t('User\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Users_Guide')
86
              )
87
          ) .
88
          '</p></div><p>' .
89
          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>';
90
      break;
91

    
92
    case 'admin/help#ckeditor':
93
      $output =
94
          '<h3>' . t('Introduction') . '</h3>' .
95
          '<p>' .
96
          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(
97
            '!wysiwyg' => '<acronym title="' . t('What You See Is What You Get') . '">' . t('WYSIWYG') . '</acronym>',
98
              )
99
          ) .
100
          '</p>' .
101
          '<p>' .
102
          t('Useful links: !ckeditorlink | !devguidelink | !userguidelink.', array(
103
            '!ckeditorlink' => l(t('CKEditor website'), 'http://ckeditor.com'),
104
            '!devguidelink' => l(t('CKEditor for Drupal 7 Documentation'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7'),
105
            '!userguidelink' => l(t('User\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Users_Guide')
106
              )
107
          ) .
108
          '</p>' .
109
          '<h4>' .
110
          t('Configuration') .
111
          '</h4>' .
112
          '<ol>' .
113
          '<li>' .
114
          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(
115
            '!adminpath' => '<strong>' . l(t('Administration panel') . ' > ' . t('Configuration') . ' > ' . t('Content Authoring') . ' > ' . t('CKEditor'), 'admin/config/content/ckeditor') . '</strong>'
116
              )
117
          ) .
118
          '</li>' .
119
          '<li>' .
120
          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(
121
            '!filterlink' => l(t('filters'), 'admin/config/content/formats')
122
              )
123
          ) .
124
          '<br /><code>' .
125
          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>') .
126
          '</code><br />' .
127
          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(
128
            '%iframe' => '<iframe>',
129
            '!readme' => '<code>' . l(t('README.txt'), $base_url . '/' . drupal_get_path('module', 'ckeditor') . '/README.txt', array('absolute' => TRUE)) . '</code>'
130
              )
131
          ) .
132
          '</li>' .
133
          '<li>' .
134
          t('To have better control over line breaks, you should disable the <strong>%settingname</strong> setting in the chosen Text format (recommended).', array(
135
            '%settingname' => t('Line break converter'),
136
              )
137
          ) .
138
          '</li>' .
139
          '<li>' .
140
          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(
141
            '!apidocs' => l(t('API documentation'), 'http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html')
142
              )
143
          ) .
144
          '</li>' .
145
          '</ol>' .
146
          '<h3>' .
147
          t('Troubleshooting') .
148
          '</h3>' .
149
          '<p>' .
150
          t('Take a look at !listlink when installing CKEditor.', array(
151
            '!listlink' => l(t('the list of common problems'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7/Troubleshooting')
152
              )
153
          ) .
154
          ' ' .
155
          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(
156
            '!officiallink' => l(t('official project page'), 'http://drupal.org/project/ckeditor')
157
              )
158
          ) .
159
          ' ' .
160
          t('More information about how to customize CKEditor for your theme can be found !herelink.', array(
161
            '!herelink' => l(t('here'), 'http://docs.cksource.com/CKEditor_for_Drupal/Open_Source/Drupal_7/Tricks')
162
              )
163
          ) .
164
          '</p>' .
165
          '<h3>' .
166
          t('Plugins: Code Snippet and MathJax') .
167
          '</h3>' .
168
          '<p>' .
169
          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.') .
170
          '</p>' .
171
          '<h4><a name="mathjax"></a>' .
172
          t('MathJax (Mathematical Formulas)') .
173
          '</h4>' .
174
          '<p>' .
175
          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(
176
            '!code' => '<code>'.htmlspecialchars('<span class="math-tex"></span>').'</code>',
177
            '!mathjax' => l('MathJax', 'http://www.mathjax.org/'),
178
            '!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>'
179
          )) .
180
          '</p>' .
181
          '<h4><a name="codesnippet"></a>' .
182
          t('Code Snippet') .
183
          '</h4>' .
184
          '<p>' .
185
          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(
186
            '!highlight' => l('highlight.js', 'http://highlightjs.org/'),
187
            '!code' => '<code>'.htmlspecialchars('<pre><code></code></pre>').'</code>',
188
            '!script' => '<br /><code>'.htmlspecialchars('<link rel="stylesheet" href="http://cdn.ckeditor.com/4.4.3/full-all/plugins/codesnippet/lib/highlight/styles/default.css">').'<br />'.
189
htmlspecialchars('<script src="http://cdn.ckeditor.com/4.4.3/full-all/plugins/codesnippet/lib/highlight/highlight.pack.js" type="text/javascript"></script>').'<br />'.
190
htmlspecialchars('<script>hljs.initHighlightingOnLoad();</script>').'</code>'
191
          )) .
192
          '</p>' .
193
          '<h3>' .
194
          t('Uploading images and files') .
195
          '</h3>' .
196
          '<p>' .
197
          t('There are three ways for uploading files:') .
198
          '</p>' .
199
          '<ol>' .
200
          '<li>' .
201
          t('By using !ckfinder (commercial), an advanced Ajax file manager.', array(
202
            '!ckfinder' => l(t('CKFinder'), 'http://cksource.com/ckfinder'),
203
              )
204
          ) .
205
          '</li>' .
206
          '<li>' .
207
          t('By using a dedicated module like !imcelink.', array(
208
            '!imcelink' => l(t('IMCE'), 'http://drupal.org/project/imce')
209
              )
210
          ) .
211
          '</li>' .
212
          '<li>' .
213
          t('By using the core upload module.') .
214
          '</li>' .
215
          '</ol>';
216

    
217
      break;
218
  }
219
  return !empty($output) ? $output : '';
220
}
221

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

    
229
  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)) {
230
    exit;
231
  }
232

    
233
  $format = filter_format_load($_POST['input_format']);
234
  if ($format == FALSE || !is_object($format) || !filter_access($format)) {
235
    exit;
236
  }
237

    
238
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
239

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

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

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

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

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

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

    
275
        // Combine allowed tags
276
        $tags = array_merge($base_allowed_tags, $filter_allowed_tags);
277

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

    
288
        $text = filter_xss($text, $tags);
289
      }
290
      continue;
291
    }
292
    $text = $filters[$name]['process callback']($text, $format_filters[$name], $format, '', TRUE, $cache_id);
293
  }
294

    
295
  echo $text;
296
}