1: <?php
2: /**
3: * THis class provices a place to share common code relating to IMP's
4: * setup and configuration of the browser HTML editor.
5: *
6: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (GPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/gpl.
10: *
11: * @author Michael Slusarz <slusarz@horde.org>
12: * @category Horde
13: * @license http://www.horde.org/licenses/gpl GPL
14: * @package IMP
15: */
16: class IMP_Ui_Editor
17: {
18: /**
19: * Initialize the Rich Text Editor (RTE).
20: *
21: * @param boolean $basic Load the basic ckeditor stub?
22: * @param string $id The DOM ID to load. If null, won't start editor
23: * on page load.
24: */
25: static public function init($basic = false, $id = null)
26: {
27: global $injector, $language, $prefs;
28:
29: $injector->getInstance('Horde_Editor')->initialize(array(
30: 'basic' => $basic,
31: 'config' => 'IMP.ckeditor_config',
32: 'id' => $id
33: ));
34:
35: $font_family = $prefs->getValue('compose_html_font_family');
36: if (!$font_family) {
37: $font_family = 'Arial';
38: }
39:
40: $font_size = intval($prefs->getValue('compose_html_font_size'));
41: $font_size = $font_size
42: /* Font size should be between 8 and 24 pixels. Or else recipients
43: * will hate us. Default to 14px. */
44: ? min(24, max(8, $font_size)) . 'px'
45: : '14px';
46:
47: $config = array(
48: /* To more closely match "normal" textarea behavior, send <BR> on
49: * enter instead of <P>. */
50: // CKEDITOR.ENTER_BR
51: 'enterMode: 2',
52: // CKEDITOR.ENTER_P
53: 'shiftEnterMode: 1',
54:
55: /* Don't load the config.js file. */
56: 'customConfig: ""',
57:
58: /* Disable resize of the textarea. */
59: 'resize_enabled: false',
60:
61: /* Disable spell check as you type. */
62: 'scayt_autoStartup: false',
63:
64: /* Convert HTML entities. */
65: 'entities: false',
66:
67: /* Set language to Horde language. */
68: 'language: "' . Horde_String::lower($language) . '"',
69:
70: /* Default display font. This is NOT the font used to send
71: * the message, however. */
72: 'contentsCss: "body { font-family: ' . $font_family . '; font-size: ' . $font_size . '; }"',
73: 'font_defaultLabel: "' . $font_family . '"',
74: 'fontSize_defaultLabel: "' . $font_size . '"'
75: );
76:
77: $buttons = $prefs->getValue('ckeditor_buttons');
78: if (!empty($buttons)) {
79: $config[] = 'toolbar: ' . $prefs->getValue('ckeditor_buttons');
80: }
81:
82: Horde::addInlineScript(array(
83: 'window.IMP = window.IMP || {}',
84: 'IMP.ckeditor_config = {' . implode(',', $config) . '}'
85: ));
86: }
87:
88: }
89: