Projet

Général

Profil

Paste
Télécharger (11,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ckeditor / includes / ckeditor.page.inc @ 5a7e6170

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

    
43
    case 'admin/config/content/ckeditor/edit/%':
44
    case 'admin/config/content/ckeditor/add':
45
      $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(
46
            '!ckeditor_module_config' => '<code>' . ckeditor_module_path('local') . '/ckeditor.config.js</code>',
47
              )
48
          ) .
49
          '</p><p>' .
50
          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(
51
            '!ckeditor_config_path' => '<code>' . ckeditor_path('local') . '/config.js</code>',
52
            '!ckeditor_config_file' => '<code>config.js</code>',
53
              )
54
          ) .
55
          '</p>';
56
      break;
57

    
58
    case 'admin/config/content/ckeditor/editg':
59
    case 'admin/config/content/ckeditor/add':
60
      $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>';
61
      break;
62

    
63
    case 'admin/config/content/ckeditor':
64
      $output =
65
          '<div style="padding:10px;border:1px solid #BEBFB9;margin-bottom:10px;"><p>' .
66
          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(
67
            '!wysiwyg' => '<acronym title="' . t('What You See Is What You Get') . '">' . t('WYSIWYG') . '</acronym>',
68
              )
69
          ) .
70
          '</p><p>' .
71
          t('Useful links: !ckeditorlink | !devguidelink | !userguidelink.', array(
72
            '!ckeditorlink' => l(t('CKEditor website'), 'http://ckeditor.com'),
73
            '!devguidelink' => l(t('Developer\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Developers_Guide'),
74
            '!userguidelink' => l(t('User\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Users_Guide')
75
              )
76
          ) .
77
          '</p></div><p>' .
78
          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>';
79
      break;
80

    
81
    case 'admin/help#ckeditor':
82
      $output =
83
          '<h3>' . t('Introduction') . '</h3>' .
84
          '<p>' .
85
          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(
86
            '!wysiwyg' => '<acronym title="' . t('What You See Is What You Get') . '">' . t('WYSIWYG') . '</acronym>',
87
              )
88
          ) .
89
          '</p>' .
90
          '<p>' .
91
          t('Useful links: !ckeditorlink | !devguidelink | !userguidelink.', array(
92
            '!ckeditorlink' => l(t('CKEditor website'), 'http://ckeditor.com'),
93
            '!devguidelink' => l(t('Developer\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Developers_Guide'),
94
            '!userguidelink' => l(t('User\'s Guide'), 'http://docs.cksource.com/CKEditor_3.x/Users_Guide')
95
              )
96
          ) .
97
          '</p>' .
98
          '<h4>' .
99
          t('Configuration') .
100
          '</h4>' .
101
          '<ol>' .
102
          '<li>' .
103
          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(
104
            '!adminpath' => '<strong>' . l(t('Administration panel') . ' > ' . t('Configuration') . ' > ' . t('Content Authoring') . ' > ' . t('CKEditor'), 'admin/config/content/ckeditor') . '</strong>'
105
              )
106
          ) .
107
          '</li>' .
108
          '<li>' .
109
          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(
110
            '!filterlink' => l(t('filters'), 'admin/config/content/formats')
111
              )
112
          ) .
113
          '<br /><code>' .
114
          htmlspecialchars('<a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tbody> <th> <tr> <td> <em> <b> <u> <i> <strong> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <embed> <object> <param> <strike> <caption> <iframe>') .
115
          '</code><br />' .
116
          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(
117
            '%iframe' => '<iframe>',
118
            '!readme' => '<code>' . l(t('README.txt'), $base_url . '/' . drupal_get_path('module', 'ckeditor') . '/README.txt', array('absolute' => TRUE)) . '</code>'
119
              )
120
          ) .
121
          '</li>' .
122
          '<li>' .
123
          t('To have better control over line breaks, you should disable the <strong>%settingname</strong> setting in the chosen Text format (recommended).', array(
124
            '%settingname' => t('Line break converter'),
125
              )
126
          ) .
127
          '</li>' .
128
          '<li>' .
129
          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(
130
            '!apidocs' => l(t('API documentation'), 'http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.config.html')
131
              )
132
          ) .
133
          '</li>' .
134
          '</ol>' .
135
          '<h3>' .
136
          t('Troubleshooting') .
137
          '</h3>' .
138
          '<p>' .
139
          t('Take a look at !listlink when installing CKEditor.', array(
140
            '!listlink' => l(t('the list of common problems'), 'http://docs.cksource.com/CKEditor_for_Drupal/Troubleshooting')
141
              )
142
          ) .
143
          ' ' .
144
          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(
145
            '!officiallink' => l(t('official project page'), 'http://drupal.org/project/ckeditor')
146
              )
147
          ) .
148
          ' ' .
149
          t('More information about how to customize CKEditor for your theme can be found !herelink.', array(
150
            '!herelink' => l(t('here'), 'http://drupal.ckeditor.com/tricks')
151
              )
152
          ) .
153
          '</p>' .
154
          '<h3>' .
155
          t('Uploading images and files') .
156
          '</h3>' .
157
          '<p>' .
158
          t('There are three ways for uploading files:') .
159
          '</p>' .
160
          '<ol>' .
161
          '<li>' .
162
          t('By using !ckfinder (commercial), an advanced Ajax file manager.', array(
163
            '!ckfinder' => l(t('CKFinder'), 'http://cksource.com/ckfinder'),
164
              )
165
          ) .
166
          '</li>' .
167
          '<li>' .
168
          t('By using a dedicated module like !imcelink.', array(
169
            '!imcelink' => l(t('IMCE'), 'http://drupal.org/project/imce')
170
              )
171
          ) .
172
          '</li>' .
173
          '<li>' .
174
          t('By using the core upload module.') .
175
          '</li>' .
176
          '</ol>';
177

    
178
      break;
179
  }
180
  return !empty($output) ? $output : '';
181
}
182

    
183
/**
184
 * AJAX callback - XSS filter
185
 */
186
function ckeditor_filter_xss() {
187
  header('Content-Type: text/html; charset=utf-8');
188
  $GLOBALS['devel_shutdown'] = FALSE;
189

    
190
  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', TRUE)) {
191
    exit;
192
  }
193

    
194
  $format = filter_format_load($_POST['input_format']);
195
  if ($format == FALSE || !is_object($format) || !filter_access($format)) {
196
    exit;
197
  }
198

    
199
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
200
  $profile = ckeditor_get_profile($_POST['input_format']);
201

    
202
  $text = $_POST['text'];
203
  $filters = filter_get_filters();
204
  $format_filters = filter_list_format($_POST['input_format']);
205
  $security_filters = ckeditor_security_filters();
206
  $cache_id = $_POST['input_format'] . ':' . '' . ':' . hash('sha256', $text);
207

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

    
214
    //Call default CKEditor built-in filter
215
    if ($name == 'filter_html' && $security_filters['filters']['filter_html'] == 1) {
216
      preg_match_all("|</?([a-z][a-z0-9]*)(?:\b[^>]*)>|i", $text, $matches);
217
      if ($matches[1]) {
218
        $tags = array_unique(array_merge($matches[1], array('!--')));
219
        $text = filter_xss($text, $tags);
220
      }
221
      continue;
222
    }
223
    $text = $filters[$name]['process callback']($text, $format_filters[$name], $format, '', TRUE, $cache_id);
224
  }
225

    
226
  echo $text;
227
}