Projet

Général

Profil

Paste
Télécharger (5,81 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / ckeditor / includes / ckeditor.user.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_user_customize(&$form, &$form_state, $form_id) {
37

    
38
  module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
39

    
40
  $data = $form['#user']->data;
41

    
42
  $default = ckeditor_user_get_setting_default();
43
  $lang_options = ckeditor_load_lang_options();
44

    
45
  // because the settings are saved as strings we need to test for the string 'true'
46
  if (user_access('customize ckeditor')) {
47
    $form['ckeditor'] = array(
48
      '#type' => 'fieldset',
49
      '#title' => t('Rich text editor settings'),
50
      '#weight' => 10,
51
      '#collapsible' => TRUE,
52
      '#collapsed' => TRUE
53
    );
54

    
55
    $form['ckeditor']['ckeditor_default'] = array(
56
      '#type' => 'radios',
57
      '#title' => t('Default state'),
58
      '#default_value' => isset($data['ckeditor_default']) ? $data['ckeditor_default'] : $default['default'],
59
      '#options' => array(
60
        't' => t('Enabled'),
61
        'f' => t('Disabled')
62
      ),
63
      '#description' => t('Should rich text editing be enabled or disabled by default in textarea fields? If disabled, the rich text editor may still be enabled by using toggle.'),
64
    );
65

    
66
    $form['ckeditor']['ckeditor_show_toggle'] = array(
67
      '#type' => 'radios',
68
      '#title' => t('Show the disable/enable rich text editor toggle'),
69
      '#default_value' => isset($data['ckeditor_show_toggle']) ? $data['ckeditor_show_toggle'] : $default['show_toggle'],
70
      '#options' => array(
71
        't' => t('Yes'),
72
        'f' => t('No')
73
      ),
74
      '#description' => t('Whether or not to show the disable/enable rich text editor toggle below the textarea.'),
75
    );
76

    
77
    $form['ckeditor']['ckeditor_width'] = array(
78
      '#type' => 'textfield',
79
      '#title' => t('Editor width'),
80
      '#default_value' => isset($data['ckeditor_width']) ? $data['ckeditor_width'] : $default['width'],
81
      '#description' => t('Editor interface width in pixels or percent.') . ' ' . t('Examples') . ': 400 ' . t('or') . ' 100%.',
82
      '#size' => 40,
83
      '#maxlength' => 128,
84
    );
85

    
86
    $form['ckeditor']['ckeditor_lang'] = array(
87
      '#type' => 'select',
88
      '#title' => t('Language'),
89
      '#default_value' => isset($data['ckeditor_lang']) ? $data['ckeditor_lang'] : $default['lang'],
90
      '#options' => $lang_options,
91
      '#description' => t('The language for the CKEditor interface.')
92
    );
93

    
94
    $form['ckeditor']['ckeditor_auto_lang'] = array(
95
      '#type' => 'radios',
96
      '#title' => t('Auto-detect language'),
97
      '#default_value' => isset($data['ckeditor_auto_lang']) ? $data['ckeditor_auto_lang'] : $default['auto_lang'],
98
      '#options' => array(
99
        't' => t('Yes'),
100
        'f' => t('No')
101
      ),
102
      '#description' => t('Automatically detect the user language.')
103
    );
104

    
105
    $form['#validate'][] = 'ckeditor_user_customize_form_validate';
106
  }
107
}
108

    
109
function ckeditor_user_customize_form_validate(&$form, &$form_state) {
110
  /*
111
    if (isset($form_state['values']['ckeditor_default'], $form_state['values']['ckeditor_popup']) && $form_state['values']['ckeditor_default'] == 't' && $form_state['values']['ckeditor_popup'] == 't') {
112
    form_set_error('ckeditor_popup', t('If CKEditor is enabled by default, the popup window must be disabled.'));
113
    }
114

    
115
    if (isset($form_state['values']['ckeditor_show_toggle'], $form_state['values']['ckeditor_popup']) && $form_state['values']['ckeditor_show_toggle'] == 't' && $form_state['values']['ckeditor_popup'] == 't') {
116
    form_set_error('ckeditor_popup', t('If toggle is enabled, the popup window must be disabled.'));
117
    }
118
   */
119
  if (isset($form_state['values']['ckeditor_width']) && !preg_match('/^\d+%?$/', $form_state['values']['ckeditor_width'])) {
120
    form_set_error('ckeditor_width', t('Enter a valid width value.') . ' ' . t('Examples:') . ': 400 ' . t('or') . ' 100%.');
121
  }
122
}
123

    
124
/**
125
 * Implements hook_user_presave().
126
 */
127
function ckeditor_user_presave(&$edit, $account, $category) {
128
  if (user_access('customize ckeditor')) {
129
    module_load_include('inc', 'ckeditor', 'includes/ckeditor.lib');
130
    $default = ckeditor_user_get_setting_default();
131

    
132
    $edit['data']['ckeditor_default'] = isset($edit['ckeditor_default']) ? $edit['ckeditor_default'] : $default['default'];
133
    $edit['data']['ckeditor_show_toggle'] = isset($edit['ckeditor_show_toggle']) ? $edit['ckeditor_show_toggle'] : $default['show_toggle'];
134
    $edit['data']['ckeditor_width'] = isset($edit['ckeditor_width']) ? $edit['ckeditor_width'] : $default['width'];
135
    $edit['data']['ckeditor_lang'] = isset($edit['ckeditor_lang']) ? $edit['ckeditor_lang'] : $default['lang'];
136
    $edit['data']['ckeditor_auto_lang'] = isset($edit['ckeditor_auto_lang']) ? $edit['ckeditor_auto_lang'] : $default['auto_lang'];
137
  }
138
}